From a2717539e6fbf557020fab6065770f54714c9c96 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 14:00:56 -0600 Subject: Adding in the new object we're building for evaluating desktop shortcuts. --- .bzrignore | 1 + libindicator/Makefile.am | 2 + libindicator/indicator-desktop-shortcuts.c | 60 ++++++++++++++++++++++++++++++ libindicator/indicator-desktop-shortcuts.h | 31 +++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 libindicator/indicator-desktop-shortcuts.c create mode 100644 libindicator/indicator-desktop-shortcuts.h diff --git a/.bzrignore b/.bzrignore index 22df703..85d91ed 100644 --- a/.bzrignore +++ b/.bzrignore @@ -147,3 +147,4 @@ libindicator/indicator-object-marshal.c libindicator/indicator-object-marshal.h libindicator/libindicator_la-indicator-object-marshal.lo libindicator/stamp-marshal +libindicator/libindicator_la-indicator-desktop-shortcuts.lo diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index 19247ce..467e09a 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -10,6 +10,7 @@ libindicatorincludedir=$(includedir)/libindicator-0.3/libindicator indicator_headers = \ indicator.h \ + indicator-desktop-shortcuts.h \ indicator-object.h \ indicator-service.h \ indicator-service-manager.h @@ -24,6 +25,7 @@ libindicator_la_SOURCES = \ $(indicator_headers) \ dbus-shared.h \ indicator-object.c \ + indicator-desktop-shortcuts.c \ indicator-object-marshal.h \ indicator-object-marshal.c \ indicator-service.c \ diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c new file mode 100644 index 0000000..49b5b52 --- /dev/null +++ b/libindicator/indicator-desktop-shortcuts.c @@ -0,0 +1,60 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "indicator-desktop-shortcuts.h" + +typedef struct _IndicatorDesktopShortcutsPrivate IndicatorDesktopShortcutsPrivate; +struct _IndicatorDesktopShortcutsPrivate { + GKeyFile * keyfile; +}; + +#define INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_TYPE_DESKTOP_SHORTCUTS, IndicatorDesktopShortcutsPrivate)) + +static void indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsClass *klass); +static void indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self); +static void indicator_desktop_shortcuts_dispose (GObject *object); +static void indicator_desktop_shortcuts_finalize (GObject *object); + +G_DEFINE_TYPE (IndicatorDesktopShortcuts, indicator_desktop_shortcuts, G_TYPE_OBJECT); + +static void +indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IndicatorDesktopShortcutsPrivate)); + + object_class->dispose = indicator_desktop_shortcuts_dispose; + object_class->finalize = indicator_desktop_shortcuts_finalize; + + return; +} + +static void +indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self) +{ + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(self); + + priv->keyfile = NULL; + + return; +} + +static void +indicator_desktop_shortcuts_dispose (GObject *object) +{ + + G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->dispose (object); + return; +} + +static void +indicator_desktop_shortcuts_finalize (GObject *object) +{ + + G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->finalize (object); + return; +} + diff --git a/libindicator/indicator-desktop-shortcuts.h b/libindicator/indicator-desktop-shortcuts.h new file mode 100644 index 0000000..6b3f022 --- /dev/null +++ b/libindicator/indicator-desktop-shortcuts.h @@ -0,0 +1,31 @@ +#ifndef __INDICATOR_DESKTOP_SHORTCUTS_H__ +#define __INDICATOR_DESKTOP_SHORTCUTS_H__ + +#include +#include + +G_BEGIN_DECLS + +#define INDICATOR_TYPE_DESKTOP_SHORTCUTS (indicator_desktop_shortcuts_get_type ()) +#define INDICATOR_DESKTOP_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_TYPE_DESKTOP_SHORTCUTS, IndicatorDesktopShortcuts)) +#define INDICATOR_DESKTOP_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_TYPE_DESKTOP_SHORTCUTS, IndicatorDesktopShortcutsClass)) +#define IS_INDICATOR_DESKTOP_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_TYPE_DESKTOP_SHORTCUTS)) +#define IS_INDICATOR_DESKTOP_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_TYPE_DESKTOP_SHORTCUTS)) +#define INDICATOR_DESKTOP_SHORTCUTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_TYPE_DESKTOP_SHORTCUTS, IndicatorDesktopShortcutsClass)) + +typedef struct _IndicatorDesktopShortcuts IndicatorDesktopShortcuts; +typedef struct _IndicatorDesktopShortcutsClass IndicatorDesktopShortcutsClass; + +struct _IndicatorDesktopShortcutsClass { + GObjectClass parent_class; +}; + +struct _IndicatorDesktopShortcuts { + GObject parent; +}; + +GType indicator_desktop_shortcuts_get_type (void); + +G_END_DECLS + +#endif -- cgit v1.2.3 From 95f07c4e018e2a257a765ee7f71c777d555f548d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 14:13:51 -0600 Subject: Copyright headers --- libindicator/indicator-desktop-shortcuts.c | 23 +++++++++++++++++++++++ libindicator/indicator-desktop-shortcuts.h | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 49b5b52..6c60638 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -1,3 +1,26 @@ +/* +A small file to parse through the actions that are available +in the desktop file and making those easily usable. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 3.0 as published by the Free Software Foundation. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License version 3.0 for more details. + +You should have received a copy of the GNU General Public +License along with this library. If not, see +. +*/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/libindicator/indicator-desktop-shortcuts.h b/libindicator/indicator-desktop-shortcuts.h index 6b3f022..190c541 100644 --- a/libindicator/indicator-desktop-shortcuts.h +++ b/libindicator/indicator-desktop-shortcuts.h @@ -1,3 +1,26 @@ +/* +A small file to parse through the actions that are available +in the desktop file and making those easily usable. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 3.0 as published by the Free Software Foundation. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License version 3.0 for more details. + +You should have received a copy of the GNU General Public +License along with this library. If not, see +. +*/ + #ifndef __INDICATOR_DESKTOP_SHORTCUTS_H__ #define __INDICATOR_DESKTOP_SHORTCUTS_H__ -- cgit v1.2.3 From d970c855552615e22881b8ebb57ecc5de6481b8a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 14:22:01 -0600 Subject: Letz get ur prototypes --- libindicator/indicator-desktop-shortcuts.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.h b/libindicator/indicator-desktop-shortcuts.h index 190c541..10cacff 100644 --- a/libindicator/indicator-desktop-shortcuts.h +++ b/libindicator/indicator-desktop-shortcuts.h @@ -39,15 +39,34 @@ G_BEGIN_DECLS typedef struct _IndicatorDesktopShortcuts IndicatorDesktopShortcuts; typedef struct _IndicatorDesktopShortcutsClass IndicatorDesktopShortcutsClass; +/** + IndicatorDesktopShortcutsClass: + @parent_class: Space for #GObjectClass + + The vtable for our precious #IndicatorDesktopShortcutsClass. +*/ struct _IndicatorDesktopShortcutsClass { GObjectClass parent_class; }; +/** + IndicatorDesktopShortcuts: + @parent: The parent data from #GObject + + The public data for an instance of the class + #IndicatorDesktopShortcuts. +*/ struct _IndicatorDesktopShortcuts { GObject parent; }; -GType indicator_desktop_shortcuts_get_type (void); +GType indicator_desktop_shortcuts_get_type (void); +IndicatorDesktopShortcuts * indicator_desktop_shortcuts_new (const gchar * file, + const gchar * identity); +const gchar ** indicator_desktop_shortcuts_get_nicks (IndicatorDesktopShortcuts * ids); +const gchar * indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, + const gchar * nick); + G_END_DECLS -- cgit v1.2.3 From 3a95d842bbcd99afc85307ca1d699cc17072d986 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 14:57:23 -0600 Subject: Instanciating the prototypes and making some comments. --- libindicator/indicator-desktop-shortcuts.c | 86 ++++++++++++++++++++++++++++++ libindicator/indicator-desktop-shortcuts.h | 3 +- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 6c60638..845f997 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -42,6 +42,7 @@ static void indicator_desktop_shortcuts_finalize (GObject *object); G_DEFINE_TYPE (IndicatorDesktopShortcuts, indicator_desktop_shortcuts, G_TYPE_OBJECT); +/* Build up the class */ static void indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsClass *klass) { @@ -55,6 +56,7 @@ indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsClass *klass) return; } +/* Initialize instance data */ static void indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self) { @@ -65,6 +67,7 @@ indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self) return; } +/* Clear object references */ static void indicator_desktop_shortcuts_dispose (GObject *object) { @@ -73,6 +76,7 @@ indicator_desktop_shortcuts_dispose (GObject *object) return; } +/* Free all memory */ static void indicator_desktop_shortcuts_finalize (GObject *object) { @@ -81,3 +85,85 @@ indicator_desktop_shortcuts_finalize (GObject *object) return; } +/* API */ + +/** + indicator_desktop_shortcuts_new: + @file: The desktop file that would be opened to + find the actions. + @identity: This is a string that represents the identity + that should be used in searching those actions. It + relates to the ShowIn and NotShownIn properties. + + This function creates the basic object. It involves opening + the file and parsing it. It could potentially block on IO. At + the end of the day you'll have a fully functional object. + + Return value: A new #IndicatorDesktopShortcuts object. +*/ +IndicatorDesktopShortcuts * +indicator_desktop_shortcuts_new (const gchar * file, const gchar * identity) +{ + + return NULL; +} + +/** + indicator_desktop_shortcuts_get_nicks: + @ids: The #IndicatorDesktopShortcuts object to look in + + Give you the list of commands that are available for this desktop + file given the identity that was passed in at creation. This will + filter out the various items in the desktop file. These nicks can + then be used as keys for working with the desktop file. + + Return value: A #NULL terminated list of strings. This memory + is managed by the @ids object. +*/ +const gchar ** +indicator_desktop_shortcuts_get_nicks (IndicatorDesktopShortcuts * ids) +{ + + + return NULL; +} + +/** + indicator_desktop_shortcuts_nick_get_name: + @ids: The #IndicatorDesktopShortcuts object to look in + @nick: Which command that we're referencing. + + This function looks in a desktop file for a nick to find the + user visible name for that shortcut. The @nick parameter + should be gotten from #indicator_desktop_shortcuts_get_nicks + though it's not required that the exact memory location + be the same. + + Return value: A user visible string for the shortcut or + #NULL on error. +*/ +const gchar * +indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, const gchar * nick) +{ + + return NULL; +} + +/** + indicator_desktop_shortcuts_nick_exec: + @ids: The #IndicatorDesktopShortcuts object to look in + @nick: Which command that we're referencing. + + Here we take a @nick and try and execute the action that is + associated with it. The @nick parameter should be gotten + from #indicator_desktop_shortcuts_get_nicks though it's not + required that the exact memory location be the same. + + Return value: #TRUE on success or #FALSE on error. +*/ +gboolean +indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gchar * nick) +{ + + return FALSE; +} diff --git a/libindicator/indicator-desktop-shortcuts.h b/libindicator/indicator-desktop-shortcuts.h index 10cacff..bda65a6 100644 --- a/libindicator/indicator-desktop-shortcuts.h +++ b/libindicator/indicator-desktop-shortcuts.h @@ -66,7 +66,8 @@ IndicatorDesktopShortcuts * indicator_desktop_shortcuts_new (const const gchar ** indicator_desktop_shortcuts_get_nicks (IndicatorDesktopShortcuts * ids); const gchar * indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, const gchar * nick); - +gboolean indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, + const gchar * nick); G_END_DECLS -- cgit v1.2.3 From a32a078bd850762c40577db69d589f660bf5e957 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 15:12:29 -0600 Subject: Getting some new private variables, and making sure they have a full lifecycle. --- libindicator/indicator-desktop-shortcuts.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 845f997..e6f5a69 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -30,6 +30,8 @@ License along with this library. If not, see typedef struct _IndicatorDesktopShortcutsPrivate IndicatorDesktopShortcutsPrivate; struct _IndicatorDesktopShortcutsPrivate { GKeyFile * keyfile; + gchar * identity; + GArray * nicks; }; #define INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(o) \ @@ -63,6 +65,8 @@ indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self) IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(self); priv->keyfile = NULL; + priv->identity = NULL; + priv->nicks = g_array_new(TRUE, TRUE, sizeof(gchar *)); return; } @@ -71,6 +75,13 @@ indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self) static void indicator_desktop_shortcuts_dispose (GObject *object) { + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(object); + + if (priv->keyfile) { + g_key_file_free(priv->keyfile); + priv->keyfile = NULL; + } + G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->dispose (object); return; @@ -80,6 +91,22 @@ indicator_desktop_shortcuts_dispose (GObject *object) static void indicator_desktop_shortcuts_finalize (GObject *object) { + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(object); + + if (priv->identity != NULL) { + g_free(priv->identity); + priv->identity = NULL; + } + + if (priv->nicks != NULL) { + gint i; + for (i = 0; i < priv->nicks->len; i++) { + gchar * nick = g_array_index(priv->nicks, gchar *, i); + g_free(nick); + } + g_array_free(priv->nicks, TRUE); + priv->nicks = NULL; + } G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->finalize (object); return; -- cgit v1.2.3 From 5d2ace5acc4c15d3ced8439ab8afa216806a1b53 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 15:20:09 -0600 Subject: Fleshing out _new and _get_nicks Both are lovely functions. --- libindicator/indicator-desktop-shortcuts.c | 16 +++++++++++----- libindicator/indicator-desktop-shortcuts.h | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index e6f5a69..4ae95b9 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -27,6 +27,9 @@ License along with this library. If not, see #include "indicator-desktop-shortcuts.h" +#define PROP_DESKTOP_FILE_S "desktop-file" +#define PROP_IDENTITY_S "identity" + typedef struct _IndicatorDesktopShortcutsPrivate IndicatorDesktopShortcutsPrivate; struct _IndicatorDesktopShortcutsPrivate { GKeyFile * keyfile; @@ -131,8 +134,11 @@ indicator_desktop_shortcuts_finalize (GObject *object) IndicatorDesktopShortcuts * indicator_desktop_shortcuts_new (const gchar * file, const gchar * identity) { - - return NULL; + GObject * obj = g_object_new(INDICATOR_TYPE_DESKTOP_SHORTCUTS, + PROP_DESKTOP_FILE_S, file, + PROP_IDENTITY_S, identity, + NULL); + return INDICATOR_DESKTOP_SHORTCUTS(obj); } /** @@ -150,9 +156,9 @@ indicator_desktop_shortcuts_new (const gchar * file, const gchar * identity) const gchar ** indicator_desktop_shortcuts_get_nicks (IndicatorDesktopShortcuts * ids) { - - - return NULL; + g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL); + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); + return (const gchar **)priv->nicks->data; } /** diff --git a/libindicator/indicator-desktop-shortcuts.h b/libindicator/indicator-desktop-shortcuts.h index bda65a6..16a23a4 100644 --- a/libindicator/indicator-desktop-shortcuts.h +++ b/libindicator/indicator-desktop-shortcuts.h @@ -32,8 +32,8 @@ G_BEGIN_DECLS #define INDICATOR_TYPE_DESKTOP_SHORTCUTS (indicator_desktop_shortcuts_get_type ()) #define INDICATOR_DESKTOP_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_TYPE_DESKTOP_SHORTCUTS, IndicatorDesktopShortcuts)) #define INDICATOR_DESKTOP_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_TYPE_DESKTOP_SHORTCUTS, IndicatorDesktopShortcutsClass)) -#define IS_INDICATOR_DESKTOP_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_TYPE_DESKTOP_SHORTCUTS)) -#define IS_INDICATOR_DESKTOP_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_TYPE_DESKTOP_SHORTCUTS)) +#define INDICATOR_IS_DESKTOP_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_TYPE_DESKTOP_SHORTCUTS)) +#define INDICATOR_IS_DESKTOP_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_TYPE_DESKTOP_SHORTCUTS)) #define INDICATOR_DESKTOP_SHORTCUTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_TYPE_DESKTOP_SHORTCUTS, IndicatorDesktopShortcutsClass)) typedef struct _IndicatorDesktopShortcuts IndicatorDesktopShortcuts; -- cgit v1.2.3 From f2196d128ea412f115d452b2cc5a3cd27ca5bee9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 15:44:00 -0600 Subject: Fleshing out getting the Name of a shortcut --- libindicator/indicator-desktop-shortcuts.c | 44 ++++++++++++++++++++++++++++-- libindicator/indicator-desktop-shortcuts.h | 2 +- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 4ae95b9..226dec4 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -27,6 +27,8 @@ License along with this library. If not, see #include "indicator-desktop-shortcuts.h" +#define GROUP_SUFFIX "Shortcut Group" + #define PROP_DESKTOP_FILE_S "desktop-file" #define PROP_IDENTITY_S "identity" @@ -115,6 +117,18 @@ indicator_desktop_shortcuts_finalize (GObject *object) return; } +/* Looks through the nicks ot see if this one is in the list, + and thus valid to use. */ +static gboolean +is_valid_nick (gchar ** list, const gchar * nick) +{ + if (*list == NULL) + return FALSE; + if (g_strcmp0(*list, nick) == 0) + return TRUE; + return is_valid_nick(list++, nick); +} + /* API */ /** @@ -175,11 +189,37 @@ indicator_desktop_shortcuts_get_nicks (IndicatorDesktopShortcuts * ids) Return value: A user visible string for the shortcut or #NULL on error. */ -const gchar * +gchar * indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, const gchar * nick) { + g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL); + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); + + g_return_val_if_fail(priv->keyfile != NULL, NULL); + g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL); + + gchar * groupheader = g_strdup_printf("%s " GROUP_SUFFIX, nick); + if (!g_key_file_has_group(priv->keyfile, groupheader)) { + g_warning("The group for nick '%s' doesn't exist anymore.", nick); + g_free(groupheader); + return NULL; + } + + if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_NAME, NULL)) { + g_warning("No name available for nick '%s'", nick); + g_free(groupheader); + return NULL; + } + + gchar * name = g_key_file_get_locale_string(priv->keyfile, + groupheader, + G_KEY_FILE_DESKTOP_KEY_NAME, + NULL, + NULL); + + g_free(groupheader); - return NULL; + return name; } /** diff --git a/libindicator/indicator-desktop-shortcuts.h b/libindicator/indicator-desktop-shortcuts.h index 16a23a4..5ed490e 100644 --- a/libindicator/indicator-desktop-shortcuts.h +++ b/libindicator/indicator-desktop-shortcuts.h @@ -64,7 +64,7 @@ GType indicator_desktop_shortcuts_get_type (void); IndicatorDesktopShortcuts * indicator_desktop_shortcuts_new (const gchar * file, const gchar * identity); const gchar ** indicator_desktop_shortcuts_get_nicks (IndicatorDesktopShortcuts * ids); -const gchar * indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, +gchar * indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, const gchar * nick); gboolean indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gchar * nick); -- cgit v1.2.3 From 5d7fbff4c97779922efe03268deaf669a5a4eaa8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 16:46:58 -0600 Subject: Fleshing out the exec function which require GIO Unix --- configure.ac | 2 + libindicator/indicator-desktop-shortcuts.c | 61 +++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a816206..698f6c7 100644 --- a/configure.ac +++ b/configure.ac @@ -28,8 +28,10 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) GTK_REQUIRED_VERSION=2.18 DBUS_REQUIRED_VERSION=0.76 +GIO_UNIX_REQUIRED_VERSION=2.23 PKG_CHECK_MODULES(LIBINDICATOR, gtk+-2.0 >= $GTK_REQUIRED_VERSION + gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION dbus-glib-1 >= $DBUS_REQUIRED_VERSION) AC_SUBST(LIBINDICATOR_CFLAGS) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 226dec4..35efe4d 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -25,6 +25,7 @@ License along with this library. If not, see #include "config.h" #endif +#include #include "indicator-desktop-shortcuts.h" #define GROUP_SUFFIX "Shortcut Group" @@ -237,6 +238,64 @@ indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, cons gboolean indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gchar * nick) { + g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE); + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); + + g_return_val_if_fail(priv->keyfile != NULL, FALSE); + g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE); + + gchar * groupheader = g_strdup_printf("%s " GROUP_SUFFIX, nick); + if (!g_key_file_has_group(priv->keyfile, groupheader)) { + g_warning("The group for nick '%s' doesn't exist anymore.", nick); + g_free(groupheader); + return FALSE; + } + + if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_NAME, NULL)) { + g_warning("No name available for nick '%s'", nick); + g_free(groupheader); + return FALSE; + } + + if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL)) { + g_warning("No exec available for nick '%s'", nick); + g_free(groupheader); + return FALSE; + } + + /* Grab the name and the exec entries out of our current group */ + gchar * name = g_key_file_get_locale_string(priv->keyfile, + groupheader, + G_KEY_FILE_DESKTOP_KEY_NAME, + NULL, + NULL); + + gchar * exec = g_key_file_get_locale_string(priv->keyfile, + groupheader, + G_KEY_FILE_DESKTOP_KEY_EXEC, + NULL, + NULL); + + /* Build a new desktop file with the name and exec in the desktop + group. We have to do this with data as apparently there isn't + and add_group function in g_key_file. Go figure. */ + gchar * desktopdata = g_strdup_printf("[" G_KEY_FILE_DESKTOP_GROUP "]\n" + G_KEY_FILE_DESKTOP_KEY_NAME "=\"%s\"\n" + G_KEY_FILE_DESKTOP_KEY_EXEC "=\"%s\"\n", + name, exec); + + + g_free(name); g_free(exec); + + GKeyFile * launcher = g_key_file_new(); + g_key_file_load_from_data(launcher, desktopdata, -1, G_KEY_FILE_NONE, NULL); + g_free(desktopdata); + + GDesktopAppInfo * appinfo = g_desktop_app_info_new_from_keyfile(launcher); + gboolean launched = g_app_info_launch(G_APP_INFO(appinfo), NULL, NULL, NULL); + + g_object_unref(appinfo); + g_key_file_free(launcher); - return FALSE; + return launched; } -- cgit v1.2.3 From ae0b7bc73ee056f893c739e5dec1311f5bcd630f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Feb 2010 17:14:12 -0600 Subject: A basic property system. --- libindicator/indicator-desktop-shortcuts.c | 68 +++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 35efe4d..eceec51 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -40,6 +40,12 @@ struct _IndicatorDesktopShortcutsPrivate { GArray * nicks; }; +enum { + PROP_0, + PROP_DESKTOP_FILE, + PROP_IDENTITY +}; + #define INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_TYPE_DESKTOP_SHORTCUTS, IndicatorDesktopShortcutsPrivate)) @@ -47,6 +53,8 @@ static void indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsCla static void indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self); static void indicator_desktop_shortcuts_dispose (GObject *object); static void indicator_desktop_shortcuts_finalize (GObject *object); +static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); +static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); G_DEFINE_TYPE (IndicatorDesktopShortcuts, indicator_desktop_shortcuts, G_TYPE_OBJECT); @@ -61,6 +69,23 @@ indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsClass *klass) object_class->dispose = indicator_desktop_shortcuts_dispose; object_class->finalize = indicator_desktop_shortcuts_finalize; + /* Property funcs */ + object_class->set_property = set_property; + object_class->get_property = get_property; + + g_object_class_install_property(object_class, PROP_DESKTOP_FILE, + g_param_spec_string(PROP_DESKTOP_FILE_S, + "The path of the desktop file to read", + "A path to a desktop file that we'll look for shortcuts in.", + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property(object_class, PROP_IDENTITY, + g_param_spec_string(PROP_IDENTITY_S, + "The string that represents the identity that we're acting as.", + "Used to process ShowIn and NotShownIn fields of the desktop shortcust to get the proper list.", + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY)); + return; } @@ -87,7 +112,6 @@ indicator_desktop_shortcuts_dispose (GObject *object) g_key_file_free(priv->keyfile); priv->keyfile = NULL; } - G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->dispose (object); return; @@ -118,6 +142,48 @@ indicator_desktop_shortcuts_finalize (GObject *object) return; } +/* Sets one of the two properties we have, only at construction though */ +static void +set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) +{ + g_return_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(object)); + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(object); + + switch(prop_id) { + case PROP_DESKTOP_FILE: + break; + case PROP_IDENTITY: + break; + /* *********************** */ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + + return; +} + +/* Gets either the desktop file our the identity. */ +static void +get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) +{ + g_return_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(object)); + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(object); + + switch(prop_id) { + case PROP_DESKTOP_FILE: + break; + case PROP_IDENTITY: + break; + /* *********************** */ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + + return; +} + /* Looks through the nicks ot see if this one is in the list, and thus valid to use. */ static gboolean -- cgit v1.2.3 From 8b8c3f426b96071e3cf92b1236c6507586805647 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 08:20:01 -0600 Subject: Some error handling. --- libindicator/indicator-desktop-shortcuts.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index eceec51..bfd8719 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -304,6 +304,8 @@ indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, cons gboolean indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gchar * nick) { + GError * error = NULL; + g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE); IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); @@ -354,11 +356,24 @@ indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gc g_free(name); g_free(exec); GKeyFile * launcher = g_key_file_new(); - g_key_file_load_from_data(launcher, desktopdata, -1, G_KEY_FILE_NONE, NULL); + g_key_file_load_from_data(launcher, desktopdata, -1, G_KEY_FILE_NONE, &error); g_free(desktopdata); + if (error != NULL) { + g_warning("Unable to build desktop keyfile for executing shortcut '%s': %s", nick, error->message); + g_error_free(error); + return FALSE; + } + GDesktopAppInfo * appinfo = g_desktop_app_info_new_from_keyfile(launcher); - gboolean launched = g_app_info_launch(G_APP_INFO(appinfo), NULL, NULL, NULL); + gboolean launched = g_app_info_launch(G_APP_INFO(appinfo), NULL, NULL, &error); + + if (error != NULL) { + g_warning("Unable to launch file from nick '%s': %s", nick, error->message); + g_error_free(error); + g_key_file_free(launcher); + return FALSE; + } g_object_unref(appinfo); g_key_file_free(launcher); -- cgit v1.2.3 From 37a107b59320377772c52e03db294614b08a2022 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 08:22:57 -0600 Subject: Identity management with the properties. --- libindicator/indicator-desktop-shortcuts.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index bfd8719..9f31c5d 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -153,6 +153,11 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec case PROP_DESKTOP_FILE: break; case PROP_IDENTITY: + if (priv->identity != NULL) { + g_warning("Identity already set to '%s' and trying to set it to '%s'.", priv->identity, g_value_get_string(value)); + return; + } + priv->identity = g_value_dup_string(value); break; /* *********************** */ default: @@ -174,6 +179,7 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe case PROP_DESKTOP_FILE: break; case PROP_IDENTITY: + g_value_set_string(value, priv->identity); break; /* *********************** */ default: -- cgit v1.2.3 From 62876d9ec2775b052493ada9e0b03e557c5ca4bb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 08:25:10 -0600 Subject: Removing the reading of the desktop file. --- libindicator/indicator-desktop-shortcuts.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 9f31c5d..07fa40a 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -78,7 +78,7 @@ indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsClass *klass) "The path of the desktop file to read", "A path to a desktop file that we'll look for shortcuts in.", NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property(object_class, PROP_IDENTITY, g_param_spec_string(PROP_IDENTITY_S, "The string that represents the identity that we're acting as.", @@ -176,8 +176,6 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(object); switch(prop_id) { - case PROP_DESKTOP_FILE: - break; case PROP_IDENTITY: g_value_set_string(value, priv->identity); break; -- cgit v1.2.3 From 55145548b36ce11274eb7083760a0913c6731615 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 08:46:22 -0600 Subject: Start loading the keyfile. --- libindicator/indicator-desktop-shortcuts.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 07fa40a..a87316f 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -55,6 +55,7 @@ static void indicator_desktop_shortcuts_dispose (GObject *object); static void indicator_desktop_shortcuts_finalize (GObject *object); static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static void parse_keyfile (IndicatorDesktopShortcuts * ids); G_DEFINE_TYPE (IndicatorDesktopShortcuts, indicator_desktop_shortcuts, G_TYPE_OBJECT); @@ -150,14 +151,28 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(object); switch(prop_id) { - case PROP_DESKTOP_FILE: + case PROP_DESKTOP_FILE: { + GError * error = NULL; + GKeyFile * keyfile = g_key_file_new(); + g_key_file_load_from_file(keyfile, g_value_get_string(value), G_KEY_FILE_NONE, &error); + + if (error != NULL) { + g_warning("Unable to load keyfile from file '%s': %s", g_value_get_string(value), error->message); + g_error_free(error); + g_key_file_free(keyfile); + } + + priv->keyfile = keyfile; + parse_keyfile(INDICATOR_DESKTOP_SHORTCUTS(object)); break; + } case PROP_IDENTITY: if (priv->identity != NULL) { g_warning("Identity already set to '%s' and trying to set it to '%s'.", priv->identity, g_value_get_string(value)); return; } priv->identity = g_value_dup_string(value); + parse_keyfile(INDICATOR_DESKTOP_SHORTCUTS(object)); break; /* *********************** */ default: @@ -188,6 +203,15 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe return; } +/* Checks to see if we can, and if we can it goes through + and parses the keyfile entries. */ +static void +parse_keyfile (IndicatorDesktopShortcuts * ids) +{ + + return; +} + /* Looks through the nicks ot see if this one is in the list, and thus valid to use. */ static gboolean -- cgit v1.2.3 From 21c3a88382bb4a1e911456c633aa4730bbb7cdff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 09:39:59 -0600 Subject: Checking for our shortcuts key, we don't really want a desktop file without it. --- libindicator/indicator-desktop-shortcuts.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index a87316f..eeb97be 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -29,6 +29,7 @@ License along with this library. If not, see #include "indicator-desktop-shortcuts.h" #define GROUP_SUFFIX "Shortcut Group" +#define SHORTCUTS_KEY "X-Ayatana-Desktop-Shortcuts" #define PROP_DESKTOP_FILE_S "desktop-file" #define PROP_IDENTITY_S "identity" @@ -160,6 +161,13 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec g_warning("Unable to load keyfile from file '%s': %s", g_value_get_string(value), error->message); g_error_free(error); g_key_file_free(keyfile); + break; + } + + if (!g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, SHORTCUTS_KEY, NULL)) { + g_warning("Keyfile from file '%s' does not have '" SHORTCUTS_KEY "' key", g_value_get_string(value)); + g_key_file_free(keyfile); + break; } priv->keyfile = keyfile; -- cgit v1.2.3 From 4ee953a0feaa4be188ef097dcd710647689a1b38 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 10:41:58 -0600 Subject: Basic parsing of the files. --- libindicator/indicator-desktop-shortcuts.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index eeb97be..b46b115 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -216,6 +216,34 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe static void parse_keyfile (IndicatorDesktopShortcuts * ids) { + IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); + + if (priv->keyfile == NULL) { + return; + } + + if (priv->identity == NULL) { + return; + } + + /* Okay, we've got everything we need. Let's get it on! */ + gint i; + gsize num_nicks = 0; + gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, SHORTCUTS_KEY, &num_nicks, NULL); + + /* If there is an error from get_string_list num_nicks should still + be zero, so this loop will drop out. */ + for (i = 0; i < num_nicks; i++) { + gchar * groupname = g_strdup_printf("%s" GROUP_SUFFIX, nicks[i]); + if (!g_key_file_has_group(priv->keyfile, groupname)) { + g_warning("Unable to find group '%s'", groupname); + g_free(groupname); + continue; + } + + gchar * nickalloc = g_strdup(nicks[i]); + g_array_append_val(priv->nicks, nickalloc); + } return; } -- cgit v1.2.3 From a39d426865186205de6bdd18d7a28748636476fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 10:53:08 -0600 Subject: Adding in checking to see if we should be showing this entry. --- libindicator/indicator-desktop-shortcuts.c | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index b46b115..cc56e61 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -241,6 +241,44 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) continue; } + /* If there is a list of OnlyShowIn entries we need to check + to see if we're in that list. If not, we drop this nick */ + if (g_key_file_has_key(priv->keyfile, groupname, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, NULL)) { + gint j; + gsize num_only = 0; + gchar ** onlies = g_key_file_get_string_list(priv->keyfile, groupname, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, &num_only, NULL); + + for (j = 0; j < num_only; j++) { + if (g_strcmp0(onlies[i], priv->identity) == 0) { + break; + } + } + + if (j == num_only) { + g_free(groupname); + break; + } + } + + /* If there is a NotShowIn entry we need to make sure that we're + not in that list. If we are, we need to drop out. */ + if (g_key_file_has_key(priv->keyfile, groupname, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, NULL)) { + gint j; + gsize num_not = 0; + gchar ** nots = g_key_file_get_string_list(priv->keyfile, groupname, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, &num_not, NULL); + + for (j = 0; j < num_not; j++) { + if (g_strcmp0(nots[i], priv->identity) == 0) { + break; + } + } + + if (j != num_not) { + g_free(groupname); + break; + } + } + gchar * nickalloc = g_strdup(nicks[i]); g_array_append_val(priv->nicks, nickalloc); } -- cgit v1.2.3 From 8fb1d365d8e8381e3ae62f06fba5fe3632bb387d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 11:02:53 -0600 Subject: Refactoring the list checks into their own functions so we can check the desktop group as well. --- libindicator/indicator-desktop-shortcuts.c | 91 ++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index cc56e61..da54536 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -57,6 +57,7 @@ static void indicator_desktop_shortcuts_finalize (GObject *object); static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static void parse_keyfile (IndicatorDesktopShortcuts * ids); +static gboolean should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity); G_DEFINE_TYPE (IndicatorDesktopShortcuts, indicator_desktop_shortcuts, G_TYPE_OBJECT); @@ -241,49 +242,77 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) continue; } - /* If there is a list of OnlyShowIn entries we need to check - to see if we're in that list. If not, we drop this nick */ - if (g_key_file_has_key(priv->keyfile, groupname, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, NULL)) { - gint j; - gsize num_only = 0; - gchar ** onlies = g_key_file_get_string_list(priv->keyfile, groupname, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, &num_only, NULL); - - for (j = 0; j < num_only; j++) { - if (g_strcmp0(onlies[i], priv->identity) == 0) { - break; - } - } + if (!should_show(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, priv->identity)) { + g_free(groupname); + break; + } + + if (!should_show(priv->keyfile, groupname, priv->identity)) { + g_free(groupname); + break; + } - if (j == num_only) { - g_free(groupname); + gchar * nickalloc = g_strdup(nicks[i]); + g_array_append_val(priv->nicks, nickalloc); + } + + if (nicks != NULL) { + g_strfreev(nicks); + } + + return; +} + +/* Checks the ONLY_SHOW_IN and NOT_SHOW_IN keys for a group to + see if we should be showing ourselves. */ +static gboolean +should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity) +{ + /* If there is a list of OnlyShowIn entries we need to check + to see if we're in that list. If not, we drop this nick */ + if (g_key_file_has_key(keyfile, group, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, NULL)) { + gint j; + gsize num_only = 0; + gchar ** onlies = g_key_file_get_string_list(keyfile, group, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, &num_only, NULL); + + for (j = 0; j < num_only; j++) { + if (g_strcmp0(onlies[j], identity) == 0) { break; } } - /* If there is a NotShowIn entry we need to make sure that we're - not in that list. If we are, we need to drop out. */ - if (g_key_file_has_key(priv->keyfile, groupname, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, NULL)) { - gint j; - gsize num_not = 0; - gchar ** nots = g_key_file_get_string_list(priv->keyfile, groupname, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, &num_not, NULL); - - for (j = 0; j < num_not; j++) { - if (g_strcmp0(nots[i], priv->identity) == 0) { - break; - } - } + if (onlies != NULL) { + g_strfreev(onlies); + } + + if (j == num_only) { + return FALSE; + } + } - if (j != num_not) { - g_free(groupname); + /* If there is a NotShowIn entry we need to make sure that we're + not in that list. If we are, we need to drop out. */ + if (g_key_file_has_key(keyfile, group, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, NULL)) { + gint j; + gsize num_not = 0; + gchar ** nots = g_key_file_get_string_list(keyfile, group, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, &num_not, NULL); + + for (j = 0; j < num_not; j++) { + if (g_strcmp0(nots[j], identity) == 0) { break; } } - gchar * nickalloc = g_strdup(nicks[i]); - g_array_append_val(priv->nicks, nickalloc); + if (nots != NULL) { + g_strfreev(nots); + } + + if (j != num_not) { + return FALSE; + } } - return; + return TRUE; } /* Looks through the nicks ot see if this one is in the list, -- cgit v1.2.3 From 1a85eb2ce73907d4f9b11a05efbc3f5c2c77e82a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 15:13:29 -0600 Subject: Create a testing desktop file --- tests/keyfile-well-formed.desktop | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/keyfile-well-formed.desktop diff --git a/tests/keyfile-well-formed.desktop b/tests/keyfile-well-formed.desktop new file mode 100644 index 0000000..fc906a3 --- /dev/null +++ b/tests/keyfile-well-formed.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Name=My Application +Exec=ls +NotShowIn=Germany +X-Ayatana-Desktop-Shortcuts=bob;alvin;jim + +[bob Shortcut Group] +Name=Bob's shortcut +Exec=ls bob + +[alvin Shortcut Group] +Name=Alivin's shortcut +Exec=ls alvin +OnlyShowIn=France + +[jim Shortcut Group] +Name=Jim's shortcut +Exec=ls jim +NotShowIn=France + -- cgit v1.2.3 From 53c9f60b7438764853c54d977a37b267bdf64485 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 15:24:51 -0600 Subject: Adding in a basic test desktop file test --- tests/Makefile.am | 35 +++++++++++++++++++++++++++++++++++ tests/test-desktop-shortcuts.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/test-desktop-shortcuts.c diff --git a/tests/Makefile.am b/tests/Makefile.am index b111655..ab776a9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,6 +33,41 @@ test_loader_LDADD = \ -L$(top_builddir)/libindicator/.libs \ -lindicator +############################# +# Test Desktop Shortcuts +############################# + +check_PROGRAMS += test-desktop-shortcuts + +test_desktop_shortcuts_SOURCES = \ + test-desktop-shortcuts.c + +test_desktop_shortcuts_CFLAGS = \ + -Wall -Werror \ + -DSRCDIR="\"$(srcdir)\"" \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) \ + -DBUILD_DIR="\"$(builddir)\"" + +test_desktop_shortcuts_LDADD = \ + $(LIBINDICATOR_LIBS) \ + -L$(top_builddir)/libindicator/.libs \ + -lindicator + +DS_XML_REPORT = desktop-shortcuts-check-results.xml +DS_HTML_REPORT = desktop-shortcuts-check-results.html + +test-desktop-shortcuts-tester: test-desktop-shortcuts Makefile.am + @echo "#!/bin/bash" > $@ + @echo $(XVFB_RUN) >> $@ + @echo gtester -k --verbose -o=$(XML_REPORT) ./test-desktop-shortcuts >> $@ + @chmod +x $@ + +TESTS += test-desktop-shortcuts-tester +DISTCLEANFILES += test-desktop-shortcuts-tester \ + $(DS_XML_REPORT) + $(DS_HTML_REPORT) + + ############################# # Dummy Indicator Blank ############################# diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c new file mode 100644 index 0000000..3368c9e --- /dev/null +++ b/tests/test-desktop-shortcuts.c @@ -0,0 +1,38 @@ +#include +#include "libindicator/indicator-desktop-shortcuts.h" + +void +test_desktop_shortcuts_creation (void) +{ + + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France"); + g_assert(ids != NULL); + + g_object_add_weak_pointer(G_OBJECT(ids), (gpointer *)&ids); + g_object_unref(G_OBJECT(ids)); + + g_assert(ids == NULL); + return; +} + +void +test_desktop_shortcuts_suite (void) +{ + g_test_add_func ("/libindicator/desktopshortcuts/creation", test_desktop_shortcuts_creation); + + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + gtk_init(&argc, &argv); + + test_desktop_shortcuts_suite(); + + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + + return g_test_run(); +} -- cgit v1.2.3 From 0a4d6689dccccc0556c4ec811e2783442a97fae9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 15:26:03 -0600 Subject: A backslash off --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index ab776a9..c7c9a1d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -64,7 +64,7 @@ test-desktop-shortcuts-tester: test-desktop-shortcuts Makefile.am TESTS += test-desktop-shortcuts-tester DISTCLEANFILES += test-desktop-shortcuts-tester \ - $(DS_XML_REPORT) + $(DS_XML_REPORT) \ $(DS_HTML_REPORT) -- cgit v1.2.3 From 17cdd8ca932b4bab811bc0f7b53795588bb2bc12 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 15:26:30 -0600 Subject: Ignoring the new stuff --- .bzrignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bzrignore b/.bzrignore index 85d91ed..97d9904 100644 --- a/.bzrignore +++ b/.bzrignore @@ -148,3 +148,5 @@ libindicator/indicator-object-marshal.h libindicator/libindicator_la-indicator-object-marshal.lo libindicator/stamp-marshal libindicator/libindicator_la-indicator-desktop-shortcuts.lo +tests/test-desktop-shortcuts +tests/test-desktop-shortcuts-tester -- cgit v1.2.3 From 755e697c2ba60010ea0fde875047a98c4f759513 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 15:27:18 -0600 Subject: Better name --- tests/keyfile-well-formed.desktop | 20 -------------------- tests/test-well-formed.desktop | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 tests/keyfile-well-formed.desktop create mode 100644 tests/test-well-formed.desktop diff --git a/tests/keyfile-well-formed.desktop b/tests/keyfile-well-formed.desktop deleted file mode 100644 index fc906a3..0000000 --- a/tests/keyfile-well-formed.desktop +++ /dev/null @@ -1,20 +0,0 @@ -[Desktop Entry] -Name=My Application -Exec=ls -NotShowIn=Germany -X-Ayatana-Desktop-Shortcuts=bob;alvin;jim - -[bob Shortcut Group] -Name=Bob's shortcut -Exec=ls bob - -[alvin Shortcut Group] -Name=Alivin's shortcut -Exec=ls alvin -OnlyShowIn=France - -[jim Shortcut Group] -Name=Jim's shortcut -Exec=ls jim -NotShowIn=France - diff --git a/tests/test-well-formed.desktop b/tests/test-well-formed.desktop new file mode 100644 index 0000000..fc906a3 --- /dev/null +++ b/tests/test-well-formed.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Name=My Application +Exec=ls +NotShowIn=Germany +X-Ayatana-Desktop-Shortcuts=bob;alvin;jim + +[bob Shortcut Group] +Name=Bob's shortcut +Exec=ls bob + +[alvin Shortcut Group] +Name=Alivin's shortcut +Exec=ls alvin +OnlyShowIn=France + +[jim Shortcut Group] +Name=Jim's shortcut +Exec=ls jim +NotShowIn=France + -- cgit v1.2.3 From 0a90515d6fbbaed9485f00db544ce1b4b23a8f7e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 15:28:29 -0600 Subject: Fix group detection to put a space in the name of the group --- libindicator/indicator-desktop-shortcuts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index da54536..b6d5b1c 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -235,7 +235,7 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) /* If there is an error from get_string_list num_nicks should still be zero, so this loop will drop out. */ for (i = 0; i < num_nicks; i++) { - gchar * groupname = g_strdup_printf("%s" GROUP_SUFFIX, nicks[i]); + gchar * groupname = g_strdup_printf("%s " GROUP_SUFFIX, nicks[i]); if (!g_key_file_has_group(priv->keyfile, groupname)) { g_warning("Unable to find group '%s'", groupname); g_free(groupname); -- cgit v1.2.3 From edaa80e3a3fe85b11cb193179e7e7f5b1e9d310a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 21:16:02 -0600 Subject: Check to ensure a global no show works. --- tests/test-desktop-shortcuts.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c index 3368c9e..621721b 100644 --- a/tests/test-desktop-shortcuts.c +++ b/tests/test-desktop-shortcuts.c @@ -15,10 +15,26 @@ test_desktop_shortcuts_creation (void) return; } +void +test_desktop_shortcuts_globalnoshow (void) +{ + + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "Germany"); + g_assert(ids != NULL); + + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); + g_assert(nicks[0] == NULL); + + g_object_unref(ids); + + return; +} + void test_desktop_shortcuts_suite (void) { - g_test_add_func ("/libindicator/desktopshortcuts/creation", test_desktop_shortcuts_creation); + g_test_add_func ("/libindicator/desktopshortcuts/creation", test_desktop_shortcuts_creation); + g_test_add_func ("/libindicator/desktopshortcuts/globalnosho", test_desktop_shortcuts_globalnoshow); return; } -- cgit v1.2.3 From b6b2a65e651701650c2dbd6b99b5c44ec2dfb534 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 21:23:59 -0600 Subject: Adding in local filter test functions. --- tests/test-desktop-shortcuts.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c index 621721b..6dab100 100644 --- a/tests/test-desktop-shortcuts.c +++ b/tests/test-desktop-shortcuts.c @@ -1,6 +1,8 @@ #include #include "libindicator/indicator-desktop-shortcuts.h" +/* Basic object creation and destruction. Stop big + f*** ups here. */ void test_desktop_shortcuts_creation (void) { @@ -15,6 +17,8 @@ test_desktop_shortcuts_creation (void) return; } +/* Tests that the NotShowIn the desktop group is watched + for */ void test_desktop_shortcuts_globalnoshow (void) { @@ -30,11 +34,40 @@ test_desktop_shortcuts_globalnoshow (void) return; } +gboolean +nicks_contains (const gchar ** nicks, const gchar * search) +{ + if (nicks[0] == NULL) + return FALSE; + if (g_strcmp0(nicks[0], search) == 0) + return TRUE; + return nicks_contains(&nicks[1], search); +} + +/* Checking that the local show OnlyIn works. */ +void +test_desktop_shortcuts_localfilter (void) +{ + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France"); + g_assert(ids != NULL); + + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); + + g_assert(nicks_contains(nicks, "bob")); + g_assert(nicks_contains(nicks, "alvin")); + g_assert(!nicks_contains(nicks, "jim")); + + g_object_unref(ids); + + return; +} + void test_desktop_shortcuts_suite (void) { g_test_add_func ("/libindicator/desktopshortcuts/creation", test_desktop_shortcuts_creation); g_test_add_func ("/libindicator/desktopshortcuts/globalnosho", test_desktop_shortcuts_globalnoshow); + g_test_add_func ("/libindicator/desktopshortcuts/localfilter", test_desktop_shortcuts_localfilter); return; } -- cgit v1.2.3 From c636c3e6adb411281646a446866ea0e737b6ba99 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 21:31:33 -0600 Subject: Making the function not recurse forever. --- libindicator/indicator-desktop-shortcuts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index b6d5b1c..988e78e 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -322,9 +322,9 @@ is_valid_nick (gchar ** list, const gchar * nick) { if (*list == NULL) return FALSE; - if (g_strcmp0(*list, nick) == 0) + if (g_strcmp0(list[0], nick) == 0) return TRUE; - return is_valid_nick(list++, nick); + return is_valid_nick(&list[1], nick); } /* API */ -- cgit v1.2.3 From e0bc1911d9618a2d8ac4d1d93de3e7f81d1a14ae Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 21:34:30 -0600 Subject: Adding a check to ensure we're getting the right names from the nicks. --- tests/test-desktop-shortcuts.c | 32 +++++++++++++++++++++++++++++++- tests/test-well-formed.desktop | 4 ++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c index 6dab100..02137ef 100644 --- a/tests/test-desktop-shortcuts.c +++ b/tests/test-desktop-shortcuts.c @@ -62,12 +62,42 @@ test_desktop_shortcuts_localfilter (void) return; } +/* Nick names -- checks to see they all have names */ +void +test_desktop_shortcuts_nicknames (void) +{ + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "France"); + g_assert(ids != NULL); + + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); + gint i = 0; + while (nicks[i] != NULL) { + gchar * expectedstr = g_strdup_printf("%s's shortcut", nicks[i]); + gchar * name = indicator_desktop_shortcuts_nick_get_name(ids, nicks[i]); + g_assert(name != NULL); + + gboolean same = (g_strcmp0(expectedstr, name) == 0); + + g_free(name); + g_free(expectedstr); + + g_assert(same); + + i++; + } + + + g_object_unref(ids); + + return; +} + void test_desktop_shortcuts_suite (void) { g_test_add_func ("/libindicator/desktopshortcuts/creation", test_desktop_shortcuts_creation); g_test_add_func ("/libindicator/desktopshortcuts/globalnosho", test_desktop_shortcuts_globalnoshow); - g_test_add_func ("/libindicator/desktopshortcuts/localfilter", test_desktop_shortcuts_localfilter); + g_test_add_func ("/libindicator/desktopshortcuts/nicknames", test_desktop_shortcuts_nicknames); return; } diff --git a/tests/test-well-formed.desktop b/tests/test-well-formed.desktop index fc906a3..dc2744f 100644 --- a/tests/test-well-formed.desktop +++ b/tests/test-well-formed.desktop @@ -5,11 +5,11 @@ NotShowIn=Germany X-Ayatana-Desktop-Shortcuts=bob;alvin;jim [bob Shortcut Group] -Name=Bob's shortcut +Name=bob's shortcut Exec=ls bob [alvin Shortcut Group] -Name=Alivin's shortcut +Name=alvin's shortcut Exec=ls alvin OnlyShowIn=France -- cgit v1.2.3 From af36cb86cf0cb671cd8521e66562341a2a015fd1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 21:40:50 -0600 Subject: Add a test to launch an nick --- tests/test-desktop-shortcuts.c | 20 ++++++++++++++++++++ tests/test-well-formed.desktop | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c index 02137ef..7594e51 100644 --- a/tests/test-desktop-shortcuts.c +++ b/tests/test-desktop-shortcuts.c @@ -92,12 +92,32 @@ test_desktop_shortcuts_nicknames (void) return; } +/* Try executing a shortcut which will touch a file */ +void +test_desktop_shortcuts_launch (void) +{ + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "Touch"); + g_assert(ids != NULL); + + const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); + g_assert(nicks[0] != NULL); + + g_assert(indicator_desktop_shortcuts_nick_exec(ids, nicks[0])); + g_assert(g_file_test("test-desktop-shortcuts-touch-test", G_FILE_TEST_EXISTS)); + + g_object_unref(ids); + + return; +} + +/* Build our test suite */ void test_desktop_shortcuts_suite (void) { g_test_add_func ("/libindicator/desktopshortcuts/creation", test_desktop_shortcuts_creation); g_test_add_func ("/libindicator/desktopshortcuts/globalnosho", test_desktop_shortcuts_globalnoshow); g_test_add_func ("/libindicator/desktopshortcuts/nicknames", test_desktop_shortcuts_nicknames); + g_test_add_func ("/libindicator/desktopshortcuts/launch", test_desktop_shortcuts_launch); return; } diff --git a/tests/test-well-formed.desktop b/tests/test-well-formed.desktop index dc2744f..84e2e02 100644 --- a/tests/test-well-formed.desktop +++ b/tests/test-well-formed.desktop @@ -2,7 +2,7 @@ Name=My Application Exec=ls NotShowIn=Germany -X-Ayatana-Desktop-Shortcuts=bob;alvin;jim +X-Ayatana-Desktop-Shortcuts=bob;alvin;jim;touch [bob Shortcut Group] Name=bob's shortcut @@ -18,3 +18,7 @@ Name=Jim's shortcut Exec=ls jim NotShowIn=France +[touch Shortcut Group] +Name=Touch Test +Exec=touch test-desktop-shortcuts-touch-test +OnlyShowIn=TouchTest -- cgit v1.2.3 From 452c195c4ec87b3e269feb2ae8124ede30da5e33 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:05:08 -0600 Subject: Forgot to set the type of the desktop file, need to be an Application. --- libindicator/indicator-desktop-shortcuts.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 988e78e..4cebbf2 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -479,8 +479,9 @@ indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gc group. We have to do this with data as apparently there isn't and add_group function in g_key_file. Go figure. */ gchar * desktopdata = g_strdup_printf("[" G_KEY_FILE_DESKTOP_GROUP "]\n" - G_KEY_FILE_DESKTOP_KEY_NAME "=\"%s\"\n" - G_KEY_FILE_DESKTOP_KEY_EXEC "=\"%s\"\n", + G_KEY_FILE_DESKTOP_KEY_TYPE "=" G_KEY_FILE_DESKTOP_TYPE_APPLICATION "\n" + G_KEY_FILE_DESKTOP_KEY_NAME "=%s\n" + G_KEY_FILE_DESKTOP_KEY_EXEC "=%s\n", name, exec); @@ -497,6 +498,12 @@ indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gc } GDesktopAppInfo * appinfo = g_desktop_app_info_new_from_keyfile(launcher); + if (appinfo == NULL) { + g_warning("Unable to build Desktop App info (unknown)"); + g_key_file_free(launcher); + return FALSE; + } + gboolean launched = g_app_info_launch(G_APP_INFO(appinfo), NULL, NULL, &error); if (error != NULL) { -- cgit v1.2.3 From b0e8d1c61b0558f67478e51dd680cd00f87baee2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:07:38 -0600 Subject: Wrong identity --- tests/test-desktop-shortcuts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c index 7594e51..a7b57d3 100644 --- a/tests/test-desktop-shortcuts.c +++ b/tests/test-desktop-shortcuts.c @@ -96,7 +96,7 @@ test_desktop_shortcuts_nicknames (void) void test_desktop_shortcuts_launch (void) { - IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "Touch"); + IndicatorDesktopShortcuts * ids = indicator_desktop_shortcuts_new(SRCDIR "/test-well-formed.desktop", "TouchTest"); g_assert(ids != NULL); const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); -- cgit v1.2.3 From b10dd199a267842284f9baaf9e6e065ed9bad109 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:21:29 -0600 Subject: Using the nick directly to make this work better. --- tests/test-desktop-shortcuts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c index a7b57d3..a4e767a 100644 --- a/tests/test-desktop-shortcuts.c +++ b/tests/test-desktop-shortcuts.c @@ -100,9 +100,9 @@ test_desktop_shortcuts_launch (void) g_assert(ids != NULL); const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); - g_assert(nicks[0] != NULL); + g_assert(nicks != NULL); - g_assert(indicator_desktop_shortcuts_nick_exec(ids, nicks[0])); + g_assert(indicator_desktop_shortcuts_nick_exec(ids, "touch")); g_assert(g_file_test("test-desktop-shortcuts-touch-test", G_FILE_TEST_EXISTS)); g_object_unref(ids); -- cgit v1.2.3 From 0aa8119e4813f84d5c0f1a8001bce69518d1d756 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:35:03 -0600 Subject: Checking to ensure the right nick is in the list --- libindicator/indicator-desktop-shortcuts.c | 2 ++ tests/test-desktop-shortcuts.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 4cebbf2..22aed73 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -322,6 +322,7 @@ is_valid_nick (gchar ** list, const gchar * nick) { if (*list == NULL) return FALSE; + g_debug("Checking Nick: %s", list[0]); if (g_strcmp0(list[0], nick) == 0) return TRUE; return is_valid_nick(&list[1], nick); @@ -486,6 +487,7 @@ indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gc g_free(name); g_free(exec); + g_debug("Desktop file: \n%s", desktopdata); GKeyFile * launcher = g_key_file_new(); g_key_file_load_from_data(launcher, desktopdata, -1, G_KEY_FILE_NONE, &error); diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c index a4e767a..c2344db 100644 --- a/tests/test-desktop-shortcuts.c +++ b/tests/test-desktop-shortcuts.c @@ -100,7 +100,7 @@ test_desktop_shortcuts_launch (void) g_assert(ids != NULL); const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(ids); - g_assert(nicks != NULL); + g_assert(nicks_contains(nicks, "touch")); g_assert(indicator_desktop_shortcuts_nick_exec(ids, "touch")); g_assert(g_file_test("test-desktop-shortcuts-touch-test", G_FILE_TEST_EXISTS)); -- cgit v1.2.3 From 7e69f61eb09bc73067a4cf963b2fe4c44bf936a1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:39:45 -0600 Subject: Clean up touch file --- tests/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index c7c9a1d..1f000bd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -64,6 +64,7 @@ test-desktop-shortcuts-tester: test-desktop-shortcuts Makefile.am TESTS += test-desktop-shortcuts-tester DISTCLEANFILES += test-desktop-shortcuts-tester \ + test-desktop-shortcuts-touch-test \ $(DS_XML_REPORT) \ $(DS_HTML_REPORT) -- cgit v1.2.3 From ef9c19ed6aec8a078a612a9e9b069934bf262b80 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:43:11 -0600 Subject: Shipping our test desktop file --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 1f000bd..cd1a958 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -67,7 +67,7 @@ DISTCLEANFILES += test-desktop-shortcuts-tester \ test-desktop-shortcuts-touch-test \ $(DS_XML_REPORT) \ $(DS_HTML_REPORT) - +EXTRA_DIST += test-well-formed.desktop ############################# # Dummy Indicator Blank -- cgit v1.2.3 From a3e1058e63218921769470126b92bd1087eac1d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:43:45 -0600 Subject: We should look at the other nicks even if this one doesn't work. --- libindicator/indicator-desktop-shortcuts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 22aed73..e1670e3 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -244,12 +244,12 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) if (!should_show(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, priv->identity)) { g_free(groupname); - break; + continue; } if (!should_show(priv->keyfile, groupname, priv->identity)) { g_free(groupname); - break; + continue; } gchar * nickalloc = g_strdup(nicks[i]); -- cgit v1.2.3 From 5a75fb5b91de1e3660606f8143b0d0ac94e0ffb6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:43:55 -0600 Subject: Debug messages. --- libindicator/indicator-desktop-shortcuts.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index e1670e3..4f58835 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -235,6 +235,7 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) /* If there is an error from get_string_list num_nicks should still be zero, so this loop will drop out. */ for (i = 0; i < num_nicks; i++) { + g_debug("Looking at group nick %s", nicks[i]); gchar * groupname = g_strdup_printf("%s " GROUP_SUFFIX, nicks[i]); if (!g_key_file_has_group(priv->keyfile, groupname)) { g_warning("Unable to find group '%s'", groupname); -- cgit v1.2.3 From 3e69079ea6fda3e08b9548376014e8ea28ce0151 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:44:22 -0600 Subject: Disabling debug messages --- libindicator/indicator-desktop-shortcuts.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 4f58835..e86a6ab 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -235,7 +235,7 @@ parse_keyfile (IndicatorDesktopShortcuts * ids) /* If there is an error from get_string_list num_nicks should still be zero, so this loop will drop out. */ for (i = 0; i < num_nicks; i++) { - g_debug("Looking at group nick %s", nicks[i]); + /* g_debug("Looking at group nick %s", nicks[i]); */ gchar * groupname = g_strdup_printf("%s " GROUP_SUFFIX, nicks[i]); if (!g_key_file_has_group(priv->keyfile, groupname)) { g_warning("Unable to find group '%s'", groupname); @@ -323,7 +323,7 @@ is_valid_nick (gchar ** list, const gchar * nick) { if (*list == NULL) return FALSE; - g_debug("Checking Nick: %s", list[0]); + /* g_debug("Checking Nick: %s", list[0]); */ if (g_strcmp0(list[0], nick) == 0) return TRUE; return is_valid_nick(&list[1], nick); @@ -488,7 +488,7 @@ indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gc g_free(name); g_free(exec); - g_debug("Desktop file: \n%s", desktopdata); + /* g_debug("Desktop file: \n%s", desktopdata); */ GKeyFile * launcher = g_key_file_new(); g_key_file_load_from_data(launcher, desktopdata, -1, G_KEY_FILE_NONE, &error); -- cgit v1.2.3 From 1b58c66bcd65fa6fe7e59b62aa357cce38308fde Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:45:54 -0600 Subject: Being more specific about where we should find the touch file for distcheck --- tests/test-desktop-shortcuts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-desktop-shortcuts.c b/tests/test-desktop-shortcuts.c index c2344db..1a655f7 100644 --- a/tests/test-desktop-shortcuts.c +++ b/tests/test-desktop-shortcuts.c @@ -103,7 +103,7 @@ test_desktop_shortcuts_launch (void) g_assert(nicks_contains(nicks, "touch")); g_assert(indicator_desktop_shortcuts_nick_exec(ids, "touch")); - g_assert(g_file_test("test-desktop-shortcuts-touch-test", G_FILE_TEST_EXISTS)); + g_assert(g_file_test(BUILD_DIR "/test-desktop-shortcuts-touch-test", G_FILE_TEST_EXISTS)); g_object_unref(ids); -- cgit v1.2.3 From 6665fd01b1b85646f5c21aa393a3c3e6a8e4ab97 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:47:04 -0600 Subject: Ignoring the touch file for the testing --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index 97d9904..5d1c40e 100644 --- a/.bzrignore +++ b/.bzrignore @@ -150,3 +150,4 @@ libindicator/stamp-marshal libindicator/libindicator_la-indicator-desktop-shortcuts.lo tests/test-desktop-shortcuts tests/test-desktop-shortcuts-tester +tests/test-desktop-shortcuts-touch-test -- cgit v1.2.3 From fdc2872ab554e4e468b3cab47dd9c25ac0fbfa47 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Feb 2010 22:52:10 -0600 Subject: releasing version 0.3.2-0ubuntu1~ppa2~shortcuts1 --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index f7b15c8..76acb02 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,9 @@ -libindicator (0.3.2-0ubuntu1~ppa2~shortcuts1) UNRELEASED; urgency=low +libindicator (0.3.2-0ubuntu1~ppa2~shortcuts1) lucid; urgency=low * Upstream merge * Adding new object for parsing desktop files for Shortcuts - -- Ted Gould Tue, 16 Feb 2010 22:50:39 -0600 + -- Ted Gould Tue, 16 Feb 2010 22:52:07 -0600 libindicator (0.3.2-0ubuntu1~ppa1) lucid; urgency=low -- cgit v1.2.3