src/account.[ch]
[claws.git] / src / gtkutils.c
index 2aad297d3c8cae897be5cf5ecfd79599259342b4..2bcc4b1c4d7405a44535f7dd23f461cdafc6c06f 100644 (file)
@@ -32,6 +32,7 @@
 #include <gtk/gtkthemes.h>
 #include <gtk/gtkbindings.h>
 #include <stdarg.h>
+#include <sys/stat.h>
 
 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
 #  include <wchar.h>
@@ -43,6 +44,9 @@
 #include "utils.h"
 #include "gtksctree.h"
 #include "codeconv.h"
+#include "stock_pixmap.h"
+#include "menu.h"
+#include "prefs_account.h"
 
 gint gtkut_get_font_width(GdkFont *font)
 {
@@ -248,6 +252,28 @@ void gtkut_combo_set_items(GtkCombo *combo, const gchar *str1, ...)
        g_list_free(combo_items);
 }
 
+gchar *gtkut_editable_get_selection(GtkEditable *editable)
+{
+       guint start_pos, end_pos;
+
+       g_return_val_if_fail(editable != NULL, NULL);
+
+       if (!editable->has_selection) return NULL;
+
+       if (editable->selection_start_pos == editable->selection_end_pos)
+               return NULL;
+
+       if (editable->selection_start_pos < editable->selection_end_pos) {
+               start_pos = editable->selection_start_pos;
+               end_pos = editable->selection_end_pos;
+       } else {
+               start_pos = editable->selection_end_pos;
+               end_pos = editable->selection_start_pos;
+       }
+
+       return gtk_editable_get_chars(editable, start_pos, end_pos);
+}
+
 /*
  * Walk through the widget tree and disclaim the selection from all currently
  * realized GtkEditable widgets.
@@ -355,7 +381,8 @@ gboolean gtkut_stext_is_uri_string(GtkSText *text,
 {
        if (gtkut_stext_str_compare(text, start_pos, text_len, "http://") ||
            gtkut_stext_str_compare(text, start_pos, text_len, "ftp://")  ||
-           gtkut_stext_str_compare(text, start_pos, text_len, "https://"))
+           gtkut_stext_str_compare(text, start_pos, text_len, "https://")||
+           gtkut_stext_str_compare(text, start_pos, text_len, "www."))
                return TRUE;
 
        return FALSE;
@@ -397,7 +424,7 @@ void gtkut_widget_wait_for_draw(GtkWidget *widget)
 {
        gboolean flag = FALSE;
 
-       if (!GTK_WIDGET_VISIBLE(widget)) return;
+       if (!GTK_WIDGET_VISIBLE(widget) || !GTK_WIDGET_MAPPED(widget)) return;
 
        gtk_signal_connect(GTK_OBJECT(widget), "draw",
                           GTK_SIGNAL_FUNC(gtkut_widget_draw_cb), &flag);
@@ -474,36 +501,49 @@ void gtkut_widget_set_app_icon(GtkWidget *widget)
 
 void gtkut_widget_set_composer_icon(GtkWidget *widget)
 {
-#include "pixmaps/stock_mail_compose.xpm"
        static GdkPixmap *xpm;
        static GdkBitmap *bmp;
 
        g_return_if_fail(widget != NULL);
        g_return_if_fail(widget->window != NULL);
        if (!xpm) {
-               PIXMAP_CREATE(widget, xpm, bmp, stock_mail_compose_xpm);
+               stock_pixmap_gdk(widget, STOCK_PIXMAP_MAIL_COMPOSE, &xpm, &bmp);
        }
        gdk_window_set_icon(widget->window, NULL, xpm, bmp);    
 }
 
-const gchar *gtkut_get_selection(GtkWidget *widget)
+GtkWidget *gtkut_account_menu_new(GList                        *ac_list,
+                                 GtkSignalFunc          callback,
+                                 gpointer               data)
 {
-       gchar *seltext = NULL;
-       guint start_pos, end_pos;
-       GtkEditable *editable = (GtkEditable *) widget;
-
-       if (editable->has_selection) {
-               if (editable->selection_start_pos < editable->selection_end_pos) {
-                       start_pos = editable->selection_start_pos;
-                       end_pos = editable->selection_end_pos;
-               }
-               else {
-                       start_pos = editable->selection_end_pos;
-                       end_pos = editable->selection_start_pos;
-               }
-
-               seltext = gtk_editable_get_chars(editable, start_pos, end_pos);
+       GList *cur_ac;
+       GtkWidget *menu;
+       
+       g_return_val_if_fail(ac_list != NULL, NULL);
+
+       menu = gtk_menu_new();
+
+       for (cur_ac = ac_list; cur_ac != NULL; cur_ac = cur_ac->next) {
+               gchar *name;
+               GtkWidget *menuitem;
+               PrefsAccount *account;
+               
+               account = (PrefsAccount *) cur_ac->data;
+               if (account->name)
+                       name = g_strdup_printf("%s: %s <%s>",
+                                              account->account_name,
+                                              account->name,
+                                              account->address);
+               else
+                       name = g_strdup_printf("%s: %s",
+                                              account->account_name,
+                                              account->address);
+               MENUITEM_ADD(menu, menuitem, name, account->account_id);
+               g_free(name);
+               if (callback != NULL)
+                       gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
+                                          callback,
+                                          data);
        }
-
-       return seltext;
+       return menu;
 }