./0000755000004100000410000000000013350212604011237 5ustar www-datawww-data./NEWS0000644000004100000410000000247213350212604011743 0ustar www-datawww-data 12.10.5 * fix crash caused by GError not being cleared (lp #1064314) * fix crash when registering an app that was previously unregistered (lp #1065169) * remove the icon if NULL is passed to source_set_icon (lp #1070421) * call gtk-update-icon-cache (lp #1060618) 12.10.4 * specify fallback icons for the ones with status emblem (lp #1056595) * make icon size consistent with the other indicators (lp #1055966) * libmessaging-menu: fix crash when receiving a invalid desktop id (lp #1058386) 12.10.3 * hide indicator when no application shows in the menu (lp #661059) * remove apps as soon as they are uninstalled (lp #864545) * make generated .gir compatible with vala (lp #104496) * draw counts as lozenges (lp #1046331) * show separators (lp #1048245) * show chat presence in the panel (lp #859905) * improve documentation 12.10.2 * libmessaging-menu: - expand source documentation and add gtk-doc to the build system - added new API: messaging_menu_app_set_source_{label,icon} - fix bug: only one MessagingMenuApp was exported to the messaging menu 12.10.1 * presence icons are shown again * the icon is changed when a source draws attention * the time in source menu items is always kep current * fixed all g-ir-scanner warnings * libmessaging-menu now removes sources when they are activated * fixed several bugs ./configure.ac0000644000004100000410000001241613350212604013531 0ustar www-datawww-data AC_INIT(indicator-messages, 12.10.5) AC_PREREQ(2.62) AM_CONFIG_HEADER(config.h) AM_INIT_AUTOMAKE([check-news]) AM_MAINTAINER_MODE IT_PROG_INTLTOOL([0.35.0]) AC_ISC_POSIX AC_PROG_CC AM_PROG_CC_C_O AC_STDC_HEADERS AC_DISABLE_STATIC AC_PROG_LIBTOOL AC_SUBST(VERSION) AC_CONFIG_MACRO_DIR([m4]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) AC_ARG_ENABLE([deprecations], [AS_HELP_STRING([--enable-deprecations], [allow deprecated API usage @<:@default=yes@:>@])], [], [enable_deprecations=yes]) AS_IF([test "x$enable_deprecations" = xno], [CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE -DGTK_DISABLE_SINGLE_INCLUDES"] ) # the Google Test targets are cpp AC_PROG_CXX ########################### # Dependencies ########################### GIO_UNIX_REQUIRED_VERSION=2.33.10 GLIB_REQUIRED_VERSION=2.35.4 INTROSPECTION_REQUIRED_VERSION=1.32.0 PKG_CHECK_MODULES(APPLET, gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION glib-2.0 >= $GLIB_REQUIRED_VERSION accountsservice) PKG_CHECK_MODULES(GIO, gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION) PKG_CHECK_MODULES(DBUSTEST, dbustest-1) AC_SUBST(APPLET_CFLAGS) AC_SUBST(APPLET_LIBS) GLIB_GSETTINGS GTK_DOC_CHECK([1.18], [--flavour no-tmpl]) GOBJECT_INTROSPECTION_CHECK([$INTROSPECTION_REQUIRED_VERSION]) AC_ARG_WITH([indicator-dir], [AS_HELP_STRING([--with-indicator-dir=DIR], [Indicator directory [default=$datadir/unity/indicators]])], [], [with_indicator_dir=$datadir/unity/indicators]) AC_SUBST([INDICATOR_DIR], [$with_indicator_dir]) SYSTEMD_USERDIR=`$PKG_CONFIG --variable=systemduserunitdir systemd` AC_SUBST(SYSTEMD_USERDIR) ########################### # gcov coverage reporting ########################### m4_include([m4/gcov.m4]) AC_TDD_GCOV AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes]) AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes]) AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes]) AC_SUBST(COVERAGE_CFLAGS) AC_SUBST(COVERAGE_CXXFLAGS) AC_SUBST(COVERAGE_LDFLAGS) ########################### # Tests ########################### AC_ARG_ENABLE([tests], [AS_HELP_STRING([--disable-tests], [Disable test scripts and tools (default=auto)])], [enable_tests=${enableval}], [enable_tests=auto]) if test "x$enable_tests" != "xno"; then m4_include([m4/gtest.m4]) CHECK_GTEST AM_PATH_PYTHON(3.0,, [:]) AC_PYTHON_MODULE(dbusmock) if test "x$have_gtest" = "xyes" -a "x$HAVE_PYMOD_DBUSMOCK" = "xyes"; then enable_tests="yes" else if test "x$enable_tests" = "xyes"; then AC_MSG_ERROR([tests were requested but gtest or dbusmock are not installed.]) else enable_tests="no" fi fi fi AM_CONDITIONAL([BUILD_TESTS],[test "x$enable_tests" = "xyes"]) ########################### # Vala API Generation ########################### AC_ARG_ENABLE([vala], AC_HELP_STRING([--disable-vala], [Disable vala]), [enable_vala=$enableval], [enable_vala=yes]) AS_IF([test "x$enable_vala" != "xno"],[ AM_COND_IF([HAVE_INTROSPECTION],,[ AC_MSG_ERROR([Vala bindings require introspection support, please --enable-introspection]) ]) AC_PATH_PROG([VALA_API_GEN], [vapigen]) ]) AM_CONDITIONAL([HAVE_VALA], [test -n "$VALA_API_GEN"]) ############################## # Custom Junk ############################## AC_DEFUN([AC_DEFINE_PATH], [ test "x$prefix" = xNONE && prefix="$ac_default_prefix" test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' ac_define_path=`eval echo [$]$2` ac_define_path=`eval echo [$]ac_define_path` $1="$ac_define_path" AC_SUBST($1) ifelse($3, , AC_DEFINE_UNQUOTED($1, "$ac_define_path"), AC_DEFINE_UNQUOTED($1, "$ac_define_path", $3)) ]) ########################### # Internationalization ########################### GETTEXT_PACKAGE=indicator-messages AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Name of the default get text domain]) AC_DEFINE_PATH(GNOMELOCALEDIR, "${datadir}/locale", [locale directory]) AM_GLIB_GNU_GETTEXT ########################### # Files ########################### AC_OUTPUT([ Makefile src/Makefile common/Makefile data/Makefile data/icons/Makefile data/icons/16x16/Makefile data/icons/16x16/status/Makefile data/icons/16x16/categories/Makefile data/icons/22x22/Makefile data/icons/22x22/status/Makefile data/icons/22x22/categories/Makefile data/icons/24x24/Makefile data/icons/24x24/status/Makefile data/icons/32x32/Makefile data/icons/32x32/status/Makefile data/icons/32x32/categories/Makefile data/icons/48x48/Makefile data/icons/48x48/status/Makefile data/icons/scalable/Makefile data/icons/scalable/status/Makefile data/icons/scalable/categories/Makefile data/upstart/Makefile po/Makefile.in tests/Makefile libmessaging-menu/Makefile libmessaging-menu/messaging-menu.pc doc/Makefile doc/reference/Makefile doc/reference/messaging-menu-docs.xml ]) ########################### # Results ########################### AC_MSG_NOTICE([ Messaging Indicator Configuration: Prefix: $prefix Indicator Dir: $INDICATORDIR tests: $enable_tests gcov: $use_gcov introspecion: $enable_introspection Vala bindings: $enable_vala documentation: $enable_gtk_doc ]) ./README0000644000004100000410000000000013350212604012105 0ustar www-datawww-data./src/0000755000004100000410000000000013350212604012026 5ustar www-datawww-data./src/im-application-list.h0000644000004100000410000000622113350212604016057 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #ifndef __IM_APPLICATION_LIST_H__ #define __IM_APPLICATION_LIST_H__ #include #include #define IM_TYPE_APPLICATION_LIST (im_application_list_get_type ()) #define IM_APPLICATION_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_APPLICATION_LIST, ImApplicationList)) #define IM_APPLICATION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_APPLICATION_LIST, ImApplicationListClass)) #define IM_IS_APPLICATION_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_APPLICATION_LIST)) #define IM_IS_APPLICATION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_APPLICATION_LIST)) #define IM_APPLICATION_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_APPLICATION_LIST, ImApplicationListClass)) typedef struct _ImApplicationList ImApplicationList; GType im_application_list_get_type (void); ImApplicationList * im_application_list_new (void); gboolean im_application_list_add (ImApplicationList *list, const gchar *desktop_id); void im_application_list_remove (ImApplicationList *list, const gchar *id); void im_application_list_set_remote (ImApplicationList *list, const gchar *id, GDBusConnection *connection, const gchar *unique_bus_name, const gchar *object_path); GActionGroup * im_application_list_get_action_group (ImApplicationList *list); GList * im_application_list_get_applications (ImApplicationList *list); GDesktopAppInfo * im_application_list_get_application (ImApplicationList *list, const gchar *id); void im_application_list_set_status (ImApplicationList *list, const gchar *id, const gchar *status); #endif ./src/im-desktop-menu.h0000644000004100000410000000242413350212604015217 0ustar www-datawww-data/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #ifndef __IM_DESKTOP_MENU_H__ #define __IM_DESKTOP_MENU_H__ #include "im-menu.h" #define IM_TYPE_DESKTOP_MENU (im_desktop_menu_get_type ()) #define IM_DESKTOP_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_DESKTOP_MENU, ImDesktopMenu)) #define IM_IS_DESKTOP_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_DESKTOP_MENU)) typedef struct _ImDesktopMenu ImDesktopMenu; GType im_desktop_menu_get_type (void); ImDesktopMenu * im_desktop_menu_new (ImApplicationList *applist); #endif ./src/gactionmuxer.h0000644000004100000410000000323413350212604014706 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel * Ryan Lortie */ #ifndef __G_ACTION_MUXER_H__ #define __G_ACTION_MUXER_H__ #include #define G_TYPE_ACTION_MUXER (g_action_muxer_get_type ()) #define G_ACTION_MUXER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_ACTION_MUXER, GActionMuxer)) #define G_IS_ACTION_MUXER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_ACTION_MUXER)) typedef struct _GActionMuxer GActionMuxer; GType g_action_muxer_get_type (void) G_GNUC_CONST; GActionMuxer * g_action_muxer_new (void); void g_action_muxer_insert (GActionMuxer *muxer, const gchar *prefix, GActionGroup *group); void g_action_muxer_remove (GActionMuxer *muxer, const gchar *prefix); GActionGroup * g_action_muxer_get_group (GActionMuxer *muxer, const gchar *prefix); #endif ./src/gsettingsstrv.h0000644000004100000410000000231713350212604015130 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #ifndef __G_SETTINGS_STRV_H__ #define __G_SETTINGS_STRV_H__ #include gboolean g_settings_strv_append_unique (GSettings *settings, const gchar *key, const gchar *item); void g_settings_strv_remove (GSettings *settings, const gchar *key, const gchar *item); #endif ./src/dbus-data.h0000644000004100000410000000211413350212604014041 0ustar www-datawww-data/* * Copyright 2012-2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #ifndef __DBUS_DATA_H__ #define __DBUS_DATA_H__ 1 #define INDICATOR_MESSAGES_DBUS_NAME "com.canonical.indicator.messages" #define INDICATOR_MESSAGES_DBUS_OBJECT "/com/canonical/indicator/messages" #define INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT "/com/canonical/indicator/messages/service" #define INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE "com.canonical.indicator.messages.service" #endif /* __DBUS_DATA_H__ */ ./src/im-menu.c0000644000004100000410000001650513350212604013550 0ustar www-datawww-data/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #include "im-menu.h" #include "im-accounts-service.h" struct _ImMenuPrivate { GMenu *toplevel_menu; GMenu *menu; ImApplicationList *applist; gboolean on_greeter; ImAccountsService *as; }; G_DEFINE_TYPE_WITH_PRIVATE (ImMenu, im_menu, G_TYPE_OBJECT) enum { PROP_0, PROP_APPLICATION_LIST, PROP_ON_GREETER, NUM_PROPERTIES }; static void im_menu_finalize (GObject *object) { ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); g_object_unref (priv->toplevel_menu); g_object_unref (priv->menu); g_object_unref (priv->applist); g_object_unref (priv->as); G_OBJECT_CLASS (im_menu_parent_class)->finalize (object); } static void im_menu_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); switch (property_id) { case PROP_APPLICATION_LIST: g_value_set_object (value, priv->applist); break; case PROP_ON_GREETER: g_value_set_boolean (value, priv->on_greeter); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } } static void im_menu_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); switch (property_id) { case PROP_APPLICATION_LIST: /* construct only */ priv->applist = g_value_dup_object (value); break; case PROP_ON_GREETER: priv->on_greeter = g_value_get_boolean (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } } static void im_menu_class_init (ImMenuClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); object_class->finalize = im_menu_finalize; object_class->get_property = im_menu_get_property; object_class->set_property = im_menu_set_property; g_object_class_install_property (object_class, PROP_APPLICATION_LIST, g_param_spec_object ("application-list", "", "", IM_TYPE_APPLICATION_LIST, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ON_GREETER, g_param_spec_boolean ("on-greeter", "", "", FALSE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } static void im_menu_init (ImMenu *menu) { ImMenuPrivate *priv = im_menu_get_instance_private (menu); GMenuItem *root; priv->toplevel_menu = g_menu_new (); priv->menu = g_menu_new (); priv->on_greeter = FALSE; priv->as = im_accounts_service_ref_default(); root = g_menu_item_new (NULL, "indicator.messages"); g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root"); g_menu_item_set_attribute (root, "action-namespace", "s", "indicator"); g_menu_item_set_submenu (root, G_MENU_MODEL (priv->menu)); g_menu_append_item (priv->toplevel_menu, root); g_object_unref (root); } ImApplicationList * im_menu_get_application_list (ImMenu *menu) { ImMenuPrivate *priv; g_return_val_if_fail (IM_IS_MENU (menu), FALSE); priv = im_menu_get_instance_private (menu); return priv->applist; } gboolean im_menu_export (ImMenu *menu, GDBusConnection *connection, const gchar *object_path, GError **error) { ImMenuPrivate *priv; g_return_val_if_fail (IM_IS_MENU (menu), FALSE); priv = im_menu_get_instance_private (menu); return g_dbus_connection_export_menu_model (connection, object_path, G_MENU_MODEL (priv->toplevel_menu), error) > 0; } void im_menu_prepend_section (ImMenu *menu, GMenuModel *section) { ImMenuPrivate *priv; g_return_if_fail (IM_IS_MENU (menu)); g_return_if_fail (G_IS_MENU_MODEL (section)); priv = im_menu_get_instance_private (menu); g_menu_prepend_section (priv->menu, NULL, section); } void im_menu_append_section (ImMenu *menu, GMenuModel *section) { ImMenuPrivate *priv; g_return_if_fail (IM_IS_MENU (menu)); g_return_if_fail (G_IS_MENU_MODEL (section)); priv = im_menu_get_instance_private (menu); g_menu_append_section (priv->menu, NULL, section); } /* * Inserts @item into @menu by comparing its * "x-messaging-menu-sort-string" with those found in existing menu * items between positions @first and @last. * * If @last is negative, it is counted from the end of @menu. */ void im_menu_insert_item_sorted (ImMenu *menu, GMenuItem *item, gint first, gint last) { ImMenuPrivate *priv; gint position = first; gchar *sort_string; g_return_if_fail (IM_IS_MENU (menu)); g_return_if_fail (G_IS_MENU_ITEM (item)); priv = im_menu_get_instance_private (menu); if (last < 0) last = g_menu_model_get_n_items (G_MENU_MODEL (priv->menu)) + last; g_return_if_fail (first <= last); if (g_menu_item_get_attribute (item, "x-messaging-menu-sort-string", "s", &sort_string)) { while (position < last) { gchar *item_sort; if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort)) { gint cmp; cmp = g_utf8_collate(sort_string, item_sort); g_free (item_sort); if (cmp < 0) break; } position++; } } g_menu_insert_item (priv->menu, position, item); } /* Whether the menu should show extra data on it. Depends on the greeter status and user settings */ gboolean im_menu_show_data (ImMenu *menu) { g_return_val_if_fail (IM_IS_MENU (menu), FALSE); ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (menu)); if (!priv->on_greeter) return TRUE; return im_accounts_service_get_show_on_greeter(priv->as); } ./src/im-desktop-menu.c0000644000004100000410000003216713350212604015221 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #include "im-desktop-menu.h" #include "indicator-desktop-shortcuts.h" #include typedef ImMenuClass ImDesktopMenuClass; struct _ImDesktopMenu { ImMenu parent; gboolean status_section_visible; GMenu *default_chat_client_section; GMenu *default_mail_client_section; GHashTable *source_sections; }; G_DEFINE_TYPE (ImDesktopMenu, im_desktop_menu, IM_TYPE_MENU); static void menu_append_status (GMenu *menu, const gchar *label, const gchar *detailed_action, const gchar *icon_name) { GMenuItem *item; GIcon *icon; icon = g_themed_icon_new (icon_name); item = g_menu_item_new (label, detailed_action); g_menu_item_set_icon (item, icon); g_menu_append_item (menu, item); g_object_unref (icon); g_object_unref (item); } static void im_desktop_menu_show_chat_section (ImDesktopMenu *menu) { GMenu *status_section; if (menu->status_section_visible) return; status_section = g_menu_new (); menu_append_status (status_section, _("Available"), "indicator.status::available", "user-available"); menu_append_status (status_section, _("Away"), "indicator.status::away", "user-away"); menu_append_status (status_section, _("Busy"), "indicator.status::busy", "user-busy"); menu_append_status (status_section, _("Invisible"), "indicator.status::invisible", "user-invisible"); menu_append_status (status_section, _("Offline"), "indicator.status::offline", "user-offline"); im_menu_prepend_section (IM_MENU (menu), G_MENU_MODEL (status_section)); menu->status_section_visible = TRUE; g_object_unref (status_section); } static gboolean g_app_info_is_default_for_uri_scheme (GAppInfo *info, const gchar *uri_scheme) { GAppInfo *default_info; gboolean is_default = FALSE; default_info = g_app_info_get_default_for_uri_scheme (uri_scheme); if (default_info) { is_default = g_app_info_equal (info, default_info); g_object_unref (default_info); } return is_default; } static void im_desktop_menu_app_added (ImApplicationList *applist, const gchar *app_id, GDesktopAppInfo *app_info, gpointer user_data) { ImDesktopMenu *menu = user_data; GMenu *section; GMenu *app_section; GMenu *source_section; gchar *namespace; GMenuItem *item; app_section = g_menu_new (); /* application launcher */ { GMenuItem *item; GVariant *icon; item = g_menu_item_new (g_app_info_get_name (G_APP_INFO (app_info)), "launch"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.application"); icon = g_icon_serialize (g_app_info_get_icon (G_APP_INFO (app_info))); if (icon) { g_menu_item_set_attribute_value (item, "icon", icon); g_variant_unref (icon); } g_menu_append_item (app_section, item); g_object_unref (item); } /* application actions */ { const gchar * filename = NULL; IndicatorDesktopShortcuts * shortcuts = NULL; const gchar ** nicks = {NULL}; filename = g_desktop_app_info_get_filename(app_info); if (filename != NULL) shortcuts = indicator_desktop_shortcuts_new(filename, "Messaging Menu"); if (shortcuts != NULL) for (nicks = indicator_desktop_shortcuts_get_nicks(shortcuts); *nicks; nicks++) { GMenuItem *item; gchar *label; label = indicator_desktop_shortcuts_nick_get_name (shortcuts, *nicks); item = g_menu_item_new (label, *nicks); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.application"); g_menu_append_item (app_section, item); g_free (label); g_object_unref (item); } g_clear_object(&shortcuts); } if (g_desktop_app_info_get_boolean (app_info, "X-MessagingMenu-UsesChatSection")) im_desktop_menu_show_chat_section (menu); source_section = g_menu_new (); section = g_menu_new (); g_menu_append_section (section, NULL, G_MENU_MODEL (app_section)); g_menu_append_section (section, NULL, G_MENU_MODEL (source_section)); item = g_menu_item_new_section (NULL, G_MENU_MODEL (section)); namespace = g_strconcat ("indicator.", app_id, NULL); g_menu_item_set_attribute (item, "action-namespace", "s", namespace); /* The default chat client is not stored anywhere, so let's hardcode empathy. */ if (g_str_equal (app_id, "empathy")) { g_menu_remove_all (menu->default_chat_client_section); g_menu_append_item (menu->default_chat_client_section, item); } else if (g_app_info_is_default_for_uri_scheme (G_APP_INFO (app_info), "mailto")) { g_menu_remove_all (menu->default_mail_client_section); g_menu_append_item (menu->default_mail_client_section, item); } else { g_menu_item_set_attribute (item, "x-messaging-menu-sort-string", "s", g_app_info_get_name(G_APP_INFO(app_info))); im_menu_insert_item_sorted (IM_MENU (menu), item, menu->status_section_visible ? 3 : 2, -1); } g_hash_table_insert (menu->source_sections, g_strdup (app_id), source_section); g_free (namespace); g_object_unref (item); g_object_unref (section); g_object_unref (app_section); } static void im_desktop_menu_source_section_insert_source (GMenu *source_section, const gchar *source_id, const gchar *label, GVariant *serialized_icon, gint pos) { GMenuItem *item; gchar *action; action = g_strconcat ("src.", source_id, NULL); item = g_menu_item_new (label, NULL); g_menu_item_set_action_and_target_value (item, action, NULL); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.source"); if (serialized_icon) g_menu_item_set_attribute_value (item, "icon", serialized_icon); if (pos >= 0) g_menu_insert_item (source_section, pos, item); else g_menu_append_item (source_section, item); g_free (action); g_object_unref (item); } static gint im_desktop_menu_source_section_find_source (GMenu *source_section, const gchar *source_id) { gint n_items; gchar *action; gint i; n_items = g_menu_model_get_n_items (G_MENU_MODEL (source_section)); action = g_strconcat ("src.", source_id, NULL); for (i = 0; i < n_items; i++) { gchar *item_action; if (g_menu_model_get_item_attribute (G_MENU_MODEL (source_section), i, "action", "s", &item_action)) { gboolean equal; equal = g_str_equal (action, item_action); g_free (item_action); if (equal) break; } } g_free (action); return i < n_items ? i : -1; } static void im_desktop_menu_source_added (ImApplicationList *applist, const gchar *app_id, const gchar *source_id, const gchar *label, GVariant *serialized_icon, gboolean visible, gpointer user_data) { ImDesktopMenu *menu = user_data; GMenu *source_section; source_section = g_hash_table_lookup (menu->source_sections, app_id); g_return_if_fail (source_section != NULL); if (visible) im_desktop_menu_source_section_insert_source (source_section, source_id, label, serialized_icon, -1); } static void im_desktop_menu_source_removed (ImApplicationList *applist, const gchar *app_id, const gchar *source_id, gpointer user_data) { ImDesktopMenu *menu = user_data; GMenu *source_section; gint pos; source_section = g_hash_table_lookup (menu->source_sections, app_id); g_return_if_fail (source_section != NULL); pos = im_desktop_menu_source_section_find_source (source_section, source_id); if (pos >= 0) g_menu_remove (source_section, pos); } static void im_desktop_menu_source_changed (ImApplicationList *applist, const gchar *app_id, const gchar *source_id, const gchar *label, GVariant *serialized_icon, gboolean visible, gpointer user_data) { ImDesktopMenu *menu = user_data; GMenu *section; gint pos; section = g_hash_table_lookup (menu->source_sections, app_id); g_return_if_fail (section != NULL); pos = im_desktop_menu_source_section_find_source (section, source_id); if (pos >= 0) g_menu_remove (section, pos); if (visible) im_desktop_menu_source_section_insert_source (section, source_id, label, serialized_icon, pos); } static void im_desktop_menu_remove_all (ImApplicationList *applist, gpointer user_data) { ImDesktopMenu *menu = user_data; GHashTableIter it; GMenu *section; g_hash_table_iter_init (&it, menu->source_sections); while (g_hash_table_iter_next (&it, NULL, (gpointer *) §ion)) { while (g_menu_model_get_n_items (G_MENU_MODEL (section)) > 0) g_menu_remove (section, 0); } } static void im_desktop_menu_app_stopped (ImApplicationList *applist, const gchar *app_id, gpointer user_data) { ImDesktopMenu *menu = user_data; GMenu *section; section = g_hash_table_lookup (menu->source_sections, app_id); g_return_if_fail (section != NULL); while (g_menu_model_get_n_items (G_MENU_MODEL (section)) > 0) g_menu_remove (section, 0); } static void im_desktop_menu_constructed (GObject *object) { ImDesktopMenu *menu = IM_DESKTOP_MENU (object); ImApplicationList *applist; menu->default_chat_client_section = g_menu_new (); im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->default_chat_client_section)); menu->default_mail_client_section = g_menu_new (); im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->default_mail_client_section)); { GMenu *clear_section; clear_section = g_menu_new (); g_menu_append (clear_section, _("Clear"), "indicator.remove-all"); im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (clear_section)); g_object_unref (clear_section); } applist = im_menu_get_application_list (IM_MENU (menu)); { GList *apps; GList *it; apps = im_application_list_get_applications (applist); for (it = apps; it != NULL; it = it->next) { const gchar *id = it->data; im_desktop_menu_app_added (applist, id, im_application_list_get_application (applist, id), menu); } g_list_free (apps); } g_signal_connect (applist, "app-added", G_CALLBACK (im_desktop_menu_app_added), menu); g_signal_connect (applist, "source-added", G_CALLBACK (im_desktop_menu_source_added), menu); g_signal_connect (applist, "source-removed", G_CALLBACK (im_desktop_menu_source_removed), menu); g_signal_connect (applist, "source-changed", G_CALLBACK (im_desktop_menu_source_changed), menu); g_signal_connect (applist, "remove-all", G_CALLBACK (im_desktop_menu_remove_all), menu); g_signal_connect (applist, "app-stopped", G_CALLBACK (im_desktop_menu_app_stopped), menu); G_OBJECT_CLASS (im_desktop_menu_parent_class)->constructed (object); } static void im_desktop_menu_finalize (GObject *object) { ImDesktopMenu *menu = IM_DESKTOP_MENU (object); g_hash_table_unref (menu->source_sections); G_OBJECT_CLASS (im_desktop_menu_parent_class)->finalize (object); } static void im_desktop_menu_class_init (ImDesktopMenuClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructed = im_desktop_menu_constructed; object_class->finalize = im_desktop_menu_finalize; } static void im_desktop_menu_init (ImDesktopMenu *menu) { menu->source_sections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } ImDesktopMenu * im_desktop_menu_new (ImApplicationList *applist) { g_return_val_if_fail (IM_IS_APPLICATION_LIST (applist), NULL); return g_object_new (IM_TYPE_DESKTOP_MENU, "application-list", applist, NULL); } ./src/im-menu.h0000644000004100000410000000563613350212604013560 0ustar www-datawww-data/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #ifndef __IM_MENU_H__ #define __IM_MENU_H__ #include #include "im-application-list.h" #define IM_TYPE_MENU (im_menu_get_type ()) #define IM_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_MENU, ImMenu)) #define IM_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_MENU, ImMenuClass)) #define IM_IS_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_MENU)) #define IM_IS_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_MENU)) #define IM_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_MENU, ImMenuClass)) typedef struct _ImMenuClass ImMenuClass; typedef struct _ImMenu ImMenu; typedef struct _ImMenuPrivate ImMenuPrivate; struct _ImMenuClass { GObjectClass parent_class; }; struct _ImMenu { GObject parent_instance; }; GType im_menu_get_type (void) G_GNUC_CONST; ImApplicationList * im_menu_get_application_list (ImMenu *menu); gboolean im_menu_export (ImMenu *menu, GDBusConnection *connection, const gchar *object_path, GError **error); void im_menu_prepend_section (ImMenu *menu, GMenuModel *section); void im_menu_append_section (ImMenu *menu, GMenuModel *section); void im_menu_insert_item_sorted (ImMenu *menu, GMenuItem *item, gint first, gint last); gboolean im_menu_show_data (ImMenu *menu); #endif ./src/im-application-list.c0000644000004100000410000013443313350212604016061 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #include "im-application-list.h" #include "indicator-messages-application.h" #include "gactionmuxer.h" #include "indicator-desktop-shortcuts.h" #include "im-accounts-service.h" #include #include #include "glib/gi18n.h" typedef GObjectClass ImApplicationListClass; struct _ImApplicationList { GObject parent; GHashTable *applications; GActionMuxer *muxer; GSimpleActionGroup * globalactions; GSimpleAction * statusaction; GHashTable *app_status; ImAccountsService * as; }; G_DEFINE_TYPE (ImApplicationList, im_application_list, G_TYPE_OBJECT); G_DEFINE_QUARK (draws_attention, message_action_draws_attention); enum { SOURCE_ADDED, SOURCE_CHANGED, SOURCE_REMOVED, MESSAGE_ADDED, MESSAGE_REMOVED, APP_ADDED, APP_STOPPED, REMOVE_ALL, STATUS_SET, N_SIGNALS }; static guint signals[N_SIGNALS]; typedef struct { ImApplicationList *list; GDesktopAppInfo *info; gchar *id; IndicatorMessagesApplication *proxy; GActionMuxer *muxer; GSimpleActionGroup *source_actions; GSimpleActionGroup *message_actions; GActionMuxer *message_sub_actions; GCancellable *cancellable; gboolean draws_attention; IndicatorDesktopShortcuts * shortcuts; } Application; /* Prototypes */ static void status_activated (GSimpleAction * action, GVariant * param, gpointer user_data); static void application_free (gpointer data) { Application *app = data; if (!app) return; g_object_unref (app->info); g_free (app->id); if (app->cancellable) { g_cancellable_cancel (app->cancellable); g_clear_object (&app->cancellable); } if (app->proxy) g_object_unref (app->proxy); if (app->muxer) { g_object_unref (app->muxer); g_object_unref (app->source_actions); g_object_unref (app->message_actions); g_object_unref (app->message_sub_actions); } g_clear_object (&app->shortcuts); g_slice_free (Application, app); } /* Check to see if we have actions by getting the full list of names and see if there is one. Not exactly efficient :-/ */ static gboolean _g_action_group_has_actions (GActionGroup * ag) { gchar ** list = NULL; gboolean retval = FALSE; list = g_action_group_list_actions(ag); retval = (list[0] != NULL); g_strfreev(list); return retval; } static gchar * escape_action_name (const gchar *name) { static const gchar *xdigits = "0123456789abcdef"; GString *escaped; gchar c; g_return_val_if_fail (name != NULL, NULL); escaped = g_string_new (NULL); while ((c = *name++)) { if (g_ascii_isalnum (c) || c == '.') { g_string_append_c (escaped, c); } else { g_string_append_c (escaped, '-'); g_string_append_c (escaped, xdigits[c >> 4]); g_string_append_c (escaped, xdigits[c & 0xf]); } } return g_string_free (escaped, FALSE); } static gchar * unescape_action_name (const gchar *name) { GString *unescaped; gint i; g_return_val_if_fail (name != NULL, NULL); unescaped = g_string_new (NULL); for (i = 0; name[i]; i++) { gint one, two; if (name[i] == '-' && (one = g_ascii_xdigit_value (name[i + 1])) >= 0 && (two = g_ascii_xdigit_value (name[i + 2])) >= 0) { g_string_append_c (unescaped, (one << 4) | two); i += 2; } else { g_string_append_c (unescaped, name[i]); } } return g_string_free (unescaped, FALSE); } /* Check to see if either of our action groups has any actions, if so return TRUE so we get chosen! */ static gboolean application_has_items (gpointer key, gpointer value, gpointer user_data) { Application *app = value; return _g_action_group_has_actions(G_ACTION_GROUP(app->source_actions)) || _g_action_group_has_actions(G_ACTION_GROUP(app->message_actions)); } static gboolean application_draws_attention (gpointer key, gpointer value, gpointer user_data) { Application *app = value; return app->draws_attention; } static void im_application_list_update_root_action (ImApplicationList *list) { const gchar *base_icon_name; const gchar *accessible_name; gchar *icon_name; GIcon * icon; GVariant *serialized_icon; GVariantBuilder builder; GVariant *state; guint n_applications; /* Figure out what type of icon we should be drawing */ if (g_hash_table_find (list->applications, application_draws_attention, NULL)) { base_icon_name = "indicator-messages-new-%s"; accessible_name = _("New Messages"); im_accounts_service_set_draws_attention(list->as, TRUE); } else { base_icon_name = "indicator-messages-%s"; accessible_name = _("Messages"); im_accounts_service_set_draws_attention(list->as, FALSE); } /* Include the IM state in the icon */ state = g_action_group_get_action_state(G_ACTION_GROUP(list->globalactions), "status"); icon_name = g_strdup_printf(base_icon_name, g_variant_get_string(state, NULL)); g_variant_unref(state); /* Build up the dictionary of values for the state */ g_variant_builder_init(&builder, G_VARIANT_TYPE_DICTIONARY); /* icon */ icon = g_themed_icon_new_with_default_fallbacks(icon_name); g_free(icon_name); if ((serialized_icon = g_icon_serialize(icon))) { g_variant_builder_add (&builder, "{sv}", "icon", serialized_icon); g_variant_unref (serialized_icon); } g_object_unref(icon); /* title */ g_variant_builder_add (&builder, "{sv}", "title", g_variant_new_string (_("Notifications"))); /* accessible description */ g_variant_builder_open(&builder, G_VARIANT_TYPE_DICT_ENTRY); g_variant_builder_add_value(&builder, g_variant_new_string("accessible-desc")); g_variant_builder_add_value(&builder, g_variant_new_variant(g_variant_new_string(accessible_name))); g_variant_builder_close(&builder); /* visibility */ n_applications = g_hash_table_size (list->applications); g_variant_builder_add (&builder, "{sv}", "visible", g_variant_new_boolean (n_applications > 0)); /* Set the state */ g_action_group_change_action_state (G_ACTION_GROUP(list->globalactions), "messages", g_variant_builder_end(&builder)); GAction * remove_action = g_action_map_lookup_action (G_ACTION_MAP (list->globalactions), "remove-all"); if (g_hash_table_find (list->applications, application_has_items, NULL)) { g_debug("Enabling remove-all"); g_simple_action_set_enabled(G_SIMPLE_ACTION(remove_action), TRUE); } else { g_debug("Disabling remove-all"); g_simple_action_set_enabled(G_SIMPLE_ACTION(remove_action), FALSE); } } /* Check a source action to see if it draws */ static gboolean app_source_action_check_draw (Application * app, const gchar * action_name) { GVariant *state; guint32 count; gint64 time; const gchar *string; gboolean draws_attention; state = g_action_group_get_action_state (G_ACTION_GROUP(app->source_actions), action_name); if (state == NULL) return FALSE; if (!g_variant_is_of_type(state, G_VARIANT_TYPE("(uxsb)"))) return FALSE; g_variant_get (state, "(ux&sb)", &count, &time, &string, &draws_attention); /* invisible sources do not draw attention */ if (count == 0 && time == 0 && (string == NULL || string[0] == '\0')) draws_attention = FALSE; g_variant_unref(state); return draws_attention; } /* Check a message action to see if it draws */ static gboolean app_message_action_check_draw (Application * app, const gchar * action_name) { GAction * action = NULL; action = g_action_map_lookup_action (G_ACTION_MAP (app->message_actions), action_name); return GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(action), message_action_draws_attention_quark())); } /* Regenerate the draw attention flag based on the sources and messages * that we have in the action groups. * * Returns TRUE if app->draws_attention has changed */ static gboolean application_update_draws_attention (Application * app) { gchar **source_actions = NULL; gchar **message_actions = NULL; gchar **it; gboolean was_drawing_attention = app->draws_attention; app->draws_attention = FALSE; source_actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); for (it = source_actions; *it && !app->draws_attention; it++) app->draws_attention = app_source_action_check_draw (app, *it); message_actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions)); for (it = message_actions; *it && !app->draws_attention; it++) app->draws_attention = app_message_action_check_draw (app, *it); g_strfreev (source_actions); g_strfreev (message_actions); return was_drawing_attention != app->draws_attention; } static void im_application_list_source_removed_action (Application *app, const gchar *action_name) { g_action_map_remove_action (G_ACTION_MAP(app->source_actions), action_name); g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, action_name); application_update_draws_attention (app); im_application_list_update_root_action (app->list); } /* Remove a source from an application, signal up and update the status of the draws attention flag. */ static void im_application_list_source_removed (Application *app, const gchar *id) { gchar *action_name; action_name = escape_action_name (id); im_application_list_source_removed_action (app, action_name); g_free (action_name); } static void im_application_list_source_activated (GSimpleAction *action, GVariant *parameter, gpointer user_data) { Application *app = user_data; const gchar *action_name; gchar *source_id; action_name = g_action_get_name (G_ACTION (action)); source_id = unescape_action_name (action_name); if (g_variant_get_boolean (parameter)) { indicator_messages_application_call_activate_source (app->proxy, source_id, app->cancellable, NULL, NULL); } else { const gchar *sources[] = { source_id, NULL }; const gchar *messages[] = { NULL }; indicator_messages_application_call_dismiss (app->proxy, sources, messages, app->cancellable, NULL, NULL); } im_application_list_source_removed_action (app, action_name); g_free (source_id); } static void im_application_list_message_removed_action (Application *app, const gchar *action_name) { g_action_map_remove_action (G_ACTION_MAP(app->message_actions), action_name); g_action_muxer_remove (app->message_sub_actions, action_name); application_update_draws_attention (app); im_application_list_update_root_action (app->list); g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, action_name); } static void im_application_list_message_removed (Application *app, const gchar *id) { gchar *action_name; action_name = escape_action_name (id); im_application_list_message_removed_action(app, action_name); g_free (action_name); } static void im_application_list_message_activated (GSimpleAction *action, GVariant *parameter, gpointer user_data) { Application *app = user_data; const gchar *action_name; gchar *message_id; action_name = g_action_get_name (G_ACTION (action)); message_id = unescape_action_name (action_name); if (g_variant_get_boolean (parameter)) { indicator_messages_application_call_activate_message (app->proxy, message_id, "", g_variant_new_array (G_VARIANT_TYPE_VARIANT, NULL, 0), app->cancellable, NULL, NULL); } else { const gchar *sources[] = { NULL }; const gchar *messages[] = { message_id, NULL }; indicator_messages_application_call_dismiss (app->proxy, sources, messages, app->cancellable, NULL, NULL); } im_application_list_message_removed_action (app, action_name); g_free (message_id); } static void im_application_list_sub_message_activated (GSimpleAction *action, GVariant *parameter, gpointer user_data) { Application *app = user_data; const gchar *message_id; gchar *action_id; GVariantBuilder builder; message_id = g_object_get_data (G_OBJECT (action), "message"); action_id = unescape_action_name (g_action_get_name (G_ACTION (action))); g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); if (parameter) g_variant_builder_add (&builder, "v", parameter); indicator_messages_application_call_activate_message (app->proxy, message_id, action_id, g_variant_builder_end (&builder), app->cancellable, NULL, NULL); im_application_list_message_removed (app, message_id); g_free (action_id); } static void im_application_list_remove_all (GSimpleAction *action, GVariant *parameter, gpointer user_data) { ImApplicationList *list = user_data; GHashTableIter iter; Application *app; g_signal_emit (list, signals[REMOVE_ALL], 0); g_hash_table_iter_init (&iter, list->applications); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &app)) { gchar **source_actions; gchar **message_actions; gchar **it; app->draws_attention = FALSE; source_actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions)); for (it = source_actions; *it; it++) im_application_list_source_removed_action (app, *it); message_actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions)); for (it = message_actions; *it; it++) im_application_list_message_removed_action (app, *it); if (app->proxy != NULL) /* If it is remote, we tell the app we've cleared */ { guint i; gchar **unescaped_source_actions; gchar **unescaped_message_actions; /* Unescape action names */ unescaped_source_actions = g_new0 (gchar *, g_strv_length (source_actions) + 1); for (i = 0; source_actions[i]; i++) unescaped_source_actions[i] = unescape_action_name (source_actions[i]); unescaped_message_actions = g_new0 (gchar *, g_strv_length (message_actions) + 1); for (i = 0; message_actions[i]; i++) unescaped_message_actions[i] = unescape_action_name (message_actions[i]); indicator_messages_application_call_dismiss (app->proxy, (const gchar * const *) unescaped_source_actions, (const gchar * const *) unescaped_message_actions, app->cancellable, NULL, NULL); g_strfreev (unescaped_source_actions); g_strfreev (unescaped_message_actions); } g_strfreev (source_actions); g_strfreev (message_actions); } im_application_list_update_root_action (list); } static void im_application_list_dispose (GObject *object) { ImApplicationList *list = IM_APPLICATION_LIST (object); g_clear_object (&list->statusaction); g_clear_object (&list->globalactions); g_clear_pointer (&list->app_status, g_hash_table_unref); g_clear_pointer (&list->applications, g_hash_table_unref); g_clear_object (&list->muxer); g_clear_object (&list->as); G_OBJECT_CLASS (im_application_list_parent_class)->dispose (object); } static void im_application_list_finalize (GObject *object) { G_OBJECT_CLASS (im_application_list_parent_class)->finalize (object); } static void im_application_list_class_init (ImApplicationListClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = im_application_list_dispose; object_class->finalize = im_application_list_finalize; signals[SOURCE_ADDED] = g_signal_new ("source-added", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_VARIANT, G_TYPE_BOOLEAN); signals[SOURCE_CHANGED] = g_signal_new ("source-changed", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_VARIANT, G_TYPE_BOOLEAN); signals[SOURCE_REMOVED] = g_signal_new ("source-removed", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); signals[MESSAGE_ADDED] = g_signal_new ("message-added", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 10, G_TYPE_STRING, G_TYPE_ICON, G_TYPE_STRING, G_TYPE_VARIANT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_VARIANT, G_TYPE_INT64, G_TYPE_BOOLEAN); signals[MESSAGE_REMOVED] = g_signal_new ("message-removed", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); signals[APP_ADDED] = g_signal_new ("app-added", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_DESKTOP_APP_INFO); signals[APP_STOPPED] = g_signal_new ("app-stopped", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); signals[REMOVE_ALL] = g_signal_new ("remove-all", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals[STATUS_SET] = g_signal_new ("status-set", IM_TYPE_APPLICATION_LIST, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_STRING); } static void im_application_list_init (ImApplicationList *list) { const GActionEntry action_entries[] = { { "remove-all", im_application_list_remove_all } }; list->applications = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, application_free); list->app_status = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); list->globalactions = g_simple_action_group_new (); { GSimpleAction * messages = g_simple_action_new_stateful("messages", NULL, g_variant_new_array(G_VARIANT_TYPE("{sv}"), NULL, 0)); g_action_map_add_action(G_ACTION_MAP(list->globalactions), G_ACTION(messages)); } g_action_map_add_action_entries (G_ACTION_MAP (list->globalactions), action_entries, G_N_ELEMENTS (action_entries), list); list->statusaction = g_simple_action_new_stateful("status", G_VARIANT_TYPE_STRING, g_variant_new_string("offline")); g_signal_connect(list->statusaction, "activate", G_CALLBACK(status_activated), list); g_action_map_add_action(G_ACTION_MAP(list->globalactions), G_ACTION(list->statusaction)); list->muxer = g_action_muxer_new (); g_action_muxer_insert (list->muxer, NULL, G_ACTION_GROUP (list->globalactions)); list->as = im_accounts_service_ref_default(); im_application_list_update_root_action (list); } ImApplicationList * im_application_list_new (void) { return g_object_new (IM_TYPE_APPLICATION_LIST, NULL); } static gchar * im_application_list_canonical_id (const gchar *id) { gchar *str; gchar *p; int len; len = strlen (id); if (g_str_has_suffix (id, ".desktop")) len -= 8; str = g_strndup (id, len); for (p = str; *p; p++) { if (*p == '.') *p = '_'; } return str; } static Application * im_application_list_lookup (ImApplicationList *list, const gchar *desktop_id) { gchar *id; Application *app; id = im_application_list_canonical_id (desktop_id); app = g_hash_table_lookup (list->applications, id); g_free (id); return app; } void im_application_list_activate_launch (GSimpleAction *action, GVariant *parameter, gpointer user_data) { Application *app = user_data; GError *error = NULL; if (!g_app_info_launch (G_APP_INFO (app->info), NULL, NULL, &error)) { g_warning ("unable to launch application: %s", error->message); g_error_free (error); } } void im_application_list_activate_app_action (GSimpleAction *action, GVariant *parameter, gpointer user_data) { Application *app = user_data; indicator_desktop_shortcuts_nick_exec_with_context (app->shortcuts, g_action_get_name (G_ACTION (action)), NULL); } gboolean im_application_list_add (ImApplicationList *list, const gchar *desktop_id) { GDesktopAppInfo *info; Application *app; const gchar *id; GSimpleActionGroup *actions; GSimpleAction *launch_action; IndicatorDesktopShortcuts * shortcuts = NULL; g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), FALSE); g_return_val_if_fail (desktop_id != NULL, FALSE); if (im_application_list_lookup (list, desktop_id)) return TRUE; info = g_desktop_app_info_new (desktop_id); if (!info) { g_warning ("an application with id '%s' is not installed", desktop_id); return FALSE; } id = g_app_info_get_id (G_APP_INFO (info)); g_return_val_if_fail (id != NULL, FALSE); { const char * filename = g_desktop_app_info_get_filename(info); if (filename != NULL) shortcuts = indicator_desktop_shortcuts_new(filename, "Messaging Menu"); } app = g_slice_new0 (Application); app->info = info; app->id = im_application_list_canonical_id (id); app->list = list; app->muxer = g_action_muxer_new (); app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); app->message_sub_actions = g_action_muxer_new (); app->draws_attention = FALSE; app->shortcuts = shortcuts; actions = g_simple_action_group_new (); launch_action = g_simple_action_new_stateful ("launch", NULL, g_variant_new_boolean (FALSE)); g_signal_connect (launch_action, "activate", G_CALLBACK (im_application_list_activate_launch), app); g_action_map_add_action (G_ACTION_MAP (actions), G_ACTION (launch_action)); if (app->shortcuts != NULL) { const gchar ** nicks; for (nicks = indicator_desktop_shortcuts_get_nicks (app->shortcuts); *nicks; nicks++) { GSimpleAction *action; action = g_simple_action_new (*nicks, NULL); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_activate_app_action), app); g_action_map_add_action (G_ACTION_MAP (actions), G_ACTION (action)); g_object_unref (action); } } g_action_muxer_insert (app->muxer, NULL, G_ACTION_GROUP (actions)); g_action_muxer_insert (app->muxer, "src", G_ACTION_GROUP (app->source_actions)); g_action_muxer_insert (app->muxer, "msg", G_ACTION_GROUP (app->message_actions)); g_action_muxer_insert (app->muxer, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); g_hash_table_insert (list->applications, (gpointer) app->id, app); g_action_muxer_insert (list->muxer, app->id, G_ACTION_GROUP (app->muxer)); im_application_list_update_root_action (list); g_signal_emit (app->list, signals[APP_ADDED], 0, app->id, app->info); g_object_unref (launch_action); g_object_unref (actions); return TRUE; } void im_application_list_remove (ImApplicationList *list, const gchar *id) { Application *app; g_return_if_fail (IM_IS_APPLICATION_LIST (list)); app = im_application_list_lookup (list, id); if (app) { if (app->proxy || app->cancellable) g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); g_hash_table_remove (list->applications, id); g_action_muxer_remove (list->muxer, id); im_application_list_update_root_action (list); } } static void im_application_list_source_added (Application *app, guint position, GVariant *source) { const gchar *id; const gchar *label; GVariant *maybe_serialized_icon; guint32 count; gint64 time; const gchar *string; gboolean draws_attention; gboolean visible; GVariant *serialized_icon = NULL; GVariant *state; GSimpleAction *action; gchar *action_name; g_variant_get (source, "(&s&s@avux&sb)", &id, &label, &maybe_serialized_icon, &count, &time, &string, &draws_attention); if (g_variant_n_children (maybe_serialized_icon) == 1) g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon); visible = count > 0 || time != 0 || (string != NULL && string[0] != '\0'); state = g_variant_new ("(uxsb)", count, time, string, draws_attention); action_name = escape_action_name (id); action = g_simple_action_new_stateful (action_name, G_VARIANT_TYPE_BOOLEAN, state); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_source_activated), app); g_action_map_add_action (G_ACTION_MAP(app->source_actions), G_ACTION (action)); g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, action_name, label, serialized_icon, visible); if (visible && draws_attention && app->draws_attention == FALSE) app->draws_attention = TRUE; im_application_list_update_root_action (app->list); g_free (action_name); g_object_unref (action); if (serialized_icon) g_variant_unref (serialized_icon); g_variant_unref (maybe_serialized_icon); } static void im_application_list_source_changed (Application *app, GVariant *source) { const gchar *id; const gchar *label; GVariant *maybe_serialized_icon; guint32 count; gint64 time; const gchar *string; gboolean draws_attention; GVariant *serialized_icon = NULL; gboolean visible; gchar *action_name; g_variant_get (source, "(&s&s@avux&sb)", &id, &label, &maybe_serialized_icon, &count, &time, &string, &draws_attention); if (g_variant_n_children (maybe_serialized_icon) == 1) g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon); action_name = escape_action_name (id); g_action_group_change_action_state (G_ACTION_GROUP (app->source_actions), action_name, g_variant_new ("(uxsb)", count, time, string, draws_attention)); visible = count > 0 || time != 0 || (string != NULL && string[0] != '\0'); g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, action_name, label, serialized_icon, visible); application_update_draws_attention (app); im_application_list_update_root_action (app->list); if (serialized_icon) g_variant_unref (serialized_icon); g_variant_unref (maybe_serialized_icon); g_free (action_name); } static void im_application_list_sources_listed (GObject *source_object, GAsyncResult *result, gpointer user_data) { Application *app = user_data; GVariant *sources; GError *error = NULL; if (indicator_messages_application_call_list_sources_finish (app->proxy, &sources, result, &error)) { GVariantIter iter; GVariant *source; guint i = 0; g_variant_iter_init (&iter, sources); while ((source = g_variant_iter_next_value (&iter))) { im_application_list_source_added (app, i++, source); g_variant_unref (source); } g_variant_unref (sources); } else { g_warning ("could not fetch the list of sources: %s", error->message); g_error_free (error); } } static GIcon * get_symbolic_app_icon (GDesktopAppInfo *info) { gchar *x_symbolic_icon; GIcon *icon; const gchar * const *names; gchar *symbolic_name; GIcon *symbolic_icon; /* If X-Ubuntu-SymbolicIcon exists, use that. It is always interpreted * as a filename. * * Simply appending -symbolic to the normal icon doesn't work for * icons specified by file name, because the symbolic icon might be in * a different format (symbolic icons tend to be svg and normal icons * png). Also, icons specified by file names don't allow for fallbacks * (without stating the file from this process), and we'd want to fall * back to the normal app icon. * * See lp: #1365408 */ if ((x_symbolic_icon = g_desktop_app_info_get_string (info, "X-Ubuntu-SymbolicIcon"))) { GFile *file; file = g_file_new_for_path (x_symbolic_icon); symbolic_icon = g_file_icon_new (file); g_object_unref (file); g_free (x_symbolic_icon); return symbolic_icon; } icon = g_app_info_get_icon (G_APP_INFO (info)); if (icon == NULL) return NULL; if (!G_IS_THEMED_ICON (icon)) return g_object_ref (icon); names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (!names || !names[0]) return g_object_ref (icon); symbolic_name = g_strconcat (names[0], "-symbolic", NULL); symbolic_icon = g_themed_icon_new_from_names ((gchar **) names, -1); g_themed_icon_prepend_name (G_THEMED_ICON (symbolic_icon), symbolic_name); g_free (symbolic_name); return symbolic_icon; } static void im_application_list_message_added (Application *app, GVariant *message) { const gchar *id; GVariant *maybe_serialized_icon; const gchar *title; const gchar *subtitle; const gchar *body; gint64 time; GVariantIter *action_iter; gboolean draws_attention; GVariant *serialized_icon = NULL; GSimpleAction *action; GIcon *app_icon; GVariant *actions = NULL; gchar *action_name; g_variant_get (message, "(&s@av&s&s&sxaa{sv}b)", &id, &maybe_serialized_icon, &title, &subtitle, &body, &time, &action_iter, &draws_attention); if (g_variant_n_children (maybe_serialized_icon) == 1) g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon); action_name = escape_action_name (id); action = g_simple_action_new (action_name, G_VARIANT_TYPE_BOOLEAN); g_object_set_qdata(G_OBJECT(action), message_action_draws_attention_quark(), GINT_TO_POINTER(draws_attention)); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); g_action_map_add_action (G_ACTION_MAP(app->message_actions), G_ACTION (action)); { GVariant *entry; GSimpleActionGroup *action_group; GVariantBuilder actions_builder; g_variant_builder_init (&actions_builder, G_VARIANT_TYPE ("aa{sv}")); action_group = g_simple_action_group_new (); while ((entry = g_variant_iter_next_value (action_iter))) { const gchar *name; GSimpleAction *action; GVariant *label; const gchar *type = NULL; GVariant *hint; GVariantBuilder dict_builder; gchar *prefixed_name; gchar *escaped_name; if (!g_variant_lookup (entry, "name", "&s", &name)) { g_warning ("action dictionary for message '%s' is missing 'name' key", id); continue; } label = g_variant_lookup_value (entry, "label", G_VARIANT_TYPE_STRING); g_variant_lookup (entry, "parameter-type", "&g", &type); hint = g_variant_lookup_value (entry, "parameter-hint", NULL); escaped_name = escape_action_name (name); action = g_simple_action_new (escaped_name, type ? G_VARIANT_TYPE (type) : NULL); g_object_set_data_full (G_OBJECT (action), "message", g_strdup (id), g_free); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_sub_message_activated), app); g_action_map_add_action (G_ACTION_MAP(action_group), G_ACTION (action)); g_variant_builder_init (&dict_builder, G_VARIANT_TYPE ("a{sv}")); prefixed_name = g_strjoin (".", app->id, "msg-actions", action_name, escaped_name, NULL); g_variant_builder_add (&dict_builder, "{sv}", "name", g_variant_new_string (prefixed_name)); if (label) { g_variant_builder_add (&dict_builder, "{sv}", "label", label); g_variant_unref (label); } if (type) g_variant_builder_add (&dict_builder, "{sv}", "parameter-type", g_variant_new_string (type)); if (hint) { g_variant_builder_add (&dict_builder, "{sv}", "parameter-hint", hint); g_variant_unref (hint); } g_variant_builder_add (&actions_builder, "a{sv}", &dict_builder); g_object_unref (action); g_variant_unref (entry); g_free (prefixed_name); g_free (escaped_name); } g_action_muxer_insert (app->message_sub_actions, action_name, G_ACTION_GROUP (action_group)); actions = g_variant_builder_end (&actions_builder); g_object_unref (action_group); } if (draws_attention && !app->draws_attention) { app->draws_attention = TRUE; im_application_list_update_root_action (app->list); } app_icon = get_symbolic_app_icon (app->info); g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, app->id, app_icon, action_name, serialized_icon, title, subtitle, body, actions, time, draws_attention); g_free (action_name); g_variant_iter_free (action_iter); g_object_unref (action); if (serialized_icon) g_variant_unref (serialized_icon); g_variant_unref (maybe_serialized_icon); g_object_unref (app_icon); } static void im_application_list_messages_listed (GObject *source_object, GAsyncResult *result, gpointer user_data) { Application *app = user_data; GVariant *messages; GError *error = NULL; if (indicator_messages_application_call_list_messages_finish (app->proxy, &messages, result, &error)) { GVariantIter iter; GVariant *message; g_variant_iter_init (&iter, messages); while ((message = g_variant_iter_next_value (&iter))) { im_application_list_message_added (app, message); g_variant_unref (message); } g_variant_unref (messages); } else { g_warning ("could not fetch the list of messages: %s", error->message); g_error_free (error); } } static void im_application_list_unset_remote (Application *app) { gboolean was_running; was_running = app->proxy || app->cancellable; if (app->cancellable) { g_cancellable_cancel (app->cancellable); g_clear_object (&app->cancellable); } g_clear_object (&app->proxy); /* clear actions by creating a new action group and overriding it in * the muxer */ g_object_unref (app->source_actions); g_object_unref (app->message_actions); g_object_unref (app->message_sub_actions); app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); app->message_sub_actions = g_action_muxer_new (); g_action_muxer_insert (app->muxer, "src", G_ACTION_GROUP (app->source_actions)); g_action_muxer_insert (app->muxer, "msg", G_ACTION_GROUP (app->message_actions)); g_action_muxer_insert (app->muxer, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); app->draws_attention = FALSE; im_application_list_update_root_action (app->list); g_action_group_change_action_state (G_ACTION_GROUP (app->muxer), "launch", g_variant_new_boolean (FALSE)); if (was_running) g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); } static void im_application_list_app_vanished (GDBusConnection *connection, const gchar *name, gpointer user_data) { Application *app = user_data; im_application_list_unset_remote (app); } static void im_application_list_proxy_created (GObject *source_object, GAsyncResult *result, gpointer user_data) { Application *app = user_data; GError *error = NULL; app->proxy = indicator_messages_application_proxy_new_finish (result, &error); if (!app->proxy) { if (error->code != G_IO_ERROR_CANCELLED) g_warning ("could not create application proxy: %s", error->message); g_error_free (error); return; } indicator_messages_application_call_list_sources (app->proxy, app->cancellable, im_application_list_sources_listed, app); indicator_messages_application_call_list_messages (app->proxy, app->cancellable, im_application_list_messages_listed, app); g_signal_connect_swapped (app->proxy, "source-added", G_CALLBACK (im_application_list_source_added), app); g_signal_connect_swapped (app->proxy, "source-changed", G_CALLBACK (im_application_list_source_changed), app); g_signal_connect_swapped (app->proxy, "source-removed", G_CALLBACK (im_application_list_source_removed), app); g_signal_connect_swapped (app->proxy, "message-added", G_CALLBACK (im_application_list_message_added), app); g_signal_connect_swapped (app->proxy, "message-removed", G_CALLBACK (im_application_list_message_removed), app); g_action_group_change_action_state (G_ACTION_GROUP (app->muxer), "launch", g_variant_new_boolean (TRUE)); g_bus_watch_name_on_connection (g_dbus_proxy_get_connection (G_DBUS_PROXY (app->proxy)), g_dbus_proxy_get_name (G_DBUS_PROXY (app->proxy)), G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, im_application_list_app_vanished, app, NULL); } void im_application_list_set_remote (ImApplicationList *list, const gchar *id, GDBusConnection *connection, const gchar *unique_bus_name, const gchar *object_path) { Application *app; g_return_if_fail (IM_IS_APPLICATION_LIST (list)); app = im_application_list_lookup (list, id); if (!app) { g_warning ("'%s' is not a registered application", id); return; } if (!connection && !unique_bus_name && !object_path) { im_application_list_unset_remote (app); return; } if (app->cancellable) { gchar *name_owner = NULL; if (app->proxy) name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (app->proxy)); if (g_strcmp0 (name_owner, unique_bus_name) != 0) { g_warning ("replacing '%s' at %s with %s", id, name_owner, unique_bus_name); im_application_list_unset_remote (app); } g_free (name_owner); } app->cancellable = g_cancellable_new (); indicator_messages_application_proxy_new (connection, G_DBUS_PROXY_FLAGS_NONE, unique_bus_name, object_path, app->cancellable, im_application_list_proxy_created, app); } GActionGroup * im_application_list_get_action_group (ImApplicationList *list) { g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), NULL); return G_ACTION_GROUP (list->muxer); } GList * im_application_list_get_applications (ImApplicationList *list) { g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), NULL); return g_hash_table_get_keys (list->applications); } GDesktopAppInfo * im_application_list_get_application (ImApplicationList *list, const gchar *id) { Application *app; g_return_val_if_fail (IM_IS_APPLICATION_LIST (list), NULL); app = g_hash_table_lookup (list->applications, id); return app ? app->info : NULL; } static void status_activated (GSimpleAction * action, GVariant * param, gpointer user_data) { g_return_if_fail (IM_IS_APPLICATION_LIST(user_data)); ImApplicationList * list = IM_APPLICATION_LIST(user_data); const gchar * status = g_variant_get_string(param, NULL); g_simple_action_set_state(action, param); GList * appshash = g_hash_table_get_keys(list->app_status); GList * appsfree = g_list_copy_deep(appshash, (GCopyFunc)g_strdup, NULL); GList * app; for (app = appsfree; app != NULL; app = g_list_next(app)) { g_hash_table_insert(list->app_status, app->data, g_strdup(status)); } g_list_free(appshash); g_list_free(appsfree); g_signal_emit (list, signals[STATUS_SET], 0, status); im_application_list_update_root_action(list); return; } #define STATUS_ID_OFFLINE (G_N_ELEMENTS(status_ids) - 1) static const gchar *status_ids[] = { "available", "away", "busy", "invisible", "offline" }; static guint status2val (const gchar * string) { if (string == NULL) return STATUS_ID_OFFLINE; guint i; for (i = 0; i < G_N_ELEMENTS(status_ids); i++) { if (g_strcmp0(status_ids[i], string) == 0) { break; } } if (i > STATUS_ID_OFFLINE) i = STATUS_ID_OFFLINE; return i; } void im_application_list_set_status (ImApplicationList * list, const gchar * id, const gchar *status) { g_return_if_fail (IM_IS_APPLICATION_LIST (list)); g_hash_table_insert(list->app_status, im_application_list_canonical_id(id), g_strdup(status)); guint final_status = STATUS_ID_OFFLINE; GList * statuses = g_hash_table_get_values(list->app_status); GList * statusentry; for (statusentry = statuses; statusentry != NULL; statusentry = g_list_next(statusentry)) { guint statusval = status2val((gchar *)statusentry->data); final_status = MIN(final_status, statusval); } g_list_free(statuses); g_simple_action_set_state(list->statusaction, g_variant_new_string(status_ids[final_status])); im_application_list_update_root_action(list); return; } ./src/gactionmuxer.c0000644000004100000410000004023113350212604014677 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel * Ryan Lortie */ #include "gactionmuxer.h" #include /* * SECTION:gactionmuxer * @short_description: Aggregate several action groups * * #GActionMuxer is a #GActionGroup that is capable of containing other * #GActionGroup instances. * * The typical use is aggregating all of the actions applicable to a * particular context into a single action group, with namespacing. * * Consider the case of two action groups -- one containing actions * applicable to an entire application (such as 'quit') and one * containing actions applicable to a particular window in the * application (such as 'fullscreen'). * * In this case, each of these action groups could be added to a * #GActionMuxer with the prefixes "app" and "win", respectively. This * would expose the actions as "app.quit" and "win.fullscreen" on the * #GActionGroup interface presented by the #GActionMuxer. * * Activations and state change requests on the #GActionMuxer are wired * through to the underlying action group in the expected way. */ typedef GObjectClass GActionMuxerClass; struct _GActionMuxer { GObject parent; GActionGroup *global_actions; GHashTable *groups; /* prefix -> subgroup */ GHashTable *reverse; /* subgroup -> prefix */ }; static void g_action_muxer_group_init (GActionGroupInterface *iface); static void g_action_muxer_dispose (GObject *object); static void g_action_muxer_finalize (GObject *object); static void g_action_muxer_disconnect_group (GActionMuxer *muxer, GActionGroup *subgroup); static gchar ** g_action_muxer_list_actions (GActionGroup *group); static void g_action_muxer_activate_action (GActionGroup *group, const gchar *action_name, GVariant *parameter); static void g_action_muxer_change_action_state (GActionGroup *group, const gchar *action_name, GVariant *value); static gboolean g_action_muxer_query_action (GActionGroup *group, const gchar *action_name, gboolean *enabled, const GVariantType **parameter_type, const GVariantType **state_type, GVariant **state_hint, GVariant **state); static void g_action_muxer_action_added (GActionGroup *group, gchar *action_name, gpointer user_data); static void g_action_muxer_action_removed (GActionGroup *group, gchar *action_name, gpointer user_data); static void g_action_muxer_action_state_changed (GActionGroup *group, gchar *action_name, GVariant *value, gpointer user_data); static void g_action_muxer_action_enabled_changed (GActionGroup *group, gchar *action_name, gboolean enabled, gpointer user_data); G_DEFINE_TYPE_WITH_CODE (GActionMuxer, g_action_muxer, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, g_action_muxer_group_init)); static void g_action_muxer_class_init (GObjectClass *klass) { klass->dispose = g_action_muxer_dispose; klass->finalize = g_action_muxer_finalize; } static void g_action_muxer_init (GActionMuxer *muxer) { muxer->global_actions = NULL; muxer->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); muxer->reverse = g_hash_table_new (g_direct_hash, g_direct_equal); } static void g_action_muxer_group_init (GActionGroupInterface *iface) { iface->list_actions = g_action_muxer_list_actions; iface->activate_action = g_action_muxer_activate_action; iface->change_action_state = g_action_muxer_change_action_state; iface->query_action = g_action_muxer_query_action; } static void g_action_muxer_dispose (GObject *object) { GActionMuxer *muxer = G_ACTION_MUXER (object); GHashTableIter it; GActionGroup *subgroup; if (muxer->global_actions) { g_action_muxer_disconnect_group (muxer, muxer->global_actions); g_clear_object (&muxer->global_actions); } g_hash_table_iter_init (&it, muxer->groups); while (g_hash_table_iter_next (&it, NULL, (gpointer *) &subgroup)) g_action_muxer_disconnect_group (muxer, subgroup); g_hash_table_remove_all (muxer->groups); g_hash_table_remove_all (muxer->reverse); } static void g_action_muxer_finalize (GObject *object) { GActionMuxer *muxer = G_ACTION_MUXER (object); g_hash_table_unref (muxer->groups); g_hash_table_unref (muxer->reverse); G_OBJECT_CLASS (g_action_muxer_parent_class)->finalize (object); } static GActionGroup * g_action_muxer_lookup_group (GActionMuxer *muxer, const gchar *full_name, const gchar **action_name) { const gchar *sep; GActionGroup *group; sep = strchr (full_name, '.'); if (sep) { gchar *prefix; prefix = g_strndup (full_name, sep - full_name); group = g_hash_table_lookup (muxer->groups, prefix); g_free (prefix); if (action_name) *action_name = sep + 1; } else { group = muxer->global_actions; if (action_name) *action_name = full_name; } return group; } static gchar * g_action_muxer_lookup_full_name (GActionMuxer *muxer, GActionGroup *subgroup, const gchar *action_name) { gpointer prefix; if (subgroup == muxer->global_actions) return g_strdup (action_name); if (g_hash_table_lookup_extended (muxer->reverse, subgroup, NULL, &prefix)) return g_strdup_printf ("%s.%s", (gchar *) prefix, action_name); return NULL; } static void g_action_muxer_disconnect_group (GActionMuxer *muxer, GActionGroup *subgroup) { gchar **actions; gchar **action; actions = g_action_group_list_actions (subgroup); for (action = actions; *action; action++) g_action_muxer_action_removed (subgroup, *action, muxer); g_strfreev (actions); g_signal_handlers_disconnect_by_func (subgroup, g_action_muxer_action_added, muxer); g_signal_handlers_disconnect_by_func (subgroup, g_action_muxer_action_removed, muxer); g_signal_handlers_disconnect_by_func (subgroup, g_action_muxer_action_enabled_changed, muxer); g_signal_handlers_disconnect_by_func (subgroup, g_action_muxer_action_state_changed, muxer); } static gchar ** g_action_muxer_list_actions (GActionGroup *group) { GActionMuxer *muxer = G_ACTION_MUXER (group); GHashTableIter it; GArray *all_actions; gchar *prefix; GActionGroup *subgroup; gchar **actions; gchar **a; all_actions = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), 8); if (muxer->global_actions) { actions = g_action_group_list_actions (muxer->global_actions); for (a = actions; *a; a++) { gchar *name = g_strdup (*a); g_array_append_val (all_actions, name); } g_strfreev (actions); } g_hash_table_iter_init (&it, muxer->groups); while (g_hash_table_iter_next (&it, (gpointer *) &prefix, (gpointer *) &subgroup)) { actions = g_action_group_list_actions (subgroup); for (a = actions; *a; a++) { gchar *full_name = g_strdup_printf ("%s.%s", prefix, *a); g_array_append_val (all_actions, full_name); } g_strfreev (actions); } return (gchar **) g_array_free (all_actions, FALSE); } static void g_action_muxer_activate_action (GActionGroup *group, const gchar *action_name, GVariant *parameter) { GActionMuxer *muxer = G_ACTION_MUXER (group); GActionGroup *subgroup; const gchar *action; g_return_if_fail (action_name != NULL); subgroup = g_action_muxer_lookup_group (muxer, action_name, &action); if (subgroup) g_action_group_activate_action (subgroup, action, parameter); } static void g_action_muxer_change_action_state (GActionGroup *group, const gchar *action_name, GVariant *value) { GActionMuxer *muxer = G_ACTION_MUXER (group); GActionGroup *subgroup; const gchar *action; g_return_if_fail (action_name != NULL); subgroup = g_action_muxer_lookup_group (muxer, action_name, &action); if (subgroup) g_action_group_change_action_state (subgroup, action, value); } static gboolean g_action_muxer_query_action (GActionGroup *group, const gchar *action_name, gboolean *enabled, const GVariantType **parameter_type, const GVariantType **state_type, GVariant **state_hint, GVariant **state) { GActionMuxer *muxer = G_ACTION_MUXER (group); GActionGroup *subgroup; const gchar *action; g_return_val_if_fail (action_name != NULL, FALSE); subgroup = g_action_muxer_lookup_group (muxer, action_name, &action); if (!subgroup) return FALSE; return g_action_group_query_action (subgroup, action, enabled, parameter_type, state_type, state_hint, state); } static void g_action_muxer_action_added (GActionGroup *group, gchar *action_name, gpointer user_data) { GActionMuxer *muxer = user_data; gchar *full_name; full_name = g_action_muxer_lookup_full_name (muxer, group, action_name); if (full_name) { g_action_group_action_added (G_ACTION_GROUP (muxer), full_name); g_free (full_name); } } static void g_action_muxer_action_removed (GActionGroup *group, gchar *action_name, gpointer user_data) { GActionMuxer *muxer = user_data; gchar *full_name; full_name = g_action_muxer_lookup_full_name (muxer, group, action_name); if (full_name) { g_action_group_action_removed (G_ACTION_GROUP (muxer), full_name); g_free (full_name); } } static void g_action_muxer_action_state_changed (GActionGroup *group, gchar *action_name, GVariant *value, gpointer user_data) { GActionMuxer *muxer = user_data; gchar *full_name; full_name = g_action_muxer_lookup_full_name (muxer, group, action_name); if (full_name) { g_action_group_action_state_changed (G_ACTION_GROUP (muxer), full_name, value); g_free (full_name); } } static void g_action_muxer_action_enabled_changed (GActionGroup *group, gchar *action_name, gboolean enabled, gpointer user_data) { GActionMuxer *muxer = user_data; gchar *full_name; full_name = g_action_muxer_lookup_full_name (muxer, group, action_name); if (full_name) { g_action_group_action_enabled_changed (G_ACTION_GROUP (muxer), full_name, enabled); g_free (full_name); } } /* * g_action_muxer_new: * * Creates a new #GActionMuxer. */ GActionMuxer * g_action_muxer_new (void) { return g_object_new (G_TYPE_ACTION_MUXER, NULL); } /* * g_action_muxer_insert: * @muxer: a #GActionMuxer * @prefix: (allow-none): the prefix string for the action group, or NULL * @group: (allow-none): a #GActionGroup, or NULL * * Adds the actions in @group to the list of actions provided by @muxer. * @prefix is prefixed to each action name, such that for each action * x in @group, there is an equivalent action * @prefix.x in @muxer. * * For example, if @prefix is "app" and @group contains an * action called "quit", then @muxer will now contain an * action called "app.quit". * * If @prefix is NULL, the actions in @group will be added * to @muxer without prefix. * * If @group is NULL, this function has the same effect as * calling g_action_muxer_remove() with @prefix. * * There may only be one group per prefix (including the * NULL-prefix). If a group has been added with @prefix in * a previous call to this function, it will be removed. * * @prefix must not contain a dot ('.'). */ void g_action_muxer_insert (GActionMuxer *muxer, const gchar *prefix, GActionGroup *group) { gchar *prefix_copy; gchar **actions; gchar **action; g_return_if_fail (G_IS_ACTION_MUXER (muxer)); g_return_if_fail (group == NULL || G_IS_ACTION_GROUP (group)); g_action_muxer_remove (muxer, prefix); if (group == NULL) return; if (prefix) { prefix_copy = g_strdup (prefix); g_hash_table_insert (muxer->groups, prefix_copy, g_object_ref (group)); g_hash_table_insert (muxer->reverse, group, prefix_copy); } else muxer->global_actions = g_object_ref (group); actions = g_action_group_list_actions (group); for (action = actions; *action; action++) g_action_muxer_action_added (group, *action, muxer); g_strfreev (actions); g_signal_connect (group, "action-added", G_CALLBACK (g_action_muxer_action_added), muxer); g_signal_connect (group, "action-removed", G_CALLBACK (g_action_muxer_action_removed), muxer); g_signal_connect (group, "action-enabled-changed", G_CALLBACK (g_action_muxer_action_enabled_changed), muxer); g_signal_connect (group, "action-state-changed", G_CALLBACK (g_action_muxer_action_state_changed), muxer); } /* * g_action_muxer_remove: * @muxer: a #GActionMuxer * @prefix: (allow-none): the prefix of the action group to remove, or NULL * * Removes a #GActionGroup from the #GActionMuxer. */ void g_action_muxer_remove (GActionMuxer *muxer, const gchar *prefix) { GActionGroup *subgroup; g_return_if_fail (G_IS_ACTION_MUXER (muxer)); subgroup = prefix ? g_hash_table_lookup (muxer->groups, prefix) : muxer->global_actions; if (!subgroup) return; g_action_muxer_disconnect_group (muxer, subgroup); if (prefix) { g_hash_table_remove (muxer->groups, prefix); g_hash_table_remove (muxer->reverse, subgroup); } else g_clear_object (&muxer->global_actions); } GActionGroup * g_action_muxer_get_group (GActionMuxer *muxer, const gchar *prefix) { g_return_val_if_fail (G_IS_ACTION_MUXER (muxer), NULL); return prefix ? g_hash_table_lookup (muxer->groups, prefix) : muxer->global_actions; } ./src/indicator-desktop-shortcuts.c0000644000004100000410000005136713350212604017665 0ustar www-datawww-data/* 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 #include #include "indicator-desktop-shortcuts.h" #define ACTIONS_KEY "Actions" #define ACTION_GROUP_PREFIX "Desktop Action" #define OLD_GROUP_SUFFIX "Shortcut Group" #define OLD_SHORTCUTS_KEY "X-Ayatana-Desktop-Shortcuts" #define OLD_ENVIRON_KEY "TargetEnvironment" #define PROP_DESKTOP_FILE_S "desktop-file" #define PROP_IDENTITY_S "identity" typedef enum _actions_t actions_t; enum _actions_t { ACTIONS_NONE, ACTIONS_XAYATANA, ACTIONS_DESKTOP_SPEC }; typedef struct _IndicatorDesktopShortcutsPrivate IndicatorDesktopShortcutsPrivate; struct _IndicatorDesktopShortcutsPrivate { actions_t actions; GKeyFile * keyfile; gchar * identity; GArray * nicks; gchar * domain; }; 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)) 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); 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, gboolean should_have_target); G_DEFINE_TYPE (IndicatorDesktopShortcuts, indicator_desktop_shortcuts, G_TYPE_OBJECT); /* Build up the class */ 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; /* 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_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.", "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; } /* Initialize instance data */ static void indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self) { IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(self); priv->keyfile = NULL; priv->identity = NULL; priv->domain = NULL; priv->nicks = g_array_new(TRUE, TRUE, sizeof(gchar *)); priv->actions = ACTIONS_NONE; return; } /* Clear object references */ 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; } /* Free all memory */ 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->domain != NULL) { g_free(priv->domain); priv->domain = 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; } /* 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: { if (priv->keyfile != NULL) { g_key_file_free(priv->keyfile); priv->keyfile = NULL; priv->actions = ACTIONS_NONE; } 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); break; } /* Always prefer the desktop spec if we can get it */ if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, ACTIONS_KEY, NULL)) { priv->actions = ACTIONS_DESKTOP_SPEC; } /* But fallback if we can't */ if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) { priv->actions = ACTIONS_XAYATANA; g_warning("Desktop file '%s' is using a deprecated format for its actions that will be dropped soon.", g_value_get_string(value)); } if (priv->actions == ACTIONS_NONE) { g_key_file_free(keyfile); break; } 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: 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_IDENTITY: g_value_set_string(value, priv->identity); break; /* *********************** */ default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } 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) { IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); if (priv->keyfile == NULL) { return; } if (priv->identity == NULL) { return; } /* Remove a previous translation domain if we had one from a previously parsed file. */ if (priv->domain != NULL) { g_free(priv->domain); priv->domain = NULL; } /* Check to see if there is a custom translation domain that we should take into account. */ if (priv->domain == NULL && g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-GNOME-Gettext-Domain", NULL)) { priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-GNOME-Gettext-Domain", NULL); } if (priv->domain == NULL && g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL)) { priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL); } /* We need to figure out what we're looking for and what we want to look for in the rest of the file */ const gchar * list_name = NULL; const gchar * group_format = NULL; gboolean should_have_target = FALSE; switch (priv->actions) { case ACTIONS_NONE: /* None, let's just get outta here */ return; case ACTIONS_XAYATANA: list_name = OLD_SHORTCUTS_KEY; group_format = "%s " OLD_GROUP_SUFFIX; should_have_target = TRUE; break; case ACTIONS_DESKTOP_SPEC: list_name = ACTIONS_KEY; group_format = ACTION_GROUP_PREFIX " %s"; should_have_target = FALSE; break; default: g_assert_not_reached(); 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, list_name, &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++) { /* g_debug("Looking at group nick %s", nicks[i]); */ gchar * groupname = g_strdup_printf(group_format, nicks[i]); if (!g_key_file_has_group(priv->keyfile, groupname)) { g_warning("Unable to find group '%s'", groupname); g_free(groupname); continue; } if (!should_show(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, priv->identity, FALSE)) { g_free(groupname); continue; } if (!should_show(priv->keyfile, groupname, priv->identity, should_have_target)) { g_free(groupname); continue; } gchar * nickalloc = g_strdup(nicks[i]); g_array_append_val(priv->nicks, nickalloc); g_free(groupname); } 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, gboolean should_have_target) { if (should_have_target && g_key_file_has_key(keyfile, group, OLD_ENVIRON_KEY, NULL)) { /* If we've got this key, we're going to return here and not process the deprecated keys. */ gint j; gsize num_env = 0; gchar ** envs = g_key_file_get_string_list(keyfile, group, OLD_ENVIRON_KEY, &num_env, NULL); for (j = 0; j < num_env; j++) { if (g_strcmp0(envs[j], identity) == 0) { break; } } if (envs != NULL) { g_strfreev(envs); } if (j == num_env) { return FALSE; } return TRUE; } /* 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 (onlies != NULL) { g_strfreev(onlies); } if (j == num_only) { return FALSE; } } /* 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; } } if (nots != NULL) { g_strfreev(nots); } if (j != num_not) { return FALSE; } } return TRUE; } /* Looks through the nicks to 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; /* g_debug("Checking Nick: %s", list[0]); */ if (g_strcmp0(list[0], nick) == 0) return TRUE; return is_valid_nick(&list[1], nick); } /* 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) { GObject * obj = g_object_new(INDICATOR_TYPE_DESKTOP_SHORTCUTS, PROP_DESKTOP_FILE_S, file, PROP_IDENTITY_S, identity, NULL); return INDICATOR_DESKTOP_SHORTCUTS(obj); } /** 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) { 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; } /** 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. */ 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->actions != ACTIONS_NONE, NULL); g_return_val_if_fail(priv->keyfile != NULL, NULL); g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL); const gchar * group_format = NULL; switch (priv->actions) { case ACTIONS_XAYATANA: group_format = "%s " OLD_GROUP_SUFFIX; break; case ACTIONS_DESKTOP_SPEC: group_format = ACTION_GROUP_PREFIX " %s"; break; default: g_assert_not_reached(); return NULL; } gchar * groupheader = g_strdup_printf(group_format, 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 = NULL; gchar * keyvalue = g_key_file_get_string(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_NAME, NULL); gchar * localeval = g_key_file_get_locale_string(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL); g_free(groupheader); if (priv->domain != NULL && g_strcmp0(keyvalue, localeval) == 0) { name = g_strdup(g_dgettext(priv->domain, keyvalue)); g_free(localeval); } else { name = localeval; } g_free(keyvalue); return name; } /** indicator_desktop_shortcuts_nick_exec_with_context: @ids: The #IndicatorDesktopShortcuts object to look in @nick: Which command that we're referencing. @launch_context: The #GAppLaunchContext to use for launching the shortcut 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_with_context (IndicatorDesktopShortcuts * ids, const gchar * nick, GAppLaunchContext * launch_context) { GError * error = NULL; 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->actions != ACTIONS_NONE, FALSE); g_return_val_if_fail(priv->keyfile != NULL, FALSE); g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE); const gchar * group_format = NULL; switch (priv->actions) { case ACTIONS_XAYATANA: group_format = "%s " OLD_GROUP_SUFFIX; break; case ACTIONS_DESKTOP_SPEC: group_format = ACTION_GROUP_PREFIX " %s"; break; default: g_assert_not_reached(); return FALSE; } gchar * groupheader = g_strdup_printf(group_format, 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); g_free(groupheader); GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE; if (launch_context) { flags |= G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION; } GAppInfo * appinfo = g_app_info_create_from_commandline(exec, name, flags, &error); g_free(name); g_free(exec); if (error != NULL) { g_warning("Unable to build Command line App info: %s", error->message); g_error_free(error); return FALSE; } if (appinfo == NULL) { g_warning("Unable to build Command line App info (unknown)"); return FALSE; } gboolean launched = g_app_info_launch(appinfo, NULL, launch_context, &error); if (error != NULL) { g_warning("Unable to launch file from nick '%s': %s", nick, error->message); g_clear_error(&error); } g_object_unref(appinfo); return launched; } /** 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. This function is deprecated and shouldn't be used in newly written code. Return value: #TRUE on success or #FALSE on error. */ gboolean indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gchar * nick) { return indicator_desktop_shortcuts_nick_exec_with_context (ids, nick, NULL); } ./src/im-accounts-service.c0000644000004100000410000001566713350212604016071 0ustar www-datawww-data/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "im-accounts-service.h" typedef struct _ImAccountsServicePrivate ImAccountsServicePrivate; struct _ImAccountsServicePrivate { ActUserManager * user_manager; GDBusProxy * touch_settings; GCancellable * cancel; }; #define IM_ACCOUNTS_SERVICE_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), IM_ACCOUNTS_SERVICE_TYPE, ImAccountsServicePrivate)) static void im_accounts_service_class_init (ImAccountsServiceClass *klass); static void im_accounts_service_init (ImAccountsService *self); static void im_accounts_service_dispose (GObject *object); static void im_accounts_service_finalize (GObject *object); static void user_changed (ActUserManager * manager, ActUser * user, gpointer user_data); static void on_user_manager_loaded (ActUserManager * manager, GParamSpec * pspect, gpointer user_data); static void security_privacy_ready (GObject * obj, GAsyncResult * res, gpointer user_data); G_DEFINE_TYPE (ImAccountsService, im_accounts_service, G_TYPE_OBJECT); static void im_accounts_service_class_init (ImAccountsServiceClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (ImAccountsServicePrivate)); object_class->dispose = im_accounts_service_dispose; object_class->finalize = im_accounts_service_finalize; } static void im_accounts_service_init (ImAccountsService *self) { ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(self); priv->cancel = g_cancellable_new(); priv->user_manager = act_user_manager_get_default(); g_signal_connect(priv->user_manager, "user-changed", G_CALLBACK(user_changed), self); g_signal_connect(priv->user_manager, "notify::is-loaded", G_CALLBACK(on_user_manager_loaded), self); gboolean isLoaded = FALSE; g_object_get(G_OBJECT(priv->user_manager), "is-loaded", &isLoaded, NULL); if (isLoaded) { on_user_manager_loaded(priv->user_manager, NULL, NULL); } } static void im_accounts_service_dispose (GObject *object) { ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(object); if (priv->cancel != NULL) { g_cancellable_cancel(priv->cancel); g_clear_object(&priv->cancel); } g_clear_object(&priv->user_manager); G_OBJECT_CLASS (im_accounts_service_parent_class)->dispose (object); } static void im_accounts_service_finalize (GObject *object) { G_OBJECT_CLASS (im_accounts_service_parent_class)->finalize (object); } /* Handles a User getting updated */ static void user_changed (ActUserManager * manager, ActUser * user, gpointer user_data) { if (g_strcmp0(act_user_get_user_name(user), g_get_user_name()) != 0) { return; } ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(user_data); g_debug("User Updated"); /* Clear old proxies */ g_clear_object(&priv->touch_settings); /* Start getting a new proxy */ g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.Accounts", act_user_get_object_path(user), "com.ubuntu.touch.AccountsService.SecurityPrivacy", priv->cancel, security_privacy_ready, user_data); } /* Respond to the async of setting up the proxy. Mostly we get it or we error. */ static void security_privacy_ready (GObject * obj, GAsyncResult * res, gpointer user_data) { GError * error = NULL; GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); if (error != NULL) { g_warning("Unable to get a proxy on accounts service for touch settings: %s", error->message); g_error_free(error); return; } ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(user_data); /* Ensure we didn't get a proxy while we weren't looking */ g_clear_object(&priv->touch_settings); priv->touch_settings = proxy; } /* When the user manager is loaded see if we have a user already loaded along with. */ static void on_user_manager_loaded (ActUserManager * manager, GParamSpec * pspect, gpointer user_data) { ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(user_data); ActUser * user = NULL; g_debug("Accounts Manager Loaded"); user = act_user_manager_get_user(priv->user_manager, g_get_user_name()); if (user != NULL) { user_changed(priv->user_manager, user, user_data); g_object_unref(user); } } /* Not the most testable way to do this but, it is a less invasive one, and we'll probably restructure this codebase soonish */ /* Gets an account service wrapper reference, so then it can be free'd */ ImAccountsService * im_accounts_service_ref_default (void) { static ImAccountsService * as = NULL; if (as == NULL) { as = IM_ACCOUNTS_SERVICE(g_object_new(IM_ACCOUNTS_SERVICE_TYPE, NULL)); g_object_add_weak_pointer(G_OBJECT(as), (gpointer *)&as); return as; } return g_object_ref(as); } /* The draws attention setting is very legacy right now, we've patched and not changed things much. We're gonna do better in the future, this function abstracts out the ugly */ void im_accounts_service_set_draws_attention (ImAccountsService * service, gboolean draws_attention) { g_return_if_fail(IM_IS_ACCOUNTS_SERVICE(service)); ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(service); if (priv->touch_settings == NULL) { return; } g_dbus_connection_call(g_dbus_proxy_get_connection(priv->touch_settings), g_dbus_proxy_get_name(priv->touch_settings), g_dbus_proxy_get_object_path(priv->touch_settings), "org.freedesktop.DBus.Properties", "Set", g_variant_new("(ssv)", "org.freedesktop.DisplayManager.AccountsService", "HasMessages", g_variant_new_boolean (draws_attention)), NULL, /* reply */ G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */ priv->cancel, /* cancellable */ NULL, NULL); /* cb */ } /* Looks at the property that is set by settings. We default to off in any case that we can or we don't know what the state is. */ gboolean im_accounts_service_get_show_on_greeter (ImAccountsService * service) { g_return_val_if_fail(IM_IS_ACCOUNTS_SERVICE(service), FALSE); ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(service); if (priv->touch_settings == NULL) { return FALSE; } GVariant * val = g_dbus_proxy_get_cached_property(priv->touch_settings, "MessagesWelcomeScreen"); if (val == NULL) { return FALSE; } gboolean retval = g_variant_get_boolean(val); g_variant_unref(val); return retval; } ./src/im-phone-menu.h0000644000004100000410000000717613350212604014670 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #ifndef __IM_PHONE_MENU_H__ #define __IM_PHONE_MENU_H__ #include "im-menu.h" #define IM_TYPE_PHONE_MENU (im_phone_menu_get_type ()) #define IM_PHONE_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_PHONE_MENU, ImPhoneMenu)) #define IM_PHONE_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_PHONE_MENU, ImPhoneMenuClass)) #define IM_IS_PHONE_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_PHONE_MENU)) #define IM_IS_PHONE_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_PHONE_MENU)) #define IM_PHONE_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_PHONE_MENU, ImPhoneMenuClass)) typedef struct _ImPhoneMenu ImPhoneMenu; GType im_phone_menu_get_type (void); ImPhoneMenu * im_phone_menu_new (ImApplicationList *applist, gboolean greeter); void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, GIcon *app_icon, const gchar *id, GVariant *serialized_icon, const gchar *title, const gchar *subtitle, const gchar *body, GVariant *actions, gint64 time); void im_phone_menu_remove_message (ImPhoneMenu *menu, const gchar *app_id, const gchar *id); void im_phone_menu_add_source (ImPhoneMenu *menu, const gchar *app_id, const gchar *id, const gchar *label, const gchar *iconstr); void im_phone_menu_remove_source (ImPhoneMenu *menu, const gchar *app_id, const gchar *id); void im_phone_menu_remove_application (ImPhoneMenu *menu, const gchar *app_id); void im_phone_menu_remove_all (ImPhoneMenu *menu); #endif ./src/indicator-desktop-shortcuts.h0000644000004100000410000000674613350212604017673 0ustar www-datawww-data/* 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__ #include #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 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; 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); IndicatorDesktopShortcuts * indicator_desktop_shortcuts_new (const gchar * file, const gchar * identity); const gchar ** indicator_desktop_shortcuts_get_nicks (IndicatorDesktopShortcuts * ids); gchar * indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, const gchar * nick); gboolean indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * ids, const gchar * nick, GAppLaunchContext * launch_context); GLIB_DEPRECATED_FOR(indicator_desktop_shortcuts_nick_exec_with_context) gboolean indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gchar * nick); G_END_DECLS #endif ./src/gsettingsstrv.c0000644000004100000410000000547613350212604015134 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #include "gsettingsstrv.h" /** * g_settings_strv_append_unique: * @settings: a #GSettings object * @key: the key at which @settings contains a string array * @item: the string to append * * Appends @item to the string array at @key if that string array doesn't * contain @item yet. * * Returns: TRUE if @item was added to the list, FALSE if it already existed. */ gboolean g_settings_strv_append_unique (GSettings *settings, const gchar *key, const gchar *item) { gchar **strv; gchar **it; gboolean add = TRUE; g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE); g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (item != NULL, FALSE); strv = g_settings_get_strv (settings, key); for (it = strv; *it; it++) { if (g_str_equal (*it, item)) { add = FALSE; break; } } if (add) { GVariantBuilder builder; g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); for (it = strv; *it; it++) g_variant_builder_add (&builder, "s", *it); g_variant_builder_add (&builder, "s", item); g_settings_set_value (settings, key, g_variant_builder_end (&builder)); } g_strfreev (strv); return add; } /** * g_settings_strv_remove: * @settings: a #GSettings object * @key: the key at which @settings contains a string array * @item: the string to remove * * Removes all occurences of @item in @key. */ void g_settings_strv_remove (GSettings *settings, const gchar *key, const gchar *item) { gchar **strv; gchar **it; GVariantBuilder builder; g_return_if_fail (G_IS_SETTINGS (settings)); g_return_if_fail (key != NULL); g_return_if_fail (item != NULL); strv = g_settings_get_strv (settings, key); g_variant_builder_init (&builder, (GVariantType *)"as"); for (it = strv; *it; it++) { if (!g_str_equal (*it, item)) g_variant_builder_add (&builder, "s", *it); } g_settings_set_value (settings, key, g_variant_builder_end (&builder)); g_strfreev (strv); } ./src/im-accounts-service.h0000644000004100000410000000400613350212604016057 0ustar www-datawww-data/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #ifndef __IM_ACCOUNTS_SERVICE_H__ #define __IM_ACCOUNTS_SERVICE_H__ #include #include G_BEGIN_DECLS #define IM_ACCOUNTS_SERVICE_TYPE (im_accounts_service_get_type ()) #define IM_ACCOUNTS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_ACCOUNTS_SERVICE_TYPE, ImAccountsService)) #define IM_ACCOUNTS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_ACCOUNTS_SERVICE_TYPE, ImAccountsServiceClass)) #define IM_IS_ACCOUNTS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_ACCOUNTS_SERVICE_TYPE)) #define IM_IS_ACCOUNTS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_ACCOUNTS_SERVICE_TYPE)) #define IM_ACCOUNTS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_ACCOUNTS_SERVICE_TYPE, ImAccountsServiceClass)) typedef struct _ImAccountsService ImAccountsService; typedef struct _ImAccountsServiceClass ImAccountsServiceClass; struct _ImAccountsServiceClass { GObjectClass parent_class; }; struct _ImAccountsService { GObject parent; }; GType im_accounts_service_get_type (void); ImAccountsService * im_accounts_service_ref_default (void); void im_accounts_service_set_draws_attention (ImAccountsService * service, gboolean draws_attention); gboolean im_accounts_service_get_show_on_greeter (ImAccountsService * service); G_END_DECLS #endif ./src/im-phone-menu.c0000644000004100000410000002434313350212604014656 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #include "im-phone-menu.h" #include #include typedef ImMenuClass ImPhoneMenuClass; struct _ImPhoneMenu { ImMenu parent; GMenu *message_section; GMenu *source_section; GMenu *clear_section; }; G_DEFINE_TYPE (ImPhoneMenu, im_phone_menu, IM_TYPE_MENU); typedef void (*ImMenuForeachFunc) (GMenuModel *menu, gint pos); static void im_phone_menu_foreach_item_with_action (GMenuModel *menu, const gchar *action, ImMenuForeachFunc func) { gint n_items; gint i; n_items = g_menu_model_get_n_items (menu); for (i = 0; i < n_items; i++) { gchar *item_action; g_menu_model_get_item_attribute (menu, i, G_MENU_ATTRIBUTE_ACTION, "s", &item_action); if (g_str_equal (action, item_action)) func (menu, i); g_free (item_action); } } static void im_phone_menu_update_clear_section (ImPhoneMenu *menu) { gboolean is_shown; gboolean should_be_shown; is_shown = g_menu_model_get_n_items (G_MENU_MODEL (menu->clear_section)) > 0; should_be_shown = (g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section)) + g_menu_model_get_n_items (G_MENU_MODEL (menu->source_section))) > 0; if (!is_shown && should_be_shown) { GMenuItem *item; item = g_menu_item_new (_("Clear All"), "remove-all"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button"); g_menu_append_item (menu->clear_section, item); g_object_unref (item); } else if (is_shown && !should_be_shown) { g_menu_remove (menu->clear_section, 0); } } static void im_phone_menu_constructed (GObject *object) { ImPhoneMenu *menu = IM_PHONE_MENU (object); ImApplicationList *applist; im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->message_section)); im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->source_section)); im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->clear_section)); applist = im_menu_get_application_list (IM_MENU (menu)); g_signal_connect_swapped (applist, "message-added", G_CALLBACK (im_phone_menu_add_message), menu); g_signal_connect_swapped (applist, "message-removed", G_CALLBACK (im_phone_menu_remove_message), menu); g_signal_connect_swapped (applist, "app-stopped", G_CALLBACK (im_phone_menu_remove_application), menu); g_signal_connect_swapped (applist, "remove-all", G_CALLBACK (im_phone_menu_remove_all), menu); G_OBJECT_CLASS (im_phone_menu_parent_class)->constructed (object); } static void im_phone_menu_dispose (GObject *object) { ImPhoneMenu *menu = IM_PHONE_MENU (object); g_clear_object (&menu->message_section); g_clear_object (&menu->source_section); g_clear_object (&menu->clear_section); G_OBJECT_CLASS (im_phone_menu_parent_class)->dispose (object); } static void im_phone_menu_finalize (GObject *object) { G_OBJECT_CLASS (im_phone_menu_parent_class)->finalize (object); } static void im_phone_menu_class_init (ImPhoneMenuClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructed = im_phone_menu_constructed; object_class->dispose = im_phone_menu_dispose; object_class->finalize = im_phone_menu_finalize; } static void im_phone_menu_init (ImPhoneMenu *menu) { menu->message_section = g_menu_new (); menu->source_section = g_menu_new (); menu->clear_section = g_menu_new (); } ImPhoneMenu * im_phone_menu_new (ImApplicationList *applist, gboolean greeter) { g_return_val_if_fail (IM_IS_APPLICATION_LIST (applist), NULL); return g_object_new (IM_TYPE_PHONE_MENU, "application-list", applist, "on-greeter", greeter, NULL); } static gint64 im_phone_menu_get_message_time (GMenuModel *model, gint i) { gint64 time; g_menu_model_get_item_attribute (model, i, "x-canonical-time", "x", &time); return time; } void im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *app_id, GIcon *app_icon, const gchar *id, GVariant *serialized_icon, const gchar *title, const gchar *subtitle, const gchar *body, GVariant *actions, gint64 time) { GMenuItem *item; gchar *action_name; gint n_messages; gint pos; GVariant *serialized_app_icon; gboolean show_data; g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id); show_data = im_menu_show_data(IM_MENU (menu)); action_name = g_strconcat (app_id, ".msg.", id, NULL); item = g_menu_item_new (title, NULL); g_menu_item_set_action_and_target_value (item, action_name, g_variant_new_boolean (TRUE)); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); g_menu_item_set_attribute (item, "x-canonical-message-id", "s", id); if (show_data) g_menu_item_set_attribute (item, "x-canonical-subtitle", "s", subtitle); if (show_data) g_menu_item_set_attribute (item, "x-canonical-text", "s", body); g_menu_item_set_attribute (item, "x-canonical-time", "x", time); if (serialized_icon) g_menu_item_set_attribute_value (item, "icon", serialized_icon); if (app_icon && (serialized_app_icon = g_icon_serialize (app_icon))) { g_menu_item_set_attribute_value (item, "x-canonical-app-icon", serialized_app_icon); g_variant_unref (serialized_app_icon); } if (actions && show_data) g_menu_item_set_attribute (item, "x-canonical-message-actions", "v", actions); n_messages = g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section)); pos = 0; while (pos < n_messages && time < im_phone_menu_get_message_time (G_MENU_MODEL (menu->message_section), pos)) pos++; g_menu_insert_item (menu->message_section, pos, item); im_phone_menu_update_clear_section (menu); g_free (action_name); g_object_unref (item); } void im_phone_menu_remove_message (ImPhoneMenu *menu, const gchar *app_id, const gchar *id) { gchar *action_name; g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); action_name = g_strconcat (app_id, ".msg.", id, NULL); im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->message_section), action_name, (ImMenuForeachFunc) g_menu_remove); im_phone_menu_update_clear_section (menu); g_free (action_name); } void im_phone_menu_add_source (ImPhoneMenu *menu, const gchar *app_id, const gchar *id, const gchar *label, const gchar *iconstr) { GMenuItem *item; gchar *action_name; g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); action_name = g_strconcat (app_id, ".src.", id, NULL); item = g_menu_item_new (label, NULL); g_menu_item_set_action_and_target_value (item, action_name, g_variant_new_boolean (TRUE)); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem"); if (iconstr) g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr); g_menu_prepend_item (menu->source_section, item); g_free (action_name); g_object_unref (item); } void im_phone_menu_remove_source (ImPhoneMenu *menu, const gchar *app_id, const gchar *id) { gchar *action_name; g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); action_name = g_strconcat (app_id, ".src.", id, NULL); im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->source_section), action_name, (ImMenuForeachFunc) g_menu_remove); g_free (action_name); } static void im_phone_menu_remove_all_for_app (GMenu *menu, const gchar *app_id) { gchar *prefix; gint n_items; gint i = 0; prefix = g_strconcat (app_id, ".", NULL); n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu)); while (i < n_items) { gchar *action; g_menu_model_get_item_attribute (G_MENU_MODEL (menu), i, G_MENU_ATTRIBUTE_ACTION, "s", &action); if (g_str_has_prefix (action, prefix)) { g_menu_remove (menu, i); n_items--; } else { i++; } g_free (action); } g_free (prefix); } void im_phone_menu_remove_application (ImPhoneMenu *menu, const gchar *app_id) { g_return_if_fail (IM_IS_PHONE_MENU (menu)); g_return_if_fail (app_id != NULL); im_phone_menu_remove_all_for_app (menu->source_section, app_id); im_phone_menu_remove_all_for_app (menu->message_section, app_id); im_phone_menu_update_clear_section (menu); } void im_phone_menu_remove_all (ImPhoneMenu *menu) { g_return_if_fail (IM_IS_PHONE_MENU (menu)); while (g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section))) g_menu_remove (menu->message_section, 0); while (g_menu_model_get_n_items (G_MENU_MODEL (menu->source_section))) g_menu_remove (menu->source_section, 0); im_phone_menu_update_clear_section (menu); } ./src/Makefile.am0000644000004100000410000000167113350212604014067 0ustar www-datawww-data EXTRA_DIST = pkglibexec_PROGRAMS = indicator-messages-service indicator_messages_service_SOURCES = \ messages-service.c \ dbus-data.h \ gactionmuxer.c \ gactionmuxer.h \ gsettingsstrv.c \ gsettingsstrv.h \ im-accounts-service.c \ im-accounts-service.h \ im-menu.c \ im-menu.h \ im-phone-menu.c \ im-phone-menu.h \ im-desktop-menu.c \ im-desktop-menu.h \ im-application-list.c \ im-application-list.h \ indicator-desktop-shortcuts.c \ indicator-desktop-shortcuts.h indicator_messages_service_CFLAGS = \ $(APPLET_CFLAGS) \ $(COVERAGE_CFLAGS) \ -I$(top_builddir)/common \ -Wall \ -Wl,-Bsymbolic-functions \ -Wl,-z,defs \ -Wl,--as-needed \ -Werror -Wno-error=deprecated-declarations \ -DG_LOG_DOMAIN=\"Indicator-Messages\" indicator_messages_service_LDADD = \ $(top_builddir)/common/libmessaging-common.la \ $(APPLET_LIBS) indicator_messages_service_LDFLAGS = \ $(COVERAGE_LDFLAGS) EXTRA_DIST += \ messages-service.xml ./src/messages-service.c0000644000004100000410000002033313350212604015440 0ustar www-datawww-data/* An indicator to show information that is in messaging applications that the user is using. Copyright 2012 Canonical Ltd. Authors: Ted Gould Lars Uebernickel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include "dbus-data.h" #include "gsettingsstrv.h" #include "indicator-messages-service.h" #include "indicator-messages-application.h" #include "im-phone-menu.h" #include "im-desktop-menu.h" #include "im-application-list.h" #define NUM_STATUSES 5 static ImApplicationList *applications; static IndicatorMessagesService *messages_service; static GHashTable *menus; static GSettings *settings; enum { DBUS_ERROR_BAD_DESKTOP_FILE, }; G_DEFINE_QUARK(indicator_messages_dbus_error, dbus_error); static gboolean register_application (IndicatorMessagesService *service, GDBusMethodInvocation *invocation, const gchar *desktop_id, const gchar *menu_path, gpointer user_data) { GDBusConnection *bus; const gchar *sender; if (!im_application_list_add (applications, desktop_id)) { g_dbus_method_invocation_return_error(invocation, dbus_error_quark(), DBUS_ERROR_BAD_DESKTOP_FILE, "Unable to find or parse desktop file for application '%s'", desktop_id); return TRUE; } bus = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (service)); sender = g_dbus_method_invocation_get_sender (invocation); im_application_list_set_remote (applications, desktop_id, bus, sender, menu_path); g_settings_strv_append_unique (settings, "applications", desktop_id); indicator_messages_service_complete_register_application (service, invocation); return TRUE; } static gboolean unregister_application (IndicatorMessagesService *service, GDBusMethodInvocation *invocation, const gchar *desktop_id, gpointer user_data) { im_application_list_remove (applications, desktop_id); g_settings_strv_remove (settings, "applications", desktop_id); indicator_messages_service_complete_unregister_application (service, invocation); return TRUE; } static gboolean set_status (IndicatorMessagesService *service, GDBusMethodInvocation *invocation, const gchar *desktop_id, const gchar *status_str, gpointer user_data) { GDesktopAppInfo *appinfo; const gchar *id; g_return_val_if_fail (g_str_equal (status_str, "available") || g_str_equal (status_str, "away")|| g_str_equal (status_str, "busy") || g_str_equal (status_str, "invisible") || g_str_equal (status_str, "offline"), FALSE); appinfo = g_desktop_app_info_new (desktop_id); if (!appinfo) { g_warning ("could not set status for '%s', there's no desktop file with that id", desktop_id); return TRUE; } id = g_app_info_get_id (G_APP_INFO (appinfo)); im_application_list_set_status(applications, id, status_str); indicator_messages_service_complete_set_status (service, invocation); g_object_unref (appinfo); return TRUE; } static gboolean app_stopped (IndicatorMessagesService *service, GDBusMethodInvocation *invocation, const gchar *desktop_id, gpointer user_data) { GDesktopAppInfo *appinfo; const gchar *id; appinfo = g_desktop_app_info_new (desktop_id); if (!appinfo) return TRUE; id = g_app_info_get_id (G_APP_INFO (appinfo)); im_application_list_set_remote (applications, id, NULL, NULL, NULL); indicator_messages_service_complete_application_stopped_running (service, invocation); g_object_unref (appinfo); return TRUE; } /* The status has been set by the user, let's tell the world! */ static void status_set_by_user (ImApplicationList * list, const gchar * status, gpointer user_data) { indicator_messages_service_emit_status_changed(messages_service, status); return; } static void on_bus_acquired (GDBusConnection *bus, const gchar *name, gpointer user_data) { GError *error = NULL; GHashTableIter it; const gchar *profile; ImMenu *menu; /* Register some errors */ g_dbus_error_register_error (dbus_error_quark(), DBUS_ERROR_BAD_DESKTOP_FILE, "BadDesktopFile"); g_dbus_connection_export_action_group (bus, INDICATOR_MESSAGES_DBUS_OBJECT, im_application_list_get_action_group (applications), &error); if (error) { g_warning ("unable to export action group on dbus: %s", error->message); g_error_free (error); return; } g_hash_table_iter_init (&it, menus); while (g_hash_table_iter_next (&it, (gpointer *) &profile, (gpointer *) &menu)) { gchar *object_path; object_path = g_strconcat (INDICATOR_MESSAGES_DBUS_OBJECT, "/", profile, NULL); if (!im_menu_export (menu, bus, object_path, &error)) { g_warning ("unable to export menu for profile '%s': %s", profile, error->message); g_clear_error (&error); } g_free (object_path); } g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (messages_service), bus, INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT, &error); if (error) { g_warning ("unable to export messages service on dbus: %s", error->message); g_error_free (error); return; } } static void on_name_lost (GDBusConnection *bus, const gchar *name, gpointer user_data) { GMainLoop *mainloop = user_data; g_main_loop_quit (mainloop); } static gboolean sig_term_handler (gpointer user_data) { GMainLoop *mainloop = user_data; g_main_loop_quit (mainloop); return FALSE; } int main (int argc, char ** argv) { GMainLoop * mainloop = NULL; GBusNameOwnerFlags flags; /* Glib init */ #if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init(); #endif mainloop = g_main_loop_new (NULL, FALSE); /* Setting up i18n and gettext. Apparently, we need all of these. */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); /* Bring up the service DBus interface */ messages_service = indicator_messages_service_skeleton_new (); flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; if (argc >= 2 && g_str_equal (argv[1], "--replace")) flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; g_bus_own_name (G_BUS_TYPE_SESSION, "com.canonical.indicator.messages", flags, on_bus_acquired, NULL, on_name_lost, mainloop, NULL); g_signal_connect (messages_service, "handle-register-application", G_CALLBACK (register_application), NULL); g_signal_connect (messages_service, "handle-unregister-application", G_CALLBACK (unregister_application), NULL); g_signal_connect (messages_service, "handle-set-status", G_CALLBACK (set_status), NULL); g_signal_connect (messages_service, "handle-application-stopped-running", G_CALLBACK (app_stopped), NULL); applications = im_application_list_new (); g_signal_connect (applications, "status-set", G_CALLBACK (status_set_by_user), NULL); settings = g_settings_new ("com.canonical.indicator.messages"); { gchar **app_ids; gchar **id; app_ids = g_settings_get_strv (settings, "applications"); for (id = app_ids; *id; id++) im_application_list_add (applications, *id); g_strfreev (app_ids); } menus = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); g_hash_table_insert (menus, "phone", im_phone_menu_new (applications, FALSE)); g_hash_table_insert (menus, "phone_greeter", im_phone_menu_new (applications, TRUE)); g_hash_table_insert (menus, "desktop", im_desktop_menu_new (applications)); g_hash_table_insert (menus, "desktop_greeter", im_desktop_menu_new (applications)); g_unix_signal_add(SIGTERM, sig_term_handler, mainloop); g_main_loop_run(mainloop); /* Clean up */ g_hash_table_unref (menus); g_object_unref (messages_service); g_object_unref (settings); g_object_unref (applications); return 0; } ./COPYING.GPLv30000644000004100000410000010451313350212604013170 0ustar www-datawww-data GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ./autogen.sh0000755000004100000410000000024713350212604013243 0ustar www-datawww-data#!/bin/sh PKG_NAME="indicator-messages" which gnome-autogen.sh || { echo "You need gnome-common from GNOME SVN" exit 1 } USE_GNOME2_MACROS=1 \ . gnome-autogen.sh ./libmessaging-menu/0000755000004100000410000000000013350212604014645 5ustar www-datawww-data./libmessaging-menu/client-example.py0000755000004100000410000000146713350212604020141 0ustar www-datawww-data#!/usr/bin/env python from gi.repository import GLib, Gio, MessagingMenu mmapp = MessagingMenu.App(desktop_id='evolution.desktop') # make the application appear in the messaging menu. The name and icon are taken from the desktop file above mmapp.register() def source_activated(mmapp, source_id): print('source {} activated'.format(source_id)) # do something when the user clicks on a source. The source will be removed automatically mmapp.connect('activate-source', source_activated) # add a 'source' (a menu item below the application's name) with the name 'Inbox' and a count of 7 icon = Gio.ThemedIcon.new_with_default_fallbacks('my-source-icon') mmapp.append_source_with_count('inbox', icon, 'Inbox', 7) # this is not necessary for gtk applications, which start a mainloop in gtk_main() GLib.MainLoop().run() ./libmessaging-menu/messaging-menu-message.h0000644000004100000410000000711213350212604021360 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #ifndef __messaging_menu_message_h__ #define __messaging_menu_message_h__ #include G_BEGIN_DECLS #define MESSAGING_MENU_TYPE_MESSAGE (messaging_menu_message_get_type ()) #define MESSAGING_MENU_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MESSAGING_MENU_TYPE_MESSAGE, MessagingMenuMessage)) #define MESSAGING_MENU_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MESSAGING_MENU_TYPE_MESSAGE, MessagingMenuMessageClass)) #define MESSAGING_MENU_IS_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MESSAGING_MENU_TYPE_MESSAGE)) #define MESSAGING_MENU_IS_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MESSAGING_MENU_TYPE_MESSAGE)) #define MESSAGING_MENU_MESSAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MESSAGING_MENU_TYPE_MESSAGE, MessagingMenuMessageClass)) typedef struct _MessagingMenuMessage MessagingMenuMessage; GType messaging_menu_message_get_type (void) G_GNUC_CONST; MessagingMenuMessage * messaging_menu_message_new (const gchar *id, GIcon *icon, const gchar *title, const gchar *subtitle, const gchar *body, gint64 time); const gchar * messaging_menu_message_get_id (MessagingMenuMessage *msg); GIcon * messaging_menu_message_get_icon (MessagingMenuMessage *msg); const gchar * messaging_menu_message_get_title (MessagingMenuMessage *msg); const gchar * messaging_menu_message_get_subtitle (MessagingMenuMessage *msg); const gchar * messaging_menu_message_get_body (MessagingMenuMessage *msg); gint64 messaging_menu_message_get_time (MessagingMenuMessage *msg); gboolean messaging_menu_message_get_draws_attention (MessagingMenuMessage *msg); void messaging_menu_message_set_draws_attention (MessagingMenuMessage *msg, gboolean draws_attention); void messaging_menu_message_add_action (MessagingMenuMessage *msg, const gchar *id, const gchar *label, const GVariantType *parameter_type, GVariant *parameter_hint); G_END_DECLS #endif ./libmessaging-menu/messaging-menu-app.h0000644000004100000410000002216513350212604020521 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #ifndef __messaging_menu_app_h__ #define __messaging_menu_app_h__ #include #include "messaging-menu-message.h" G_BEGIN_DECLS #define MESSAGING_MENU_TYPE_APP messaging_menu_app_get_type() #define MESSAGING_MENU_APP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MESSAGING_MENU_TYPE_APP, MessagingMenuApp)) #define MESSAGING_MENU_APP_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), MESSAGING_MENU_TYPE_APP, MessagingMenuAppClass)) #define MESSAGING_MENU_IS_APP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MESSAGING_MENU_TYPE_APP)) /** * MessagingMenuStatus: * @MESSAGING_MENU_STATUS_AVAILABLE: available * @MESSAGING_MENU_STATUS_AWAY: away * @MESSAGING_MENU_STATUS_BUSY: busy * @MESSAGING_MENU_STATUS_INVISIBLE: invisible * @MESSAGING_MENU_STATUS_OFFLINE: offline * * An enumeration for the possible chat statuses the messaging menu can be in. */ typedef enum { MESSAGING_MENU_STATUS_AVAILABLE, MESSAGING_MENU_STATUS_AWAY, MESSAGING_MENU_STATUS_BUSY, MESSAGING_MENU_STATUS_INVISIBLE, MESSAGING_MENU_STATUS_OFFLINE } MessagingMenuStatus; typedef GObjectClass MessagingMenuAppClass; typedef struct _MessagingMenuApp MessagingMenuApp; GType messaging_menu_app_get_type (void) G_GNUC_CONST; MessagingMenuApp * messaging_menu_app_new (const gchar *desktop_id); void messaging_menu_app_register (MessagingMenuApp *app); void messaging_menu_app_unregister (MessagingMenuApp *app); void messaging_menu_app_set_status (MessagingMenuApp *app, MessagingMenuStatus status); void messaging_menu_app_insert_source (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label); void messaging_menu_app_append_source (MessagingMenuApp *app, const gchar *id, GIcon *icon, const gchar *label); void messaging_menu_app_insert_source_with_count (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label, guint count); void messaging_menu_app_append_source_with_count (MessagingMenuApp *app, const gchar *id, GIcon *icon, const gchar *label, guint count); void messaging_menu_app_insert_source_with_time (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label, gint64 time); void messaging_menu_app_append_source_with_time (MessagingMenuApp *app, const gchar *id, GIcon *icon, const gchar *label, gint64 time); void messaging_menu_app_append_source_with_string (MessagingMenuApp *app, const gchar *id, GIcon *icon, const gchar *label, const gchar *str); void messaging_menu_app_insert_source_with_string (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label, const gchar *str); void messaging_menu_app_remove_source (MessagingMenuApp *app, const gchar *source_id); gboolean messaging_menu_app_has_source (MessagingMenuApp *app, const gchar *source_id); void messaging_menu_app_set_source_label (MessagingMenuApp *app, const gchar *source_id, const gchar *label); void messaging_menu_app_set_source_icon (MessagingMenuApp *app, const gchar *source_id, GIcon *icon); void messaging_menu_app_set_source_count (MessagingMenuApp *app, const gchar *source_id, guint count); void messaging_menu_app_set_source_time (MessagingMenuApp *app, const gchar *source_id, gint64 time); void messaging_menu_app_set_source_string (MessagingMenuApp *app, const gchar *source_id, const gchar *str); void messaging_menu_app_draw_attention (MessagingMenuApp *app, const gchar *source_id); void messaging_menu_app_remove_attention (MessagingMenuApp *app, const gchar *source_id); void messaging_menu_app_append_message (MessagingMenuApp *app, MessagingMenuMessage *msg, const gchar *source_id, gboolean notify); MessagingMenuMessage * messaging_menu_app_get_message (MessagingMenuApp *app, const gchar *id); void messaging_menu_app_remove_message (MessagingMenuApp *app, MessagingMenuMessage *msg); void messaging_menu_app_remove_message_by_id (MessagingMenuApp *app, const gchar *id); G_END_DECLS #endif ./libmessaging-menu/messaging-menu.pc.in0000644000004100000410000000041713350212604020517 0ustar www-datawww-dataprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@/messaging-menu Name: Messaging Menu Library Description: Messaging Menu client library Version: @VERSION@ Requires: gio-unix-2.0 Libs: -L${libdir} -lmessaging-menu Cflags: -I${includedir} ./libmessaging-menu/messaging-menu-app.c0000644000004100000410000013511113350212604020510 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #include "messaging-menu-app.h" #include "indicator-messages-service.h" #include "indicator-messages-application.h" #include #include /** * SECTION:messaging-menu-app * @title: MessagingMenuApp * @short_description: An application section in the messaging menu * @include: messaging-menu.h * * A #MessagingMenuApp represents an application section in the * Messaging Menu. An application section is tied to an installed * application through a desktop file id, which must be passed to * messaging_menu_app_new(). * * To register the application with the Messaging Menu, call * messaging_menu_app_register(). This signifies that the application * should be present in the menu and be marked as "running". * * The first menu item in an application section represents the * application itself, using the name and icon found in the associated * desktop file. Activating this item starts the application. * * Following the application item, the Messaging Menu inserts all * shortcut actions found in the desktop file. Actions whose * NotShowIn keyword contains "Messaging Menu" or whose * OnlyShowIn keyword does not contain "Messaging Menu" * will not appear (the * desktop file specification contains a detailed explanation of * shortcut actions.) An application cannot add, remove, or change * these shortcut items while it is running. * * Next, an application section contains menu items for message sources. * What exactly constitutes a message source depends on the type of * application: an email client's message sources are folders * containing new messages, while those of a chat program are persons * that have contacted the user. * * A message source is represented in the menu by a label and optionally * also an icon. It can be associated with either a count, a time, or * an arbitrary string, which will appear on the right side of the menu * item. * * When the user activates a source, the source is immediately removed * from the menu and the "activate-source" signal is emitted. * * Applications should always expose all the message sources available. * However, the Messaging Menu might limit the amount of sources it * displays to the user. * * The Messaging Menu offers users a way to set their chat status * (available, away, busy, invisible, or offline) for multiple * applications at once. Applications that appear in the Messaging Menu * can integrate with this by setting the * "X-MessagingMenu-UsesChatSection" key in their desktop file to True. * Use messaging_menu_app_set_status() to signify that the application's * chat status has changed. When the user changes status through the * Messaging Menu, the ::status-changed signal will be emitted. * * If the application stops running without calling * messaging_menu_app_unregister(), it will be marked as "not running". * Its application and shortcut items stay in the menu, but all message * sources are removed. If messaging_menu_app_unregister() is called, * the application section is removed completely. * * More information about the design and recommended usage of the * Messaging Menu is available at https://wiki.ubuntu.com/MessagingMenu. */ /** * MessagingMenuApp: * * #MessagingMenuApp is an opaque structure. */ struct _MessagingMenuApp { GObject parent_instance; GDesktopAppInfo *appinfo; int registered; /* -1 for unknown */ MessagingMenuStatus status; gboolean status_set; GDBusConnection *bus; GHashTable *messages; GList *sources; IndicatorMessagesApplication *app_interface; IndicatorMessagesService *messages_service; guint watch_id; GCancellable *cancellable; }; G_DEFINE_TYPE (MessagingMenuApp, messaging_menu_app, G_TYPE_OBJECT); enum { PROP_0, PROP_DESKTOP_ID, N_PROPERTIES }; enum { ACTIVATE_SOURCE, STATUS_CHANGED, N_SIGNALS }; static GParamSpec *properties[N_PROPERTIES]; static guint signals[N_SIGNALS]; static const gchar *status_ids[] = { "available", "away", "busy", "invisible", "offline" }; typedef struct { gchar *id; GIcon *icon; gchar *label; guint32 count; gint64 time; gchar *string; gboolean draws_attention; } Source; static void global_status_changed (IndicatorMessagesService *service, const gchar *status_str, gpointer user_data); /* in messaging-menu-message.c */ GVariant * _messaging_menu_message_to_variant (MessagingMenuMessage *msg); static void source_free (gpointer data) { Source *source = data; if (source) { g_free (source->id); g_clear_object (&source->icon); g_free (source->label); g_free (source->string); g_slice_free (Source, source); } } static GVariant * source_to_variant (Source *source) { GVariant *v; GVariant *serialized_icon; GVariantBuilder builder; serialized_icon = source->icon ? g_icon_serialize (source->icon) : NULL; g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); if (serialized_icon) { g_variant_builder_add (&builder, "v", serialized_icon); g_variant_unref (serialized_icon); } v = g_variant_new ("(ssavuxsb)", source->id, source->label, &builder, source->count, source->time, source->string ? source->string : "", source->draws_attention); return v; } static gchar * messaging_menu_app_get_dbus_object_path (MessagingMenuApp *app) { gchar *path; if (!app->appinfo) return NULL; path = g_strconcat ("/com/canonical/indicator/messages/", g_app_info_get_id (G_APP_INFO (app->appinfo)), NULL); g_strcanon (path, "/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", '_'); return path; } static void messaging_menu_app_got_bus (GObject *source, GAsyncResult *res, gpointer user_data) { MessagingMenuApp *app = user_data; GError *error = NULL; gchar *object_path; app->bus = g_bus_get_finish (res, &error); if (app->bus == NULL) { g_warning ("unable to connect to session bus: %s", error->message); g_error_free (error); return; } object_path = messaging_menu_app_get_dbus_object_path (app); if (object_path && !g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (app->app_interface), app->bus, object_path, &error)) { g_warning ("unable to export application interface: %s", error->message); g_clear_error (&error); } g_free (object_path); } static void messaging_menu_app_set_desktop_id (MessagingMenuApp *app, const gchar *desktop_id) { g_return_if_fail (desktop_id != NULL); /* no need to clean up, it's construct only */ app->appinfo = g_desktop_app_info_new (desktop_id); if (app->appinfo == NULL) { g_warning ("could not find the desktop file for '%s'", desktop_id); } g_bus_get (G_BUS_TYPE_SESSION, app->cancellable, messaging_menu_app_got_bus, app); } static void messaging_menu_app_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { MessagingMenuApp *app = MESSAGING_MENU_APP (object); switch (prop_id) { case PROP_DESKTOP_ID: messaging_menu_app_set_desktop_id (app, g_value_get_string (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void messaging_menu_app_finalize (GObject *object) { G_OBJECT_CLASS (messaging_menu_app_parent_class)->finalize (object); } static void messaging_menu_app_dispose (GObject *object) { MessagingMenuApp *app = MESSAGING_MENU_APP (object); if (app->watch_id > 0) { g_bus_unwatch_name (app->watch_id); app->watch_id = 0; } if (app->cancellable) { g_cancellable_cancel (app->cancellable); g_object_unref (app->cancellable); app->cancellable = NULL; } if (app->messages_service) { indicator_messages_service_call_application_stopped_running (app->messages_service, g_app_info_get_id (G_APP_INFO (app->appinfo)), NULL, NULL, NULL); g_signal_handlers_disconnect_by_func (app->messages_service, global_status_changed, app); g_clear_object (&app->messages_service); } g_clear_pointer (&app->messages, g_hash_table_unref); g_list_free_full (app->sources, source_free); app->sources = NULL; g_clear_object (&app->app_interface); g_clear_object (&app->appinfo); g_clear_object (&app->bus); G_OBJECT_CLASS (messaging_menu_app_parent_class)->dispose (object); } static void messaging_menu_app_class_init (MessagingMenuAppClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); object_class->set_property = messaging_menu_app_set_property; object_class->finalize = messaging_menu_app_finalize; object_class->dispose = messaging_menu_app_dispose; /** * MessagingMenuApp:desktop-id: * * The desktop id of the application associated with this application * section. Must be given when the #MessagingMenuApp is created. */ properties[PROP_DESKTOP_ID] = g_param_spec_string ("desktop-id", "Desktop Id", "The desktop id of the associated application", NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, N_PROPERTIES, properties); /** * MessagingMenuApp::activate-source: * @mmapp: the #MessagingMenuApp * @source_id: the source id that was activated * * Emitted when the user has activated the message source with id * @source_id. The source is immediately removed from the menu, * handlers of this signal do not need to call * messaging_menu_app_remove_source(). */ signals[ACTIVATE_SOURCE] = g_signal_new ("activate-source", MESSAGING_MENU_TYPE_APP, G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); /** * MessagingMenuApp::status-changed: * @mmapp: the #MessagingMenuApp * @status: a #MessagingMenuStatus * * Emitted when the chat status is changed through the messaging menu. * * Applications which are registered to use the chat status should * change their status to @status upon receiving this signal. Call * messaging_menu_app_set_status() to acknowledge that the application * changed its status. */ signals[STATUS_CHANGED] = g_signal_new ("status-changed", MESSAGING_MENU_TYPE_APP, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); } static void created_messages_service (GObject *source_object, GAsyncResult *result, gpointer user_data) { MessagingMenuApp *app = user_data; GError *error = NULL; app->messages_service = indicator_messages_service_proxy_new_finish (result, &error); if (!app->messages_service) { g_warning ("unable to connect to the mesaging menu service: %s", error->message); g_error_free (error); return; } g_signal_connect (app->messages_service, "status-changed", G_CALLBACK (global_status_changed), app); /* sync current status */ if (app->registered == TRUE) messaging_menu_app_register (app); else if (app->registered == FALSE) messaging_menu_app_unregister (app); if (app->status_set) messaging_menu_app_set_status (app, app->status); } static void indicator_messages_appeared (GDBusConnection *bus, const gchar *name, const gchar *name_owner, gpointer user_data) { MessagingMenuApp *app = user_data; indicator_messages_service_proxy_new (bus, G_DBUS_PROXY_FLAGS_NONE, "com.canonical.indicator.messages", "/com/canonical/indicator/messages/service", app->cancellable, created_messages_service, app); } static void indicator_messages_vanished (GDBusConnection *bus, const gchar *name, gpointer user_data) { MessagingMenuApp *app = user_data; if (app->messages_service) { g_signal_handlers_disconnect_by_func (app->messages_service, global_status_changed, app); g_clear_object (&app->messages_service); } } static gboolean messaging_menu_app_list_sources (IndicatorMessagesApplication *app_interface, GDBusMethodInvocation *invocation, gpointer user_data) { MessagingMenuApp *app = user_data; GVariantBuilder builder; GList *it; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ssavuxsb)")); for (it = app->sources; it; it = it->next) g_variant_builder_add_value (&builder, source_to_variant (it->data)); indicator_messages_application_complete_list_sources (app_interface, invocation, g_variant_builder_end (&builder)); return TRUE; } static gint compare_source_id (gconstpointer a, gconstpointer b) { const Source *source = a; const gchar *id = b; return strcmp (source->id, id); } static gboolean messaging_menu_app_remove_source_internal (MessagingMenuApp *app, const gchar *source_id) { GList *node; node = g_list_find_custom (app->sources, source_id, compare_source_id); if (node) { source_free (node->data); app->sources = g_list_delete_link (app->sources, node); return TRUE; } return FALSE; } static gboolean messaging_menu_app_remove_message_internal (MessagingMenuApp *app, const gchar *message_id) { return g_hash_table_remove (app->messages, message_id); } static gboolean messaging_menu_app_activate_source (IndicatorMessagesApplication *app_interface, GDBusMethodInvocation *invocation, const gchar *source_id, gpointer user_data) { MessagingMenuApp *app = user_data; GQuark q = g_quark_from_string (source_id); /* Activate implies removing the source, no need for SourceRemoved */ if (messaging_menu_app_remove_source_internal (app, source_id)) g_signal_emit (app, signals[ACTIVATE_SOURCE], q, source_id); indicator_messages_application_complete_activate_source (app_interface, invocation); return TRUE; } static gboolean messaging_menu_app_list_messages (IndicatorMessagesApplication *app_interface, GDBusMethodInvocation *invocation, gpointer user_data) { MessagingMenuApp *app = user_data; GVariantBuilder builder; GHashTableIter iter; MessagingMenuMessage *message; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(savsssxaa{sv}b)")); g_hash_table_iter_init (&iter, app->messages); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &message)) g_variant_builder_add_value (&builder, _messaging_menu_message_to_variant (message)); indicator_messages_application_complete_list_messages (app_interface, invocation, g_variant_builder_end (&builder)); return TRUE; } static gboolean messaging_menu_app_activate_message (IndicatorMessagesApplication *app_interface, GDBusMethodInvocation *invocation, const gchar *message_id, const gchar *action_id, GVariant *params, gpointer user_data) { MessagingMenuApp *app = user_data; MessagingMenuMessage *msg; msg = g_hash_table_lookup (app->messages, message_id); if (msg) { if (*action_id) { gchar *signal; signal = g_strconcat ("activate::", action_id, NULL); if (g_variant_n_children (params)) { GVariant *param; g_variant_get_child (params, 0, "v", ¶m); g_signal_emit_by_name (msg, signal, action_id, param); g_variant_unref (param); } else g_signal_emit_by_name (msg, signal, action_id, NULL); g_free (signal); } else g_signal_emit_by_name (msg, "activate", NULL, NULL); /* Activate implies removing the message, no need for MessageRemoved */ messaging_menu_app_remove_message_internal (app, message_id); } indicator_messages_application_complete_activate_message (app_interface, invocation); return TRUE; } static gboolean messaging_menu_app_dismiss (IndicatorMessagesApplication *app_interface, GDBusMethodInvocation *invocation, const gchar * const *sources, const gchar * const *messages, gpointer user_data) { MessagingMenuApp *app = user_data; const gchar * const *it; for (it = sources; *it; it++) messaging_menu_app_remove_source_internal (app, *it); for (it = messages; *it; it++) messaging_menu_app_remove_message_internal (app, *it); return TRUE; } static void messaging_menu_app_init (MessagingMenuApp *app) { app->registered = -1; app->status_set = FALSE; app->bus = NULL; app->cancellable = g_cancellable_new (); app->app_interface = indicator_messages_application_skeleton_new (); g_signal_connect (app->app_interface, "handle-list-sources", G_CALLBACK (messaging_menu_app_list_sources), app); g_signal_connect (app->app_interface, "handle-activate-source", G_CALLBACK (messaging_menu_app_activate_source), app); g_signal_connect (app->app_interface, "handle-list-messages", G_CALLBACK (messaging_menu_app_list_messages), app); g_signal_connect (app->app_interface, "handle-activate-message", G_CALLBACK (messaging_menu_app_activate_message), app); g_signal_connect (app->app_interface, "handle-dismiss", G_CALLBACK (messaging_menu_app_dismiss), app); app->messages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); app->watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, "com.canonical.indicator.messages", G_BUS_NAME_WATCHER_FLAGS_NONE, indicator_messages_appeared, indicator_messages_vanished, app, NULL); } /** * messaging_menu_new: * @desktop_id: a desktop file id. See g_desktop_app_info_new() * * Creates a new #MessagingMenuApp for the application associated with * @desktop_id. * * The application will not show up (nor be marked as "running") in the * Messaging Menu before messaging_menu_app_register() has been called. * * Returns: (transfer full): a new #MessagingMenuApp */ MessagingMenuApp * messaging_menu_app_new (const gchar *desktop_id) { return g_object_new (MESSAGING_MENU_TYPE_APP, "desktop-id", desktop_id, NULL); } /** * messaging_menu_app_register: * @app: a #MessagingMenuApp * * Registers @app with the Messaging Menu. * * If the application doesn't already have a section in the Messaging * Menu, one will be created for it. The application will also be * marked as "running". * * The application will be marked as "not running" as soon as @app is * destroyed. The application launcher as well as shortcut actions will * remain in the menu. To completely remove the application section * from the Messaging Menu, call messaging_menu_app_unregister(). */ void messaging_menu_app_register (MessagingMenuApp *app) { gchar *object_path; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); app->registered = TRUE; /* state will be synced right after connecting to the service */ if (!app->messages_service) return; object_path = messaging_menu_app_get_dbus_object_path (app); if (!object_path) return; indicator_messages_service_call_register_application (app->messages_service, g_app_info_get_id (G_APP_INFO (app->appinfo)), object_path, app->cancellable, NULL, NULL); g_free (object_path); } /** * messaging_menu_app_unregister: * @app: a #MessagingMenuApp * * Completely removes the @app from the Messaging Menu. If the * application's launcher and shortcut actions should remain in the * menu, destroying @app with g_object_unref() suffices. * * Note: @app will remain valid and usable after this call. */ void messaging_menu_app_unregister (MessagingMenuApp *app) { g_return_if_fail (MESSAGING_MENU_IS_APP (app)); app->registered = FALSE; /* state will be synced right after connecting to the service */ if (!app->messages_service) return; if (!app->appinfo) return; indicator_messages_service_call_unregister_application (app->messages_service, g_app_info_get_id (G_APP_INFO (app->appinfo)), app->cancellable, NULL, NULL); } /** * messaging_menu_app_set_status: * @app: a #MessagingMenuApp * @status: a #MessagingMenuStatus * * Notify the Messaging Menu that the chat status of @app has changed to * @status. * * Connect to the ::status-changed signal to receive notification about * the user changing their global chat status through the Messaging * Menu. * * This function does nothing for applications whose desktop file does * not include X-MessagingMenu-UsesChatSection. */ void messaging_menu_app_set_status (MessagingMenuApp *app, MessagingMenuStatus status) { g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (status >= MESSAGING_MENU_STATUS_AVAILABLE && status <= MESSAGING_MENU_STATUS_OFFLINE); app->status = status; app->status_set = TRUE; /* state will be synced right after connecting to the service */ if (!app->messages_service) return; if (!app->appinfo) return; indicator_messages_service_call_set_status (app->messages_service, g_app_info_get_id (G_APP_INFO (app->appinfo)), status_ids [status], app->cancellable, NULL, NULL); } static int status_from_string (const gchar *s) { int i; if (!s) return -1; for (i = 0; i <= MESSAGING_MENU_STATUS_OFFLINE; i++) { if (g_str_equal (s, status_ids[i])) return i; } return -1; } static void global_status_changed (IndicatorMessagesService *service, const gchar *status_str, gpointer user_data) { MessagingMenuApp *app = user_data; int status; status = status_from_string (status_str); g_return_if_fail (status >= 0); g_signal_emit (app, signals[STATUS_CHANGED], 0, status); } static Source * messaging_menu_app_lookup_source (MessagingMenuApp *app, const gchar *id) { GList *node; node = g_list_find_custom (app->sources, id, compare_source_id); return node ? node->data : NULL; } static Source * messaging_menu_app_get_source (MessagingMenuApp *app, const gchar *id) { Source *source; source = messaging_menu_app_lookup_source (app, id); if (!source) g_warning ("a source with id '%s' doesn't exist", id); return source; } static void messaging_menu_app_notify_source_changed (MessagingMenuApp *app, Source *source) { indicator_messages_application_emit_source_changed (app->app_interface, source_to_variant (source)); } static void messaging_menu_app_insert_source_internal (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label, guint count, gint64 time, const gchar *string) { Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (id != NULL); g_return_if_fail (label != NULL); if (messaging_menu_app_lookup_source (app, id)) { g_warning ("a source with id '%s' already exists", id); return; } source = g_slice_new0 (Source); source->id = g_strdup (id); source->label = g_strdup (label); if (icon) source->icon = g_object_ref (icon); source->count = count; source->time = time; source->string = g_strdup (string); app->sources = g_list_insert (app->sources, source, position); indicator_messages_application_emit_source_added (app->app_interface, position, source_to_variant (source)); } /** * messaging_menu_app_insert_source: * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added * @icon: the icon associated with the source * @label: a user-visible string best describing the source * * Inserts a new message source into the section representing @app. Equivalent * to calling messaging_menu_app_insert_source_with_time() with the current * time. * * It is an error to insert a source with an @id which already exists. Use * messaging_menu_app_has_source() to find out whether there is such a source. */ void messaging_menu_app_insert_source (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label) { messaging_menu_app_insert_source_with_time (app, position, id, icon, label, g_get_real_time ()); } /** * messaging_menu_app_append_source: * @app: a #MessagingMenuApp * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * * Appends a new message source to the end of the section representing @app. * Equivalent to calling messaging_menu_app_append_source_with_time() with the * current time. * * It is an error to add a source with an @id which already exists. Use * messaging_menu_app_has_source() to find out whether there is such a source. */ void messaging_menu_app_append_source (MessagingMenuApp *app, const gchar *id, GIcon *icon, const gchar *label) { messaging_menu_app_insert_source (app, -1, id, icon, label); } /** * messaging_menu_app_insert_source_with_count: * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @count: the count for the source * * Inserts a new message source into the section representing @app and * initializes it with @count. * * To update the count, use messaging_menu_app_set_source_count(). * * It is an error to insert a source with an @id which already exists. Use * messaging_menu_app_has_source() to find out whether there is such a source. */ void messaging_menu_app_insert_source_with_count (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label, guint count) { messaging_menu_app_insert_source_internal (app, position, id, icon, label, count, 0, ""); } /** * messaging_menu_app_append_source_with_count: * @app: a #MessagingMenuApp * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @count: the count for the source * * Appends a new message source to the end of the section representing @app and * initializes it with @count. * * To update the count, use messaging_menu_app_set_source_count(). * * It is an error to add a source with an @id which already exists. Use * messaging_menu_app_has_source() to find out whether there is such a source. */ void messaging_menu_app_append_source_with_count (MessagingMenuApp *app, const gchar *id, GIcon *icon, const gchar *label, guint count) { messaging_menu_app_insert_source_with_count (app, -1, id, icon, label, count); } /** * messaging_menu_app_insert_source_with_time: * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @time: the time when the source was created, in microseconds * * Inserts a new message source into the section representing @app and * initializes it with @time. Use messaging_menu_app_insert_source() to * insert a source with the current time. * * To change the time, use messaging_menu_app_set_source_time(). * * It is an error to insert a source with an @id which already exists. Use * messaging_menu_app_has_source() to find out whether there is such a source. */ void messaging_menu_app_insert_source_with_time (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label, gint64 time) { messaging_menu_app_insert_source_internal (app, position, id, icon, label, 0, time, ""); } /** * messaging_menu_app_append_source_with_time: * @app: a #MessagingMenuApp * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @time: the time when the source was created, in microseconds * * Appends a new message source to the end of the section representing * @app and initializes it with @time. Use * messaging_menu_app_append_source() to append a source with the * current time. * * To change the time, use messaging_menu_app_set_source_time(). * * It is an error to insert a source with an @id which already exists. Use * messaging_menu_app_has_source() to find out whether there is such a source. */ void messaging_menu_app_append_source_with_time (MessagingMenuApp *app, const gchar *id, GIcon *icon, const gchar *label, gint64 time) { messaging_menu_app_insert_source_with_time (app, -1, id, icon, label, time); } /** * messaging_menu_app_insert_source_with_string: * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @str: a string associated with the source * * Inserts a new message source into the section representing @app and * initializes it with @str. * * To update the string, use messaging_menu_app_set_source_string(). * * It is an error to insert a source with an @id which already exists. Use * messaging_menu_app_has_source() to find out whether there is such a source. */ void messaging_menu_app_insert_source_with_string (MessagingMenuApp *app, gint position, const gchar *id, GIcon *icon, const gchar *label, const gchar *str) { messaging_menu_app_insert_source_internal (app, position, id, icon, label, 0, 0, str); } /** * messaging_menu_app_append_source_with_string: * @app: a #MessagingMenuApp * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @str: a string associated with the source * * Appends a new message source to the end of the section representing @app and * initializes it with @str. * * To update the string, use messaging_menu_app_set_source_string(). * * It is an error to insert a source with an @id which already exists. Use * messaging_menu_app_has_source() to find out whether there is such a source. */ void messaging_menu_app_append_source_with_string (MessagingMenuApp *app, const gchar *id, GIcon *icon, const gchar *label, const gchar *str) { messaging_menu_app_insert_source_with_string (app, -1, id, icon, label, str); } /** * messaging_menu_app_remove_source: * @app: a #MessagingMenuApp * @source_id: the id of the source to remove * * Removes the source corresponding to @source_id from the menu. */ void messaging_menu_app_remove_source (MessagingMenuApp *app, const gchar *source_id) { g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); if (messaging_menu_app_remove_source_internal (app, source_id)) indicator_messages_application_emit_source_removed (app->app_interface, source_id); } /** * messaging_menu_app_has_source: * @app: a #MessagingMenuApp * @source_id: a source id * * Returns: TRUE if there is a source associated with @source_id */ gboolean messaging_menu_app_has_source (MessagingMenuApp *app, const gchar *source_id) { g_return_val_if_fail (MESSAGING_MENU_IS_APP (app), FALSE); g_return_val_if_fail (source_id != NULL, FALSE); return messaging_menu_app_lookup_source (app, source_id) != NULL; } /** * messaging_menu_app_set_source_label: * @app: a #MessagingMenuApp * @source_id: a source id * @label: the new label for the source * * Changes the label of @source_id to @label. */ void messaging_menu_app_set_source_label (MessagingMenuApp *app, const gchar *source_id, const gchar *label) { Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); g_return_if_fail (label != NULL); source = messaging_menu_app_get_source (app, source_id); if (source) { g_free (source->label); source->label = g_strdup (label); messaging_menu_app_notify_source_changed (app, source); } } /** * messaging_menu_app_set_source_icon: * @app: a #MessagingMenuApp * @source_id: a source id * @icon: (allow-none): the new icon for the source * * Changes the icon of @source_id to @icon. */ void messaging_menu_app_set_source_icon (MessagingMenuApp *app, const gchar *source_id, GIcon *icon) { Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); source = messaging_menu_app_get_source (app, source_id); if (source) { g_clear_object (&source->icon); if (icon) source->icon = g_object_ref (icon); messaging_menu_app_notify_source_changed (app, source); } } /** * messaging_menu_app_set_source_count: * @app: a #MessagingMenuApp * @source_id: a source id * @count: the new count for the source * * Updates the count of @source_id to @count. */ void messaging_menu_app_set_source_count (MessagingMenuApp *app, const gchar *source_id, guint count) { Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); source = messaging_menu_app_get_source (app, source_id); if (source) { source->count = count; messaging_menu_app_notify_source_changed (app, source); } } /** * messaging_menu_app_set_source_time: * @app: a #MessagingMenuApp * @source_id: a source id * @time: the new time for the source, in microseconds * * Updates the time of @source_id to @time. */ void messaging_menu_app_set_source_time (MessagingMenuApp *app, const gchar *source_id, gint64 time) { Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); source = messaging_menu_app_get_source (app, source_id); if (source) { source->time = time; messaging_menu_app_notify_source_changed (app, source); } } /** * messaging_menu_app_set_source_string: * @app: a #MessagingMenuApp * @source_id: a source id * @str: the new string for the source * * Updates the string displayed next to @source_id to @str. */ void messaging_menu_app_set_source_string (MessagingMenuApp *app, const gchar *source_id, const gchar *str) { Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); source = messaging_menu_app_get_source (app, source_id); if (source) { g_free (source->string); source->string = g_strdup (str); messaging_menu_app_notify_source_changed (app, source); } } /** * messaging_menu_app_draw_attention: * @app: a #MessagingMenuApp * @source_id: a source id * * Indicates that @source_id has important unread messages. Currently, this * means that the messaging menu's envelope icon will turn blue. * * Use messaging_menu_app_remove_attention() to stop indicating that the source * needs attention. */ void messaging_menu_app_draw_attention (MessagingMenuApp *app, const gchar *source_id) { Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); source = messaging_menu_app_get_source (app, source_id); if (source) { source->draws_attention = TRUE; messaging_menu_app_notify_source_changed (app, source); } } /** * messaging_menu_app_remove_attention: * @app: a #MessagingMenuApp * @source_id: a source id * * Stop indicating that @source_id needs attention. * * This function does not need to be called when the source is removed * with messaging_menu_app_remove_source() or the user has activated the * source. * * Use messaging_menu_app_draw_attention() to make @source_id draw attention * again. */ void messaging_menu_app_remove_attention (MessagingMenuApp *app, const gchar *source_id) { Source *source; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (source_id != NULL); source = messaging_menu_app_get_source (app, source_id); if (source) { source->draws_attention = FALSE; messaging_menu_app_notify_source_changed (app, source); } } /** * messaging_menu_app_append_message: * @app: a #MessagingMenuApp * @msg: the #MessagingMenuMessage to append * @source_id: (allow-none): the source id to which @msg is added, or NULL * @notify: whether a notification bubble should be shown for this * message * * Appends @msg to the source with id @source_id of @app. The messaging * menu might not display this message immediately if other messages are * queued before this one. * * If @source_id has a count associated with it, that count will be * increased by one. * * If @source_id is %NULL, @msg won't be associated with a source. */ void messaging_menu_app_append_message (MessagingMenuApp *app, MessagingMenuMessage *msg, const gchar *source_id, gboolean notify) { const gchar *id; g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (MESSAGING_MENU_IS_MESSAGE (msg)); id = messaging_menu_message_get_id (msg); if (g_hash_table_lookup (app->messages, id)) { g_warning ("a message with id '%s' already exists", id); return; } g_hash_table_insert (app->messages, g_strdup (id), g_object_ref (msg)); indicator_messages_application_emit_message_added (app->app_interface, _messaging_menu_message_to_variant (msg)); if (source_id) { Source *source; source = messaging_menu_app_get_source (app, source_id); if (source && source->count >= 0) { source->count++; messaging_menu_app_notify_source_changed (app, source); } } } /** * messaging_menu_app_get_message: * @app: a #MessagingMenuApp * @id: id of the message to retrieve * * Retrieves the message with @id, that was added with * messaging_menu_app_append_message(). * * Returns: (transfer none) (allow-none): the #MessagingMenuApp with * @id, or %NULL */ MessagingMenuMessage * messaging_menu_app_get_message (MessagingMenuApp *app, const gchar *id) { g_return_val_if_fail (MESSAGING_MENU_IS_APP (app), NULL); g_return_val_if_fail (id != NULL, NULL); return g_hash_table_lookup (app->messages, id); } /** * messaging_menu_app_remove_message: * @app: a #MessagingMenuApp * @msg: the #MessagingMenuMessage to remove * * Removes @msg from @app. * * If @source_id has a count associated with it, that count will be * decreased by one. */ void messaging_menu_app_remove_message (MessagingMenuApp *app, MessagingMenuMessage *msg) { /* take a ref of @msg here to make sure the pointer returned by * _get_id() is valid for the duration of remove_message_by_id. */ g_object_ref (msg); messaging_menu_app_remove_message_by_id (app, messaging_menu_message_get_id (msg)); g_object_unref (msg); } /** * messaging_menu_app_remove_message_by_id: * @app: a #MessagingMenuApp * @id: the unique id of @msg * * Removes the message with the id @id from @app. * * If @source_id has a count associated with it, that count will be * decreased by one. */ void messaging_menu_app_remove_message_by_id (MessagingMenuApp *app, const gchar *id) { g_return_if_fail (MESSAGING_MENU_IS_APP (app)); g_return_if_fail (id != NULL); if (messaging_menu_app_remove_message_internal (app, id)) indicator_messages_application_emit_message_removed (app->app_interface, id); } ./libmessaging-menu/messaging-menu-message.c0000644000004100000410000004003313350212604021352 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #include "messaging-menu-message.h" /** * SECTION:messaging-menu-message * @title: MessagingMenuMessage * @short_description: A single message in the messaging menu * @include: messaging-menu.h */ typedef GObjectClass MessagingMenuMessageClass; struct _MessagingMenuMessage { GObject parent; gchar *id; GIcon *icon; gchar *title; gchar *subtitle; gchar *body; gint64 time; gboolean draws_attention; GSList *actions; }; G_DEFINE_TYPE (MessagingMenuMessage, messaging_menu_message, G_TYPE_OBJECT); enum { PROP_0, PROP_ID, PROP_ICON, PROP_TITLE, PROP_SUBTITLE, PROP_BODY, PROP_TIME, PROP_DRAWS_ATTENTION, NUM_PROPERTIES }; static GParamSpec *properties[NUM_PROPERTIES]; typedef struct { gchar *id; gchar *label; GVariantType *parameter_type; GVariant *parameter_hint; } Action; static void action_free (gpointer data) { Action *action = data; g_free (action->id); g_free (action->label); if (action->parameter_type) g_variant_type_free (action->parameter_type); if (action->parameter_hint) g_variant_unref (action->parameter_hint); g_slice_free (Action, action); } static void messaging_menu_message_dispose (GObject *object) { MessagingMenuMessage *msg = MESSAGING_MENU_MESSAGE (object); g_clear_object (&msg->icon); G_OBJECT_CLASS (messaging_menu_message_parent_class)->dispose (object); } static void messaging_menu_message_finalize (GObject *object) { MessagingMenuMessage *msg = MESSAGING_MENU_MESSAGE (object); g_free (msg->id); g_free (msg->title); g_free (msg->subtitle); g_free (msg->body); g_slist_free_full (msg->actions, action_free); msg->actions = NULL; G_OBJECT_CLASS (messaging_menu_message_parent_class)->finalize (object); } static void messaging_menu_message_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { MessagingMenuMessage *msg = MESSAGING_MENU_MESSAGE (object); switch (property_id) { case PROP_ID: g_value_set_string (value, msg->id); break; case PROP_ICON: g_value_set_object (value, msg->icon); break; case PROP_TITLE: g_value_set_string (value, msg->title); break; case PROP_SUBTITLE: g_value_set_string (value, msg->subtitle); break; case PROP_BODY: g_value_set_string (value, msg->body); break; case PROP_TIME: g_value_set_int64 (value, msg->time); break; case PROP_DRAWS_ATTENTION: g_value_set_boolean (value, msg->draws_attention); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } } static void messaging_menu_message_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { MessagingMenuMessage *msg = MESSAGING_MENU_MESSAGE (object); switch (property_id) { case PROP_ID: msg->id = g_value_dup_string (value); break; case PROP_ICON: msg->icon = g_value_dup_object (value); break; case PROP_TITLE: msg->title = g_value_dup_string (value); break; case PROP_SUBTITLE: msg->subtitle = g_value_dup_string (value); break; case PROP_BODY: msg->body = g_value_dup_string (value); break; case PROP_TIME: msg->time = g_value_get_int64 (value); break; case PROP_DRAWS_ATTENTION: messaging_menu_message_set_draws_attention (msg, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } } static void messaging_menu_message_class_init (MessagingMenuMessageClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = messaging_menu_message_dispose; object_class->finalize = messaging_menu_message_finalize; object_class->get_property = messaging_menu_message_get_property; object_class->set_property = messaging_menu_message_set_property; properties[PROP_ID] = g_param_spec_string ("id", "Id", "Unique id of the message", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_ICON] = g_param_spec_object ("icon", "Icon", "Icon of the message", G_TYPE_ICON, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_TITLE] = g_param_spec_string ("title", "Title", "Title of the message", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_SUBTITLE] = g_param_spec_string ("subtitle", "Subtitle", "Subtitle of the message", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_BODY] = g_param_spec_string ("body", "Body", "First lines of the body of the message", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_TIME] = g_param_spec_int64 ("time", "Time", "Time the message was sent, in microseconds", 0, G_MAXINT64, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); properties[PROP_DRAWS_ATTENTION] = g_param_spec_boolean ("draws-attention", "Draws attention", "Whether the message should draw attention", TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (klass, NUM_PROPERTIES, properties); /** * MessagingMenuMessage::activate: * @msg: the #MessagingMenuMessage * @action: (allow-none): the id of activated action, or %NULL * @parameter: (allow-none): activation parameter, or %NULL * * Emitted when the user has activated the message. The message is * immediately removed from the application's menu, handlers of this * signal do not need to call messaging_menu_app_remove_message(). */ g_signal_new ("activate", MESSAGING_MENU_TYPE_MESSAGE, G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED, 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VARIANT); } static void messaging_menu_message_init (MessagingMenuMessage *self) { self->draws_attention = TRUE; } /** * messaging_menu_message_new: * @id: unique id of the message * @icon: (transfer full) (allow-none): a #GIcon representing the message * @title: the title of the message * @subtitle: (allow-none): the subtitle of the message * @body: (allow-none): the message body * @time: the time the message was received * * Creates a new #MessagingMenuMessage. * * Returns: (transfer full): a new #MessagingMenuMessage */ MessagingMenuMessage * messaging_menu_message_new (const gchar *id, GIcon *icon, const gchar *title, const gchar *subtitle, const gchar *body, gint64 time) { g_return_val_if_fail (id != NULL, NULL); g_return_val_if_fail (title != NULL, NULL); return g_object_new (MESSAGING_MENU_TYPE_MESSAGE, "id", id, "icon", icon, "title", title, "subtitle", subtitle, "body", body, "time", time, NULL); } /** * messaging_menu_message_get_id: * @msg: a #MessagingMenuMessage * * Returns: the unique id of @msg */ const gchar * messaging_menu_message_get_id (MessagingMenuMessage *msg) { g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), NULL); return msg->id; } /** * messaging_menu_message_get_icon: * @msg: a #MessagingMenuMessage * * Returns: (transfer none): the icon of @msg */ GIcon * messaging_menu_message_get_icon (MessagingMenuMessage *msg) { g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), NULL); return msg->icon; } /** * messaging_menu_message_get_title: * @msg: a #MessagingMenuMessage * * Returns: the title of @msg */ const gchar * messaging_menu_message_get_title (MessagingMenuMessage *msg) { g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), NULL); return msg->title; } /** * messaging_menu_message_get_subtitle: * @msg: a #MessagingMenuMessage * * Returns: the subtitle of @msg */ const gchar * messaging_menu_message_get_subtitle (MessagingMenuMessage *msg) { g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), NULL); return msg->subtitle; } /** * messaging_menu_message_get_body: * @msg: a #MessagingMenuMessage * * Returns: the body of @msg */ const gchar * messaging_menu_message_get_body (MessagingMenuMessage *msg) { g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), NULL); return msg->body; } /** * messaging_menu_message_get_time: * @msg: a #MessagingMenuMessage * * Returns: the time at which @msg was received */ gint64 messaging_menu_message_get_time (MessagingMenuMessage *msg) { g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), 0); return msg->time; } /** * messaging_menu_message_get_draws_attention: * @msg: a #MessagingMenuMessage * * Returns: whether @msg is drawing attention */ gboolean messaging_menu_message_get_draws_attention (MessagingMenuMessage *msg) { g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), FALSE); return msg->draws_attention; } /** * messaging_menu_message_set_draws_attention: * @msg: a #MessagingMenuMessage * @draws_attention: whether @msg should draw attention * * Sets whether @msg is drawing attention. */ void messaging_menu_message_set_draws_attention (MessagingMenuMessage *msg, gboolean draws_attention) { g_return_if_fail (MESSAGING_MENU_IS_MESSAGE (msg)); msg->draws_attention = draws_attention; g_object_notify_by_pspec (G_OBJECT (msg), properties[PROP_DRAWS_ATTENTION]); } /** * messaging_menu_message_add_action: * @msg: a #MessagingMenuMessage * @id: unique id of the action * @label: (allow-none): label of the action * @parameter_type: (allow-none): a #GVariantType * @parameter_hint: (allow-none): a #GVariant suggesting a valid range * for parameters * * Adds an action with @id and @label to @message. Actions are an * alternative way for users to activate a message. Note that messages * can still be activated without an action. * * If @parameter_type is non-%NULL, the action is able to receive user * input in addition to simply activating the action. Currently, only * string parameters are supported. * * A list of predefined parameters can be supplied as a #GVariant array * of @parameter_type in @parameter_hint. If @parameter_hint is * floating, it will be consumed. * * It is recommended to add at most two actions to a message. */ void messaging_menu_message_add_action (MessagingMenuMessage *msg, const gchar *id, const gchar *label, const GVariantType *parameter_type, GVariant *parameter_hint) { Action *action; g_return_if_fail (MESSAGING_MENU_IS_MESSAGE (msg)); g_return_if_fail (id != NULL); action = g_slice_new (Action); action->id = g_strdup (id); action->label = g_strdup (label); action->parameter_type = parameter_type ? g_variant_type_copy (parameter_type) : NULL; action->parameter_hint = parameter_hint ? g_variant_ref_sink (parameter_hint) : NULL; msg->actions = g_slist_append (msg->actions, action); } static GVariant * action_to_variant (Action *action) { GVariantBuilder builder; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (action->id)); if (action->label) g_variant_builder_add (&builder, "{sv}", "label", g_variant_new_string (action->label)); if (action->parameter_type) { gchar *type = g_variant_type_dup_string (action->parameter_type); g_variant_builder_add (&builder, "{sv}", "parameter-type", g_variant_new_signature (type)); g_free (type); } if (action->parameter_hint) g_variant_builder_add (&builder, "{sv}", "parameter-hint", action->parameter_hint); return g_variant_builder_end (&builder); } /* * _messaging_menu_message_to_variant: * @msg: a #MessagingMenuMessage * * Serializes @msg to a #GVariant of the form (savsssxaa{sv}b): * * id * icon (fake-maybe) * title * subtitle * body * time * array of action dictionaries * draws_attention * * Returns: a new floating #GVariant instance */ GVariant * _messaging_menu_message_to_variant (MessagingMenuMessage *msg) { GVariantBuilder builder; GSList *it; GVariant *serialized_icon; GVariantBuilder icon_builder; g_return_val_if_fail (MESSAGING_MENU_IS_MESSAGE (msg), NULL); serialized_icon = msg->icon ? g_icon_serialize (msg->icon) : NULL; g_variant_builder_init (&icon_builder, G_VARIANT_TYPE ("av")); if (serialized_icon) { g_variant_builder_add (&icon_builder, "v", serialized_icon); g_variant_unref (serialized_icon); } g_variant_builder_init (&builder, G_VARIANT_TYPE ("(savsssxaa{sv}b)")); g_variant_builder_add (&builder, "s", msg->id); g_variant_builder_add (&builder, "av", &icon_builder); g_variant_builder_add (&builder, "s", msg->title ? msg->title : ""); g_variant_builder_add (&builder, "s", msg->subtitle ? msg->subtitle : ""); g_variant_builder_add (&builder, "s", msg->body ? msg->body : ""); g_variant_builder_add (&builder, "x", msg->time); g_variant_builder_open (&builder, G_VARIANT_TYPE ("aa{sv}")); for (it = msg->actions; it; it = it->next) g_variant_builder_add_value (&builder, action_to_variant (it->data)); g_variant_builder_close (&builder); g_variant_builder_add (&builder, "b", msg->draws_attention); return g_variant_builder_end (&builder); } ./libmessaging-menu/messaging-menu.h0000644000004100000410000000146613350212604017744 0ustar www-datawww-data/* * Copyright 2012 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Lars Uebernickel */ #ifndef __messaging_menu_h__ #define __messaging_menu_h__ #include "messaging-menu-app.h" #endif ./libmessaging-menu/Makefile.am0000644000004100000410000000350713350212604016706 0ustar www-datawww-data lib_LTLIBRARIES = libmessaging-menu.la libmessaging_menu_ladir = $(includedir)/messaging-menu libmessaging_menu_la_SOURCES = \ messaging-menu-app.c \ messaging-menu-message.c libmessaging_menu_la_HEADERS = \ messaging-menu-app.h \ messaging-menu.h \ messaging-menu-message.h libmessaging_menu_la_LIBADD = \ $(GIO_LIBS) \ $(top_builddir)/common/libmessaging-common.la libmessaging_menu_la_CFLAGS = \ -I$(top_builddir)/common \ $(GIO_CFLAGS) \ -Wall libmessaging_menu_la_LDFLAGS = -export-symbols-regex "^messaging_menu_.*" pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = messaging-menu.pc -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) --warn-all INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) if HAVE_INTROSPECTION MessagingMenu-1.0.gir: libmessaging-menu.la MessagingMenu_1_0_gir_NAMESPACE = MessagingMenu MessagingMenu_1_0_gir_INCLUDES = GObject-2.0 Gio-2.0 MessagingMenu_1_0_gir_CFLAGS = $(INCLUDES) $(GIO_CFLAGS) MessagingMenu_1_0_gir_SCANNERFLAGS = --c-include="messaging-menu.h" MessagingMenu_1_0_gir_LIBS = libmessaging-menu.la MessagingMenu_1_0_gir_FILES = \ messaging-menu-app.c \ messaging-menu-app.h \ messaging-menu-message.c \ messaging-menu-message.h MessagingMenu_1_0_gir_EXPORT_PACKAGES = messaging-menu INTROSPECTION_GIRS += MessagingMenu-1.0.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) typelibdir = $(libdir)/girepository-1.0 typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) CLEANFILES = $(gir_DATA) $(typelib_DATA) ######################### # VAPI Files ######################### if HAVE_VALA vapidir = $(datadir)/vala/vapi vapi_DATA = MessagingMenu-1.0.vapi MessagingMenu-1.0.vapi: MessagingMenu-1.0.gir $(VALA_API_GEN) --pkg gio-2.0 --library=MessagingMenu-1.0 $< CLEANFILES += $(vapi_DATA) endif endif ./ChangeLog0000644000004100000410000000003113350212604013003 0ustar www-datawww-data# Generated by Makefile ./MERGE-REVIEW0000644000004100000410000000142013350212604013015 0ustar www-datawww-data This documents the expections that the project has on what both submitters and reviewers should ensure that they've done for a merge into the project. == Submitter Responsibilities == * Ensure the project compiles and the test suite executes without error * Ensure that non-obvious code has comments explaining it * If the change works on specific profiles, please include those in the merge description. == Reviewer Responsibilities == * Did the Jenkins build compile? Pass? Run unit tests successfully? * Are there appropriate tests to cover any new functionality? * If the description says this effects the phone profile: * Run tests indicator-messages/unity8* * If the description says this effects the desktop profile: * Run tests indicator-messages/unity7* ./Makefile.am.coverage0000644000004100000410000000250513350212604015067 0ustar www-datawww-data # Coverage targets .PHONY: clean-gcno clean-gcda \ coverage-html generate-coverage-html clean-coverage-html \ coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr if HAVE_GCOV clean-gcno: @echo Removing old coverage instrumentation -find -name '*.gcno' -print | xargs -r rm clean-gcda: @echo Removing old coverage results -find -name '*.gcda' -print | xargs -r rm coverage-html: clean-gcda -$(MAKE) $(AM_MAKEFLAGS) -k check $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html generate-coverage-html: @echo Collecting coverage data $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info clean-coverage-html: clean-gcda -$(LCOV) --directory $(top_builddir) -z -rm -rf coverage.info coveragereport if HAVE_GCOVR coverage-gcovr: clean-gcda -$(MAKE) $(AM_MAKEFLAGS) -k check $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr generate-coverage-gcovr: @echo Generating coverage GCOVR report $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml clean-coverage-gcovr: clean-gcda -rm -rf $(top_builddir)/coverage.xml endif # HAVE_GCOVR endif # HAVE_GCOV ./tests/0000755000004100000410000000000013350212612012400 5ustar www-datawww-data./tests/test-client.py0000755000004100000410000000615613350212604015221 0ustar www-datawww-data#!/usr/bin/env python3 import unittest import dbus from dbus.mainloop.glib import DBusGMainLoop import dbusmock import subprocess from gi.repository import GLib, Gio, MessagingMenu DBusGMainLoop(set_as_default=True) class MessagingMenuTest(dbusmock.DBusTestCase): @classmethod def setUpClass(klass): klass.start_session_bus() klass.bus = klass.get_dbus(False) def setUp(self): name = 'com.canonical.indicator.messages' obj_path = '/com/canonical/indicator/messages/service' iface = 'com.canonical.indicator.messages.service' self.messaging_service = self.spawn_server(name, obj_path, iface, stdout=subprocess.PIPE) self.mock = dbus.Interface(self.bus.get_object(name, obj_path), dbusmock.MOCK_IFACE) self.mock.AddMethod('', 'RegisterApplication', 'so', '', '') self.mock.AddMethod('', 'UnregisterApplication', 's', '', '') self.mock.AddMethod('', 'ApplicationStoppedRunning', 's', '', '') self.mock.AddMethod('', 'SetStatus', 'ss', '', '') self.loop = GLib.MainLoop() def tearDown(self): self.messaging_service.terminate() self.messaging_service.wait() def assertArgumentsEqual(self, args, *expected_args): self.assertEqual(len(args), len(expected_args)) for i in range(len(args)): if expected_args[i]: self.assertEqual(args[i], expected_args[i]) def assertMethodCalled(self, name, *expected_args): # set a flag on timeout, assertions don't get bubbled up through c functions self.timed_out = False def timeout(): self.timed_out = True timeout_id = GLib.timeout_add_seconds(10, timeout) while 1: calls = self.mock.GetMethodCalls(name) if len(calls) > 0: GLib.source_remove(timeout_id) self.assertArgumentsEqual(calls[0][1], *expected_args) break GLib.MainContext.default().iteration(True) if self.timed_out: raise self.failureException('method %s was not called after 10 seconds' % name) def test_registration(self): mmapp = MessagingMenu.App.new('test.desktop') mmapp.register() self.assertMethodCalled('RegisterApplication', 'test.desktop', None) mmapp.unregister() self.assertMethodCalled('UnregisterApplication', 'test.desktop') # ApplicationStoppedRunning is called when the last ref on mmapp is dropped # Since mmapp is the only thing holding on to a GDBusConnection, the # connection might get freed before it sends the StoppedRunning # message. Flush the connection to make sure it is sent. bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) bus.flush_sync(None) del mmapp self.assertMethodCalled('ApplicationStoppedRunning', 'test.desktop') def test_status(self): mmapp = MessagingMenu.App.new('test.desktop') mmapp.register() mmapp.set_status(MessagingMenu.Status.AWAY) self.assertMethodCalled('SetStatus', 'test.desktop', 'away') unittest.main(testRunner=unittest.TextTestRunner()) ./tests/indicator-messages-service-activate.build.sh0000644000004100000410000000021413350212604023045 0ustar www-datawww-data#!/bin/sh gcc -o indicator-messages-service-activate indicator-messages-service-activate.c `pkg-config --cflags --libs dbus-1 dbus-glib-1` ./tests/accounts-service-mock.h0000644000004100000410000001241613350212604016762 0ustar www-datawww-data/* * Copyright © 2014 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * This program 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 for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: * Ted Gould */ #include #include class AccountsServiceMock { DbusTestDbusMock * mock = nullptr; DbusTestDbusMockObject * soundobj = nullptr; DbusTestDbusMockObject * userobj = nullptr; DbusTestDbusMockObject * dmobj = nullptr; DbusTestDbusMockObject * syssoundobj = nullptr; DbusTestDbusMockObject * privacyobj = nullptr; public: AccountsServiceMock () { mock = dbus_test_dbus_mock_new("org.freedesktop.Accounts"); dbus_test_task_set_bus(DBUS_TEST_TASK(mock), DBUS_TEST_SERVICE_BUS_SYSTEM); DbusTestDbusMockObject * baseobj = dbus_test_dbus_mock_get_object(mock, "/org/freedesktop/Accounts", "org.freedesktop.Accounts", NULL); dbus_test_dbus_mock_object_add_method(mock, baseobj, "CacheUser", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH, "ret = dbus.ObjectPath('/user')\n", NULL); dbus_test_dbus_mock_object_add_method(mock, baseobj, "FindUserById", G_VARIANT_TYPE_INT64, G_VARIANT_TYPE_OBJECT_PATH, "ret = dbus.ObjectPath('/user')\n", NULL); dbus_test_dbus_mock_object_add_method(mock, baseobj, "FindUserByName", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH, "ret = dbus.ObjectPath('/user')\n", NULL); dbus_test_dbus_mock_object_add_method(mock, baseobj, "ListCachedUsers", NULL, G_VARIANT_TYPE_OBJECT_PATH_ARRAY, "ret = [ dbus.ObjectPath('/user') ]\n", NULL); dbus_test_dbus_mock_object_add_method(mock, baseobj, "UncacheUser", G_VARIANT_TYPE_STRING, NULL, "", NULL); userobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.Accounts.User", NULL); dbus_test_dbus_mock_object_add_property(mock, userobj, "UserName", G_VARIANT_TYPE_STRING, g_variant_new_string(g_get_user_name()), NULL); dmobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.DisplayManager.AccountsService", NULL); dbus_test_dbus_mock_object_add_property(mock, dmobj, "HasMesages", G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(FALSE), NULL); soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "Timestamp", G_VARIANT_TYPE_UINT64, g_variant_new_uint64(0), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "PlayerName", G_VARIANT_TYPE_STRING, g_variant_new_string(""), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "PlayerIcon", G_VARIANT_TYPE_VARIANT, g_variant_new_variant(g_variant_new_string("")), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "Running", G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(FALSE), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "State", G_VARIANT_TYPE_STRING, g_variant_new_string(""), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "Title", G_VARIANT_TYPE_STRING, g_variant_new_string(""), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "Artist", G_VARIANT_TYPE_STRING, g_variant_new_string(""), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "Album", G_VARIANT_TYPE_STRING, g_variant_new_string(""), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "ArtUrl", G_VARIANT_TYPE_STRING, g_variant_new_string(""), NULL); syssoundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.ubuntu.touch.AccountsService.Sound", NULL); dbus_test_dbus_mock_object_add_property(mock, syssoundobj, "SilentMode", G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(FALSE), NULL); privacyobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.ubuntu.touch.AccountsService.SecurityPrivacy", NULL); dbus_test_dbus_mock_object_add_property(mock, privacyobj, "MessagesWelcomeScreen", G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(true), NULL); dbus_test_dbus_mock_object_add_property(mock, privacyobj, "StatsWelcomeScreen", G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(true), NULL); } ~AccountsServiceMock () { g_debug("Destroying the Accounts Service Mock"); g_clear_object(&mock); } void setSilentMode (bool modeValue) { dbus_test_dbus_mock_object_update_property(mock, syssoundobj, "SilentMode", g_variant_new_boolean(modeValue ? TRUE : FALSE), NULL); } operator std::shared_ptr () { return std::shared_ptr( DBUS_TEST_TASK(g_object_ref(mock)), [](DbusTestTask * task) { g_clear_object(&task); }); } operator DbusTestTask* () { return DBUS_TEST_TASK(mock); } operator DbusTestDbusMock* () { return mock; } DbusTestDbusMockObject * get_sound () { return soundobj; } }; ./tests/indicator-fixture.h0000644000004100000410000005702113350212604016217 0ustar www-datawww-data/* * Copyright © 2014 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * This program 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 for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include #include #include #include #include class IndicatorFixture : public ::testing::Test { private: std::string _indicatorPath; std::string _indicatorAddress; std::vector> _mocks; protected: std::chrono::milliseconds _eventuallyTime; private: class PerRunData { public: /* We're private in the fixture but other than that we don't care, we don't leak out. This object's purpose isn't to hide data it is to make the lifecycle of the items more clear. */ std::shared_ptr _menu; std::shared_ptr _actions; DbusTestService * _session_service; DbusTestService * _system_service; DbusTestTask * _test_indicator; DbusTestTask * _test_dummy; GDBusConnection * _session; GDBusConnection * _system; PerRunData (const std::string& indicatorPath, const std::string& indicatorAddress, std::vector>& mocks) : _menu(nullptr) , _session(nullptr) { _session_service = dbus_test_service_new(nullptr); dbus_test_service_set_bus(_session_service, DBUS_TEST_SERVICE_BUS_SESSION); _system_service = dbus_test_service_new(nullptr); dbus_test_service_set_bus(_system_service, DBUS_TEST_SERVICE_BUS_SYSTEM); _test_indicator = DBUS_TEST_TASK(dbus_test_process_new(indicatorPath.c_str())); dbus_test_task_set_name(_test_indicator, "Indicator"); dbus_test_service_add_task(_session_service, _test_indicator); _test_dummy = dbus_test_task_new(); dbus_test_task_set_wait_for(_test_dummy, indicatorAddress.c_str()); dbus_test_task_set_name(_test_dummy, "Dummy"); dbus_test_service_add_task(_session_service, _test_dummy); for(auto task : mocks) { if (dbus_test_task_get_bus(task.get()) == DBUS_TEST_SERVICE_BUS_SYSTEM) { dbus_test_service_add_task(_system_service, task.get()); } else { dbus_test_service_add_task(_session_service, task.get()); } } g_debug("Starting System Bus"); dbus_test_service_start_tasks(_system_service); _system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr); g_dbus_connection_set_exit_on_close(_system, FALSE); g_debug("Starting Session Bus"); dbus_test_service_start_tasks(_session_service); _session = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); g_dbus_connection_set_exit_on_close(_session, FALSE); } virtual ~PerRunData (void) { _menu.reset(); _actions.reset(); /* D-Bus Test Stuff */ g_clear_object(&_test_dummy); g_clear_object(&_test_indicator); g_clear_object(&_session_service); g_clear_object(&_system_service); /* Wait for D-Bus session bus to go */ if (!g_dbus_connection_is_closed(_session)) { g_dbus_connection_close_sync(_session, nullptr, nullptr); } g_clear_object(&_session); if (!g_dbus_connection_is_closed(_system)) { g_dbus_connection_close_sync(_system, nullptr, nullptr); } g_clear_object(&_system); } }; std::shared_ptr run; public: virtual ~IndicatorFixture() = default; IndicatorFixture (const std::string& path, const std::string& addr) : _indicatorPath(path) , _indicatorAddress(addr) , _eventuallyTime(std::chrono::seconds(5)) { }; protected: virtual void SetUp() override { run = std::make_shared(_indicatorPath, _indicatorAddress, _mocks); _mocks.clear(); } virtual void TearDown() override { run.reset(); } void addMock (std::shared_ptr mock) { _mocks.push_back(mock); } std::shared_ptr buildBustleMock (const std::string& filename, DbusTestServiceBus bus = DBUS_TEST_SERVICE_BUS_BOTH) { return std::shared_ptr([filename, bus]() { DbusTestTask * bustle = DBUS_TEST_TASK(dbus_test_bustle_new(filename.c_str())); dbus_test_task_set_name(bustle, "Bustle"); dbus_test_task_set_bus(bustle, bus); return bustle; }(), [](DbusTestTask * bustle) { g_clear_object(&bustle); }); } private: void waitForCore (GObject * obj, const gchar * signalname) { auto loop = g_main_loop_new(nullptr, FALSE); /* Our two exit criteria */ gulong signal = g_signal_connect_swapped(obj, signalname, G_CALLBACK(g_main_loop_quit), loop); guint timer = g_timeout_add_seconds(5, [](gpointer user_data) -> gboolean { g_warning("Menu Timeout"); g_main_loop_quit((GMainLoop *)user_data); return G_SOURCE_CONTINUE; }, loop); /* Wait for sync */ g_main_loop_run(loop); /* Clean up */ g_source_remove(timer); g_signal_handler_disconnect(obj, signal); g_main_loop_unref(loop); } void menuWaitForItems (const std::shared_ptr& menu) { auto count = g_menu_model_get_n_items(menu.get()); if (count != 0) return; waitForCore(G_OBJECT(menu.get()), "items-changed"); } void agWaitForActions (const std::shared_ptr& group) { auto list = std::shared_ptr( g_action_group_list_actions(group.get()), [](gchar ** list) { g_strfreev(list); }); if (g_strv_length(list.get()) != 0) { return; } waitForCore(G_OBJECT(group.get()), "action-added"); } testing::AssertionResult expectEventually (std::function &testfunc) { auto loop = std::shared_ptr(g_main_loop_new(nullptr, FALSE), [](GMainLoop * loop) { if (loop != nullptr) g_main_loop_unref(loop); }); std::promise retpromise; auto retfuture = retpromise.get_future(); auto start = std::chrono::steady_clock::now(); /* The core of the idle function as an object so we can use the C++-isms of attaching the variables and make this code reasonably readable */ std::function idlefunc = [&loop, &retpromise, &testfunc, &start, this]() -> void { auto result = testfunc(); if (result == false && _eventuallyTime > (std::chrono::steady_clock::now() - start)) { return; } retpromise.set_value(result); g_main_loop_quit(loop.get()); }; auto idlesrc = g_idle_add([](gpointer data) -> gboolean { auto func = reinterpret_cast *>(data); (*func)(); return G_SOURCE_CONTINUE; }, &idlefunc); g_main_loop_run(loop.get()); g_source_remove(idlesrc); return retfuture.get(); } protected: void setMenu (const std::string& path) { run->_menu.reset(); g_debug("Getting Menu: %s:%s", _indicatorAddress.c_str(), path.c_str()); run->_menu = std::shared_ptr(G_MENU_MODEL(g_dbus_menu_model_get(run->_session, _indicatorAddress.c_str(), path.c_str())), [](GMenuModel * modelptr) { g_clear_object(&modelptr); }); menuWaitForItems(run->_menu); } void setActions (const std::string& path) { run->_actions.reset(); run->_actions = std::shared_ptr(G_ACTION_GROUP(g_dbus_action_group_get(run->_session, _indicatorAddress.c_str(), path.c_str())), [](GActionGroup * groupptr) { g_clear_object(&groupptr); }); agWaitForActions(run->_actions); } void activateAction (const std::string &name, std::shared_ptr ¶meter) { g_action_group_activate_action(run->_actions.get(), name.c_str(), parameter.get()); } void activateAction (const std::string &name, GVariant * parameter = nullptr) { std::shared_ptr param; if (parameter != nullptr) param = std::shared_ptr(g_variant_ref_sink(parameter), [](GVariant * var) { g_variant_unref(var); }); return activateAction(name, param); } testing::AssertionResult expectActionExists (const gchar * nameStr, const std::string& name) { bool hasit = g_action_group_has_action(run->_actions.get(), name.c_str()); if (!hasit) { auto result = testing::AssertionFailure(); result << " Action: " << nameStr << std::endl << " Expected: " << "Exists" << std::endl << " Actual: " << "No action found" << std::endl; return result; } auto result = testing::AssertionSuccess(); return result; } template testing::AssertionResult expectEventuallyActionExists (Args&& ... args) { std::function func = [&]() { return expectActionExists(std::forward(args)...); }; return expectEventually(func); } testing::AssertionResult expectActionDoesNotExist (const gchar * nameStr, const std::string& name) { bool hasit = g_action_group_has_action(run->_actions.get(), name.c_str()); if (hasit) { auto result = testing::AssertionFailure(); result << " Action: " << nameStr << std::endl << " Expected: " << "No action found" << std::endl << " Actual: " << "Exists" << std::endl; return result; } auto result = testing::AssertionSuccess(); return result; } template testing::AssertionResult expectEventuallyActionDoesNotExist (Args&& ... args) { std::function func = [&]() { return expectActionDoesNotExist(std::forward(args)...); }; return expectEventually(func); } testing::AssertionResult expectActionEnabled (const char * nameStr, const char * typeStr, const std::string& name, bool enabled) { auto aenabled = g_action_group_get_action_enabled(run->_actions.get(), name.c_str()); if (enabled != aenabled) { auto result = testing::AssertionFailure(); result << " Action: " << nameStr << std::endl << " Expected: " << enabled << std::endl << " Actual: " << aenabled << std::endl; return result; } auto result = testing::AssertionSuccess(); return result; } template testing::AssertionResult expectEventuallyActionEnabled (Args&& ... args) { std::function func = [&]() { return expectActionEnabled(std::forward(args)...); }; return expectEventually(func); } testing::AssertionResult expectActionStateType (const char * nameStr, const char * typeStr, const std::string& name, const GVariantType * type) { auto atype = g_action_group_get_action_state_type(run->_actions.get(), name.c_str()); bool same = false; if (atype != nullptr) { same = g_variant_type_equal(atype, type); } if (!same) { auto result = testing::AssertionFailure(); result << " Action: " << nameStr << std::endl << " Expected: " << typeStr << std::endl << " Actual: " << (atype == nullptr ? "(null)" : g_variant_type_peek_string(atype)) << std::endl; return result; } auto result = testing::AssertionSuccess(); return result; } template testing::AssertionResult expectEventuallyActionStateType (Args&& ... args) { std::function func = [&]() { return expectActionStateType(std::forward(args)...); }; return expectEventually(func); } testing::AssertionResult expectActionActivationType (const char * nameStr, const char * typeStr, const std::string& name, const GVariantType * type) { auto atype = g_action_group_get_action_parameter_type(run->_actions.get(), name.c_str()); bool same = false; if (atype != nullptr) { same = g_variant_type_equal(atype, type); } if (!same) { auto result = testing::AssertionFailure(); result << " Action: " << nameStr << std::endl << " Expected: " << typeStr << std::endl << " Actual: " << (atype == nullptr ? "(null)" : g_variant_type_peek_string(atype)) << std::endl; return result; } auto result = testing::AssertionSuccess(); return result; } template testing::AssertionResult expectEventuallyActionActivationType (Args&& ... args) { std::function func = [&]() { return expectActionActivationType(std::forward(args)...); }; return expectEventually(func); } testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, std::shared_ptr varref) { auto aval = std::shared_ptr(g_action_group_get_action_state(run->_actions.get(), name.c_str()), [] (GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); }); bool match = false; if (aval != nullptr) { match = g_variant_equal(aval.get(), varref.get()); } if (!match) { gchar * attstr = nullptr; if (aval != nullptr) { attstr = g_variant_print(aval.get(), TRUE); } else { attstr = g_strdup("nullptr"); } auto result = testing::AssertionFailure(); result << " Action: " << nameStr << std::endl << " Expected: " << valueStr << std::endl << " Actual: " << attstr << std::endl; g_free(attstr); return result; } else { auto result = testing::AssertionSuccess(); return result; } } testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, GVariant * value) { auto varref = std::shared_ptr(g_variant_ref_sink(value), [](GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); }); return expectActionStateIs(nameStr, valueStr, name, varref); } testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, bool value) { GVariant * var = g_variant_new_boolean(value); return expectActionStateIs(nameStr, valueStr, name, var); } testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, std::string value) { GVariant * var = g_variant_new_string(value.c_str()); return expectActionStateIs(nameStr, valueStr, name, var); } testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, const char * value) { GVariant * var = g_variant_new_string(value); return expectActionStateIs(nameStr, valueStr, name, var); } testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, double value) { GVariant * var = g_variant_new_double(value); return expectActionStateIs(nameStr, valueStr, name, var); } testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, float value) { GVariant * var = g_variant_new_double(value); return expectActionStateIs(nameStr, valueStr, name, var); } template testing::AssertionResult expectEventuallyActionStateIs (Args&& ... args) { std::function func = [&]() { return expectActionStateIs(std::forward(args)...); }; return expectEventually(func); } private: std::shared_ptr getMenuAttributeVal (int location, std::shared_ptr& menu, const std::string& attribute, std::shared_ptr& value) { if (!(location < g_menu_model_get_n_items(menu.get()))) { return nullptr; } if (location >= g_menu_model_get_n_items(menu.get())) return nullptr; auto menuval = std::shared_ptr(g_menu_model_get_item_attribute_value(menu.get(), location, attribute.c_str(), g_variant_get_type(value.get())), [](GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); }); return menuval; } std::shared_ptr getMenuAttributeRecurse (std::vector::const_iterator menuLocation, std::vector::const_iterator menuEnd, const std::string& attribute, std::shared_ptr& value, std::shared_ptr& menu) { if (menuLocation == menuEnd) return nullptr; if (menuLocation + 1 == menuEnd) return getMenuAttributeVal(*menuLocation, menu, attribute, value); auto clearfunc = [](GMenuModel * modelptr) { g_clear_object(&modelptr); }; auto submenu = std::shared_ptr(g_menu_model_get_item_link(menu.get(), *menuLocation, G_MENU_LINK_SUBMENU), clearfunc); if (submenu == nullptr) submenu = std::shared_ptr(g_menu_model_get_item_link(menu.get(), *menuLocation, G_MENU_LINK_SECTION), clearfunc); if (submenu == nullptr) return nullptr; menuWaitForItems(submenu); return getMenuAttributeRecurse(menuLocation + 1, menuEnd, attribute, value, submenu); } protected: testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const char * attributeStr, const char * valueStr, const std::vector menuLocation, const std::string& attribute, GVariant * value) { auto varref = std::shared_ptr(g_variant_ref_sink(value), [](GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); }); auto attrib = getMenuAttributeRecurse(menuLocation.cbegin(), menuLocation.cend(), attribute, varref, run->_menu); bool same = false; if (attrib != nullptr && varref != nullptr) { same = g_variant_equal(attrib.get(), varref.get()); } if (!same) { gchar * attstr = nullptr; if (attrib != nullptr) { attstr = g_variant_print(attrib.get(), TRUE); } else { attstr = g_strdup("nullptr"); } auto result = testing::AssertionFailure(); result << " Menu: " << menuLocationStr << std::endl << " Attribute: " << attributeStr << std::endl << " Expected: " << valueStr << std::endl << " Actual: " << attstr << std::endl; g_free(attstr); return result; } else { auto result = testing::AssertionSuccess(); return result; } } testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const char * attributeStr, const char * valueStr, const std::vector menuLocation, const std::string& attribute, bool value) { GVariant * var = g_variant_new_boolean(value); return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var); } testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const char * attributeStr, const char * valueStr, const std::vector menuLocation, const std::string& attribute, std::string value) { GVariant * var = g_variant_new_string(value.c_str()); return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var); } testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const char * attributeStr, const char * valueStr, const std::vector menuLocation, const std::string& attribute, const char * value) { GVariant * var = g_variant_new_string(value); return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var); } template testing::AssertionResult expectEventuallyMenuAttribute (Args&& ... args) { std::function func = [&]() { return expectMenuAttribute(std::forward(args)...); }; return expectEventually(func); } /* Eventually Helpers */ #define _EVENTUALLY_HELPER(oper) \ template testing::AssertionResult expectEventually##oper (Args&& ... args) { \ std::function func = [&]() { \ return testing::internal::CmpHelper##oper(std::forward(args)...); \ }; \ return expectEventually(func); \ } _EVENTUALLY_HELPER(EQ); _EVENTUALLY_HELPER(NE); _EVENTUALLY_HELPER(LT); _EVENTUALLY_HELPER(GT); _EVENTUALLY_HELPER(STREQ); _EVENTUALLY_HELPER(STRNE); #undef _EVENTUALLY_HELPER }; /* Menu Attrib */ #define ASSERT_MENU_ATTRIB(menu, attrib, value) \ ASSERT_PRED_FORMAT3(IndicatorFixture::expectMenuAttribute, menu, attrib, value) #define EXPECT_MENU_ATTRIB(menu, attrib, value) \ EXPECT_PRED_FORMAT3(IndicatorFixture::expectMenuAttribute, menu, attrib, value) #define EXPECT_EVENTUALLY_MENU_ATTRIB(menu, attrib, value) \ EXPECT_PRED_FORMAT3(IndicatorFixture::expectEventuallyMenuAttribute, menu, attrib, value) /* Action Exists */ #define ASSERT_ACTION_EXISTS(action) \ ASSERT_PRED_FORMAT1(IndicatorFixture::expectActionExists, action) #define EXPECT_ACTION_EXISTS(action) \ EXPECT_PRED_FORMAT1(IndicatorFixture::expectActionExists, action) #define EXPECT_EVENTUALLY_ACTION_EXISTS(action) \ EXPECT_PRED_FORMAT1(IndicatorFixture::expectEventuallyActionExists, action) /* Action Does Not Exist */ #define ASSERT_ACTION_DOES_NOT_EXIST(action) \ ASSERT_PRED_FORMAT1(IndicatorFixture::expectActionDoesNotExist, action) #define EXPECT_ACTION_DOES_NOT_EXIST(action) \ EXPECT_PRED_FORMAT1(IndicatorFixture::expectActionDoesNotExist, action) #define EXPECT_EVENTUALLY_ACTION_DOES_NOT_EXIST(action) \ EXPECT_PRED_FORMAT1(IndicatorFixture::expectEventuallyActionDoesNotExist, action) /* Action Enabled */ #define ASSERT_ACTION_ENABLED(action, state) \ ASSERT_PRED_FORMAT2(IndicatorFixture::expectActionEnabled, action, state) #define EXPECT_ACTION_ENABLED(action, state) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectActionEnabled, action, state) #define EXPECT_EVENTUALLY_ACTION_ENABLED(action, state) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallyActionEnabled, action, state) /* Action State */ #define ASSERT_ACTION_STATE(action, value) \ ASSERT_PRED_FORMAT2(IndicatorFixture::expectActionStateIs, action, value) #define EXPECT_ACTION_STATE(action, value) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectActionStateIs, action, value) #define EXPECT_EVENTUALLY_ACTION_STATE(action, value) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallyActionStateIs, action, value) /* Action State Type */ #define ASSERT_ACTION_STATE_TYPE(action, type) \ ASSERT_PRED_FORMAT2(IndicatorFixture::expectActionStateType, action, type) #define EXPECT_ACTION_STATE_TYPE(action, type) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectActionStateType, action, type) #define EXPECT_EVENTUALLY_ACTION_STATE_TYPE(action, type) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallyActionStateType, action, type) /* Action Activation Type */ #define ASSERT_ACTION_ACTIVATION_TYPE(action, type) \ ASSERT_PRED_FORMAT2(IndicatorFixture::expectActionActivationType, action, type) #define EXPECT_ACTION_ACTIVATION_TYPE(action, type) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectActionActivationType, action, type) #define EXPECT_EVENTUALLY_ACTION_ACTIVATION_TYPE(action, type) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallyActionActivationType, action, type) /* Helpers */ #define EXPECT_EVENTUALLY_EQ(expected, actual) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallyEQ, expected, actual) #define EXPECT_EVENTUALLY_NE(expected, actual) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallyNE, expected, actual) #define EXPECT_EVENTUALLY_LT(expected, actual) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallyLT, expected, actual) #define EXPECT_EVENTUALLY_GT(expected, actual) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallyGT, expected, actual) #define EXPECT_EVENTUALLY_STREQ(expected, actual) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallySTREQ, expected, actual) #define EXPECT_EVENTUALLY_STRNE(expected, actual) \ EXPECT_PRED_FORMAT2(IndicatorFixture::expectEventuallySTRNE, expected, actual) ./tests/indicator-messages-service-activate.c0000644000004100000410000000336413350212604021570 0ustar www-datawww-data/* An indicator to show information that is in messaging applications that the user is using. Copyright 2009 Canonical Ltd. Authors: Ted Gould This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include "../src/dbus-data.h" int main (int argc, char ** argv) { #if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init(); #endif guint returnval = 0; GError * error = NULL; DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); DBusGProxy * proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); g_debug("Activating service: %s", INDICATOR_MESSAGES_DBUS_NAME); if (!org_freedesktop_DBus_start_service_by_name (proxy, INDICATOR_MESSAGES_DBUS_NAME, 0, &returnval, &error)) { g_error("Unable to send message to DBus to start service: %s", error != NULL ? error->message : "(NULL error)" ); g_error_free(error); return 1; } if (returnval != DBUS_START_REPLY_SUCCESS && returnval != DBUS_START_REPLY_ALREADY_RUNNING) { g_error("Return value isn't indicative of success: %d", returnval); return 1; } return 0; } ./tests/indicator-test.cpp0000644000004100000410000001750313350212612016043 0ustar www-datawww-data/* * Copyright © 2015 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * This program 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 for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include "indicator-fixture.h" #include "accounts-service-mock.h" #include "messaging-menu-app.h" #include "messaging-menu-message.h" class IndicatorTest : public IndicatorFixture { protected: IndicatorTest (void) : IndicatorFixture(INDICATOR_MESSAGES_SERVICE_BINARY, "com.canonical.indicator.messages") { } std::shared_ptr as; virtual void SetUp() override { g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE); g_setenv("GSETTINGS_BACKEND", "memory", TRUE); g_setenv("XDG_DATA_DIRS", XDG_DATA_DIRS, TRUE); as = std::make_shared(); addMock(*as); IndicatorFixture::SetUp(); } virtual void TearDown() override { as.reset(); IndicatorFixture::TearDown(); } }; TEST_F(IndicatorTest, RootAction) { setActions("/com/canonical/indicator/messages"); EXPECT_EVENTUALLY_ACTION_EXISTS("messages"); EXPECT_ACTION_STATE_TYPE("messages", G_VARIANT_TYPE("a{sv}")); EXPECT_ACTION_STATE("messages", g_variant_new_parsed("{'icon': <('themed', <['indicator-messages-offline', 'indicator-messages', 'indicator', 'indicator-messages-offline-symbolic', 'indicator-messages-symbolic', 'indicator-symbolic']>)>, 'title': <'Notifications'>, 'accessible-desc': <'Messages'>, 'visible': }")); } TEST_F(IndicatorTest, SingleMessage) { setActions("/com/canonical/indicator/messages"); auto app = std::shared_ptr(messaging_menu_app_new("test.desktop"), [](MessagingMenuApp * app) { g_clear_object(&app); }); ASSERT_NE(nullptr, app); messaging_menu_app_register(app.get()); EXPECT_EVENTUALLY_ACTION_EXISTS("test.launch"); auto msg = std::shared_ptr(messaging_menu_message_new( "testid", nullptr, /* no icon */ "Test Title", "A subtitle too", "You only like me for my body", 0), [](MessagingMenuMessage * msg) { g_clear_object(&msg); }); messaging_menu_app_append_message(app.get(), msg.get(), nullptr, FALSE); EXPECT_EVENTUALLY_ACTION_EXISTS("test.msg.testid"); setMenu("/com/canonical/indicator/messages/phone"); EXPECT_EVENTUALLY_MENU_ATTRIB(std::vector({0, 0, 0}), "x-canonical-type", "com.canonical.indicator.messages.messageitem"); EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "label", "Test Title"); EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "x-canonical-message-id", "testid"); EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "x-canonical-subtitle", "A subtitle too"); EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "x-canonical-text", "You only like me for my body"); } static void messageReplyActivate (GObject * obj, gchar * name, GVariant * value, gpointer user_data) { auto res = reinterpret_cast(user_data); *res = g_variant_get_string(value, nullptr); } TEST_F(IndicatorTest, MessageReply) { setActions("/com/canonical/indicator/messages"); auto app = std::shared_ptr(messaging_menu_app_new("test.desktop"), [](MessagingMenuApp * app) { g_clear_object(&app); }); ASSERT_NE(nullptr, app); messaging_menu_app_register(app.get()); EXPECT_EVENTUALLY_ACTION_EXISTS("test.launch"); auto msg = std::shared_ptr(messaging_menu_message_new( "messageid", nullptr, /* no icon */ "Reply Message", "A message to reply to", "In-app replies are for wimps, reply here to save yourself time and be cool.", 0), [](MessagingMenuMessage * msg) { g_clear_object(&msg); }); messaging_menu_message_add_action(msg.get(), "replyid", "Reply", G_VARIANT_TYPE_STRING, nullptr); messaging_menu_app_append_message(app.get(), msg.get(), nullptr, FALSE); EXPECT_EVENTUALLY_ACTION_EXISTS("test.msg.messageid"); EXPECT_EVENTUALLY_ACTION_EXISTS("test.msg-actions.messageid.replyid"); EXPECT_ACTION_ACTIVATION_TYPE("test.msg-actions.messageid.replyid", G_VARIANT_TYPE_STRING); EXPECT_ACTION_ENABLED("remove-all", true); setMenu("/com/canonical/indicator/messages/phone"); EXPECT_EVENTUALLY_MENU_ATTRIB(std::vector({0, 0, 0}), "x-canonical-type", "com.canonical.indicator.messages.messageitem"); std::string activateResponse; g_signal_connect(msg.get(), "activate", G_CALLBACK(messageReplyActivate), &activateResponse); activateAction("test.msg-actions.messageid.replyid", g_variant_new_string("Reply to me")); EXPECT_EVENTUALLY_EQ("Reply to me", activateResponse); EXPECT_EVENTUALLY_ACTION_ENABLED("remove-all", false); } TEST_F(IndicatorTest, IconNotification) { auto normalicon = std::shared_ptr(g_variant_ref_sink(g_variant_new_parsed("{'icon': <('themed', <['indicator-messages-offline', 'indicator-messages', 'indicator', 'indicator-messages-offline-symbolic', 'indicator-messages-symbolic', 'indicator-symbolic']>)>, 'title': <'Notifications'>, 'accessible-desc': <'Messages'>, 'visible': }")), [](GVariant *var) {if (var != nullptr) g_variant_unref(var); }); auto blueicon = std::shared_ptr(g_variant_ref_sink(g_variant_new_parsed("{'icon': <('themed', <['indicator-messages-new-offline', 'indicator-messages-new', 'indicator-messages', 'indicator', 'indicator-messages-new-offline-symbolic', 'indicator-messages-new-symbolic', 'indicator-messages-symbolic', 'indicator-symbolic']>)>, 'title': <'Notifications'>, 'accessible-desc': <'New Messages'>, 'visible': }")), [](GVariant *var) {if (var != nullptr) g_variant_unref(var); }); setActions("/com/canonical/indicator/messages"); auto app = std::shared_ptr(messaging_menu_app_new("test.desktop"), [](MessagingMenuApp * app) { g_clear_object(&app); }); ASSERT_NE(nullptr, app); messaging_menu_app_register(app.get()); EXPECT_EVENTUALLY_ACTION_EXISTS("test.launch"); EXPECT_ACTION_STATE("messages", normalicon); auto app2 = std::shared_ptr(messaging_menu_app_new("test2.desktop"), [](MessagingMenuApp * app) { g_clear_object(&app); }); ASSERT_NE(nullptr, app2); messaging_menu_app_register(app2.get()); EXPECT_EVENTUALLY_ACTION_EXISTS("test2.launch"); messaging_menu_app_append_source_with_count(app2.get(), "countsource", nullptr, "Count Source", 500); messaging_menu_app_draw_attention(app2.get(), "countsource"); EXPECT_EVENTUALLY_ACTION_STATE("messages", blueicon); auto msg = std::shared_ptr(messaging_menu_message_new( "messageid", nullptr, /* no icon */ "Message", "A secret message", "asdfa;lkweraoweprijas;dvlknasvdoiewur;aslkd", 0), [](MessagingMenuMessage * msg) { g_clear_object(&msg); }); messaging_menu_message_set_draws_attention(msg.get(), true); messaging_menu_app_append_message(app.get(), msg.get(), nullptr, FALSE); EXPECT_EVENTUALLY_ACTION_EXISTS("test.msg.messageid"); EXPECT_ACTION_STATE("messages", blueicon); messaging_menu_app_unregister(app2.get()); app2.reset(); EXPECT_EVENTUALLY_ACTION_DOES_NOT_EXIST("test2.msg.countsource"); EXPECT_ACTION_STATE("messages", blueicon); messaging_menu_app_remove_message(app.get(), msg.get()); EXPECT_EVENTUALLY_ACTION_STATE("messages", normalicon); EXPECT_ACTION_ENABLED("remove-all", false); messaging_menu_app_append_message(app.get(), msg.get(), nullptr, FALSE); EXPECT_EVENTUALLY_ACTION_STATE("messages", blueicon); EXPECT_ACTION_ENABLED("remove-all", true); activateAction("remove-all"); EXPECT_EVENTUALLY_ACTION_STATE("messages", normalicon); } ./tests/manual0000644000004100000410000001010313350212604013574 0ustar www-datawww-data Test-case indicator-messages/unity7-items-check
Log in to a Unity 7 user session
Go to the panel and click on the Messages indicator
Ensure there are items in the menu
Test-case indicator-messages/unity7-greeter-items-check
Start a system and wait for the greeter or logout of the current user session
Go to the panel and click on the Messages indicator
Ensure there are items in the menu
Test-case indicator-messages/unity8-items-check
Login to a user session running Unity 8
Pull down the top panel until it sticks open
Navigate through the tabs until "Notifications" is shown
Incoming is at the top of the menu
The menu is populated with items
Test-case indicator-messages/unity8-phone-symbolic-icon
NOTE: Requires Unity8 and Telephony hardware
Login to a user session running Unity 8
Send an SMS to the device
Icon on the panel should change color signifying a new message
Verify the application icon in the menu item is monochromatic
On the right side of the item the application icon should have no color
Test-case indicator-messages/unity8-embedded-greeter
NOTE: Only works with embedded greeter, split greeter will require modifications to this test
NOTE: Only works on a device that can receive SMS messages
Ensure System Settings is set to "Show Messages on Greeter"
Send an SMS to the device
The notification icon should change color
There should be an entry in the messaging menu with the SMS message
The item should include the sender and the start of the message
Go to the greeter. This can be done by hitting the lock button twice.
Ensure the messaging menu has the message
The notification icon should have color
There should be an entry in the messaging menu with the SMS message
The item should include the sender and the start of the message
Clear the message in the greeter
The message should no longer be in the messaging menu
Disable System Settings value "Show Messages on Greeter"
Send an SMS to the device
The notification icon should change color
There should be an entry in the messaging menu with the SMS message
The item should include the sender and the start of the message
Go to the greeter. This can be done by hitting the lock button twice.
Ensure the messaging menu has the message, but it does not include the start of the message
The notification icon should have color
There should be an entry in the messaging menu with the SMS message
The item should include the sender but NOT the start of the message
Clear the message in the greeter
The message should no longer be in the messaging menu
Test-case indicator-messages/push-message-twitter
From a shell prompt send a simultated Twitter push notification
gdbus call --session --dest com.ubuntu.Postal --object-path /com/ubuntu/Postal/com_2eubuntu_2edeveloper_2ewebapps_2ewebapp_2dtwitter --method com.ubuntu.Postal.Post com.ubuntu.developer.webapps.webapp-twitter_webapp-twitter '"{\"message\": \"foobar\", \"notification\":{\"card\": {\"summary\": \"yes\", \"body\": \"hello\", \"popup\": true, \"persist\": true}}}"'
The messaging envelope on the panel should change to highlight a message
Open the messaging menu
The menu should contain an entry with the Twitter icon for the application
The title of the message should be 'yes'
The body of the message should be 'hello'
At the bottom of them menu there should be a 'Clear All' menu item
Clear the message using the 'Clear All' command
The Twitter message should disappear
The 'Clear All' item should disappear
The icon in the panel should return to its original state
./tests/test-gactionmuxer.cpp0000644000004100000410000003111513350212604016570 0ustar www-datawww-data/* An indicator to show information that is in messaging applications that the user is using. Copyright 2012 Canonical Ltd. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include extern "C" { #include "gactionmuxer.h" } static gboolean strv_contains (gchar **str_array, const gchar *str) { gchar **it; for (it = str_array; *it; it++) { if (!g_strcmp0 (*it, str)) return TRUE; } return FALSE; } TEST(GActionMuxerTest, Sanity) { GActionMuxer *muxer; #if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init (); #endif g_test_expect_message ("Indicator-Messages", G_LOG_LEVEL_CRITICAL, "*G_IS_ACTION_MUXER*"); g_action_muxer_insert (NULL, NULL, NULL); g_test_assert_expected_messages (); g_test_expect_message ("Indicator-Messages", G_LOG_LEVEL_CRITICAL, "*G_IS_ACTION_MUXER*"); g_action_muxer_remove (NULL, NULL); g_test_assert_expected_messages (); muxer = g_action_muxer_new (); g_action_muxer_insert (muxer, NULL, NULL); g_action_muxer_remove (muxer, NULL); g_test_expect_message ("Indicator-Messages", G_LOG_LEVEL_CRITICAL, "*NULL*"); EXPECT_FALSE (g_action_group_has_action (G_ACTION_GROUP (muxer), NULL)); g_test_assert_expected_messages (); g_test_expect_message ("Indicator-Messages", G_LOG_LEVEL_CRITICAL, "*NULL*"); EXPECT_FALSE (g_action_group_get_action_enabled (G_ACTION_GROUP (muxer), NULL)); g_test_assert_expected_messages (); g_test_expect_message ("Indicator-Messages", G_LOG_LEVEL_CRITICAL, "*NULL*"); EXPECT_FALSE (g_action_group_query_action (G_ACTION_GROUP (muxer), NULL, NULL, NULL, NULL, NULL, NULL)); g_test_assert_expected_messages (); g_test_expect_message ("GLib-GIO", G_LOG_LEVEL_CRITICAL, "*NULL*"); g_action_group_activate_action (G_ACTION_GROUP (muxer), NULL, NULL); g_test_assert_expected_messages (); g_object_unref (muxer); } TEST(GActionMuxerTest, Empty) { GActionMuxer *muxer; gchar **actions; #if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init (); #endif muxer = g_action_muxer_new (); actions = g_action_group_list_actions (G_ACTION_GROUP (muxer)); EXPECT_EQ (0, g_strv_length (actions)); g_strfreev (actions); g_object_unref (muxer); } TEST(GActionMuxerTest, AddAndRemove) { const GActionEntry entries1[] = { { "one" }, { "two" }, { "three" } }; const GActionEntry entries2[] = { { "gb" }, { "es" }, { "fr" } }; const GActionEntry entries3[] = { { "foo" }, { "bar" } }; GSimpleActionGroup *group1; GSimpleActionGroup *group2; GSimpleActionGroup *group3; GActionMuxer *muxer; gchar **actions; #if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init (); #endif group1 = g_simple_action_group_new (); g_action_map_add_action_entries (G_ACTION_MAP (group1), entries1, G_N_ELEMENTS (entries1), NULL); group2 = g_simple_action_group_new (); g_action_map_add_action_entries (G_ACTION_MAP (group2), entries2, G_N_ELEMENTS (entries2), NULL); group3 = g_simple_action_group_new (); g_action_map_add_action_entries (G_ACTION_MAP (group3), entries3, G_N_ELEMENTS (entries3), NULL); muxer = g_action_muxer_new (); g_action_muxer_insert (muxer, "first", G_ACTION_GROUP (group1)); g_action_muxer_insert (muxer, "second", G_ACTION_GROUP (group2)); g_action_muxer_insert (muxer, NULL, G_ACTION_GROUP (group3)); actions = g_action_group_list_actions (G_ACTION_GROUP (muxer)); EXPECT_TRUE (g_action_group_has_action (G_ACTION_GROUP (muxer), "first.one")); EXPECT_FALSE (g_action_group_has_action (G_ACTION_GROUP (muxer), "one")); EXPECT_EQ (8, g_strv_length (actions)); EXPECT_TRUE (strv_contains (actions, "first.one")); EXPECT_TRUE (strv_contains (actions, "first.two")); EXPECT_TRUE (strv_contains (actions, "first.three")); EXPECT_TRUE (strv_contains (actions, "second.gb")); EXPECT_TRUE (strv_contains (actions, "second.es")); EXPECT_TRUE (strv_contains (actions, "second.fr")); EXPECT_TRUE (strv_contains (actions, "foo")); EXPECT_TRUE (strv_contains (actions, "bar")); g_strfreev (actions); g_action_muxer_remove (muxer, NULL); EXPECT_FALSE (g_action_group_has_action (G_ACTION_GROUP (muxer), "foo")); EXPECT_TRUE (g_action_group_has_action (G_ACTION_GROUP (muxer), "first.one")); actions = g_action_group_list_actions (G_ACTION_GROUP (muxer)); EXPECT_EQ (6, g_strv_length (actions)); EXPECT_FALSE (strv_contains (actions, "foo")); EXPECT_TRUE (strv_contains (actions, "first.one")); g_strfreev (actions); g_action_muxer_remove (muxer, "first"); EXPECT_FALSE (g_action_group_has_action (G_ACTION_GROUP (muxer), "first.two")); EXPECT_TRUE (g_action_group_has_action (G_ACTION_GROUP (muxer), "second.es")); actions = g_action_group_list_actions (G_ACTION_GROUP (muxer)); EXPECT_EQ (3, g_strv_length (actions)); EXPECT_FALSE (strv_contains (actions, "first.two")); EXPECT_TRUE (strv_contains (actions, "second.es")); g_strfreev (actions); g_action_muxer_insert (muxer, "second", G_ACTION_GROUP (group2)); actions = g_action_group_list_actions (G_ACTION_GROUP (muxer)); EXPECT_EQ (3, g_strv_length (actions)); g_strfreev (actions); g_action_muxer_insert (muxer, NULL, G_ACTION_GROUP (group3)); actions = g_action_group_list_actions (G_ACTION_GROUP (muxer)); EXPECT_EQ (5, g_strv_length (actions)); g_strfreev (actions); g_object_unref (muxer); g_object_unref (group1); g_object_unref (group2); g_object_unref (group3); } static gboolean g_variant_equal0 (gconstpointer one, gconstpointer two) { if (one == NULL) return two == NULL; else return g_variant_equal (one, two); } TEST(GActionMuxerTest, ActionAttributes) { GSimpleActionGroup *group; GSimpleAction *action; GActionMuxer *muxer; gboolean enabled[2]; const GVariantType *param_type[2]; const GVariantType *state_type[2]; GVariant *state_hint[2]; GVariant *state[2]; #if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34 g_type_init (); #endif group = g_simple_action_group_new (); action = g_simple_action_new ("one", G_VARIANT_TYPE_STRING); g_action_map_add_action (G_ACTION_MAP(group), G_ACTION (action)); muxer = g_action_muxer_new (); g_action_muxer_insert (muxer, "first", G_ACTION_GROUP (group)); /* test two of the convenience functions */ EXPECT_TRUE (g_action_group_get_action_enabled (G_ACTION_GROUP (muxer), "first.one")); g_simple_action_set_enabled (action, FALSE); EXPECT_FALSE (g_action_group_get_action_enabled (G_ACTION_GROUP (muxer), "first.one")); EXPECT_STREQ ((gchar *) g_action_group_get_action_parameter_type (G_ACTION_GROUP (muxer), "first.one"), (gchar *) G_VARIANT_TYPE_STRING); /* query_action */ g_action_group_query_action (G_ACTION_GROUP (group), "one", &enabled[0], ¶m_type[0], &state_type[0], &state_hint[0], &state[0]); g_action_group_query_action (G_ACTION_GROUP (muxer), "first.one", &enabled[1], ¶m_type[1], &state_type[1], &state_hint[1], &state[1]); EXPECT_EQ (enabled[0], enabled[1]); EXPECT_STREQ ((gchar *) param_type[0], (gchar *) param_type[1]); EXPECT_STREQ ((gchar *) state_type[0], (gchar *) state_type[1]); EXPECT_TRUE (g_variant_equal0 ((gconstpointer) state_hint[0], (gconstpointer) state_hint[1])); EXPECT_TRUE (g_variant_equal0 ((gconstpointer) state[0], (gconstpointer) state[1])); g_object_unref (action); g_object_unref (group); g_object_unref (muxer); } typedef struct { gboolean signal_ran; const gchar *name; } TestSignalClosure; static void action_added (GActionGroup *group, gchar *action_name, gpointer user_data) { TestSignalClosure *c = (TestSignalClosure *)user_data; EXPECT_STREQ (c->name, action_name); c->signal_ran = TRUE; } static void action_enabled_changed (GActionGroup *group, gchar *action_name, gboolean enabled, gpointer user_data) { TestSignalClosure *c = (TestSignalClosure *)user_data; EXPECT_EQ (enabled, FALSE); c->signal_ran = TRUE; } static void action_state_changed (GActionGroup *group, gchar *action_name, GVariant *value, gpointer user_data) { TestSignalClosure *c = (TestSignalClosure *)user_data; EXPECT_STREQ (g_variant_get_string (value, NULL), "off"); c->signal_ran = TRUE; } static void action_removed (GActionGroup *group, gchar *action_name, gpointer user_data) { TestSignalClosure *c = (TestSignalClosure *)user_data; EXPECT_STREQ (c->name, action_name); c->signal_ran = TRUE; } TEST(GActionMuxerTest, Signals) { GSimpleActionGroup *group; GSimpleAction *action; GActionMuxer *muxer; TestSignalClosure closure; group = g_simple_action_group_new (); action = g_simple_action_new ("one", G_VARIANT_TYPE_STRING); g_action_map_add_action (G_ACTION_MAP(group), G_ACTION (action)); g_object_unref (action); muxer = g_action_muxer_new (); g_signal_connect (muxer, "action-added", G_CALLBACK (action_added), (gpointer) &closure); g_signal_connect (muxer, "action-enabled-changed", G_CALLBACK (action_enabled_changed), (gpointer) &closure); g_signal_connect (muxer, "action-state-changed", G_CALLBACK (action_state_changed), (gpointer) &closure); g_signal_connect (muxer, "action-removed", G_CALLBACK (action_removed), (gpointer) &closure); /* add the group with "one" action and check whether the signal is emitted */ closure.signal_ran = FALSE; closure.name = "first.one"; g_action_muxer_insert (muxer, "first", G_ACTION_GROUP (group)); EXPECT_TRUE (closure.signal_ran); /* add a second action after the group was added to the muxer */ closure.signal_ran = FALSE; closure.name = "first.two"; action = g_simple_action_new_stateful ("two", G_VARIANT_TYPE_STRING, g_variant_new_string ("on")); g_action_map_add_action (G_ACTION_MAP(group), G_ACTION (action)); EXPECT_TRUE (closure.signal_ran); /* disable the action */ closure.signal_ran = FALSE; g_simple_action_set_enabled (action, FALSE); EXPECT_TRUE (closure.signal_ran); /* change its state */ closure.signal_ran = FALSE; g_simple_action_set_state (action, g_variant_new_string ("off")); EXPECT_TRUE (closure.signal_ran); g_object_unref (action); /* remove the first action */ closure.signal_ran = FALSE; closure.name = "first.one"; g_action_map_remove_action (G_ACTION_MAP(group), "one"); EXPECT_TRUE (closure.signal_ran); /* remove the whole group, should be notified about "first.two" */ closure.signal_ran = FALSE; closure.name = "first.two"; g_action_muxer_remove (muxer, "first"); EXPECT_TRUE (closure.signal_ran); g_object_unref (group); g_object_unref (muxer); } static void action_activated (GSimpleAction *simple, GVariant *parameter, gpointer user_data) { gboolean *signal_ran = (gboolean *)user_data; EXPECT_STREQ (g_variant_get_string (parameter, NULL), "value"); *signal_ran = TRUE; } static void action_change_state (GSimpleAction *simple, GVariant *value, gpointer user_data) { gboolean *signal_ran = (gboolean *)user_data; EXPECT_STREQ (g_variant_get_string (value, NULL), "off"); *signal_ran = TRUE; } TEST(GActionMuxerTest, ActivateAction) { GSimpleActionGroup *group; GSimpleAction *action; GActionMuxer *muxer; gboolean signal_ran; group = g_simple_action_group_new (); action = g_simple_action_new ("one", G_VARIANT_TYPE_STRING); g_action_map_add_action (G_ACTION_MAP(group), G_ACTION (action)); g_signal_connect (action, "activate", G_CALLBACK (action_activated), (gpointer) &signal_ran); g_object_unref (action); action = g_simple_action_new_stateful ("two", NULL, g_variant_new_string ("on")); g_action_map_add_action (G_ACTION_MAP(group), G_ACTION (action)); g_signal_connect (action, "change-state", G_CALLBACK (action_change_state), (gpointer) &signal_ran); g_object_unref (action); muxer = g_action_muxer_new (); g_action_muxer_insert (muxer, "first", G_ACTION_GROUP (group)); signal_ran = FALSE; g_action_group_activate_action (G_ACTION_GROUP (muxer), "first.one", g_variant_new_string ("value")); EXPECT_TRUE (signal_ran); signal_ran = FALSE; g_action_group_change_action_state (G_ACTION_GROUP (muxer), "first.two", g_variant_new_string ("off")); EXPECT_TRUE (signal_ran); g_object_unref (group); g_object_unref (muxer); } ./tests/Makefile.am0000644000004100000410000000612113350212604014435 0ustar www-datawww-data CLEANFILES= check_LTLIBRARIES = libgtest.la check_PROGRAMS = test-gactionmuxer TESTS = $(check_PROGRAMS) AM_CPPFLAGS = $(GTEST_CPPFLAGS) \ -I${top_srcdir}/src ###################################### # Google Test ###################################### nodist_libgtest_la_SOURCES = \ $(GTEST_SOURCE)/src/gtest-all.cc \ $(GTEST_SOURCE)/src/gtest_main.cc libgtest_la_CPPFLAGS = \ $(GTEST_CPPFLAGS) -w \ $(AM_CPPFLAGS) libgtest_la_CXXFLAGS = \ $(AM_CXXFLAGS) ###################################### # GActionMixer ###################################### test_gactionmuxer_SOURCES = \ test-gactionmuxer.cpp test_gactionmuxer_CPPFLAGS = \ $(APPLET_CFLAGS) \ $(AM_CPPFLAGS) test_gactionmuxer_LDADD = \ $(APPLET_LIBS) \ libindicator-messages-service.la \ libgtest.la ###################################### # Indicator Test ###################################### SCHEMA_COMPILED_DIR="$(abs_builddir)/gsettings-schemas-compiled/" indicator_test_SOURCES = \ indicator-test.cpp indicator_test_CPPFLAGS = \ -DINDICATOR_MESSAGES_SERVICE_BINARY="\"$(abs_top_builddir)/src/indicator-messages-service\"" \ -DSCHEMA_DIR="\"$(SCHEMA_COMPILED_DIR)\"" \ -DXDG_DATA_DIRS="\"$(abs_srcdir)/\"" \ -I$(top_srcdir)/libmessaging-menu \ -std=c++11 \ $(APPLET_CFLAGS) \ $(DBUSTEST_CFLAGS) \ $(AM_CPPFLAGS) indicator_test_LDADD = \ $(APPLET_LIBS) \ $(DBUSTEST_LIBS) \ $(top_builddir)/libmessaging-menu/libmessaging-menu.la \ libgtest.la \ -lc -lpthread indicator-test.cpp: schemas-compiled.stamp schemas-compiled.stamp: $(top_srcdir)/data/*gschema.xml @rm -rf $(SCHEMA_COMPILED_DIR) @mkdir -p $(SCHEMA_COMPILED_DIR) @cp -f $(top_srcdir)/data/*gschema.xml $(SCHEMA_COMPILED_DIR) @`pkg-config gio-2.0 --variable glib_compile_schemas` $(SCHEMA_COMPILED_DIR) @touch schemas-compiled.stamp CLEANFILES += schemas-compiled.stamp TESTS += indicator-test check_PROGRAMS += indicator-test ###################################### # Lib containing code under test ###################################### noinst_LTLIBRARIES = \ libindicator-messages-service.la libindicator_messages_service_la_SOURCES = \ $(top_builddir)/common/indicator-messages-service.c \ $(top_builddir)/common/indicator-messages-service.h \ $(top_srcdir)/src/gactionmuxer.c \ $(top_srcdir)/src/gactionmuxer.h \ $(top_srcdir)/src/dbus-data.h libindicator_messages_service_ladir = \ $(includedir)/libindicator-messages-service/ libindicator_messages_service_la_CFLAGS = \ $(APPLET_CFLAGS) \ $(COVERAGE_CFLAGS) \ -I$(top_builddir)/src \ -I$(top_builddir)/common \ -Wall \ -Wl,-Bsymbolic-functions \ -Wl,-z,defs \ -Wl,--as-needed \ -Werror -Wno-error=deprecated-declarations \ -DG_LOG_DOMAIN=\"Indicator-Messages\" libindicator_messages_service_la_LIBADD = \ $(APPLET_LIBS) libindicator_messages_service_la_LDFLAGS = \ $(COVERAGE_LDFLAGS) ###################################### # Test client with dbusmock ###################################### TESTS_ENVIRONMENT = \ export LD_LIBRARY_PATH=$(top_builddir)/libmessaging-menu/.libs; \ export GI_TYPELIB_PATH=$(top_builddir)/libmessaging-menu; \ export XDG_DATA_DIRS=$(abs_srcdir); TESTS += test-client.py ./tests/applications/0000755000004100000410000000000013350212604015067 5ustar www-datawww-data./tests/applications/test.desktop0000644000004100000410000000010313350212604017433 0ustar www-datawww-data[Desktop Entry] Type=Application Name=Test Exec=test Icon=test-app ./tests/applications/test2.desktop0000644000004100000410000000010313350212604017515 0ustar www-datawww-data[Desktop Entry] Type=Application Name=Test Exec=test Icon=test-app ./po/0000755000004100000410000000000013350212604011655 5ustar www-datawww-data./po/POTFILES.in0000644000004100000410000000036413350212604013435 0ustar www-datawww-data[encoding: UTF-8] src/im-phone-menu.c src/messages-service.c src/im-desktop-menu.c src/im-menu.c src/im-application-list.c src/gsettingsstrv.c src/gactionmuxer.c libmessaging-menu/messaging-menu-message.c libmessaging-menu/messaging-menu-app.c ./Makefile.am0000644000004100000410000000250513350212604013275 0ustar www-datawww-data SUBDIRS = \ common \ src \ libmessaging-menu \ data \ po if ENABLE_GTK_DOC SUBDIRS += doc endif if BUILD_TESTS SUBDIRS += \ tests # build src first tests: src libmessaging-menu endif DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall --enable-deprecations --enable-introspection --enable-gtk-doc dist-hook: @if test -d "$(top_srcdir)/.bzr"; \ then \ echo Creating ChangeLog && \ ( cd "$(top_srcdir)" && \ echo '# Generated by Makefile. Do not edit.'; echo; \ $(top_srcdir)/missing --run bzr log --gnu-changelog ) > ChangeLog.tmp \ && mv -f ChangeLog.tmp $(top_distdir)/ChangeLog \ || (rm -f ChangeLog.tmp; \ echo Failed to generate ChangeLog >&2 ); \ else \ echo Failed to generate ChangeLog: not a branch >&2; \ fi @if test -d "$(top_srcdir)/.bzr"; \ then \ echo Creating AUTHORS && \ ( cd "$(top_srcdir)" && \ echo '# Generated by Makefile. Do not edit.'; echo; \ $(top_srcdir)/missing --run bzr log --long --levels=0 | grep -e "^\s*author:" -e "^\s*committer:" | cut -d ":" -f 2 | cut -d "<" -f 1 | sort -u) > AUTHORS.tmp \ && mv -f AUTHORS.tmp $(top_distdir)/AUTHORS \ || (rm -f AUTHORS.tmp; \ echo Failed to generate AUTHORS >&2 ); \ else \ echo Failed to generate AUTHORS: not a branch >&2; \ fi include $(top_srcdir)/Makefile.am.coverage ./common/0000755000004100000410000000000013350212604012527 5ustar www-datawww-data./common/com.canonical.indicator.messages.service.xml0000644000004100000410000000136513350212604023202 0ustar www-datawww-data ./common/com.canonical.indicator.messages.application.xml0000644000004100000410000000264013350212604024042 0ustar www-datawww-data ./common/Makefile.am0000644000004100000410000000202013350212604014555 0ustar www-datawww-data noinst_LTLIBRARIES = libmessaging-common.la indicator-messages-service.c: com.canonical.indicator.messages.service.xml $(AM_V_GEN) gdbus-codegen \ --interface-prefix com.canonical.indicator.messages. \ --generate-c-code indicator-messages-service \ --c-namespace IndicatorMessages \ $^ indicator-messages-service.h: indicator-messages-service.c indicator-messages-application.c: com.canonical.indicator.messages.application.xml $(AM_V_GEN) gdbus-codegen \ --interface-prefix com.canonical.indicator.messages. \ --generate-c-code indicator-messages-application \ --c-namespace IndicatorMessages \ $^ indicator-messages-application.h: indicator-messages-application.c BUILT_SOURCES = \ indicator-messages-service.c \ indicator-messages-service.h \ indicator-messages-application.c \ indicator-messages-application.h libmessaging_common_la_SOURCES = \ $(BUILT_SOURCES) libmessaging_common_la_CFLAGS = $(GIO_CFLAGS) libmessaging_common_la_LIBADD = $(GIO_LIBS) CLEANFILES = $(BUILT_SOURCES) ./m4/0000755000004100000410000000000013350212604011557 5ustar www-datawww-data./m4/ax_python_module.m40000644000004100000410000000232713350212604015403 0ustar www-datawww-data# =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_python_module.html # =========================================================================== # # SYNOPSIS # # AX_PYTHON_MODULE(modname[, fatal]) # # DESCRIPTION # # Checks for Python module. # # If fatal is non-empty then absence of a module will trigger an error. # # LICENSE # # Copyright (c) 2008 Andrew Collier # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. #serial 5 AU_ALIAS([AC_PYTHON_MODULE], [AX_PYTHON_MODULE]) AC_DEFUN([AX_PYTHON_MODULE],[ if test -z $PYTHON; then PYTHON="python" fi PYTHON_NAME=`basename $PYTHON` AC_MSG_CHECKING($PYTHON_NAME module: $1) $PYTHON -c "import $1" 2>/dev/null if test $? -eq 0; then AC_MSG_RESULT(yes) eval AS_TR_CPP(HAVE_PYMOD_$1)=yes else AC_MSG_RESULT(no) eval AS_TR_CPP(HAVE_PYMOD_$1)=no # if test -n "$2" then AC_MSG_ERROR(failed to find required module $1) exit 1 fi fi ]) ./m4/gcov.m40000644000004100000410000000471713350212604012770 0ustar www-datawww-data# Checks for existence of coverage tools: # * gcov # * lcov # * genhtml # * gcovr # # Sets ac_cv_check_gcov to yes if tooling is present # and reports the executables to the variables LCOV, GCOVR and GENHTML. AC_DEFUN([AC_TDD_GCOV], [ AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov], [enable coverage testing with gcov]), [use_gcov=$enableval], [use_gcov=no]) if test "x$use_gcov" = "xyes"; then # we need gcc: if test "$GCC" != "yes"; then AC_MSG_ERROR([GCC is required for --enable-gcov]) fi # Check if ccache is being used AC_CHECK_PROG(SHTOOL, shtool, shtool) case `$SHTOOL path $CC` in *ccache*[)] gcc_ccache=yes;; *[)] gcc_ccache=no;; esac if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) fi lcov_version_list="1.6 1.7 1.8 1.9 1.10 1.11" AC_CHECK_PROG(LCOV, lcov, lcov) AC_CHECK_PROG(GENHTML, genhtml, genhtml) if test "$LCOV"; then AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [ glib_cv_lcov_version=invalid lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'` for lcov_check_version in $lcov_version_list; do if test "$lcov_version" = "$lcov_check_version"; then glib_cv_lcov_version="$lcov_check_version (ok)" fi done ]) else lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list" AC_MSG_ERROR([$lcov_msg]) fi case $glib_cv_lcov_version in ""|invalid[)] lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)." AC_MSG_ERROR([$lcov_msg]) LCOV="exit 0;" ;; esac if test -z "$GENHTML"; then AC_MSG_ERROR([Could not find genhtml from the lcov package]) fi ac_cv_check_gcov=yes ac_cv_check_lcov=yes # Remove all optimization flags from CFLAGS changequote({,}) CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` changequote([,]) # Add the special gcc flags COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage" COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage" COVERAGE_LDFLAGS="-lgcov" # Check availability of gcovr AC_CHECK_PROG(GCOVR, gcovr, gcovr) if test -z "$GCOVR"; then ac_cv_check_gcovr=no else ac_cv_check_gcovr=yes fi fi ]) # AC_TDD_GCOV ./m4/gtest.m40000644000004100000410000000477113350212604013160 0ustar www-datawww-data# Copyright (C) 2012 Canonical, Ltd. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # Checks whether the gtest source is available on the system. Allows for # adjusting the include and source path. Sets have_gtest=yes if the source is # present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and # source location respectively. AC_DEFUN([CHECK_GTEST], [ AC_ARG_WITH([gtest-include-path], [AS_HELP_STRING([--with-gtest-include-path], [location of the Google test headers])], [GTEST_CPPFLAGS="-I$withval"]) AC_ARG_WITH([gtest-source-path], [AS_HELP_STRING([--with-gtest-source-path], [location of the Google test sources, defaults to /usr/src/gtest])], [GTEST_SOURCE="$withval"], [GTEST_SOURCE="/usr/src/gtest"]) GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE" AC_LANG_PUSH([C++]) tmp_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $GTEST_CPPFLAGS" AC_CHECK_HEADER([gtest/gtest.h]) CPPFLAGS="$tmp_CPPFLAGS" AC_LANG_POP AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc] [$GTEST_SOURCE/src/gtest_main.cc], [have_gtest_source=yes], [have_gtest_source=no]) AS_IF([test "x$ac_cv_header_gtest_gtest_h" = xyes -a \ "x$have_gtest_source" = xyes], [have_gtest=yes] [AC_SUBST(GTEST_CPPFLAGS)] [AC_SUBST(GTEST_SOURCE)], [have_gtest=no]) ]) # CHECK_GTEST ./doc/0000755000004100000410000000000013350212604012004 5ustar www-datawww-data./doc/reference/0000755000004100000410000000000013350212604013742 5ustar www-datawww-data./doc/reference/messaging-menu-docs.xml.in0000644000004100000410000000253513350212604020743 0ustar www-datawww-data ]> Messaging Menu Reference Manual Messaging Menu Reference Manual for libmessaging-menu &version; 2012 Canonical Ltd. API Reference Object Hierarchy API Index Index of deprecated API ./doc/reference/Makefile.am0000644000004100000410000000104413350212604015775 0ustar www-datawww-dataDOC_MODULE = messaging-menu DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml DOC_SOURCE_DIR = $(top_srcdir)/libmessaging-menu MKDB_OPTIONS=--xml-mode --output-format=xml # Used for dependencies. The docs will be rebuilt if any of these change. HFILE_GLOB = $(top_srcdir)/libmessaging-menu/*.h CFILE_GLOB = $(top_srcdir)/libmessaging-menu/*.c IGNORE_HFILES= \ indicator-messages-service.h INCLUDES=-I$(top_srcdir)/libmessaging-menu $(GIO_CFLAGS) GTKDOC_LIBS=$(top_builddir)/libmessaging-menu/libmessaging-menu.la include $(top_srcdir)/gtk-doc.make ./doc/Makefile.am0000644000004100000410000000002413350212604014034 0ustar www-datawww-dataSUBDIRS = reference ./AUTHORS0000644000004100000410000000003113350212604012301 0ustar www-datawww-data# Generated by Makefile ./data/0000755000004100000410000000000013350212604012150 5ustar www-datawww-data./data/indicator-messages.service.in0000644000004100000410000000027513350212604017724 0ustar www-datawww-data[Unit] Description=Indicator Messages Service PartOf=graphical-session.target After=indicators-pre.target [Service] ExecStart=@pkglibexecdir@/indicator-messages-service Restart=on-failure ./data/com.canonical.indicator.messages.gschema.xml0000644000004100000410000000073313350212604022570 0ustar www-datawww-data List of applications that are shown in the messaging menu Applications corresponding to the desktop file ids in this list are shown in the messaging menu. [] ./data/icons/0000755000004100000410000000000013350212604013263 5ustar www-datawww-data./data/icons/22x22/0000755000004100000410000000000013350212604014042 5ustar www-datawww-data./data/icons/22x22/categories/0000755000004100000410000000000013350212604016167 5ustar www-datawww-data./data/icons/22x22/categories/applications-email-panel.png0000644000004100000410000000174713350212604023556 0ustar www-datawww-dataPNG  IHDRĴl;sBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<dIDAT8Mh\U͛7oK|4֦+EučmR1W-dRqnZBq!.7uiM53I潗wDrQka QIl5TZzuXAIt~:7{nѪYV(0 v98RgAN _%|yT&|n-kZ/h9(Wz }O_|.a%;1BZ^ZcS3|]*-N ./N7(ڱ7*c:ҬJZfzL*~PZx<>D33Giܾs+!rq>5IowS5<4D("xw;wGͦ?491,)+Ăq@aY6ёfZ٦0VTOpfPD:2c *##666H&##}%b$CwlƲ, c2ݒ0{;C~_H( cshxGRyfΑ?(x_0@2irlrcL=sL "~OT ?[ɞ`JɓclDրɧ^nq]~Hblw-hh'cgtDS!ډ6l0 P_hME*]')D@kilmuD4n;~kԈh2#J)wx1h==6Z}}Za:lHTJN*qfF/_@(A)F[0l`iJ)%uUJ)'OOIENDB`./data/icons/22x22/categories/Makefile.am0000644000004100000410000000020213350212604020215 0ustar www-datawww-data iconsdir = $(datadir)/icons/hicolor/22x22/categories icons_DATA = \ applications-email-panel.png EXTRA_DIST = $(icons_DATA) ./data/icons/22x22/status/0000755000004100000410000000000013350212604015365 5ustar www-datawww-data./data/icons/22x22/status/indicator-messages-new.png0000644000004100000410000000202513350212604022442 0ustar www-datawww-dataPNG  IHDRĴl;bKGD pHYs B(xtIME4|IDAT8˽KlU{:㸱c;̓4Z U*RP7=Y5 TBHJ@BTTE.XBJJAvl&{ȉP #93s)® ~ B b;) )`d $AbȮ TAAmKJ%2A΂ 9V^f*@صv,\2@Cg\_)\p\JQ*B^f 6kUky*c? I(\Y#p)(p/[]MQLB#dk}к**.1<Z>[|DO ",{O=+ł{}x\/e,ra"B A"6.z<|ZDa24~0(@ɽ['ͣt~vJ)R4|sDQFi^uC>J)|w2hF$^[[p%z/[Oǎwߠt L`eOSN>s,r(;{zI4M9} ֿ<1L:rFp' }H)J"@HAg;ɋl!QNstl8 &*Cc'Ώ`!xڝv(c6Lmv"0u۷dg8Lz?Eu^jggO>C)s#J)iƽ{(1}h0"/T9*x/CU=^H镔N)Θ/~̋(Fjrf!p_u]G)IENDB`./data/icons/22x22/status/Makefile.am0000644000004100000410000000022613350212604017421 0ustar www-datawww-data iconsdir = $(datadir)/icons/hicolor/22x22/status icons_DATA = \ indicator-messages.png \ indicator-messages-new.png EXTRA_DIST = $(icons_DATA) ./data/icons/22x22/Makefile.am0000644000004100000410000000003413350212604016073 0ustar www-datawww-dataSUBDIRS = status categories ./data/icons/scalable/0000755000004100000410000000000013350212604015031 5ustar www-datawww-data./data/icons/scalable/categories/0000755000004100000410000000000013350212604017156 5ustar www-datawww-data./data/icons/scalable/categories/applications-chat-panel.svg0000644000004100000410000003400413350212604024400 0ustar www-datawww-data image/svg+xml Person Jakub Steiner http://jimmac.musichall.cz user person ./data/icons/scalable/categories/Makefile.am0000644000004100000410000000024413350212604021212 0ustar www-datawww-data iconsdir = $(datadir)/icons/hicolor/scalable/categories icons_DATA = \ applications-email-panel.svg \ applications-chat-panel.svg EXTRA_DIST = $(icons_DATA) ./data/icons/scalable/categories/applications-email-panel.svg0000644000004100000410000005012213350212604024547 0ustar www-datawww-data image/svg+xml Mail Emblem 2005-02-19 Lapo Calamandrei Mail emblem Jakub Steiner Andreas Nilsson mail message e-mail Lapo Calamandrei, Andreas Nilsson, Novell Inc. ./data/icons/scalable/status/0000755000004100000410000000000013350212604016354 5ustar www-datawww-data./data/icons/scalable/status/indicator-messages-new.svg0000644000004100000410000004462713350212604023462 0ustar www-datawww-data image/svg+xml Lapo Calamandrei Mail stuff ./data/icons/scalable/status/application-running.svg0000644000004100000410000001473113350212604023064 0ustar www-datawww-data image/svg+xml August 2006 Andreas Nilsson Jakub Steiner http://www.gnome.org next arrow go ./data/icons/scalable/status/indicator-messages.svg0000644000004100000410000004336413350212604022670 0ustar www-datawww-data image/svg+xml Jakub Steiner Andreas Nilsson http://jimmac.musichall.cz ./data/icons/scalable/status/Makefile.am0000644000004100000410000000026413350212604020412 0ustar www-datawww-data iconsdir = $(datadir)/icons/hicolor/scalable/status icons_DATA = \ application-running.svg \ indicator-messages.svg \ indicator-messages-new.svg EXTRA_DIST = $(icons_DATA) ./data/icons/scalable/Makefile.am0000644000004100000410000000003413350212604017062 0ustar www-datawww-dataSUBDIRS = status categories ./data/icons/48x48/0000755000004100000410000000000013350212604014062 5ustar www-datawww-data./data/icons/48x48/status/0000755000004100000410000000000013350212604015405 5ustar www-datawww-data./data/icons/48x48/status/indicator-messages-new.png0000644000004100000410000000427313350212604022471 0ustar www-datawww-dataPNG  IHDR00WsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<tEXtTitleMail stuff=tEXtAuthorLapo Calamandreiߑ*IDAThMGgzgvg֞w퍵޵8_HDHp"WABBpE(B$A $8~L=;=3,I5]S]WUݢ6j7 {Æw\[1j%N6,T:ٝ,tg% kn˦#,Uu&  L)2"6#N$"6Sb/ګx]%q!s J:NpGn]rw̤&iee[.{sȼUtVSܬu^#Qo("EG|C^Sz؄#b#2kUDt6Yσຟ9.& VuYϋM;?vo\~RC*&T3dd}ZmzRKxZ:wX]-Zccc9]o>žwP\~ˏ|ek]EQ}x$9Hu7Ǚ# ,)#ޝˏ]F@CھTP(?]AX\*>*8I)!{E[W{[`Q "#HV $@ [Ř>HsbGq:/dCX^~-'tuKI_BV'e 8BZvDXNPy⣔4IԐ mdV QMjUTxq*P!]h4\r<ӗ}/HJ8J IЃ{u$yk_+ԵPm`mnTFĪp,.̡CxAvH栺Pց-T}YwDҙ1_ MCR; jO{?aΞ=C'y,p(IErPF, TVSuajM~C!SQW7 p >Od1\~Yi~r/<"(uM$jXqR;I,<NPQ X?̟'>Ϡj nw돕FmUD^̥KbbvJF%Ij,dW )ufgo|,6M a;ڵ lfVVqÁ_?Je\Dr|xFP++Mfff0)HO {` ;?s{}DQO1G~#oT*S cpk-i 0䩗xK'O%j \2ݑΟ?A0*vOϰ޻}C`̓VW * Iv_GtFҎ۸KuJ1?!cWIΒ;{{2r ˍoȖ_[D/L5 u?)ؿozUm_-hڢ=潶p|۞# E(Plm۬w?jԯxKD `fkt;7hn+7:Nt[ 8ܹƦfukG:Ik Gv x3،c8{G# Xc9!a^Y?r~,^i^xiwt1sHd}knݚ7C9bX[l;;~o;6A?jB^rI ֯U7ˊ|3|fCȳ qL$xl kjGľ+"X21@5zfkw['ީVЏЂ1?eh4mFUhϿ03dOm6V>a{8r ϲ("MXHL/'@̑!C&MA.gspZ}o1 T ،3,/%2 U1Ӝ~h J@rQ዇24!,쭡sU" & "4!Xsvg7<8p&CBDhC$Ʉ <2xhfCTtMD,nuxud@~KYU+bѹ9GCϼT@CHSe`5 >N;X4n1>xtr",^0BȦ-f 4XpHD5tn:LfS+9I91g`WISNO0uȒ]U051NNMݚuS٪T"RH :U섓!p75u-Ǚw3?Wqwk;[DDvP)5$ |јKߏ\|t0߳RQzCr"<K  bcVΥ:nsE]Y=JsN{o_#<#>j2fJ `&_&{V 7U)TA͈xh(HJTpxRٟR}}Jޟ$)"cPpC A3,bX8\bQ&IB 2㤅:wo ɨ~(Q`RÝwi{sssܸq{;K~y&N{d̉'<9JHC۬9[=:ڞPzWI,;5]5r|. !Пv8s \c*@U- ~1o4t"ǗЮ@%!VWN?T^Hb?t& E+h|A)dqbDL>QFbzf'Opm-d7,oQJjuxeȑmEU${ ALaqaE޽Z2WZ T.SSSϣ<6>,@ v8q86&뢵R(EN+j 4ͷ֭B㉌!ՄW|?IE<8s~q8cHӔ$M!._8Y~O?fmm;JONpX PY8ClnnN<%W_Q#b$s=𙙞رc\}9{k~ kETtK]!s.?ڇ ˢBDD;^@x~_( L$m4M DJ&◎o,LePZR fgfu #~9F* DpJ)FFG}7o0Ѵ"VDjsbN{.(IJv9p=MӘqn~=V&'0\1,oU| b vvH>\@7tI0g@!1 !8~]y2 >MZ+\(p";;|z <G*uɃy¡>?e[Gs]F~3ضs(( [yÄgS"6m0AFBPu|Ns h8uDyIiy "Tea3whۀaEsR8NX3az2i}F *Ukڵw>|o!j{i @R^ZR~/WT)XZIENDB`./data/icons/24x24/status/application-running.png0000644000004100000410000000140613350212604022061 0ustar www-datawww-dataPNG  IHDRw=sBIT|d pHYsu85tEXtSoftwarewww.inkscape.org<tEXtAuthorAndreas Nilsson+tEXtCreation TimeAugust 2006{ tEXtSourcehttp://www.gnome.orgCUIDATHֿkas\jMARBxRtqEE:][D]\ԭ\,SEi.=qȉg xis/|x=ٔPP ww#2cܓHBJt/\RGzx%F@>40LG?wY'''O>i[TvիCW6 +uAږ~Խ|^uj0@'B(`8rd6Dw ԊE3;*Ucݸ830h۴ZDA(-YWo 0ZyM%o*VԇىZk o}|zmT"RhcLc翼}v ND1 (( @Vfi 10w!ڿt?ت7}\4>V%_VAc @ћ0OYߗEIENDB`./data/icons/24x24/status/indicator-messages.png0000644000004100000410000000160613350212604021663 0ustar www-datawww-dataPNG  IHDRw=sRGBbKGD pHYs B(xtIME*IDATHKoU1wfj8&1u\CK _!lXJ|!U X!Ă$]U@ AY(cJ];iX=wFsܳh;o==Jץ"@JTB <6-?Na-y?BvyG݅@ P>gƑ#x}Bkff0ș2SkאAs2٭ !{'jgg?)s5:,~T7¢~^laUQ9*x/C !+)R)1n>-\jrN'p~GJCIENDB`./data/icons/24x24/status/Makefile.am0000644000004100000410000000026113350212604017424 0ustar www-datawww-data iconsdir = $(datadir)/icons/hicolor/24x24/status icons_DATA = \ application-running.png \ indicator-messages.png \ indicator-messages-new.png EXTRA_DIST = $(icons_DATA) ./data/icons/24x24/Makefile.am0000644000004100000410000000002113350212604016073 0ustar www-datawww-dataSUBDIRS = status ./data/icons/16x16/0000755000004100000410000000000013350212604014050 5ustar www-datawww-data./data/icons/16x16/categories/0000755000004100000410000000000013350212604016175 5ustar www-datawww-data./data/icons/16x16/categories/applications-microblogging-panel.png0000644000004100000410000000151413350212604025307 0ustar www-datawww-dataPNG  IHDRabKGDCIDATx]Kk$eꪾ&$Nm:㘌q\ "b*wnAƭ? ^ r@$&LL\Ituݿʅ=zVy^*o*܅'f jښcKvSi9@< c3 թW|L%%R{41yzp H2eKŬg._˨ny @?kч/\Otť;ᄃT.L'bGFyy5egw~d $*'AJ##R d9V~z;5_T/]룅R-J#BFM:78 2B&k+b4mz'lI\&+BTUf.N!|pnԞ~VH4H]il@F8~xx~cܽZgZV)wǭӀX2?[#%=q $1ipڙ 'e!OUljd>[]l˥^ bN8;iF@Xr~gA>c[iRrxH{: `;to;k&q>mc[mtacv'p j?(p+a}bv>@4_k+;S"=Ό>f %-XjEX+[Uwx 0?eETt7ߛvW7BIENDB`./data/icons/16x16/categories/applications-chat-panel.png0000644000004100000410000000112213350212604023377 0ustar www-datawww-dataPNG  IHDRa pHYs  ~tIME ,xtEXtCommentCreated with The GIMPd%nIDAT8ˍjQ t;yul,|(Du `QPB$ M2{̽.@N[wq8\AJ:p.JۗW)Zf Zc5 ^k[f&qZc],VJiVJi1 8VjB /T+5.] (yŜDJ""xK{`#JGcI>qp J+H%QZl8,H:@q2 7C5:RNg8 8Y$I뇮~aRτhy:Rً;h`EрճdəsohGVn@[b-*e͟?;N$G!2N@?vݝ3b?!)k7Au:BH ){wZ.KZ+Gë߾픱8Ziuݍ OŽZ94/_2GV hܘ }W/8~iOg]:_V xXo⻊˄,K\0MsZrtl@rm})$MptSdY,-Nem6@ l  &~ vهUQ@an4Zx^@&%aY=9H)qg&;zN7nn}Sx䘚:B>_`qqX, ƀ5DA@WuRP(ȏY30`-qQZB) \&G.T ZuOD)|mO0$GS黤Ѻzah @n`ÛCОM<{^*_ IENDB`./data/icons/16x16/categories/Makefile.am0000644000004100000410000000031113350212604020224 0ustar www-datawww-data iconsdir = $(datadir)/icons/hicolor/16x16/categories icons_DATA = \ applications-email-panel.png \ applications-chat-panel.png \ applications-microblogging-panel.png EXTRA_DIST = $(icons_DATA) ./data/icons/16x16/status/0000755000004100000410000000000013350212604015373 5ustar www-datawww-data./data/icons/16x16/status/indicator-messages-new.png0000644000004100000410000000133113350212604022447 0ustar www-datawww-dataPNG  IHDRabKGD pHYs B(xtIME;PfIDAT8˕oLaϽw;I;NSF;E?w–H$,ja? b%Ē a+:"h$>2Vx)Z|sWXՅ,P\=Y<2]Qzu=@n g QU͉7͍ҫ]:"pO6#RY3:/}Ky {o q:(OrK]8wQ؞HngF2CD2R̶kOg;}<:=A< "ŵ6\;woc[>`;Ju,jft͏QzeY+}~<IJRZ[e % "vnVwkI֩JA0?P5ffRz)*Yk =RyPU8٨Sot0/^b ])io:7Hdhq(wfgٳs/ZA *ضG.xZFcf-c$XЦޕQ5-'8Y' ^WPWJ4YV$c_|zGۙ3z< "IENDB`./data/icons/16x16/status/application-running.png0000644000004100000410000000111213350212604022055 0ustar www-datawww-dataPNG  IHDRasBIT|d pHYs|4ktEXtSoftwarewww.inkscape.org<tEXtAuthorAndreas Nilsson+tEXtCreation TimeAugust 2006{ tEXtSourcehttp://www.gnome.orgCUYIDAT8ӿKBQe" "R"0hphq*hkhhh Z Zilh( HtF[!0ϧ׽-1;|8{ !JZ.}{K@nP[ F @s|l82~< 1dz8.fMBEÄMףs;CMRq;]c~ߕawa3 `Jшw7EѠo.P\9y$Lpޫ5B `#7rNɇZ@UfE5*/?%6Dd'" Cȷ'+/i:QoԷ3.yPH@ W5򜭖WIENDB`./data/icons/16x16/status/indicator-messages.png0000644000004100000410000000115113350212604021660 0ustar www-datawww-dataPNG  IHDRasBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<IDAT8œjSAYhrUх (A"BQ_ւE,I[ŗ/ ¦4ͽ"5͙҅9c"%֖eIQ)>!I c ιR2:6J`}R !9YkMft6I )FA^oƘ9w$IJhST#בBBlPViwȲ RYczz>8_8fyۿ~R>R z=vs.GG,[RB$)33-~|%zBZ<eb8Pڂ.sAcNwxrEiKҬ2ǰJ[pu.Z_|rΝj>tC"ҋH>Qɳ(ow.&&IENDB`./data/icons/16x16/status/Makefile.am0000644000004100000410000000026113350212604017426 0ustar www-datawww-data iconsdir = $(datadir)/icons/hicolor/16x16/status icons_DATA = \ application-running.png \ indicator-messages.png \ indicator-messages-new.png EXTRA_DIST = $(icons_DATA) ./data/icons/16x16/Makefile.am0000644000004100000410000000003413350212604016101 0ustar www-datawww-dataSUBDIRS = status categories ./data/icons/Makefile.am0000644000004100000410000000067613350212604015330 0ustar www-datawww-dataSUBDIRS = scalable 16x16 22x22 24x24 32x32 48x48 gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor install-data-hook: update-icon-cache uninstall-hook: update-icon-cache update-icon-cache: @-if test -z "$(DESTDIR)"; then \ echo "Updating Gtk icon cache."; \ $(gtk_update_icon_cache); \ else \ echo "*** Icon cache not updated. After (un)install, run this:"; \ echo "*** $(gtk_update_icon_cache)"; \ fi ./data/icons/32x32/0000755000004100000410000000000013350212604014044 5ustar www-datawww-data./data/icons/32x32/categories/0000755000004100000410000000000013350212604016171 5ustar www-datawww-data./data/icons/32x32/categories/applications-chat-panel.png0000644000004100000410000000344713350212604023407 0ustar www-datawww-dataPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<IDATX[l̙̮/kK\JDLzQ$ZR0CF[ Mf$܉Rbu \\^>{iG{P@A7_x/+zgc&`1M@RJ!J%3v ^n `=Q!@@!1J5R`'b4Mضu BQ@AJ)%J*y&ijPmO4ڦ !*[]QM FM6ۺ𧻓{9(] 8`AҌU=Hga'^b) QJeUKm.w7`u]9RBxKf$O#rzu{okNR)HYrp]=QN]|fRyi  (ܚųձB.!FuJT쌚IL\|}]}_}Tx;T\?g/uضy)9d2YQނIeBawSȤ3ظy;VW ~2ݯz 07?v475~tK$oaq.} =DnCp8vxNv("SpVK`ed2A)ap hiiE5k_Ox8 #˂R ]ghnn1>,/gP(!!ihll@4c B yc}2>^=x79FMi_>_[1]F2 L8NS ò,1F.{7s"7M8,@A{{:;;Յ-[ѱ UTer9Bpܾ})b&L8w /!RJBiodK@dwˉ] $g`  4!D[{zjÉ 7 Rx~`drWQ(wJP5fo7",+ Vx  xztoN:Yv(ζt}VLB0m;9./yٛ*Sv@i˲X6y'b` Ӵ*Y)J%199}岼y_^ ^B@@pǎ햖^шR)4<`(ZJލ\|қXzXe5ts)?x(*pU%^VIENDB`./data/icons/32x32/categories/applications-email-panel.png0000644000004100000410000000323313350212604023550 0ustar www-datawww-dataPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<IDATXŗ_l[W?sƎ'qtITIZ-]6mڠ2CՒ=!!UBB xx& Bx@/oH[U`^VhilqvX=ι}gIuܸ뺝,dE^˶wݮ'vK.cǎk`UհèP.MΝ;r`ܹs"jȿ3ē>3j24؎8(j>nܸ\KgϞ'W\> _|zoߘf|M:pk߼yoNMOO<ϟpFǟs'O,XŽŻ.J$<t[X"СC Ǜ&#]@B 繮, 2 l#GzbH_ d(Xex$IhZM;t(Tè09kL,2PEQeum|!LJ~@"IRl ߕ$x?H8xm; "W}i"+'\)y7슢0>~2c־/imQq÷5˶dtG0ATj6[&Ӳ* _{M>|,kCk46> oP,¬#b5su6QrܐTU"(c_|vy| 4 %mU!N]w]|uZި5I z*ȒD{0,xDl@̴BX#p>+Q5+@?oق-$YKnu][ZJ4_̈́2 a(w`) ~?o1CR簶IENDB`./data/icons/32x32/categories/Makefile.am0000644000004100000410000000024113350212604020222 0ustar www-datawww-data iconsdir = $(datadir)/icons/hicolor/32x32/categories icons_DATA = \ applications-email-panel.png \ applications-chat-panel.png EXTRA_DIST = $(icons_DATA) ./data/icons/32x32/status/0000755000004100000410000000000013350212604015367 5ustar www-datawww-data./data/icons/32x32/status/indicator-messages-new.png0000644000004100000410000000304713350212604022451 0ustar www-datawww-dataPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org<IDATXKl[K^ERԃ-ǯ0rVHYt]n".EwM @nJRhQ5EI59'{/EJXF cs;FU9B`0F@P5%nU PAd<sP{jzM ,V:*, `nPܒtǶ Z=(eßn8O~hr cej~.nuX 2Yφ?;gh.%&VPڂ'Apus[, ?Bρ`n [~L~v˪jG (,U[TcT:Tl"_ǍnnnO/]8s/2 -Tz \S=M 0; $vTO P +E0'&Cd"0efH@5?7]Pⵦ,Q]}f% rwb+ ^NS*aZZ|O^x"xTUj !2xG|AB]G|DV,`W ūьrJRRN6 ]GYAYCL.G,@v{`0:ޯ\`#NPQETP__[#q/f.!AUg`Nc9mdA]cYE9Y8lLM@UACaЍh<߿ǥK/D9Tx۴ڟqǬJފ $?@‹a^$aMlAh8$/I>^*Jj&&B{wM\¹4k1 c|Q$y__ogI? d,".$bL3Q'ۗ/-E:-`q0R%S2<@)Ηf?=BڝT&sX@KGI;oƏlۀjC0 &?DLl,K,l) Ծ4f &@9=?$}Q7vgIENDB`./data/icons/32x32/status/application-running.png0000644000004100000410000000174413350212604022064 0ustar www-datawww-dataPNG  IHDR szzsBIT|d pHYs : :dJtEXtSoftwarewww.inkscape.org<tEXtAuthorAndreas Nilsson+tEXtCreation TimeAugust 2006{ tEXtSourcehttp://www.gnome.orgCUIDATXKLQ3ӖByTBD (LLtaXHCpR$c%tqKJ nd% 0Qc D'-L3EgBkh.<əL2s;K13gly@ya 㨲:56m]U&fSKɢH6.BA c#?zIl?5^.)Aϝim/,\|X3͢CNDO5[+k `>*3Doiz_o:$nR1U:V_k?vɵ`O4ܳƞr Tffowe),C&}VklHϣL ĄJhfڅәJ pFA,+@١E51:gD<5@EHxxpwgT<%v_G=\Y_"o#9Yq,;Hҹ81W$9Ae~|@A!)<۹a"GD{rm1Ơּ>[X*`R@H)LB g`s9\A!*JYfTMODƘ:8~/-Ͼ(PU1M8>Bai+dTkG;Le*J(w+65[-9ʯ@kQtlqۈkSR @8E9-Vp^IENDB`./data/icons/32x32/status/indicator-messages.png0000644000004100000410000000222013350212604021652 0ustar www-datawww-dataPNG  IHDR szzsBIT|d pHYs B(xtEXtSoftwarewww.inkscape.org< IDATXIoE{ŎV"'J@\X8' 76! !.Wq @("B"mV؎dg̒YC3c#X9Ҽ]={WF1CDFb0Dsɽ\^ۑ %Z,A)Ș{c :uX02!Me!jB-Mcgt`\|s"Tb b#L=^&k L'nvY@>Q?R&Rqln EF:Q<072D.p!n