[Xfce4-commits] <xfce4-indicator-plugin:andrzejr/tmp3> Configuration system rework.
Andrzej
noreply at xfce.org
Mon Mar 11 03:18:01 CET 2013
Updating branch refs/heads/andrzejr/tmp3
to 86c62c471dcaf3f2a9b84a501e9e49d2ffc1152e (commit)
from 94c371f5760b00df1cbba141a12c3192aa339e2b (commit)
commit 86c62c471dcaf3f2a9b84a501e9e49d2ffc1152e
Author: Andrzej <ndrwrdck at gmail.com>
Date: Mon Mar 11 02:17:21 2013 +0000
Configuration system rework.
Abstracted out configuration settings. All xfconf, configuration and
dialog properies are now bound.
Reworked parts of box and button classes to match the configuration
system better.
At the moment, filtering options (white/blacklists) work only at start-up.
Not sure if libindicator allows unloading indicator modules.
Also, for now, indicator sorting does not change the indicator order in
the container.
panel-plugin/Makefile.am | 2 +
panel-plugin/indicator-box.c | 326 +++-------------
panel-plugin/indicator-box.h | 52 +---
panel-plugin/indicator-button.c | 114 ++++--
panel-plugin/indicator-button.h | 34 +--
panel-plugin/indicator-config.c | 774 +++++++++++++++++++++++++++++++++++
panel-plugin/indicator-config.h | 103 +++++
panel-plugin/indicator-dialog.c | 348 +++++++++++++++--
panel-plugin/indicator-dialog.glade | 130 +++----
panel-plugin/indicator-dialog.h | 5 +-
panel-plugin/indicator.c | 146 ++-----
11 files changed, 1440 insertions(+), 594 deletions(-)
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 80c33f0..fcec7f7 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -19,6 +19,8 @@ libindicator_built_sources = \
libindicator_plugin_la_SOURCES = \
$(libindicator_built_sources) \
+ indicator-config.c \
+ indicator-config.h \
indicator-button.c \
indicator-button.h \
indicator-box.c \
diff --git a/panel-plugin/indicator-box.c b/panel-plugin/indicator-box.c
index 854f4a4..2766bc1 100644
--- a/panel-plugin/indicator-box.c
+++ b/panel-plugin/indicator-box.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 Andrzej <ndrwrdck at gmail.com>
+/* Copyright (c) 2012-2013 Andrzej <ndrwrdck at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,14 +34,6 @@
#include "indicator-button.h"
static void xfce_indicator_box_finalize (GObject *object);
-static void xfce_indicator_box_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void xfce_indicator_box_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
static void xfce_indicator_box_add (GtkContainer *container,
GtkWidget *child);
static void xfce_indicator_box_remove (GtkContainer *container,
@@ -55,23 +47,31 @@ static void xfce_indicator_box_size_request (GtkWidget
GtkRequisition *requisition);
static void xfce_indicator_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static gint xfce_indicator_box_get_row_size (XfceIndicatorBox *box);
-enum
+struct _XfceIndicatorBox
{
- PROP_0,
- PROP_ICON_SIZE_MAX,
- PROP_ALIGN_LEFT
+ GtkContainer __parent__;
+
+ IndicatorConfig *config;
+
+ GSList *children;
+
+ gint panel_size;
+ gint nrows;
+ gint icon_size_max;
+ gboolean align_left;
+
+ GtkOrientation panel_orientation;
+ GtkOrientation orientation;
};
-enum
+struct _XfceIndicatorBoxClass
{
- BOX_LAYOUT_CHANGED,
- LAST_SIGNAL
+ GtkContainerClass __parent__;
};
-static guint xfce_indicator_box_signals[LAST_SIGNAL] = { 0, };
+
G_DEFINE_TYPE (XfceIndicatorBox, xfce_indicator_box, GTK_TYPE_CONTAINER)
@@ -85,8 +85,6 @@ xfce_indicator_box_class_init (XfceIndicatorBoxClass *klass)
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = xfce_indicator_box_finalize;
- gobject_class->get_property = xfce_indicator_box_get_property;
- gobject_class->set_property = xfce_indicator_box_set_property;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->size_request = xfce_indicator_box_size_request;
@@ -97,28 +95,6 @@ xfce_indicator_box_class_init (XfceIndicatorBoxClass *klass)
gtkcontainer_class->remove = xfce_indicator_box_remove;
gtkcontainer_class->forall = xfce_indicator_box_forall;
gtkcontainer_class->child_type = xfce_indicator_box_child_type;
-
- g_object_class_install_property (gobject_class,
- PROP_ICON_SIZE_MAX,
- g_param_spec_uint ("icon-size-max",
- NULL, NULL,
- 1,
- 128,
- 24,
- EXO_PARAM_READWRITE));
- g_object_class_install_property (gobject_class,
- PROP_ALIGN_LEFT,
- g_param_spec_boolean ("align-left", NULL, NULL,
- FALSE,
- EXO_PARAM_READWRITE));
-
- xfce_indicator_box_signals[BOX_LAYOUT_CHANGED] =
- g_signal_new (g_intern_static_string ("box-layout-changed"),
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
}
@@ -132,13 +108,6 @@ xfce_indicator_box_init (XfceIndicatorBox *box)
gtk_container_set_border_width(GTK_CONTAINER(box), 0);
box->children = NULL;
-
- box->nrows = 1;
- box->icon_size_max = 24;
- box->align_left = FALSE;
- box->panel_size = 16;
- box->panel_orientation = GTK_ORIENTATION_HORIZONTAL;
- box->orientation = GTK_ORIENTATION_HORIZONTAL;
}
@@ -159,137 +128,12 @@ xfce_indicator_box_finalize (GObject *object)
-static void
-xfce_indicator_box_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- XfceIndicatorBox *box = XFCE_INDICATOR_BOX (object);
-
- switch (prop_id)
- {
- case PROP_ICON_SIZE_MAX:
- g_value_set_uint (value, box->icon_size_max);
- break;
-
- case PROP_ALIGN_LEFT:
- g_value_set_boolean (value, box->align_left);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-
-
-static void
-xfce_indicator_box_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- XfceIndicatorBox *box = XFCE_INDICATOR_BOX (object);
- gint val;
-
- switch (prop_id)
- {
- case PROP_ICON_SIZE_MAX:
- val = g_value_get_uint (value);
- if (box->icon_size_max != val)
- {
- box->icon_size_max = val;
- g_signal_emit (G_OBJECT (box), xfce_indicator_box_signals[BOX_LAYOUT_CHANGED], 0);
- }
- break;
-
- case PROP_ALIGN_LEFT:
- val = g_value_get_boolean (value);
- if (box->align_left != val)
- {
- box->align_left = val;
- g_signal_emit (G_OBJECT (box), xfce_indicator_box_signals[BOX_LAYOUT_CHANGED], 0);
- }
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-
-
-void
-xfce_indicator_box_set_orientation (XfceIndicatorBox *box,
- GtkOrientation panel_orientation,
- GtkOrientation orientation)
-{
- gboolean needs_update = FALSE;
-
- g_return_if_fail (XFCE_IS_INDICATOR_BOX (box));
-
- if (box->orientation != orientation)
- {
- box->orientation = orientation;
- needs_update = TRUE;
- }
-
- if (box->panel_orientation != panel_orientation)
- {
- box->panel_orientation = panel_orientation;
- needs_update = TRUE;
- }
-
- if (needs_update)
- {
- g_signal_emit (G_OBJECT (box), xfce_indicator_box_signals[BOX_LAYOUT_CHANGED], 0);
- gtk_widget_queue_resize (GTK_WIDGET (box));
- }
-}
-
-
-
-void
-xfce_indicator_box_set_size (XfceIndicatorBox *box,
- gint panel_size,
- gint nrows)
-{
- gboolean needs_update = FALSE;
-
- g_return_if_fail (XFCE_IS_INDICATOR_BOX (box));
-
- if (box->nrows != nrows)
- {
- box->nrows = nrows;
- needs_update = TRUE;
- }
-
- if (box->panel_size != panel_size)
- {
- box->panel_size = panel_size;
- needs_update = TRUE;
- }
-
- if (needs_update)
- {
- g_signal_emit (G_OBJECT (box), xfce_indicator_box_signals[BOX_LAYOUT_CHANGED], 0);
- gtk_widget_queue_resize (GTK_WIDGET (box));
- }
-}
-
-
-
GtkWidget *
-xfce_indicator_box_new (XfcePanelPlugin *plugin)
+xfce_indicator_box_new (IndicatorConfig *config)
{
XfceIndicatorBox *box = g_object_new (XFCE_TYPE_INDICATOR_BOX, NULL);
- box->plugin = plugin;
- if (box->plugin != NULL)
- g_object_ref (G_OBJECT (box->plugin));
+ box->config = config;
return GTK_WIDGET (box);
}
@@ -366,6 +210,26 @@ xfce_indicator_box_child_type (GtkContainer *container)
+static gint
+xfce_indicator_box_get_row_size (XfceIndicatorBox *box)
+{
+ gint border_thickness;
+ GtkStyle *style;
+
+ g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), 24);
+
+ style = gtk_widget_get_style (GTK_WIDGET (box));
+ border_thickness = 2 * MAX (style->xthickness, style->ythickness) + 2;
+
+ return MIN (indicator_config_get_panel_size (box->config) /
+ indicator_config_get_nrows (box->config),
+ indicator_config_get_icon_size_max (box->config) + border_thickness);
+}
+
+
+
+
+
static void
xfce_indicator_box_size_request (GtkWidget *widget,
GtkRequisition *requisition)
@@ -380,12 +244,14 @@ xfce_indicator_box_size_request (GtkWidget *widget,
gint nrows;
gint x;
gboolean has_label;
+ GtkOrientation panel_orientation;
- panel_size = box->panel_size;
+ panel_size = indicator_config_get_panel_size (box->config);
+ panel_orientation = indicator_config_get_panel_orientation (box->config);
row = 0;
length = 0;
x = 0;
- nrows = xfce_indicator_box_get_nrows (box);
+ nrows = panel_size / xfce_indicator_box_get_row_size (box);
for (li = box->children; li != NULL; li = li->next)
{
@@ -404,7 +270,7 @@ xfce_indicator_box_size_request (GtkWidget *widget,
}
length =
- MAX (length, (box->panel_orientation == GTK_ORIENTATION_HORIZONTAL) ? child_req.width :child_req.height);
+ MAX (length, (panel_orientation == GTK_ORIENTATION_HORIZONTAL) ? child_req.width :child_req.height);
if (has_label || row >= nrows)
{
@@ -420,7 +286,7 @@ xfce_indicator_box_size_request (GtkWidget *widget,
x += length;
- if (box->panel_orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (panel_orientation == GTK_ORIENTATION_HORIZONTAL)
{
requisition->width = x;
requisition->height = panel_size;
@@ -451,6 +317,7 @@ xfce_indicator_box_size_allocate (GtkWidget *widget,
gint row;
gint nrows;
gboolean has_label;
+ GtkOrientation panel_orientation;
row = 0;
length = 0;
@@ -459,8 +326,9 @@ xfce_indicator_box_size_allocate (GtkWidget *widget,
x0 = allocation->x;
y0 = allocation->y;
- nrows = xfce_indicator_box_get_nrows (box);
- panel_size = box->panel_size;
+ panel_size = indicator_config_get_panel_size (box->config);
+ panel_orientation = indicator_config_get_panel_orientation (box->config);
+ nrows = panel_size / xfce_indicator_box_get_row_size (box);
size = panel_size / nrows;
for (li = box->children; li != NULL; li = li->next)
@@ -483,9 +351,9 @@ xfce_indicator_box_size_allocate (GtkWidget *widget,
width = (has_label) ? panel_size : size;
length = MAX (length,
- (box->panel_orientation == GTK_ORIENTATION_HORIZONTAL) ? child_req.width :child_req.height);
+ (panel_orientation == GTK_ORIENTATION_HORIZONTAL) ? child_req.width :child_req.height);
- if (box->panel_orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (panel_orientation == GTK_ORIENTATION_HORIZONTAL)
{
child_alloc.x = x0 + x;
child_alloc.y = y0 + y;
@@ -522,21 +390,6 @@ xfce_indicator_box_size_allocate (GtkWidget *widget,
-static gint
-xfce_indicator_box_get_row_size (XfceIndicatorBox *box)
-{
- gint border_thickness;
- GtkStyle *style;
-
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), 24);
-
- style = gtk_widget_get_style (GTK_WIDGET (box));
- border_thickness = 2 * MAX (style->xthickness, style->ythickness) + 2;
-
- return MIN (box->panel_size / box->nrows, box->icon_size_max + border_thickness);
-}
-
-
void
xfce_indicator_box_remove_entry (XfceIndicatorBox *box,
IndicatorObjectEntry *entry)
@@ -561,78 +414,3 @@ xfce_indicator_box_remove_entry (XfceIndicatorBox *box,
}
}
-
-
-
-
-GtkOrientation
-xfce_indicator_box_get_panel_orientation (XfceIndicatorBox *box)
-{
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), GTK_ORIENTATION_HORIZONTAL);
-
- return box->panel_orientation;
-}
-
-
-GtkOrientation
-xfce_indicator_box_get_indicator_orientation (XfceIndicatorBox *box)
-{
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), GTK_ORIENTATION_HORIZONTAL);
-
- return box->orientation;
-}
-
-
-gint
-xfce_indicator_box_get_nrows (XfceIndicatorBox *box)
-{
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), 0);
-
- return box->panel_size / xfce_indicator_box_get_row_size (box);
-
-}
-
-
-gint
-xfce_indicator_box_get_panel_size (XfceIndicatorBox *box)
-{
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), 0);
-
- return box->panel_size;
-}
-
-
-gint
-xfce_indicator_box_get_indicator_size (XfceIndicatorBox *box)
-{
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), 0);
-
- return xfce_indicator_box_get_row_size (box);
-}
-
-
-gint
-xfce_indicator_box_get_icon_size_max (XfceIndicatorBox *box)
-{
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), 0);
-
- return box->icon_size_max;
-}
-
-
-gboolean
-xfce_indicator_box_get_align_left (XfceIndicatorBox *box)
-{
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), FALSE);
-
- return box->align_left;
-}
-
-
-XfcePanelPlugin *
-xfce_indicator_box_get_plugin (XfceIndicatorBox *box)
-{
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (box), NULL);
-
- return box->plugin;
-}
diff --git a/panel-plugin/indicator-box.h b/panel-plugin/indicator-box.h
index d0746c8..8647e04 100644
--- a/panel-plugin/indicator-box.h
+++ b/panel-plugin/indicator-box.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 Andrzej <ndrwrdck at gmail.com>
+/* Copyright (c) 2012-2013 Andrzej <ndrwrdck at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
#include <gtk/gtk.h>
#include <libindicator/indicator-object.h>
#include <libxfce4panel/libxfce4panel.h>
+#include "indicator-config.h"
G_BEGIN_DECLS
@@ -37,57 +38,10 @@ GType xfce_indicator_box_get_type (void);
typedef struct _XfceIndicatorBox XfceIndicatorBox;
typedef struct _XfceIndicatorBoxClass XfceIndicatorBoxClass;
-struct _XfceIndicatorBox
-{
- GtkContainer __parent__;
-
- XfcePanelPlugin *plugin;
-
- GSList *children;
-
- gint panel_size;
- gint nrows;
- gint icon_size_max;
- gboolean align_left;
-
- GtkOrientation panel_orientation;
- GtkOrientation orientation;
-};
-
-struct _XfceIndicatorBoxClass
-{
- GtkContainerClass __parent__;
-};
-
-void xfce_indicator_box_set_orientation (XfceIndicatorBox *box,
- GtkOrientation panel_orientation,
- GtkOrientation orientation);
-
-void xfce_indicator_box_set_size (XfceIndicatorBox *box,
- gint panel_size,
- gint nrows);
-
-
-GtkOrientation xfce_indicator_box_get_panel_orientation (XfceIndicatorBox *box);
-
-GtkOrientation xfce_indicator_box_get_indicator_orientation (XfceIndicatorBox *box);
-
-gint xfce_indicator_box_get_nrows (XfceIndicatorBox *box);
-
-gint xfce_indicator_box_get_panel_size (XfceIndicatorBox *box);
-
-gint xfce_indicator_box_get_indicator_size (XfceIndicatorBox *box);
-
-gint xfce_indicator_box_get_icon_size_max (XfceIndicatorBox *box);
-
-gboolean xfce_indicator_box_get_align_left (XfceIndicatorBox *box);
-
void xfce_indicator_box_remove_entry (XfceIndicatorBox *box,
IndicatorObjectEntry *entry);
-XfcePanelPlugin *xfce_indicator_box_get_plugin (XfceIndicatorBox *box);
-
-GtkWidget *xfce_indicator_box_new ();
+GtkWidget *xfce_indicator_box_new (IndicatorConfig *config);
G_END_DECLS
diff --git a/panel-plugin/indicator-button.c b/panel-plugin/indicator-button.c
index 74f7d28..49c7a1e 100644
--- a/panel-plugin/indicator-button.c
+++ b/panel-plugin/indicator-button.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 Andrzej <ndrwrdck at gmail.com>
+/* Copyright (c) 2012-2013 Andrzej <ndrwrdck at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -47,6 +47,36 @@ static gboolean xfce_indicator_button_scroll (GtkWidget
GdkEventScroll *event);
static void xfce_indicator_button_menu_deactivate (XfceIndicatorButton *button,
GtkMenu *menu);
+static gint xfce_indicator_button_get_size (XfceIndicatorButton *button);
+
+
+
+struct _XfceIndicatorButton
+{
+ GtkToggleButton __parent__;
+
+ IndicatorObject *io;
+ IndicatorObjectEntry *entry;
+ GtkMenu *menu;
+ XfcePanelPlugin *plugin;
+ IndicatorConfig *config;
+
+ GtkWidget *align_box;
+ GtkWidget *box;
+ GtkWidget *label;
+ GtkWidget *icon;
+ GtkWidget *orig_icon;
+
+ gulong orig_icon_changed_id;
+ gulong configuration_changed_id;
+};
+
+struct _XfceIndicatorButtonClass
+{
+ GtkToggleButtonClass __parent__;
+};
+
+
G_DEFINE_TYPE (XfceIndicatorButton, xfce_indicator_button, GTK_TYPE_TOGGLE_BUTTON)
@@ -79,14 +109,15 @@ xfce_indicator_button_init (XfceIndicatorButton *button)
button->io = NULL;
button->entry = NULL;
- button->buttonbox = NULL;
+ button->plugin = NULL;
+ button->config = NULL;
button->menu = NULL;
button->label = NULL;
button->orig_icon = NULL;
button->icon = NULL;
button->orig_icon_changed_id = 0;
- button->box_layout_changed_id = 0;
+ button->configuration_changed_id = 0;
button->align_box = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_add (GTK_CONTAINER (button), button->align_box);
@@ -114,8 +145,6 @@ xfce_indicator_button_finalize (GObject *object)
g_object_unref (G_OBJECT (button->icon));
if (button->menu != NULL)
g_object_unref (G_OBJECT (button->menu));
- if (button->buttonbox != NULL)
- g_object_unref (G_OBJECT (button->buttonbox));
/* IndicatorObjectEntry is not GObject */
/* if (button->entry != NULL) */
/* g_object_unref (G_OBJECT (button->entry)); */
@@ -134,24 +163,23 @@ xfce_indicator_button_update_layout (XfceIndicatorButton *button)
gfloat align_x;
g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
- g_return_if_fail (XFCE_IS_INDICATOR_BOX (button->buttonbox));
if (button->label != NULL)
gtk_label_set_ellipsize (GTK_LABEL (button->label), PANGO_ELLIPSIZE_NONE);
/* deskbar mode? */
if (button->label != NULL &&
- xfce_indicator_box_get_panel_orientation (button->buttonbox) == GTK_ORIENTATION_VERTICAL &&
- xfce_indicator_box_get_indicator_orientation (button->buttonbox) == GTK_ORIENTATION_HORIZONTAL)
+ indicator_config_get_panel_orientation (button->config) == GTK_ORIENTATION_VERTICAL &&
+ indicator_config_get_orientation (button->config) == GTK_ORIENTATION_HORIZONTAL)
{
gtk_widget_size_request (button->label, &label_size);
/* check if icon and label fit side by side */
- if (!xfce_indicator_box_get_align_left (button->buttonbox)
+ if (!indicator_config_get_align_left (button->config)
|| (button->icon != NULL
&& label_size.width >
- xfce_indicator_box_get_panel_size (button->buttonbox)
- - xfce_indicator_box_get_indicator_size (button->buttonbox)))
+ indicator_config_get_panel_size (button->config)
+ - xfce_indicator_button_get_size (button)))
{
align_x = 0.5;
gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_VERTICAL);
@@ -163,7 +191,7 @@ xfce_indicator_button_update_layout (XfceIndicatorButton *button)
}
/* check if label alone fits in the panel */
- if (label_size.width > xfce_indicator_box_get_panel_size (button->buttonbox) - 6)
+ if (label_size.width > indicator_config_get_panel_size (button->config) - 6)
{
gtk_alignment_set (GTK_ALIGNMENT (button->align_box), align_x, 0.5, 1.0, 0.0);
gtk_label_set_ellipsize (GTK_LABEL (button->label), PANGO_ELLIPSIZE_END);
@@ -177,13 +205,13 @@ xfce_indicator_button_update_layout (XfceIndicatorButton *button)
{
gtk_alignment_set (GTK_ALIGNMENT (button->align_box), 0.5, 0.5, 0.0, 0.0);
gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box),
- xfce_indicator_box_get_indicator_orientation (button->buttonbox));
+ indicator_config_get_orientation (button->config));
}
if (button->label != NULL)
gtk_label_set_angle (GTK_LABEL (button->label),
- (xfce_indicator_box_get_indicator_orientation (button->buttonbox) == GTK_ORIENTATION_VERTICAL)
+ (indicator_config_get_orientation (button->config) == GTK_ORIENTATION_VERTICAL)
? -90 : 0);
if (button->icon != NULL)
xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), xfce_indicator_button_get_icon_size (button));
@@ -413,29 +441,45 @@ xfce_indicator_button_get_icon_size (XfceIndicatorButton *button)
GtkStyle *style;
g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), 24);
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (button->buttonbox), 24);
- indicator_size = xfce_indicator_box_get_indicator_size (button->buttonbox);
+ indicator_size = xfce_indicator_button_get_size (button);
style = gtk_widget_get_style (GTK_WIDGET (button));
border_thickness = 2 * MAX (style->xthickness, style->ythickness) + 2;
return MIN (indicator_size - border_thickness,
- xfce_indicator_box_get_icon_size_max (button->buttonbox));
+ indicator_config_get_icon_size_max (button->config));
+}
+
+
+
+static gint
+xfce_indicator_button_get_size (XfceIndicatorButton *button)
+{
+ gint border_thickness;
+ GtkStyle *style;
+
+ g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), 24);
+
+ style = gtk_widget_get_style (GTK_WIDGET (button));
+ border_thickness = 2 * MAX (style->xthickness, style->ythickness) + 2;
+
+ return MIN (indicator_config_get_panel_size (button->config) /
+ indicator_config_get_nrows (button->config),
+ indicator_config_get_icon_size_max (button->config) + border_thickness);
}
+
static void
-xfce_indicator_button_box_layout_changed (XfceIndicatorButton *button,
- XfceIndicatorBox *box)
+xfce_indicator_configuration_changed (XfceIndicatorButton *button,
+ IndicatorConfig *config)
{
g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
- g_return_if_fail (XFCE_IS_INDICATOR_BOX (box));
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
g_return_if_fail (GTK_WIDGET (button)->parent != NULL);
- //printf ("parent %x\n", (guint) GTK_WIDGET (button)->parent);
-
if (button->orig_icon != NULL)
xfce_indicator_button_update_icon (button);
xfce_indicator_button_update_layout (button);
@@ -446,24 +490,26 @@ xfce_indicator_button_box_layout_changed (XfceIndicatorButton *button,
GtkWidget *
xfce_indicator_button_new (IndicatorObject *io,
IndicatorObjectEntry *entry,
- XfceIndicatorBox *buttonbox)
+ XfcePanelPlugin *plugin,
+ IndicatorConfig *config)
{
XfceIndicatorButton *button = g_object_new (XFCE_TYPE_INDICATOR_BUTTON, NULL);
- g_return_val_if_fail (XFCE_IS_INDICATOR_BOX (buttonbox), NULL);
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), NULL);
+ g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), NULL);
button->io = io;
button->entry = entry;
- button->buttonbox = buttonbox;
+ button->plugin = plugin;
+ button->config = config;
+
if (button->io != NULL)
g_object_ref (G_OBJECT (button->io));
/* IndicatorObjectEntry is not GObject */
/* g_object_ref (G_OBJECT (button->entry)); */
- if (button->buttonbox != NULL)
- g_object_ref (G_OBJECT (button->buttonbox));
- button->box_layout_changed_id =
- g_signal_connect_swapped (G_OBJECT (button->buttonbox), "box-layout-changed",
- G_CALLBACK (xfce_indicator_button_box_layout_changed), button);
+ button->configuration_changed_id =
+ g_signal_connect_swapped (G_OBJECT (button->config), "configuration-changed",
+ G_CALLBACK (xfce_indicator_configuration_changed), button);
return GTK_WIDGET (button);
}
@@ -480,10 +526,10 @@ xfce_indicator_button_disconnect_signals (XfceIndicatorButton *button)
gtk_menu_popdown (button->menu);
}
- if (button->box_layout_changed_id != 0)
+ if (button->configuration_changed_id != 0)
{
- g_signal_handler_disconnect (button->buttonbox, button->box_layout_changed_id);
- button->box_layout_changed_id = 0;
+ g_signal_handler_disconnect (button->config, button->configuration_changed_id);
+ button->configuration_changed_id = 0;
}
if (button->orig_icon_changed_id != 0)
@@ -507,7 +553,7 @@ xfce_indicator_button_button_press (GtkWidget *widget,
gtk_menu_reposition (GTK_MENU (button->menu));
gtk_menu_popup (button->menu, NULL, NULL,
xfce_panel_plugin_position_menu,
- xfce_indicator_box_get_plugin (button->buttonbox),
+ button->plugin,
1, gtk_get_current_event_time ());
return TRUE;
}
diff --git a/panel-plugin/indicator-button.h b/panel-plugin/indicator-button.h
index d7499bf..80912fa 100644
--- a/panel-plugin/indicator-button.h
+++ b/panel-plugin/indicator-button.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 Andrzej <ndrwrdck at gmail.com>
+/* Copyright (c) 2012-2013 Andrzej <ndrwrdck at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +21,8 @@
#include <glib.h>
#include <gtk/gtk.h>
#include <libindicator/indicator-object.h>
+
+#include "indicator-config.h"
#include "indicator-box.h"
G_BEGIN_DECLS
@@ -37,29 +39,6 @@ GType xfce_indicator_button_get_type (void);
typedef struct _XfceIndicatorButton XfceIndicatorButton;
typedef struct _XfceIndicatorButtonClass XfceIndicatorButtonClass;
-struct _XfceIndicatorButton
-{
- GtkToggleButton __parent__;
-
- IndicatorObject *io;
- IndicatorObjectEntry *entry;
- XfceIndicatorBox *buttonbox;
- GtkMenu *menu;
-
- GtkWidget *align_box;
- GtkWidget *box;
- GtkWidget *label;
- GtkWidget *icon;
- GtkWidget *orig_icon;
-
- gulong orig_icon_changed_id;
- gulong box_layout_changed_id;
-};
-
-struct _XfceIndicatorButtonClass
-{
- GtkToggleButtonClass __parent__;
-};
void xfce_indicator_button_set_label (XfceIndicatorButton *button, GtkLabel *label);
@@ -77,9 +56,10 @@ IndicatorObject *xfce_indicator_button_get_io (XfceIndicatorButton *button);
GtkMenu *xfce_indicator_button_get_menu (XfceIndicatorButton *button);
-GtkWidget *xfce_indicator_button_new (IndicatorObject *io,
- IndicatorObjectEntry *entry,
- XfceIndicatorBox *buttonbox);
+GtkWidget *xfce_indicator_button_new (IndicatorObject *io,
+ IndicatorObjectEntry *entry,
+ XfcePanelPlugin *plugin,
+ IndicatorConfig *config);
void xfce_indicator_button_disconnect_signals (XfceIndicatorButton *button);
diff --git a/panel-plugin/indicator-config.c b/panel-plugin/indicator-config.c
new file mode 100644
index 0000000..f73ea94
--- /dev/null
+++ b/panel-plugin/indicator-config.c
@@ -0,0 +1,774 @@
+/*
+ * Copyright (C) 2013 Andrzej <ndrwrdck at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+
+
+/*
+ * This file implements a configuration store. The class extends GObject.
+ *
+ */
+
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
+#include <xfconf/xfconf.h>
+#include <exo/exo.h>
+#include <libxfce4panel/xfce-panel-plugin.h>
+
+#include "indicator.h"
+#include "indicator-config.h"
+
+
+
+
+#define DEFAULT_ICON_SIZE_MAX 24
+#define DEFAULT_ALIGN_LEFT FALSE
+#define DEFAULT_EXCLUDED_MODULES NULL
+#define DEFAULT_ORIENTATION GTK_ORIENTATION_HORIZONTAL
+#define DEFAULT_PANEL_ORIENTATION GTK_ORIENTATION_HORIZONTAL
+#define DEFAULT_PANEL_SIZE 28
+#define DEFAULT_MODE_WHITELIST FALSE
+
+
+
+
+static void indicator_config_finalize (GObject *object);
+static void indicator_config_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void indicator_config_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+
+
+struct _IndicatorConfigClass
+{
+ GObjectClass __parent__;
+};
+
+struct _IndicatorConfig
+{
+ GObject __parent__;
+
+ gint icon_size_max;
+ gboolean align_left;
+ gboolean mode_whitelist;
+ GHashTable *blacklist;
+ GHashTable *whitelist;
+ GList *known_indicators;
+
+ gchar **excluded_modules;
+
+ /* not xfconf properties but it is still convenient to have them here */
+ GtkOrientation orientation;
+ GtkOrientation panel_orientation;
+ gint nrows;
+ gint panel_size;
+};
+
+
+
+enum
+{
+ PROP_0,
+ PROP_ICON_SIZE_MAX,
+ PROP_ALIGN_LEFT,
+ PROP_MODE_WHITELIST,
+ PROP_BLACKLIST,
+ PROP_WHITELIST,
+ PROP_KNOWN_INDICATORS
+};
+
+enum
+{
+ CONFIGURATION_CHANGED,
+ INDICATOR_LIST_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint indicator_config_signals[LAST_SIGNAL] = { 0, };
+
+
+
+
+G_DEFINE_TYPE (IndicatorConfig, indicator_config, G_TYPE_OBJECT)
+
+
+
+
+GType
+indicator_config_value_array_get_type (void)
+{
+ static volatile gsize type__volatile = 0;
+ GType type;
+
+ if (g_once_init_enter (&type__volatile))
+ {
+ type = dbus_g_type_get_collection ("GPtrArray", G_TYPE_VALUE);
+ g_once_init_leave (&type__volatile, type);
+ }
+
+ return type__volatile;
+}
+
+
+static void
+indicator_config_class_init (IndicatorConfigClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = indicator_config_finalize;
+ gobject_class->get_property = indicator_config_get_property;
+ gobject_class->set_property = indicator_config_set_property;
+
+ g_object_class_install_property (gobject_class,
+ PROP_ICON_SIZE_MAX,
+ g_param_spec_uint ("icon-size-max",
+ NULL, NULL,
+ 1,
+ 128,
+ DEFAULT_ICON_SIZE_MAX,
+ EXO_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_ALIGN_LEFT,
+ g_param_spec_boolean ("align-left", NULL, NULL,
+ DEFAULT_ALIGN_LEFT,
+ EXO_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_MODE_WHITELIST,
+ g_param_spec_boolean ("mode-whitelist", NULL, NULL,
+ DEFAULT_MODE_WHITELIST,
+ EXO_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_BLACKLIST,
+ g_param_spec_boxed ("blacklist",
+ NULL, NULL,
+ XFCE_TYPE_INDICATOR_CONFIG_VALUE_ARRAY,
+ EXO_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_WHITELIST,
+ g_param_spec_boxed ("whitelist",
+ NULL, NULL,
+ XFCE_TYPE_INDICATOR_CONFIG_VALUE_ARRAY,
+ EXO_PARAM_READWRITE));
+
+
+ g_object_class_install_property (gobject_class,
+ PROP_KNOWN_INDICATORS,
+ g_param_spec_boxed ("known-indicators",
+ NULL, NULL,
+ XFCE_TYPE_INDICATOR_CONFIG_VALUE_ARRAY,
+ EXO_PARAM_READWRITE));
+
+
+ indicator_config_signals[CONFIGURATION_CHANGED] =
+ g_signal_new (g_intern_static_string ("configuration-changed"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ indicator_config_signals[INDICATOR_LIST_CHANGED] =
+ g_signal_new (g_intern_static_string ("indicator-list-changed"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+
+
+static void
+indicator_config_init (IndicatorConfig *config)
+{
+ config->icon_size_max = DEFAULT_ICON_SIZE_MAX;
+ config->align_left = DEFAULT_ALIGN_LEFT;
+ config->mode_whitelist = DEFAULT_MODE_WHITELIST;
+ config->blacklist = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ config->whitelist = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ config->known_indicators = NULL;
+
+ config->orientation = DEFAULT_ORIENTATION;
+ config->panel_orientation = DEFAULT_PANEL_ORIENTATION;
+ config->nrows = 1;
+ config->panel_size = DEFAULT_PANEL_SIZE;
+}
+
+
+
+static void
+indicator_config_finalize (GObject *object)
+{
+ IndicatorConfig *config = XFCE_INDICATOR_CONFIG (object);
+
+ xfconf_shutdown();
+
+ g_hash_table_destroy (config->blacklist);
+ g_hash_table_destroy (config->whitelist);
+ g_list_foreach (config->known_indicators, (GFunc) g_free, NULL);
+ g_list_free (config->known_indicators);
+
+ G_OBJECT_CLASS (indicator_config_parent_class)->finalize (object);
+}
+
+
+
+static void
+indicator_config_collect_keys (gpointer key,
+ gpointer value,
+ gpointer array)
+{
+ GValue *tmp;
+
+ tmp = g_new0 (GValue, 1);
+ g_value_init (tmp, G_TYPE_STRING);
+ g_value_set_string (tmp, key);
+ g_ptr_array_add (array, tmp);
+}
+
+
+
+static void
+indicator_config_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IndicatorConfig *config = XFCE_INDICATOR_CONFIG (object);
+ GPtrArray *array;
+ GList *li;
+ GValue *tmp;
+
+ switch (prop_id)
+ {
+ case PROP_ICON_SIZE_MAX:
+ g_value_set_uint (value, config->icon_size_max);
+ break;
+
+ case PROP_ALIGN_LEFT:
+ g_value_set_boolean (value, config->align_left);
+ break;
+
+ case PROP_MODE_WHITELIST:
+ g_value_set_boolean (value, config->mode_whitelist);
+ break;
+
+ case PROP_BLACKLIST:
+ array = g_ptr_array_new ();
+ g_hash_table_foreach (config->blacklist, indicator_config_collect_keys, array);
+ g_value_set_boxed (value, array);
+ xfconf_array_free (array);
+ break;
+
+ case PROP_WHITELIST:
+ array = g_ptr_array_new ();
+ g_hash_table_foreach (config->whitelist, indicator_config_collect_keys, array);
+ g_value_set_boxed (value, array);
+ xfconf_array_free (array);
+ break;
+
+ case PROP_KNOWN_INDICATORS:
+ array = g_ptr_array_new ();
+ for(li = config->known_indicators; li != NULL; li = li->next)
+ {
+ tmp = g_new0 (GValue, 1);
+ g_value_init (tmp, G_TYPE_STRING);
+ g_value_set_string (tmp, li->data);
+ g_ptr_array_add (array, tmp);
+ }
+ g_value_set_boxed (value, array);
+ xfconf_array_free (array);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+indicator_config_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IndicatorConfig *config = XFCE_INDICATOR_CONFIG (object);
+ gint val;
+ GPtrArray *array;
+ const GValue *tmp;
+ gchar *name;
+ guint i;
+
+ switch (prop_id)
+ {
+ case PROP_ICON_SIZE_MAX:
+ val = g_value_get_uint (value);
+ if (config->icon_size_max != val)
+ {
+ config->icon_size_max = val;
+ g_signal_emit (G_OBJECT (config), indicator_config_signals [CONFIGURATION_CHANGED], 0);
+ }
+ break;
+
+ case PROP_ALIGN_LEFT:
+ val = g_value_get_boolean (value);
+ if (config->align_left != val)
+ {
+ config->align_left = val;
+ g_signal_emit (G_OBJECT (config), indicator_config_signals [CONFIGURATION_CHANGED], 0);
+ }
+ break;
+
+ case PROP_MODE_WHITELIST:
+ val = g_value_get_boolean (value);
+ if (config->mode_whitelist != val)
+ {
+ config->mode_whitelist = val;
+ g_signal_emit (G_OBJECT (config), indicator_config_signals [INDICATOR_LIST_CHANGED], 0);
+ }
+ break;
+
+ case PROP_BLACKLIST:
+ g_hash_table_remove_all (config->blacklist);
+ array = g_value_get_boxed (value);
+ if (G_LIKELY (array != NULL))
+ {
+ for (i = 0; i < array->len; i++)
+ {
+ tmp = g_ptr_array_index (array, i);
+ g_assert (G_VALUE_HOLDS_STRING (tmp));
+ name = g_value_dup_string (tmp);
+ g_hash_table_replace (config->blacklist, name, name);
+ }
+ }
+ g_signal_emit (G_OBJECT (config), indicator_config_signals [INDICATOR_LIST_CHANGED], 0);
+ break;
+
+ case PROP_WHITELIST:
+ g_hash_table_remove_all (config->whitelist);
+ array = g_value_get_boxed (value);
+ if (G_LIKELY (array != NULL))
+ {
+ for (i = 0; i < array->len; i++)
+ {
+ tmp = g_ptr_array_index (array, i);
+ g_assert (G_VALUE_HOLDS_STRING (tmp));
+ name = g_value_dup_string (tmp);
+ g_hash_table_replace (config->whitelist, name, name);
+ }
+ }
+ g_signal_emit (G_OBJECT (config), indicator_config_signals [INDICATOR_LIST_CHANGED], 0);
+ break;
+
+ case PROP_KNOWN_INDICATORS:
+ g_list_foreach (config->known_indicators, (GFunc) g_free, NULL);
+ g_list_free (config->known_indicators);
+ config->known_indicators = NULL;
+ array = g_value_get_boxed (value);
+ if (G_LIKELY (array != NULL))
+ {
+ for (i = 0; i < array->len; i++)
+ {
+ tmp = g_ptr_array_index (array, i);
+ g_assert (G_VALUE_HOLDS_STRING (tmp));
+ name = g_value_dup_string (tmp);
+ config->known_indicators = g_list_append (config->known_indicators, name);
+ }
+ }
+ g_signal_emit (G_OBJECT (config), indicator_config_signals [INDICATOR_LIST_CHANGED], 0);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+
+gint
+indicator_config_get_icon_size_max (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), DEFAULT_ICON_SIZE_MAX);
+
+ return config->icon_size_max;
+}
+
+
+
+
+gboolean
+indicator_config_get_align_left (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), DEFAULT_ALIGN_LEFT);
+
+ return config->align_left;
+}
+
+
+
+
+void
+indicator_config_set_orientation (IndicatorConfig *config,
+ GtkOrientation panel_orientation,
+ GtkOrientation orientation)
+{
+ gboolean needs_update = FALSE;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
+
+ if (config->orientation != orientation)
+ {
+ config->orientation = orientation;
+ needs_update = TRUE;
+ }
+
+ if (config->panel_orientation != panel_orientation)
+ {
+ config->panel_orientation = panel_orientation;
+ needs_update = TRUE;
+ }
+
+ if (needs_update)
+ g_signal_emit (G_OBJECT (config), indicator_config_signals[CONFIGURATION_CHANGED], 0);
+}
+
+
+
+GtkOrientation
+indicator_config_get_orientation (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), DEFAULT_ORIENTATION);
+
+ return config->orientation;
+}
+
+
+
+
+GtkOrientation
+indicator_config_get_panel_orientation (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), DEFAULT_PANEL_ORIENTATION);
+
+ return config->panel_orientation;
+}
+
+
+
+
+void
+indicator_config_set_size (IndicatorConfig *config,
+ gint panel_size,
+ gint nrows)
+{
+ gboolean needs_update = FALSE;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
+
+ if (config->nrows != nrows)
+ {
+ config->nrows = nrows;
+ needs_update = TRUE;
+ }
+
+ if (config->panel_size != panel_size)
+ {
+ config->panel_size = panel_size;
+ needs_update = TRUE;
+ }
+
+ if (needs_update)
+ g_signal_emit (G_OBJECT (config), indicator_config_signals[CONFIGURATION_CHANGED], 0);
+}
+
+
+
+gint
+indicator_config_get_nrows (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), 1);
+
+ return config->nrows;
+}
+
+
+
+
+gint
+indicator_config_get_panel_size (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), DEFAULT_PANEL_SIZE);
+
+ return config->panel_size;
+}
+
+
+
+
+gchar**
+indicator_config_get_excluded_modules (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), DEFAULT_ALIGN_LEFT);
+
+ return config->excluded_modules;
+}
+
+
+
+
+gboolean
+indicator_config_get_mode_whitelist (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), FALSE);
+
+ return config->mode_whitelist;
+}
+
+
+
+
+gboolean
+indicator_config_is_blacklisted (IndicatorConfig *config,
+ const gchar *name)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), FALSE);
+
+ return g_hash_table_lookup_extended (config->blacklist, name, NULL, NULL);
+}
+
+
+
+
+void
+indicator_config_blacklist_set (IndicatorConfig *config,
+ const gchar *name,
+ gboolean add)
+{
+ gchar *name_copy;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
+ g_return_if_fail (!exo_str_is_empty (name));
+
+ if (add)
+ {
+ name_copy = g_strdup (name);
+ g_hash_table_replace (config->blacklist, name_copy, name_copy);
+ }
+ else
+ {
+ g_hash_table_remove (config->blacklist, name);
+ }
+ g_object_notify (G_OBJECT (config), "blacklist");
+}
+
+
+
+
+
+void
+indicator_config_whitelist_set (IndicatorConfig *config,
+ const gchar *name,
+ gboolean add)
+{
+ gchar *name_copy;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
+ g_return_if_fail (!exo_str_is_empty (name));
+
+ if (add)
+ {
+ name_copy = g_strdup (name);
+ g_hash_table_replace (config->whitelist, name_copy, name_copy);
+ }
+ else
+ {
+ g_hash_table_remove (config->whitelist, name);
+ }
+ g_object_notify (G_OBJECT (config), "whitelist");
+}
+
+
+
+
+
+gboolean
+indicator_config_is_whitelisted (IndicatorConfig *config,
+ const gchar *name)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), FALSE);
+
+ return g_hash_table_lookup_extended (config->whitelist, name, NULL, NULL);
+}
+
+
+
+
+GList*
+indicator_config_get_known_indicators (IndicatorConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), NULL);
+
+ return config->known_indicators;
+}
+
+
+
+
+void
+indicator_config_add_known_indicator (IndicatorConfig *config,
+ const gchar *name)
+{
+ GList *li;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
+ g_return_if_fail (!exo_str_is_empty (name));
+
+ /* check if the indicator is already known */
+ for(li = config->known_indicators; li != NULL; li = li->next)
+ if (g_strcmp0 (li->data, name) == 0)
+ return;
+
+ config->known_indicators = g_list_append (config->known_indicators, g_strdup (name));
+
+ g_object_notify (G_OBJECT (config), "known-indicators");
+}
+
+
+
+
+void
+indicator_config_swap_known_indicators (IndicatorConfig *config,
+ const gchar *name1,
+ const gchar *name2)
+{
+ GList *li, *li_tmp;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
+ g_return_if_fail (!exo_str_is_empty (name1));
+ g_return_if_fail (!exo_str_is_empty (name2));
+
+ for(li = config->known_indicators; li != NULL; li = li->next)
+ if (g_strcmp0 (li->data, name1) == 0)
+ break;
+
+ /* make sure that the list contains name1 followed by name2 */
+ if (li == NULL || li->next == NULL || g_strcmp0 (li->next->data, name2) != 0)
+ {
+ g_debug("Couldn't swap indicators: %s and %s\n", name1, name2);
+ return;
+ }
+
+ /* li_tmp will contain only the removed element (name2) */
+ li_tmp = li->next;
+ config->known_indicators = g_list_remove_link (config->known_indicators, li_tmp);
+
+ /* not strictly necessary (in testing the list contents was preserved)
+ * but searching for the index again should be safer */
+ for(li = config->known_indicators; li != NULL; li = li->next)
+ if (g_strcmp0 (li->data, name1) == 0)
+ break;
+
+ config->known_indicators = g_list_insert_before (config->known_indicators, li, li_tmp->data);
+ g_list_free (li_tmp);
+
+ g_object_notify (G_OBJECT (config), "known-indicators");
+}
+
+
+
+
+void
+indicator_config_names_clear (IndicatorConfig *config)
+{
+ g_list_foreach (config->known_indicators, (GFunc) g_free, NULL);
+ g_list_free (config->known_indicators);
+ config->known_indicators = NULL;
+ g_object_notify (G_OBJECT (config), "known-indicators");
+
+ g_hash_table_remove_all (config->blacklist);
+ g_object_notify (G_OBJECT (config), "blacklist");
+
+ g_hash_table_remove_all (config->whitelist);
+ g_object_notify (G_OBJECT (config), "whitelist");
+}
+
+
+
+
+IndicatorConfig *
+indicator_config_new (const gchar *property_base)
+{
+ IndicatorConfig *config;
+ XfconfChannel *channel;
+ gchar *property;
+
+ config = g_object_new (XFCE_TYPE_INDICATOR_CONFIG, NULL);
+
+ if (xfconf_init (NULL))
+ {
+ channel = xfconf_channel_get ("xfce4-panel");
+
+ property = g_strconcat (property_base, "/icon-size-max", NULL);
+ xfconf_g_property_bind (channel, property, G_TYPE_INT, config, "icon-size-max");
+ g_free (property);
+
+ property = g_strconcat (property_base, "/align-left", NULL);
+ xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, config, "align-left");
+ g_free (property);
+
+ property = g_strconcat (property_base, "/mode-whitelist", NULL);
+ xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, config, "mode-whitelist");
+ g_free (property);
+
+ property = g_strconcat (property_base, "/blacklist", NULL);
+ xfconf_g_property_bind (channel, property, XFCE_TYPE_INDICATOR_CONFIG_VALUE_ARRAY, config, "blacklist");
+ g_free (property);
+
+ property = g_strconcat (property_base, "/whitelist", NULL);
+ xfconf_g_property_bind (channel, property, XFCE_TYPE_INDICATOR_CONFIG_VALUE_ARRAY, config, "whitelist");
+ g_free (property);
+
+ property = g_strconcat (property_base, "/known-indicators", NULL);
+ xfconf_g_property_bind (channel, property, XFCE_TYPE_INDICATOR_CONFIG_VALUE_ARRAY, config, "known-indicators");
+ g_free (property);
+ }
+
+ return config;
+}
diff --git a/panel-plugin/indicator-config.h b/panel-plugin/indicator-config.h
new file mode 100644
index 0000000..8c820c2
--- /dev/null
+++ b/panel-plugin/indicator-config.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2013 Andrzej <ndrwrdck at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __INDICATOR_CONFIG_H__
+#define __INDICATOR_CONFIG_H__
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _IndicatorConfigClass IndicatorConfigClass;
+typedef struct _IndicatorConfig IndicatorConfig;
+
+#define XFCE_TYPE_INDICATOR_CONFIG (indicator_config_get_type ())
+#define XFCE_INDICATOR_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_INDICATOR_CONFIG, IndicatorConfig))
+#define XFCE_INDICATOR_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_INDICATOR_CONFIG, IndicatorConfigClass))
+#define XFCE_IS_INDICATOR_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_INDICATOR_CONFIG))
+#define XFCE_IS_INDICATOR_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_INDICATOR_CONFIG))
+#define XFCE_INDICATOR_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_INDICATOR_CONFIG, IndicatorConfigClass))
+
+#define XFCE_TYPE_INDICATOR_CONFIG_VALUE_ARRAY (indicator_config_value_array_get_type ())
+
+typedef struct _IncicatorConfigProperty IndicatorConfigProperty;
+struct _IndicatorConfigProperty
+{
+ const gchar *property;
+ GType type;
+};
+
+GType indicator_config_value_array_get_type (void) G_GNUC_CONST;
+
+GType indicator_config_get_type (void) G_GNUC_CONST;
+
+IndicatorConfig *indicator_config_new (const gchar *property_base);
+
+void indicator_config_set_orientation (IndicatorConfig *config,
+ GtkOrientation panel_orientation,
+ GtkOrientation orientation);
+
+GtkOrientation indicator_config_get_orientation (IndicatorConfig *config);
+
+GtkOrientation indicator_config_get_panel_orientation (IndicatorConfig *config);
+
+void indicator_config_set_size (IndicatorConfig *config,
+ gint panel_size,
+ gint nrows);
+
+gint indicator_config_get_nrows (IndicatorConfig *config);
+
+gint indicator_config_get_panel_size (IndicatorConfig *config);
+
+gint indicator_config_get_icon_size_max (IndicatorConfig *config);
+
+gboolean indicator_config_get_align_left (IndicatorConfig *config);
+
+gboolean indicator_config_get_mode_whitelist (IndicatorConfig *config);
+
+gboolean indicator_config_is_blacklisted (IndicatorConfig *config,
+ const gchar *name);
+
+void indicator_config_blacklist_set (IndicatorConfig *config,
+ const gchar *name,
+ gboolean add);
+
+gboolean indicator_config_is_whitelisted (IndicatorConfig *config,
+ const gchar *name);
+
+void indicator_config_whitelist_set (IndicatorConfig *config,
+ const gchar *name,
+ gboolean add);
+
+gchar **indicator_config_get_excluded_modules (IndicatorConfig *config);
+
+GList *indicator_config_get_known_indicators (IndicatorConfig *config);
+
+void indicator_config_add_known_indicator (IndicatorConfig *config,
+ const gchar *name);
+
+void indicator_config_swap_known_indicators (IndicatorConfig *config,
+ const gchar *name1,
+ const gchar *name2);
+
+void indicator_config_names_clear (IndicatorConfig *config);
+
+G_END_DECLS
+
+#endif /* !__INDICATOR_CONFIG_H__ */
diff --git a/panel-plugin/indicator-dialog.c b/panel-plugin/indicator-dialog.c
index a2afba7..1387c76 100644
--- a/panel-plugin/indicator-dialog.c
+++ b/panel-plugin/indicator-dialog.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Andrzej <ndrwrdck at gmail.com>
+ * Copyright (C) 2012-2013 Andrzej <ndrwrdck at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,18 +35,15 @@
#include <libxfce4util/libxfce4util.h>
#include <libxfce4ui/libxfce4ui.h>
-#include <xfconf/xfconf.h>
#include <exo/exo.h>
#include <libxfce4panel/xfce-panel-plugin.h>
-#include "indicator.h"
#include "indicator-dialog.h"
#include "indicator-dialog_ui.h"
-static void indicator_dialog_build (IndicatorDialog *dialog,
- IndicatorPlugin *plugin);
+static void indicator_dialog_build (IndicatorDialog *dialog);
static void indicator_dialog_response (GtkWidget *window,
gint response_id,
IndicatorDialog *dialog);
@@ -63,15 +60,18 @@ struct _IndicatorDialog
GtkBuilder __parent__;
GObject *dialog;
+ GObject *store;
+ IndicatorConfig *config;
+};
- XfconfChannel *channel;
-
- IndicatorPlugin *plugin;
- //GtkTreeSelection *selection;
- //gulong bindings[4];
- gulong property_watch_id;
+enum
+{
+ COLUMN_PIXBUF,
+ COLUMN_TITLE,
+ COLUMN_HIDDEN,
+ COLUMN_VISIBLE
};
@@ -90,44 +90,339 @@ indicator_dialog_class_init (IndicatorDialogClass *klass)
static void
indicator_dialog_init (IndicatorDialog *dialog)
{
+ dialog->dialog = NULL;
+ dialog->store = NULL;
+ dialog->config = NULL;
}
static void
-indicator_dialog_build (IndicatorDialog *dialog,
- IndicatorPlugin *plugin)
+indicator_dialog_add_indicator (IndicatorDialog *dialog,
+ GdkPixbuf *pixbuf,
+ const gchar *name,
+ gboolean hidden,
+ gboolean visible)
+{
+ GtkTreeIter iter;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_DIALOG (dialog));
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+ g_return_if_fail (name == NULL || g_utf8_validate (name, -1, NULL));
+
+ /* insert in the store */
+ gtk_list_store_append (GTK_LIST_STORE (dialog->store), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (dialog->store), &iter,
+ COLUMN_PIXBUF, pixbuf,
+ COLUMN_TITLE, name,
+ COLUMN_HIDDEN, hidden,
+ COLUMN_VISIBLE, visible,
+ -1);
+}
+
+
+
+static void
+indicator_dialog_update_indicator_names (IndicatorDialog *dialog)
{
+ GList *li;
+ const gchar *name;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_DIALOG (dialog));
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (dialog->config));
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+
+ for(li = indicator_config_get_known_indicators (dialog->config); li != NULL; li = li->next)
+ {
+ name = li->data;
+ indicator_dialog_add_indicator
+ (dialog,
+ NULL,
+ name,
+ indicator_config_is_blacklisted (dialog->config, name),
+ indicator_config_is_whitelisted (dialog->config, name));
+ }
+}
+
+
+
+static void
+indicator_dialog_hidden_toggled (GtkCellRendererToggle *renderer,
+ const gchar *path_string,
+ IndicatorDialog *dialog)
+{
+ GtkTreeIter iter;
+ gboolean hidden;
+ gchar *name;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_DIALOG (dialog));
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (dialog->config));
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+
+ if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (dialog->store), &iter, path_string))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (dialog->store), &iter,
+ COLUMN_HIDDEN, &hidden,
+ COLUMN_TITLE, &name, -1);
+
+ /* insert value (we need to update it) */
+ hidden = !hidden;
+
+ /* update box and store with new state */
+ indicator_config_blacklist_set (dialog->config, name, hidden);
+ gtk_list_store_set (GTK_LIST_STORE (dialog->store), &iter, 2, hidden, -1);
+
+ g_free (name);
+ }
+}
+
+
+
+static void
+indicator_dialog_visible_toggled (GtkCellRendererToggle *renderer,
+ const gchar *path_string,
+ IndicatorDialog *dialog)
+{
+ GtkTreeIter iter;
+ gboolean visible;
+ gchar *name;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_DIALOG (dialog));
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (dialog->config));
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+
+ if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (dialog->store), &iter, path_string))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (dialog->store), &iter,
+ COLUMN_VISIBLE, &visible,
+ COLUMN_TITLE, &name, -1);
+
+ /* insert value (we need to update it) */
+ visible = !visible;
+
+ /* update box and store with new state */
+ indicator_config_whitelist_set (dialog->config, name, visible);
+ gtk_list_store_set (GTK_LIST_STORE (dialog->store), &iter, 3, visible, -1);
+
+ g_free (name);
+ }
+}
+
+
+
+
+static void
+indicator_dialog_swap_rows (IndicatorDialog *dialog,
+ GtkTreeIter *iter_prev,
+ GtkTreeIter *iter)
+{
+ GdkPixbuf *pixbuf1, *pixbuf2;
+ gchar *name1, *name2;
+ gboolean hidden1, hidden2;
+ gboolean visible1, visible2;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_DIALOG (dialog));
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (dialog->config));
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+
+ gtk_tree_model_get (GTK_TREE_MODEL (dialog->store), iter_prev,
+ COLUMN_PIXBUF, &pixbuf1,
+ COLUMN_TITLE, &name1,
+ COLUMN_HIDDEN, &hidden1,
+ COLUMN_VISIBLE, &visible1, -1);
+ gtk_tree_model_get (GTK_TREE_MODEL (dialog->store), iter,
+ COLUMN_PIXBUF, &pixbuf2,
+ COLUMN_TITLE, &name2,
+ COLUMN_HIDDEN, &hidden2,
+ COLUMN_VISIBLE, &visible2, -1);
+ gtk_list_store_set (GTK_LIST_STORE (dialog->store), iter_prev,
+ COLUMN_PIXBUF, pixbuf2,
+ COLUMN_TITLE, name2,
+ COLUMN_HIDDEN, hidden2,
+ COLUMN_VISIBLE, visible2, -1);
+ gtk_list_store_set (GTK_LIST_STORE (dialog->store), iter,
+ COLUMN_PIXBUF, pixbuf1,
+ COLUMN_TITLE, name1,
+ COLUMN_HIDDEN, hidden1,
+ COLUMN_VISIBLE, visible1, -1);
+
+ /* do a matching operation on IndicatorConfig */
+ indicator_config_swap_known_indicators (dialog->config, name1, name2);
+}
+
+
+
+
+
+static gboolean
+indicator_dialog_iter_equal (GtkTreeIter *iter1,
+ GtkTreeIter *iter2)
+{
+ return (iter1->user_data == iter2->user_data &&
+ iter1->user_data2 == iter2->user_data2 &&
+ iter1->user_data3 == iter2->user_data3);
+}
+
+
+
+
+
+static void
+indicator_dialog_item_up_clicked (GtkWidget *button,
+ IndicatorDialog *dialog)
+{
+ GObject *treeview;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter, iter_prev, iter_tmp;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_DIALOG (dialog));
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+
+ treeview = gtk_builder_get_object (GTK_BUILDER (dialog), "indicators-treeview");
+ g_return_if_fail (GTK_IS_TREE_VIEW (treeview));
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
+ return;
+
+ /* gtk_tree_model_iter_previous available from Gtk3 */
+ /* so we have to search for it starting from the first iter */
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dialog->store), &iter_prev))
+ return;
+
+ iter_tmp = iter_prev;
+ while (!indicator_dialog_iter_equal (&iter_tmp, &iter))
+ {
+ iter_prev = iter_tmp;
+ if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (dialog->store), &iter_tmp))
+ return;
+ }
+
+ indicator_dialog_swap_rows (dialog, &iter_prev, &iter);
+ gtk_tree_selection_select_iter (selection, &iter_prev);
+}
+
+
+
+
+
+static void
+indicator_dialog_item_down_clicked (GtkWidget *button,
+ IndicatorDialog *dialog)
+{
+ GObject *treeview;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter, iter_next;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_DIALOG (dialog));
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+
+ treeview = gtk_builder_get_object (GTK_BUILDER (dialog), "indicators-treeview");
+ g_return_if_fail (GTK_IS_TREE_VIEW (treeview));
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
+ return;
+
+ iter_next = iter;
+ if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (dialog->store), &iter_next))
+ return;
+
+ indicator_dialog_swap_rows (dialog, &iter, &iter_next);
+ gtk_tree_selection_select_iter (selection, &iter_next);
+}
+
+
+
+
+
+static void
+indicator_dialog_clear_clicked (GtkWidget *button,
+ IndicatorDialog *dialog)
+{
+ g_return_if_fail (XFCE_IS_INDICATOR_DIALOG (dialog));
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (dialog->config));
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+
+ if (xfce_dialog_confirm (GTK_WINDOW (gtk_widget_get_toplevel (button)),
+ GTK_STOCK_CLEAR, NULL, NULL,
+ _("Are you sure you want to clear the list of "
+ "known indicators?")))
+ {
+ gtk_list_store_clear (GTK_LIST_STORE (dialog->store));
+
+ indicator_config_names_clear (dialog->config);
+ }
+}
+
+
+
+
+
+static void
+indicator_dialog_build (IndicatorDialog *dialog)
+{
+ GtkBuilder *builder = GTK_BUILDER (dialog);
GObject *object;
GError *error = NULL;
- dialog->channel = xfconf_channel_get ("xfce4-panel");
- dialog->plugin = plugin;
-
if (xfce_titled_dialog_get_type () == 0)
return;
/* load the builder data into the object */
- if (gtk_builder_add_from_string (GTK_BUILDER (dialog), indicator_dialog_ui,
+ if (gtk_builder_add_from_string (builder, indicator_dialog_ui,
indicator_dialog_ui_length, &error))
{
- dialog->dialog = gtk_builder_get_object (GTK_BUILDER (dialog), "dialog");
+ dialog->dialog = gtk_builder_get_object (builder, "dialog");
g_return_if_fail (XFCE_IS_TITLED_DIALOG (dialog->dialog));
g_signal_connect (G_OBJECT (dialog->dialog), "response",
G_CALLBACK (indicator_dialog_response), dialog);
- object = gtk_builder_get_object (GTK_BUILDER (dialog), "size-max");
+ object = gtk_builder_get_object (builder, "size-max");
g_return_if_fail (GTK_IS_WIDGET (object));
- exo_mutual_binding_new (G_OBJECT (indicator_get_buttonbox (plugin)), "icon-size-max",
+ exo_mutual_binding_new (G_OBJECT (dialog->config), "icon-size-max",
G_OBJECT (object), "value");
- object = gtk_builder_get_object (GTK_BUILDER (dialog), "checkbutton-align-left");
+ object = gtk_builder_get_object (builder, "checkbutton-align-left");
g_return_if_fail (GTK_IS_WIDGET (object));
- exo_mutual_binding_new (G_OBJECT (indicator_get_buttonbox (plugin)), "align-left",
+ exo_mutual_binding_new (G_OBJECT (dialog->config), "align-left",
G_OBJECT (object), "active");
+ object = gtk_builder_get_object (builder, "checkbutton-whitelist");
+ g_return_if_fail (GTK_IS_WIDGET (object));
+ exo_mutual_binding_new (G_OBJECT (dialog->config), "mode-whitelist",
+ G_OBJECT (object), "active");
+
+ dialog->store = gtk_builder_get_object (builder, "indicators-store");
+ g_return_if_fail (GTK_IS_LIST_STORE (dialog->store));
+ indicator_dialog_update_indicator_names (dialog);
+
+ object = gtk_builder_get_object (builder, "hidden-toggle");
+ g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (object));
+ g_signal_connect (G_OBJECT (object), "toggled",
+ G_CALLBACK (indicator_dialog_hidden_toggled), dialog);
+
+ object = gtk_builder_get_object (builder, "visible-toggle");
+ g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (object));
+ g_signal_connect (G_OBJECT (object), "toggled",
+ G_CALLBACK (indicator_dialog_visible_toggled), dialog);
+
+ object = gtk_builder_get_object (builder, "item-up");
+ g_return_if_fail (GTK_IS_BUTTON (object));
+ g_signal_connect (G_OBJECT (object), "clicked",
+ G_CALLBACK (indicator_dialog_item_up_clicked), dialog);
+
+ object = gtk_builder_get_object (builder, "item-down");
+ g_return_if_fail (GTK_IS_BUTTON (object));
+ g_signal_connect (G_OBJECT (object), "clicked",
+ G_CALLBACK (indicator_dialog_item_down_clicked), dialog);
+
+ object = gtk_builder_get_object (builder, "indicators-clear");
+ g_return_if_fail (GTK_IS_BUTTON (object));
+ g_signal_connect (G_OBJECT (object), "clicked",
+ G_CALLBACK (indicator_dialog_clear_clicked), dialog);
}
else
{
@@ -152,8 +447,6 @@ indicator_dialog_response (GtkWidget *window,
}
else
{
- g_signal_handler_disconnect (dialog->channel, dialog->property_watch_id);
-
gtk_widget_destroy (window);
g_object_unref (G_OBJECT (dialog));
@@ -164,18 +457,19 @@ indicator_dialog_response (GtkWidget *window,
void
indicator_dialog_show (GdkScreen *screen,
- IndicatorPlugin *plugin)
+ IndicatorConfig *config)
{
static IndicatorDialog *dialog = NULL;
g_return_if_fail (GDK_IS_SCREEN (screen));
- g_return_if_fail (XFCE_IS_INDICATOR_PLUGIN (plugin));
+ g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
if (dialog == NULL)
{
dialog = g_object_new (XFCE_TYPE_INDICATOR_DIALOG, NULL);
g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &dialog);
- indicator_dialog_build (XFCE_INDICATOR_DIALOG (dialog), plugin);
+ dialog->config = config;
+ indicator_dialog_build (XFCE_INDICATOR_DIALOG (dialog));
gtk_widget_show (GTK_WIDGET (dialog->dialog));
}
else
diff --git a/panel-plugin/indicator-dialog.glade b/panel-plugin/indicator-dialog.glade
index fbb7808..31b28ec 100644
--- a/panel-plugin/indicator-dialog.glade
+++ b/panel-plugin/indicator-dialog.glade
@@ -3,18 +3,6 @@
<requires lib="gtk+" version="2.14"/>
<!-- interface-requires libxfce4ui 0.0 -->
<!-- interface-naming-policy toplevel-contextual -->
- <object class="GtkListStore" id="applications-store">
- <columns>
- <!-- column-name icon -->
- <column type="GdkPixbuf"/>
- <!-- column-name title -->
- <column type="gchararray"/>
- <!-- column-name hidden -->
- <column type="gboolean"/>
- <!-- column-name internal-name -->
- <column type="gchararray"/>
- </columns>
- </object>
<object class="XfceTitledDialog" id="dialog">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Indicators</property>
@@ -118,6 +106,7 @@
<object class="GtkSpinButton" id="size-max">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="tooltip_text" translatable="yes">Icons are scaled to fit a single row of the panel. Use this option to restrict the maximum size of the icon.</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
@@ -139,51 +128,19 @@
</packing>
</child>
<child>
- <object class="GtkRadioButton" id="radiobutton-whitelist">
- <property name="label" translatable="yes">Show indicators unless hidden</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- <property name="group">radiobutton-blacklist</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkRadioButton" id="radiobutton-blacklist">
- <property name="label" translatable="yes">Hide invisible indicators</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
<object class="GtkCheckButton" id="checkbutton-align-left">
- <property name="label" translatable="yes">Align left in the deskbar mode</property>
+ <property name="label" translatable="yes">Align left in deskbar mode</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Controls the indicator button layout when the panel is in a Deskbar mode. Possible choices are "centered" or "aligned left".</property>
<property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">3</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -225,6 +182,22 @@
<property name="border_width">6</property>
<property name="spacing">6</property>
<child>
+ <object class="GtkCheckButton" id="checkbutton-whitelist">
+ <property name="label" translatable="yes">Hide indicators by default</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">When enabled, only indicators marked "Visible" are shown. Otherwise, all indicators not marked "Hidden" are displayed.</property>
+ <property name="use_action_appearance">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -237,14 +210,24 @@
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">in</property>
<child>
- <object class="GtkTreeView" id="applications-treeview">
+ <object class="GtkTreeView" id="indicators-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="model">applications-store</property>
+ <property name="model">indicators-store</property>
<property name="headers_clickable">False</property>
<property name="rules_hint">True</property>
<property name="enable_search">False</property>
- <property name="search_column">1</property>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn-icon">
+ <property name="min_width">24</property>
+ <child>
+ <object class="GtkCellRendererPixbuf" id="cellrendererpixbuf1"/>
+ <attributes>
+ <attribute name="pixbuf">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn-name">
<property name="title">Indicator</property>
@@ -272,31 +255,9 @@
<object class="GtkTreeViewColumn" id="treeviewcolumn-whitelist">
<property name="title">Visible</property>
<child>
- <object class="GtkCellRendererToggle" id="hidden-toggle1"/>
+ <object class="GtkCellRendererToggle" id="visible-toggle"/>
<attributes>
- <attribute name="active">2</attribute>
- </attributes>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="treeviewcolumn-icon">
- <property name="title">Icon</property>
- <child>
- <object class="GtkCellRendererToggle" id="hidden-toggle2"/>
- <attributes>
- <attribute name="active">2</attribute>
- </attributes>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="treeviewcolumn-label">
- <property name="title">Label</property>
- <child>
- <object class="GtkCellRendererToggle" id="hidden-toggle3"/>
- <attributes>
- <attribute name="active">2</attribute>
+ <attribute name="active">3</attribute>
</attributes>
</child>
</object>
@@ -320,6 +281,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Move the selected indicator one row up.</property>
<property name="use_action_appearance">False</property>
<child>
<object class="GtkImage" id="image2">
@@ -340,6 +302,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Move the selected indicator one row down.</property>
<property name="use_action_appearance">False</property>
<child>
<object class="GtkImage" id="image3">
@@ -366,7 +329,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
@@ -376,10 +339,11 @@
<property name="layout_style">start</property>
<child>
<object class="GtkButton" id="indicators-clear">
- <property name="label" translatable="yes">C_lear Known Indicators</property>
+ <property name="label" translatable="yes">C_lear known indicators</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Resets the list of indicators and their visibility settings.</property>
<property name="use_action_appearance">False</property>
<property name="image">image1</property>
<property name="use_underline">True</property>
@@ -394,7 +358,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
@@ -437,6 +401,18 @@
<property name="can_focus">False</property>
<property name="stock">gtk-clear</property>
</object>
+ <object class="GtkListStore" id="indicators-store">
+ <columns>
+ <!-- column-name icon -->
+ <column type="GdkPixbuf"/>
+ <!-- column-name title -->
+ <column type="gchararray"/>
+ <!-- column-name hidden -->
+ <column type="gboolean"/>
+ <!-- column-name visible -->
+ <column type="gboolean"/>
+ </columns>
+ </object>
<object class="GtkAdjustment" id="size-adjustment">
<property name="lower">12</property>
<property name="upper">64</property>
diff --git a/panel-plugin/indicator-dialog.h b/panel-plugin/indicator-dialog.h
index fe6cf04..6117860 100644
--- a/panel-plugin/indicator-dialog.h
+++ b/panel-plugin/indicator-dialog.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Andrzej <ndrwrdck at gmail.com>
+ * Copyright (C) 2012-2013 Andrzej <ndrwrdck at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
#define __INDICATOR_DIALOG_H__
#include <gtk/gtk.h>
+#include "indicator-config.h"
G_BEGIN_DECLS
@@ -36,7 +37,7 @@ typedef struct _IndicatorDialog IndicatorDialog;
GType indicator_dialog_get_type (void) G_GNUC_CONST;
void indicator_dialog_show (GdkScreen *screen,
- IndicatorPlugin *plugin);
+ IndicatorConfig *config);
G_END_DECLS
diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c
index 47c5e1b..42ef448 100644
--- a/panel-plugin/indicator.c
+++ b/panel-plugin/indicator.c
@@ -1,4 +1,5 @@
-/* Copyright (c) 2009 Mark Trompell <mark at foresightlinux.org>
+/* Copyright (c) 2009 Mark Trompell <mark at foresightlinux.org>
+ * Copyright (c) 2012-2013 Andrzej <ndrwrdck at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,15 +36,12 @@
#include <libxfce4util/libxfce4util.h>
#include <libxfce4panel/xfce-panel-plugin.h>
#include <libindicator/indicator-object.h>
-#include <xfconf/xfconf.h>
#include "indicator.h"
#include "indicator-box.h"
#include "indicator-button.h"
#include "indicator-dialog.h"
-#define DEFAULT_EXCLUDED_MODULES NULL
-
#ifdef LIBXFCE4PANEL_CHECK_VERSION
#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0)
#define HAS_PANEL_49
@@ -82,7 +80,7 @@ struct _IndicatorPlugin
GtkWidget *buttonbox;
/* indicator settings */
- gchar **excluded_modules;
+ IndicatorConfig *config;
};
@@ -92,72 +90,10 @@ XFCE_PANEL_DEFINE_PLUGIN (IndicatorPlugin, indicator)
-#if 0
-void
-indicator_save (XfcePanelPlugin *plugin,
- IndicatorPlugin *indicator)
-{
- XfceRc *rc;
- gchar *file;
-
- /* get the config file location */
- file = xfce_panel_plugin_save_location (plugin, TRUE);
-
- if (G_UNLIKELY (file == NULL))
- {
- DBG ("Failed to open config file");
- return;
- }
-
- /* open the config file, read/write */
- rc = xfce_rc_simple_open (file, FALSE);
- g_free (file);
-
- if (G_LIKELY (rc != NULL))
- {
- /* save the settings */
- DBG(".");
- if (indicator->excluded_modules)
- xfce_rc_write_list_entry (rc, "Exclude",
- indicator->excluded_modules, NULL);
-
- /* close the rc file */
- xfce_rc_close (rc);
- }
-}
-#endif
-
-
-static void
-indicator_read (IndicatorPlugin *indicator)
-{
- XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (indicator);
- XfconfChannel * channel = xfconf_channel_get ("xfce4-panel");
- gchar * property = g_strconcat (xfce_panel_plugin_get_property_base(plugin),"/blacklist",NULL);
- indicator->excluded_modules = xfconf_channel_get_string_list(channel, property);
- g_free (property);
- property = g_strconcat (xfce_panel_plugin_get_property_base(plugin),"/icon-size-max",NULL);
- xfconf_g_property_bind (channel, property, G_TYPE_INT, indicator->buttonbox, "icon-size-max");
- g_free (property);
- property = g_strconcat (xfce_panel_plugin_get_property_base(plugin),"/align-left",NULL);
- xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, indicator->buttonbox, "align-left");
- g_free (property);
- /* something went wrong, apply default values */
- /*
- DBG ("Applying default settings");
- indicator->excluded_modules = DEFAULT_EXCLUDED_MODULES;
- */
-}
-
static void
indicator_class_init (IndicatorPluginClass *klass)
{
XfcePanelPluginClass *plugin_class;
- //GObjectClass *gobject_class;
-
- //gobject_class = G_OBJECT_CLASS (klass);
- //gobject_class->get_property = indicator_get_property;
- //gobject_class->set_property = indicator_set_property;
plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
plugin_class->construct = indicator_construct;
@@ -176,17 +112,11 @@ indicator_class_init (IndicatorPluginClass *klass)
static void
indicator_init (IndicatorPlugin *indicator)
{
- XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (indicator);
-
/* Indicators print a lot of warnings. By default, "wrapper"
makes them critical, so the plugin "crashes" when run as an external
plugin but not internal one (loaded by "xfce4-panel" itself).
The following lines makes only g_error critical. */
g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
-
- indicator->buttonbox = xfce_indicator_box_new (plugin);
- gtk_container_add (GTK_CONTAINER (plugin), GTK_WIDGET(indicator->buttonbox));
- gtk_widget_show(GTK_WIDGET(indicator->buttonbox));
}
@@ -194,14 +124,12 @@ indicator_init (IndicatorPlugin *indicator)
static void
indicator_free (XfcePanelPlugin *plugin)
{
- //IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
GtkWidget *dialog;
/* check if the dialog is still open. if so, destroy it */
dialog = g_object_get_data (G_OBJECT (plugin), "dialog");
if (G_UNLIKELY (dialog != NULL))
gtk_widget_destroy (dialog);
- xfconf_shutdown();
}
@@ -209,9 +137,9 @@ indicator_free (XfcePanelPlugin *plugin)
static void
indicator_configure_plugin (XfcePanelPlugin *plugin)
{
- g_return_if_fail (XFCE_IS_INDICATOR_PLUGIN (plugin));
+ IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
- indicator_dialog_show (gtk_widget_get_screen (GTK_WIDGET (plugin)), XFCE_INDICATOR_PLUGIN (plugin));
+ indicator_dialog_show (gtk_widget_get_screen (GTK_WIDGET (plugin)), indicator->config);
}
@@ -229,7 +157,7 @@ indicator_mode_changed (XfcePanelPlugin *plugin,
orientation = (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ?
GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
- xfce_indicator_box_set_orientation (XFCE_INDICATOR_BOX (indicator->buttonbox), panel_orientation, orientation);
+ indicator_config_set_orientation (indicator->config, panel_orientation, orientation);
indicator_size_changed (plugin, xfce_panel_plugin_get_size (plugin));
}
@@ -243,7 +171,7 @@ indicator_orientation_changed (XfcePanelPlugin *plugin,
{
IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
- xfce_indicator_box_set_orientation (XFCE_INDICATOR_BOX (indicator->buttonbox), orientation, GTK_ORIENTATION_HORIZONTAL);
+ indicator_config_set_orientation (indicator->config, orientation, GTK_ORIENTATION_HORIZONTAL);
indicator_size_changed (plugin, xfce_panel_plugin_get_size (plugin));
}
@@ -257,11 +185,9 @@ indicator_size_changed (XfcePanelPlugin *plugin,
IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
#ifdef HAS_PANEL_49
- xfce_indicator_box_set_size (XFCE_INDICATOR_BOX (indicator->buttonbox),
- size, xfce_panel_plugin_get_nrows (plugin));
+ indicator_config_set_size (indicator->config, size, xfce_panel_plugin_get_nrows (plugin));
#else
- xfce_indicator_box_set_size (XFCE_INDICATOR_BOX (indicator->buttonbox),
- size, 1);
+ indicator_config_set_size (indicator->config, size, 1);
#endif
return TRUE;
@@ -286,39 +212,46 @@ indicator_construct (XfcePanelPlugin *plugin)
/*gtk_widget_set_name(GTK_WIDGET (indicator->plugin), "indicator-plugin");*/
/* initialize xfconf */
- if (xfconf_init(NULL)){
- /* get the list of excluded modules */
- indicator_read (indicator);
- }
+ indicator->config = indicator_config_new (xfce_panel_plugin_get_property_base (plugin));
+
+ /* instantiate a button box */
+ indicator->buttonbox = xfce_indicator_box_new (indicator->config);
+ gtk_container_add (GTK_CONTAINER (plugin), GTK_WIDGET(indicator->buttonbox));
+ gtk_widget_show(GTK_WIDGET(indicator->buttonbox));
+
/* load 'em */
if (g_file_test(INDICATOR_DIR, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
GDir * dir = g_dir_open(INDICATOR_DIR, 0, NULL);
const gchar * name;
- guint i, length;
- gboolean match = FALSE;
-
- length = (indicator->excluded_modules != NULL) ? g_strv_length (indicator->excluded_modules) : 0;
- while ((name = g_dir_read_name(dir)) != NULL) {
- for (i = 0; i < length; ++i) {
- if ((match = g_strcmp0 (name, indicator->excluded_modules[i])) == 0)
- break;
+ if (indicator_config_get_mode_whitelist (indicator->config))
+ {
+ while ((name = g_dir_read_name (dir)) != NULL)
+ if (indicator_config_is_whitelisted (indicator->config, name))
+ {
+ g_debug ("Loading whitelisted module: %s", name);
+ if (load_module(name, indicator))
+ indicators_loaded++;
+ }
}
-
- if (G_UNLIKELY (match)) {
- g_debug ("Excluding module: %s", name);
- continue;
+ else
+ {
+ while ((name = g_dir_read_name (dir)) != NULL)
+ if (indicator_config_is_blacklisted (indicator->config, name))
+ g_debug ("Excluding blacklisted module: %s", name);
+ else if (load_module(name, indicator))
+ indicators_loaded++;
}
- if (load_module(name, indicator))
- indicators_loaded++;
- }
g_dir_close (dir);
}
if (indicators_loaded == 0) {
/* A label to allow for click through */
- indicator->item = xfce_indicator_button_new(NULL, NULL, XFCE_INDICATOR_BOX (indicator->buttonbox));
+ indicator->item = xfce_indicator_button_new (NULL,
+ NULL,
+ plugin,
+ indicator->config);
label = gtk_label_new ( _("No Indicators"));
xfce_indicator_button_set_label (XFCE_INDICATOR_BUTTON (indicator->item), GTK_LABEL (label));
gtk_container_add (GTK_CONTAINER (indicator->buttonbox), indicator->item);
@@ -333,7 +266,10 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d
{
XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (user_data);
IndicatorPlugin *indicator = XFCE_INDICATOR_PLUGIN (plugin);
- GtkWidget * button = xfce_indicator_button_new (io, entry, XFCE_INDICATOR_BOX (indicator->buttonbox));
+ GtkWidget *button = xfce_indicator_button_new (io,
+ entry,
+ plugin,
+ indicator->config);
/* remove placeholder item when there are real entries to be added */
if (indicator->item != NULL)
@@ -384,6 +320,8 @@ load_module (const gchar * name, IndicatorPlugin * indicator)
g_debug("Loading Module: %s", name);
+ indicator_config_add_known_indicator (indicator->config, name);
+
fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
io = indicator_object_new_from_file(fullpath);
g_free(fullpath);
More information about the Xfce4-commits
mailing list