[Xfce4-commits] <xfce4-weather-plugin:master> Implement multi-lines for the scrollbox (bug #5722).

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


Updating branch refs/heads/master
         to b4652feca2bf4a6791f40ecdf977772cbd7a4016 (commit)
       from 6e35276358f6153698947b2c9e53d504472eb7c3 (commit)

commit b4652feca2bf4a6791f40ecdf977772cbd7a4016
Author: Harald Judt <h.judt at gmx.at>
Date:   Mon Nov 26 16:30:00 2012 +0100

    Implement multi-lines for the scrollbox (bug #5722).
    
    It works fine, except that there is no easy way to align the pango layout
    vertically. This will only be noticeable when there are fewer values than
    lines, so I consider this only a minor problem which can be solved with
    proper configuration (change number of lines or add values to fill up the
    empty lines).

 panel-plugin/weather-config.c    |    1 +
 panel-plugin/weather-scrollbox.c |    2 ++
 panel-plugin/weather.c           |   33 ++++++++++++++++++++++-----------
 panel-plugin/weather.h           |    2 +-
 4 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index a4ce00d..d2b7e25 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -791,6 +791,7 @@ spin_scrollbox_lines_value_changed(const GtkWidget *spin,
     xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
     dialog->wd->scrollbox_lines =
         (guint) gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
+    update_scrollbox(dialog->wd);
 }
 
 
diff --git a/panel-plugin/weather-scrollbox.c b/panel-plugin/weather-scrollbox.c
index 350b444..7104511 100644
--- a/panel-plugin/weather-scrollbox.c
+++ b/panel-plugin/weather-scrollbox.c
@@ -108,11 +108,13 @@ gtk_scrollbox_set_font(GtkScrollbox *self,
     if (layout) {
         pango_layout_set_font_description(layout, desc);
         pango_layout_set_attributes(layout, self->pattr_list);
+        pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
     } else
         for (li = self->labels; li != NULL; li = li->next) {
             layout = PANGO_LAYOUT(li->data);
             pango_layout_set_font_description(layout, desc);
             pango_layout_set_attributes(layout, self->pattr_list);
+            pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
         }
     pango_font_description_free(desc);
 }
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 555edec..9cff3a6 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -206,27 +206,38 @@ void
 update_scrollbox(xfceweather_data *data)
 {
     xml_time *conditions;
-    guint i;
+    GString *out;
+    gchar *single = NULL;
     data_types type;
-    gchar *str;
-    gint size;
+    guint i = 0, j = 0;
 
     gtk_scrollbox_clear(GTK_SCROLLBOX(data->scrollbox));
     gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox),
                               data->scrollbox_animate);
 
     if (data->weatherdata) {
-        for (i = 0; i < data->labels->len; i++) {
-            type = g_array_index(data->labels, data_types, i);
-            str = make_label(data, type);
-            gtk_scrollbox_set_label(GTK_SCROLLBOX(data->scrollbox), -1, str);
-            g_free(str);
+        while (i < data->labels->len) {
+            j = 0;
+            out = g_string_sized_new(128);
+            while ((i + j) < data->labels->len && j < data->scrollbox_lines) {
+                type = g_array_index(data->labels, data_types, i + j);
+                single = make_label(data, type);
+                g_string_append_printf(out, "%s%s", single,
+                                       (j < (data->scrollbox_lines - 1)
+                                        ? "\n"
+                                        : ""));
+                g_free(single);
+                j++;
+            }
+            gtk_scrollbox_set_label(GTK_SCROLLBOX(data->scrollbox), -1, out->str);
+            g_string_free(out, TRUE);
+            i = i + j;
         }
         weather_debug("Added %u labels to scrollbox.", data->labels->len);
     } else {
-        str = g_strdup(_("No Data"));
-        gtk_scrollbox_set_label(GTK_SCROLLBOX(data->scrollbox), -1, str);
-        g_free(str);
+        single = g_strdup(_("No Data"));
+        gtk_scrollbox_set_label(GTK_SCROLLBOX(data->scrollbox), -1, single);
+        g_free(single);
         weather_debug("No weather data available, set single label '%s'.",
                       _("No Data"));
     }
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 14dae1a..7a1d352 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -27,7 +27,7 @@
 #define PLUGIN_WEBSITE "http://goodies.xfce.org/projects/panel-plugins/xfce4-weather-plugin"
 #define MAX_FORECAST_DAYS 10
 #define DEFAULT_FORECAST_DAYS 5
-#define MAX_SCROLLBOX_LINES 6
+#define MAX_SCROLLBOX_LINES 10
 
 G_BEGIN_DECLS
 


More information about the Xfce4-commits mailing list