aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/indicator-menu-item.c395
-rw-r--r--src/indicator-menu-item.h81
-rw-r--r--src/indicator-printers-menu.c334
-rw-r--r--src/indicator-printers-menu.h76
-rw-r--r--src/indicator-printers.c303
-rw-r--r--src/indicator-printers.h70
6 files changed, 0 insertions, 1259 deletions
diff --git a/src/indicator-menu-item.c b/src/indicator-menu-item.c
deleted file mode 100644
index ed89a0f..0000000
--- a/src/indicator-menu-item.c
+++ /dev/null
@@ -1,395 +0,0 @@
-/*
- * 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 "indicator-menu-item.h"
-
-#include <math.h>
-
-struct _IndicatorMenuItemPrivate
-{
- GtkImage *image;
- GtkWidget *label;
- GtkWidget *right_label;
- gboolean right_is_lozenge;
-};
-
-G_DEFINE_TYPE_WITH_PRIVATE(IndicatorMenuItem, indicator_menu_item, GTK_TYPE_MENU_ITEM)
-
-enum {
- PROP_0,
- PROP_ICON,
- PROP_ICON_NAME,
- PROP_LABEL,
- PROP_RIGHT,
- PROP_RIGHT_IS_LOZENGE,
- N_PROPERTIES
-};
-
-static GParamSpec *properties[N_PROPERTIES];
-
-
-static gint
-gtk_widget_get_font_size (GtkWidget *widget)
-{
- const PangoFontDescription *font;
-
- gtk_style_context_get(gtk_widget_get_style_context(widget), gtk_widget_get_state_flags(widget), "font", &font, NULL);
-
- return pango_font_description_get_size (font) / PANGO_SCALE;
-}
-
-static void
-cairo_lozenge (cairo_t *cr, double x, double y, double w, double h)
-{
- double radius = MIN (w / 2.0, h / 2.0);
- double x1 = x + w - radius;
- double x2 = x + radius;
- double y1 = y + radius;
- double y2 = y + h - radius;
-
- cairo_move_to (cr, x+radius, y);
- cairo_arc (cr, x1, y1, radius, M_PI * 1.5, M_PI * 2);
- cairo_arc (cr, x1, y2, radius, 0, M_PI * 0.5);
- cairo_arc (cr, x2, y2, radius, M_PI * 0.5, M_PI);
- cairo_arc (cr, x2, y1, radius, M_PI, M_PI * 1.5);
-}
-
-static gboolean
-detail_label_draw (GtkWidget *widget,
- cairo_t *cr,
- gpointer data)
-{
- GtkAllocation allocation;
- double x, y, w, h;
- GdkRGBA color;
- PangoLayout *layout;
- PangoRectangle layout_extents;
- gboolean is_lozenge = *(gboolean *)data;
- gint font_size = gtk_widget_get_font_size (widget);
-
- /* let the label handle the drawing if it's not a lozenge */
- if (!is_lozenge)
- return FALSE;
-
- layout = gtk_label_get_layout (GTK_LABEL(widget));
- pango_layout_get_extents (layout, NULL, &layout_extents);
- pango_extents_to_pixels (&layout_extents, NULL);
-
- gtk_widget_get_allocation (widget, &allocation);
- x = -font_size / 2.0;
- y = 1;
- w = allocation.width;
- h = MIN (allocation.height, layout_extents.height + 4);
-
- if (layout_extents.width == 0)
- return TRUE;
-
- gtk_style_context_get_color (gtk_widget_get_style_context (widget),
- gtk_widget_get_state_flags (widget),
- &color);
- gdk_cairo_set_source_rgba (cr, &color);
-
- cairo_set_line_width (cr, 1.0);
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_lozenge (cr, x - font_size / 2.0, y, w + font_size, h);
-
- x += (w - layout_extents.width) / 2.0;
- y += (h - layout_extents.height) / 2.0;
- cairo_move_to (cr, floor (x), floor (y));
- pango_cairo_layout_path (cr, layout);
- cairo_fill (cr);
-
- return TRUE;
-}
-
-
-static void
-indicator_menu_item_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object);
-
- switch (property_id)
- {
- case PROP_ICON:
- g_value_set_object (value, indicator_menu_item_get_icon (self));
- break;
-
- case PROP_ICON_NAME:
- g_value_set_string (value, indicator_menu_item_get_icon_name (self));
- break;
-
- case PROP_LABEL:
- g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->priv->label)));
- break;
-
- case PROP_RIGHT:
- g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->priv->right_label)));
- break;
-
- case PROP_RIGHT_IS_LOZENGE:
- g_value_set_boolean (value, self->priv->right_is_lozenge);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
-}
-
-
-static void
-indicator_menu_item_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- switch (property_id)
- {
- case PROP_ICON:
- indicator_menu_item_set_icon (INDICATOR_MENU_ITEM (object),
- g_value_get_object (value));
- break;
-
- case PROP_ICON_NAME:
- indicator_menu_item_set_icon_name (INDICATOR_MENU_ITEM (object),
- g_value_get_string (value));
- break;
-
- case PROP_LABEL:
- indicator_menu_item_set_label (INDICATOR_MENU_ITEM (object),
- g_value_get_string (value));
- break;
-
- case PROP_RIGHT:
- indicator_menu_item_set_right (INDICATOR_MENU_ITEM (object),
- g_value_get_string (value));
- break;
-
- case PROP_RIGHT_IS_LOZENGE:
- indicator_menu_item_set_right_is_lozenge (INDICATOR_MENU_ITEM (object),
- g_value_get_boolean (value));
- break;
-
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
-}
-
-
-static void
-indicator_menu_item_dispose (GObject *object)
-{
- IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object);
-
- g_clear_object (&self->priv->image);
- g_clear_object (&self->priv->label);
- g_clear_object (&self->priv->right_label);
-
- G_OBJECT_CLASS (indicator_menu_item_parent_class)->dispose (object);
-}
-
-
-static void
-indicator_menu_item_class_init (IndicatorMenuItemClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = indicator_menu_item_get_property;
- object_class->set_property = indicator_menu_item_set_property;
- object_class->dispose = indicator_menu_item_dispose;
-
- properties[PROP_ICON] = g_param_spec_object ("icon",
- "Icon",
- "Icon for this menu item",
- GDK_TYPE_PIXBUF,
- G_PARAM_READWRITE);
-
- properties[PROP_ICON_NAME] = g_param_spec_string ("icon-name",
- "Icon name",
- "Name of the themed icon",
- "",
- G_PARAM_READWRITE);
-
- properties[PROP_LABEL] = g_param_spec_string ("label",
- "Label",
- "The text for the main label",
- "",
- G_PARAM_READWRITE);
-
- properties[PROP_RIGHT] = g_param_spec_string ("right",
- "Right",
- "The text on the right side of the menu item",
- "",
- G_PARAM_READWRITE);
-
- properties[PROP_RIGHT_IS_LOZENGE] = g_param_spec_boolean ("right-is-lozenge",
- "Right is a lozenge",
- "Whether the right label is displayed as a lonzenge",
- FALSE,
- G_PARAM_READWRITE);
-
- g_object_class_install_properties (object_class, N_PROPERTIES, properties);
-}
-
-
-static void
-indicator_menu_item_init (IndicatorMenuItem *self)
-{
- IndicatorMenuItemPrivate *priv;
- gint spacing;
- GtkWidget *hbox;
-
- priv = indicator_menu_item_get_instance_private(self);
- self->priv = priv;
-
- gtk_widget_style_get (GTK_WIDGET (self),
- "toggle-spacing", &spacing,
- NULL);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, spacing);
-
- priv->image = g_object_new (GTK_TYPE_IMAGE, NULL);
- g_object_ref_sink (priv->image);
- gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (priv->image), FALSE, FALSE, 0);
-
- priv->label = g_object_new (GTK_TYPE_LABEL,
- "xalign", 0.0,
- NULL);
- g_object_ref_sink (priv->label);
- gtk_box_pack_start (GTK_BOX (hbox), priv->label, TRUE, TRUE, 0);
-
- priv->right_label = g_object_new (GTK_TYPE_LABEL,
- "xalign", 1.0,
- "width-chars", 2,
- NULL);
- gtk_style_context_add_class (gtk_widget_get_style_context (priv->right_label),
- "accelerator");
- g_signal_connect (priv->right_label,
- "draw",
- G_CALLBACK (detail_label_draw),
- &priv->right_is_lozenge);
- g_object_ref_sink (priv->right_label);
- gtk_box_pack_start (GTK_BOX (hbox),
- priv->right_label,
- FALSE,
- FALSE,
- gtk_widget_get_font_size (priv->right_label) / 2.0 + 1);
-
- gtk_container_add (GTK_CONTAINER (self), hbox);
-
- priv->right_is_lozenge = FALSE;
-}
-
-
-IndicatorMenuItem *
-indicator_menu_item_new (void)
-{
- return g_object_new (INDICATOR_TYPE_MENU_ITEM, NULL);
-}
-
-
-const gchar *
-indicator_menu_item_get_label (IndicatorMenuItem *self)
-{
- return gtk_label_get_label (GTK_LABEL (self->priv->label));
-}
-
-
-void
-indicator_menu_item_set_label (IndicatorMenuItem *self,
- const gchar *text)
-{
- gtk_label_set_label (GTK_LABEL (self->priv->label), text);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]);
-}
-
-
-const gchar *
-indicator_menu_item_get_right (IndicatorMenuItem *self)
-{
- return gtk_label_get_label (GTK_LABEL (self->priv->right_label));
-}
-
-
-void
-indicator_menu_item_set_right (IndicatorMenuItem *self,
- const gchar *text)
-{
- gtk_label_set_label (GTK_LABEL (self->priv->right_label), text);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT]);
-}
-
-
-gboolean
-indicator_menu_item_get_right_is_lozenge (IndicatorMenuItem *self)
-{
- return self->priv->right_is_lozenge;
-}
-
-
-void
-indicator_menu_item_set_right_is_lozenge (IndicatorMenuItem *self,
- gboolean is_lozenge)
-{
- self->priv->right_is_lozenge = is_lozenge;
- gtk_widget_queue_draw (self->priv->right_label);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT_IS_LOZENGE]);
-}
-
-
-GdkPixbuf *
-indicator_menu_item_get_icon (IndicatorMenuItem *self)
-{
- if (gtk_image_get_storage_type (self->priv->image) == GTK_IMAGE_PIXBUF)
- return gtk_image_get_pixbuf (self->priv->image);
- else
- return NULL;
-}
-
-
-void
-indicator_menu_item_set_icon (IndicatorMenuItem *self,
- GdkPixbuf *icon)
-{
- gtk_image_set_from_pixbuf (self->priv->image, icon);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]);
-}
-
-
-const gchar *
-indicator_menu_item_get_icon_name (IndicatorMenuItem *self)
-{
- const gchar *name = NULL;
-
- if (gtk_image_get_storage_type (self->priv->image) == GTK_IMAGE_ICON_NAME)
- gtk_image_get_icon_name (self->priv->image, &name, NULL);
-
- return name;
-}
-
-
-void
-indicator_menu_item_set_icon_name (IndicatorMenuItem *self,
- const gchar *name)
-{
- gtk_image_set_from_icon_name (self->priv->image, name, GTK_ICON_SIZE_MENU);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON_NAME]);
-}
diff --git a/src/indicator-menu-item.h b/src/indicator-menu-item.h
deleted file mode 100644
index 84d6b74..0000000
--- a/src/indicator-menu-item.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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_MENU_ITEM_H
-#define INDICATOR_MENU_ITEM_H
-
-#include <gtk/gtk.h>
-
-G_BEGIN_DECLS
-
-#define INDICATOR_TYPE_MENU_ITEM indicator_menu_item_get_type()
-
-#define INDICATOR_MENU_ITEM(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
- INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItem))
-
-#define INDICATOR_MENU_ITEM_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), \
- INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItemClass))
-
-#define INDICATOR_IS_MENU_ITEM(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
- INDICATOR_TYPE_MENU_ITEM))
-
-#define INDICATOR_IS_MENU_ITEM_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
- INDICATOR_TYPE_MENU_ITEM))
-
-#define INDICATOR_MENU_ITEM_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
- INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItemClass))
-
-typedef struct _IndicatorMenuItem IndicatorMenuItem;
-typedef struct _IndicatorMenuItemClass IndicatorMenuItemClass;
-typedef struct _IndicatorMenuItemPrivate IndicatorMenuItemPrivate;
-
-struct _IndicatorMenuItem
-{
- GtkMenuItem parent;
- IndicatorMenuItemPrivate *priv;
-};
-
-struct _IndicatorMenuItemClass
-{
- GtkMenuItemClass parent_class;
-};
-
-GType indicator_menu_item_get_type (void) G_GNUC_CONST;
-
-IndicatorMenuItem *indicator_menu_item_new (void);
-
-const gchar * indicator_menu_item_get_label (IndicatorMenuItem *self);
-void indicator_menu_item_set_label (IndicatorMenuItem *self, const gchar *text);
-const gchar * indicator_menu_item_get_right (IndicatorMenuItem *self);
-void indicator_menu_item_set_right (IndicatorMenuItem *self, const gchar *text);
-
-gboolean indicator_menu_item_get_right_is_lozenge (IndicatorMenuItem *self);
-void indicator_menu_item_set_right_is_lozenge (IndicatorMenuItem *self, gboolean is_lozenge);
-const gchar * indicator_menu_item_get_icon_name (IndicatorMenuItem *self);
-void indicator_menu_item_set_icon (IndicatorMenuItem *self, GdkPixbuf *icon);
-GdkPixbuf * indicator_menu_item_get_icon (IndicatorMenuItem *self);
-void indicator_menu_item_set_icon_name (IndicatorMenuItem *self, const gchar *name);
-
-G_END_DECLS
-
-#endif
diff --git a/src/indicator-printers-menu.c b/src/indicator-printers-menu.c
deleted file mode 100644
index bf0bc07..0000000
--- a/src/indicator-printers-menu.c
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * 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 "indicator-printers-menu.h"
-
-#include <glib/gi18n.h>
-
-#include <cups/cups.h>
-
-#include "spawn-printer-settings.h"
-
-struct _IndicatorPrintersMenuPrivate
-{
- DbusmenuMenuitem *root;
- GHashTable *printers; /* printer name -> dbusmenuitem */
- CupsNotifier *cups_notifier;
-};
-
-G_DEFINE_TYPE_WITH_PRIVATE(IndicatorPrintersMenu, indicator_printers_menu, G_TYPE_OBJECT)
-
-enum {
- PROP_0,
- PROP_CUPS_NOTIFIER,
- NUM_PROPERTIES
-};
-
-static GParamSpec *properties[NUM_PROPERTIES];
-
-
-static void
-dispose (GObject *object)
-{
- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
-
- if (self->priv->printers) {
- g_hash_table_unref (self->priv->printers);
- self->priv->printers = NULL;
- }
-
- g_clear_object (&self->priv->root);
- g_clear_object (&self->priv->cups_notifier);
-
- G_OBJECT_CLASS (indicator_printers_menu_parent_class)->dispose (object);
-}
-
-
-void
-set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
-
- switch (property_id) {
- case PROP_CUPS_NOTIFIER:
- indicator_printers_menu_set_cups_notifier (self,
- g_value_get_object (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
-}
-
-
-void
-get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object);
-
- switch (property_id) {
- case PROP_CUPS_NOTIFIER:
- g_value_set_object (value,
- indicator_printers_menu_get_cups_notifier (self));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
-}
-
-
-static void
-indicator_printers_menu_class_init (IndicatorPrintersMenuClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = dispose;
- object_class->get_property = get_property;
- object_class->set_property = set_property;
-
- properties[PROP_CUPS_NOTIFIER] = g_param_spec_object ("cups-notifier",
- "Cups Notifier",
- "A cups notifier object",
- CUPS_TYPE_NOTIFIER,
- G_PARAM_READWRITE);
-
- g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
-}
-
-
-static void
-on_printer_item_activated (DbusmenuMenuitem *menuitem,
- guint timestamp,
- gpointer user_data)
-{
- const gchar *printer = user_data;
- spawn_printer_settings_with_args ("--show-jobs %s", printer);
-}
-
-
-static void
-update_indicator_visibility (IndicatorPrintersMenu *self)
-{
- GList *it;
- gboolean is_visible = FALSE;
-
- for (it = dbusmenu_menuitem_get_children (self->priv->root);
- it;
- it = g_list_next (it))
- {
- DbusmenuMenuitem *child = it->data;
- if ((is_visible = dbusmenu_menuitem_property_get_bool (child, "visible")))
- break;
- }
-
- dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", is_visible);
-}
-
-
-static void
-update_printer_menuitem (IndicatorPrintersMenu *self,
- const char *printer,
- int state)
-{
- DbusmenuMenuitem *item;
- int njobs;
- cups_job_t *jobs;
-
- njobs = cupsGetJobs (&jobs, printer, 1, CUPS_WHICHJOBS_ACTIVE);
- cupsFreeJobs (njobs, jobs);
-
- if (njobs < 0) {
- g_warning ("printer '%s' does not exist\n", printer);
- return;
- }
-
- item = g_hash_table_lookup (self->priv->printers, printer);
-
- if (!item) {
- item = dbusmenu_menuitem_new ();
- dbusmenu_menuitem_property_set (item, "type", "indicator-item");
- dbusmenu_menuitem_property_set (item, "indicator-icon-name", "printer");
- dbusmenu_menuitem_property_set (item, "indicator-label", printer);
- g_signal_connect_data (item, "item-activated",
- G_CALLBACK (on_printer_item_activated),
- g_strdup (printer), (GClosureNotify) g_free, 0);
-
- dbusmenu_menuitem_child_append(self->priv->root, item);
- g_hash_table_insert (self->priv->printers, g_strdup (printer), item);
- }
-
- if (njobs == 0) {
- dbusmenu_menuitem_property_set_bool (item, "visible", FALSE);
- update_indicator_visibility (self);
- return;
- }
-
- /* there are jobs for this printer. Make sure the indicator and the menu
- * item for that printer are shown */
- dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", TRUE);
- dbusmenu_menuitem_property_set_bool (item, "visible", TRUE);
-
- switch (state) {
- case IPP_PRINTER_STOPPED:
- dbusmenu_menuitem_property_set (item, "indicator-right", _("Paused"));
- dbusmenu_menuitem_property_set_bool (item, "indicator-right-is-lozenge", FALSE);
- break;
-
- case IPP_PRINTER_PROCESSING: {
- gchar *jobstr = g_strdup_printf ("%d", njobs);
- dbusmenu_menuitem_property_set (item, "indicator-right", jobstr);
- dbusmenu_menuitem_property_set_bool (item, "indicator-right-is-lozenge", TRUE);
- g_free (jobstr);
- break;
- }
- }
-}
-
-
-static void
-update_all_printer_menuitems (IndicatorPrintersMenu *self)
-{
- int ndests, i;
- cups_dest_t *dests;
-
- ndests = cupsGetDests (&dests);
- for (i = 0; i < ndests; i++) {
- const char *option = cupsGetOption ("printer-state",
- dests[i].num_options,
- dests[i].options);
- if (option != NULL) {
- int state = atoi (option);
- update_printer_menuitem (self, dests[i].name, state);
- }
- }
- cupsFreeDests (ndests, dests);
-}
-
-
-static void
-update_job (CupsNotifier *cups_notifier,
- const gchar *text,
- const gchar *printer_uri,
- const gchar *printer_name,
- guint printer_state,
- const gchar *printer_state_reasons,
- gboolean printer_is_accepting_jobs,
- guint job_id,
- guint job_state,
- const gchar *job_state_reasons,
- const gchar *job_name,
- guint job_impressions_completed,
- gpointer user_data)
-{
- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (user_data);
-
- /* CUPS doesn't send the printer's name for these events. Update all menu
- * items as a temporary workaround */
- if (job_state == IPP_JOB_CANCELLED ||
- job_state == IPP_JOB_ABORTED ||
- job_state == IPP_JOB_COMPLETED)
- update_all_printer_menuitems (self);
- else
- update_printer_menuitem (self, printer_name, printer_state);
-}
-
-
-static void
-on_printer_state_changed (CupsNotifier *object,
- const gchar *text,
- const gchar *printer_uri,
- const gchar *printer_name,
- guint printer_state,
- const gchar *printer_state_reasons,
- gboolean printer_is_accepting_jobs,
- gpointer user_data)
-{
- IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (user_data);
-
- update_printer_menuitem (self, printer_name, printer_state);
-}
-
-
-static void
-indicator_printers_menu_init (IndicatorPrintersMenu *self)
-{
- self->priv = indicator_printers_menu_get_instance_private(self);
-
- self->priv->root = dbusmenu_menuitem_new ();
- dbusmenu_menuitem_property_set_bool (self->priv->root, "visible", FALSE);
-
- self->priv->printers = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_object_unref);
-
- /* create initial menu items */
- update_all_printer_menuitems (self);
-}
-
-
-IndicatorPrintersMenu *
-indicator_printers_menu_new (void)
-{
- return g_object_new (INDICATOR_TYPE_PRINTERS_MENU, NULL);
-}
-
-
-DbusmenuMenuitem *
-indicator_printers_menu_get_root (IndicatorPrintersMenu *self)
-{
- return self->priv->root;
-}
-
-
-CupsNotifier *
-indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self)
-{
- return self->priv->cups_notifier;
-}
-
-
-void
-indicator_printers_menu_set_cups_notifier (IndicatorPrintersMenu *self,
- CupsNotifier *cups_notifier)
-{
- if (self->priv->cups_notifier) {
- g_object_disconnect (self->priv->cups_notifier,
- "any-signal", update_job, self,
- "any-signal", on_printer_state_changed, self,
- NULL);
- g_clear_object (&self->priv->cups_notifier);
- }
-
- if (cups_notifier) {
- self->priv->cups_notifier = g_object_ref (cups_notifier);
- g_object_connect (self->priv->cups_notifier,
- "signal::job-created", update_job, self,
- "signal::job-state", update_job, self,
- "signal::job-completed", update_job, self,
- "signal::printer-state-changed", on_printer_state_changed, self,
- NULL);
- }
-}
diff --git a/src/indicator-printers-menu.h b/src/indicator-printers-menu.h
deleted file mode 100644
index c10f221..0000000
--- a/src/indicator-printers-menu.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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_MENU_H
-#define INDICATOR_PRINTERS_MENU_H
-
-#include <glib-object.h>
-#include <libdbusmenu-glib/dbusmenu-glib.h>
-
-#include "cups-notifier.h"
-
-G_BEGIN_DECLS
-
-#define INDICATOR_TYPE_PRINTERS_MENU indicator_printers_menu_get_type()
-
-#define INDICATOR_PRINTERS_MENU(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
- INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenu))
-
-#define INDICATOR_PRINTERS_MENU_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), \
- INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenuClass))
-
-#define INDICATOR_IS_PRINTERS_MENU(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
- INDICATOR_TYPE_PRINTERS_MENU))
-
-#define INDICATOR_IS_PRINTERS_MENU_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
- INDICATOR_TYPE_PRINTERS_MENU))
-
-#define INDICATOR_PRINTERS_MENU_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
- INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenuClass))
-
-typedef struct _IndicatorPrintersMenu IndicatorPrintersMenu;
-typedef struct _IndicatorPrintersMenuClass IndicatorPrintersMenuClass;
-typedef struct _IndicatorPrintersMenuPrivate IndicatorPrintersMenuPrivate;
-
-struct _IndicatorPrintersMenu
-{
- GObject parent;
- IndicatorPrintersMenuPrivate *priv;
-};
-
-struct _IndicatorPrintersMenuClass
-{
- GObjectClass parent_class;
-};
-
-GType indicator_printers_menu_get_type (void) G_GNUC_CONST;
-
-IndicatorPrintersMenu *indicator_printers_menu_new (void);
-DbusmenuMenuitem * indicator_printers_menu_get_root (IndicatorPrintersMenu *menu);
-CupsNotifier * indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self);
-void indicator_printers_menu_set_cups_notifier (IndicatorPrintersMenu *self,
- CupsNotifier *cups_notifier);
-
-G_END_DECLS
-
-#endif
diff --git a/src/indicator-printers.c b/src/indicator-printers.c
deleted file mode 100644
index 2b7bb36..0000000
--- a/src/indicator-printers.c
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * Copyright 2012 Canonical Ltd.
- * Copyright 2022 Robert Tari
- *
- * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
- * Robert Tari <robert@tari.in>
- *
- * 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 "indicator-printers.h"
-#include "indicator-menu-item.h"
-#include "dbus-names.h"
-
-#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-#include <gio/gio.h>
-
-#include <libayatana-indicator/indicator.h>
-#include <libayatana-indicator/indicator-image-helper.h>
-
-#include <libdbusmenu-gtk/menu.h>
-#include <libdbusmenu-gtk/menuitem.h>
-
-
-INDICATOR_SET_VERSION
-INDICATOR_SET_TYPE(INDICATOR_PRINTERS_TYPE)
-
-struct _IndicatorPrintersPrivate
-{
- IndicatorObjectEntry entry;
- guint name_watch;
-};
-
-G_DEFINE_TYPE_WITH_PRIVATE(IndicatorPrinters, indicator_printers, INDICATOR_OBJECT_TYPE)
-
-static void
-dispose (GObject *object)
-{
- IndicatorPrinters *self = INDICATOR_PRINTERS (object);
- if (self->priv->name_watch != 0) {
- g_bus_unwatch_name(self->priv->name_watch);
- self->priv->name_watch = 0;
- }
- g_clear_object (&self->priv->entry.menu);
- g_clear_object (&self->priv->entry.image);
- G_OBJECT_CLASS (indicator_printers_parent_class)->dispose (object);
-}
-
-
-static GList *
-get_entries (IndicatorObject *io)
-{
- IndicatorPrinters *self = INDICATOR_PRINTERS (io);
- return g_list_append (NULL, &self->priv->entry);
-}
-
-
-static void
-indicator_printers_class_init (IndicatorPrintersClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- IndicatorObjectClass *io_class = INDICATOR_OBJECT_CLASS (klass);
-
- object_class->dispose = dispose;
-
- io_class->get_entries = get_entries;
-}
-
-
-static void
-name_vanished (GDBusConnection * con,
- const gchar * name,
- gpointer user_data)
-{
- IndicatorPrinters *self = INDICATOR_PRINTERS (user_data);
-
- indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE);
-}
-
-
-static GdkPixbuf *
-gdk_pixbuf_new_from_encoded_data (guchar *data,
- gsize length)
-{
- GInputStream * input;
- GError *err = NULL;
- GdkPixbuf *img;
-
- input = g_memory_input_stream_new_from_data(data, length, NULL);
- if (input == NULL)
- return NULL;
-
- img = gdk_pixbuf_new_from_stream(input, NULL, &err);
- if (err) {
- g_warning("%s", err->message);
- g_error_free(err);
- }
-
- g_object_unref(input);
- return img;
-}
-
-
-static GdkPixbuf *
-g_variant_get_image (GVariant *value)
-{
- const gchar *strvalue = NULL;
- gsize length = 0;
- guchar *icondata;
- GdkPixbuf *img;
-
- if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
- strvalue = g_variant_get_string(value, NULL);
-
- if (!strvalue || !*strvalue) {
- g_warning ("%s: value does not contain a base64 encoded image",
- __func__);
- return NULL;
- }
-
- icondata = g_base64_decode(strvalue, &length);
- img = gdk_pixbuf_new_from_encoded_data (icondata, length);
-
- g_free(icondata);
- return img;
-}
-
-
-static gboolean
-properties_match (const gchar *name,
- const gchar *prop,
- GVariant *value,
- const GVariantType *type)
-{
- return !g_strcmp0 (name, prop) && g_variant_is_of_type (value, type);
-}
-
-
-static void
-indicator_prop_change_cb (DbusmenuMenuitem *mi,
- gchar *prop,
- GVariant *value,
- gpointer user_data)
-{
- IndicatorMenuItem *menuitem = user_data;
-
- if (properties_match (prop, "indicator-label", value, G_VARIANT_TYPE_STRING))
- indicator_menu_item_set_label (menuitem, g_variant_get_string (value, NULL));
-
- else if (properties_match (prop, "indicator-right", value, G_VARIANT_TYPE_STRING))
- indicator_menu_item_set_right (menuitem, g_variant_get_string (value, NULL));
-
- else if (properties_match (prop, "indicator-icon-name", value, G_VARIANT_TYPE_STRING))
- indicator_menu_item_set_icon_name (menuitem, g_variant_get_string (value, NULL));
-
- else if (properties_match (prop, "indicator-icon", value, G_VARIANT_TYPE_STRING)) {
- GdkPixbuf *pb = g_variant_get_image (value);
- indicator_menu_item_set_icon (menuitem, pb);
- g_object_unref (pb);
- }
-
- else if (properties_match (prop, "visible", value, G_VARIANT_TYPE_BOOLEAN))
- gtk_widget_set_visible (GTK_WIDGET (menuitem), g_variant_get_boolean (value));
-
- else if (properties_match (prop, "indicator-right-is-lozenge", value, G_VARIANT_TYPE_BOOLEAN))
- indicator_menu_item_set_right_is_lozenge (menuitem, g_variant_get_boolean (value));
-}
-
-
-static void
-root_property_changed (DbusmenuMenuitem *mi,
- gchar *prop,
- GVariant *value,
- gpointer user_data)
-{
- IndicatorObject *io = user_data;
-
- if (properties_match (prop, "visible", value, G_VARIANT_TYPE_BOOLEAN))
- indicator_object_set_visible (io, g_variant_get_boolean (value));
-}
-
-
-static gboolean
-new_indicator_item (DbusmenuMenuitem *newitem,
- DbusmenuMenuitem *parent,
- DbusmenuClient *client,
- gpointer user_data)
-{
- GtkWidget *menuitem;
- const gchar *icon_name, *text, *right_text;
- GVariant *icon;
- gboolean is_lozenge, visible;
-
- icon_name = dbusmenu_menuitem_property_get (newitem, "indicator-icon-name");
- icon = dbusmenu_menuitem_property_get_variant (newitem, "indicator-icon");
- text = dbusmenu_menuitem_property_get (newitem, "indicator-label");
- right_text = dbusmenu_menuitem_property_get (newitem, "indicator-right");
- is_lozenge = dbusmenu_menuitem_property_get_bool (newitem, "indicator-right-is-lozenge");
- visible = dbusmenu_menuitem_property_get_bool (newitem, "visible");
-
- menuitem = g_object_new (INDICATOR_TYPE_MENU_ITEM,
- "icon-name", icon_name,
- "label", text,
- "right", right_text,
- "right-is-lozenge", is_lozenge,
- "visible", visible,
- NULL);
- if (icon) {
- GdkPixbuf *pb = g_variant_get_image (icon);
- indicator_menu_item_set_icon (INDICATOR_MENU_ITEM (menuitem), pb);
- g_object_unref (pb);
- }
- gtk_widget_show_all (menuitem);
-
- dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
- newitem,
- GTK_MENU_ITEM (menuitem),
- parent);
-
- g_signal_connect(G_OBJECT(newitem),
- "property-changed",
- G_CALLBACK(indicator_prop_change_cb),
- menuitem);
-
- return TRUE;
-}
-
-
-static void
-root_changed (DbusmenuClient *client,
- DbusmenuMenuitem *newroot,
- gpointer user_data)
-{
- IndicatorPrinters *indicator = user_data;
- gboolean is_visible;
-
- if (newroot) {
- is_visible = dbusmenu_menuitem_property_get_bool (newroot, "visible");
- g_signal_connect (newroot, "property-changed",
- G_CALLBACK (root_property_changed), indicator);
- }
- else
- is_visible = FALSE;
-
- indicator_object_set_visible (INDICATOR_OBJECT (indicator), is_visible);
-}
-
-
-static void
-indicator_printers_init (IndicatorPrinters *self)
-{
- IndicatorPrintersPrivate *priv;
- DbusmenuGtkMenu *menu;
- DbusmenuClient *client;
- GtkImage *image;
-
- priv = indicator_printers_get_instance_private(self);
- self->priv = priv;
-
- priv->name_watch = g_bus_watch_name(G_BUS_TYPE_SESSION,
- INDICATOR_PRINTERS_DBUS_NAME,
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- NULL, /* appeared */
- name_vanished,
- self, NULL);
-
- menu = dbusmenu_gtkmenu_new(INDICATOR_PRINTERS_DBUS_NAME,
- INDICATOR_PRINTERS_DBUS_OBJECT_PATH);
-
- client = DBUSMENU_CLIENT (dbusmenu_gtkmenu_get_client (menu));
- dbusmenu_client_add_type_handler(client,
- "indicator-item",
- new_indicator_item);
- g_signal_connect (client, "root-changed", G_CALLBACK (root_changed), self);
-
- image = indicator_image_helper ("printer-symbolic");
- gtk_widget_show (GTK_WIDGET (image));
-
- priv->entry.name_hint = PACKAGE_NAME;
- priv->entry.accessible_desc = _("Printers");
- priv->entry.menu = GTK_MENU (g_object_ref_sink (menu));
- priv->entry.image = g_object_ref_sink (image);
-
- indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE);
-}
-
-
-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
deleted file mode 100644
index 51b790c..0000000
--- a/src/indicator-printers.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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 <libayatana-indicator/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;
- IndicatorPrintersPrivate *priv;
-};
-
-struct _IndicatorPrintersClass
-{
- IndicatorObjectClass parent_class;
-};
-
-GType indicator_printers_get_type (void) G_GNUC_CONST;
-
-IndicatorPrinters *indicator_printers_new (void);
-
-G_END_DECLS
-
-#endif
-