2012-04-01 [colin] 3.8.0cvs36
[claws.git] / src / toolbar.c
index a3297ddc6e5156ded8f4ec0bdc57b88355334a87..c6a782bd049b65c5b7346e72cbbb1a8e2457a1b8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2009 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 2001-2011 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
@@ -57,6 +57,9 @@
 #include "prefs_toolbar.h"
 #include "alertpanel.h"
 #include "imap.h"
+#ifdef USE_NEW_ADDRBOOK
+       #include "addressbook-dbus.h"
+#endif
 
 /* elements */
 #define TOOLBAR_TAG_INDEX        "toolbar"
@@ -136,6 +139,8 @@ static void toolbar_print_cb                        (GtkWidget      *widget,
 
 static void toolbar_actions_execute_cb         (GtkWidget      *widget,
                                                 gpointer        data);
+static void toolbar_plugins_execute_cb      (GtkWidget      *widget,
+                             gpointer        data);
 
 
 static void toolbar_send_cb                    (GtkWidget      *widget,
@@ -175,8 +180,8 @@ struct {
        gchar *index_str;
        const gchar *descr;
 } toolbar_text [] = {
-       { "A_RECEIVE_ALL",      N_("Receive Mail on all Accounts")         },
-       { "A_RECEIVE_CUR",      N_("Receive Mail on current Account")      },
+       { "A_RECEIVE_ALL",      N_("Receive Mail from all Accounts")       },
+       { "A_RECEIVE_CUR",      N_("Receive Mail from current Account")    },
        { "A_SEND_QUEUED",      N_("Send Queued Messages")                 },
        { "A_COMPOSE_EMAIL",    N_("Compose Email")                        },
        { "A_COMPOSE_NEWS",     N_("Compose News")                         },
@@ -214,7 +219,8 @@ struct {
        { "A_CLAWS_ACTIONS",    N_("Claws Mail Actions Feature")           }, 
        { "A_CANCEL_INC",       N_("Cancel receiving")                     },
        { "A_CLOSE",            N_("Close window")                         },
-       { "A_SEPARATOR",        N_("Separator")                         }
+       { "A_SEPARATOR",        N_("Separator")                         },
+       { "A_CLAWS_PLUGINS",    N_("Claws Mail Plugins")       },
 };
 
 /* struct holds configuration files and a list of
@@ -273,7 +279,7 @@ static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
 {
        GSList *cur;
 
-       if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS)
+       if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS) || (action == A_CLAWS_PLUGINS))
                return FALSE;
 
        for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
@@ -349,7 +355,7 @@ static void toolbar_parse_item(XMLFile *file, ToolbarType source)
                if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0) 
                        item->file = g_strdup (value);
                else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
-                       item->text = g_strdup (gettext(value));
+                       item->text = g_strdup (*value ? gettext(value):"");
                else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
                        item->index = toolbar_ret_val_from_text(value);
                if (item->index == -1 && !strcmp(value, "A_DELETE")) {
@@ -358,7 +364,7 @@ static void toolbar_parse_item(XMLFile *file, ToolbarType source)
                        g_free(item->file);
                        item->file = g_strdup("trash_btn");
                        g_free(item->text);
-                       item->text = g_strdup(_("Trash"));
+                       item->text = g_strdup(Q_("Toolbar|Trash"));
                        rewrite = TRUE;
                }
                if (item->index == -1 && !strcmp(value, "A_SYL_ACTIONS")) {
@@ -390,10 +396,10 @@ const gchar *toolbar_get_short_text(int action) {
        case A_COMPOSE_NEWS:    return Q_("Toolbar|Compose");
        case A_REPLY_MESSAGE:   return _("Reply");
        case A_REPLY_ALL:       return _("All");
-       case A_REPLY_SENDER:    return _("Sender");
+       case A_REPLY_SENDER:    return Q_("Toolbar|Sender");
        case A_REPLY_ML:        return _("List");
        case A_FORWARD:         return _("Forward");
-       case A_TRASH:           return _("Trash");
+       case A_TRASH:           return Q_("Toolbar|Trash");
        case A_DELETE_REAL:     return _("Delete");
        case A_LEARN_SPAM:      return _("Spam");
        case A_GOTO_PREV:       return _("Prev");
@@ -809,40 +815,52 @@ static void toolbar_action_execute(GtkWidget    *widget,
                            gpointer     data,
                            gint         source) 
 {
-       GSList *cur, *lop;
-       gchar *action, *action_p;
-       gboolean found = FALSE;
+       GSList *cur;
        gint i = 0;
 
        for (cur = action_list; cur != NULL;  cur = cur->next) {
                ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
 
                if (widget == act->widget) {
-                       
-                       for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
-                               action = g_strdup((gchar*)lop->data);
-
-                               action_p = strstr(action, ": ");
-                               action_p[0] = 0x00;
-                               if (g_utf8_collate(act->name, action) == 0) {
-                                       found = TRUE;
-                                       g_free(action);
-                                       break;
-                               } else 
-                                       i++;
-                               g_free(action);
-                       }
-                       if (found) 
+                       i = prefs_actions_find_by_name(act->name);
+
+                       if (i != -1) 
                                break;
                }
        }
 
-       if (found
+       if (i != -1
                actions_execute(data, i, widget, source);
        else
                g_warning ("Error: did not find Claws Action to execute");
 }
 
+gboolean toolbar_check_action_btns(ToolbarType type)
+{
+       GSList *temp, *curr, *list = toolbar_config[type].item_list;
+       gboolean modified = FALSE;
+       
+       curr = list;
+       while (curr != NULL) {
+               ToolbarItem *toolbar_item = (ToolbarItem *) curr->data;
+               temp = curr;
+               curr = curr->next;
+               
+               if (toolbar_item->index != A_CLAWS_ACTIONS)
+                       continue;
+
+               if (prefs_actions_find_by_name(toolbar_item->text) == -1) {
+                       list = g_slist_delete_link(list, temp);
+                       g_free(toolbar_item->file);
+                       g_free(toolbar_item->text);
+                       g_free(toolbar_item);
+                       modified = TRUE;
+               }
+       }
+       
+       return modified;
+}
+
 #if !(GTK_CHECK_VERSION(2,12,0))
 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
        gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(widget), GTK_TOOLTIPS(toolbar_tips),    \
@@ -1300,7 +1318,17 @@ static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
        default:
                return;
        }
+#ifndef USE_NEW_ADDRBOOK
        addressbook_open(compose);
+#else
+       GError* error = NULL;
+       addressbook_connect_signals(compose);
+       addressbook_dbus_open(TRUE, &error);
+       if (error) {
+               g_warning("%s", error->message);
+               g_error_free(error);
+       }
+#endif
 }
 
 
@@ -1618,6 +1646,12 @@ static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
        toolbar_action_execute(widget, action_list, parent, toolbar_item->type);        
 }
 
+static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data)
+{
+       ToolbarItem *toolbar_item = data;
+       prefs_toolbar_execute_plugin_item(toolbar_item->parent, toolbar_item->type, toolbar_item->text);
+}
+
 static MainWindow *get_mainwin(gpointer data)
 {
        ToolbarItem *toolbar_item = (ToolbarItem*)data;
@@ -1712,7 +1746,8 @@ static void toolbar_buttons_cb(GtkWidget   *widget,
                { A_CHECK_SPELLING,     toolbar_check_spelling_cb       },
 #endif
                { A_CLAWS_ACTIONS,      toolbar_actions_execute_cb      },
-               { A_CANCEL_INC,         toolbar_cancel_inc_cb           }
+               { A_CANCEL_INC,         toolbar_cancel_inc_cb           },
+               { A_CLAWS_PLUGINS,  toolbar_plugins_execute_cb  },
        };
 
        num_items = sizeof(callbacks)/sizeof(callbacks[0]);
@@ -1727,6 +1762,7 @@ static void toolbar_buttons_cb(GtkWidget   *widget,
 #ifndef GENERIC_UMPC
 #define TOOLBAR_ITEM(item,icon,text,tooltip) {                                                         \
        item = GTK_WIDGET(gtk_tool_button_new(icon, text));                                             \
+       gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE);                            \
        gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE);                                      \
        gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE);                                      \
        g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item);     \
@@ -1750,7 +1786,9 @@ static void toolbar_buttons_cb(GtkWidget   *widget,
        gchild = gtk_container_get_children(                                                            \
                        GTK_CONTAINER(child));                                                          \
        btn = (GtkWidget *)gchild->data;                                                                \
+       gtkut_widget_set_can_focus(btn, FALSE);                                                         \
        arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL);                                      \
+       gtkut_widget_set_can_focus(arr, FALSE);                                                         \
        g_list_free(gchild);                                                                            \
        gchild = gtk_container_get_children(GTK_CONTAINER(arr));                                        \
        gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1);                                   \
@@ -1759,6 +1797,7 @@ static void toolbar_buttons_cb(GtkWidget   *widget,
 #else
 #define TOOLBAR_ITEM(item,icon,text,tooltip) {                                                         \
        item = GTK_WIDGET(gtk_tool_button_new(icon, text));                                             \
+       gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE);                            \
        gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE);                                      \
        gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE);                                      \
        g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item);     \
@@ -1777,7 +1816,9 @@ static void toolbar_buttons_cb(GtkWidget   *widget,
        gchild = gtk_container_get_children(                                                            \
                        GTK_CONTAINER(child));                                                          \
        btn = (GtkWidget *)gchild->data;                                                                \
+       gtkut_widget_set_can_focus(btn, FALSE);                                                         \
        arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL);                                      \
+       gtkut_widget_set_can_focus(arr, FALSE);                                                         \
        g_list_free(gchild);                                                                            \
        gchild = gtk_container_get_children(GTK_CONTAINER(arr));                                        \
        gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1);                                   \
@@ -1844,7 +1885,11 @@ Toolbar *toolbar_create(ToolbarType       type,
 
        toolbar = gtk_toolbar_new();
 
+#if (GTK_CHECK_VERSION(2,16,0))
+       gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
+#else
        gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
+#endif
        gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
        gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
        
@@ -1876,12 +1921,12 @@ Toolbar *toolbar_create(ToolbarType      type,
                        break;
                case A_RECEIVE_ALL:
                        TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
-                               _("Receive Mail on all Accounts"),
-                               _("Receive Mail on selected Account"));
+                               _("Receive Mail from all Accounts"),
+                               _("Receive Mail from selected Account"));
                        toolbar_data->getall_btn = item;
                        break;
                case A_RECEIVE_CUR:
-                       TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
+                       TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail from current Account"));
                        toolbar_data->get_btn = item;
                        break;
                case A_SEND_QUEUED:
@@ -2108,6 +2153,9 @@ Toolbar *toolbar_create(ToolbarType        type,
                        TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
                        toolbar_data->cancel_inc_btn = item;
                        break;
+               case A_CLAWS_PLUGINS:
+                       TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
+                       break;
                default:
                        TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
                                toolbar_ret_descr_from_val(toolbar_item->index));
@@ -2131,8 +2179,7 @@ Toolbar *toolbar_create(ToolbarType        type,
                item = GTK_WIDGET(gtk_tool_item_new());
                gtk_container_add (GTK_CONTAINER (item), progressbar);
                gtk_widget_show(item);
-               gtk_widget_show(progressbar);
-               gtk_widget_set_size_request(progressbar, 70, -1);
+               gtk_widget_set_size_request(progressbar, 84, -1);
                gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
                mainwin->progressbar = progressbar;
 #endif
@@ -2146,7 +2193,7 @@ Toolbar *toolbar_create(ToolbarType        type,
        
 #ifndef MAEMO
        gtk_container_add(GTK_CONTAINER(container), toolbar);
-       gtk_container_set_border_width(GTK_CONTAINER(container), 2);
+       gtk_container_set_border_width(GTK_CONTAINER(container), 0);
 #else
        if ( GTK_IS_WINDOW(container) ) {
                hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
@@ -2326,11 +2373,11 @@ void toolbar_main_set_sensitive(gpointer data)
        
        if (toolbar->get_btn)
                SET_WIDGET_COND(toolbar->get_btn, 
-                       M_HAVE_ACCOUNT|M_UNLOCKED);
+                       M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_RETRIEVABLE_ACCOUNT);
 
        if (toolbar->getall_btn) {
                SET_WIDGET_COND(toolbar->getall_btn, 
-                       M_HAVE_ACCOUNT|M_UNLOCKED);
+                       M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
        }
        if (toolbar->send_btn) {
                SET_WIDGET_COND(toolbar->send_btn,