]> granicus.if.org Git - handbrake/commitdiff
LinGui: add preference for update check frequency
authorjstebbins <jstebbins.hb@gmail.com>
Wed, 17 Jun 2009 19:19:04 +0000 (19:19 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Wed, 17 Jun 2009 19:19:04 +0000 (19:19 +0000)
Options are Never, Daily, Weekly, and Monthly.
Default is Weekly.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2561 b64f7644-9d1e-0410-96f1-a4d463321fa5

gtk/src/callbacks.c
gtk/src/ghb.ui
gtk/src/hb-backend.c
gtk/src/internal_defaults.xml
gtk/src/main.c

index 09a213e57ea420596bb6f3d1d5dff17025dde370..aa44aef280874cf08a211fe0cfa4eb073f783abf 100644 (file)
@@ -18,6 +18,7 @@
 #include <string.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#include <time.h>
 
 #if !defined(_WIN32)
 #include <poll.h>
@@ -60,6 +61,8 @@ static void update_chapter_list(signal_user_data_t *ud);
 static GList* dvd_device_list();
 static void prune_logs(signal_user_data_t *ud);
 void ghb_notify_done(signal_user_data_t *ud);
+gpointer ghb_check_update(signal_user_data_t *ud);
+static gboolean appcast_busy = FALSE;
 
 // This is a dependency map used for greying widgets
 // that are dependent on the state of another widget.
@@ -2256,6 +2259,37 @@ ghb_timer_cb(gpointer data)
                ghb_set_preview_image (ud);
                update_preview = FALSE;
        }
+
+       if (!appcast_busy)
+       {
+               gchar *updates;
+               updates = ghb_settings_get_string(ud->settings, "check_updates");
+               gint64 duration = 0;
+               if (strcmp(updates, "daily") == 0)
+                       duration = 60 * 60 * 24;
+               else if (strcmp(updates, "weekly") == 0)
+                       duration = 60 * 60 * 24 * 7;
+               else if (strcmp(updates, "monthly") == 0)
+                       duration = 60 * 60 * 24 * 7;
+
+               g_free(updates);
+               if (duration != 0)
+               {
+                       gint64 last;
+                       time_t tt;
+
+                       last = ghb_settings_get_int64(ud->settings, "last_update_check");
+                       time(&tt);
+                       if (last + duration < tt)
+                       {
+                               ghb_settings_set_int64(ud->settings, 
+                                                                               "last_update_check", tt);
+                               ghb_pref_save(ud->settings, "last_update_check");
+                               g_thread_create((GThreadFunc)ghb_check_update, ud, 
+                                                               FALSE, NULL);
+                       }
+               }
+       }
        return TRUE;
 }
 
@@ -3487,6 +3521,7 @@ done:
        g_free(ud->appcast);
        ud->appcast_len = 0;
        ud->appcast = NULL;
+       appcast_busy = FALSE;
 }
 
 void
@@ -3544,6 +3579,7 @@ ghb_net_open(signal_user_data_t *ud, gchar *address, gint port)
        if( !( host = gethostbyname( address ) ) )
        {
                g_warning( "gethostbyname failed (%s)", address );
+               appcast_busy = FALSE;
                return NULL;
        }
 
@@ -3556,12 +3592,14 @@ ghb_net_open(signal_user_data_t *ud, gchar *address, gint port)
        if( fd < 0 )
        {
                g_debug( "socket failed" );
+               appcast_busy = FALSE;
                return NULL;
        }
 
        if(connect(fd, (struct sockaddr*)&sock, sizeof(struct sockaddr_in )) < 0 )
        {
                g_debug( "connect failed" );
+               appcast_busy = FALSE;
                return NULL;
        }
        ioc = g_io_channel_unix_new(fd);
@@ -3581,6 +3619,7 @@ ghb_check_update(signal_user_data_t *ud)
        GError *gerror = NULL;
 
        g_debug("ghb_check_update");
+       appcast_busy = TRUE;
        if (hb_get_build(NULL) % 100)
        {
                query = 
index 233d583fda94ed4466247dd585d194a1f2bdc0da..5e64ed54b8237d90ce0f48fe31960e7fcd5d89a3 100644 (file)
@@ -3496,16 +3496,42 @@ no-dct-decimate=0:cabac=1</property>
                       <object class="GtkVBox" id="vbox42">
                         <property name="visible">True</property>
                         <child>
-                          <object class="GtkCheckButton" id="check_updates">
+                          <object class="GtkAlignment" id="alignment60">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="tooltip_text">Check for updates to HandBrake at startup.</property>
-                            <property name="label" translatable="yes">Check for Updates</property>
-                            <property name="draw_indicator">True</property>
-                            <signal name="toggled" handler="pref_changed_cb"/>
+                            <property name="left_padding">0</property>
+                            <child>
+                              <object class="GtkHBox" id="hbox80">
+                                <property name="spacing">4</property>
+                                <property name="visible">True</property>
+                                <child>
+                                  <object class="GtkComboBox" id="check_updates">
+                                    <property name="visible">True</property>
+                                    <property name="tooltip_text">Frequency to poll for HandBrake updates.</property>
+                                    <signal name="changed" handler="pref_changed_cb"/>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label74">
+                                    <property name="justify">GTK_JUSTIFY_LEFT</property>
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Check For Updates</property>
+                                    <property name="use_markup">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
                           </object>
                           <packing>
                             <property name="expand">False</property>
+                            <property name="position">0</property>
                           </packing>
                         </child>
 
@@ -3610,6 +3636,7 @@ non-hidef screens.  </property>
                             <property name="left_padding">4</property>
                             <child>
                               <object class="GtkHBox" id="hbox66">
+                                <property name="spacing">4</property>
                                 <property name="visible">True</property>
                                 <child>
                                   <object class="GtkSpinButton" id="preview_count">
@@ -3634,7 +3661,7 @@ increases scan duration.</property>
                                   <object class="GtkLabel" id="label77">
                                     <property name="justify">GTK_JUSTIFY_LEFT</property>
                                     <property name="visible">True</property>
-                                    <property name="label" translatable="yes"> Number of previews </property>
+                                    <property name="label" translatable="yes">Number of previews</property>
                                     <property name="use_markup">True</property>
                                   </object>
                                   <packing>
index ed0d54db0eeda358ab3ea4a79172a77ded2d5fea..4a2589c78f5d9baf10fded61ee23ce880dffc6d1 100644 (file)
@@ -107,6 +107,19 @@ combo_opts_t logging_opts =
        d_logging_opts
 };
 
+static options_map_t d_appcast_update_opts[] =
+{
+       {"Never", "never", 0, "never"},
+       {"Daily", "daily", 1, "daily"},
+       {"Weekly", "weekly", 2, "weekly"},
+       {"Monthly", "monthly", 3, "monthly"},
+};
+combo_opts_t appcast_update_opts =
+{
+       sizeof(d_appcast_update_opts)/sizeof(options_map_t),
+       d_appcast_update_opts
+};
+
 static options_map_t d_vqual_granularity_opts[] =
 {
        {"0.2",  "0.2",  0.2,  "0.2"},
@@ -322,6 +335,7 @@ combo_name_map_t combo_name_map[] =
        {"PicturePAR", &par_opts},
        {"PictureModulus", &alignment_opts},
        {"LoggingLevel", &logging_opts},
+       {"check_updates", &appcast_update_opts},
        {"VideoQualityGranularity", &vqual_granularity_opts},
        {"FileFormat", &container_opts},
        {"PictureDeinterlace", &deint_opts},
@@ -2196,6 +2210,7 @@ ghb_update_ui_combo_box(
                generic_opts_set(ud->builder, "PicturePAR", &par_opts);
                generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
                generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
+               generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
                generic_opts_set(ud->builder, "FileFormat", &container_opts);
                generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
                generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
index e845e59efed6deebf83763d9ed363b31fec372f2..9bb7651a6788abe6b87ea3f14fd05cab5ab978fa 100644 (file)
                <false />
                <key>title_no_in_destination</key>
                <false />
+               <key>last_update_check</key>
+               <integer>0</integer>
                <key>check_updates</key>
-               <true />
+               <string>weekly</string>
                <key>chapters_in_destination</key>
                <false />
                <key>default_source</key>
index 043c4c6b3db5be4610b4fb453649eb0131284512..0b3eb09a50293122f6b192a0276f4191dbd6c864 100644 (file)
@@ -783,10 +783,7 @@ main (int argc, char *argv[])
        }
        // Reload and check status of the last saved queue
        g_idle_add((GSourceFunc)ghb_reload_queue, ud);
-       if (ghb_settings_get_boolean(ud->settings, "check_updates"))
-       {
-               g_thread_create((GThreadFunc)ghb_check_update, ud, FALSE, NULL);
-       }
+
        // Start timer for monitoring libhb status, 500ms
        g_timeout_add (500, ghb_timer_cb, (gpointer)ud);