Re: [PATCH] support for YAST date config in clock applet



On Tue, 2005-07-19 at 19:36 +0200, Vincent Untz wrote:
> > > You also want to change something in config_tool_changed(), I think.
> > > 
> > like checking if the command entered by the user is correct? Added to
> > the patch also.
> 
> Great!
> 
> Just one last comment: at the end of fill_clock_applet(),
> cd->config_tool should be set to config_tool, especially if you want to
> use the hard-coded config tools :-)
> 
> It's okay to commit after that. Thanks for your work!
> 
ok, find attached what I committed, my previous patch with the
fill_clock_applet addition.
-- 
Rodrigo Moya <rodrigo gnome-db org>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-panel/applets/clock/ChangeLog,v
retrieving revision 1.592
diff -u -p -r1.592 ChangeLog
--- ChangeLog	18 Jul 2005 12:15:45 -0000	1.592
+++ ChangeLog	19 Jul 2005 22:41:38 -0000
@@ -1,3 +1,14 @@
+2005-07-19  Rodrigo Moya <rodrigo novell com>
+
+	* clock.c: added support for SuSE's YAST datetime config tool.
+	(try_config_tool): support command lines with arguments.
+	(clock_check_config_tool): new function to look for the tools
+	correctly, even if the command line has arguments.
+	(fill_clock_applet): use clock_check_config_tool to look for the
+	configuration tool.
+	(config_tool_changed): check the value entered by the user before
+	using it.
+
 2005-07-15  Rodrigo Moya <rodrigo novell com>
 
 	* clock.c (update_clock): only show the date in the tooltip if the applet
Index: clock.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/applets/clock/clock.c,v
retrieving revision 1.167
diff -u -p -r1.167 clock.c
--- clock.c	18 Jul 2005 12:15:45 -0000	1.167
+++ clock.c	19 Jul 2005 22:41:39 -0000
@@ -82,6 +82,7 @@ static const char* KEY_SHOW_WEEK     = "
 static const char *clock_config_tools [] = {
 	"system-config-date",
 	"redhat-config-date",
+        "/sbin/yast2 timezone",
 	"time-admin",
 };
 
@@ -1784,25 +1785,33 @@ try_config_tool (GdkScreen  *screen,
 {
 	GtkWidget *dialog;
 	GError    *err;
-	char      *argv[2];
-	char      *app;
+	char     **argv;
+	gboolean   app = FALSE;
 
 	g_return_val_if_fail (tool != NULL, FALSE);
 
-	app = g_find_program_in_path (tool);
+        if (tool && g_shell_parse_argv (tool, NULL, &argv, NULL)) {
+                char *path;
+
+                app = TRUE;
+
+                if (!(path = g_find_program_in_path (argv [0])))
+                        app = FALSE;
+
+                g_free (path);
+        }
 
 	if (!app)
 		return FALSE;
-		
-	argv [0] = app;
-	argv [1] = NULL;		
 
 	err = NULL;
 	if (gdk_spawn_on_screen (screen, NULL, argv, NULL, 0, NULL, NULL, NULL, &err)) {
-		g_free (app);
+                g_strfreev (argv);
 		return TRUE;
 	}
-			
+
+        g_strfreev (argv);
+
 	dialog = gtk_message_dialog_new (NULL,
 					 GTK_DIALOG_DESTROY_WITH_PARENT,
 					 GTK_MESSAGE_ERROR,
@@ -1817,8 +1826,6 @@ try_config_tool (GdkScreen  *screen,
 	gtk_window_set_screen (GTK_WINDOW (dialog), screen);
 			
 	gtk_widget_show_all (dialog);			
-
-	g_free (app);
 		
 	return TRUE;
 }
@@ -1956,8 +1963,10 @@ config_tool_changed (GConfClient  *clien
 
 	value = gconf_value_get_string (entry->value);
 
-        g_free (clock->config_tool);
-	clock->config_tool = g_strdup (value);
+        if (clock_check_config_tool (clock, value)) {
+                g_free (clock->config_tool);
+                clock->config_tool = g_strdup (value);
+        }
 }
 
 static void
@@ -2122,6 +2131,30 @@ clock_migrate_to_26 (ClockData *clock)
 				       NULL);
 }
 
+static char *
+clock_check_config_tool (ClockData *cd, const char *config_tool)
+{
+        char **argv = NULL;
+        char *tool = NULL;
+
+        if (config_tool && g_shell_parse_argv (config_tool, NULL, &argv, NULL)) {
+                char *path;
+
+                g_assert (argv != NULL);
+
+                if (!(path = g_find_program_in_path (argv [0])))
+                        tool = NULL;
+                else {
+                        tool = config_tool;
+                        g_free (path);
+                }
+
+                g_strfreev (argv);
+        }
+
+        return tool;
+}
+
 static gboolean
 fill_clock_applet (PanelApplet *applet)
 {
@@ -2227,25 +2260,35 @@ fill_clock_applet (PanelApplet *applet)
 	}
 
         config_tool = NULL;
-	if (cd->config_tool && cd->config_tool [0])
-		config_tool = g_find_program_in_path (cd->config_tool);
+	if (cd->config_tool && cd->config_tool [0]) {
+		config_tool = clock_check_config_tool (cd, cd->config_tool);
+        }
 
         if (!config_tool) {
                 int i;
 
                 for (i = 0; i < G_N_ELEMENTS (clock_config_tools); i++)
-                        if ((config_tool = g_find_program_in_path (clock_config_tools [i])))
+                        if (config_tool = clock_check_config_tool (cd, clock_config_tools [i]))
                                 break;
         }
 
-	if (!config_tool)
+        g_free (cd->config_tool);
+	if (config_tool) {
+                cd->config_tool = g_strdup (config_tool);
+
+                bonobo_ui_component_set_prop (popup_component,
+					      "/commands/ClockConfig",
+					      "hidden", "0",
+					      NULL);
+        } else {
+                cd->config_tool = NULL;
+
 		bonobo_ui_component_set_prop (popup_component,
 					      "/commands/ClockConfig",
 					      "hidden", "1",
 					      NULL);
-        
-        g_free (config_tool);
-	
+        }
+
 	return TRUE;
 }
 


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