make the progress window more responsive when importing mbox file
[claws.git] / src / gtk / gtkutils.c
index a933471f62181a42ab6fd2e7f9c59c4bdffee663..4eea7fb31d61b844e8a865e3e6e7d1076cb39ba6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2018 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
  *
  * 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
@@ -757,7 +757,7 @@ static gboolean move_bar_cb(gpointer data)
        if (!GTK_IS_PROGRESS_BAR(w)) {
                return FALSE;
        }
-
+       gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(w), 0.1);
        gtk_progress_bar_pulse(GTK_PROGRESS_BAR(w));
        GTK_EVENTS_FLUSH();
        return TRUE;
@@ -1224,10 +1224,8 @@ GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *
 {
        GtkWidget *btn;
        GtkWidget *btn_label;
-#if !GTK_CHECK_VERSION(3, 0, 0)
        GdkColormap *cmap;
        gboolean success[2];
-#endif
        GdkColor uri_color[2] = {{0, 0, 0, 0xffff}, {0, 0xffff, 0, 0}};
        gchar *local_url = NULL;
        if (!url)
@@ -1241,11 +1239,9 @@ GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *
        btn = gtk_button_new_with_label(label?label:url);
        gtk_button_set_relief(GTK_BUTTON(btn), GTK_RELIEF_NONE);
        btn_label = gtk_bin_get_child(GTK_BIN((btn)));
-#if !GTK_CHECK_VERSION(3, 0, 0)
        cmap = gdk_drawable_get_colormap(gtk_widget_get_window(window));
        gdk_colormap_alloc_colors(cmap, uri_color, 2, FALSE, TRUE, success);
        if (success[0] == TRUE && success[1] == TRUE) {
-#endif
                GtkStyle *style;
                gtk_widget_ensure_style(btn_label);
                style = gtk_style_copy
@@ -1255,10 +1251,8 @@ GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *
                style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
                gtk_widget_set_style(btn_label, style);
                g_object_unref(style);
-#if !GTK_CHECK_VERSION(3, 0, 0)
        } else
                g_warning("color allocation failed");
-#endif
 
        g_signal_connect(G_OBJECT(btn), "enter",
                         G_CALLBACK(link_btn_enter), window);
@@ -1807,7 +1801,7 @@ GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *src_pixbuf, int box_width,
        return pixbuf;
 }
 
-#if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
+#if defined USE_GNUTLS
 static void auto_configure_done(const gchar *hostname, gint port, gboolean ssl, AutoConfigureData *data)
 {
        gboolean smtp = strcmp(data->tls_service, "submission") == 0 ? TRUE : FALSE;
@@ -1989,3 +1983,144 @@ gboolean auto_configure_service_sync(const gchar *service, const gchar *domain,
        return result;
 }
 #endif
+
+gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
+               gint column, GtkTreeModel **_model, GtkTreeSelection **_selection,
+               GtkTreeIter *_iter)
+{
+       GtkTreeIter iter;
+       GtkTreeModel *model;
+       GtkTreeSelection *sel;
+       gpointer ptr;
+       GType type;
+
+       cm_return_val_if_fail(view != NULL, NULL);
+       cm_return_val_if_fail(column >= 0, NULL);
+
+       model = gtk_tree_view_get_model(view);
+       if (_model != NULL)
+               *_model = model;
+
+       sel = gtk_tree_view_get_selection(view);
+       if (_selection != NULL)
+               *_selection = sel;
+
+       if (!gtk_tree_selection_get_selected(sel, NULL, &iter))
+               return NULL; /* No row selected */
+
+       if (_iter != NULL)
+               *_iter = iter;
+
+       if (gtk_tree_selection_count_selected_rows(sel) > 1)
+               return NULL; /* Can't work with multiselect */
+
+       cm_return_val_if_fail(
+                       gtk_tree_model_get_n_columns(model) > column,
+                       NULL);
+
+       type = gtk_tree_model_get_column_type(model, column);
+       cm_return_val_if_fail(
+                       type == G_TYPE_POINTER || type == G_TYPE_STRING,
+                       NULL);
+
+       gtk_tree_model_get(model, &iter, column, &ptr, -1);
+
+       return ptr;
+}
+
+static GList *get_predefined_times(void)
+{
+       int h,m;
+       GList *times = NULL;
+       for (h = 0; h < 24; h++) {
+               for (m = 0; m < 60; m += 15) {
+                       gchar *tmp = g_strdup_printf("%02d:%02d", h, m);
+                       times = g_list_append(times, tmp);
+               }
+       }
+       return times;
+}
+
+static int get_list_item_num(int h, int m)
+{
+       if (m % 15 != 0)
+               return -1;
+
+       return (h*4 + m/15);
+}
+
+GtkWidget *gtkut_time_select_combo_new()
+{
+       GtkWidget *combo = gtk_combo_box_text_new_with_entry();
+       GList *times = get_predefined_times();
+
+       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), -1);
+       combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(combo), times);
+
+       list_free_strings_full(times);
+
+       return combo;
+}
+
+
+void gtkut_time_select_select_by_time(GtkComboBox *combo, int hour, int minute)
+{
+       gchar *time_text = g_strdup_printf("%02d:%02d", hour, minute);
+       gint num = get_list_item_num(hour, minute);
+
+       if (num > -1)
+               combobox_select_by_text(combo, time_text);
+       else
+               gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo))), time_text);
+
+       g_free(time_text);
+}
+
+static void get_time_from_combo(GtkComboBox *combo, int *h, int *m)
+{
+       gchar *tmp;
+       gchar **parts;
+
+       if (!h || !m) 
+               return;
+
+       tmp = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(combo))), 0, -1);
+       parts = g_strsplit(tmp, ":", 2);
+       if (parts[0] && parts[1] && *parts[0] && *parts[1]) {
+               *h = atoi(parts[0]);
+               *m = atoi(parts[1]);
+       }
+       g_strfreev(parts);
+       g_free(tmp);
+}
+
+gboolean gtkut_time_select_get_time(GtkComboBox *combo, int *hour, int *minute)
+{
+       const gchar *value = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo))));
+
+       if (value == NULL || strlen(value) != 5)
+               return FALSE;
+
+       if (hour == NULL || minute == NULL)
+               return FALSE;
+
+       get_time_from_combo(combo, hour, minute);
+
+       if (*hour < 0 || *hour > 23)
+               return FALSE;
+       if (*minute < 0 || *minute > 59)
+               return FALSE;
+
+       return TRUE;
+}
+
+void gtk_calendar_select_today(GtkCalendar *calendar)
+{
+       time_t t = time (NULL);
+       struct tm buft;
+       struct tm *lt = localtime_r (&t, &buft);
+
+       mktime(lt);
+       gtk_calendar_select_day(calendar, lt->tm_mday);
+       gtk_calendar_select_month(calendar, lt->tm_mon, lt->tm_year + 1900);
+}