aboutsummaryrefslogtreecommitdiff
path: root/src/im-menu.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-08-12 21:19:42 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-08-12 21:19:42 +0200
commitff4aefe6c8d9c36881f26c2cf8514c2ce1f3edca (patch)
tree853b2ae06615f5beed76334efe97bbc94f2f2fb7 /src/im-menu.c
parent769affeef08a04881a5a84aa5c2db2caedf70646 (diff)
downloadayatana-indicator-messages-ff4aefe6c8d9c36881f26c2cf8514c2ce1f3edca.tar.gz
ayatana-indicator-messages-ff4aefe6c8d9c36881f26c2cf8514c2ce1f3edca.tar.bz2
ayatana-indicator-messages-ff4aefe6c8d9c36881f26c2cf8514c2ce1f3edca.zip
Add ImMenu
A base class for all messaging menus. ImPhoneMenu already subclasses from it, with a desktop version coming up.
Diffstat (limited to 'src/im-menu.c')
-rw-r--r--src/im-menu.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/im-menu.c b/src/im-menu.c
new file mode 100644
index 0000000..9f4d3e0
--- /dev/null
+++ b/src/im-menu.c
@@ -0,0 +1,148 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Lars Uebernickel <lars.uebernickel@canonical.com>
+ */
+
+#include "im-menu.h"
+
+struct _ImMenuPrivate
+{
+ GMenu *toplevel_menu;
+ GMenu *menu;
+ ImApplicationList *applist;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (ImMenu, im_menu, G_TYPE_OBJECT)
+
+enum
+{
+ PROP_0,
+ PROP_APPLICATION_LIST,
+ 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_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;
+
+ 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;
+
+ 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));
+}
+
+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 ();
+
+ 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_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;
+}