gnome-panel r11402 - trunk/gnome-panel



Author: vuntz
Date: Tue Dec  9 19:21:01 2008
New Revision: 11402
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11402&view=rev

Log:
2008-12-09  Vincent Untz  <vuntz gnome org>

	Remove dependency on gnome_util_home_file()

	* launcher.h: move PANEL_LAUNCHERS_PATH to panel-util.c
	* launcher.c: (panel_launcher_delete): update to use
	panel_launcher_is_in_personal_path()
	Move some functions to panel-util.c. That's suboptimal, but I can't
	figure out yet how I want the code to be organized, so...
	* panel-util.c: (panel_launcher_get_personal_path): new, real
	gnome_util_home_file() killer
	(panel_launcher_is_in_personal_path): new, does what the name implies
	(panel_launcher_get_gfile),
	(panel_launcher_get_uri), (panel_launcher_get_filename): moved from
	launcher.c
	(panel_make_full_path): trivial update
	* panel-util.h: also remove UpdateFunction which was unused


Modified:
   trunk/gnome-panel/ChangeLog
   trunk/gnome-panel/launcher.c
   trunk/gnome-panel/launcher.h
   trunk/gnome-panel/panel-util.c
   trunk/gnome-panel/panel-util.h

Modified: trunk/gnome-panel/launcher.c
==============================================================================
--- trunk/gnome-panel/launcher.c	(original)
+++ trunk/gnome-panel/launcher.c	Tue Dec  9 19:21:01 2008
@@ -20,7 +20,6 @@
 
 #include <glib/gi18n.h>
 #include <gio/gio.h>
-#include <libgnome/gnome-util.h>
 #include <gdk/gdkx.h>
 
 #include <libpanel-util/panel-error.h>
@@ -96,61 +95,6 @@
 			  launcher);
 }
 
-static GFile *
-panel_launcher_get_gfile (const char *location)
-{
-	char  *path;
-	GFile *file;
-
-	if (!g_ascii_strncasecmp (location, "file:", strlen ("file:")))
-		return g_file_new_for_uri (location);
-
-	if (g_path_is_absolute (location))
-		return g_file_new_for_path (location);
-
-	path = panel_make_full_path (NULL, location);
-	file = g_file_new_for_path (path);
-	g_free (path);
-
-	return file;
-}
-
-static char *
-panel_launcher_get_uri (const char *location)
-{
-	char *path;
-	char *uri;
-
-	if (!g_ascii_strncasecmp (location, "file:", strlen ("file:")))
-		return g_strdup (location);
-
-	if (!g_path_is_absolute (location))
-		path = panel_make_full_path (NULL, location);
-	else
-		path = g_strdup (location);
-
-	uri = g_filename_to_uri (path, NULL, NULL);
-	g_free (path);
-
-	return uri;
-}
-
-static const char *
-panel_launcher_get_filename (const char *location)
-{
-	char *p;
-
-	if (!g_path_is_absolute (location) &&
-	    g_ascii_strncasecmp (location, "file:", strlen ("file:")))
-		/* this is not a local URI */
-		return NULL;
-
-	if ((p = strstr (location, PANEL_LAUNCHERS_PATH)))
-		p += sizeof (PANEL_LAUNCHERS_PATH);
-
-	return p;
-}
-
 static void
 launch_url (Launcher *launcher)
 {
@@ -331,22 +275,15 @@
 void
 panel_launcher_delete (Launcher *launcher)
 {
-	GFile *file;
-	GFile *launchers;
-	char  *launchers_path;
-
 	if (!launcher->location)
 		return;
 
-	launchers_path = gnome_util_home_file (PANEL_LAUNCHERS_PATH);
-	launchers = g_file_new_for_path (launchers_path);
-	g_free (launchers_path);
-
-	file = panel_launcher_get_gfile (launcher->location);
-
 	/* do not remove the file if it's not in the user's launchers path */
-	if (g_file_has_prefix (file, launchers)) {
+	if (panel_launcher_is_in_personal_path (launcher->location)) {
 		GError *error;
+		GFile  *file;
+
+		file = panel_launcher_get_gfile (launcher->location);
 
 		error = NULL;
 		if (!g_file_delete (file, NULL, &error)) {
@@ -358,10 +295,9 @@
 			g_free (path);
 			g_error_free (error);
 		}
-	}
 
-	g_object_unref (file);
-	g_object_unref (launchers);
+		g_object_unref (file);
+	}
 }
 
 static gboolean

Modified: trunk/gnome-panel/launcher.h
==============================================================================
--- trunk/gnome-panel/launcher.h	(original)
+++ trunk/gnome-panel/launcher.h	Tue Dec  9 19:21:01 2008
@@ -16,8 +16,6 @@
 
 G_BEGIN_DECLS
 
-#define PANEL_LAUNCHERS_PATH "panel2.d/default/launchers"
-
 typedef struct {
 	AppletInfo        *info;
 	GtkWidget         *button;

Modified: trunk/gnome-panel/panel-util.c
==============================================================================
--- trunk/gnome-panel/panel-util.c	(original)
+++ trunk/gnome-panel/panel-util.c	Tue Dec  9 19:21:01 2008
@@ -17,6 +17,7 @@
 #include "panel-util.h"
 
 #include <dirent.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -28,7 +29,6 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include <libgnome/gnome-desktop-item.h>
-#include <libgnome/gnome-util.h>
 #include <libgnomeui/gnome-help.h>
 
 #include <libpanel-util/panel-error.h>
@@ -727,6 +727,106 @@
 }
 
 
+#define PANEL_LAUNCHER_PERSONAL_PATH "panel2.d/default/launchers"
+
+static char *
+panel_launcher_get_personal_path (void)
+{
+	return g_build_filename (g_get_home_dir (), ".gnome2",
+				 PANEL_LAUNCHER_PERSONAL_PATH, NULL);
+}
+
+gboolean
+panel_launcher_is_in_personal_path (const char *location)
+{
+	GFile    *file;
+	GFile    *launchers_dir;
+	char     *launchers_path;
+	gboolean  retval;
+
+	if (!location)
+		return FALSE;
+
+	launchers_path = panel_launcher_get_personal_path ();
+	launchers_dir = g_file_new_for_path (launchers_path);
+	g_free (launchers_path);
+
+	file = panel_launcher_get_gfile (location);
+
+	retval = g_file_has_prefix (file, launchers_dir);
+
+	g_object_unref (file);
+	g_object_unref (launchers_dir);
+
+	return retval;
+}
+
+GFile *
+panel_launcher_get_gfile (const char *location)
+{
+	char  *path;
+	GFile *file;
+
+	if (!g_ascii_strncasecmp (location, "file:", strlen ("file:")))
+		return g_file_new_for_uri (location);
+
+	if (g_path_is_absolute (location))
+		return g_file_new_for_path (location);
+
+	path = panel_make_full_path (NULL, location);
+	file = g_file_new_for_path (path);
+	g_free (path);
+
+	return file;
+}
+
+char *
+panel_launcher_get_uri (const char *location)
+{
+	char *path;
+	char *uri;
+
+	if (!g_ascii_strncasecmp (location, "file:", strlen ("file:")))
+		return g_strdup (location);
+
+	if (!g_path_is_absolute (location))
+		path = panel_make_full_path (NULL, location);
+	else
+		path = g_strdup (location);
+
+	uri = g_filename_to_uri (path, NULL, NULL);
+	g_free (path);
+
+	return uri;
+}
+
+char *
+panel_launcher_get_filename (const char *location)
+{
+	GFile *file;
+	GFile *launchers_dir;
+	char  *launchers_path;
+	char  *retval;
+
+	if (!g_path_is_absolute (location) &&
+	    g_ascii_strncasecmp (location, "file:", strlen ("file:")))
+		/* this is not a local URI */
+		return NULL;
+
+	launchers_path = panel_launcher_get_personal_path ();
+	launchers_dir = g_file_new_for_path (launchers_path);
+	g_free (launchers_path);
+
+	file = panel_launcher_get_gfile (location);
+
+	retval = g_file_get_relative_path (launchers_dir, file);
+
+	g_object_unref (file);
+	g_object_unref (launchers_dir);
+
+	return retval;
+}
+
 char *
 panel_make_full_path (const char *dir,
 		      const char *filename)
@@ -737,7 +837,7 @@
 	g_return_val_if_fail (filename != NULL, NULL);
 
 	if (!dir) {
-		freeme = gnome_util_home_file (PANEL_LAUNCHERS_PATH);
+		freeme = panel_launcher_get_personal_path ();
 		dir = freeme;
 	}
 

Modified: trunk/gnome-panel/panel-util.h
==============================================================================
--- trunk/gnome-panel/panel-util.h	(original)
+++ trunk/gnome-panel/panel-util.h	Tue Dec  9 19:21:01 2008
@@ -6,8 +6,6 @@
 
 G_BEGIN_DECLS
 
-typedef void (*UpdateFunction) (gpointer);
-
 #define		sure_string(s)		((const char *)((s)!=NULL?(s):""))
 
 void            panel_util_launch_from_key_file (GKeyFile                *keyfile,
@@ -69,6 +67,11 @@
 					 int            desired_height,
 					 char         **error_msg);
 
+GFile      *panel_launcher_get_gfile           (const char *location);
+char       *panel_launcher_get_uri             (const char *location);
+char       *panel_launcher_get_filename        (const char *location);
+gboolean    panel_launcher_is_in_personal_path (const char *location);
+
 char *panel_make_full_path   (const char *dir,
 			      const char *filename);
 char *panel_make_unique_desktop_path_from_name (const char *dir,



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