summaryrefslogtreecommitdiffstats
path: root/preferred-apps.patch
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@fedoraproject.org>2007-09-06 16:59:35 +0000
committerMatthias Clasen <mclasen@fedoraproject.org>2007-09-06 16:59:35 +0000
commitadb8fd2f3b45ea9be616686229df78dc936509f6 (patch)
treeb2bd556f6e351efa232d919a633f56ad033e0669 /preferred-apps.patch
parentb6b876425a293962a99f64cfea524752adff1c7b (diff)
downloadgnome-panel-adb8fd2f3b45ea9be616686229df78dc936509f6.tar.gz
gnome-panel-adb8fd2f3b45ea9be616686229df78dc936509f6.tar.xz
gnome-panel-adb8fd2f3b45ea9be616686229df78dc936509f6.zip
Diffstat (limited to 'preferred-apps.patch')
-rw-r--r--preferred-apps.patch240
1 files changed, 240 insertions, 0 deletions
diff --git a/preferred-apps.patch b/preferred-apps.patch
new file mode 100644
index 0000000..0bff680
--- /dev/null
+++ b/preferred-apps.patch
@@ -0,0 +1,240 @@
+diff -up gnome-panel-2.19.6/gnome-panel/main.c.preferred-apps gnome-panel-2.19.6/gnome-panel/main.c
+--- gnome-panel-2.19.6/gnome-panel/main.c.preferred-apps 2007-08-28 01:01:57.000000000 -0400
++++ gnome-panel-2.19.6/gnome-panel/main.c 2007-08-28 01:02:42.000000000 -0400
+@@ -26,6 +26,7 @@
+ #include "panel-action-protocol.h"
+ #include "panel-lockdown.h"
+ #include "panel-icon-names.h"
++#include "launcher.h"
+ #include "xstuff.h"
+
+ #include "nothing.cP"
+@@ -81,6 +82,7 @@ main (int argc, char **argv)
+ GCONF_CLIENT_PRELOAD_NONE,
+ NULL);
+
++ panel_preferred_apps_init ();
+ panel_global_config_load ();
+ panel_lockdown_init ();
+ panel_profile_load ();
+diff -up gnome-panel-2.19.6/gnome-panel/launcher.c.preferred-apps gnome-panel-2.19.6/gnome-panel/launcher.c
+--- gnome-panel-2.19.6/gnome-panel/launcher.c.preferred-apps 2007-08-28 00:49:14.000000000 -0400
++++ gnome-panel-2.19.6/gnome-panel/launcher.c 2007-08-28 01:01:47.000000000 -0400
+@@ -22,6 +22,7 @@
+ #include <libgnomeui/gnome-url.h>
+ #include <libgnomevfs/gnome-vfs.h>
+ #include <gdk/gdkx.h>
++#include <gmenu-tree.h>
+
+ #include "launcher.h"
+
+@@ -39,6 +40,7 @@
+ #include "panel-compatibility.h"
+ #include "panel-ditem-editor.h"
+ #include "panel-icon-names.h"
++#include "panel-run-dialog.h"
+
+ static GdkScreen *
+ launcher_get_screen (Launcher *launcher)
+@@ -1264,3 +1266,166 @@ panel_launcher_set_dnd_enabled (Launcher
+ } else
+ gtk_drag_source_unset (launcher->button);
+ }
++
++static gchar *
++find_desktop_file_from_exec (const gchar *exec)
++{
++ GSList *all_applications, *l;
++ gchar *path = NULL;
++ gchar **tokens, **tokens2;
++ gint i, match = 0;
++
++ /* FIXME no need to construct a humongous list here */
++ all_applications = get_all_applications ();
++
++ for (l = all_applications; l; l = l->next) {
++ GMenuTreeEntry *entry = l->data;
++ const char *entry_exec;
++
++ entry_exec = gmenu_tree_entry_get_exec (entry);
++
++ if (strcmp (exec, entry_exec) == 0) {
++ path = gmenu_tree_entry_get_desktop_file_path (entry);
++ break;
++ }
++
++ tokens = g_strsplit (exec, " ", -1);
++ tokens2 = g_strsplit (entry_exec, " ", -1);
++
++ for (i = 0; tokens[i] && tokens2[i]; i++) {
++ if (strcmp (tokens[i], tokens2[i]) != 0)
++ break;
++ }
++ if (i > match) {
++ match = i;
++ path = gmenu_tree_entry_get_desktop_file_path (entry);
++ }
++
++ g_strfreev (tokens);
++ g_strfreev (tokens2);
++ }
++
++ path = g_strdup (path);
++ g_slist_free (all_applications);
++
++ return path;
++}
++
++static void
++update_preferred_app (const gchar *filename,
++ const gchar *key,
++ const gchar *exec)
++{
++ gchar *location;
++ GKeyFile *key_file;
++ GError *error = NULL;
++ gchar *data;
++ gsize len;
++ gboolean needs_terminal;
++
++ location = find_desktop_file_from_exec (exec);
++ key_file = g_key_file_new ();
++ if (!panel_util_key_file_load_from_uri (key_file, location,
++ G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
++ NULL)) {
++ /* FIXME would be much better if preferred apps were backed by desktop files */
++ g_key_file_set_string (key_file, "Desktop Entry", "Version", "1.0");
++ g_key_file_set_string (key_file, "Desktop Entry", "Encoding", "UTF-8");
++ g_key_file_set_string (key_file, "Desktop Entry", "Type", "Application");
++ g_key_file_set_string (key_file, "Desktop Entry", "Exec", exec);
++ if (strstr (key, "http")) {
++ g_key_file_set_string (key_file, "Desktop Entry", "Name", "Preferred Web Browser");
++ g_key_file_set_string (key_file, "Desktop Entry", "GenericName", "Web Browser");
++ g_key_file_set_string (key_file, "Desktop Entry", "Comment", "Browse the Web");
++ g_key_file_set_string (key_file, "Desktop Entry", "Icon", "redhat-web-browser.png");
++ }
++ else if (strstr (key, "mailto")) {
++ g_key_file_set_string (key_file, "Desktop Entry", "Name", "Preferred Mail Reader");
++ g_key_file_set_string (key_file, "Desktop Entry", "GenericName", "Mail Reader");
++ g_key_file_set_string (key_file, "Desktop Entry", "Comment", "Send email");
++ g_key_file_set_string (key_file, "Desktop Entry", "Icon", "redhat-email.png");
++ }
++ if (g_str_has_suffix (key, "command")) {
++ int len;
++ char *key2;
++
++ len = strlen (key);
++ key2 = g_new (char, len - strlen ("command") + strlen ("needs_terminal") + 1);
++ strncpy (key2, key, len - strlen ("command"));
++ strcpy (key2 + len - strlen ("command"), "needs_terminal");
++ needs_terminal = gconf_client_get_bool (panel_gconf_get_client (),
++ key2,
++ NULL);
++ g_free (key2);
++ }
++ else
++ needs_terminal = FALSE;
++ g_key_file_set_boolean (key_file, "Desktop Entry", "Terminal", needs_terminal);
++ }
++
++ g_free (location);
++
++ g_key_file_set_boolean (key_file, "Desktop Entry", "X-Panel-Monitor", TRUE);
++ g_key_file_set_boolean (key_file, "Desktop Entry", "NoDisplay", TRUE);
++
++ data = g_key_file_to_data (key_file, &len, &error);
++ if (error) {
++ g_printerr (_("Failed to convert data for '%s': %s"),
++ filename, error->message);
++ g_error_free (error);
++ g_key_file_free (key_file);
++
++ return;
++ }
++ if (!g_file_set_contents (filename, data, len, &error)) {
++ g_printerr (_("Failed to save '%s': %s"),
++ filename, error->message);
++ g_error_free (error);
++ }
++
++ g_key_file_free (key_file);
++ g_free (data);
++}
++
++static void
++preferred_app_changed (GConfClient *client,
++ gint notify_id,
++ GConfEntry *entry,
++ const gchar *filename)
++{
++ update_preferred_app (filename,
++ gconf_entry_get_key (entry),
++ gconf_value_get_string (entry->value));
++}
++
++void
++panel_preferred_apps_init (void)
++{
++ GConfClient *client;
++ gchar *filename, *exec;
++ gint i;
++
++ const gchar *keys[] = {
++ "/desktop/gnome/url-handlers/http/command",
++ "/desktop/gnome/url-handlers/mailto/command",
++ NULL };
++ const gchar *files[] = {
++ "preferred-web-browser.desktop",
++ "preferred-mail-reader.desktop",
++ NULL };
++
++ client = panel_gconf_get_client ();
++
++ for (i = 0; keys[i]; i++) {
++ filename = g_build_filename (g_get_user_data_dir (),
++ "applications", files[i], NULL);
++ if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
++ exec = gconf_client_get_string (client, keys[i], NULL);
++ update_preferred_app (filename, keys[i], exec);
++ g_free (exec);
++ }
++ gconf_client_notify_add (client, keys[i],
++ (GConfClientNotifyFunc) preferred_app_changed,
++ filename, g_free, NULL);
++ }
++}
+diff -up gnome-panel-2.19.6/gnome-panel/launcher.h.preferred-apps gnome-panel-2.19.6/gnome-panel/launcher.h
+--- gnome-panel-2.19.6/gnome-panel/launcher.h.preferred-apps 2007-08-28 00:46:47.000000000 -0400
++++ gnome-panel-2.19.6/gnome-panel/launcher.h 2007-08-28 00:47:10.000000000 -0400
+@@ -75,6 +75,7 @@ void launcher_properties_dest
+ void panel_launcher_set_dnd_enabled (Launcher *launcher,
+ gboolean dnd_enabled);
+
++void panel_preferred_apps_init (void);
+
+ G_END_DECLS
+
+diff -up gnome-panel-2.19.6/gnome-panel/panel-run-dialog.h.preferred-apps gnome-panel-2.19.6/gnome-panel/panel-run-dialog.h
+--- gnome-panel-2.19.6/gnome-panel/panel-run-dialog.h.preferred-apps 2007-08-28 00:48:11.000000000 -0400
++++ gnome-panel-2.19.6/gnome-panel/panel-run-dialog.h 2007-08-28 00:48:34.000000000 -0400
+@@ -32,6 +32,8 @@ G_BEGIN_DECLS
+ void panel_run_dialog_present (GdkScreen *screen,
+ guint32 activate_time);
+
++GSList *get_all_applications (void);
++
+ G_END_DECLS
+
+ #endif /* __PANEL_RUN_DIALOG_H__ */
+diff -up gnome-panel-2.19.6/gnome-panel/panel-run-dialog.c.preferred-apps gnome-panel-2.19.6/gnome-panel/panel-run-dialog.c
+--- gnome-panel-2.19.6/gnome-panel/panel-run-dialog.c.preferred-apps 2007-08-28 00:47:26.000000000 -0400
++++ gnome-panel-2.19.6/gnome-panel/panel-run-dialog.c 2007-08-28 00:47:51.000000000 -0400
+@@ -813,7 +813,7 @@ get_all_applications_from_dir (GMenuTree
+ return list;
+ }
+
+-static GSList *
++GSList *
+ get_all_applications (void)
+ {
+ GMenuTree *tree;