[gnome-calendar] window: syncronize sources from time to time
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] window: syncronize sources from time to time
- Date: Sat, 3 Jan 2015 19:17:19 +0000 (UTC)
commit 8aefe7131694b5e2f4ebcf453fc472918c21fb8b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sat Jan 3 17:17:09 2015 -0200
window: syncronize sources from time to time
Currently, it is hardcoded 5min for active windows, and 20min for innactive windows. These values may
change later.
data/ui/window.ui | 1 +
src/gcal-window.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index f9e6cbb..7549dcc 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -9,6 +9,7 @@
<property name="default_height">600</property>
<property name="show_menubar">False</property>
<signal name="key-press-event" handler="key_pressed" object="GcalWindow" swapped="no"/>
+ <signal name="window-state-event" handler="window_state_changed" object="GcalWindow" swapped="no"/>
<child>
<object class="GtkOverlay" id="views_overlay">
<property name="visible">True</property>
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 846bf74..6ccb886 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -100,6 +100,8 @@ typedef struct
/* calendar management */
GMenu *calendar_menu;
+ gint refresh_timeout;
+ gint refresh_timeout_id;
/* temp to keep event_creation */
gboolean open_edit_dialog;
@@ -115,6 +117,8 @@ enum
};
#define SAVE_GEOMETRY_ID_TIMEOUT 100 /* ms */
+#define FAST_REFRESH_TIMEOUT 300000 /* ms */
+#define SLOW_REFRESH_TIMEOUT 1200000 /* ms */
static gboolean key_pressed (GtkWidget *widget,
GdkEvent *event,
@@ -177,6 +181,12 @@ static void on_calendar_toggled (GSimpleAction *a
GVariant *value,
gpointer user_data);
+static gboolean refresh_sources (GcalWindow *window);
+
+static gboolean window_state_changed (GtkWidget *window,
+ GdkEvent *event,
+ gpointer user_data);
+
/* handling events interaction */
static void create_event (gpointer user_data,
GtkWidget *widget);
@@ -804,6 +814,53 @@ on_calendar_toggled (GSimpleAction *action,
g_simple_action_set_state (action, value);
}
+static gboolean
+refresh_sources (GcalWindow *window)
+{
+ GcalWindowPrivate *priv;
+ static gint current_timeout = 0;
+
+ priv = gcal_window_get_instance_private (window);
+
+ /* update current_timeout the first time it's called */
+ if (current_timeout == 0)
+ current_timeout = priv->refresh_timeout;
+
+ /* refresh sources */
+ gcal_manager_refresh (priv->manager);
+
+ /* check window state */
+ if (current_timeout != 0 && current_timeout != priv->refresh_timeout)
+ {
+ current_timeout = priv->refresh_timeout;
+
+ priv->refresh_timeout_id = g_timeout_add (priv->refresh_timeout, (GSourceFunc) refresh_sources,
window);
+
+ return G_SOURCE_REMOVE;
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
+static gboolean
+window_state_changed (GtkWidget *window,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ GcalWindowPrivate *priv;
+ GdkEventWindowState *state;
+ gboolean active;
+
+ priv = gcal_window_get_instance_private (GCAL_WINDOW (window));
+ state = (GdkEventWindowState*) event;
+ active = (state->new_window_state & GDK_WINDOW_STATE_FOCUSED);
+
+ /* update timeout time according to the state */
+ priv->refresh_timeout = (active ? FAST_REFRESH_TIMEOUT : SLOW_REFRESH_TIMEOUT);
+
+ return FALSE;
+}
+
static void
create_event (gpointer user_data,
GtkWidget *widget)
@@ -1192,6 +1249,9 @@ gcal_window_class_init(GcalWindowClass *klass)
/* Event creation related */
gtk_widget_class_bind_template_callback (widget_class, create_event);
gtk_widget_class_bind_template_callback (widget_class, close_new_event_widget);
+
+ /* Syncronization related */
+ gtk_widget_class_bind_template_callback (widget_class, window_state_changed);
}
static void
@@ -1307,6 +1367,9 @@ gcal_window_constructed (GObject *object)
g_signal_connect (priv->views[i], "event-activated", G_CALLBACK (event_activated), object);
}
}
+
+ /* refresh timeout, first is fast */
+ priv->refresh_timeout_id = g_timeout_add (FAST_REFRESH_TIMEOUT, (GSourceFunc) refresh_sources, object);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]