aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-printers-menu.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-01-12 17:04:30 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-01-12 17:04:30 +0100
commiteda55d25b59b4ed7c373f37eb9004832f9e26367 (patch)
treeee817c63f6a61f9dade1721edb17dc4fc7b628a9 /src/indicator-printers-menu.c
parent72ec836bd31f905d1191480e648252195aa5ec33 (diff)
downloadayatana-indicator-printers-eda55d25b59b4ed7c373f37eb9004832f9e26367.tar.gz
ayatana-indicator-printers-eda55d25b59b4ed7c373f37eb9004832f9e26367.tar.bz2
ayatana-indicator-printers-eda55d25b59b4ed7c373f37eb9004832f9e26367.zip
Move menu related code into a separate class
Also removes the "System Settings" menu item (according to spec). Printer menu items are hardcoded for now.
Diffstat (limited to 'src/indicator-printers-menu.c')
-rw-r--r--src/indicator-printers-menu.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/indicator-printers-menu.c b/src/indicator-printers-menu.c
new file mode 100644
index 0000000..26ed526
--- /dev/null
+++ b/src/indicator-printers-menu.c
@@ -0,0 +1,123 @@
+
+#include "indicator-printers-menu.h"
+
+#include <gio/gio.h>
+
+
+#define MENUITEM_PROP_PRINTER "indicator-printers-printer"
+
+
+G_DEFINE_TYPE (IndicatorPrintersMenu, indicator_printers_menu, G_TYPE_OBJECT)
+
+#define PRINTERS_MENU_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenuPrivate))
+
+
+struct _IndicatorPrintersMenuPrivate
+{
+ DbusmenuMenuitem *root;
+};
+
+
+static void
+dispose (GObject *object)
+{
+ IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (object);
+
+ g_clear_object (priv->root);
+
+ G_OBJECT_CLASS (indicator_printers_menu_parent_class)->dispose (object);
+}
+
+
+static void
+indicator_printers_menu_class_init (IndicatorPrintersMenuClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (IndicatorPrintersMenuPrivate));
+
+ object_class->dispose = dispose;
+}
+
+
+static void
+show_system_settings (DbusmenuMenuitem *menuitem,
+ guint timestamp,
+ gpointer user_data)
+{
+ GAppInfo *appinfo;
+ GError *err = NULL;
+ const gchar *printer;
+ gchar *cmdline;
+
+ printer = dbusmenu_menuitem_property_get (menuitem, MENUITEM_PROP_PRINTER);
+ cmdline = g_strdup_printf ("gnome-control-center printing show-printer %s",
+ printer);
+
+ appinfo = g_app_info_create_from_commandline (cmdline,
+ "gnome-control-center",
+ G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION,
+ &err);
+ g_free (cmdline);
+
+ if (err) {
+ g_warning ("failed to create application info: %s", err->message);
+ g_error_free (err);
+ return;
+ }
+
+ g_app_info_launch (appinfo, NULL, NULL, &err);
+ if (err) {
+ g_warning ("failed to launch gnome-control-center: %s", err->message);
+ g_error_free (err);
+ }
+
+ g_object_unref (appinfo);
+}
+
+
+static void
+add_printer_menuitem (IndicatorPrintersMenu *self,
+ const gchar *printer)
+{
+ IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self);
+ DbusmenuMenuitem *child;
+
+ child = dbusmenu_menuitem_new ();
+ dbusmenu_menuitem_property_set (child, "label", printer);
+ g_signal_connect (child,
+ "item-activated",
+ G_CALLBACK (show_system_settings),
+ NULL);
+
+ dbusmenu_menuitem_child_append(priv->root, child);
+ g_object_unref (child);
+}
+
+
+static void
+indicator_printers_menu_init (IndicatorPrintersMenu *self)
+{
+ IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self);
+
+ priv->root = dbusmenu_menuitem_new ();
+ add_printer_menuitem (self, "canon-mono-duplex");
+ add_printer_menuitem (self, "kitchen");
+}
+
+
+IndicatorPrintersMenu *
+indicator_printers_menu_new (void)
+{
+ return g_object_new (INDICATOR_TYPE_PRINTERS_MENU, NULL);
+}
+
+
+DbusmenuMenuitem *
+indicator_printers_menu_get_root (IndicatorPrintersMenu *self)
+{
+ IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self);
+ return priv->root;
+}
+