Fix some copyright headers
[claws.git] / src / gtk / gtkutils.c
index 695ca623c97ce5a5361990afd939f5e70c1814cc..23b19a6e294dbc27b582f358772531ba19c0580e 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2018 Hiroyuki Yamamoto and the Claws Mail team
  *
  * 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -232,6 +231,7 @@ void gtkut_ctree_node_move_if_on_the_edge(GtkCMCTree *ctree, GtkCMCTreeNode *nod
        GtkCMCList *clist = GTK_CMCLIST(ctree);
        gint row;
        GtkVisibility row_visibility, prev_row_visibility, next_row_visibility;
+       gfloat row_align;
 
        cm_return_if_fail(ctree != NULL);
        cm_return_if_fail(node != NULL);
@@ -244,7 +244,12 @@ void gtkut_ctree_node_move_if_on_the_edge(GtkCMCTree *ctree, GtkCMCTreeNode *nod
        next_row_visibility = gtk_cmclist_row_is_visible(clist, row + 1);
 
        if (row_visibility == GTK_VISIBILITY_NONE) {
-               gtk_cmclist_moveto(clist, row, -1, 0.5, 0);
+               row_align = 0.5;
+               if (gtk_cmclist_row_is_above_viewport(clist, row))
+                       row_align = 0.2;
+               else if (gtk_cmclist_row_is_below_viewport(clist, row))
+                       row_align = 0.8;
+               gtk_cmclist_moveto(clist, row, -1, row_align, 0);
                return;
        }
        if (row_visibility == GTK_VISIBILITY_FULL &&
@@ -710,8 +715,8 @@ void gtkut_widget_set_app_icon(GtkWidget *widget)
        cm_return_if_fail(gtk_widget_get_window(widget) != NULL);
        if (!icon_list) {
                GdkPixbuf *icon = NULL, *big_icon = NULL;
-               stock_pixbuf_gdk(widget, STOCK_PIXMAP_CLAWS_MAIL_ICON, &icon);
-               stock_pixbuf_gdk(widget, STOCK_PIXMAP_CLAWS_MAIL_LOGO, &big_icon);
+               stock_pixbuf_gdk(STOCK_PIXMAP_CLAWS_MAIL_ICON, &icon);
+               stock_pixbuf_gdk(STOCK_PIXMAP_CLAWS_MAIL_LOGO, &big_icon);
                if (icon)
                        icon_list = g_list_append(icon_list, icon);
                if (big_icon)
@@ -729,8 +734,8 @@ void gtkut_widget_set_composer_icon(GtkWidget *widget)
        cm_return_if_fail(gtk_widget_get_window(widget) != NULL);
        if (!icon_list) {
                GdkPixbuf *icon = NULL, *big_icon = NULL;
-               stock_pixbuf_gdk(widget, STOCK_PIXMAP_MAIL_COMPOSE, &icon);
-               stock_pixbuf_gdk(widget, STOCK_PIXMAP_MAIL_COMPOSE_LOGO, &big_icon);
+               stock_pixbuf_gdk(STOCK_PIXMAP_MAIL_COMPOSE, &icon);
+               stock_pixbuf_gdk(STOCK_PIXMAP_MAIL_COMPOSE_LOGO, &big_icon);
                if (icon)
                        icon_list = g_list_append(icon_list, icon);
                if (big_icon)
@@ -858,6 +863,7 @@ void gtkut_set_widget_bgcolor_rgb(GtkWidget *widget, guint rgbvalue)
        newstyle->bg[GTK_STATE_PRELIGHT] = gdk_color;
        newstyle->bg[GTK_STATE_ACTIVE]   = gdk_color;
        gtk_widget_set_style(widget, newstyle);
+       gtk_style_unref(newstyle);
 }
   
 /*!
@@ -1061,13 +1067,13 @@ gboolean get_tag_range(GtkTextIter *iter,
 
        _end_iter = *iter;
        if (!gtk_text_iter_forward_to_tag_toggle(&_end_iter, tag)) {
-               debug_print("Can't find end");
+               debug_print("Can't find end.\n");
                return FALSE;
        }
 
        _start_iter = _end_iter;
        if (!gtk_text_iter_backward_to_tag_toggle(&_start_iter, tag)) {
-               debug_print("Can't find start.");
+               debug_print("Can't find start.\n");
                return FALSE;
        }
 
@@ -1227,9 +1233,9 @@ GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *
        if (!url)
                return NULL;
 
-       gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
+       gtkut_convert_int_to_gdk_color(prefs_common.color[COL_URI],
                                               &uri_color[0]);
-       gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
+       gtkut_convert_int_to_gdk_color(prefs_common.color[COL_URI],
                                               &uri_color[1]);
 
        btn = gtk_button_new_with_label(label?label:url);
@@ -1248,6 +1254,7 @@ GtkWidget *gtkut_get_link_btn(GtkWidget *window, const gchar *url, const gchar *
                style->fg[GTK_STATE_ACTIVE]   = uri_color[1];
                style->fg[GTK_STATE_PRELIGHT] = uri_color[0];
                gtk_widget_set_style(btn_label, style);
+               gtk_style_unref(style);
 #if !GTK_CHECK_VERSION(3, 0, 0)
        } else
                g_warning("color allocation failed");
@@ -1873,6 +1880,8 @@ GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *src_pixbuf, int box_width,
 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
 static void auto_configure_done(const gchar *hostname, gint port, gboolean ssl, AutoConfigureData *data)
 {
+       gboolean smtp = strcmp(data->tls_service, "submission") == 0 ? TRUE : FALSE;
+
        if (hostname != NULL) {
                if (data->hostname_entry)
                        gtk_entry_set_text(data->hostname_entry, hostname);
@@ -1898,7 +1907,15 @@ static void auto_configure_done(const gchar *hostname, gint port, gboolean ssl,
                                /* Wizard where TLS is [x]SSL + [x]TLS */
                                gtk_toggle_button_set_active(data->ssl_checkbtn, TRUE);
                        }
-                       gtk_toggle_button_set_active(data->tls_checkbtn, TRUE);
+
+                       /* Even though technically this is against the RFCs,
+                        * if a "_submission._tcp" SRV record uses port 465,
+                        * it is safe to assume TLS-only service, instead of
+                        * plaintext + STARTTLS one. */
+                       if (smtp && port == 465)
+                               gtk_toggle_button_set_active(data->ssl_checkbtn, TRUE);
+                       else
+                               gtk_toggle_button_set_active(data->tls_checkbtn, TRUE);
                }
 
                /* Check authentication by default. This is probably required if
@@ -1915,7 +1932,19 @@ static void auto_configure_done(const gchar *hostname, gint port, gboolean ssl,
 
                gtk_label_set_text(data->info_label, _("Done."));
        } else {
-       gtk_label_set_text(data->info_label, _("Failed."));
+               gchar *msg;
+               switch (data->resolver_error) {
+               case G_RESOLVER_ERROR_NOT_FOUND:
+                       msg = g_strdup(_("Failed: no service record found."));
+                       break;
+               case G_RESOLVER_ERROR_TEMPORARY_FAILURE:
+                       msg = g_strdup(_("Failed: network error."));
+                       break;
+               default:
+                       msg = g_strdup_printf(_("Failed: unknown error (%d)."), data->resolver_error);
+               }
+               gtk_label_set_text(data->info_label, msg);
+               g_free(msg);
        }
        gtk_widget_show(GTK_WIDGET(data->configure_button));
        gtk_widget_hide(GTK_WIDGET(data->cancel_button));
@@ -1951,6 +1980,8 @@ static void resolve_done(GObject *source, GAsyncResult *result, gpointer user_da
        } else if (error) {
                if (error->code == G_IO_ERROR_CANCELLED)
                        abort = TRUE;
+               else
+                       data->resolver_error = error->code;
                debug_print("error %s\n", error->message);
                g_error_free(error);
        }