aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-02-12 14:11:27 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-02-12 14:11:27 +0100
commitc3b56f70cd7305b1ddcc052cea808afb7b987856 (patch)
tree64754406304d4d766be6a6ba087bb85bfc1756fa /src
parenta796e6d7df042dacb147dbf4dc31df1909f0cc41 (diff)
downloadayatana-indicator-printers-c3b56f70cd7305b1ddcc052cea808afb7b987856.tar.gz
ayatana-indicator-printers-c3b56f70cd7305b1ddcc052cea808afb7b987856.tar.bz2
ayatana-indicator-printers-c3b56f70cd7305b1ddcc052cea808afb7b987856.zip
Only show print indicator when there are print jobs
Note: this doesn't fully implement the design spec yet, as the menu should stay visible 5 seconds after the last print job finished.
Diffstat (limited to 'src')
-rw-r--r--src/indicator-printers-menu.c24
-rw-r--r--src/indicator-printers.c36
2 files changed, 60 insertions, 0 deletions
diff --git a/src/indicator-printers-menu.c b/src/indicator-printers-menu.c
index 58bd72a..bc98cf3 100644
--- a/src/indicator-printers-menu.c
+++ b/src/indicator-printers-menu.c
@@ -138,6 +138,25 @@ on_printer_item_activated (DbusmenuMenuitem *menuitem,
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)
@@ -171,9 +190,13 @@ update_printer_menuitem (IndicatorPrintersMenu *self,
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) {
@@ -241,6 +264,7 @@ indicator_printers_menu_init (IndicatorPrintersMenu *self)
IndicatorPrintersMenuPrivate);
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,
diff --git a/src/indicator-printers.c b/src/indicator-printers.c
index 1a285e9..bcb0579 100644
--- a/src/indicator-printers.c
+++ b/src/indicator-printers.c
@@ -162,6 +162,19 @@ indicator_prop_change_cb (DbusmenuMenuitem *mi,
}
+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,
@@ -209,6 +222,26 @@ new_indicator_item (DbusmenuMenuitem *newitem,
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;
@@ -228,6 +261,7 @@ indicator_printers_init (IndicatorPrinters *self)
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));
@@ -236,6 +270,8 @@ indicator_printers_init (IndicatorPrinters *self)
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);
}