[atomato] Added local changes from my SVN checkout
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Subject: [atomato] Added local changes from my SVN checkout
- Date: Sun, 3 May 2009 15:39:34 -0400 (EDT)
commit a2fc40fd50453f35678ca48e42b81a6647b679a2
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Sun May 3 21:39:23 2009 +0200
Added local changes from my SVN checkout
---
ChangeLog | 5 +
configure.in | 1 +
libatomato/Makefile.am | 7 +-
libatomato/atomato-action-provider.c | 31 +----
libatomato/atomato-action-provider.h | 14 +--
libatomato/atomato-action.c | 146 ++++++++------------
libatomato/atomato.c | 146 ++++----------------
libatomato/atomato.h | 37 +-----
libatomato/dbus-action-provider.c | 186 +++++++++++++++++++++-----
libatomato/shell-action-provider.c | 220 +++++++++++++++++++++++++++--
services/desktop/Makefile.am | 7 +-
services/desktop/desktop-session.atomato | 21 ---
src/main-window.c | 11 +-
tests/test-list-actions.c | 6 +-
14 files changed, 479 insertions(+), 359 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4e9682d..ac11297 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,11 @@
* configure.in: Added "cs", "bn" and "pl" to ALL_LINGUAS.
+2008-06-16 Rodrigo Moya <rodrigo gnome-db org>
+
+ * libatomato/shell-action-provider.c (shell_action_provider_run_action):
+ added missing implementation
+
2008-03-23 Kostas Papadimas <pkst gnome org>
* configure.in: Added 'el' to ALL_LINGUAS.
diff --git a/configure.in b/configure.in
index db5eeb9..34c608d 100644
--- a/configure.in
+++ b/configure.in
@@ -31,6 +31,7 @@ DBUS_REQUIRED=0.60
PKG_CHECK_MODULES(ATOMATO,
glib-2.0 >= $GTK_REQUIRED
+ gobject-2.0 >= $GTK_REQUIRED
libxml-2.0
dbus-glib-1 >= $DBUS_REQUIRED)
AC_SUBST(ATOMATO_CFLAGS)
diff --git a/libatomato/Makefile.am b/libatomato/Makefile.am
index a0b7972..cb74272 100644
--- a/libatomato/Makefile.am
+++ b/libatomato/Makefile.am
@@ -1,9 +1,10 @@
-INCLUDES = \
+INCLUDES = \
+ -DATOMATO_ACTIONS_DIR=\"$(libdir)/atomato/actions\" \
$(ATOMATO_CFLAGS)
lib_LTLIBRARIES = libatomato.la
-DBUS_ACTION_PROVIDER_SRC = dbus-action-provider.c dbus-action-provider.h
+#DBUS_ACTION_PROVIDER_SRC = dbus-action-provider.c dbus-action-provider.h
libatomato_la_SOURCES = \
$(DBUS_ACTION_PROVIDER_SRC) \
@@ -12,6 +13,8 @@ libatomato_la_SOURCES = \
atomato-action.c \
atomato.c \
atomato.h \
+ dbus-action-provider.c \
+ dbus-action-provider.h \
shell-action-provider.c \
shell-action-provider.h
diff --git a/libatomato/atomato-action-provider.c b/libatomato/atomato-action-provider.c
index fd74cd0..98b6113 100644
--- a/libatomato/atomato-action-provider.c
+++ b/libatomato/atomato-action-provider.c
@@ -57,34 +57,15 @@ atomato_action_provider_get_type (void)
}
/**
- * atomato_action_provider_get_method:
+ * atomato_action_provider_get_actions:
* @provider: An action provider.
*
- * Returns the method implemented by the action provider to make calls to
- * actions.
+ * Gets the list of actions this provider has available.
*
- * Return value: The method implemented by the action provider.
+ * Return value: A list of AtomatoAction structs.
*/
-AtomatoMethod
-atomato_action_provider_get_method (AtomatoActionProvider *provider)
+GSList *
+atomato_action_provider_get_actions (AtomatoActionProvider *provider)
{
- return ATOMATO_ACTION_PROVIDER_GET_INTERFACE (provider)->get_method (provider);
-}
-
-/**
- * atomato_action_provider_run_action:
- * @provider: An action provider.
- * @action_name: The name of the action to be executed.
- * @input_args: Input arguments.
- *
- * Runs a specific action through the selected action provider implementation.
- *
- * Return value: An array with all output values returned from the action.
- */
-GValueArray *
-atomato_action_provider_run_action (AtomatoActionProvider *provider,
- AtomatoAction *action,
- const GValueArray *input_args)
-{
- return ATOMATO_ACTION_PROVIDER_GET_INTERFACE (provider)->run_action (provider, action, input_args);
+ return ATOMATO_ACTION_PROVIDER_GET_INTERFACE (provider)->get_actions (provider);
}
diff --git a/libatomato/atomato-action-provider.h b/libatomato/atomato-action-provider.h
index 2aa81a8..b9d0413 100644
--- a/libatomato/atomato-action-provider.h
+++ b/libatomato/atomato-action-provider.h
@@ -24,7 +24,7 @@
#define __ATOMATO_ACTION_PROVIDER_H__
#include <glib-object.h>
-#include "atomato.h"
+#include "atomato-action.h"
G_BEGIN_DECLS
@@ -42,18 +42,12 @@ struct _AtomatoActionProvider {
struct _AtomatoActionProviderInterface {
GTypeInterface parent;
- AtomatoMethod (* get_method) (AtomatoActionProvider *provider);
- GValueArray * (* run_action) (AtomatoActionProvider *provider,
- AtomatoAction *action,
- const GValueArray *input_args);
+ GList * (* get_actions) (AtomatoActionProvider *provider);
};
-GType atomato_action_provider_get_type (void);
+GType atomato_action_provider_get_type (void);
-AtomatoMethod atomato_action_provider_get_method (AtomatoActionProvider *provider);
-GValueArray *atomato_action_provider_run_action (AtomatoActionProvider *provider,
- AtomatoAction *action,
- const GValueArray *input_args);
+GSList *atomato_action_provider_get_actions (AtomatoActionProvider *provider);
G_END_DECLS
diff --git a/libatomato/atomato-action.c b/libatomato/atomato-action.c
index 9dea4db..2f07864 100644
--- a/libatomato/atomato-action.c
+++ b/libatomato/atomato-action.c
@@ -21,116 +21,88 @@
*/
#include <stdlib.h>
-#include <libxml/parser.h>
-#include "atomato.h"
+#include "atomato-action.h"
-static AtomatoAction *
-read_action_from_xml_node (xmlNodePtr node)
+static void
+atomato_action_base_init (gpointer g_class)
{
- AtomatoAction *action = NULL;
- gchar *str;
+ static gboolean initialized = FALSE;
- if (!node->name || strcmp (node->name, "action")) {
- g_warning ("Invalid action node");
- return NULL;
+ if (!initialized) {
+ /* Create signals for the interface */
+ initialized = TRUE;
}
+}
- action = g_new0 (AtomatoAction, 1);
- action->section = (gchar *) xmlGetProp (node, "section");
- action->name = (gchar *) xmlGetProp (node, "name");
- action->description = (gchar *) xmlGetProp (node, "description");
-
- str = (gchar *) xmlGetProp (node, "method");
- if (!strcmp (str, "shell"))
- action->method = ATOMATO_METHOD_SHELL;
- else if (!strcmp (str, "dbus"))
- action->method = ATOMATO_METHOD_DBUS;
- else {
- atomato_action_free (action);
- return NULL;
+GType
+atomato_action_get_type (void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof (AtomatoActionInterface),
+ atomato_action_base_init, /* base_init */
+ NULL, /* base_finalize */
+ NULL, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ 0,
+ 0, /* n_preallocs */
+ NULL /* instance_init */
+ };
+ type = g_type_register_static (G_TYPE_INTERFACE, "AtomatoAction", &info, 0);
}
- action->command = (gchar *) xmlGetProp (node, "command");
-
- return action;
+ return type;
}
/**
- * atomatio_read_action_file:
- * @filename: Full path of the file to parse.
- *
- * Read a .atomato file and converts it to a list of AtomatoAction objects.
- *
- * Return value: A list containing all actions in the file.
+ * atomato_action_get_name:
*/
-GSList *
-atomato_read_action_file (const gchar *filename)
+const gchar *
+atomato_action_get_name (AtomatoAction *action)
{
- GSList *list = NULL;
- xmlDocPtr doc;
- xmlNodePtr root, current_node;
-
- doc = xmlParseFile (filename);
- if (!doc) {
- g_warning ("Could not read %s file", filename);
- return NULL;
- }
-
- root = xmlDocGetRootElement (doc);
- if (!root) {
- g_warning ("Cannot get root element for %s", filename);
- xmlFreeDoc (doc);
- return NULL;
- }
-
- if (!root->name || strcmp ((const char *) root->name, "atomato")) {
- g_warning (" %s is not a valid Atomato XML file", filename);
- xmlFreeDoc (doc);
- return NULL;
- }
-
- /* now read the actions */
- for (current_node = root->xmlChildrenNode;
- current_node != NULL;
- current_node = current_node->next) {
- if (!strcmp (current_node->name, "action")) {
- AtomatoAction *action;
-
- action = read_action_from_xml_node (current_node);
- if (action)
- list = g_slist_append (list, action);
- }
- }
+ return ATOMATO_ACTION_GET_INTERFACE (action)->get_name (action);
+}
- return list;
+/**
+ * atomato_action_get_section:
+ */
+const gchar *
+atomato_action_get_section (AtomatoAction *action)
+{
+ return ATOMATO_ACTION_GET_INTERFACE (action)->get_section (action);
}
-void
-atomato_action_argument_free (AtomatoActionArgument *argument)
+/**
+ * atomato_action_get_description:
+ */
+const gchar *
+atomato_action_get_description (AtomatoAction *action)
{
- g_return_if_fail (argument != NULL);
+ return ATOMATO_ACTION_GET_INTERFACE (action)->get_description (action);
+}
- g_free (argument->name);
- g_free (argument);
+/**
+ * atomato_action_run:
+ */
+GValue *
+atomato_action_run (AtomatoAction *action, GValueArray *arguments)
+{
+ return ATOMATO_ACTION_GET_INTERFACE (action)->run (action, arguments);
}
/**
- * atomato_action_free:
+ * atomato_action_free_argument:
*/
void
-atomato_action_free (AtomatoAction *action)
+atomato_action_free_argument (AtomatoActionArgument *argument)
{
- g_return_if_fail (action != NULL);
-
- xmlFree (action->section);
- xmlFree (action->name);
- xmlFree (action->description);
-
- while (action->args != NULL) {
- atomato_action_argument_free ((AtomatoActionArgument *) action->args->data);
+ g_return_if_fail (argument != NULL);
- action->args = g_slist_remove (action->args, action->args);
- }
+ g_free (argument->name);
+ g_free (argument->description);
- g_free (action);
+ g_free (argument);
}
diff --git a/libatomato/atomato.c b/libatomato/atomato.c
index 4e819fb..4e89c07 100644
--- a/libatomato/atomato.c
+++ b/libatomato/atomato.c
@@ -24,85 +24,13 @@
#include "dbus-action-provider.h"
#include "shell-action-provider.h"
-static GHashTable *action_providers = NULL;
-static GHashTable *actions = NULL;
+static GSList *action_providers = NULL;
static gboolean initialized = FALSE;
static void
add_action_provider (AtomatoActionProvider *provider)
{
- AtomatoMethod method, *ptr_method;
-
- method = atomato_action_provider_get_method (provider);
- if (g_hash_table_lookup (action_providers, &method)) {
- g_warning ("2 providers for the same method!!!!");
- return;
- }
-
- ptr_method = g_new (AtomatoMethod, 1);
- *ptr_method = method;
-
- g_hash_table_insert (action_providers, ptr_method, provider);
-}
-
-static void
-read_actions_from_dir (const gchar *path)
-{
- GDir *dir;
- const gchar *file;
-
- dir = g_dir_open (path, 0, NULL);
- if (!dir)
- return;
-
- while ((file = g_dir_read_name (dir))) {
- gchar *action_file;
- GSList *list;
-
- if (!g_str_has_suffix (file, ".atomato"))
- continue;
-
- action_file = g_build_filename (path, file, NULL);
- list = atomato_read_action_file (action_file);
- g_free (action_file);
- while (list != NULL) {
- AtomatoAction *action;
- gchar *full_name;
-
- action = list->data;
-
- if (!actions) {
- actions = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, atomato_action_free);
- }
-
- full_name = g_strdup_printf ("%s.%s", action->section, action->name);
- if (g_hash_table_lookup (actions, full_name)) {
- g_warning ("2 actions with the same name!!!");
- g_free (full_name);
- } else
- g_hash_table_insert (actions, full_name, action);
-
- list = g_slist_remove (list, list->data);
- }
- }
-
- g_dir_close (dir);
-}
-
-static void
-read_action_dirs (void)
-{
- gint i;
- gchar *path;
- const gchar* const * system_dirs;
-
- system_dirs = g_get_system_data_dirs ();
- for (i = 0; system_dirs[i] != NULL; i++) {
- path = g_build_filename (system_dirs[i], "atomato", "actions", NULL);
- read_actions_from_dir ((const gchar *) path);
- g_free (path);
- }
+ action_providers = g_slist_append (action_providers, provider);
}
static void
@@ -111,50 +39,15 @@ initialize (void)
if (initialized)
return;
- /* get all available actions */
- read_action_dirs ();
-
/* initialize action providers */
- action_providers = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_object_unref);
- add_action_provider (ATOMATO_ACTION_PROVIDER (g_object_new (SHELL_TYPE_ACTION_PROVIDER, NULL)));
- add_action_provider (ATOMATO_ACTION_PROVIDER (g_object_new (DBUS_TYPE_ACTION_PROVIDER, NULL)));
+ action_providers = g_slist_append (action_providers,
+ g_object_new (SHELL_TYPE_ACTION_PROVIDER, NULL));
+ action_providers = g_slist_append (action_providers,
+ g_object_new (DBUS_TYPE_ACTION_PROVIDER, NULL));
initialized = TRUE;
}
-static void
-add_provider_method_hash_cb (gpointer key, gpointer value, gpointer user_data)
-{
- AtomatoMethod *method = key;
- GSList **list = user_data;
-
- *list = g_slist_append (*list, GINT_TO_POINTER (*method));
-}
-
-/**
- * atomato_list_methods:
- */
-GSList *
-atomato_list_methods (void)
-{
- GSList *list = NULL;
-
- initialize ();
-
- g_hash_table_foreach (action_providers, (GHFunc) add_provider_method_hash_cb, &list);
-
- return list;
-}
-
-static void
-add_action_hash_cb (gpointer key, gpointer value, gpointer user_data)
-{
- AtomatoAction *action = value;
- GSList **list = user_data;
-
- *list = g_slist_append (*list, action);
-}
-
/**
* atomato_list_actions:
*
@@ -162,22 +55,33 @@ add_action_hash_cb (gpointer key, gpointer value, gpointer user_data)
GSList *
atomato_list_actions (void)
{
- GSList *list = NULL;
+ GSList *list = NULL, *l;
initialize ();
- g_hash_table_foreach (actions, (GHFunc) add_action_hash_cb, &list);
+ for (l = action_providers; l != NULL; l = l->next) {
+ GSList *provider_list;
+
+ provider_list = atomato_action_provider_get_actions (
+ ATOMATO_ACTION_PROVIDER (l->data));
+
+ list = g_slist_concat (list, provider_list);
+ }
return list;
}
/**
- * atomato_get_action_by_name:
+ * atomato_free_actions_list:
+ * @list: List of actions as returned by #atomato_list_actions.
+ *
+ * Frees the memory associated with an actions list.
*/
-AtomatoAction *
-atomato_get_action_by_name (const gchar *name)
+void
+atomato_free_actions_list (GSList *list)
{
- initialize ();
-
- return g_hash_table_lookup (actions, name);
+ while (list) {
+ g_object_unref (G_OBJECT (list->data));
+ list = g_slist_remove (list, list->data);
+ }
}
diff --git a/libatomato/atomato.h b/libatomato/atomato.h
index 44fcfa2..3a51478 100644
--- a/libatomato/atomato.h
+++ b/libatomato/atomato.h
@@ -24,44 +24,13 @@
#define __ATOMATO_H__
#include <glib-object.h>
+#include "atomato-action.h"
+#include "atomato-action-provider.h"
G_BEGIN_DECLS
-typedef enum {
- ATOMATO_ACTION_ARGUMENT_DIRECTION_UNKNOWN,
- ATOMATO_ACTION_ARGUMENT_DIRECTION_IN,
- ATOMATO_ACTION_ARGUMENT_DIRECTION_OUT,
- ATOMATO_ACTION_ARGUMENT_DIRECTION_INOUT,
-} AtomatoActionArgumentDirection;
-
-typedef struct {
- char *name;
- AtomatoActionArgumentDirection direction;
- GType type;
-} AtomatoActionArgument;
-
-typedef enum {
- ATOMATO_METHOD_UNKNOWN = -1,
- ATOMATO_METHOD_DBUS,
- ATOMATO_METHOD_SHELL
-} AtomatoMethod;
-
-typedef struct {
- gchar *section;
- gchar *name;
- gchar *description;
- AtomatoMethod method;
- gchar *command;
- GList *args;
-} AtomatoAction;
-
-GSList *atomato_read_action_file (const gchar *filename);
-void atomato_action_free (AtomatoAction *action);
-
-GSList *atomato_list_methods (void);
GSList *atomato_list_actions (void);
-
-AtomatoAction *atomato_get_action_by_name (const gchar *name);
+void atomato_free_actions_list (GSList *list);
G_END_DECLS
diff --git a/libatomato/dbus-action-provider.c b/libatomato/dbus-action-provider.c
index 37564b3..0fe25c9 100644
--- a/libatomato/dbus-action-provider.c
+++ b/libatomato/dbus-action-provider.c
@@ -27,15 +27,134 @@
#include "dbus-action-provider.h"
struct _DbusActionProviderPrivate {
- //DBusGConnection *system_connection;
DBusGConnection *session_connection;
- //DBusGProxy *system_proxy;
DBusGProxy *session_proxy;
GHashTable *names;
};
-static GObjectClass *parent_class = NULL;
+static GObjectClass *action_parent_class = NULL;
+static GObjectClass *provider_parent_class = NULL;
+
+/*
+ * DbusAction class implementation
+ */
+
+typedef struct {
+ GObject *parent;
+
+ gchar *name;
+ GSList *args;
+} DbusAction;
+
+typedef struct {
+ GObjectClass parent_class;
+} DbusActionClass;
+
+static const gchar *
+dbus_action_get_name (AtomatoAction *action)
+{
+ DbusAction *dbus_action = (DbusAction *) action;
+
+ return (const gchar *) dbus_action->name;
+}
+
+static const gchar *
+dbus_action_get_section (AtomatoAction *action)
+{
+ return "";
+}
+
+static const gchar *
+dbus_action_get_description (AtomatoAction *action)
+{
+ return "";
+}
+
+static GValue *
+dbus_action_run (AtomatoAction *action, GValueArray *arguments)
+{
+}
+
+static void
+dbus_action_interface_init (gpointer g_iface, gpointer iface_data)
+{
+ AtomatoActionInterface *iface = (AtomatoActionInterface *) g_iface;
+
+ iface->get_name = dbus_action_get_name;
+ iface->get_section = dbus_action_get_section;
+ iface->get_description = dbus_action_get_description;
+ iface->run = dbus_action_run;
+}
+
+static void
+dbus_action_instance_init (GTypeInstance *instance, gpointer g_class)
+{
+ DbusAction *dbus_action = (DbusAction *) instance;
+}
+
+static void
+dbus_action_finalize (GObject *object)
+{
+ DbusAction *dbus_action = (DbusAction *) object;
+
+ if (dbus_action->name) {
+ g_free (dbus_action->name);
+ dbus_action->name = NULL;
+ }
+
+ if (dbus_action->args) {
+ g_slist_foreach (dbus_action->args, (GFunc) atomato_action_free_argument, NULL);
+ g_slist_free (dbus_action->args);
+ dbus_action->args = NULL;
+ }
+
+ action_parent_class->finalize (object);
+}
+
+static void
+dbus_action_class_init (DbusActionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ action_parent_class = g_type_class_ref (G_TYPE_OBJECT);
+
+ object_class->finalize = dbus_action_finalize;
+}
+
+GType
+dbus_action_get_type (void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof (DbusActionClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ dbus_action_class_init, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (DbusAction),
+ 0, /* n_preallocs */
+ dbus_action_instance_init /* instance_init */
+ };
+ static const GInterfaceInfo iap_info = {
+ (GInterfaceInitFunc) dbus_action_interface_init, /* interface_init */
+ NULL, /* interface_finalize */
+ NULL /* interface_data */
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT, "DbusAction", &info, 0);
+ g_type_add_interface_static (type, ATOMATO_TYPE_ACTION, &iap_info);
+ }
+
+ return type;
+}
+
+/*
+ * DbusActionProvider class implementation
+ */
static void
parse_xml_interface (DbusActionProvider *dbus_provider, xmlNodePtr xml_node)
@@ -43,14 +162,15 @@ parse_xml_interface (DbusActionProvider *dbus_provider, xmlNodePtr xml_node)
xmlNodePtr subnode, arg_node;
for (subnode = xml_node->xmlChildrenNode; subnode != NULL; subnode = subnode->next) {
- AtomatoAction *action;
+ DbusAction *dbus_action;
if (strcmp ((char *) subnode->name, "method"))
continue;
- action = g_new0 (AtomatoAction, 1);
- action->name = g_strdup (xmlGetProp (subnode, "name"));
+ dbus_action = g_object_new (dbus_action_get_type (), NULL);
+ dbus_action->name = g_strdup (xmlGetProp (subnode, "name"));
+ dbus_action->args = NULL;
for (arg_node = subnode->xmlChildrenNode; arg_node != NULL;
arg_node = arg_node->next) {
AtomatoActionArgument *argument;
@@ -63,10 +183,12 @@ parse_xml_interface (DbusActionProvider *dbus_provider, xmlNodePtr xml_node)
//argument->direction = g_strdup (xmlGetProp (arg_node, "direction"));
//argument->type = g_strdup (xmlGetProp (arg_node, "type"));
- action->args = g_list_append (action->args, argument);
+ dbus_action->args = g_slist_append (dbus_action->args, argument);
}
- g_hash_table_insert (dbus_provider->priv->names, action->name, action);
+ g_hash_table_insert (dbus_provider->priv->names,
+ g_strdup (dbus_action->name),
+ dbus_action);
}
}
@@ -81,7 +203,9 @@ parse_xml_document (DbusActionProvider *dbus_provider, char *data)
xml_root = xmlDocGetRootElement (xml_doc);
if (!strcmp ((char *) xml_root->name, "node")) {
- for (xml_node = xml_root->xmlChildrenNode; xml_node != NULL; xml_node = xml_node->next) {
+ for (xml_node = xml_root->xmlChildrenNode;
+ xml_node != NULL;
+ xml_node = xml_node->next) {
if (strcmp ((char *) xml_node->name, "interface"))
continue;
parse_xml_interface (dbus_provider, xml_node);
@@ -145,27 +269,32 @@ list_dbus_names (DbusActionProvider *dbus_provider, DBusGProxy *proxy, DBusGConn
}
static void
-hash_to_slist (gpointer key, gpointer value, gpointer user_data)
+hash_to_slist_cb (gpointer key, gpointer value, gpointer user_data)
{
GSList **list = (GSList **) user_data;
*list = g_slist_append (*list, value);
}
-static AtomatoMethod
-dbus_action_provider_get_method (AtomatoActionProvider *provider)
+static GSList *
+dbus_action_provider_get_actions (AtomatoActionProvider *provider)
{
- g_return_val_if_fail (DBUS_IS_ACTION_PROVIDER (provider), ATOMATO_METHOD_UNKNOWN);
+ DbusActionProvider *dbus_provider = (DbusActionProvider *) provider;
+ GSList *list = NULL;
+
+ if (!dbus_provider->priv->names) {
+ dbus_provider->priv->names = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_object_unref);
+ list_dbus_names (dbus_provider,
+ dbus_provider->priv->session_proxy,
+ dbus_provider->priv->session_connection);
+ }
- return ATOMATO_METHOD_DBUS;
-}
+ g_hash_table_foreach (dbus_provider->priv->names, (GHFunc) hash_to_slist_cb, &list);
-static GValueArray *
-dbus_action_provider_run_action (AtomatoActionProvider *provider,
- AtomatoAction *action,
- const GValueArray *input_args)
-{
- return NULL;
+ return list;
}
static void
@@ -173,8 +302,7 @@ dbus_action_provider_interface_init (gpointer g_iface, gpointer iface_data)
{
AtomatoActionProviderInterface *iface = (AtomatoActionProviderInterface *) g_iface;
- iface->get_method = dbus_action_provider_get_method;
- iface->run_action = dbus_action_provider_run_action;
+ iface->get_actions = dbus_action_provider_get_actions;
}
static DBusGProxy *
@@ -203,14 +331,6 @@ dbus_action_provider_instance_init (GTypeInstance *instance, gpointer g_class)
provider->priv = g_new0 (DbusActionProviderPrivate, 1);
/* get DBus connections */
- /* error = NULL; */
-/* if (!(provider->priv->system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error))) { */
-/* g_warning ("Could not get the system bus: %s. Not using system services\n", error->message); */
-/* g_error_free (error); */
-/* } else { */
-/* provider->priv->system_proxy = set_proxy (provider->priv->system_connection); */
-/* } */
-
error = NULL;
if (!(provider->priv->session_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error))) {
g_warning ("Could not get the session bus: %s. Not using session services\n", error->message);
@@ -235,7 +355,7 @@ dbus_action_provider_finalize (GObject *object)
provider->priv = NULL;
}
- parent_class->finalize (object);
+ provider_parent_class->finalize (object);
}
static void
@@ -243,7 +363,7 @@ dbus_action_provider_class_init (DbusActionProviderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_ref (G_TYPE_OBJECT);
+ provider_parent_class = g_type_class_ref (G_TYPE_OBJECT);
object_class->finalize = dbus_action_provider_finalize;
}
diff --git a/libatomato/shell-action-provider.c b/libatomato/shell-action-provider.c
index a1da940..7b2671a 100644
--- a/libatomato/shell-action-provider.c
+++ b/libatomato/shell-action-provider.c
@@ -23,24 +23,209 @@
#include "shell-action-provider.h"
struct _ShellActionProviderPrivate {
+ GHashTable *actions;
};
-static GObjectClass *parent_class = NULL;
+static GObjectClass *action_parent_class = NULL;
+static GObjectClass *provider_parent_class = NULL;
-static AtomatoMethod
-shell_action_provider_get_method (AtomatoActionProvider *provider)
+/*
+ * ShellAction class implementation
+ */
+
+typedef struct {
+ GObject parent;
+
+ gchar *script_file;
+ gchar *name;
+ gchar *section;
+ gchar *description;
+} ShellAction;
+
+typedef struct {
+ GObjectClass parent_class;
+} ShellActionClass;
+
+static const gchar *
+shell_action_get_name (AtomatoAction *action)
+{
+ ShellAction *shell_action = (ShellAction *) action;
+
+ return (const gchar *) shell_action->name;
+}
+
+static const gchar *
+shell_action_get_section (AtomatoAction *action)
+{
+ ShellAction *shell_action = (ShellAction *) action;
+
+ return (const gchar *) shell_action->section;
+}
+
+static const gchar *
+shell_action_get_description (AtomatoAction *action)
+{
+ ShellAction *shell_action = (ShellAction *) action;
+
+ return (const gchar *) shell_action->description;
+}
+
+static GValue *
+shell_action_run (AtomatoAction *action, GValueArray *arguments)
+{
+}
+
+static void
+shell_action_interface_init (gpointer g_iface, gpointer iface_data)
+{
+ AtomatoActionInterface *iface = (AtomatoActionInterface *) g_iface;
+
+ iface->get_name = shell_action_get_name;
+ iface->get_section = shell_action_get_section;
+ iface->get_description = shell_action_get_description;
+ iface->run = shell_action_run;
+}
+
+static void
+shell_action_instance_init (GTypeInstance *instance, gpointer g_class)
{
- g_return_val_if_fail (SHELL_IS_ACTION_PROVIDER (provider), ATOMATO_METHOD_UNKNOWN);
+ ShellAction *shell_action = (ShellAction *) instance;
+}
+
+static void
+shell_action_finalize (GObject *object)
+{
+ ShellAction *shell_action = (ShellAction *) object;
+
+ if (shell_action->script_file) {
+ g_free (shell_action->script_file);
+ shell_action->script_file = NULL;
+ }
+
+ if (shell_action->name) {
+ g_free (shell_action->name);
+ shell_action->name = NULL;
+ }
+
+ if (shell_action->section) {
+ g_free (shell_action->section);
+ shell_action->section = NULL;
+ }
- return ATOMATO_METHOD_SHELL;
+ if (shell_action->description) {
+ g_free (shell_action->description);
+ shell_action->description = NULL;
+ }
+
+ action_parent_class->finalize (object);
}
-static GValueArray *
-shell_action_provider_run_action (AtomatoActionProvider *provider,
- AtomatoAction *action,
- const GValueArray *input_args)
+static void
+shell_action_class_init (ShellActionClass *klass)
{
- return NULL;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ action_parent_class = g_type_class_ref (G_TYPE_OBJECT);
+
+ object_class->finalize = shell_action_finalize;
+}
+
+GType
+shell_action_get_type (void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof (ShellActionClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ shell_action_class_init, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (ShellAction),
+ 0, /* n_preallocs */
+ shell_action_instance_init /* instance_init */
+ };
+ static const GInterfaceInfo iap_info = {
+ (GInterfaceInitFunc) shell_action_interface_init, /* interface_init */
+ NULL, /* interface_finalize */
+ NULL /* interface_data */
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT, "ShellAction", &info, 0);
+ g_type_add_interface_static (type, ATOMATO_TYPE_ACTION, &iap_info);
+ }
+
+ return type;
+}
+
+static AtomatoAction *
+shell_action_new (const gchar *script_file)
+{
+ AtomatoAction *action;
+ ShellAction *shell_action;
+ gchar **a;
+
+ if (!script_file) {
+ g_warning ("%s: 'script_file' is NULL", __FUNCTION__);
+ return NULL;
+ }
+
+ action = shell_action = g_object_new (shell_action_get_type (), NULL);
+ shell_action->script_file = g_strdup (script_file);
+ shell_action->name = g_path_get_basename (shell_action->script_file);
+
+ a = g_strsplit (shell_action->name, ".", 0);
+ if (a && a[0])
+ shell_action->section = g_strdup (a[0]);
+
+ g_strfreev (a);
+
+ return action;
+}
+
+/*
+ * ShellActionProvider class implementation
+ */
+
+static GSList *
+shell_action_provider_get_actions (AtomatoActionProvider *provider)
+{
+ GSList *list = NULL;
+ ShellActionProvider *shell_provider = (ShellActionProvider *) provider;
+
+ if (!shell_provider->priv->actions) {
+ GDir *dir;
+ GError *error = NULL;
+
+ shell_provider->priv->actions =
+ g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
+ /* Load all scripts in ATOMATO_ACTIONS_DIR */
+ dir = g_dir_open (ATOMATO_ACTIONS_DIR "/shell", 0, &error);
+ if (dir) {
+ gchar *file;
+
+ while ((file = g_dir_read_name (dir))) {
+ gchar *full_path;
+
+ full_path = g_strdup_printf ("%s/shell/%s",
+ ATOMATO_ACTIONS_DIR,
+ file);
+
+ list = g_slist_append (list, shell_action_new (full_path));
+ g_free (full_path);
+ }
+
+ g_dir_close (dir);
+ } else {
+ g_warning ("%s: %s", __FUNCTION__, error->message);
+ g_error_free (error);
+ }
+ }
+
+ return list;
}
static void
@@ -48,16 +233,15 @@ shell_action_provider_interface_init (gpointer g_iface, gpointer iface_data)
{
AtomatoActionProviderInterface *iface = (AtomatoActionProviderInterface *) g_iface;
- iface->get_method = shell_action_provider_get_method;
- iface->run_action = shell_action_provider_run_action;
+ iface->get_actions = shell_action_provider_get_actions;
}
static void
shell_action_provider_instance_init (GTypeInstance *instance, gpointer g_class)
{
- ShellActionProvider *provider = (ShellActionProvider *) instance;
+ ShellActionProvider *shell_provider = (ShellActionProvider *) instance;
- provider->priv = g_new0 (ShellActionProviderPrivate, 1);
+ shell_provider->priv = g_new0 (ShellActionProviderPrivate, 1);
}
static void
@@ -66,12 +250,16 @@ shell_action_provider_finalize (GObject *object)
ShellActionProvider *provider = (ShellActionProvider *) object;
if (provider->priv) {
+ if (provider->priv->actions) {
+ g_hash_table_destroy (provider->priv->actions);
+ provider->priv->actions = NULL;
+ }
g_free (provider->priv);
provider->priv = NULL;
}
- parent_class->finalize (object);
+ provider_parent_class->finalize (object);
}
static void
@@ -79,7 +267,7 @@ shell_action_provider_class_init (ShellActionProviderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_ref (G_TYPE_OBJECT);
+ provider_parent_class = g_type_class_ref (G_TYPE_OBJECT);
object_class->finalize = shell_action_provider_finalize;
}
diff --git a/services/desktop/Makefile.am b/services/desktop/Makefile.am
index 33bb858..05f9bbf 100644
--- a/services/desktop/Makefile.am
+++ b/services/desktop/Makefile.am
@@ -1,3 +1,4 @@
-actionsdir = $(datadir)/atomato/actions
-actions_DATA = \
- desktop-session.atomato
+shellactionsdir = $(libdir)/atomato/actions/shell
+shellactions_SCRIPTS = \
+ Desktop.ActivateScreensaver \
+ Desktop.LockScreen
diff --git a/services/desktop/desktop-session.atomato b/services/desktop/desktop-session.atomato
index 9702d5e..e69de29 100644
--- a/services/desktop/desktop-session.atomato
+++ b/services/desktop/desktop-session.atomato
@@ -1,21 +0,0 @@
-<atomato>
-
- <action section="Desktop"
- name="LockScreen"
- description="Lock screen"
- method="shell"
- command="gnome-screensaver-command --lock">
- <arguments>
- </arguments>
- </action>
-
- <action section="Desktop"
- name="SaveSession"
- description="Save session"
- method="shell"
- command="gnome-session-save">
- <arguments>
- </arguments>
- </action>
-
-</atomato>
\ No newline at end of file
diff --git a/src/main-window.c b/src/main-window.c
index bf89b83..fed0f55 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -50,7 +50,8 @@ populate_actions_model (MainWindow *window)
AtomatoAction *action = sl->data;
/* 1st add the section parent node if not present yet */
- section_path = g_hash_table_lookup (window->sections, action->section);
+ section_path = g_hash_table_lookup (window->sections,
+ atomato_action_get_section (action));
if (section_path) {
gtk_tree_model_get_iter (GTK_TREE_MODEL (window->actions_model),
§ion_iter,
@@ -59,9 +60,10 @@ populate_actions_model (MainWindow *window)
gchar *section_name;
gtk_tree_store_append (window->actions_model, §ion_iter, NULL);
- gtk_tree_store_set (window->actions_model, §ion_iter, 0, action->section, -1);
+ gtk_tree_store_set (window->actions_model, §ion_iter,
+ 0, atomato_action_get_section (action), -1);
- section_name = g_strdup (action->section);
+ section_name = g_strdup (atomato_action_get_section (action));
section_path = gtk_tree_model_get_path (GTK_TREE_MODEL (window->actions_model),
§ion_iter);
g_hash_table_insert (window->sections, section_name, section_path);
@@ -69,7 +71,8 @@ populate_actions_model (MainWindow *window)
/* now add the action to the tree */
gtk_tree_store_append (window->actions_model, &iter, §ion_iter);
- gtk_tree_store_set (window->actions_model, &iter, 0, action->description, -1);
+ gtk_tree_store_set (window->actions_model, &iter, 0,
+ atomato_action_get_description (action), -1);
/* FIXME: associate AtomatoAction with added row */
}
diff --git a/tests/test-list-actions.c b/tests/test-list-actions.c
index 494a639..01ac4f1 100644
--- a/tests/test-list-actions.c
+++ b/tests/test-list-actions.c
@@ -33,9 +33,9 @@ main (int argc, char **argv)
while (names != NULL) {
AtomatoAction *action = names->data;
g_printf ("Action: %s.%s: %s\n",
- (const gchar *) action->section,
- (const gchar *) action->name,
- (const gchar *) action->description);
+ atomato_action_get_section (action),
+ atomato_action_get_name (action),
+ atomato_action_get_description (action));
names = names->next;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]