[Xfce4-commits] <xfce4-weather-plugin:master> Implement scrollbox font support.

Harald Judt noreply at xfce.org
Tue Nov 27 16:46:28 CET 2012


Updating branch refs/heads/master
         to dd04f1961900fb7e348b30b748765fe08da001a3 (commit)
       from f37354fe6f2858c4feb9dadff79ad5023ccd0d2c (commit)

commit dd04f1961900fb7e348b30b748765fe08da001a3
Author: Harald Judt <h.judt at gmx.at>
Date:   Sun Nov 25 19:14:16 2012 +0100

    Implement scrollbox font support.

 panel-plugin/weather-config.c    |   36 +++++++++++++++++++++++++
 panel-plugin/weather-debug.c     |    2 +
 panel-plugin/weather-scrollbox.c |   53 +++++++++++++++++++++++++++++++++++--
 panel-plugin/weather-scrollbox.h |    4 +++
 panel-plugin/weather.c           |   12 ++++++++
 panel-plugin/weather.h           |    1 +
 6 files changed, 105 insertions(+), 3 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 4a95722..03a1554 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -790,6 +790,37 @@ spin_scrollbox_lines_value_changed(const GtkWidget *spin,
 }
 
 
+static gboolean
+button_scrollbox_font_clicked(GtkWidget *button,
+                              gpointer user_data)
+{
+    xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
+    GtkFontSelectionDialog *fsd;
+    gchar *fontname;
+    gint result;
+
+    fsd = GTK_FONT_SELECTION_DIALOG
+        (gtk_font_selection_dialog_new(_("Select font")));
+    if (dialog->wd->scrollbox_font)
+        gtk_font_selection_dialog_set_font_name(fsd,
+                                                dialog->wd->scrollbox_font);
+
+    result = gtk_dialog_run(GTK_DIALOG(fsd));
+    if (result == GTK_RESPONSE_OK || result == GTK_RESPONSE_ACCEPT) {
+        fontname = gtk_font_selection_dialog_get_font_name(fsd);
+        if (fontname != NULL) {
+            gtk_button_set_label(GTK_BUTTON(button), fontname);
+            g_free(dialog->wd->scrollbox_font);
+            dialog->wd->scrollbox_font = fontname;
+            gtk_scrollbox_set_fontname(GTK_SCROLLBOX(dialog->wd->scrollbox),
+                                       fontname);
+        }
+    }
+    gtk_widget_destroy(GTK_WIDGET(fsd));
+    return FALSE;
+}
+
+
 static GtkWidget *
 make_label(void)
 {
@@ -1005,6 +1036,11 @@ create_scrollbox_page(xfceweather_dialog *dialog)
         gtk_button_new_with_mnemonic(_("Select _font"));
     gtk_box_pack_start(GTK_BOX(hbox), dialog->button_scrollbox_font,
                        TRUE, TRUE, 0);
+    if (dialog->wd->scrollbox_font)
+        gtk_button_set_label(GTK_BUTTON(dialog->button_scrollbox_font),
+                             dialog->wd->scrollbox_font);
+    g_signal_connect(dialog->button_scrollbox_font, "clicked",
+                     G_CALLBACK(button_scrollbox_font_clicked), dialog);
     gdk_color_parse("#000000", &color);
     dialog->button_scrollbox_color =
         gtk_color_button_new_with_color(&color);
diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index 22fb330..b601647 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -411,6 +411,7 @@ weather_dump_plugindata(const xfceweather_data *data)
                            "  --------------------------------------------\n"
                            "  show scrollbox: %s\n"
                            "  scrollbox lines: %d\n"
+                           "  scrollbox font: %s\n"
                            "  animate scrollbox: %s\n"
                            "  --------------------------------------------",
                            data->panel_size,
@@ -427,6 +428,7 @@ weather_dump_plugindata(const xfceweather_data *data)
                            data->forecast_days,
                            YESNO(data->show_scrollbox),
                            data->scrollbox_lines,
+                           data->scrollbox_font,
                            YESNO(data->scrollbox_animate));
     g_free(last_astro_update);
     g_free(last_data_update);
diff --git a/panel-plugin/weather-scrollbox.c b/panel-plugin/weather-scrollbox.c
index 8ea0830..b9decae 100644
--- a/panel-plugin/weather-scrollbox.c
+++ b/panel-plugin/weather-scrollbox.c
@@ -45,7 +45,7 @@ G_DEFINE_TYPE(GtkScrollbox, gtk_scrollbox, GTK_TYPE_DRAWING_AREA)
 
 
 static void
-gtk_scrollbox_class_init (GtkScrollboxClass *klass)
+gtk_scrollbox_class_init(GtkScrollboxClass *klass)
 {
     GObjectClass *gobject_class;
     GtkWidgetClass *widget_class;
@@ -69,6 +69,7 @@ gtk_scrollbox_init(GtkScrollbox *self)
     self->offset = 0;
     self->active = NULL;
     self->orientation = GTK_ORIENTATION_HORIZONTAL;
+    self->fontname = NULL;
 }
 
 
@@ -85,11 +86,35 @@ gtk_scrollbox_finalize(GObject *object)
     g_slist_foreach(self->labels, (GFunc) g_object_unref, NULL);
     g_slist_free(self->labels);
 
+    /* free everything else */
+    g_free(self->fontname);
+
     G_OBJECT_CLASS(gtk_scrollbox_parent_class)->finalize(object);
 }
 
 
 static void
+gtk_scrollbox_set_font(GtkScrollbox *self,
+                       PangoLayout *layout)
+{
+    GSList *li;
+    PangoFontDescription *desc = NULL;
+
+    if (self->fontname)
+        desc = pango_font_description_from_string(self->fontname);
+
+    if (layout)
+        pango_layout_set_font_description(layout, desc);
+    else
+        for (li = self->labels; li != NULL; li = li->next) {
+            layout = PANGO_LAYOUT(li->data);
+            pango_layout_set_font_description(layout, desc);
+        }
+    pango_font_description_free(desc);
+}
+
+
+static void
 gtk_scrollbox_size_request(GtkWidget *widget,
                            GtkRequisition *requisition)
 {
@@ -270,9 +295,9 @@ gtk_scrollbox_set_label(GtkScrollbox *self,
 
     layout = gtk_widget_create_pango_layout(GTK_WIDGET(self), NULL);
     pango_layout_set_markup(layout, markup, -1);
+    gtk_scrollbox_set_font(self, layout);
     self->labels = g_slist_insert(self->labels, layout, position);
     gtk_widget_queue_resize(GTK_WIDGET(self));
-
     gtk_scrollbox_start_fade(self);
 }
 
@@ -312,6 +337,8 @@ void
 gtk_scrollbox_set_animate(GtkScrollbox *self,
                           gboolean animate)
 {
+    g_return_if_fail(GTK_IS_SCROLLBOX(self));
+
     self->animate = animate;
 }
 
@@ -319,8 +346,28 @@ gtk_scrollbox_set_animate(GtkScrollbox *self,
 void
 gtk_scrollbox_next_label(GtkScrollbox *self)
 {
+    g_return_if_fail(GTK_IS_SCROLLBOX(self));
+
     if (self->active->next != NULL) {
         self->active = self->active->next;
-        gtk_widget_queue_resize (GTK_WIDGET (self));
+        gtk_widget_queue_resize(GTK_WIDGET(self));
     }
 }
+
+
+void
+gtk_scrollbox_set_fontname(GtkScrollbox *self,
+                           const gchar *fontname)
+{
+    g_return_if_fail(GTK_IS_SCROLLBOX(self));
+
+    if (fontname == NULL)
+        return;
+
+    g_free(self->fontname);
+    self->fontname = g_strdup(fontname);
+
+    /* update all labels */
+    gtk_scrollbox_set_font(self, NULL);
+    gtk_widget_queue_resize(GTK_WIDGET(self));
+}
diff --git a/panel-plugin/weather-scrollbox.h b/panel-plugin/weather-scrollbox.h
index 198a530..245ea0a 100644
--- a/panel-plugin/weather-scrollbox.h
+++ b/panel-plugin/weather-scrollbox.h
@@ -49,6 +49,7 @@ struct _GtkScrollbox {
     GSList *active;
     gboolean animate;
     GtkOrientation orientation;
+    gchar *fontname;
 };
 
 struct _GtkScrollboxClass {
@@ -72,6 +73,9 @@ void gtk_scrollbox_set_animate(GtkScrollbox *self,
 
 void gtk_scrollbox_next_label(GtkScrollbox *self);
 
+void gtk_scrollbox_set_fontname(GtkScrollbox *self,
+                                const gchar *fontname);
+
 G_END_DECLS
 
 #endif
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 7f670cf..cdab60c 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -562,6 +562,12 @@ xfceweather_read_config(XfcePanelPlugin *plugin,
         data->scrollbox_lines > MAX_SCROLLBOX_LINES)
         data->scrollbox_lines = 1;
 
+    value = xfce_rc_read_entry(rc, "scrollbox_font", NULL);
+    if (value) {
+        g_free(data->scrollbox_font);
+        data->scrollbox_font = g_strdup(value);
+    }
+
     data->scrollbox_animate =
         xfce_rc_read_bool_entry(rc, "scrollbox_animate", TRUE);
     gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox),
@@ -637,6 +643,9 @@ xfceweather_write_config(XfcePanelPlugin *plugin,
 
     xfce_rc_write_int_entry(rc, "scrollbox_lines", data->scrollbox_lines);
 
+    if (data->scrollbox_font)
+        xfce_rc_write_entry(rc, "scrollbox_font", data->scrollbox_font);
+
     for (i = 0; i < data->labels->len; i++) {
         g_snprintf(label, 10, "label%d", i);
         xfce_rc_write_int_entry(rc, label,
@@ -1101,6 +1110,7 @@ xfceweather_free(XfcePanelPlugin *plugin,
     g_free(data->lat);
     g_free(data->lon);
     g_free(data->location_name);
+    g_free(data->scrollbox_font);
 
     /* free array */
     g_array_free(data->labels, TRUE);
@@ -1262,6 +1272,8 @@ weather_construct(XfcePanelPlugin *plugin)
     data = xfceweather_create_control(plugin);
     xfceweather_read_config(plugin, data);
     scrollbox_set_visible(data);
+    gtk_scrollbox_set_fontname(GTK_SCROLLBOX(data->scrollbox),
+                               data->scrollbox_font);
 
 #if LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
     xfceweather_set_mode(plugin, xfce_panel_plugin_get_mode(plugin), data);
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 05a6de2..3f9fc52 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -56,6 +56,7 @@ typedef struct {
     GtkWidget *scrollbox;
     gboolean show_scrollbox;
     guint scrollbox_lines;
+    gchar *scrollbox_font;
     gboolean scrollbox_animate;
     GArray *labels;
 


More information about the Xfce4-commits mailing list