aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-01-11 15:29:38 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-01-11 15:29:38 +0100
commit4bfc1513316ecda883cd0053cfb9fd23c1fbc5e1 (patch)
treed6dd85b026d7b13136930708638091db62b49d0f /src
downloadayatana-indicator-printers-4bfc1513316ecda883cd0053cfb9fd23c1fbc5e1.tar.gz
ayatana-indicator-printers-4bfc1513316ecda883cd0053cfb9fd23c1fbc5e1.tar.bz2
ayatana-indicator-printers-4bfc1513316ecda883cd0053cfb9fd23c1fbc5e1.zip
Initial import
Includes indicator-printers plugin for unity-panel-service and indicator-printers-service, which generates a fairly useless menu for now.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am20
-rw-r--r--src/dbus-names.h32
-rw-r--r--src/indicator-printers-service.c135
-rw-r--r--src/indicator-printers.c149
-rw-r--r--src/indicator-printers.h69
5 files changed, 405 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..c5bdd52
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,20 @@
+
+printersmenulibdir = $(INDICATORDIR)
+printersmenulib_LTLIBRARIES = libprintersmenu.la
+libprintersmenu_la_SOURCES = \
+ indicator-printers.c \
+ indicator-printers.h
+
+libprintersmenu_la_CPPFLAGS = $(APPLET_CFLAGS)
+libprintersmenu_la_LIBADD = $(APPLET_LIBS)
+libprintersmenu_la_LDFLAGS = -module -avoid-version
+
+
+libexec_PROGRAMS = indicator-printers-service
+indicator_printers_service_SOURCES = \
+ indicator-printers-service.c \
+ indicator-printers-service.h
+
+indicator_printers_service_CPPFLAGS = $(SERVICE_CFLAGS)
+indicator_printers_service_LDADD = $(SERVICE_LIBS)
+
diff --git a/src/dbus-names.h b/src/dbus-names.h
new file mode 100644
index 0000000..0dac6e7
--- /dev/null
+++ b/src/dbus-names.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
+ *
+ * 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/>.
+ */
+
+#ifndef DBUS_NAMES_H
+#define DBUS_NAMES_H
+
+#define INDICATOR_PRINTERS_DBUS_NAME "com.canonical.indicator.printers"
+#define INDICATOR_PRINTERS_DBUS_OBJECT_PATH "/com/canonical/indicator/printers"
+#define INDICATOR_PRINTERS_DBUS_INTERFACE "com.canonical.indicator.printers"
+#define INDICATOR_PRINTERS_DBUS_VERSION 1
+
+#define CUPS_DBUS_NAME "org.cups.cupsd.Notifier"
+#define CUPS_DBUS_PATH "/org/cups/cupsd/Notifier"
+#define CUPS_DBUS_INTERFACE "org.cups.cupsd.Notifier"
+
+#endif
+
diff --git a/src/indicator-printers-service.c b/src/indicator-printers-service.c
new file mode 100644
index 0000000..c350ee0
--- /dev/null
+++ b/src/indicator-printers-service.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
+ *
+ * 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/>.
+ */
+
+#include <libindicator/indicator-service.h>
+#include <libdbusmenu-glib/dbusmenu-glib.h>
+#include <gtk/gtk.h>
+#include "dbus-names.h"
+
+
+static void
+service_shutdown (IndicatorService *service, gpointer user_data)
+{
+ g_debug("Shutting down indicator-printers-service");
+ gtk_main_quit ();
+}
+
+
+static void
+show_system_settings (DbusmenuMenuitem *menuitem,
+ guint timestamp,
+ gpointer user_data)
+{
+ GAppInfo *appinfo;
+ GError *err = NULL;
+
+ appinfo = g_app_info_create_from_commandline ("gnome-control-center printing",
+ "gnome-control-center",
+ G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION,
+ &err);
+ 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
+dbusmenu_menuitem_append_separator (DbusmenuMenuitem *item)
+{
+ DbusmenuMenuitem *separator;
+
+ separator = dbusmenu_menuitem_new();
+ dbusmenu_menuitem_property_set(separator,
+ "type",
+ DBUSMENU_CLIENT_TYPES_SEPARATOR);
+
+ dbusmenu_menuitem_child_append(item, separator);
+ g_object_unref (separator);
+}
+
+
+static void
+dbusmenu_menuitem_append_label (DbusmenuMenuitem *item,
+ const gchar *text,
+ GCallback activated,
+ gpointer user_data)
+{
+ DbusmenuMenuitem *child;
+
+ child = dbusmenu_menuitem_new ();
+ dbusmenu_menuitem_property_set (child, "label", text);
+ g_signal_connect (child, "item-activated", activated, user_data);
+
+ dbusmenu_menuitem_child_append(item, child);
+ g_object_unref (child);
+}
+
+
+static DbusmenuMenuitem *
+create_menu ()
+{
+ DbusmenuMenuitem *root;
+
+ root = dbusmenu_menuitem_new ();
+ dbusmenu_menuitem_append_separator (root);
+ dbusmenu_menuitem_append_label (root,
+ "Printer Settingsā€¦",
+ G_CALLBACK(show_system_settings),
+ NULL);
+ return root;
+}
+
+
+int main (int argc, char *argv[])
+{
+ IndicatorService *service;
+ DbusmenuServer *menuserver;
+ DbusmenuMenuitem *root;
+ GError *err = NULL;
+
+ gtk_init (&argc, &argv);
+
+ service = indicator_service_new_version (INDICATOR_PRINTERS_DBUS_NAME,
+ INDICATOR_PRINTERS_DBUS_VERSION);
+ g_signal_connect (service,
+ "shutdown",
+ G_CALLBACK (service_shutdown),
+ NULL);
+
+ menuserver = dbusmenu_server_new (INDICATOR_PRINTERS_DBUS_OBJECT_PATH);
+ root = create_menu ();
+ dbusmenu_server_set_root (menuserver, root);
+ g_object_unref (root);
+
+ gtk_main ();
+
+ g_object_unref (menuserver);
+ g_object_unref (service);
+ return 0;
+}
+
diff --git a/src/indicator-printers.c b/src/indicator-printers.c
new file mode 100644
index 0000000..1483d09
--- /dev/null
+++ b/src/indicator-printers.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
+ *
+ * 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/>.
+ */
+
+#include "config.h"
+
+#include "indicator-printers.h"
+#include "dbus-names.h"
+
+#include <gtk/gtk.h>
+
+#include <libindicator/indicator.h>
+#include <libindicator/indicator-image-helper.h>
+
+#include <libdbusmenu-gtk3/menu.h>
+#include <libdbusmenu-gtk3/menuitem.h>
+
+
+INDICATOR_SET_VERSION
+INDICATOR_SET_TYPE(INDICATOR_PRINTERS_TYPE)
+
+
+G_DEFINE_TYPE (IndicatorPrinters, indicator_printers, INDICATOR_OBJECT_TYPE)
+
+#define INDICATOR_PRINTERS_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_PRINTERS_TYPE, IndicatorPrintersPrivate))
+
+
+struct _IndicatorPrintersPrivate
+{
+ GtkImage *image;
+ gchar *accessible_desc;
+};
+
+
+static void
+dispose (GObject *object)
+{
+ IndicatorPrintersPrivate *priv = INDICATOR_PRINTERS_GET_PRIVATE (object);
+ g_clear_object (&priv->image);
+ G_OBJECT_CLASS (indicator_printers_parent_class)->dispose (object);
+}
+
+
+static void
+finalize (GObject *object)
+{
+ IndicatorPrintersPrivate *priv = INDICATOR_PRINTERS_GET_PRIVATE (object);
+ g_free (priv->accessible_desc);
+ G_OBJECT_CLASS (indicator_printers_parent_class)->finalize (object);
+}
+
+
+static GtkLabel *
+get_label (IndicatorObject *io)
+{
+ return NULL;
+}
+
+
+static GtkImage *
+get_image (IndicatorObject *io)
+{
+ IndicatorPrintersPrivate *priv = INDICATOR_PRINTERS_GET_PRIVATE (io);
+
+ if (!priv->image) {
+ priv->image = indicator_image_helper ("printer-symbolic");
+ g_object_ref_sink (priv->image);
+ }
+
+ gtk_widget_show (GTK_WIDGET (priv->image));
+ return priv->image;
+}
+
+
+static GtkMenu *
+get_menu (IndicatorObject *io)
+{
+ DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_PRINTERS_DBUS_NAME,
+ INDICATOR_PRINTERS_DBUS_OBJECT_PATH);
+ return GTK_MENU(menu);
+}
+
+
+static const gchar *
+get_accessible_desc (IndicatorObject * io)
+{
+ IndicatorPrintersPrivate *priv = INDICATOR_PRINTERS_GET_PRIVATE (io);
+ if (!priv->accessible_desc)
+ priv->accessible_desc = g_strdup ("Printers");
+ return priv->accessible_desc;
+}
+
+
+static const gchar *
+get_name_hint (IndicatorObject *io)
+{
+ return PACKAGE_NAME;
+}
+
+
+static void
+indicator_printers_class_init (IndicatorPrintersClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ IndicatorObjectClass *io_class = INDICATOR_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (IndicatorPrintersPrivate));
+
+ object_class->dispose = dispose;
+ object_class->finalize = finalize;
+
+ io_class->get_label = get_label;
+ io_class->get_image = get_image;
+ io_class->get_menu = get_menu;
+ io_class->get_accessible_desc = get_accessible_desc;
+ io_class->get_name_hint = get_name_hint;
+}
+
+
+static void
+indicator_printers_init (IndicatorPrinters *io)
+{
+ IndicatorPrintersPrivate *priv = INDICATOR_PRINTERS_GET_PRIVATE (io);
+
+ priv->accessible_desc = NULL;
+}
+
+
+IndicatorPrinters *
+indicator_printers_new (void)
+{
+ return g_object_new (INDICATOR_PRINTERS_TYPE, NULL);
+}
+
diff --git a/src/indicator-printers.h b/src/indicator-printers.h
new file mode 100644
index 0000000..0d97769
--- /dev/null
+++ b/src/indicator-printers.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
+ *
+ * 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/>.
+ */
+
+#ifndef INDICATOR_PRINTERS_H
+#define INDICATOR_PRINTERS_H
+
+#include <libindicator/indicator-object.h>
+
+G_BEGIN_DECLS
+
+#define INDICATOR_PRINTERS_TYPE indicator_printers_get_type()
+
+#define INDICATOR_PRINTERS(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ INDICATOR_PRINTERS_TYPE, IndicatorPrinters))
+
+#define INDICATOR_PRINTERS_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ INDICATOR_PRINTERS_TYPE, IndicatorPrintersClass))
+
+#define INDICATOR_IS_PRINTERS(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ INDICATOR_PRINTERS_TYPE))
+
+#define INDICATOR_IS_PRINTERS_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ INDICATOR_PRINTERS_TYPE))
+
+#define INDICATOR_PRINTERS_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ INDICATOR_PRINTERS_TYPE, IndicatorPrintersClass))
+
+typedef struct _IndicatorPrinters IndicatorPrinters;
+typedef struct _IndicatorPrintersClass IndicatorPrintersClass;
+typedef struct _IndicatorPrintersPrivate IndicatorPrintersPrivate;
+
+struct _IndicatorPrinters
+{
+ IndicatorObject parent;
+};
+
+struct _IndicatorPrintersClass
+{
+ IndicatorObjectClass parent_class;
+};
+
+GType indicator_printers_get_type (void) G_GNUC_CONST;
+
+IndicatorPrinters *indicator_printers_new (void);
+
+G_END_DECLS
+
+#endif
+