[Xfce4-commits] <xfce4-weather-plugin:master> Make number of forecast days configurable.
Harald Judt
noreply at xfce.org
Fri Jul 13 16:50:19 CEST 2012
Updating branch refs/heads/master
to 8687ba61669a1e347dc26b3bbc34b46c5e6e8283 (commit)
from e77af5bf30ab30c1f931431eba7efbd48375862e (commit)
commit 8687ba61669a1e347dc26b3bbc34b46c5e6e8283
Author: Harald Judt <h.judt at gmx.at>
Date: Wed Jul 11 19:49:38 2012 +0200
Make number of forecast days configurable.
Add a spinner button to the configuration dialog and read/write
config entries. The max limit is 10 days, as imposed by the XML
feed.
panel-plugin/weather-config.c | 17 +++++++++++++++++
panel-plugin/weather-config.h | 1 +
panel-plugin/weather-summary.c | 6 +++---
panel-plugin/weather.c | 5 +++++
panel-plugin/weather.h | 2 ++
5 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index cbffe73..bc07470 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -229,6 +229,8 @@ apply_options (xfceweather_dialog *dialog)
data->proxy_host = NULL;
}
+ data->forecast_days = (gint) gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->spin_forecast_days));
+
data->animation_transitions = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(dialog->chk_animate_transition));
@@ -510,6 +512,21 @@ create_config_dialog (xfceweather_data *data,
}
+ /* number of days shown in forecast */
+ label = gtk_label_new_with_mnemonic (_("Number of _forecast days:"));
+ dialog->spin_forecast_days = gtk_spin_button_new_with_range (1, MAX_FORECAST_DAYS, 1);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->spin_forecast_days),
+ dialog->wd->forecast_days);
+ gtk_label_set_mnemonic_widget(GTK_LABEL (label),
+ GTK_WIDGET (dialog->spin_forecast_days));
+
+ hbox = gtk_hbox_new (FALSE, BORDER);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), dialog->spin_forecast_days, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+ gtk_size_group_add_widget (sg, label);
+
+
/* labels */
dialog->opt_xmloption = make_label ();
dialog->mdl_xmloption = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
diff --git a/panel-plugin/weather-config.h b/panel-plugin/weather-config.h
index 52db012..2b41c88 100644
--- a/panel-plugin/weather-config.h
+++ b/panel-plugin/weather-config.h
@@ -38,6 +38,7 @@ typedef struct
GtkWidget *txt_proxy_port;
GtkWidget *chk_proxy_use;
GtkWidget *chk_proxy_fromenv;
+ GtkWidget *spin_forecast_days;
GtkWidget *tooltip_yes;
GtkWidget *tooltip_no;
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index b8bf063..c2a1029 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -406,13 +406,13 @@ make_forecast (xfceweather_data *data)
GdkPixbuf *icon;
GdkColor lightbg = {0, 0xeaea, 0xeaea, 0xeaea};
GdkColor darkbg = {0, 0x6666, 0x6666, 0x6666};
- gint num_days = 5, i, weekday, daytime;
+ gint i, weekday, daytime;
gchar *dayname, *wind_speed, *value, *rawvalue;
xml_time *fcdata;
time_t now_t = time(NULL), fcday_t;
struct tm tm_fcday;
- table = gtk_table_new(num_days + 1, 5, FALSE);
+ table = gtk_table_new(data->forecast_days + 1, 5, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(table), 0);
gtk_table_set_col_spacings(GTK_TABLE(table), 0);
gtk_widget_show(GTK_WIDGET(table));
@@ -438,7 +438,7 @@ make_forecast (xfceweather_data *data)
add_forecast_header(_("Night"), 0.0, &darkbg),
4, 5, 0, 1);
- for (i = 0; i < num_days; i++) {
+ for (i = 0; i < data->forecast_days; i++) {
/* Forecast day headers */
tm_fcday = *localtime(&now_t);
fcday_t = time_calc_day(tm_fcday, i);
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 10b23cc..608972d 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -535,6 +535,9 @@ xfceweather_read_config (XfcePanelPlugin *plugin,
data->proxy_port = data->saved_proxy_port;
}
+ val = xfce_rc_read_int_entry (rc, "forecast_days", 5);
+ data->forecast_days = (val > 0 && val <= MAX_FORECAST_DAYS) ? val : 5;
+
data->animation_transitions = xfce_rc_read_bool_entry (rc,
"animation_transitions", TRUE);
@@ -603,6 +606,8 @@ xfceweather_write_config (XfcePanelPlugin *plugin,
xfce_rc_write_int_entry (rc, "proxy_port", data->proxy_port);
}
+ xfce_rc_write_int_entry (rc, "forecast_days", data->forecast_days);
+
xfce_rc_write_bool_entry (rc, "animation_transitions", data->animation_transitions);
for (i = 0; i < data->labels->len; i++)
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index fdffe48..9462a24 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -23,6 +23,7 @@
#define PLUGIN_WEBSITE "http://goodies.xfce.org/projects/panel-plugins/xfce4-weather-plugin"
#define PARTNER_ID "1121946239"
#define LICENSE_KEY "3c4cd39ee5dec84f"
+#define MAX_FORECAST_DAYS 10
G_BEGIN_DECLS
@@ -69,6 +70,7 @@ typedef struct
gint saved_proxy_port;
gboolean animation_transitions;
+ gint forecast_days;
}
xfceweather_data;
More information about the Xfce4-commits
mailing list