[Xfce4-commits] <xfce4-panel:devel> Use XfceMenuItem's for all the internal items.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:26:49 CEST 2009
Updating branch refs/heads/devel
to d140008bd4fbb117c73f92f04b8fa5618f6d15e2 (commit)
from 4c1579e46196e3fa9b5736e2b0c28495ef386cbb (commit)
commit d140008bd4fbb117c73f92f04b8fa5618f6d15e2
Author: Nick Schermer <nick at xfce.org>
Date: Mon Feb 16 12:52:28 2009 +0100
Use XfceMenuItem's for all the internal items.
We use the XfceMenuItemPool to quickly lookup the desktop id's.
The advantage of this is that libxfce4menu does a lot of work for
us and since the desktop id's are stored, we're not fixed to the
file location, so we will pickup changes in
~/.local/share/applications too.
plugins/launcher/Makefile.am | 8 +
plugins/launcher/launcher-dialog.c | 268 ++++++++++------------
plugins/launcher/launcher-dialog.glade | 50 ++--
plugins/launcher/launcher.c | 399 ++++++++++++++++----------------
plugins/launcher/launcher.h | 8 +-
5 files changed, 361 insertions(+), 372 deletions(-)
diff --git a/plugins/launcher/Makefile.am b/plugins/launcher/Makefile.am
index 5feff27..b51eb91 100644
--- a/plugins/launcher/Makefile.am
+++ b/plugins/launcher/Makefile.am
@@ -3,6 +3,7 @@
INCLUDES = \
-I$(top_srcdir) \
-DBINDIR=\"$(bindir)\" \
+ -DSYSCONFDIR=\"$(sysconfdir)\" \
-DG_LOG_DOMAIN=\"liblauncher\" \
-DSN_API_NOT_YET_FROZEN \
-DEXO_API_SUBJECT_TO_CHANGE \
@@ -76,8 +77,15 @@ launcher.desktop.in: $(desktop_in_in_files)
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@
+#
+# .menu file
+#
+menudir = $(sysconfdir)/xdg/menus
+menu_DATA = launcher.menu
+
EXTRA_DIST = \
launcher-dialog.glade \
+ $(menu_DATA) \
$(desktop_in_in_files)
DISTCLEANFILES = \
diff --git a/plugins/launcher/launcher-dialog.c b/plugins/launcher/launcher-dialog.c
index 1e09630..89656d6 100644
--- a/plugins/launcher/launcher-dialog.c
+++ b/plugins/launcher/launcher-dialog.c
@@ -25,7 +25,6 @@
#include <exo/exo.h>
#include <libxfce4ui/libxfce4ui.h>
-#include <libxfce4menu/libxfce4menu.h>
#include <libxfce4util/libxfce4util.h>
#include <common/panel-private.h>
@@ -48,14 +47,14 @@ enum
{
COL_ICON,
COL_NAME,
- COL_FILENAME,
+ COL_ITEM,
COL_SEARCH
};
-static void launcher_dialog_entries_insert_item (GtkListStore *store, GtkTreeIter *iter, const gchar *filename);
-static void launcher_dialog_entries_changed (XfconfChannel *channel, const gchar *property_name, const GValue *value, LauncherPluginDialog *dialog);
+static void launcher_dialog_items_insert_item (GtkListStore *store, GtkTreeIter *iter, XfceMenuItem *item);
+static void launcher_dialog_items_changed (XfconfChannel *channel, const gchar *property_name, const GValue *value, LauncherPluginDialog *dialog);
@@ -71,7 +70,7 @@ launcher_dialog_add_visible_function (GtkTreeModel *model,
gchar *text_casefolded;
gchar *name_casefolded;
- /* get the search string from the entry */
+ /* get the search string from the item */
text = gtk_entry_get_text (GTK_ENTRY (user_data));
if (G_UNLIKELY (!IS_STRING (text)))
return TRUE;
@@ -134,8 +133,6 @@ launcher_dialog_add_store_insert (gpointer filename,
panel_return_if_fail (XFCE_IS_MENU_ITEM (item));
panel_return_if_fail (GTK_IS_LIST_STORE (user_data));
- panel_return_if_fail (exo_str_is_equal (xfce_menu_item_get_filename (item),
- (gchar *) filename));
/* TODO get rid of this and support absolute paths too */
icon_name = xfce_menu_item_get_icon_name (item);
@@ -157,7 +154,7 @@ launcher_dialog_add_store_insert (gpointer filename,
gtk_list_store_set (store, &iter,
COL_ICON, icon_name,
COL_NAME, markup,
- COL_FILENAME, (gchar *) filename,
+ COL_ITEM, item,
-1);
g_free (markup);
@@ -169,46 +166,23 @@ static gboolean
launcher_dialog_add_populate_model_idle (gpointer user_data)
{
LauncherPluginDialog *dialog = user_data;
- XfceMenu *root;
- GError *error = NULL;
GObject *store;
- XfceMenuItemCache *cache;
+ XfceMenuItemPool *pool;
panel_return_val_if_fail (GTK_IS_BUILDER (dialog->builder), FALSE);
- /* initialize the menu library */
- xfce_menu_init (NULL);
-
GDK_THREADS_ENTER ();
- /* get the root menu */
- root = xfce_menu_get_root (&error);
- if (G_LIKELY (root != NULL))
- {
- /* 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 */
- cache = xfce_menu_item_cache_get_default ();
- xfce_menu_item_cache_foreach (cache,
- launcher_dialog_add_store_insert, store);
+ /* start appending items in the store */
+ store = gtk_builder_get_object (dialog->builder, "add-store");
- /* release the root menu and cache */
- g_object_unref (G_OBJECT (root));
- g_object_unref (G_OBJECT (cache));
- }
- else
- {
- /* TODO make this a warning dialog or something */
- g_message ("Failed to load the root menu: %s", error->message);
- g_error_free (error);
- }
+ /* 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);
GDK_THREADS_LEAVE ();
- /* shutdown menu library */
- xfce_menu_shutdown ();
-
return FALSE;
}
@@ -266,20 +240,23 @@ launcher_dialog_tree_save_foreach (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data)
{
- GPtrArray *array = user_data;
- GValue *value;
- gchar *filename;
-
- /* get the filename of the entry from the store */
- gtk_tree_model_get (model, iter, COL_FILENAME, &filename, -1);
+ GPtrArray *array = user_data;
+ GValue *value;
+ XfceMenuItem *item;
- /* create a value with the filename */
- value = g_new0 (GValue, 1);
- g_value_init (value, G_TYPE_STRING);
- g_value_take_string (value, filename);
-
- /* put it in the array */
- g_ptr_array_add (array, value);
+ /* get the desktop id of the item from the store */
+ gtk_tree_model_get (model, iter, COL_ITEM, &item, -1);
+ if (G_LIKELY (item != NULL))
+ {
+ /* 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));
+
+ /* put it in the array and release */
+ g_ptr_array_add (array, value);
+ g_object_unref (G_OBJECT (item));
+ }
return FALSE;
}
@@ -292,12 +269,12 @@ launcher_dialog_tree_save (LauncherPluginDialog *dialog)
GObject *store;
GPtrArray *array;
- store = gtk_builder_get_object (dialog->builder, "entry-store");
+ store = gtk_builder_get_object (dialog->builder, "item-store");
array = g_ptr_array_new ();
gtk_tree_model_foreach (GTK_TREE_MODEL (store),
launcher_dialog_tree_save_foreach, array);
- xfconf_channel_set_arrayv (dialog->channel, "/entries", array);
+ xfconf_channel_set_arrayv (dialog->channel, "/items", array);
xfconf_array_free (array);
}
@@ -329,27 +306,27 @@ launcher_dialog_tree_selection_changed (GtkTreeSelection *selection,
}
/* update the sensitivity of the buttons */
- object = gtk_builder_get_object (dialog->builder, "entry-remove");
+ object = gtk_builder_get_object (dialog->builder, "item-remove");
gtk_widget_set_sensitive (GTK_WIDGET (object), !!(n_children > 0));
- object = gtk_builder_get_object (dialog->builder, "entry-move-up");
+ object = gtk_builder_get_object (dialog->builder, "item-move-up");
sensitive = !!(position > 0 && position <= n_children);
gtk_widget_set_sensitive (GTK_WIDGET (object), sensitive);
- object = gtk_builder_get_object (dialog->builder, "entry-move-down");
+ object = gtk_builder_get_object (dialog->builder, "item-move-down");
sensitive = !!(position >= 0 && position < n_children - 1);
gtk_widget_set_sensitive (GTK_WIDGET (object), sensitive);
- object = gtk_builder_get_object (dialog->builder, "entry-edit");
- sensitive = !!(position >= 0 && n_children > 0); /* TODO custom entries only */
+ object = gtk_builder_get_object (dialog->builder, "item-edit");
+ sensitive = !!(position >= 0 && n_children > 0); /* TODO custom items only */
gtk_widget_set_sensitive (GTK_WIDGET (object), sensitive);
}
static void
-launcher_dialog_entry_button_clicked (GtkWidget *button,
- LauncherPluginDialog *dialog)
+launcher_dialog_item_button_clicked (GtkWidget *button,
+ LauncherPluginDialog *dialog)
{
const gchar *name;
GObject *object;
@@ -365,7 +342,7 @@ launcher_dialog_entry_button_clicked (GtkWidget *button,
/* name of the button */
name = gtk_buildable_get_name (GTK_BUILDABLE (button));
- if (exo_str_is_equal (name, "entry-add"))
+ if (exo_str_is_equal (name, "item-add"))
{
object = gtk_builder_get_object (dialog->builder, "dialog-add");
launcher_dialog_add_populate_model (dialog);
@@ -374,12 +351,12 @@ launcher_dialog_entry_button_clicked (GtkWidget *button,
else
{
/* get the selected item in the tree, leave if none is found */
- treeview = gtk_builder_get_object (dialog->builder, "entry-treeview");
+ treeview = gtk_builder_get_object (dialog->builder, "item-treeview");
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
if (!gtk_tree_selection_get_selected (selection, &model, &iter_a))
return;
- if (exo_str_is_equal (name, "entry-remove"))
+ if (exo_str_is_equal (name, "item-remove"))
{
/* create question dialog */
window = gtk_message_dialog_new (
@@ -402,12 +379,12 @@ launcher_dialog_entry_button_clicked (GtkWidget *button,
/* destroy */
gtk_widget_destroy (window);
}
- else if (exo_str_is_equal (name, "entry-edit"))
+ else if (exo_str_is_equal (name, "item-edit"))
{
object = gtk_builder_get_object (dialog->builder, "dialog-editor");
gtk_widget_show (GTK_WIDGET (object));
}
- else if (exo_str_is_equal (name, "entry-move-up"))
+ else if (exo_str_is_equal (name, "item-move-up"))
{
path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter_a);
if (gtk_tree_path_prev (path)
@@ -417,7 +394,7 @@ launcher_dialog_entry_button_clicked (GtkWidget *button,
}
else
{
- panel_return_if_fail (exo_str_is_equal (name, "entry-move-down"));
+ panel_return_if_fail (exo_str_is_equal (name, "item-move-down"));
iter_b = iter_a;
if (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter_b))
gtk_list_store_swap (GTK_LIST_STORE (model), &iter_a, &iter_b);
@@ -458,7 +435,7 @@ launcher_dialog_response (GtkWidget *widget,
/* disconnect signal */
g_signal_handlers_disconnect_by_func (G_OBJECT (dialog->channel),
- launcher_dialog_entries_changed,
+ launcher_dialog_items_changed,
dialog);
/* unblock plugin menu */
@@ -492,9 +469,9 @@ launcher_dialog_add_response (GtkWidget *widget,
{
GObject *treeview, *store;
GtkTreeSelection *selection;
- GtkTreeModel *entry_model, *add_model;
+ GtkTreeModel *item_model, *add_model;
GtkTreeIter iter, sibling, tmp;
- gchar *filename;
+ XfceMenuItem *item;
GList *list, *li;
panel_return_if_fail (GTK_IS_DIALOG (widget));
@@ -507,35 +484,38 @@ launcher_dialog_add_response (GtkWidget *widget,
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
list = gtk_tree_selection_get_selected_rows (selection, &add_model);
- /* append after the selected item in the entry dialog */
- treeview = gtk_builder_get_object (dialog->builder, "entry-treeview");
+ /* append after the selected item in the item dialog */
+ treeview = gtk_builder_get_object (dialog->builder, "item-treeview");
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
- entry_model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
+ item_model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
if (gtk_tree_selection_get_selected (selection, NULL, &sibling))
- gtk_list_store_insert_after (GTK_LIST_STORE (entry_model),
+ gtk_list_store_insert_after (GTK_LIST_STORE (item_model),
&iter, &sibling);
else
- gtk_list_store_append (GTK_LIST_STORE (entry_model), &iter);
+ gtk_list_store_append (GTK_LIST_STORE (item_model), &iter);
for (li = list; li != NULL; li = g_list_next (li))
{
/* get the selected file in the add dialog */
gtk_tree_model_get_iter (add_model, &tmp, li->data);
- gtk_tree_model_get (add_model, &tmp, COL_FILENAME, &filename, -1);
+ gtk_tree_model_get (add_model, &tmp, COL_ITEM, &item, -1);
/* insert the item in the item store */
- launcher_dialog_entries_insert_item (GTK_LIST_STORE (entry_model),
- &iter, filename);
+ if (G_LIKELY (item != NULL))
+ {
+ launcher_dialog_items_insert_item (GTK_LIST_STORE (item_model),
+ &iter, item);
+ g_object_unref (G_OBJECT (item));
+ }
/* cleanup */
- g_free (filename);
gtk_tree_path_free (li->data);
if (g_list_next (li) != NULL)
{
/* insert a new iter after the new added item */
sibling = iter;
- gtk_list_store_insert_after (GTK_LIST_STORE (entry_model),
+ gtk_list_store_insert_after (GTK_LIST_STORE (item_model),
&iter, &sibling);
}
}
@@ -561,78 +541,70 @@ launcher_dialog_add_response (GtkWidget *widget,
static void
-launcher_dialog_entries_insert_item (GtkListStore *store,
- GtkTreeIter *iter,
- const gchar *filename)
+launcher_dialog_items_insert_item (GtkListStore *store,
+ GtkTreeIter *iter,
+ XfceMenuItem *item)
{
- XfceRc *rc;
- const gchar *icon, *name, *comment;
+ const gchar *name, *comment;
gchar *markup;
panel_return_if_fail (GTK_IS_LIST_STORE (store));
- panel_return_if_fail (IS_STRING (filename));
+ panel_return_if_fail (XFCE_IS_MENU_ITEM (item));
- rc = xfce_rc_simple_open (filename, TRUE);
- if (G_LIKELY (rc != NULL))
- {
- xfce_rc_set_group (rc, "Desktop Entry");
- icon = xfce_rc_read_entry_untranslated (rc, "Icon", NULL);
- name = xfce_rc_read_entry (rc, "Name", NULL);
- comment = xfce_rc_read_entry (rc, "Comment", NULL);
+ name = xfce_menu_item_get_name (item);
+ comment = xfce_menu_item_get_comment (item);
- if (IS_STRING (comment))
- markup = g_strdup_printf ("<b>%s</b>\n%s", name, comment);
- else
- markup = g_strdup_printf ("<b>%s</b>", name);
-
- gtk_list_store_set (GTK_LIST_STORE (store), iter,
- COL_ICON, icon,
- COL_NAME, markup,
- COL_FILENAME, filename,
- -1);
- xfce_rc_close (rc);
- g_free (markup);
- }
+ if (IS_STRING (comment))
+ markup = g_strdup_printf ("<b>%s</b>\n%s", name, comment);
+ else
+ markup = g_strdup_printf ("<b>%s</b>", name);
+
+ gtk_list_store_set (GTK_LIST_STORE (store), iter,
+ COL_ICON, xfce_menu_item_get_icon_name (item),
+ COL_NAME, markup,
+ COL_ITEM, item,
+ -1);
+
+ g_free (markup);
}
static void
-launcher_dialog_entries_changed (XfconfChannel *channel,
- const gchar *property_name,
- const GValue *value,
- LauncherPluginDialog *dialog)
+launcher_dialog_items_changed (XfconfChannel *channel,
+ const gchar *property_name,
+ const GValue *value,
+ LauncherPluginDialog *dialog)
{
- gchar **filenames;
- gchar *filename;
- guint i;
+ XfceMenuItem *item;
GObject *store;
+ GSList *items, *li;
+ gboolean update = TRUE;
GtkTreeIter iter;
- gboolean update = FALSE;
- gint n_children;
- /* only handle something when the entries changes */
- if (!exo_str_is_equal (property_name, "/entries"))
+ /* only do something when the items changed */
+ if (!exo_str_is_equal (property_name, "/items"))
return;
/* get the store and clear it */
- store = gtk_builder_get_object (dialog->builder, "entry-store");
+ store = gtk_builder_get_object (dialog->builder, "item-store");
- filenames = xfconf_channel_get_string_list (channel, "/entries");
- if (G_LIKELY (filenames != NULL))
+ items = launcher_plugin_get_items (dialog->plugin);
+ if (G_LIKELY (items != NULL))
{
- /* compare if the number of items is different */
- n_children = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
- update = g_strv_length (filenames) != (guint) n_children;
-
- /* if not, compare the model and the array if there are differences */
- if (!update && gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
{
- for (i = 0; filenames[i] != NULL; i++)
+ for (li = items; li != NULL; li = li->next)
{
- gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
- COL_FILENAME, &filename, -1);
- update = !exo_str_is_equal (filenames[i], filename);
+ gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_ITEM, &item, -1);
+ if (G_UNLIKELY (item == NULL))
+ break;
+
+ update = !exo_str_is_equal (xfce_menu_item_get_desktop_id (li->data),
+ xfce_menu_item_get_desktop_id (item));
+
+ g_object_unref (G_OBJECT (item));
+
if (G_UNLIKELY (update))
break;
@@ -644,15 +616,13 @@ launcher_dialog_entries_changed (XfconfChannel *channel,
if (update == TRUE)
{
gtk_list_store_clear (GTK_LIST_STORE (store));
- for (i = 0; update && filenames[i] != NULL; i++)
+ for (li = items; li != NULL; li = li->next)
{
gtk_list_store_append (GTK_LIST_STORE (store), &iter);
- launcher_dialog_entries_insert_item (GTK_LIST_STORE (store),
- &iter, filenames[i]);
+ launcher_dialog_items_insert_item (GTK_LIST_STORE (store),
+ &iter, XFCE_MENU_ITEM (li->data));
}
}
-
- g_strfreev (filenames);
}
else if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) > 0)
{
@@ -667,12 +637,12 @@ void
launcher_dialog_show (LauncherPlugin *plugin)
{
GtkBuilder *builder;
- GObject *window, *object, *entry;
+ GObject *window, *object, *item;
guint i;
GtkTreeSelection *selection;
- const gchar *entry_names[] = { "entry-add", "entry-remove",
- "entry-move-up", "entry-move-down",
- "entry-edit" };
+ const gchar *button_names[] = { "item-add", "item-remove",
+ "item-move-up", "item-move-down",
+ "item-edit" };
LauncherPluginDialog *dialog;
panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
@@ -689,7 +659,7 @@ launcher_dialog_show (LauncherPlugin *plugin)
/* monitor the channel for any changes */
g_signal_connect (G_OBJECT (dialog->channel), "property-changed",
- G_CALLBACK (launcher_dialog_entries_changed), dialog);
+ G_CALLBACK (launcher_dialog_items_changed), dialog);
/* block plugin menu */
xfce_panel_plugin_block_menu (XFCE_PANEL_PLUGIN (plugin));
@@ -700,16 +670,16 @@ launcher_dialog_show (LauncherPlugin *plugin)
g_signal_connect (G_OBJECT (window), "response",
G_CALLBACK (launcher_dialog_response), dialog);
- /* connect entry buttons */
- for (i = 0; i < G_N_ELEMENTS (entry_names); i++)
+ /* connect item buttons */
+ for (i = 0; i < G_N_ELEMENTS (button_names); i++)
{
- object = gtk_builder_get_object (builder, entry_names[i]);
+ object = gtk_builder_get_object (builder, button_names[i]);
g_signal_connect (G_OBJECT (object), "clicked",
- G_CALLBACK (launcher_dialog_entry_button_clicked), dialog);
+ G_CALLBACK (launcher_dialog_item_button_clicked), dialog);
}
/* setup treeview selection */
- object = gtk_builder_get_object (builder, "entry-treeview");
+ object = gtk_builder_get_object (builder, "item-treeview");
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (object));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
g_signal_connect (G_OBJECT (selection), "changed",
@@ -760,20 +730,20 @@ launcher_dialog_show (LauncherPlugin *plugin)
/* setup search filter in the add dialog */
object = gtk_builder_get_object (builder, "add-store-filter");
- entry = gtk_builder_get_object (builder, "add-search");
+ item = gtk_builder_get_object (builder, "add-search");
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (object),
- launcher_dialog_add_visible_function, entry, NULL);
- g_signal_connect_swapped (G_OBJECT (entry), "changed",
+ launcher_dialog_add_visible_function, item, NULL);
+ g_signal_connect_swapped (G_OBJECT (item), "changed",
G_CALLBACK (gtk_tree_model_filter_refilter), object);
/* setup the icon size in the icon renderers */
object = gtk_builder_get_object (builder, "addrenderericon");
g_object_set (G_OBJECT (object), "stock-size", GTK_ICON_SIZE_DND, NULL);
- object = gtk_builder_get_object (builder, "entryrenderericon");
+ object = gtk_builder_get_object (builder, "itemrenderericon");
g_object_set (G_OBJECT (object), "stock-size", GTK_ICON_SIZE_DND, NULL);
/* load the launchers */
- launcher_dialog_entries_changed (dialog->channel, "/entries", NULL, dialog);
+ launcher_dialog_items_changed (dialog->channel, "/items", NULL, dialog);
/* show the dialog */
gtk_widget_show (GTK_WIDGET (window));
diff --git a/plugins/launcher/launcher-dialog.glade b/plugins/launcher/launcher-dialog.glade
index aa79195..a75c9c1 100644
--- a/plugins/launcher/launcher-dialog.glade
+++ b/plugins/launcher/launcher-dialog.glade
@@ -35,20 +35,20 @@
<column type="gchararray"/>
<!-- column-name name -->
<column type="gchararray"/>
- <!-- column-name filename -->
- <column type="gchararray"/>
+ <!-- column-name item -->
+ <column type="GObject"/>
<!-- column-name search -->
<column type="gchararray"/>
</columns>
</object>
- <object class="GtkListStore" id="entry-store">
+ <object class="GtkListStore" id="item-store">
<columns>
<!-- column-name icon -->
<column type="gchararray"/>
<!-- column-name name -->
<column type="gchararray"/>
- <!-- column-name filename -->
- <column type="gchararray"/>
+ <!-- column-name item -->
+ <column type="GObject"/>
</columns>
</object>
<object class="GtkTreeModelFilter" id="add-store-filter">
@@ -83,10 +83,10 @@
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">etched-in</property>
<child>
- <object class="GtkTreeView" id="entry-treeview">
+ <object class="GtkTreeView" id="item-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="model">entry-store</property>
+ <property name="model">item-store</property>
<property name="headers_visible">False</property>
<property name="rules_hint">True</property>
<property name="enable_search">False</property>
@@ -94,13 +94,13 @@
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="spacing">2</property>
<child>
- <object class="GtkCellRendererPixbuf" id="entryrenderericon"/>
+ <object class="GtkCellRendererPixbuf" id="itemrenderericon"/>
<attributes>
<attribute name="icon-name">0</attribute>
</attributes>
</child>
<child>
- <object class="GtkCellRendererText" id="entryrenderername"/>
+ <object class="GtkCellRendererText" id="itemrenderername"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
@@ -126,7 +126,7 @@
<property name="spacing">6</property>
<property name="homogeneous">True</property>
<child>
- <object class="GtkButton" id="entry-move-up">
+ <object class="GtkButton" id="item-move-up">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -145,7 +145,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="entry-move-down">
+ <object class="GtkButton" id="item-move-down">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -164,7 +164,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="entry-add">
+ <object class="GtkButton" id="item-add">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -183,7 +183,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="entry-remove">
+ <object class="GtkButton" id="item-remove">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -202,7 +202,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="entry-edit">
+ <object class="GtkButton" id="item-edit">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -274,7 +274,7 @@
</child>
<child>
<object class="GtkCheckButton" id="move-first">
- <property name="label" translatable="yes">Show last _used entry in panel</property>
+ <property name="label" translatable="yes">Show last _used item in panel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -458,7 +458,7 @@
</packing>
</child>
<child>
- <object class="GtkEntry" id="entry-name">
+ <object class="GtkEntry" id="item-name">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
@@ -469,7 +469,7 @@
</packing>
</child>
<child>
- <object class="GtkEntry" id="entry-description">
+ <object class="GtkEntry" id="item-description">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
@@ -482,7 +482,7 @@
</packing>
</child>
<child>
- <object class="GtkFileChooserButton" id="entry-working-directory">
+ <object class="GtkFileChooserButton" id="item-working-directory">
<property name="visible">True</property>
<property name="action">select-folder</property>
<property name="title" translatable="yes">Select a Working Directory</property>
@@ -496,7 +496,7 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="entry-terminal">
+ <object class="GtkCheckButton" id="item-terminal">
<property name="label" translatable="yes">Run in _terminal</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -513,7 +513,7 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="entry-startup-notify">
+ <object class="GtkCheckButton" id="item-startup-notify">
<property name="label" translatable="yes">Use _statup notification</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -562,7 +562,7 @@
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
- <object class="GtkEntry" id="entry-command3">
+ <object class="GtkEntry" id="item-command">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
@@ -571,7 +571,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="entry-open3">
+ <object class="GtkButton" id="item-open">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -603,7 +603,7 @@
<property name="xalign">0</property>
<property name="xscale">0</property>
<child>
- <object class="GtkButton" id="entry-iconn">
+ <object class="GtkButton" id="item-icon">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -673,7 +673,7 @@
</action-widgets>
</object>
<object class="XfceTitledDialog" id="dialog-add">
- <property name="title" translatable="yes">Add New Entry</property>
+ <property name="title" translatable="yes">Add New Item</property>
<property name="window_position">center-on-parent</property>
<property name="default_width">400</property>
<property name="default_height">400</property>
@@ -681,7 +681,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 entry</property>
+ <property name="subtitle" translatable="yes">Add a new or custom launcher item</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox4">
<property name="visible">True</property>
diff --git a/plugins/launcher/launcher.c b/plugins/launcher/launcher.c
index af6763d..674cfad 100644
--- a/plugins/launcher/launcher.c
+++ b/plugins/launcher/launcher.c
@@ -49,16 +49,14 @@ static gboolean launcher_plugin_button_release_event (GtkWidget *button, GdkEven
static gboolean launcher_plugin_button_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, LauncherPlugin *plugin);
static void launcher_plugin_button_drag_data_received (GtkWidget *widget,GdkDragContext *context, gint x,gint y,GtkSelectionData *selection_data, guint info, guint drag_time, LauncherPlugin *plugin);
-static void launcher_plugin_entries_load (LauncherPlugin *plugin);
-static gboolean launcher_plugin_entry_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, LauncherEntry *entry);
-static LauncherEntry *launcher_plugin_entry_new_from_filename (const gchar *filename);
-static void launcher_plugin_entry_free (LauncherEntry *entry);
-
-static gboolean launcher_plugin_entry_exec_on_screen (LauncherEntry *entry, guint32 event_time, GdkScreen *screen, GSList *uri_list);
-static void launcher_plugin_entry_exec (LauncherEntry *entry, guint32 event_time, GdkScreen *screen, GSList *uri_list);
-static void launcher_plugin_entry_exec_from_clipboard (LauncherEntry *entry, guint32 event_time, GdkScreen *screen);
+static void launcher_plugin_items_load (LauncherPlugin *plugin);
+static gboolean launcher_plugin_item_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, XfceMenuItem *item);
+
+static gboolean launcher_plugin_item_exec_on_screen (XfceMenuItem *item, guint32 event_time, GdkScreen *screen, GSList *uri_list);
+static void launcher_plugin_item_exec (XfceMenuItem *item, guint32 event_time, GdkScreen *screen, GSList *uri_list);
+static void launcher_plugin_item_exec_from_clipboard (XfceMenuItem *item, guint32 event_time, GdkScreen *screen);
static void launcher_plugin_exec_append_quoted (GString *string, const gchar *unquoted);
-static gboolean launcher_plugin_exec_parse (LauncherEntry *entry, GSList *uri_list, gboolean terminal, gint *argc, gchar ***argv, GError **error);
+static gboolean launcher_plugin_exec_parse (XfceMenuItem *item, GSList *uri_list, gint *argc, gchar ***argv, GError **error);
@@ -78,22 +76,13 @@ struct _LauncherPlugin
GtkWidget *arrow;
GtkWidget *image;
- GSList *entries;
+ GSList *items;
- guint disable_tooltips : 1;
+ guint disable_tooltips : 1;
};
-struct _LauncherEntry
-{
- gchar *filename;
- gchar *name;
- gchar *comment;
- gchar *exec;
- gchar *path;
- gchar *icon;
- guint terminal : 1;
- guint startup_notify : 1;
-};
+/* shared root menu for all the launchers */
+static XfceMenu *root_menu = NULL;
@@ -126,11 +115,37 @@ 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));
+ }
}
@@ -149,16 +164,15 @@ launcher_plugin_property_changed (XfconfChannel *channel,
{
plugin->disable_tooltips = g_value_get_boolean (value);
}
- else if (exo_str_is_equal (property_name, "/entries"))
+ else if (exo_str_is_equal (property_name, "/items"))
{
- /* free entries */
- g_slist_foreach (plugin->entries, (GFunc)
- launcher_plugin_entry_free, NULL);
- g_slist_free (plugin->entries);
- plugin->entries = NULL;
+ /* free items */
+ g_slist_foreach (plugin->items, (GFunc) g_object_unref, NULL);
+ g_slist_free (plugin->items);
+ plugin->items = NULL;
- /* load the new entries */
- launcher_plugin_entries_load (plugin);
+ /* load the new items */
+ launcher_plugin_items_load (plugin);
/* update the icon */
launcher_plugin_button_set_icon (plugin);
@@ -225,8 +239,8 @@ launcher_plugin_construct (XfcePanelPlugin *panel_plugin)
"/disable-tooltips",
FALSE);
- /* load the entries */
- launcher_plugin_entries_load (plugin);
+ /* load the items */
+ launcher_plugin_items_load (plugin);
/* update the icon */
launcher_plugin_button_set_icon (plugin);
@@ -245,10 +259,15 @@ launcher_plugin_free_data (XfcePanelPlugin *panel_plugin)
/* shutdown xfconf */
xfconf_shutdown ();
- /* free entries */
- g_slist_foreach (plugin->entries, (GFunc)
- launcher_plugin_entry_free, NULL);
- g_slist_free (plugin->entries);
+ /* 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 ();
}
@@ -277,30 +296,30 @@ static void
launcher_plugin_save (XfcePanelPlugin *panel_plugin)
{
LauncherPlugin *plugin = XFCE_LAUNCHER_PLUGIN (panel_plugin);
- gchar **filenames;
- guint i, length;
+ gchar **desktop_ids;
+ guint i, length;
GSList *li;
- LauncherEntry *entry;
+ XfceMenuItem *item;
/* save the global settings */
xfconf_channel_set_bool (plugin->channel, "/disable-tooltips",
plugin->disable_tooltips);
- length = g_slist_length (plugin->entries);
+ length = g_slist_length (plugin->items);
if (G_LIKELY (length > 0))
{
- /* create the array with filenames */
- filenames = g_new0 (gchar *, length + 1);
- for (li = plugin->entries, i = 0; li != NULL; li = li->next)
- if (G_LIKELY ((entry = li->data) != NULL))
- filenames[i++] = entry->filename;
+ /* create the array with the desktop ids */
+ desktop_ids = 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);
/* store the list of filenames */
- xfconf_channel_set_string_list (plugin->channel, "/entries",
- (const gchar **) filenames);
+ xfconf_channel_set_string_list (plugin->channel, "/items",
+ (const gchar **) desktop_ids);
/* cleanup */
- g_free (filenames);
+ g_free (desktop_ids);
}
}
@@ -327,32 +346,33 @@ launcher_plugin_screen_position_changed (XfcePanelPlugin *panel_plugin,
static void
launcher_plugin_button_set_icon (LauncherPlugin *plugin)
{
- LauncherEntry *entry;
+ XfceMenuItem *item;
+ const gchar *icon_name;
panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
panel_return_if_fail (XFCE_IS_SCALED_IMAGE (plugin->image));
- if (G_LIKELY (plugin->entries != NULL))
+ if (G_LIKELY (plugin->items != NULL))
{
- entry = plugin->entries->data;
+ item = XFCE_MENU_ITEM (plugin->items->data);
- if (IS_STRING (entry->icon))
+ icon_name = xfce_menu_item_get_icon_name (item);
+ if (IS_STRING (icon_name))
{
- if (g_path_is_absolute (entry->icon))
+ if (g_path_is_absolute (icon_name))
xfce_scaled_image_set_from_file (XFCE_SCALED_IMAGE (plugin->image),
- entry->icon);
+ icon_name);
else
xfce_scaled_image_set_from_icon_name (XFCE_SCALED_IMAGE (plugin->image),
- entry->icon);
+ icon_name);
/* TODO some more name checking */
+ return;
}
}
- else
- {
- /* set missing image icon */
- xfce_scaled_image_set_from_icon_name (XFCE_SCALED_IMAGE (plugin->image),
- GTK_STOCK_MISSING_IMAGE);
- }
+
+ /* set missing image icon */
+ xfce_scaled_image_set_from_icon_name (XFCE_SCALED_IMAGE (plugin->image),
+ GTK_STOCK_MISSING_IMAGE);
}
@@ -390,21 +410,21 @@ launcher_plugin_button_release_event (GtkWidget *button,
GdkEventButton *event,
LauncherPlugin *plugin)
{
- LauncherEntry *entry;
- GdkScreen *screen;
+ XfceMenuItem *item;
+ GdkScreen *screen;
panel_return_val_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin), FALSE);
- if (G_UNLIKELY (plugin->entries == NULL))
+ if (G_UNLIKELY (plugin->items == NULL))
return FALSE;
- entry = plugin->entries->data;
+ item = XFCE_MENU_ITEM (plugin->items->data);
screen = gtk_widget_get_screen (button);
if (event->button == 1)
- launcher_plugin_entry_exec (entry, event->time, screen, NULL);
+ launcher_plugin_item_exec (item, event->time, screen, NULL);
else if (event->button == 2)
- launcher_plugin_entry_exec_from_clipboard (entry, event->time, screen);
+ launcher_plugin_item_exec_from_clipboard (item, event->time, screen);
else
return TRUE;
@@ -424,12 +444,13 @@ 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->entries == NULL || plugin->entries->data == NULL
- || plugin->disable_tooltips)
+ if (plugin->disable_tooltips ||
+ plugin->items == NULL || plugin->items->data == NULL)
return FALSE;
- return launcher_plugin_entry_query_tooltip (widget, x, y, keyboard_mode,
- tooltip, plugin->entries->data);
+ return launcher_plugin_item_query_tooltip (widget, x, y, keyboard_mode,
+ tooltip,
+ XFCE_MENU_ITEM (plugin->items->data));
}
@@ -452,61 +473,71 @@ launcher_plugin_button_drag_data_received (GtkWidget *widget,
static void
-launcher_plugin_entries_load (LauncherPlugin *plugin)
+launcher_plugin_items_load (LauncherPlugin *plugin)
{
- gchar **filenames;
- guint i;
- LauncherEntry *entry;
+ gchar **desktop_ids;
+ guint i;
+ XfceMenuItem *item;
+ XfceMenuItemPool *pool;
panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
+ panel_return_if_fail (plugin->items == NULL);
/* get the list of launcher filenames */
- filenames = xfconf_channel_get_string_list (plugin->channel, "/entries");
- if (G_LIKELY (filenames != NULL))
+ desktop_ids = xfconf_channel_get_string_list (plugin->channel, "/items");
+ if (G_LIKELY (desktop_ids != NULL))
{
- /* try to load all the entries */
- for (i = 0; filenames[i] != NULL; i++)
+ /* 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++)
{
- entry = launcher_plugin_entry_new_from_filename (filenames[i]);
- if (G_LIKELY (entry != NULL))
- plugin->entries = g_slist_append (plugin->entries, entry);
+ item = xfce_menu_item_pool_lookup (pool, desktop_ids[i]);
+ if (G_LIKELY (item != NULL))
+ plugin->items = g_slist_append (plugin->items,
+ g_object_ref (G_OBJECT (item)));
}
/* cleanup */
- g_strfreev (filenames);
+ g_strfreev (desktop_ids);
}
}
static gboolean
-launcher_plugin_entry_query_tooltip (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip,
- LauncherEntry *entry)
+launcher_plugin_item_query_tooltip (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_mode,
+ GtkTooltip *tooltip,
+ XfceMenuItem *item)
{
- gchar *markup;
+ gchar *markup;
+ const gchar *name, *comment, *icon_name;
- panel_return_val_if_fail (entry != NULL, FALSE);
+ panel_return_val_if_fail (XFCE_IS_MENU_ITEM (item), FALSE);
- /* require atleast an entry name */
- if (!IS_STRING (entry->name))
+ /* require atleast an item name */
+ name = xfce_menu_item_get_name (item);
+ if (!IS_STRING (name))
return FALSE;
- if (IS_STRING (entry->comment))
+ comment = xfce_menu_item_get_comment (item);
+ if (IS_STRING (comment))
{
- markup = g_strdup_printf ("<b>%s</b>\n%s", entry->name, entry->comment);
+ markup = g_strdup_printf ("<b>%s</b>\n%s", name, comment);
gtk_tooltip_set_markup (tooltip, markup);
g_free (markup);
}
else
{
- gtk_tooltip_set_text (tooltip, entry->name);
+ gtk_tooltip_set_text (tooltip, name);
}
- if (G_LIKELY (entry->icon))
+ icon_name = xfce_menu_item_get_icon_name (item);
+ if (G_LIKELY (icon_name))
{
/* TODO pixbuf with cache */
}
@@ -516,79 +547,29 @@ launcher_plugin_entry_query_tooltip (GtkWidget *widget,
-static LauncherEntry *
-launcher_plugin_entry_new_from_filename (const gchar *filename)
-{
- LauncherEntry *entry = NULL;
- XfceRc *rc;
-
- panel_return_val_if_fail (filename != NULL, NULL);
- panel_return_val_if_fail (g_path_is_absolute (filename), NULL);
-
- rc = xfce_rc_simple_open (filename, TRUE);
- if (G_LIKELY (rc != NULL))
- {
- /* allocate a new entry */
- entry = g_slice_new0 (LauncherEntry);
-
- /* set group */
- xfce_rc_set_group (rc, "Desktop Entry");
-
- /* set entry values */
- entry->filename = g_strdup (filename);
- entry->name = g_strdup (xfce_rc_read_entry (rc, "Name", NULL));
- entry->comment = g_strdup (xfce_rc_read_entry (rc, "Comment", NULL));
- entry->exec = g_strdup (xfce_rc_read_entry_untranslated (rc, "Exec", NULL));
- entry->icon = g_strdup (xfce_rc_read_entry_untranslated (rc, "Icon", NULL));
- entry->path = g_strdup (xfce_rc_read_entry_untranslated (rc, "Path", NULL));
- entry->terminal = xfce_rc_read_bool_entry (rc, "Terminal", FALSE);
- entry->startup_notify = xfce_rc_read_bool_entry (rc, "StartupNotify", FALSE);
-
- /* close */
- xfce_rc_close (rc);
- }
-
- return entry;
-}
-
-
-
-static void
-launcher_plugin_entry_free (LauncherEntry *entry)
-{
- panel_return_if_fail (entry != NULL);
-
- g_free (entry->filename);
- g_free (entry->name);
- g_free (entry->comment);
- g_free (entry->exec);
- g_free (entry->icon);
- g_free (entry->path);
-
- g_slice_free (LauncherEntry, entry);
-}
-
-
-
static gboolean
-launcher_plugin_entry_exec_on_screen (LauncherEntry *entry,
- guint32 event_time,
- GdkScreen *screen,
- GSList *uri_list)
+launcher_plugin_item_exec_on_screen (XfceMenuItem *item,
+ guint32 event_time,
+ GdkScreen *screen,
+ GSList *uri_list)
{
GError *error = NULL;
gchar **argv;
gboolean succeed = FALSE;
+ panel_return_val_if_fail (XFCE_IS_MENU_ITEM (item), FALSE);
+
/* parse the execute command */
- if (launcher_plugin_exec_parse (entry, uri_list, entry->terminal,
- NULL, &argv, &error))
+ if (launcher_plugin_exec_parse (item, uri_list, NULL, &argv, &error))
{
/* launch the command on the screen */
- succeed = xfce_execute_argv_on_screen (screen, entry->path, argv,
- NULL, G_SPAWN_SEARCH_PATH,
- entry->startup_notify,
- event_time, entry->icon, &error);
+ succeed = xfce_execute_argv_on_screen (screen,
+ xfce_menu_item_get_path (item),
+ argv, NULL, G_SPAWN_SEARCH_PATH,
+ xfce_menu_item_supports_startup_notification (item),
+ event_time,
+ xfce_menu_item_get_icon_name (item),
+ &error);
/* cleanup */
g_strfreev (argv);
@@ -607,23 +588,25 @@ launcher_plugin_entry_exec_on_screen (LauncherEntry *entry,
static void
-launcher_plugin_entry_exec (LauncherEntry *entry,
- guint32 event_time,
- GdkScreen *screen,
- GSList *uri_list)
+launcher_plugin_item_exec (XfceMenuItem *item,
+ guint32 event_time,
+ GdkScreen *screen,
+ GSList *uri_list)
{
- GSList *li, fake;
- gboolean proceed = TRUE;
+ GSList *li, fake;
+ gboolean proceed = TRUE;
+ const gchar *command;
- panel_return_if_fail (entry != NULL);
+ panel_return_if_fail (XFCE_IS_MENU_ITEM (item));
/* leave when there is nothing to execute */
- if (!IS_STRING (entry->exec))
+ command = xfce_menu_item_get_command (item);
+ if (!IS_STRING (command))
return;
if (G_UNLIKELY (uri_list != NULL
- && strstr (entry->exec, "%F") == NULL
- && strstr (entry->exec, "%U") == NULL))
+ && strstr (command, "%F") == NULL
+ && strstr (command, "%U") == NULL))
{
fake.next = NULL;
@@ -631,26 +614,26 @@ launcher_plugin_entry_exec (LauncherEntry *entry,
for (li = uri_list; li != NULL && proceed; li = li->next)
{
fake.data = li->data;
- proceed = launcher_plugin_entry_exec_on_screen (entry,
- event_time,
- screen, &fake);
+ proceed = launcher_plugin_item_exec_on_screen (item,
+ event_time,
+ screen, &fake);
}
}
else
{
- launcher_plugin_entry_exec_on_screen (entry, event_time, screen,
- uri_list);
+ launcher_plugin_item_exec_on_screen (item, event_time, screen,
+ uri_list);
}
}
static void
-launcher_plugin_entry_exec_from_clipboard (LauncherEntry *entry,
- guint32 event_time,
- GdkScreen *screen)
+launcher_plugin_item_exec_from_clipboard (XfceMenuItem *item,
+ guint32 event_time,
+ GdkScreen *screen)
{
- panel_return_if_fail (entry != NULL);
+ panel_return_if_fail (XFCE_IS_MENU_ITEM (item));
/* TODO */
}
@@ -671,30 +654,33 @@ launcher_plugin_exec_append_quoted (GString *string,
static gboolean
-launcher_plugin_exec_parse (LauncherEntry *entry,
- GSList *uri_list,
- gboolean terminal,
- gint *argc,
- gchar ***argv,
- GError **error)
+launcher_plugin_exec_parse (XfceMenuItem *item,
+ GSList *uri_list,
+ gint *argc,
+ gchar ***argv,
+ GError **error)
{
GString *string;
const gchar *p;
gboolean result;
GSList *li;
gchar *filename;
+ const gchar *command, *tmp;
+
+ panel_return_val_if_fail (XFCE_IS_MENU_ITEM (item), FALSE);
- panel_return_val_if_fail (entry != NULL, FALSE);
- panel_return_val_if_fail (IS_STRING (entry->exec), FALSE);
+ /* get the command */
+ command = xfce_menu_item_get_command (item);
+ panel_return_val_if_fail (IS_STRING (command), FALSE);
/* allocate an empty string */
string = g_string_sized_new (100);
/* prepend terminal command if required */
- if (G_UNLIKELY (terminal))
+ if (xfce_menu_item_requires_terminal (item))
g_string_append (string, "exo-open --launch TerminalEmulator ");
- for (p = entry->exec; *p != '\0'; ++p)
+ for (p = command; *p != '\0'; ++p)
{
if (p[0] == '%' && p[1] != '\0')
{
@@ -732,21 +718,24 @@ launcher_plugin_exec_parse (LauncherEntry *entry,
break;
case 'i':
- if (IS_STRING (entry->icon))
+ tmp = xfce_menu_item_get_icon_name (item);
+ if (IS_STRING (tmp))
{
g_string_append (string, "--icon ");
- launcher_plugin_exec_append_quoted (string, entry->icon);
+ launcher_plugin_exec_append_quoted (string, tmp);
}
break;
case 'c':
- if (IS_STRING (entry->name))
- launcher_plugin_exec_append_quoted (string, entry->name);
+ tmp = xfce_menu_item_get_name (item);
+ if (IS_STRING (tmp))
+ launcher_plugin_exec_append_quoted (string, tmp);
break;
case 'k':
- if (IS_STRING (entry->filename))
- launcher_plugin_exec_append_quoted (string, entry->filename);
+ tmp = xfce_menu_item_get_filename (item);
+ if (IS_STRING (tmp))
+ launcher_plugin_exec_append_quoted (string, tmp);
break;
case '%':
@@ -774,3 +763,21 @@ launcher_plugin_get_channel (LauncherPlugin *plugin)
panel_return_val_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin), NULL);
return plugin->channel;
}
+
+
+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)
+{
+ panel_return_val_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin), NULL);
+ return plugin->items;
+}
diff --git a/plugins/launcher/launcher.h b/plugins/launcher/launcher.h
index 3bc2fe6..5448e8d 100644
--- a/plugins/launcher/launcher.h
+++ b/plugins/launcher/launcher.h
@@ -21,6 +21,7 @@
#include <gtk/gtk.h>
#include <xfconf/xfconf.h>
#include <libxfce4panel/libxfce4panel.h>
+#include <libxfce4menu/libxfce4menu.h>
G_BEGIN_DECLS
@@ -35,10 +36,13 @@ typedef struct _LauncherEntry LauncherEntry;
#define XFCE_IS_LAUNCHER_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_LAUNCHER_PLUGIN))
#define XFCE_LAUNCHER_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_LAUNCHER_PLUGIN, LauncherPluginClass))
-GType launcher_plugin_get_type (void) G_GNUC_CONST;
+GType launcher_plugin_get_type (void) G_GNUC_CONST;
-XfconfChannel *launcher_plugin_get_channel (LauncherPlugin *plugin);
+XfconfChannel *launcher_plugin_get_channel (LauncherPlugin *plugin);
+XfceMenuItemPool *launcher_plugin_get_item_pool (LauncherPlugin *plugin);
+
+GSList *launcher_plugin_get_items (LauncherPlugin *plugin);
G_END_DECLS
#endif /* !__LAUNCHER_H__ */
More information about the Xfce4-commits
mailing list