Fix wrong time unit shown in offline-override dialog (IMAP), and
[claws.git] / src / inc.c
index 473e11e83c9259fc20ac0de0e24451b8132685a1..ed681fb3ab85c6200ca00dd611dfc4e518393447 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -65,6 +65,9 @@ extern SessionStats session_stats;
 
 static GList *inc_dialog_list = NULL;
 
+static time_t inc_offline_overridden_yes = 0;
+static time_t inc_offline_overridden_no  = 0;
+
 guint inc_lock_count = 0;
 
 static GdkPixbuf *currentpix;
@@ -1567,6 +1570,7 @@ void inc_account_autocheck_timer_remove(PrefsAccount *account)
        cm_return_if_fail(account != NULL);
 
        if (account->autocheck_timer != 0) {
+               g_source_remove(account->autocheck_timer);
                debug_print("INC: account %d: removed inc timer %d\n", account->account_id,
                                account->autocheck_timer);
                account->autocheck_timer = 0;
@@ -1592,9 +1596,7 @@ void inc_account_autocheck_timer_set_interval(PrefsAccount *account)
 
 gboolean inc_offline_should_override(gboolean force_ask, const gchar *msg)
 {
-       static time_t overridden_yes = 0;
-       static time_t overridden_no  = 0;
-       int length = 10; /* minutes */
+       gint length = 10; /* seconds */
        gint answer = G_ALERTDEFAULT;
 
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
@@ -1604,27 +1606,51 @@ gboolean inc_offline_should_override(gboolean force_ask, const gchar *msg)
 #endif
 
        if (prefs_common.autochk_newmail)
-               length = prefs_common.autochk_itv; /* minutes */
+               length = prefs_common.autochk_itv; /* seconds */
 
        if (force_ask) {
-               overridden_no = (time_t)0;
+               inc_offline_overridden_no = (time_t)0;
        }
 
        if (prefs_common.work_offline) {
                gchar *tmp = NULL;
                
-               if (time(NULL) - overridden_yes < length * 60) /* seconds */
+               if (time(NULL) - inc_offline_overridden_yes < length * 60) /* seconds */
                         return TRUE;
-               else if (time(NULL) - overridden_no < length * 60) /* seconds */
+               else if (time(NULL) - inc_offline_overridden_no < length * 60) /* seconds */
                         return FALSE;
 
-               if (!force_ask)
+               if (!force_ask) {
+                       gchar *unit = _("seconds");
+
+                       /* show the offline override time (length) using the must appropriate unit:
+                          the biggest unit possible (hours, minutes, seconds), provided that there
+                          is not inferior unit involved: 1 hour, 150 minutes, 25 minutes, 90 minutes,
+                          30 seconds, 90 seconds. */
+                       if ((length / 3600) > 0) { /* hours? */
+                               if (((length % 3600) % 60) == 0) { /* no seconds left? */
+                                       if ((length % 3600) > 0) { /* minutes left? */
+                                               length = length / 60;
+                                               unit = ngettext("minute", "minutes", length);
+                                       } else {
+                                               length = length / 3600;
+                                               unit = ngettext("hour", "hours", length);
+                                       }
+                               } /* else: seconds */
+                       } else {
+                               if ((length / 60) > 0) { /* minutes left? */
+                                       if ((length % 60) == 0) {
+                                               length = length / 60;
+                                               unit = ngettext("minute", "minutes", length);
+                                       }
+                               } /* else: seconds */
+                       }
                        tmp = g_strdup_printf(
-                               _("%s%sYou're working offline. Override for %d minutes?"),
+                               _("%s%sYou're working offline. Override for %d %s?"),
                                msg?msg:"", 
                                msg?"\n\n":"",
-                               length);
-               else
+                               length, unit);
+               else
                        tmp = g_strdup_printf(
                                _("%s%sYou're working offline. Override?"),
                                msg?msg:"", 
@@ -1636,17 +1662,23 @@ gboolean inc_offline_should_override(gboolean force_ask, const gchar *msg)
                                !force_ask? _("On_ly once"):NULL, ALERTFOCUS_SECOND);
                g_free(tmp);
                if (answer == G_ALERTALTERNATE) {
-                       overridden_yes = time(NULL);
+                       inc_offline_overridden_yes = time(NULL);
                        return TRUE;
                } else if (answer == G_ALERTDEFAULT) {
                        if (!force_ask)
-                               overridden_no  = time(NULL);
+                               inc_offline_overridden_no  = time(NULL);
                        return FALSE;
                } else {
-                       overridden_yes = (time_t)0;
-                       overridden_no  = (time_t)0;
+                       inc_reset_offline_override_timers();
                        return TRUE;
                }
        }
        return TRUE;
 }
+
+void inc_reset_offline_override_timers()
+{
+       debug_print("resetting offline override timers\n");
+       inc_offline_overridden_yes = (time_t)0;
+       inc_offline_overridden_no  = (time_t)0;
+}