]> Pileus Git - aweather/commitdiff
Add support for auto-update
authorAndy Spencer <andy753421@gmail.com>
Thu, 9 Jun 2011 07:24:26 +0000 (07:24 +0000)
committerAndy Spencer <andy753421@gmail.com>
Thu, 9 Jun 2011 07:51:26 +0000 (07:51 +0000)
Preference and UI changes:
  - Add a timeout interval to the preferences dialog, timeout in minutes.
  - Add a auto-update toggle in the toolbar and menus.

Auto-update is reset on init, refresh, and when any auto-update related
preferences change.

When auto-update timeout is triggered, the viewer's time is
automatically set to the current time.

data/main.ui.in
src/aweather-gui.c
src/aweather-gui.h

index 79c028adaf3f3e332b1ebca1e54508827a5aec4f..a364e2ed164cabb7f815431edfcde1d902e0c2ab 100644 (file)
@@ -4,55 +4,63 @@
   <!-- interface-requires AWeather 0.0 -->
   <!-- interface-naming-policy project-wide -->
   <object class="GtkAction" id="about">
-    <property name="label">About</property>
+    <property name="label">_About</property>
     <property name="stock_id">gtk-about</property>
     <signal name="activate" handler="gtk_window_present" object="about_window" swapped="yes"/>
   </object>
   <object class="GtkAction" id="cleancache">
-    <property name="label">Clean cache</property>
+    <property name="label">_Clean cache</property>
     <property name="short_label">Clean cache</property>
     <property name="tooltip">Clean out old cached files</property>
     <property name="stock_id">gtk-clear</property>
     <signal name="activate" handler="on_cleancache" swapped="no"/>
   </object>
   <object class="GtkAction" id="contents">
-    <property name="label">Contents</property>
+    <property name="label">_Contents</property>
     <property name="short_label">Contents</property>
     <property name="tooltip">AWeather Reference Manual</property>
     <property name="stock_id">gtk-help</property>
     <signal name="activate" handler="on_contents" swapped="no"/>
   </object>
   <object class="GtkToggleAction" id="fullscreen">
-    <property name="label">Fullscreen</property>
+    <property name="label">_Fullscreen</property>
     <property name="stock_id">gtk-fullscreen</property>
     <signal name="toggled" handler="on_fullscreen" swapped="no"/>
   </object>
   <object class="GtkToggleAction" id="offline">
-    <property name="label">Offline</property>
+    <property name="label">_Offline</property>
     <property name="stock_id">gtk-disconnect</property>
     <signal name="toggled" handler="on_offline" swapped="no"/>
   </object>
   <object class="GtkAction" id="prefs">
+    <property name="label" translatable="yes">_Preferences</property>
     <property name="stock_id">gtk-preferences</property>
     <signal name="activate" handler="gtk_window_present" object="prefs_window" swapped="yes"/>
   </object>
   <object class="GtkAction" id="quit">
-    <property name="label">Quit</property>
+    <property name="label">_Quit</property>
     <property name="stock_id">gtk-quit</property>
     <signal name="activate" handler="on_quit" swapped="no"/>
   </object>
   <object class="GtkAction" id="refresh">
-    <property name="label">Refresh</property>
+    <property name="label">_Refresh</property>
     <property name="stock_id">gtk-refresh</property>
     <signal name="activate" handler="on_refresh" swapped="no"/>
   </object>
+  <object class="GtkToggleAction" id="update">
+    <property name="label" translatable="yes">_Auto-update</property>
+    <property name="short_label" translatable="yes">Auto-update</property>
+    <property name="tooltip" translatable="yes">Automatically refresh after a timeout</property>
+    <property name="stock_id">gtk-media-play</property>
+    <signal name="toggled" handler="on_update" swapped="no"/>
+  </object>
   <object class="GtkAction" id="zoomin">
-    <property name="label">Zoom In</property>
+    <property name="label">Zoom _In</property>
     <property name="stock_id">gtk-zoom-in</property>
     <signal name="activate" handler="on_zoomin" swapped="no"/>
   </object>
   <object class="GtkAction" id="zoomout">
-    <property name="label">Zoom Out</property>
+    <property name="label">Zoom _Out</property>
     <property name="stock_id">gtk-zoom-out</property>
     <signal name="activate" handler="on_zoomout" swapped="no"/>
   </object>
@@ -370,14 +378,28 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                       </object>
                     </child>
                     <child>
-                      <object class="GtkImageMenuItem" id="main_menu_file_prefs">
+                      <object class="GtkImageMenuItem" id="main_menu_file_refresh">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="related_action">prefs</property>
+                        <property name="related_action">refresh</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
                     </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="main_menu_file_update">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="related_action">update</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="main_menu_file_0">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                      </object>
+                    </child>
                     <child>
                       <object class="GtkImageMenuItem" id="main_menu_file_cleancache">
                         <property name="visible">True</property>
@@ -388,7 +410,7 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                       </object>
                     </child>
                     <child>
-                      <object class="GtkSeparatorMenuItem" id="main_menu_file_0">
+                      <object class="GtkSeparatorMenuItem" id="main_menu_file_1">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                       </object>
@@ -406,6 +428,30 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkMenuItem" id="main_menu_edit">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="label" translatable="yes">_Edit</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="main_menu_edit_menu">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="main_menu_edit_prefs">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="related_action">prefs</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
             <child>
               <object class="GtkMenuItem" id="main_menu_view">
                 <property name="visible">True</property>
@@ -442,25 +488,11 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                       </object>
                     </child>
                     <child>
-                      <object class="GtkCheckMenuItem" id="main_menu_view_fullscreen">
+                      <object class="GtkImageMenuItem" id="main_menu_view_fullscreen">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="related_action">fullscreen</property>
                         <property name="use_underline">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="main_menu_view_1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkImageMenuItem" id="main_menu_view_refresh">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="related_action">refresh</property>
-                        <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
                     </child>
@@ -489,7 +521,7 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                       </object>
                     </child>
                     <child>
-                      <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
+                      <object class="GtkSeparatorMenuItem" id="main_menu_help_0">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                       </object>
@@ -599,6 +631,19 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                 <property name="homogeneous">True</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkToggleToolButton" id="main_tb_update">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="related_action">update</property>
+                <property name="label" translatable="yes">toolbutton1</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkSeparatorToolItem" id="main_tb_2">
                 <property name="visible">True</property>
@@ -775,6 +820,13 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
       <column type="gboolean"/>
     </columns>
   </object>
+  <object class="GtkAdjustment" id="prefs_general_freq_adj">
+    <property name="lower">1</property>
+    <property name="upper">60</property>
+    <property name="value">5</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">5</property>
+  </object>
   <object class="GtkAdjustment" id="prefs_general_log_adj">
     <property name="upper">8</property>
     <property name="step_increment">1</property>
@@ -858,6 +910,49 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                                 <property name="position">0</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkHBox" id="prefs_general_freq_0">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">5</property>
+                                <child>
+                                  <object class="GtkLabel" id="prefs_general_freq_label">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label" translatable="yes">Update Freq</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkSpinButton" id="prefs_general_freq">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="invisible_char">●</property>
+                                    <property name="primary_icon_activatable">False</property>
+                                    <property name="secondary_icon_activatable">False</property>
+                                    <property name="primary_icon_sensitive">True</property>
+                                    <property name="secondary_icon_sensitive">True</property>
+                                    <property name="adjustment">prefs_general_freq_adj</property>
+                                    <signal name="value-changed" handler="on_update_freq_changed" swapped="no"/>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">True</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
                             <child>
                               <object class="GtkHBox" id="prefs_general_site_0">
                                 <property name="visible">True</property>
@@ -899,7 +994,7 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                               <packing>
                                 <property name="expand">True</property>
                                 <property name="fill">True</property>
-                                <property name="position">1</property>
+                                <property name="position">2</property>
                               </packing>
                             </child>
                             <child>
@@ -941,7 +1036,7 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                               <packing>
                                 <property name="expand">True</property>
                                 <property name="fill">True</property>
-                                <property name="position">2</property>
+                                <property name="position">3</property>
                               </packing>
                             </child>
                             <child>
@@ -985,7 +1080,7 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                               <packing>
                                 <property name="expand">True</property>
                                 <property name="fill">True</property>
-                                <property name="position">3</property>
+                                <property name="position">4</property>
                               </packing>
                             </child>
                           </object>
@@ -1072,6 +1167,7 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
   </object>
   <object class="GtkSizeGroup" id="prefs_general_size">
     <widgets>
+      <widget name="prefs_general_freq_label"/>
       <widget name="prefs_general_log_label"/>
       <widget name="prefs_general_url_label"/>
       <widget name="prefs_general_site_label"/>
index 7b42818d912452dc08c0a344c45e8d549ec62db4..1b50efed5d87e016f595f3de652ab80ad9d0d0ab 100644 (file)
@@ -116,7 +116,6 @@ G_MODULE_EXPORT void on_zoomout(GtkAction *action, AWeatherGui *self)
 
 G_MODULE_EXPORT void on_fullscreen(GtkToggleAction *action, AWeatherGui *self)
 {
-       g_message("fullscreen");
        gchar *hide[] = {"main_menu", "main_sidebar", "main_tabs"};
        if (gtk_toggle_action_get_active(action)) {
                gtk_window_fullscreen(GTK_WINDOW(self));
@@ -134,7 +133,37 @@ G_MODULE_EXPORT void on_refresh(GtkAction *action, AWeatherGui *self)
        grits_viewer_refresh(self->viewer);
 }
 
-G_MODULE_EXPORT void on_plugin_toggled(GtkCellRendererToggle *cell, gchar *path_str, AWeatherGui *self)
+static gboolean on_update_timeout(AWeatherGui *self)
+{
+       g_debug("AWeatherGui: on_update_timeout");
+       grits_viewer_set_time(self->viewer, time(NULL));
+       grits_viewer_refresh(self->viewer);
+       return FALSE;
+}
+static void set_update_timeout(AWeatherGui *self)
+{
+       GObject *action = aweather_gui_get_object(self, "update");
+       gint freq = grits_prefs_get_integer(self->prefs, "aweather/update_freq", NULL);
+       if (self->update_source) {
+               g_debug("AWeatherGui: set_update_timeout - clear");
+               g_source_remove(self->update_source);
+       }
+       self->update_source = 0;
+       if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) && freq > 0) {
+               g_debug("AWeatherGui: set_update_timeout - %d min", freq);
+               self->update_source = g_timeout_add_seconds(freq*60,
+                               (GSourceFunc)on_update_timeout, self);
+       }
+}
+G_MODULE_EXPORT void on_update(GtkToggleAction *action, AWeatherGui *self)
+{
+       grits_prefs_set_boolean(self->prefs, "aweather/update_enab",
+                       gtk_toggle_action_get_active(action));
+       set_update_timeout(self);
+}
+
+G_MODULE_EXPORT void on_plugin_toggled(GtkCellRendererToggle *cell,
+               gchar *path_str, AWeatherGui *self)
 {
        GtkWidget    *tview = aweather_gui_get_widget(self, "prefs_plugins_view");
        GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(tview));
@@ -218,6 +247,15 @@ G_MODULE_EXPORT void on_offline(GtkToggleAction *action, AWeatherGui *self)
        grits_viewer_set_offline(self->viewer, value);
 }
 
+G_MODULE_EXPORT int on_update_freq_changed(GtkSpinButton *spinner, AWeatherGui *self)
+{
+       gint value = gtk_spin_button_get_value_as_int(spinner);
+       g_debug("AWeatherGui: on_update_freq_changed - %p, freq=%d", self, value);
+       grits_prefs_set_integer(self->prefs, "aweather/update_freq", value);
+       set_update_timeout(self);
+       return TRUE;
+}
+
 G_MODULE_EXPORT void on_initial_site_changed(GtkComboBox *combo, AWeatherGui *self)
 {
        gchar *code;
@@ -282,12 +320,15 @@ static void site_setup(AWeatherGui *self)
 static void prefs_setup(AWeatherGui *self)
 {
        /* Set values */
+       gint   uf = grits_prefs_get_integer(self->prefs, "aweather/update_freq",  NULL);
        gchar *nu = grits_prefs_get_string (self->prefs, "aweather/nexrad_url",   NULL);
        gint   ll = grits_prefs_get_integer(self->prefs, "aweather/log_level",    NULL);
        gchar *is = grits_prefs_get_string (self->prefs, "aweather/initial_site", NULL);
+       GtkWidget *ufw = aweather_gui_get_widget(self, "prefs_general_freq");
        GtkWidget *nuw = aweather_gui_get_widget(self, "prefs_general_url");
        GtkWidget *llw = aweather_gui_get_widget(self, "prefs_general_log");
        GtkWidget *isw = aweather_gui_get_widget(self, "prefs_general_site");
+       if (uf) gtk_spin_button_set_value(GTK_SPIN_BUTTON(ufw), uf);
        if (nu) gtk_entry_set_text(GTK_ENTRY(nuw), nu), g_free(nu);
        if (ll) gtk_spin_button_set_value(GTK_SPIN_BUTTON(llw), ll);
        if (is) {
@@ -310,6 +351,13 @@ static void prefs_setup(AWeatherGui *self)
        gtk_tree_view_append_column(tview, col2);
        g_signal_connect(rend2, "toggled", G_CALLBACK(on_plugin_toggled), self);
        gtk_tree_view_set_model(GTK_TREE_VIEW(tview), GTK_TREE_MODEL(self->gtk_plugins));
+
+       /* Setup auto update enable */
+       gboolean auto_update = grits_prefs_get_boolean(self->prefs, "aweather/update_enab", NULL);
+       GObject *action      = aweather_gui_get_object(self, "update");
+       gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), auto_update);
+       g_signal_connect_swapped(self->viewer, "refresh", G_CALLBACK(set_update_timeout), self);
+       set_update_timeout(self);
 }
 
 static void time_setup(AWeatherGui *self)
index 640ff2a3e9f93884bd0a43f87c99d60414cccff0..ba74cab7656691b54fa965eb76716bb18d6e8721 100644 (file)
@@ -43,6 +43,7 @@ struct _AWeatherGui {
        GritsPlugins *plugins;
        GritsPrefs   *prefs;
        GtkListStore *gtk_plugins;
+       guint         update_source;
 };
 
 struct _AWeatherGuiClass {