[Xfce4-commits] <xfce4-panel:devel> Move back to a launcher with filenames, not desktop id's.

Nick Schermer nick at xfce.org
Tue Aug 11 20:26:50 CEST 2009


Updating branch refs/heads/devel
         to 4f3dc438a8d5af0d042970cec503cff18197dd8e (commit)
       from d140008bd4fbb117c73f92f04b8fa5618f6d15e2 (commit)

commit 4f3dc438a8d5af0d042970cec503cff18197dd8e
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Feb 18 18:13:58 2009 +0100

    Move back to a launcher with filenames, not desktop id's.

 common/panel-private.h                 |   15 +++--
 libxfce4panel/xfce-panel-plugin.c      |    2 +-
 panel/panel-application.c              |    2 +-
 plugins/launcher/launcher-dialog.c     |   50 +++++++++++-----
 plugins/launcher/launcher-dialog.glade |   67 +++++++++++-----------
 plugins/launcher/launcher.c            |   97 +++++++++-----------------------
 plugins/launcher/launcher.h            |    3 +-
 7 files changed, 106 insertions(+), 130 deletions(-)

diff --git a/common/panel-private.h b/common/panel-private.h
index 17e9ced..caebebe 100644
--- a/common/panel-private.h
+++ b/common/panel-private.h
@@ -21,17 +21,20 @@
 #define __PANEL_PRIVATE_H__
 
 /* handling flags */
-#define PANEL_SET_FLAG(flags,flag)   G_STMT_START{ ((flags) |= (flag)); }G_STMT_END
+#define PANEL_SET_FLAG(flags,flag) G_STMT_START{ ((flags) |= (flag)); }G_STMT_END
 #define PANEL_UNSET_FLAG(flags,flag) G_STMT_START{ ((flags) &= ~(flag)); }G_STMT_END
-#define PANEL_HAS_FLAG(flags,flag)   (((flags) & (flag)) != 0)
+#define PANEL_HAS_FLAG(flags,flag) (((flags) & (flag)) != 0)
 
 /* check if the string is not empty */
-#define IS_STRING(string)            ((string) != NULL && *(string) != '\0')
+#define IS_STRING(string) ((string) != NULL && *(string) != '\0')
 
-/* relative plugin filename (printf format) */
-#define PANEL_PLUGIN_RELATIVE_PATH   "xfce4" G_DIR_SEPARATOR_S "panel" G_DIR_SEPARATOR_S "%s-%d.rc"
+/* relative path to the plugin directory */
+#define PANEL_PLUGIN_RELATIVE_PATH "xfce4" G_DIR_SEPARATOR_S "panel"
+
+/* relative plugin's rc filename (printf format) */
+#define PANEL_PLUGIN_RC_RELATIVE_PATH PANEL_PLUGIN_RELATIVE_PATH G_DIR_SEPARATOR_S "%s-%d.rc"
 
 /* xfconf property base (printf format) */
-#define PANEL_PLUGIN_PROPERTY_BASE   "/plugins/plugin-%d"
+#define PANEL_PLUGIN_PROPERTY_BASE "/plugins/plugin-%d"
 
 #endif /* !__PANEL_PRIVATE_H__ */
\ No newline at end of file
diff --git a/libxfce4panel/xfce-panel-plugin.c b/libxfce4panel/xfce-panel-plugin.c
index af09909..989e782 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -843,7 +843,7 @@ xfce_panel_plugin_relative_filename (XfcePanelPlugin *plugin)
   panel_return_val_if_fail (xfce_panel_plugin_get_unique_id (plugin) != -1, NULL);
 
   /* return the relative configuration filename */
-  return g_strdup_printf (PANEL_PLUGIN_RELATIVE_PATH,
+  return g_strdup_printf (PANEL_PLUGIN_RC_RELATIVE_PATH,
                           plugin->priv->name, plugin->priv->unique_id);
 }
 
diff --git a/panel/panel-application.c b/panel/panel-application.c
index e79a14a..443a681 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -401,7 +401,7 @@ panel_application_plugin_provider_signal (XfcePanelPluginProvider       *provide
                                     xfce_panel_plugin_provider_get_unique_id (provider));
 
         /* build the plugin rc filename */
-        filename = g_strdup_printf (PANEL_PLUGIN_RELATIVE_PATH,
+        filename = g_strdup_printf (PANEL_PLUGIN_RC_RELATIVE_PATH,
                                     xfce_panel_plugin_provider_get_name (provider),
                                     xfce_panel_plugin_provider_get_unique_id (provider));
 
diff --git a/plugins/launcher/launcher-dialog.c b/plugins/launcher/launcher-dialog.c
index 89656d6..9db1543 100644
--- a/plugins/launcher/launcher-dialog.c
+++ b/plugins/launcher/launcher-dialog.c
@@ -167,19 +167,39 @@ launcher_dialog_add_populate_model_idle (gpointer user_data)
 {
   LauncherPluginDialog *dialog = user_data;
   GObject              *store;
-  XfceMenuItemPool     *pool;
+  XfceMenu             *menu;
+  GError               *error = NULL;
 
   panel_return_val_if_fail (GTK_IS_BUILDER (dialog->builder), FALSE);
 
   GDK_THREADS_ENTER ();
-
-  /* start appending items in the store */
-  store = gtk_builder_get_object (dialog->builder, "add-store");
-
-  /* get the item cache and insert everything in the store */
-  pool = launcher_plugin_get_item_pool (dialog->plugin);
-  xfce_menu_item_pool_foreach (pool,
-      launcher_dialog_add_store_insert, store);
+  
+  /* initialize the menu library */
+  xfce_menu_init (NULL);
+  
+  /* load our menu file */
+  menu = xfce_menu_new (SYSCONFDIR "/xdg/menus/launcher.menu", &error);
+  if (G_UNLIKELY (menu != NULL))
+    {
+      /* start appending items in the store */
+      store = gtk_builder_get_object (dialog->builder, "add-store");
+
+      /* get the item pool and insert everything in the store */
+      xfce_menu_item_pool_foreach (xfce_menu_get_item_pool (menu),
+                                   launcher_dialog_add_store_insert,
+                                   store);
+          
+      /* release the menu */
+      g_object_unref (G_OBJECT (menu));
+    }
+  else
+    {
+      /* TODO */
+      g_error_free (error);
+    }
+      
+  /* shutdown menu library */
+  xfce_menu_shutdown ();
 
   GDK_THREADS_LEAVE ();
 
@@ -251,7 +271,7 @@ launcher_dialog_tree_save_foreach (GtkTreeModel *model,
       /* create a value with the filename */
       value = g_new0 (GValue, 1);
       g_value_init (value, G_TYPE_STRING);
-      g_value_set_static_string (value, xfce_menu_item_get_desktop_id (item));
+      g_value_set_static_string (value, xfce_menu_item_get_filename (item));
 
       /* put it in the array and release */
       g_ptr_array_add (array, value);
@@ -306,7 +326,7 @@ launcher_dialog_tree_selection_changed (GtkTreeSelection     *selection,
     }
 
   /* update the sensitivity of the buttons */
-  object = gtk_builder_get_object (dialog->builder, "item-remove");
+  object = gtk_builder_get_object (dialog->builder, "item-delete");
   gtk_widget_set_sensitive (GTK_WIDGET (object), !!(n_children > 0));
 
   object = gtk_builder_get_object (dialog->builder, "item-move-up");
@@ -356,14 +376,14 @@ launcher_dialog_item_button_clicked (GtkWidget            *button,
       if (!gtk_tree_selection_get_selected (selection, &model, &iter_a))
         return;
 
-      if (exo_str_is_equal (name, "item-remove"))
+      if (exo_str_is_equal (name, "item-delete"))
         {
           /* create question dialog */
           window = gtk_message_dialog_new (
               GTK_WINDOW (gtk_widget_get_toplevel (button)),
               GTK_DIALOG_DESTROY_WITH_PARENT,
               GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
-              _("Are you sure you want to remove\nthe selected item?"));
+              _("Are you sure you want to remove the selected item?"));
           gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (window),
               _("If you delete an item, it is permanently removed from the launcher."));
           gtk_dialog_add_buttons (GTK_DIALOG (window),
@@ -640,9 +660,9 @@ launcher_dialog_show (LauncherPlugin *plugin)
   GObject              *window, *object, *item;
   guint                 i;
   GtkTreeSelection     *selection;
-  const gchar          *button_names[] = { "item-add", "item-remove",
+  const gchar          *button_names[] = { "item-add", "item-delete",
                                            "item-move-up", "item-move-down",
-                                           "item-edit" };
+                                           "item-edit", "item-new" };
   LauncherPluginDialog *dialog;
 
   panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
diff --git a/plugins/launcher/launcher-dialog.glade b/plugins/launcher/launcher-dialog.glade
index a75c9c1..fcfcf36 100644
--- a/plugins/launcher/launcher-dialog.glade
+++ b/plugins/launcher/launcher-dialog.glade
@@ -168,7 +168,7 @@
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
-                            <property name="tooltip_text" translatable="yes">Add new item to the launcher</property>
+                            <property name="tooltip_text" translatable="yes">Add one or more existing items to the launcher</property>
                             <child>
                               <object class="GtkImage" id="image4">
                                 <property name="visible">True</property>
@@ -183,32 +183,50 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkButton" id="item-remove">
+                          <object class="GtkButton" id="item-new">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
-                            <property name="tooltip_text" translatable="yes">Remove currently selected item</property>
+                            <property name="tooltip_text" translatable="yes">Add a new empty item</property>
                             <child>
-                              <object class="GtkImage" id="image5">
+                              <object class="GtkImage" id="image10">
                                 <property name="visible">True</property>
-                                <property name="stock">gtk-remove</property>
+                                <property name="stock">gtk-new</property>
                                 <property name="icon-size">4</property>
                               </object>
                             </child>
                           </object>
                           <packing>
-                            <property name="expand">False</property>
                             <property name="position">3</property>
                           </packing>
                         </child>
                         <child>
+                          <object class="GtkButton" id="item-delete">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="tooltip_text" translatable="yes">Delete the currently selected item</property>
+                            <child>
+                              <object class="GtkImage" id="image9">
+                                <property name="visible">True</property>
+                                <property name="stock">gtk-delete</property>
+                                <property name="icon-size">4</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">4</property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkButton" id="item-edit">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
                             <property name="tooltip_text" translatable="yes">Edit the currently selected item</property>
                             <child>
-                              <object class="GtkImage" id="image6">
+                              <object class="GtkImage" id="image1">
                                 <property name="visible">True</property>
                                 <property name="stock">gtk-edit</property>
                                 <property name="icon-size">4</property>
@@ -217,7 +235,7 @@
                           </object>
                           <packing>
                             <property name="expand">False</property>
-                            <property name="position">4</property>
+                            <property name="position">5</property>
                           </packing>
                         </child>
                       </object>
@@ -305,6 +323,7 @@
                       <object class="GtkComboBox" id="arrow-position">
                         <property name="visible">True</property>
                         <property name="model">arrow-position-store</property>
+                        <property name="active">0</property>
                         <property name="button_sensitivity">on</property>
                         <child>
                           <object class="GtkCellRendererText" id="cellrenderertext1"/>
@@ -681,7 +700,7 @@
     <property name="icon_name">gtk-add</property>
     <property name="type_hint">normal</property>
     <property name="has_separator">False</property>
-    <property name="subtitle" translatable="yes">Add a new or custom launcher item</property>
+    <property name="subtitle" translatable="yes">Add one or more existing items to the launcher</property>
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox4">
         <property name="visible">True</property>
@@ -784,29 +803,15 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="button-custom">
-                <property name="label" translatable="yes">C_ustom</property>
-                <property name="visible">True</property>
-                <property name="sensitive">False</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="image">image1</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button7">
-                <property name="label" translatable="yes">gtk-cancel</property>
+              <object class="GtkButton" id="button5">
+                <property name="label" translatable="yes">gtk-close</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
-                <property name="position">2</property>
+                <property name="position">1</property>
               </packing>
             </child>
           </object>
@@ -819,14 +824,8 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="2">button-add</action-widget>
-      <action-widget response="3">button-custom</action-widget>
-      <action-widget response="0">button7</action-widget>
+      <action-widget response="1">button-add</action-widget>
+      <action-widget response="0">button5</action-widget>
     </action-widgets>
   </object>
-  <object class="GtkImage" id="image1">
-    <property name="visible">True</property>
-    <property name="stock">gtk-new</property>
-    <property name="icon-size">4</property>
-  </object>
 </interface>
diff --git a/plugins/launcher/launcher.c b/plugins/launcher/launcher.c
index 674cfad..f1de1e1 100644
--- a/plugins/launcher/launcher.c
+++ b/plugins/launcher/launcher.c
@@ -81,9 +81,6 @@ struct _LauncherPlugin
   guint      disable_tooltips : 1;
 };
 
-/* shared root menu for all the launchers */
-static XfceMenu *root_menu = NULL;
-
 
 
 G_DEFINE_TYPE (LauncherPlugin, launcher_plugin, XFCE_TYPE_PANEL_PLUGIN);
@@ -115,37 +112,11 @@ launcher_plugin_class_init (LauncherPluginClass *klass)
 static void
 launcher_plugin_init (LauncherPlugin *plugin)
 {
-  GError *error;
-
   /* initialize xfconf */
   xfconf_init (NULL);
 
   /* show the configure menu item */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
-
-  /* initialize the menu library */
-  xfce_menu_init (NULL);
-
-  if (root_menu == NULL)
-    {
-      /* get the launcher menu */
-      root_menu = xfce_menu_new (SYSCONFDIR "/xdg/menus/launcher.menu", &error);
-      if (G_UNLIKELY (root_menu != NULL))
-        {
-          g_object_add_weak_pointer (G_OBJECT (root_menu), (gpointer) &root_menu);
-          g_message ("Loaded root menu");
-        }
-      else
-        {
-          g_critical ("Failed to load the root menu....");
-          g_error_free (error);
-        }
-    }
-  else
-    {
-      /* take a reference */
-      g_object_ref (G_OBJECT (root_menu));
-    }
 }
 
 
@@ -185,7 +156,7 @@ static void
 launcher_plugin_construct (XfcePanelPlugin *panel_plugin)
 {
   LauncherPlugin *plugin = XFCE_LAUNCHER_PLUGIN (panel_plugin);
-  GtkWidget     *widget;
+  GtkWidget      *widget;
 
   /* open the xfconf channel */
   plugin->channel = xfce_panel_plugin_xfconf_channel_new (panel_plugin);
@@ -262,12 +233,6 @@ launcher_plugin_free_data (XfcePanelPlugin *panel_plugin)
   /* free items */
   g_slist_foreach (plugin->items, (GFunc) g_object_unref, NULL);
   g_slist_free (plugin->items);
-
-  /* release the root menu */
-  g_object_unref (G_OBJECT (root_menu));
-
-  /* shutdown menu library */
-  xfce_menu_shutdown ();
 }
 
 
@@ -296,7 +261,7 @@ static void
 launcher_plugin_save (XfcePanelPlugin *panel_plugin)
 {
   LauncherPlugin  *plugin = XFCE_LAUNCHER_PLUGIN (panel_plugin);
-  gchar          **desktop_ids;
+  gchar          **filenames;
   guint            i, length;
   GSList          *li;
   XfceMenuItem    *item;
@@ -309,17 +274,17 @@ launcher_plugin_save (XfcePanelPlugin *panel_plugin)
   if (G_LIKELY (length > 0))
     {
       /* create the array with the desktop ids */
-      desktop_ids = g_new0 (gchar *, length + 1);
+      filenames = g_new0 (gchar *, length + 1);
       for (li = plugin->items, i = 0; li != NULL; li = li->next)
         if (G_LIKELY ((item = li->data) != NULL))
-          desktop_ids[i++] = (gchar *) xfce_menu_item_get_desktop_id (item);
+          filenames[i++] = (gchar *) xfce_menu_item_get_filename (item);
 
       /* store the list of filenames */
       xfconf_channel_set_string_list (plugin->channel, "/items",
-                                      (const gchar **) desktop_ids);
+                                      (const gchar **) filenames);
 
       /* cleanup */
-      g_free (desktop_ids);
+      g_free (filenames);
     }
 }
 
@@ -444,8 +409,9 @@ launcher_plugin_button_query_tooltip (GtkWidget      *widget,
   panel_return_val_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin), FALSE);
 
   /* check if we show tooltips */
-  if (plugin->disable_tooltips ||
-      plugin->items == NULL || plugin->items->data == NULL)
+  if (plugin->disable_tooltips
+      || plugin->items == NULL
+      || plugin->items->data == NULL)
     return FALSE;
 
   return launcher_plugin_item_query_tooltip (widget, x, y, keyboard_mode,
@@ -475,32 +441,30 @@ launcher_plugin_button_drag_data_received (GtkWidget        *widget,
 static void
 launcher_plugin_items_load (LauncherPlugin *plugin)
 {
-  gchar            **desktop_ids;
-  guint              i;
-  XfceMenuItem      *item;
-  XfceMenuItemPool  *pool;
+  gchar        **filenames;
+  guint          i;
+  XfceMenuItem  *item;
 
   panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
   panel_return_if_fail (plugin->items == NULL);
 
   /* get the list of launcher filenames */
-  desktop_ids = xfconf_channel_get_string_list (plugin->channel, "/items");
-  if (G_LIKELY (desktop_ids != NULL))
+  filenames = xfconf_channel_get_string_list (plugin->channel, "/items");
+  if (G_LIKELY (filenames != NULL))
     {
-      /* get the menu item pool */
-      pool = launcher_plugin_get_item_pool (plugin);
-
       /* try to load all the items */
-      for (i = 0; desktop_ids[i] != NULL; i++)
+      for (i = 0; filenames[i] != NULL; i++)
         {
-          item = xfce_menu_item_pool_lookup (pool, desktop_ids[i]);
+          /* create a new item from the file */
+          item = xfce_menu_item_new (filenames[i]);
           if (G_LIKELY (item != NULL))
-            plugin->items = g_slist_append (plugin->items,
-                                            g_object_ref (G_OBJECT (item)));
+            plugin->items = g_slist_append (plugin->items, item);
+          else
+            g_message ("Lookup the item in the pool...");
         }
 
       /* cleanup */
-      g_strfreev (desktop_ids);
+      g_strfreev (filenames);
     }
 }
 
@@ -577,7 +541,7 @@ launcher_plugin_item_exec_on_screen (XfceMenuItem *item,
 
   if (G_UNLIKELY (succeed == FALSE))
     {
-      /* TODO */
+      /* TODO make this some nice error dialog */
       g_message ("Failed to launch.... (%s)", error->message);
       g_error_free (error);
     }
@@ -699,7 +663,7 @@ launcher_plugin_exec_parse (XfceMenuItem   *item,
                     if (*p == 'f')
                       break;
                     if (li->next != NULL)
-                      g_string_insert_c (string, -1, ' ');
+                      g_string_append_c (string, ' ');
                   }
                 break;
 
@@ -713,7 +677,7 @@ launcher_plugin_exec_parse (XfceMenuItem   *item,
                     if (*p == 'u')
                       break;
                     if (li->next != NULL)
-                      g_string_insert_c (string, -1, ' ');
+                      g_string_append_c (string, ' ');
                   }
                 break;
 
@@ -739,13 +703,13 @@ launcher_plugin_exec_parse (XfceMenuItem   *item,
                 break;
 
               case '%':
-                g_string_insert_c (string, -1, '%');
+                g_string_append_c (string, '%');
                 break;
             }
         }
       else
         {
-          g_string_insert_c (string, -1, *p);
+          g_string_append_c (string, *p);
         }
     }
 
@@ -765,15 +729,6 @@ launcher_plugin_get_channel (LauncherPlugin *plugin)
 }
 
 
-XfceMenuItemPool *
-launcher_plugin_get_item_pool (LauncherPlugin *plugin)
-{
-  panel_return_val_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin), NULL);
-  panel_return_val_if_fail (XFCE_IS_MENU (root_menu), NULL);
-  return xfce_menu_get_item_pool (root_menu);
-}
-
-
 
 GSList *
 launcher_plugin_get_items (LauncherPlugin *plugin)
diff --git a/plugins/launcher/launcher.h b/plugins/launcher/launcher.h
index 5448e8d..cbe54ab 100644
--- a/plugins/launcher/launcher.h
+++ b/plugins/launcher/launcher.h
@@ -40,9 +40,8 @@ GType             launcher_plugin_get_type    (void) G_GNUC_CONST;
 
 XfconfChannel    *launcher_plugin_get_channel (LauncherPlugin *plugin);
 
-XfceMenuItemPool *launcher_plugin_get_item_pool (LauncherPlugin *plugin);
+GSList           *launcher_plugin_get_items   (LauncherPlugin *plugin);
 
-GSList           *launcher_plugin_get_items (LauncherPlugin *plugin);
 G_END_DECLS
 
 #endif /* !__LAUNCHER_H__ */



More information about the Xfce4-commits mailing list