[prev in list] [next in list] [prev in thread] [next in thread] 

List:       asterisk-dev
Subject:    Re: [Asterisk-Dev] gastman hostname patch
From:       Tilghman Lesher <tilghman () mail ! jeffandtilghman ! com>
Date:       2003-05-27 4:45:58
Message-ID: 200305262345.58313.tilghman () mail ! jeffandtilghman ! com
[Download RAW message or body]

On Monday 26 May 2003 22:45, Tilghman Lesher wrote:
> On Friday 23 May 2003 23:15, Tilghman Lesher wrote:
> > This patch changes the initial hostname in gastman from an Entry
> > box to a Combo box, listing all the hostnames for which there are
> > configurations for the user, but also allowing additional hostnames
> > (new machines) to be entered.
>
> Fixes for (harmless) error messages.

Nothing really special in this one, but it may annoy some users.
Displays the IP address in parentheses immediately following the
hostname.

-Tilghman

["gastman__combo_hostname__2.diff" (text/x-diff)]

? gui.diff
Index: Makefile
===================================================================
RCS file: /usr/cvsroot/gastman/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- Makefile	25 Mar 2003 19:45:15 -0000	1.2
+++ Makefile	27 May 2003 05:00:44 -0000
@@ -7,12 +7,32 @@
 #
 # For GTK 1.2
 #
-GTKFLAGS=$(shell if [ -z "$(GTK2FLAGS)" ]; then echo `gtk12-config --cflags`; else \
                echo $(GTK2FLAGS); fi)
-GTKLIBS=$(shell if [ -z "$(GTK2LIBS)" ]; then echo `gtk12-config --libs`; else echo \
                $(GTK2LIBS); fi)
-#GTKFLAGS=$(shell gtk-config --cflags)
-#GTKLIBS=$(shell gtk-config --libs)
-
-GLIBFLAGS=$(shell echo `glib12-config --cflags`)
+GTKFLAGS=$(shell \
+	if [ -z $(GTK2FLAGS) ]; then \
+		if [ `which gtk12-config 2>/dev/null`="" ]; then \
+			echo `gtk-config --cflags`; \
+		else \
+			echo `gtk12-config --cflags`; \
+		fi \
+	else \
+		echo $(GTK2FLAGS); \
+	fi)
+GTKLIBS=$(shell \
+	if [ -z "$(GTK2LIBS)" ]; then \
+		if [ `which gtk12-config 2>/dev/null`="" ]; then \
+			echo `gtk-config --cflags`; \
+		else \
+			echo `gtk12-config --libs`; \
+		fi \
+	else \
+		echo $(GTK2LIBS); \
+	fi)
+GLIBFLAGS=$(shell \
+	if [ `which glib12-config 2>/dev/null`="" ]; then \
+		echo `glib-config --cflags 2>/dev/null`; \
+	else \
+		echo `glib12-config --cflags`; \
+	fi)
 
 CFLAGS=-Wall -g $(GTKFLAGS) $(GLIBFLAGS) -Iinclude -DGTK_ENABLE_BROKEN
 LIBS=$(GTKLIBS) $(shell if [ -f /etc/master.passwd ]; then echo ""; else echo "-ldb \
                "; fi)
Index: gastman.c
===================================================================
RCS file: /usr/cvsroot/gastman/gastman.c,v
retrieving revision 1.3
diff -u -r1.3 gastman.c
--- gastman.c	30 Mar 2003 20:35:24 -0000	1.3
+++ gastman.c	27 May 2003 05:00:44 -0000
@@ -1539,7 +1539,7 @@
 		strncpy(host, *argv, sizeof(host) - 1);
 
 	if (strlen(host) || 
-		(!gui_get_user_input("Enter hostname", "Enter the hostname you wish to connect \
to:", host, sizeof(host) - 1) && +		(!gui_get_hostname(host, sizeof(host) - 1) &&
 			strlen(host))) {
 		if (!login(host)) {
 			manage_calls(host);
Index: gastman.h
===================================================================
RCS file: /usr/cvsroot/gastman/gastman.h,v
retrieving revision 1.2
diff -u -r1.2 gastman.h
--- gastman.h	30 Mar 2003 20:35:24 -0000	1.2
+++ gastman.h	27 May 2003 05:00:44 -0000
@@ -45,6 +45,7 @@
 int gui_set_icon(int nformat);
 int gui_status(char *str);
 int gui_get_user_input(char *title, char *msg, char *buf, int buflen);
+int gui_get_hostname(char *buf, int buflen);
 int gui_link(struct gui_object *obj1, struct gui_object *obj2);
 int gui_unlink(struct gui_object *obj1, struct gui_object *obj2);
 int gui_show_chan_menu(void);
Index: gui.c
===================================================================
RCS file: /usr/cvsroot/gastman/gui.c,v
retrieving revision 1.3
diff -u -r1.3 gui.c
--- gui.c	30 Mar 2003 20:35:24 -0000	1.3
+++ gui.c	27 May 2003 05:00:46 -0000
@@ -28,6 +28,10 @@
 #include <gtk/gtk.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
 #include <db.h>
 #include <math.h>
 #include <time.h>
@@ -834,7 +838,7 @@
 int gui_init(int *argc, char **argv[])
 {
 	char *fn = loc_file();
-	int res;
+	int res = 0;
 	if (fn) {
 #ifdef __FreeBSD__
 		if (!(db = dbopen(fn, O_CREAT | O_RDWR, 0664, DB_BTREE, NULL))) {
@@ -852,7 +856,7 @@
 	}
 	gtk_init(argc, argv);
 	srand(time(NULL));
-	return 0;
+	return res;
 }
 
 void dialog_answer(GtkWidget *widget, gpointer data)
@@ -866,6 +870,7 @@
 }
 
 static GtkWidget *entry;
+static GtkWidget *combo;
 static char *outmsg;
 static int outmsglen;
 void entry_answer(GtkWidget *widget, gpointer data)
@@ -879,6 +884,21 @@
 	dialog = NULL;
 }
 
+void combo_answer(GtkWidget *widget, gpointer data)
+{
+	GtkCombo *combo2 = GTK_COMBO(combo);
+	choice = (int)(long)data;
+	if (!choice) {
+		char *extra;
+		strncpy(outmsg, gtk_entry_get_text(GTK_ENTRY(combo2->entry)), outmsglen - 1);
+		if ((extra = strstr(outmsg, " (")))
+			extra[0] = '\0';
+	} else
+		strcpy(outmsg, "");
+	gtk_widget_destroy(dialog);
+	dialog = NULL;
+}
+
 static char lastcmd[512];
 
 void command_ready(GtkWidget *widget, gpointer data)
@@ -942,6 +962,108 @@
 		gtk_main_iteration_do(1);
 	if (window)
 		gtk_widget_set_sensitive(window, TRUE);
+	return choice;
+}
+
+int gui_get_hostname(char *buf, int buflen)
+{
+	GtkWidget *button;
+	GtkWidget *tw;
+	GtkWidget *vbox, *hbox;
+	GtkWidget *icon;
+	GList *list = NULL;
+	char *rtext = "GAstman: Select hostname";
+	int x;
+	int choices = 2;
+	DIR *gastman_dir;
+	struct dirent *gastman_dirent;
+	static char fn[256];
+
+	snprintf(fn, sizeof(fn), "%s" G_DIR_SEPARATOR_S ".gastman", gui_get_home_dir());
+	gastman_dir = opendir(fn);
+	while (( gastman_dirent = readdir(gastman_dir) )) {
+		char *thedot;
+		if ( gastman_dirent->d_name[0] == '.' )
+			continue;
+		if (( thedot = strstr(gastman_dirent->d_name, ".extens") )) {
+			char *copy;
+			struct hostent *hostent;
+
+			thedot[0] = '\0';
+			if ((hostent = gethostbyname(gastman_dirent->d_name))) {
+				struct in_addr addr;
+				memcpy(&addr, hostent->h_addr_list[0], sizeof(addr));
+				if (strcmp(inet_ntoa(addr), gastman_dirent->d_name)) {
+					copy = alloca(strlen(gastman_dirent->d_name) + strlen(inet_ntoa(addr)) + 4);
+					if (copy) {
+						sprintf(copy, "%s (%s)", gastman_dirent->d_name, inet_ntoa(addr));
+						list = g_list_append(list, copy);
+					}
+				} else {
+					copy = alloca(strlen(gastman_dirent->d_name) + 1);
+					if (copy) {
+						strcpy(copy, gastman_dirent->d_name);
+						list = g_list_append(list, copy);
+					}
+				}
+			} else {
+				copy = alloca(strlen(gastman_dirent->d_name) + 1);
+				if (copy) {
+					strcpy(copy, gastman_dirent->d_name);
+					list = g_list_append(list, copy);
+				}
+			}
+		}
+	}
+	closedir(gastman_dir);
+
+	dialog = gtk_dialog_new();
+	tw = gtk_label_new("Select or enter the hostname you wish to connect to:");
+	gtk_window_set_title(GTK_WINDOW(dialog), rtext);
+	gtk_widget_realize(dialog);
+	fix_icon(dialog->window);
+	gtk_widget_show(tw);
+	vbox = gtk_vbox_new(FALSE, 0);
+	hbox = gtk_hbox_new(FALSE, 0);
+	icon = make_pixmap_from_data(dialog, inkwell_xpm);
+	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 10);
+	gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 10);
+	gtk_box_pack_start(GTK_BOX(vbox), tw, TRUE, TRUE, 15);
+	gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 10);
+	combo = gtk_combo_new();
+	gtk_combo_set_case_sensitive(GTK_COMBO(combo), FALSE);
+	gtk_combo_set_value_in_list(GTK_COMBO(combo), FALSE, FALSE);
+	gtk_combo_set_use_arrows(GTK_COMBO(combo), TRUE);
+	gtk_combo_set_use_arrows_always(GTK_COMBO(combo), TRUE);
+	gtk_combo_set_popdown_strings(GTK_COMBO(combo), list);
+	gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 5);
+	/* gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)), "activate", \
GTK_SIGNAL_FUNC(combo_answer), (gpointer)(long)0); */ +	choice = -1;
+	
+	for (x=0;x<choices;x++) {
+		button = gtk_button_new_with_label(okcancel[x]);
+		gtk_widget_set_usize(button, 80, 30);
+		gtk_widget_show(button);
+		gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(combo_answer), \
(gpointer)(long)x); +		gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), \
button, FALSE, FALSE, 10); +	}
+	gtk_widget_grab_focus(combo);
+	if (window)
+		gtk_widget_set_sensitive(window, FALSE);
+	outmsg = buf;
+	outmsglen = buflen;
+	gtk_window_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
+	gtk_widget_show_all(dialog);
+	/* Block as long as dialog is here */
+	while(dialog) 
+		gtk_main_iteration_do(1);
+	if (window)
+		gtk_widget_set_sensitive(window, TRUE);
+
+	/* Clean up associated memory */
+	g_list_free(list);
+
 	return choice;
 }
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic