[gnome-network][PATCH] command line functions



Hi,

Here is a patch that implements what I proposed yesterday.

Please let me know if it looks ok and I'll commit it. I should point out that this patch also includes a capitalization fix for the .desktop file.

Thanks,
Jon
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ChangeLog,v
retrieving revision 1.103
diff -u -r1.103 ChangeLog
--- ChangeLog	15 Dec 2003 19:15:23 -0000	1.103
+++ ChangeLog	16 Dec 2003 21:16:27 -0000
@@ -1,9 +1,27 @@
+2003-12-16  William Jon McCann  <mccann jhu edu>
+
+	* gnome-netinfo.desktop.in (Name): Capitalize name.
+
+	* netinfo.h: Fix out of order enum fields.
+
+	* netinfo.[ch] (netinfo_set_host): New function to set host field
+	in UI.
+	(netinfo_set_user): New function to set user field in UI.
+	
+	* main.c (start_initial_process_cb): New function to process
+	command line requests.
+	(main): Add command line options and set initial state.
+
+	* info.[ch] (info_set_nic): New function to set interface in UI.
+
+	* callbacks.h: Add typedef for activate callback functions.
+
 2003-12-15  Carlos García Campos <carlosgc gnome org>
 
 	* info.c (info_get_nic_information): removed invalid g_free()
 
 2003-12-01  Bastien Nocera  <hadess hadess net>
-                                                                                
+
 	* main.c: (load_whois_widgets_from_xml): we don't have a "user"
     entry in the whois tab (fixes startup warnings)
 	  fixes #128282
Index: callbacks.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/callbacks.h,v
retrieving revision 1.12
diff -u -r1.12 callbacks.h
--- callbacks.h	20 Nov 2003 22:11:05 -0000	1.12
+++ callbacks.h	16 Dec 2003 21:16:27 -0000
@@ -1,5 +1,7 @@
 #include <gnome.h>
 
+typedef void* (* NetinfoActivateFn) (GtkWidget *widget, gpointer data);
+
 void on_ping_activate (GtkWidget * editable, gpointer data);
 
 void on_traceroute_activate (GtkWidget * editable, gpointer data);
Index: gnome-netinfo.desktop.in
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/gnome-netinfo.desktop.in,v
retrieving revision 1.2
diff -u -r1.2 gnome-netinfo.desktop.in
--- gnome-netinfo.desktop.in	25 Aug 2003 15:54:37 -0000	1.2
+++ gnome-netinfo.desktop.in	16 Dec 2003 21:16:27 -0000
@@ -1,5 +1,5 @@
 [Desktop Entry]
-Name=Network information
+Name=Network Information
 Comment=Network information tools
 Exec=gnome-netinfo
 Icon=gnome-netinfo.png
Index: info.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/info.c,v
retrieving revision 1.20
diff -u -r1.20 info.c
--- info.c	15 Dec 2003 19:15:23 -0000	1.20
+++ info.c	16 Dec 2003 21:16:27 -0000
@@ -48,6 +48,26 @@
 }
 
 void
+info_set_nic (Netinfo * netinfo, const gchar *nic)
+{
+	GList *interfaces = NULL, *p;
+
+	g_return_if_fail (netinfo != NULL);
+	
+	if (nic == NULL)
+		return;
+
+	interfaces = info_get_interfaces ();
+	for (p = interfaces; p != NULL; p = p->next) {
+		if (! strcmp (p->data, nic)) {
+			gtk_entry_set_text (GTK_ENTRY (netinfo->nic),
+					    nic);
+		}
+	}
+	g_list_free (interfaces);
+}
+
+void
 info_load_iface (Netinfo * info, GtkWidget * combo)
 {
 	GList *items = NULL;
Index: info.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/info.h,v
retrieving revision 1.8
diff -u -r1.8 info.h
--- info.h	24 Jul 2003 17:21:11 -0000	1.8
+++ info.h	16 Dec 2003 21:16:27 -0000
@@ -34,6 +34,7 @@
 #endif
 
 void info_do (const gchar * nic, Netinfo * info);
+void info_set_nic (Netinfo * info, const gchar *nic);
 void info_load_iface (Netinfo * info, GtkWidget * combo);
 
 void info_nic_changed (GtkEditable *editable, gpointer data);
Index: main.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/main.c,v
retrieving revision 1.41
diff -u -r1.41 main.c
--- main.c	5 Dec 2003 02:27:22 -0000	1.41
+++ main.c	16 Dec 2003 21:16:27 -0000
@@ -43,6 +43,7 @@
 Netinfo *load_finger_widgets_from_xml (GladeXML * xml);
 Netinfo *load_whois_widgets_from_xml (GladeXML * xml);
 Netinfo *load_info_widgets_from_xml (GladeXML * xml);
+static gboolean start_initial_process_cb (gpointer data);
 
 int
 main (int argc, char *argv[])
@@ -60,6 +61,42 @@
 	Netinfo *finger;
 	Netinfo *whois;
 	gchar *icon_path;
+	gint current_page = 0;
+	static gchar *info_input = NULL;
+	static gchar *ping_input = NULL;
+	static gchar *netstat_input = NULL;
+	static gchar *scan_input = NULL;
+	static gchar *traceroute_input = NULL;
+	static gchar *lookup_input = NULL;
+	static gchar *finger_input = NULL;
+	static gchar *whois_input = NULL;
+	static const struct poptOption options[] = {
+		{ "info", 'i', POPT_ARG_STRING, &info_input, 0,
+		  N_("Load information for a network device"),
+		  N_("DEVICE") },
+		{ "ping", 'p', POPT_ARG_STRING, &ping_input, 0,
+		  N_("Send a ping to a network address"),
+		  N_("HOST") },
+		{ "netstat", 'n', POPT_ARG_STRING, &netstat_input, 0,
+		  N_("Get netstat information.  Valid options are: route, active, multicast."),
+		  N_("COMMAND") },
+		{ "traceroute", 't', POPT_ARG_STRING, &traceroute_input, 0,
+		  N_("Trace a route to a network address"),
+		  N_("HOST") },
+		{ "port-scan", 's', POPT_ARG_STRING, &scan_input, 0,
+		  N_("Port scan a network address"),
+		  N_("HOST") },
+		{ "lookup", 'l', POPT_ARG_STRING, &lookup_input, 0,
+		  N_("Look up a network address"),
+		  N_("HOST") },
+		{ "finger", 'f', POPT_ARG_STRING, &finger_input, 0,
+		  N_("Finger command to run"),
+		  N_("USER") },
+		{ "whois", 'w', POPT_ARG_STRING, &whois_input, 0,
+		  N_("Perform a whois lookup for a network domain"),
+		  N_("DOMAIN") },
+		{ NULL, '\0', 0, NULL, 0 }
+	};
 
 #ifdef ENABLE_NLS
 	bindtextdomain (GETTEXT_PACKAGE, GNOME_NETINFO_LOCALEDIR);
@@ -69,6 +106,9 @@
 
 	gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE,
 			    argc, argv,
+			    GNOME_PARAM_HUMAN_READABLE_NAME,
+			    _("Network Information"),
+			    GNOME_PARAM_POPT_TABLE, options,
 			    GNOME_PARAM_APP_DATADIR, DATADIR,
 			    GNOME_PARAM_NONE);
 
@@ -95,6 +135,61 @@
 	finger = load_finger_widgets_from_xml (xml);
 	whois = load_whois_widgets_from_xml (xml);
 
+	if (info_input) {
+		current_page = INFO;
+		info_set_nic (info, info_input);
+		gtk_idle_add (start_initial_process_cb, info);
+	}
+	if (ping_input) {
+		current_page = PING;
+		netinfo_set_host (pinger, ping_input);
+		gtk_idle_add (start_initial_process_cb, pinger);
+	}
+	if (netstat_input) {
+		current_page = NETSTAT;
+		if (! strcmp (netstat_input, "route"))
+			gtk_toggle_button_set_active
+				(GTK_TOGGLE_BUTTON (netstat->routing), TRUE);
+		else if (! strcmp (netstat_input, "active"))
+			gtk_toggle_button_set_active
+				(GTK_TOGGLE_BUTTON (netstat->protocol), TRUE);
+		else if (! strcmp (netstat_input, "multicast"))
+			gtk_toggle_button_set_active
+				(GTK_TOGGLE_BUTTON (netstat->multicast), TRUE);
+		gtk_idle_add (start_initial_process_cb, netstat);
+	}
+	if (traceroute_input) {
+		current_page = TRACEROUTE;
+		netinfo_set_host (tracer, traceroute_input);
+		gtk_idle_add (start_initial_process_cb, tracer);
+	}
+	if (scan_input) {
+		current_page = PORTSCAN;
+		netinfo_set_host (scan, scan_input);
+		gtk_idle_add (start_initial_process_cb, scan);
+	}
+	if (lookup_input) {
+		current_page = LOOKUP;
+		netinfo_set_host (lookup, lookup_input);
+		gtk_idle_add (start_initial_process_cb, lookup);
+	}
+	if (finger_input) {
+		gchar **split_input = NULL;
+		current_page = FINGER;
+		split_input = g_strsplit (finger_input, "@", 2);
+		if (split_input[0])
+			netinfo_set_user (finger, split_input[0]);
+		if (split_input[1])
+			netinfo_set_host (finger, split_input[1]);
+		g_strfreev (split_input);
+		gtk_idle_add (start_initial_process_cb, finger);
+	}
+	if (whois_input) {
+		current_page = WHOIS;
+		netinfo_set_host (whois, whois_input);
+		gtk_idle_add (start_initial_process_cb, whois);
+	}
+
 	notebook = glade_xml_get_widget (xml, "notebook");
 	g_object_set_data (G_OBJECT (notebook), "pinger", pinger);
 	g_object_set_data (G_OBJECT (notebook), "tracer", tracer);
@@ -108,6 +203,8 @@
 	glade_xml_signal_autoconnect (xml);
 	g_object_unref (G_OBJECT (xml));
 
+	gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), current_page);
+
 	gtk_widget_show_all (window);
 
 	gtk_main ();
@@ -124,6 +221,20 @@
 	return 0;
 }
 
+static gboolean
+start_initial_process_cb (gpointer data)
+{
+	Netinfo *ni = data;
+	NetinfoActivateFn fn_cb;
+
+	g_return_val_if_fail (data != NULL, FALSE);
+
+	fn_cb = (NetinfoActivateFn) ni->button_callback;
+	if (fn_cb)
+		(*fn_cb) (ni->button, data);
+	return FALSE;
+}
+
 /* The value returned must be released from memory */
 Netinfo *
 load_ping_widgets_from_xml (GladeXML * xml)
Index: netinfo.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.c,v
retrieving revision 1.17
diff -u -r1.17 netinfo.c
--- netinfo.c	20 Nov 2003 21:12:43 -0000	1.17
+++ netinfo.c	16 Dec 2003 21:16:27 -0000
@@ -60,6 +60,20 @@
 				 (GNOME_ENTRY (netinfo->host))));
 }
 
+void
+netinfo_set_host (Netinfo * netinfo, const gchar *host)
+{
+	g_return_if_fail (netinfo != NULL);
+	g_return_if_fail (GTK_IS_ENTRY
+			  (gnome_entry_gtk_entry
+			   (GNOME_ENTRY (netinfo->host))));
+
+	gtk_entry_set_text (GTK_ENTRY
+				(gnome_entry_gtk_entry
+				 (GNOME_ENTRY (netinfo->host))),
+			    host);
+}
+
 const gchar *
 netinfo_get_user (Netinfo * netinfo)
 {
@@ -74,6 +88,20 @@
 				 (GNOME_ENTRY (netinfo->user))));
 }
 
+void
+netinfo_set_user (Netinfo * netinfo, const gchar *user)
+{
+	g_return_if_fail (netinfo != NULL);
+	g_return_if_fail (GTK_IS_ENTRY
+			  (gnome_entry_gtk_entry
+			   (GNOME_ENTRY (netinfo->user))));
+
+	gtk_entry_set_text (GTK_ENTRY
+				(gnome_entry_gtk_entry
+				 (GNOME_ENTRY (netinfo->user))),
+			    user);
+}
+
 gint
 netinfo_get_ip_version (Netinfo * netinfo)
 {
Index: netinfo.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.h,v
retrieving revision 1.16
diff -u -r1.16 netinfo.h
--- netinfo.h	19 Nov 2003 16:19:10 -0000	1.16
+++ netinfo.h	16 Dec 2003 21:16:27 -0000
@@ -93,8 +93,8 @@
 enum {
 	INFO = 0,
 	PING,
-	TRACEROUTE,
 	NETSTAT,
+	TRACEROUTE,
 	PORTSCAN,
 	LOOKUP,
 	FINGER,
@@ -117,6 +117,8 @@
 gushort netinfo_get_count (Netinfo * netinfo);
 const gchar * netinfo_get_host (Netinfo * netinfo);
 const gchar * netinfo_get_user (Netinfo * netinfo);
+void netinfo_set_host (Netinfo * netinfo, const gchar *host);
+void netinfo_set_user (Netinfo * netinfo, const gchar *user);
 gint netinfo_get_ip_version (Netinfo * netinfo);
 gboolean netinfo_validate_host (Netinfo * netinfo);
 void netinfo_toggle_button (Netinfo * netinfo);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]