[Xfce4-commits] <xfce4-weather-plugin:master> Summary window: Print current time at the location next to the name.
Harald Judt
noreply at xfce.org
Fri Feb 1 16:20:09 CET 2013
Updating branch refs/heads/master
to 9ddb59e8eff39ac7cde3df61bf13b9097bea1434 (commit)
from 12cfe8cb47126c869b5efd0a760f9f44b0b9c7ae (commit)
commit 9ddb59e8eff39ac7cde3df61bf13b9097bea1434
Author: Harald Judt <h.judt at gmx.at>
Date: Fri Feb 1 14:12:05 2013 +0100
Summary window: Print current time at the location next to the name.
Now the plugin can be used as a world clock too ;-)
panel-plugin/weather-summary.c | 45 +++++++++++++++++++++++++++++++++++----
panel-plugin/weather-summary.h | 2 +
panel-plugin/weather.c | 10 ++++++++
panel-plugin/weather.h | 1 +
4 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index b03da45..67ff2c1 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -29,7 +29,6 @@
#include "weather-translate.h"
#include "weather-icon.h"
-
static gboolean
lnk_clicked(GtkTextTag *tag,
GObject *obj,
@@ -980,13 +979,50 @@ cb_notebook_page_switched(GtkNotebook *notebook,
}
+gboolean
+update_summary_subtitle(plugin_data *data)
+{
+ time_t now_t;
+ GTimeVal now;
+ gchar *title, *date;
+ guint update_interval;
+ gint64 now_ms;
+
+ if (data->summary_update_timer) {
+ g_source_remove(data->update_timer);
+ data->summary_update_timer = 0;
+ }
+
+ if (G_UNLIKELY(data->location_name == NULL) ||
+ G_UNLIKELY(data->summary_window == NULL))
+ return FALSE;
+
+ time(&now_t);
+ date = format_date(now_t, "%Y-%m-%d %H:%M:%S %Z", TRUE);
+ title = g_strdup_printf("%s\n%s", data->location_name, date);
+ g_free(date);
+ xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(data->summary_window),
+ title);
+ g_free(title);
+
+ /* compute and schedule the next update */
+ g_get_current_time(&now);
+ now_ms = ((gint64) now.tv_sec * 1000) + ((gint64) now.tv_usec / 1000);
+ update_interval = 1000 - (now_ms % 1000) + 1;
+ data->summary_update_timer =
+ g_timeout_add(update_interval, (GSourceFunc) update_summary_subtitle,
+ data);
+ return FALSE;
+}
+
+
GtkWidget *
create_summary_window(plugin_data *data)
{
GtkWidget *window, *notebook, *vbox, *hbox, *label;
- gchar *title, *symbol;
GdkPixbuf *icon;
xml_time *conditions;
+ gchar *title, *symbol;
conditions = get_current_conditions(data->weatherdata);
window = xfce_titled_dialog_new_with_buttons(_("Weather Report"),
@@ -994,12 +1030,11 @@ create_summary_window(plugin_data *data)
GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CLOSE,
GTK_RESPONSE_ACCEPT, NULL);
- if (data->location_name != NULL) {
- title = g_strdup_printf("%s", data->location_name);
+ if (G_LIKELY(data->location_name != NULL)) {
+ title = g_strdup_printf("%s\n", data->location_name);
xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(window), title);
g_free(title);
}
-
vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), vbox, TRUE, TRUE, 0);
diff --git a/panel-plugin/weather-summary.h b/panel-plugin/weather-summary.h
index 5434fa2..6b06429 100644
--- a/panel-plugin/weather-summary.h
+++ b/panel-plugin/weather-summary.h
@@ -23,6 +23,8 @@ G_BEGIN_DECLS
GtkWidget *create_summary_window(plugin_data *data);
+gboolean update_summary_subtitle(plugin_data *data);
+
void summary_details_free(summary_details *sum);
G_END_DECLS
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 9db161d..9739ee2 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -1353,6 +1353,12 @@ close_summary(GtkWidget *widget,
data->summary_details = NULL;
data->summary_window = NULL;
+ /* deactivate the summary window update timer */
+ if (data->summary_update_timer) {
+ g_source_remove(data->update_timer);
+ data->summary_update_timer = 0;
+ }
+
/* sync toggle button state */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->button), FALSE);
}
@@ -1371,6 +1377,10 @@ forecast_click(GtkWidget *widget,
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->button), TRUE);
data->summary_window = create_summary_window(data);
+
+ /* start the summary window subtitle update timer */
+ update_summary_subtitle(data);
+
g_signal_connect(G_OBJECT(data->summary_window), "destroy",
G_CALLBACK(close_summary), data);
gtk_widget_show_all(data->summary_window);
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 5b5e084..d0da2ca 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -84,6 +84,7 @@ typedef struct {
time_t next_wakeup;
gchar *next_wakeup_reason;
guint update_timer;
+ guint summary_update_timer;
GtkWidget *scrollbox;
gboolean show_scrollbox;
More information about the Xfce4-commits
mailing list