[Xfce4-commits] <xfce4-panel:devel> Hookup the combo boxes in the clock plugin properties.
Nick Schermer
noreply at xfce.org
Mon Nov 16 15:26:04 CET 2009
Updating branch refs/heads/devel
to d7c4109257039530be70398529a514d1b97d4398 (commit)
from 71ce262e78ed6a28cc909e9d5179bea25c4d3459 (commit)
commit d7c4109257039530be70398529a514d1b97d4398
Author: Nick Schermer <nick at xfce.org>
Date: Mon Nov 16 15:10:19 2009 +0100
Hookup the combo boxes in the clock plugin properties.
plugins/clock/clock-dialog.ui | 79 +++++++++++++++----
plugins/clock/clock-digital.c | 2 -
plugins/clock/clock-digital.h | 2 +
plugins/clock/clock.c | 167 ++++++++++++++++++++++++++++++++++++++---
4 files changed, 221 insertions(+), 29 deletions(-)
diff --git a/plugins/clock/clock-dialog.ui b/plugins/clock/clock-dialog.ui
index 33e4cd2..ef47b67 100644
--- a/plugins/clock/clock-dialog.ui
+++ b/plugins/clock/clock-dialog.ui
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<interface>
- <!-- interface-requires gtk+ 2.14 -->
+ <requires lib="gtk+" version="2.14"/>
<!-- interface-requires libxfce4ui 0.0 -->
<!-- interface-naming-policy toplevel-contextual -->
<object class="XfceTitledDialog" id="dialog">
@@ -11,11 +11,13 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox2">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="border_width">6</property>
+ <property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkFrame" id="frame3">
@@ -31,7 +33,7 @@
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="border_width">6</property>
- <property name="n_rows">3</property>
+ <property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
@@ -77,6 +79,23 @@
</packing>
</child>
<child>
+ <object class="GtkComboBox" id="tooltip-chooser">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext2"/>
+ <attributes>
+ <attribute name="text">2</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkCheckButton" id="show-frame">
<property name="label" translatable="yes">Show _frame</property>
<property name="visible">True</property>
@@ -87,24 +106,26 @@
</object>
<packing>
<property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
</packing>
</child>
<child>
- <object class="GtkComboBox" id="combobox1">
+ <object class="GtkEntry" id="tooltip-format">
<property name="visible">True</property>
- <child>
- <object class="GtkCellRendererText" id="cellrenderertext2"/>
- </child>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">•</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
</packing>
</child>
+ <child>
+ <placeholder/>
+ </child>
</object>
</child>
</object>
@@ -137,6 +158,7 @@
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="border_width">6</property>
+ <property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="show-seconds">
@@ -204,31 +226,54 @@
</packing>
</child>
<child>
- <object class="GtkHBox" id="format-box">
- <property name="spacing">12</property>
+ <object class="GtkTable" id="digital-box">
+ <property name="visible">True</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
<child>
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="label" translatable="yes">F_ormat:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">digital-format</property>
+ <property name="mnemonic_widget">digital-chooser</property>
</object>
<packing>
- <property name="expand">False</property>
- <property name="position">0</property>
+ <property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
- <object class="GtkComboBox" id="digital-format">
+ <object class="GtkComboBox" id="digital-chooser">
<property name="visible">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
+ <attributes>
+ <attribute name="text">2</attribute>
+ </attributes>
</child>
</object>
<packing>
- <property name="position">1</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="digital-format">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">•</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
</packing>
</child>
+ <child>
+ <placeholder/>
+ </child>
</object>
<packing>
<property name="position">5</property>
diff --git a/plugins/clock/clock-digital.c b/plugins/clock/clock-digital.c
index e990566..c5827b1 100644
--- a/plugins/clock/clock-digital.c
+++ b/plugins/clock/clock-digital.c
@@ -29,8 +29,6 @@
#include "clock.h"
#include "clock-digital.h"
-#define DEFAULT_DIGITAL_FORMAT "%R"
-
static void xfce_clock_digital_set_property (GObject *object,
diff --git a/plugins/clock/clock-digital.h b/plugins/clock/clock-digital.h
index 4280ae3..dec3440 100644
--- a/plugins/clock/clock-digital.h
+++ b/plugins/clock/clock-digital.h
@@ -21,6 +21,8 @@
G_BEGIN_DECLS
+#define DEFAULT_DIGITAL_FORMAT "%R"
+
typedef struct _XfceClockDigitalClass XfceClockDigitalClass;
typedef struct _XfceClockDigital XfceClockDigital;
diff --git a/plugins/clock/clock.c b/plugins/clock/clock.c
index 016a6f7..6906c74 100644
--- a/plugins/clock/clock.c
+++ b/plugins/clock/clock.c
@@ -131,6 +131,31 @@ typedef struct
}
ClockPluginDialog;
+static const gchar *tooltip_formats[] =
+{
+ DEFAULT_TOOLTIP_FORMAT,
+ "%x",
+ N_("Week %V"),
+ NULL
+};
+
+static const gchar *digital_formats[] =
+{
+ DEFAULT_DIGITAL_FORMAT,
+ "%T",
+ "%r",
+ "%R %p",
+ NULL
+};
+
+enum
+{
+ COLUMN_FORMAT,
+ COLUMN_SEPARATOR,
+ COLUMN_TEXT,
+ N_COLUMNS
+};
+
/* define the plugin */
@@ -401,7 +426,7 @@ static void
clock_plugin_configure_plugin_mode_changed (GtkComboBox *combo,
ClockPluginDialog *dialog)
{
- guint i, active, mode;
+ guint i, active, mode;
GObject *object;
struct {
const gchar *widget;
@@ -413,7 +438,7 @@ clock_plugin_configure_plugin_mode_changed (GtkComboBox *combo,
{ "show-military", "show-military", "active" },
{ "flash-separators", "flash-separators", "active" },
{ "show-meridiem", "show-meridiem", "active" },
- { "format-box", "digital-format", "active" },
+ { "digital-box", "digital-format", "text" },
{ "fuzziness-box", "fuzziness", "value" }
};
@@ -450,7 +475,7 @@ clock_plugin_configure_plugin_mode_changed (GtkComboBox *combo,
for (i = 0; i < G_N_ELEMENTS (names); i++)
{
object = gtk_builder_get_object (dialog->builder, names[i].widget);
- panel_return_if_fail (G_IS_OBJECT (object));
+ panel_return_if_fail (GTK_IS_WIDGET (object));
if (PANEL_HAS_FLAG (active, 1 << (i + 1)))
gtk_widget_show (GTK_WIDGET (object));
else
@@ -478,8 +503,115 @@ clock_plugin_configure_plugin_mode_changed (GtkComboBox *combo,
static void
-clock_plugin_configure_plugin_free (gpointer user_data,
- GObject *where_the_object_was)
+clock_plugin_configure_plugin_chooser_changed (GtkComboBox *combo,
+ GtkEntry *entry)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gchar *format;
+
+ panel_return_if_fail (GTK_IS_COMBO_BOX (combo));
+ panel_return_if_fail (GTK_IS_ENTRY (entry));
+
+ if (gtk_combo_box_get_active_iter (combo, &iter))
+ {
+ model = gtk_combo_box_get_model (combo);
+ gtk_tree_model_get (model, &iter, COLUMN_FORMAT, &format, -1);
+
+ if (format != NULL)
+ {
+ gtk_entry_set_text (entry, format);
+ gtk_widget_hide (GTK_WIDGET (entry));
+ g_free (format);
+ }
+ else
+ {
+ gtk_widget_show (GTK_WIDGET (entry));
+ }
+ }
+}
+
+
+
+static gboolean
+clock_plugin_configure_plugin_chooser_separator (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ gboolean separator;
+
+ gtk_tree_model_get (model, iter, COLUMN_SEPARATOR, &separator, -1);
+
+ return separator;
+}
+
+
+
+static void
+clock_plugin_configure_plugin_chooser_fill (GtkComboBox *combo,
+ GtkEntry *entry,
+ const gchar *formats[])
+{
+ guint i;
+ GtkListStore *store;
+ gchar *preview;
+ struct tm now;
+ GtkTreeIter iter;
+ const gchar *active_format;
+ gboolean has_active = FALSE;
+
+ panel_return_if_fail (GTK_IS_COMBO_BOX (combo));
+ panel_return_if_fail (GTK_IS_ENTRY (entry));
+
+ gtk_combo_box_set_row_separator_func (combo,
+ clock_plugin_configure_plugin_chooser_separator, NULL, NULL);
+
+ store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
+ gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
+
+ clock_plugin_get_localtime (&now);
+
+ active_format = gtk_entry_get_text (entry);
+
+ for (i = 0; formats[i] != NULL; i++)
+ {
+ preview = clock_plugin_strdup_strftime (_(formats[i]), &now);
+ gtk_list_store_insert_with_values (store, &iter, i,
+ COLUMN_FORMAT, _(formats[i]),
+ COLUMN_TEXT, preview, -1);
+ g_free (preview);
+
+ if (has_active == FALSE
+ && IS_STRING (active_format)
+ && strcmp (active_format, formats[i]) == 0)
+ {
+ gtk_combo_box_set_active_iter (combo, &iter);
+ gtk_widget_hide (GTK_WIDGET (entry));
+ has_active = TRUE;
+ }
+ }
+
+ gtk_list_store_insert_with_values (store, NULL, i++,
+ COLUMN_SEPARATOR, TRUE, -1);
+
+ gtk_list_store_insert_with_values (store, &iter, i++,
+ COLUMN_TEXT, _("Custom Format"), -1);
+ if (!has_active)
+ {
+ gtk_combo_box_set_active_iter (combo, &iter);
+ gtk_widget_show (GTK_WIDGET (entry));
+ }
+
+ g_signal_connect (G_OBJECT (combo), "changed",
+ G_CALLBACK (clock_plugin_configure_plugin_chooser_changed), entry);
+
+ g_object_unref (G_OBJECT (store));
+}
+
+
+
+static void
+clock_plugin_configure_plugin_free (gpointer user_data)
{
g_slice_free (ClockPluginDialog, user_data);
}
@@ -494,6 +626,7 @@ clock_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
GtkBuilder *builder;
GObject *window;
GObject *object;
+ GObject *combo;
panel_return_if_fail (XFCE_IS_CLOCK_PLUGIN (plugin));
@@ -506,11 +639,11 @@ clock_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
dialog = g_slice_new0 (ClockPluginDialog);
dialog->plugin = plugin;
dialog->builder = builder;
- g_object_weak_ref (G_OBJECT (builder), clock_plugin_configure_plugin_free, dialog);
object = gtk_builder_get_object (builder, "mode");
- g_signal_connect (G_OBJECT (object), "changed",
- G_CALLBACK (clock_plugin_configure_plugin_mode_changed), dialog);
+ g_signal_connect_data (G_OBJECT (object), "changed",
+ G_CALLBACK (clock_plugin_configure_plugin_mode_changed), dialog,
+ (GClosureNotify) clock_plugin_configure_plugin_free, 0);
exo_mutual_binding_new (G_OBJECT (plugin), "mode",
G_OBJECT (object), "active");
@@ -518,6 +651,20 @@ clock_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
exo_mutual_binding_new (G_OBJECT (plugin), "show-frame",
G_OBJECT (object), "active");
+ object = gtk_builder_get_object (builder, "tooltip-format");
+ exo_mutual_binding_new (G_OBJECT (plugin), "tooltip-format",
+ G_OBJECT (object), "text");
+ combo = gtk_builder_get_object (builder, "tooltip-chooser");
+ clock_plugin_configure_plugin_chooser_fill (GTK_COMBO_BOX (combo),
+ GTK_ENTRY (object),
+ tooltip_formats);
+
+ object = gtk_builder_get_object (builder, "digital-format");
+ combo = gtk_builder_get_object (builder, "digital-chooser");
+ clock_plugin_configure_plugin_chooser_fill (GTK_COMBO_BOX (combo),
+ GTK_ENTRY (object),
+ digital_formats);
+
gtk_widget_show (GTK_WIDGET (window));
}
@@ -595,7 +742,7 @@ clock_plugin_tooltip (gpointer user_data)
/* set the tooltip */
string = clock_plugin_strdup_strftime (plugin->tooltip_format, &tm);
- gtk_widget_set_tooltip_text (GTK_WIDGET (plugin), string);
+ gtk_widget_set_tooltip_markup (GTK_WIDGET (plugin), string);
g_free (string);
/* make sure the tooltip is up2date */
@@ -781,7 +928,7 @@ clock_plugin_strdup_strftime (const gchar *format,
{
gchar *converted, *result;
gsize length;
- gchar buffer[512];
+ gchar buffer[1024];
/* leave when format is null */
if (G_UNLIKELY (!IS_STRING (format)))
More information about the Xfce4-commits
mailing list