[Frugalware-darcs] fw-control-center: gnetconfig: users can now specify a description for the profile.

Priyank priyank at frugalware.org
Wed Jun 20 10:08:06 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=fw-control-center;a=darcs_commitdiff;h=20070620070118-5ce2c-eadf2454591aaed31774fa0808ef13284aa0a3a2.gz;

[gnetconfig: users can now specify a description for the profile.
Priyank <priyank at frugalware.org>**20070620070118
 * Allow users to specify a description for the profile while creating a
   new profile.
 * Do not create new input dialogs everytime an input operation is
   required.
 * gnetconfig-messages: new function gn_input() which serves as an input
   dialog.
 * Code cleanups.
] {
hunk ./gnetconfig/src/gnetconfig-messages.c 91
+char *
+gn_input (const char *title, const char *message, int *res)
+{
+	GtkWidget	*dialog;
+	GtkWidget	*entry;
+	GtkWidget	*label;
+	char		*ret = NULL;
+
+	ret = NULL;
+
+	dialog = gtk_dialog_new_with_buttons (title,
+						GTK_WINDOW(gn_main_window),
+						GTK_DIALOG_DESTROY_WITH_PARENT,
+						GTK_STOCK_OK,
+                                         	GTK_RESPONSE_ACCEPT,
+                                         	GTK_STOCK_CANCEL,
+                                         	GTK_RESPONSE_REJECT,
+                                         	NULL);
+	gtk_window_set_resizable (GTK_WINDOW(dialog), FALSE);
+	label = gtk_label_new (message);
+	entry = gtk_entry_new ();
+
+	gtk_misc_set_padding (GTK_MISC(label), 5, 5);
+	gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
+	gtk_container_set_border_width (GTK_CONTAINER((GTK_DIALOG(dialog))->vbox), 10);
+	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
+	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), entry);
+	gtk_widget_show_all (GTK_WIDGET(dialog));
+	*res = gtk_dialog_run (GTK_DIALOG(dialog));
+	ret = (char*)g_strdup(gtk_entry_get_text (GTK_ENTRY(entry)));
+	gtk_widget_destroy (GTK_WIDGET(dialog));
+
+	return ret;
+}
hunk ./gnetconfig/src/gnetconfig-messages.h 25
+
+char * gn_input (const char *, const char *, int *);
hunk ./gnetconfig/src/gnetconfig-new_profile.c 34
-static void cb_gn_new_profile_dialog_response (GtkDialog *dlg, gint arg1, gpointer dialog);
-
hunk ./gnetconfig/src/gnetconfig-new_profile.c 51
-	GtkWidget 	*dialog;
-	GtkWidget 	*label;
-	GtkWidget 	*entry;
-	static gchar	*message = "Enter a name for the new profile: ";
-
-	dialog = gtk_dialog_new_with_buttons (_("New Profile"),
-                                         GTK_WINDOW(gn_main_window),
-                                         GTK_DIALOG_DESTROY_WITH_PARENT,
-                                         GTK_STOCK_OK,
-                                         GTK_RESPONSE_ACCEPT,
-                                         GTK_STOCK_CANCEL,
-                                         GTK_RESPONSE_REJECT,
-                                         NULL);
-	gtk_window_set_resizable (GTK_WINDOW(dialog), FALSE);
-	label = gtk_label_new (message);
-	entry = gtk_entry_new ();
+	gint	res;
+	char	*pname = NULL;
+	gchar	*filename = NULL;
hunk ./gnetconfig/src/gnetconfig-new_profile.c 55
-	g_signal_connect_swapped (dialog,
-                             "response",
-                             G_CALLBACK (cb_gn_new_profile_dialog_response),
-                             dialog);
-	gtk_misc_set_padding (GTK_MISC(label), 5, 5);
-	gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
-	gtk_container_set_border_width (GTK_CONTAINER((GTK_DIALOG(dialog))->vbox), 10);
-	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
-	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), entry);
+	up: pname = gn_input (_("New Profile"),
+				_("Enter a name for the new profile"),
+				&res);
+	if (res == GTK_RESPONSE_ACCEPT)
+	{
+		/* check if profile already exists */
+		filename = g_strdup_printf ("/etc/sysconfig/network/%s", pname);
+		if (g_file_test(filename, G_FILE_TEST_EXISTS))
+		{	
+			gn_error ("A profile with this name already exists. Please provide a unique profile name.", ERROR_GUI);
+			g_free (filename);
+			goto up;
+			return;
+		}
hunk ./gnetconfig/src/gnetconfig-new_profile.c 70
-	gtk_widget_show_all (dialog);
+		/* further processing */
+		if (gnetconfig_setup_new_profile (pname))
+		{
+			gn_error ("Error setting up new profile", ERROR_GUI);
+			g_free (filename);
+			return;
+		}
+		g_free (pname);
+		g_free (filename);
+	}
hunk ./gnetconfig/src/gnetconfig-new_profile.c 98
+	if (gn_question(_("Do you want to give a description to the new profile?")) == GTK_RESPONSE_YES)
+	{
+		char *ret = NULL;
+		gint res;
hunk ./gnetconfig/src/gnetconfig-new_profile.c 103
+		up: ret = gn_input (_("New Profile"), _("Enter a description for this profile:"), &res);
+		if (res != GTK_RESPONSE_ACCEPT)
+			goto down;
+		if (ret!=NULL && strlen(ret))
+		{
+			snprintf (new_profile->desc, PATH_MAX, ret);
+			fwnet_writeconfig (new_profile, NULL);
+			g_free (ret);
+		}
+		else
+		{
+			gn_error (_("Please enter a valid description for the new profile or click the Cancel button to contiune without entering a description."), ERROR_GUI);
+			goto up;
+		}
+	}
hunk ./gnetconfig/src/gnetconfig-new_profile.c 119
+	down:
hunk ./gnetconfig/src/gnetconfig-new_profile.c 133
-
-/* CALLBACKS */
-
-static void
-cb_gn_new_profile_dialog_response (GtkDialog *dlg, gint arg1, gpointer dialog)
-{
-	if (arg1 == GTK_RESPONSE_ACCEPT)
-	{
-		GList		*wlist = NULL;
-		gchar		*filename = NULL;
-		const gchar	*pname;
-
-		wlist = gtk_container_get_children (GTK_CONTAINER(GTK_DIALOG(dialog)->vbox));
-		wlist = g_list_next (wlist);
-		pname = gtk_entry_get_text (GTK_ENTRY(wlist->data));
-
-		/* check if profile already exists */
-		filename = g_strdup_printf ("/etc/sysconfig/network/%s", pname);
-		if (g_file_test(filename, G_FILE_TEST_EXISTS))
-		{	
-			gn_error ("profile already exists", ERROR_GUI);
-			g_free (filename);
-			return;
-		}
-
-		/* further processing */
-		if (gnetconfig_setup_new_profile (pname))
-		{
-			gn_error ("Error setting up new profile", ERROR_GUI);
-			g_free (filename);
-			return;
-		}
-
-		g_free (filename);
-		g_list_free (wlist);
-	}
-
-	gtk_widget_destroy (GTK_WIDGET(dlg));
-	return;
-}
}


More information about the Frugalware-darcs mailing list