Libravatar: more compact prefs, add hint to entry
[claws.git] / src / plugins / libravatar / libravatar_prefs.c
index b85cfa44ece17f96cdf2415fcf2d4b69559cefc9..4c015451af2535a62190d22fbd692a61ae243cd4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2014 Hiroyuki Yamamoto and the Claws Mail Team
- * Copyright (C) 2014 Ricardo Mones
+ * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 2015 Ricardo Mones
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 #define PREFS_BLOCK_NAME "Libravatar"
 #define NUM_DEF_BUTTONS 7
+#define CUSTOM_URL_BUTTON_INDEX 6
 /* cache interval goes from 1 hour to 30 days */
 #define INTERVAL_MIN_H 1.0
 #define INTERVAL_MAX_H 720.0
+/* timeout interval goes from 0 seconds (= use general timeout value)
+   to (general timeout value - 1) seconds */
+#define TIMEOUT_MIN_S 0.0
 
 LibravatarPrefs libravatarprefs;
 GHashTable *libravatarmisses;
@@ -56,6 +60,7 @@ struct LibravatarPrefsPage
 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
        GtkWidget *allow_federated_check;
 #endif
+       GtkWidget *timeout;
 };
 
 struct LibravatarPrefsPage libravatarprefs_page;
@@ -84,6 +89,9 @@ static PrefParam param[] = {
          &libravatarprefs.allow_federated,
           P_BOOL, NULL, NULL, NULL },
 #endif
+       { "timeout", "0",
+         &libravatarprefs.timeout,
+          P_INT, NULL, NULL, NULL },
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
@@ -102,9 +110,28 @@ static void cache_icons_check_toggled_cb(GtkToggleButton *button, gpointer data)
                                 gtk_toggle_button_get_active(button));
 }
 
+static GtkWidget *labeled_spinner_box(gchar *label, GtkWidget *spinner, gchar *units, gchar *hint)
+{
+       GtkWidget *lbl, *lbla, *hbox;
+
+       lbl = gtk_label_new(label);
+       gtk_widget_show(lbl);
+       lbla = gtk_label_new(units);
+       gtk_widget_show(lbla);
+       hbox = gtk_hbox_new(FALSE, 6);
+       if (hint != NULL) {
+               CLAWS_SET_TIP(spinner, hint);
+       }
+       gtk_box_pack_start(GTK_BOX(hbox), lbl, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), lbla, FALSE, FALSE, 0);
+
+       return hbox;
+}
+
 static GtkWidget *p_create_frame_cache(struct LibravatarPrefsPage *page)
 {
-       GtkWidget *vbox, *checkbox, *lbl, *lbla, *spinner, *hbox;
+       GtkWidget *vbox, *checkbox, *spinner, *hbox;
        GtkAdjustment *adj;
 
        vbox =  gtk_vbox_new(FALSE, 6);
@@ -118,10 +145,6 @@ static GtkWidget *p_create_frame_cache(struct LibravatarPrefsPage *page)
                         G_CALLBACK(cache_icons_check_toggled_cb), NULL);
        page->cache_icons_check = checkbox;
 
-       lbl = gtk_label_new(_("Cache refresh interval"));
-       gtk_widget_show(lbl);
-       lbla = gtk_label_new(_("hours"));
-       gtk_widget_show(lbla);
        adj = (GtkAdjustment *) gtk_adjustment_new(
                                        libravatarprefs.cache_interval,
                                        INTERVAL_MIN_H, INTERVAL_MAX_H, 1.0,
@@ -129,10 +152,7 @@ static GtkWidget *p_create_frame_cache(struct LibravatarPrefsPage *page)
        spinner = gtk_spin_button_new(adj, 1.0, 0);
        gtk_widget_show(spinner);
        gtk_widget_set_sensitive(spinner, libravatarprefs.cache_icons);
-       hbox = gtk_hbox_new(FALSE, 6);
-       gtk_box_pack_start(GTK_BOX(hbox), lbl, FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(hbox), lbla, FALSE, FALSE, 0);
+       hbox = labeled_spinner_box(_("Cache refresh interval"), spinner, _("hours"), NULL);
        page->cache_interval_spin = spinner;
 
        gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
@@ -180,7 +200,7 @@ static const guint radio_value[] = {
 
 static GtkWidget *p_create_frame_missing(struct LibravatarPrefsPage *page)
 {
-       GtkWidget *vbox, *radio[NUM_DEF_BUTTONS], *hbox, *label, *entry;
+       GtkWidget *vbox, *radio[NUM_DEF_BUTTONS], *hbox, *entry;
        gboolean enable = FALSE;
        int i, e = 0;
        gchar *radio_label[] = {
@@ -210,7 +230,27 @@ static GtkWidget *p_create_frame_missing(struct LibravatarPrefsPage *page)
                radio[i] = gtk_radio_button_new_with_label_from_widget(
                                (i > 0)? GTK_RADIO_BUTTON(radio[i - 1]): NULL, radio_label[i]);
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio[i]), enable);
-               gtk_box_pack_start(GTK_BOX(vbox), radio[i], FALSE, FALSE, 0);
+               if (i == CUSTOM_URL_BUTTON_INDEX) {
+                       /* set related entry next to radio button */
+                       entry = gtk_entry_new_with_max_length(MAX_URL_LENGTH);
+                       CLAWS_SET_TIP(entry, _("Enter the URL you want to be "
+                               "redirected when no user icon is available. "
+                               "Leave an empty URL to use the default "
+                               "libravatar orange icon."));
+                       gtk_widget_show(entry);
+                       gtk_entry_set_text(GTK_ENTRY(entry),
+                               libravatarprefs.default_mode_url);
+                       hbox = gtk_hbox_new(FALSE, 6);
+                       gtk_box_pack_start(GTK_BOX(hbox), radio[i], FALSE, FALSE, 0);
+                       gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
+                       gtk_widget_set_sensitive(entry,
+                               (libravatarprefs.default_mode == DEF_MODE_URL)
+                               ? TRUE: FALSE);
+                       page->defm_url_text = entry;
+                       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+               } else {
+                       gtk_box_pack_start(GTK_BOX(vbox), radio[i], FALSE, FALSE, 0);
+               }
                g_signal_connect(radio[i], "toggled",
                                 G_CALLBACK(default_mode_radio_button_cb),
                                 (gpointer) &(radio_value[i]));
@@ -226,27 +266,15 @@ static GtkWidget *p_create_frame_missing(struct LibravatarPrefsPage *page)
        prefs_common.enable_avatars = (libravatarprefs.default_mode == DEF_MODE_NONE)
                                                ? AVATARS_ENABLE_BOTH: AVATARS_DISABLE;
 
-       label = gtk_label_new(_("URL:"));
-       gtk_widget_show(label);
-       entry = gtk_entry_new_with_max_length(MAX_URL_LENGTH);
-       gtk_widget_show(entry);
-       gtk_entry_set_text(GTK_ENTRY(entry), libravatarprefs.default_mode_url);
-
-       hbox = gtk_hbox_new(FALSE, 6);
-       gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
-       gtk_widget_set_sensitive(entry,
-               (libravatarprefs.default_mode == DEF_MODE_URL)? TRUE: FALSE);
-       page->defm_url_text = entry;
 
-       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 
        return vbox;
 }
 
 static GtkWidget *p_create_frame_network(struct LibravatarPrefsPage *page)
 {
-       GtkWidget *vbox, *chk_redirects;
+       GtkWidget *vbox, *chk_redirects, *spinner, *hbox;
+       GtkAdjustment *adj;
 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
        GtkWidget *chk_federated;
 #endif
@@ -272,6 +300,22 @@ static GtkWidget *p_create_frame_network(struct LibravatarPrefsPage *page)
        gtk_box_pack_start(GTK_BOX(vbox), chk_federated, FALSE, FALSE, 0);
 #endif
 
+       adj = (GtkAdjustment *) gtk_adjustment_new(
+                                       libravatarprefs.timeout,
+                                       TIMEOUT_MIN_S,
+                                       (prefs_common_get_prefs()->io_timeout_secs > 0)
+                                       ? (prefs_common_get_prefs()->io_timeout_secs - 1)
+                                       : 0,
+                                       1.0, 0.0, 0.0);
+       spinner = gtk_spin_button_new(adj, 1.0, 0);
+       gtk_widget_show(spinner);
+       hbox = labeled_spinner_box(_("Request timeout"), spinner, _("seconds"),
+               _("Set to 0 to use global socket I/O timeout. "
+                  "Maximum value must be also less than global socket "
+                  "I/O timeout."));
+       page->timeout = spinner;
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
        return vbox;
 }
 
@@ -287,12 +331,12 @@ static GtkWidget *p_create_frame_network(struct LibravatarPrefsPage *page)
   │ ( ) MonsterID                                        │
   │ ( ) Wavatar                                          │
   │ ( ) Retro                                            │
-  │ ( ) Custom URL                                       │
-  │     URL: [_________________________________________] │
+  │ ( ) Custom URL [___________________________________] │
   └──────────────────────────────────────────────────────┘
   ┌─Network──────────────────────────────────────────────┐
   │ [✔] Allow redirects                                  │
   │ [✔] Federated servers                                │
+  │ Timeout [ 10 |⬘] seconds                             │
   └──────────────────────────────────────────────────────┘
  */
 static void libravatar_prefs_create_widget_func(PrefsPage * _page,
@@ -387,6 +431,9 @@ static void libravatar_prefs_save_func(PrefsPage * _page)
        libravatarprefs.allow_federated = gtk_toggle_button_get_active(
                GTK_TOGGLE_BUTTON(page->allow_federated_check));
 #endif
+       /* timeout */
+       libravatarprefs.timeout = gtk_spin_button_get_value_as_int(
+               GTK_SPIN_BUTTON(page->timeout));
 
        libravatar_save_config();
 }