ftlerror-guest changed gksu/trunk/ChangeLog, gksu/trunk/gksu/gksuexec.c

Guilherme de S. Pastore ftlerror-guest at costa.debian.org
Tue Sep 13 20:40:04 UTC 2005


Mensagem de log: 
* gksu/gksuexec.c:
- spit out an error message if no command is given
* gksu/gksuexec.c:
- switch from the deprecated GtkCombo to GtkComboBox
- remove check for empty user;,GtkComboBox won't allow this
- drop get_user_list() and use fill_with_user_list() instead,
  for appending to the ComboBox rather than returning a list
  (also drop free_user_list(), consequently)
* gksu/gksuexec.c:
- destroy the dialog when we no longer need it


-----


Modified: gksu/trunk/ChangeLog
===================================================================
--- gksu/trunk/ChangeLog	2005-09-13 17:22:35 UTC (rev 437)
+++ gksu/trunk/ChangeLog	2005-09-13 20:40:04 UTC (rev 438)
@@ -1,3 +1,19 @@
+2005-09-13  Guilherme de S. Pastore  <guilherme.pastore at terra.com.br>
+
+	* gksu/gksuexec.c:
+	- spit out an error message if no command is given
+
+	* gksu/gksuexec.c:
+	- switch from the deprecated GtkCombo to GtkComboBox
+	- remove check for empty user;,GtkComboBox won't allow this
+	- drop get_user_list() and use fill_with_user_list() instead,
+	  for appending to the ComboBox rather than returning a list
+	  (also drop free_user_list(), consequently)
+
+	* gksu/gksuexec.c:
+	- destroy the dialog when we no longer need it
+
+
 2005-09-13  Gustavo Noronha Silva  <kov at debian.org>
 
 	* gksu/gksu.c, man/gksu.1:

Modified: gksu/trunk/gksu/gksuexec.c
===================================================================
--- gksu/trunk/gksu/gksuexec.c	2005-09-13 17:22:35 UTC (rev 437)
+++ gksu/trunk/gksu/gksuexec.c	2005-09-13 20:40:04 UTC (rev 438)
@@ -42,12 +42,6 @@
   gchar **cmd = g_malloc (sizeof(gchar*)*7);
   gint i = 0;
 
-  if (!strcmp (conf.user, ""))
-    {
-      g_free (conf.user);
-      conf.user = g_strdup ("root");
-    }
-
   cmd[i] = g_strdup (GKSU_CMD); i++;
   cmd[i] = g_strdup ("--user"); i++;
   cmd[i] = g_strdup (conf.user); i++;
@@ -168,22 +162,20 @@
 /*
  * Comparison function for g_list_sort()
  */
-static int get_user_list_cmp(gconstpointer a, gconstpointer b)
+static int fill_with_user_list_cmp(gconstpointer a, gconstpointer b)
 {
   return strcmp(((TmpUser *) a)->username, ((TmpUser *) b)->username);
 }
 
 /*
- * Return an alphabetically sorted list of all users on the system
+ * Fill combobox with an alphabetically sorted list of all users on the system
  */
-static GList *get_user_list()
+static GList *fill_with_user_list(GtkWidget *combobox)
 {
-  GList *ret, *tmp, *list;
+  GList *tmp = NULL, *list;
   TmpUser *tu;
   struct passwd *pw;
 
-  ret = tmp = NULL;
-
   setpwent();
 
   /* Get all the users info and store it temporary */
@@ -197,32 +189,25 @@
   }
 
   /* Sort it! */
-  tmp = g_list_sort(tmp, get_user_list_cmp);
+  tmp = g_list_sort(tmp, fill_with_user_list_cmp);
 
   /* Add only the usernames */
   for (list = tmp; list; list = g_list_next(list)) {
     tu = list->data;
 
-    ret = g_list_append(ret, tu->username);
+    gtk_combo_box_append_text (GTK_COMBO_BOX(combobox), tu->username);
+
+    if (!strcmp (tu->username, "root"))
+      gtk_combo_box_set_active (GTK_COMBO_BOX(combobox),
+				g_list_position(tmp, list));
+
     g_free(tu);
   }
 
   g_list_free(tmp);
   endpwent();
-
-  return ret;
 }
 
-static void free_user_list(GList *users)
-{
-  GList *list;
-
-  for (list = users; list; list = g_list_next(list))
-    g_free(list->data);
-
-  g_list_free(users);
-}
-
 int 
 main (int argc, char **argv)
 {
@@ -244,7 +229,6 @@
   gint response;
 
   GksuContext conf;
-  GList *users;
 
   /* init the default values */
   conf.login_shell = FALSE;
@@ -293,13 +277,9 @@
   gtk_label_set_justify (GTK_LABEL(label_user), GTK_JUSTIFY_LEFT);
   gtk_box_pack_start (GTK_BOX(lvbox), label_user, TRUE, TRUE, 0);
 
-  combo_user = gtk_combo_new ();
-  gtk_editable_set_editable (GTK_EDITABLE(GTK_COMBO(combo_user)->entry), 
-			     FALSE);
-  users = get_user_list();
-  gtk_combo_set_popdown_strings(GTK_COMBO(combo_user), users);
-  free_user_list(users);
-  gtk_combo_set_value_in_list(GTK_COMBO(combo_user), TRUE, FALSE);
+  combo_user = gtk_combo_box_new_text ();
+  fill_with_user_list (combo_user);
+
   gtk_box_pack_start (GTK_BOX(lvbox), combo_user, TRUE, TRUE, 0);
 
   /* right vertical box */
@@ -319,23 +299,33 @@
   /* let the magic begin! */
   gtk_widget_show_all (dialog);
 
-  response = gtk_dialog_run (GTK_DIALOG(dialog));
-
-  switch (response)
+  while (TRUE)
     {
-    case GTK_RESPONSE_CANCEL:
-    case GTK_RESPONSE_DELETE_EVENT:
-    case GTK_RESPONSE_NONE:
-      exit (0);
-    }
+      response = gtk_dialog_run (GTK_DIALOG(dialog));
 
-  gtk_widget_hide (dialog);
+      switch (response)
+	{
+	case GTK_RESPONSE_CANCEL:
+	case GTK_RESPONSE_DELETE_EVENT:
+	case GTK_RESPONSE_NONE:
+	  exit (0);
+	}
 
-  conf.command = gtk_editable_get_chars (GTK_EDITABLE(entry_cmd), 0, -1);
-  conf.user =
-    gtk_editable_get_chars (GTK_EDITABLE(GTK_COMBO(combo_user)->entry), 0, -1);
+      conf.command = gtk_editable_get_chars (GTK_EDITABLE(entry_cmd), 0, -1);
+      conf.user = gtk_combo_box_get_active_text (GTK_COMBO_BOX(combo_user));
 
-  run_gksu (conf);
+      if (!strcmp (conf.command, ""))
+	{
+	  gk_dialog (GTK_MESSAGE_ERROR, _("Missing command to run."));
+	}
+      else
+	{
+	  gtk_widget_destroy (dialog);
+	  run_gksu (conf);
 
+	  break;
+	}
+    }
+
   return 0;
 }




More information about the gksu-commits mailing list