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. --- libindicator/indicator-desktop-shortcuts.h | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 libindicator/indicator-desktop-shortcuts.h (limited to 'libindicator/indicator-desktop-shortcuts.h') 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(+) (limited to 'libindicator/indicator-desktop-shortcuts.h') 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(-) (limited to 'libindicator/indicator-desktop-shortcuts.h') 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(-) (limited to 'libindicator/indicator-desktop-shortcuts.h') 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 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(-) (limited to 'libindicator/indicator-desktop-shortcuts.h') 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(-) (limited to 'libindicator/indicator-desktop-shortcuts.h') 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