aboutsummaryrefslogtreecommitdiff
path: root/src/launcher-menu-item.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/launcher-menu-item.c')
-rw-r--r--src/launcher-menu-item.c123
1 files changed, 107 insertions, 16 deletions
diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c
index 50e8ce6..d6386a3 100644
--- a/src/launcher-menu-item.c
+++ b/src/launcher-menu-item.c
@@ -27,6 +27,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <gdk/gdk.h>
#include <glib/gi18n.h>
#include <gio/gdesktopappinfo.h>
+#include <libindicator/indicator-desktop-shortcuts.h>
#include "launcher-menu-item.h"
#include "dbus-data.h"
@@ -42,16 +43,21 @@ struct _LauncherMenuItemPrivate
{
GAppInfo * appinfo;
gchar * desktop;
+ IndicatorDesktopShortcuts * ids;
+ GList * shortcuts;
};
#define LAUNCHER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LAUNCHER_MENU_ITEM_TYPE, LauncherMenuItemPrivate))
+#define NICK_DATA "ids-nick-data"
+
/* Prototypes */
static void launcher_menu_item_class_init (LauncherMenuItemClass *klass);
static void launcher_menu_item_init (LauncherMenuItem *self);
static void launcher_menu_item_dispose (GObject *object);
static void launcher_menu_item_finalize (GObject *object);
static void activate_cb (LauncherMenuItem * self, guint timestamp, gpointer data);
+static void nick_activate_cb (LauncherMenuItem * self, guint timestamp, gpointer data);
G_DEFINE_TYPE (LauncherMenuItem, launcher_menu_item, DBUSMENU_TYPE_MENUITEM);
@@ -86,20 +92,21 @@ launcher_menu_item_init (LauncherMenuItem *self)
priv->appinfo = NULL;
priv->desktop = NULL;
+ priv->ids = NULL;
+ priv->shortcuts = NULL;
+
return;
}
static void
-launcher_menu_item_dispose (GObject *object)
+func_unref (gpointer data, gpointer user_data)
{
- // LauncherMenuItem * self = LAUNCHER_MENU_ITEM(object);
- // LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self);
-
- G_OBJECT_CLASS (launcher_menu_item_parent_class)->dispose (object);
+ g_object_unref(G_OBJECT(data));
+ return;
}
static void
-launcher_menu_item_finalize (GObject *object)
+launcher_menu_item_dispose (GObject *object)
{
LauncherMenuItem * self = LAUNCHER_MENU_ITEM(object);
LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self);
@@ -109,6 +116,26 @@ launcher_menu_item_finalize (GObject *object)
priv->appinfo = NULL;
}
+ if (priv->ids != NULL) {
+ g_object_unref(priv->ids);
+ priv->ids = NULL;
+ }
+
+ if (priv->shortcuts != NULL) {
+ g_list_foreach(priv->shortcuts, func_unref, NULL);
+ g_list_free(priv->shortcuts);
+ priv->shortcuts = NULL;
+ }
+
+ G_OBJECT_CLASS (launcher_menu_item_parent_class)->dispose (object);
+}
+
+static void
+launcher_menu_item_finalize (GObject *object)
+{
+ LauncherMenuItem * self = LAUNCHER_MENU_ITEM(object);
+ LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self);
+
if (priv->desktop != NULL) {
g_free(priv->desktop);
priv->desktop = NULL;
@@ -127,16 +154,35 @@ launcher_menu_item_new (const gchar * desktop_file)
LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self);
+ /* Parse the desktop file we've been given. */
priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file));
priv->desktop = g_strdup(desktop_file);
+ /* Set the appropriate values on this menu item based on the
+ app info that we've parsed */
g_debug("\tName: %s", launcher_menu_item_get_name(self));
dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, LAUNCHER_MENUITEM_TYPE);
dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), LAUNCHER_MENUITEM_PROP_APP_NAME, launcher_menu_item_get_name(self));
dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), LAUNCHER_MENUITEM_PROP_APP_DESC, launcher_menu_item_get_description(self));
+ dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL);
+ /* Start to build static shortcuts */
+ priv->ids = indicator_desktop_shortcuts_new(priv->desktop, "Messaging Menu");
+ const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(priv->ids);
+ gint i;
+ for (i = 0; nicks[i] != NULL; i++) {
+ DbusmenuMenuitem * mi = dbusmenu_menuitem_new();
+ g_object_set_data(G_OBJECT(mi), NICK_DATA, (gpointer)nicks[i]);
+
+ dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, indicator_desktop_shortcuts_nick_get_name(priv->ids, nicks[i]));
+ g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(nick_activate_cb), self);
+
+ priv->shortcuts = g_list_append(priv->shortcuts, mi);
+ }
+
+ /* Check to see if we should be eclipsed */
if (priv->appinfo == NULL) {
launcher_menu_item_set_eclipsed(self, TRUE);
}
@@ -156,6 +202,27 @@ launcher_menu_item_get_name (LauncherMenuItem * appitem)
}
}
+/* Respond to one of the shortcuts getting clicked on. */
+static void
+nick_activate_cb (LauncherMenuItem * self, guint timestamp, gpointer data)
+{
+ gchar * nick = (gchar *)g_object_get_data(G_OBJECT(self), NICK_DATA);
+ LauncherMenuItem * lmi = LAUNCHER_MENU_ITEM(data);
+
+ g_return_if_fail(nick != NULL);
+ g_return_if_fail(lmi != NULL);
+
+ LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(lmi);
+
+ g_return_if_fail(priv->ids != NULL);
+
+ if (!indicator_desktop_shortcuts_nick_exec(priv->ids, nick)) {
+ g_warning("Unable to execute nick '%s' for desktop file '%s'", nick, priv->desktop);
+ }
+
+ return;
+}
+
/* When the menu item is clicked on it tries to launch
the application that is represented by the desktop file */
static void
@@ -191,26 +258,50 @@ launcher_menu_item_get_description (LauncherMenuItem * li)
return g_app_info_get_description(priv->appinfo);
}
+/* Apply the eclipse value to all the shortcuts */
+static void
+eclipse_shortcuts_cb (gpointer data, gpointer user_data)
+{
+ DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(data);
+ g_return_if_fail(mi != NULL);
+
+ gboolean eclipsed = GPOINTER_TO_UINT(user_data);
+
+ dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !eclipsed);
+ return;
+}
+
/* Hides the menu item based on whether it is eclipsed
or not. */
void
launcher_menu_item_set_eclipsed (LauncherMenuItem * li, gboolean eclipsed)
{
+ g_return_if_fail(IS_LAUNCHER_MENU_ITEM(li));
+ LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(li);
+
g_debug("Laucher '%s' is %s", launcher_menu_item_get_name(li), eclipsed ? "now eclipsed" : "shown again");
- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_VISIBLE, eclipsed ? "false" : "true");
+ dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_VISIBLE, !eclipsed);
+
+ g_list_foreach(priv->shortcuts, eclipse_shortcuts_cb, GINT_TO_POINTER(eclipsed));
+
return;
}
+/* Check to see if this item is eclipsed */
gboolean
launcher_menu_item_get_eclipsed (LauncherMenuItem * li)
{
- const gchar * show = dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_VISIBLE);
- if (show == NULL) {
- return FALSE;
- }
- g_debug("Launcher check eclipse: %s", show);
- if (!g_strcmp0(show, "false")) {
- return TRUE;
- }
- return FALSE;
+ gboolean show = dbusmenu_menuitem_property_get_bool(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_VISIBLE);
+ g_debug("Launcher check eclipse: %s", show ? "false" : "true");
+ return !show;
+}
+
+/* Gets the shortcuts that are associated with this
+ launcher. They're a list of DbusmenuMenuitems */
+GList *
+launcher_menu_item_get_items (LauncherMenuItem * li)
+{
+ g_return_val_if_fail(IS_LAUNCHER_MENU_ITEM(li), NULL);
+ LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(li);
+ return priv->shortcuts;
}