diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-01-11 15:29:38 +0100 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-01-11 15:29:38 +0100 |
commit | 4bfc1513316ecda883cd0053cfb9fd23c1fbc5e1 (patch) | |
tree | d6dd85b026d7b13136930708638091db62b49d0f | |
download | ayatana-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.
-rw-r--r-- | .bzrignore | 28 | ||||
-rw-r--r-- | AUTHORS | 2 | ||||
-rw-r--r-- | ChangeLog | 0 | ||||
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | NEWS | 0 | ||||
-rw-r--r-- | README | 0 | ||||
-rwxr-xr-x | autogen.sh | 9 | ||||
-rw-r--r-- | configure.ac | 34 | ||||
-rw-r--r-- | src/Makefile.am | 20 | ||||
-rw-r--r-- | src/dbus-names.h | 32 | ||||
-rw-r--r-- | src/indicator-printers-service.c | 135 | ||||
-rw-r--r-- | src/indicator-printers.c | 149 | ||||
-rw-r--r-- | src/indicator-printers.h | 69 |
13 files changed, 481 insertions, 0 deletions
diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 0000000..13759d0 --- /dev/null +++ b/.bzrignore @@ -0,0 +1,28 @@ +COPYING +INSTALL +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +compile +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +depcomp +install-sh +libtool +ltmain.sh +missing +stamp-h1 +src/.deps/ +src/.libs/ +src/Makefile +src/Makefile.in +src/indicator-printers-service +src/libprintersmenu.la +src/libprintersmenu_la-indicator-printers.lo + @@ -0,0 +1,2 @@ +Lars Uebernickel <lars.uebernickel@canonical.com> + diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ChangeLog diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..6b75694 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,3 @@ + +SUBDIRS = src + diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..5164b66 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +which gnome-autogen.sh || { + echo "Could not find 'gnome-autgen.sh'. Is gnome-common installed?" + exit 1 +} + +. gnome-autogen.sh + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..3c9160f --- /dev/null +++ b/configure.ac @@ -0,0 +1,34 @@ + +AC_INIT(indicator-printers, 0.1) + +AC_PREREQ(2.53) +AM_INIT_AUTOMAKE([]) + +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_LIBTOOL +AM_PROG_CC_C_O + +AC_CONFIG_HEADER(config.h) +AC_CONFIG_FILES([ + Makefile + src/Makefile +]) + +PKG_CHECK_MODULES(APPLET, gtk+-3.0 >= 3.0 + indicator3-0.4 >= 0.2 + dbusmenu-gtk3-0.4 >= 0.2) +PKG_CHECK_MODULES(SERVICE, gtk+-3.0 >= 3.0 + indicator3-0.4 >= 0.2 + dbusmenu-glib-0.4 >= 0.2) + +INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator3-0.4` +INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator3-0.4` + +AC_SUBST(INDICATORDIR) +AC_SUBST(INDICATORICONDIR) + +AC_SUBST(AM_CFLAGS, "-Wall") + +AC_OUTPUT + 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 + |