From 0b452791f51e34ac834fd7a4f9b4517877e82c7d Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Thu, 30 Sep 2010 09:47:23 +1000 Subject: An example Mission Control plugin --- autogen.sh | 2 +- configure.ac | 18 +- docs/examples/Makefile.am | 1 + docs/examples/mission_control_plugin/Makefile.am | 17 ++ .../mcp-account-manager-example.c | 252 +++++++++++++++++++++ .../mcp-account-manager-example.h | 56 +++++ .../mission-control-plugin.c | 48 ++++ 7 files changed, 391 insertions(+), 3 deletions(-) create mode 100644 docs/examples/mission_control_plugin/Makefile.am create mode 100644 docs/examples/mission_control_plugin/mcp-account-manager-example.c create mode 100644 docs/examples/mission_control_plugin/mcp-account-manager-example.h create mode 100644 docs/examples/mission_control_plugin/mission-control-plugin.c diff --git a/autogen.sh b/autogen.sh index 0a7e989..62c424a 100755 --- a/autogen.sh +++ b/autogen.sh @@ -2,7 +2,7 @@ set -x gnome-doc-prepare --force --copy || exit 1 aclocal -I m4 || exit 1 -# libtoolize --force +libtoolize --force # autoheader autoconf || exit 1 automake -a || exit 1 diff --git a/configure.ac b/configure.ac index 77b0fcb..4de1e9f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,11 @@ dnl configure.ac for template xml docbook AC_INIT(telepathy-doc, 0.5.0.1) +m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) AM_INIT_AUTOMAKE([-Wno-portability]) +AC_PROG_CC +AC_PROG_LIBTOOL + dnl Add parameters for aclocal AC_SUBST(ACLOCAL_AMFLAGS, "-I m4") @@ -11,16 +15,25 @@ GNOME_DOC_INIT([0.9.0]) PKG_CHECK_MODULES(GNOME_DOC_UTILS, gnome-doc-utils) PKG_CHECK_MODULES(TELEPATHY_GLIB, [ - telepathy-glib >= 0.7.3 + telepathy-glib >= 0.11.6 + mission-control-plugins >= 5.5 gtk+-2.0 >= 2.12.0 gio-unix-2.0 >= 2.21.4 ]) AC_SUBST(TELEPATHY_GLIB_CFLAGS) AC_SUBST(TELEPATHY_GLIB_LIBS) -AC_PROG_CC() AM_PATH_PYTHON() +AC_MSG_CHECKING([Mission Control plugins dir]) +MISSION_CONTROL_PLUGINS_DIR=`pkg-config --variable=plugindir mission-control-plugins` +if test "x$MISSION_CONTROL_PLUGINS_DIR" = "x"; then + AC_MSG_ERROR([could not determine plugindir]) +else + AC_MSG_RESULT([$MISSION_CONTROL_PLUGINS_DIR]) +fi +AC_SUBST(MISSION_CONTROL_PLUGINS_DIR) + AC_OUTPUT([ Makefile m4/Makefile @@ -44,6 +57,7 @@ AC_OUTPUT([ docs/examples/glib_mc5_presence_app/Makefile docs/examples/glib_mc5_request_call/Makefile docs/examples/gtk_presence_app/Makefile + docs/examples/mission_control_plugin/Makefile docs/examples/pygtk_chat_client/Makefile docs/examples/python_get_parameters/Makefile docs/examples/python_iface_messaging/Makefile diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index b36da94..83bbaa3 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -16,6 +16,7 @@ example_dirs = \ glib_mc5_presence_app \ glib_mc5_request_call \ gtk_presence_app \ + mission_control_plugin \ pygtk_chat_client \ python_get_parameters \ python_iface_messaging \ diff --git a/docs/examples/mission_control_plugin/Makefile.am b/docs/examples/mission_control_plugin/Makefile.am new file mode 100644 index 0000000..f02eee1 --- /dev/null +++ b/docs/examples/mission_control_plugin/Makefile.am @@ -0,0 +1,17 @@ +AM_CPPFLAGS = \ + $(TELEPATHY_GLIB_CFLAGS) + +pluginsdir = $(MISSION_CONTROL_PLUGINS_DIR) +plugins_LTLIBRARIES = \ + mcp-account-manager-socialweb.la + +mcp_account_manager_socialweb_la_SOURCES = \ + mission-control-plugin.c \ + mcp-account-manager-example.c mcp-account-manager-example.h + +mcp_account_manager_socialweb_la_LIBADD = \ + $(MISSION_CONTROL_MODULE_LIBS) + +mcp_account_manager_socialweb_la_LDFLAGS = \ + -module \ + -avoid-version diff --git a/docs/examples/mission_control_plugin/mcp-account-manager-example.c b/docs/examples/mission_control_plugin/mcp-account-manager-example.c new file mode 100644 index 0000000..acda627 --- /dev/null +++ b/docs/examples/mission_control_plugin/mcp-account-manager-example.c @@ -0,0 +1,252 @@ +/* + * mcp-account-manager-example.c + * + * McpAccountManagerExample - an example Mission Control plugin + * + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + * Authors: + * Danielle Madeley + */ + +#include + +#include "mcp-account-manager-example.h" + +#define DEBUG g_debug + +#define PLUGIN_NAME "ExamplePlugin" +#define PLUGIN_PRIORITY (MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_KEYRING + 10) +#define PLUGIN_DESCRIPTION "Provide an example Telepathy Account" +#define PLUGIN_PROVIDER "au.id.madeley.danielle.ExamplePlugin" + +#define ACCOUNT_NAME "gabble/jabber/example0" + +#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MCP_TYPE_ACCOUNT_MANAGER_EXAMPLE, McpAccountManagerExamplePrivate)) + +static void account_storage_iface_init (McpAccountStorageIface *iface); + +G_DEFINE_TYPE_WITH_CODE (McpAccountManagerExample, + mcp_account_manager_example, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (MCP_TYPE_ACCOUNT_STORAGE, + account_storage_iface_init)); + +typedef struct _McpAccountManagerExamplePrivate McpAccountManagerExamplePrivate; +struct _McpAccountManagerExamplePrivate +{ + gboolean ready; +}; + + +static void +mcp_account_manager_example_dispose (GObject *self) +{ + McpAccountManagerExamplePrivate *priv = GET_PRIVATE (self); + + G_OBJECT_CLASS (mcp_account_manager_example_parent_class)->dispose (self); +} + + +static void +mcp_account_manager_example_class_init (McpAccountManagerExampleClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->dispose = mcp_account_manager_example_dispose; + + g_type_class_add_private (gobject_class, + sizeof (McpAccountManagerExamplePrivate)); +} + + +static void +mcp_account_manager_example_init (McpAccountManagerExample *self) +{ +} + + +static GList * +mcp_account_manager_example_list (const McpAccountStorage *self, + const McpAccountManager *am) +{ + McpAccountManagerExamplePrivate *priv = GET_PRIVATE (self); + GList *accounts = NULL; + + DEBUG (G_STRFUNC); + + accounts = g_list_prepend (accounts, g_strdup (ACCOUNT_NAME)); + + return accounts; +} + + +typedef struct +{ + char *key; + char *value; +} Parameter; + +static const Parameter parameters[] = { + { "manager", "gabble" }, + { "protocol", "jabber" }, + { "Icon", "im-xmpp" }, + { "ConnectAutomatically", "true" }, + { "Enabled", "false" }, + { "DisplayName", "My Example Account" }, + + { "param-account", "escher@tuxedo.cat" }, +}; + + +static gboolean +mcp_account_manager_example_get (const McpAccountStorage *self, + const McpAccountManager *am, + const gchar *acct, + const gchar *key) +{ + DEBUG ("%s: %s, %s", G_STRFUNC, acct, key); + + if (!tp_strdiff (acct, ACCOUNT_NAME)) + { + if (key == NULL) + { + guint i; + + /* load all keys */ + for (i = 0; i < G_N_ELEMENTS (parameters); i++) + { + const Parameter *param = ¶meters[i]; + + DEBUG ("Loading %s = %s", param->key, param->value); + mcp_account_manager_set_value (am, acct, + param->key, param->value); + } + + return TRUE; + } + else + { + guint i; + + /* get a specific key */ + for (i = 0; i < G_N_ELEMENTS (parameters); i++) + { + const Parameter *param = ¶meters[i]; + + if (!tp_strdiff (param->key, key)) + { + DEBUG ("Loading %s = %s", param->key, param->value); + mcp_account_manager_set_value (am, acct, + param->key, param->value); + + return TRUE; + } + } + + return FALSE; + } + } + + return FALSE; +} + + +static gboolean +mcp_account_manager_example_set (const McpAccountStorage *self, + const McpAccountManager *am, + const gchar *acct, + const gchar *key, + const gchar *val) +{ + McpAccountManagerExamplePrivate *priv = GET_PRIVATE (self); + GError *error = NULL; + + DEBUG ("%s: (%s, %s, %s)", G_STRFUNC, acct, key, val); + + if (!tp_strdiff (acct, ACCOUNT_NAME)) + /* pretend we saved everything */ + return TRUE; + else + return FALSE; +} + + +static gboolean +mcp_account_manager_example_delete (const McpAccountStorage *self, + const McpAccountManager *am, + const gchar *acct, + const gchar *key) +{ + DEBUG ("%s: (%s, %s)", G_STRFUNC, acct, key); + + if (!tp_strdiff (acct, ACCOUNT_NAME)) + return TRUE; + else + return FALSE; +} + + +static gboolean +mcp_account_manager_example_commit (const McpAccountStorage *self, + const McpAccountManager *am) +{ + DEBUG ("%s", G_STRFUNC); + + return TRUE; +} + + +static void +mcp_account_manager_example_ready (const McpAccountStorage *self, + const McpAccountManager *am) +{ + McpAccountManagerExamplePrivate *priv = GET_PRIVATE (self); + + DEBUG (G_STRFUNC); + + priv->ready = TRUE; +} + + +static guint +mcp_account_manager_example_get_restrictions (const McpAccountStorage *self, + const gchar *account) +{ + return TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS | + TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_SERVICE; +} + + +static void +account_storage_iface_init (McpAccountStorageIface *iface) +{ + mcp_account_storage_iface_set_name (iface, PLUGIN_NAME); + mcp_account_storage_iface_set_desc (iface, PLUGIN_DESCRIPTION); + mcp_account_storage_iface_set_priority (iface, PLUGIN_PRIORITY); + mcp_account_storage_iface_set_provider (iface, PLUGIN_PROVIDER); + +#define IMPLEMENT(x) mcp_account_storage_iface_implement_##x(iface, \ + mcp_account_manager_example_##x) + IMPLEMENT (get); + IMPLEMENT (list); + IMPLEMENT (set); + IMPLEMENT (delete); + IMPLEMENT (commit); + IMPLEMENT (ready); + IMPLEMENT (get_restrictions); +#undef IMPLEMENT +} diff --git a/docs/examples/mission_control_plugin/mcp-account-manager-example.h b/docs/examples/mission_control_plugin/mcp-account-manager-example.h new file mode 100644 index 0000000..a5673c3 --- /dev/null +++ b/docs/examples/mission_control_plugin/mcp-account-manager-example.h @@ -0,0 +1,56 @@ +/* + * mcp-account-manager-example.h + * + * McpAccountManagerExample - an example Mission Control plugin + * + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + * Authors: + * Danielle Madeley + */ + +#include + +#ifndef __MCP_ACCOUNT_MANAGER_EXAMPLE_H__ +#define __MCP_ACCOUNT_MANAGER_EXAMPLE_H__ + +G_BEGIN_DECLS + +#define MCP_TYPE_ACCOUNT_MANAGER_EXAMPLE (mcp_account_manager_example_get_type ()) +#define MCP_ACCOUNT_MANAGER_EXAMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MCP_TYPE_ACCOUNT_MANAGER_EXAMPLE, McpAccountManagerExample)) +#define MCP_ACCOUNT_MANAGER_EXAMPLE_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), MCP_TYPE_ACCOUNT_MANAGER_EXAMPLE, McpAccountManagerExampleClass)) +#define MCP_IS_ACCOUNT_MANAGER_EXAMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MCP_TYPE_ACCOUNT_MANAGER_EXAMPLE)) +#define MCP_IS_ACCOUNT_MANAGER_EXAMPLE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), MCP_TYPE_ACCOUNT_MANAGER_EXAMPLE)) +#define MCP_ACCOUNT_MANAGER_EXAMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MCP_TYPE_ACCOUNT_MANAGER_EXAMPLE, McpAccountManagerExampleClass)) + +typedef struct _McpAccountManagerExample McpAccountManagerExample; +typedef struct _McpAccountManagerExampleClass McpAccountManagerExampleClass; + +struct _McpAccountManagerExample +{ + GObject parent; +}; + +struct _McpAccountManagerExampleClass +{ + GObjectClass parent_class; +}; + +GType mcp_account_manager_example_get_type (void); + +G_END_DECLS + +#endif diff --git a/docs/examples/mission_control_plugin/mission-control-plugin.c b/docs/examples/mission_control_plugin/mission-control-plugin.c new file mode 100644 index 0000000..f016acc --- /dev/null +++ b/docs/examples/mission_control_plugin/mission-control-plugin.c @@ -0,0 +1,48 @@ +/* + * mission-control-plugin.c + * + * A Mission Control plugin to expose libsocialweb accounts with chat + * capabilities (e.g. Facebook) to Mission Control + * + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + * Authors: + * Danielle Madeley + */ + +#include + +#include "mcp-account-manager-example.h" + +GObject * +mcp_plugin_ref_nth_object (guint n) +{ + static void *plugin_0 = NULL; + + if (plugin_0 == NULL) + plugin_0 = g_object_new (MCP_TYPE_ACCOUNT_MANAGER_EXAMPLE, NULL); + + switch (n) + { + case 0: + return g_object_ref (plugin_0); + break; + + default: + return NULL; + break; + } +} -- cgit v1.2.3