2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2015 Hiroyuki Yamamoto & the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * General functions for accessing address book files.
26 #include "claws-features.h"
32 #include <glib/gi18n.h>
34 #include <gdk/gdkkeysyms.h>
38 #include "stock_pixmap.h"
39 #include "manage_window.h"
42 #include "mainwindow.h"
43 #include "alertpanel.h"
44 #include "prefs_common.h"
45 #include "prefs_actions.h"
50 #include "prefs_toolbar.h"
51 #include "prefswindow.h"
52 #include "prefs_gtk.h"
54 #include "messageview.h"
62 SET_ICON_TEXT
= 4, /*!< "icon" text (separator) */
63 SET_ICON_IS_TEXT
= 5, /*!< icon is text representation */
75 static const gint ToolbarIcons
[] =
77 STOCK_PIXMAP_ADDRESS_BOOK
,
78 STOCK_PIXMAP_ADDRESS_SEARCH
,
80 STOCK_PIXMAP_CATEGORY
,
81 STOCK_PIXMAP_CHECK_SPELLING
,
83 STOCK_PIXMAP_DOWN_ARROW
,
84 STOCK_PIXMAP_UP_ARROW
,
85 STOCK_PIXMAP_EDIT_EXTERN
,
89 STOCK_PIXMAP_INSERT_FILE
,
90 STOCK_PIXMAP_INTERFACE
,
93 STOCK_PIXMAP_LINEWRAP_CURRENT
,
94 STOCK_PIXMAP_LINEWRAP_ALL
,
96 STOCK_PIXMAP_MAIL_ATTACH
,
97 STOCK_PIXMAP_MAIL_COMPOSE
,
98 STOCK_PIXMAP_MAIL_FORWARD
,
99 STOCK_PIXMAP_MAIL_RECEIVE
,
100 STOCK_PIXMAP_MAIL_RECEIVE_ALL
,
101 STOCK_PIXMAP_MAIL_REPLY
,
102 STOCK_PIXMAP_MAIL_REPLY_TO_ALL
,
103 STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR
,
104 STOCK_PIXMAP_MAIL_REPLY_TO_LIST
,
105 STOCK_PIXMAP_MAIL_SEND
,
106 STOCK_PIXMAP_MAIL_SEND_QUEUE
,
107 STOCK_PIXMAP_MAIL_SIGN
,
108 STOCK_PIXMAP_OPEN_MAIL
,
109 STOCK_PIXMAP_NEWS_COMPOSE
,
111 STOCK_PIXMAP_PREFERENCES
,
112 STOCK_PIXMAP_PROPERTIES
,
115 STOCK_PIXMAP_OFFLINE
,
116 STOCK_PIXMAP_NOTICE_WARN
, /* small warning */
117 STOCK_PIXMAP_NOTICE_ERROR
, /* small error */
118 STOCK_PIXMAP_NOTICE_NOTE
, /* small message */
119 STOCK_PIXMAP_GO_FOLDERS
,
120 STOCK_PIXMAP_MIME_TEXT_PLAIN
,
121 STOCK_PIXMAP_MIME_TEXT_HTML
,
122 STOCK_PIXMAP_MIME_TEXT_PATCH
,
123 STOCK_PIXMAP_MIME_APPLICATION
,
124 STOCK_PIXMAP_MIME_IMAGE
,
125 STOCK_PIXMAP_MIME_AUDIO
,
126 STOCK_PIXMAP_MIME_TEXT_ENRICHED
,
127 STOCK_PIXMAP_MIME_UNKNOWN
,
128 STOCK_PIXMAP_MIME_PDF
,
129 STOCK_PIXMAP_MIME_PS
,
130 STOCK_PIXMAP_MIME_TEXT_CALENDAR
,
131 STOCK_PIXMAP_MIME_PGP_SIG
,
132 STOCK_PIXMAP_PRINTER
,
133 STOCK_PIXMAP_PRIVACY_SIGNED
,
134 STOCK_PIXMAP_PRIVACY_PASSED
,
135 STOCK_PIXMAP_PRIVACY_FAILED
,
136 STOCK_PIXMAP_PRIVACY_UNKNOWN
,
137 STOCK_PIXMAP_PRIVACY_EXPIRED
,
138 STOCK_PIXMAP_PRIVACY_WARN
,
139 STOCK_PIXMAP_PRIVACY_EMBLEM_SIGNED
,
140 STOCK_PIXMAP_PRIVACY_EMBLEM_PASSED
,
141 STOCK_PIXMAP_PRIVACY_EMBLEM_FAILED
,
142 STOCK_PIXMAP_PRIVACY_EMBLEM_WARN
,
143 STOCK_PIXMAP_MIME_MESSAGE
,
144 STOCK_PIXMAP_SPAM_BTN
,
145 STOCK_PIXMAP_HAM_BTN
,
149 STOCK_PIXMAP_EMPTY
, /* last entry */
152 typedef struct _ToolbarPage
156 GtkWidget
*window
; /* do not modify */
159 GList
*combo_action_list
; /* list of internal functions */
161 GtkWidget
*list_view_set
; /* toolbar items treeview */
162 GtkWidget
*item_text_entry
; /* item name */
163 GtkWidget
*item_type_combo
; /* item type selection widget */
164 GtkWidget
*item_func_combo
; /* item internal function widget */
165 GtkWidget
*item_action_combo
; /* item user action widget */
166 GtkWidget
*item_plugin_combo
; /* items registered by plugins */
167 GtkWidget
*icon_button
; /* item icon chooser widget */
169 GtkWidget
*icon_chooser_win
;
170 GtkWidget
*icon_chooser_view
;
172 gchar
*item_icon_file
; /* item icon file */
176 #define ERROR_MSG _("Selected Action already set.\nPlease choose another Action from List")
177 #define ERROR_MSG_NO_ICON _("Item has no icon defined.")
178 #define ERROR_MSG_NO_TEXT _("Item has no text defined.")
180 typedef struct _ToolbarPluginItem ToolbarPluginItem
;
181 struct _ToolbarPluginItem
{
184 ToolbarPluginCallback cb
;
188 /* items registered by plugins */
189 static GHashTable
*plugin_items_mainwin
= NULL
;
190 static GHashTable
*plugin_items_compose
= NULL
;
191 static GHashTable
*plugin_items_msgview
= NULL
;
193 static void prefs_toolbar_populate (ToolbarPage
*prefs_toolbar
);
195 static void get_action_name (const gchar
*entry
,
198 static gboolean
is_duplicate (ToolbarPage
*prefs_toolbar
,
199 gchar
*chosen_action
);
200 static void prefs_toolbar_save (PrefsPage
*_page
);
202 static void prefs_toolbar_register (GtkButton
*button
,
203 ToolbarPage
*prefs_toolbar
);
204 static void prefs_toolbar_substitute (GtkButton
*button
,
205 ToolbarPage
*prefs_toolbar
);
206 static void prefs_toolbar_delete (GtkButton
*button
,
207 ToolbarPage
*prefs_toolbar
);
209 static void prefs_toolbar_up (GtkButton
*button
,
210 ToolbarPage
*prefs_toolbar
);
212 static void prefs_toolbar_down (GtkButton
*button
,
213 ToolbarPage
*prefs_toolbar
);
215 static void action_selection_changed (GtkComboBox
*action_combo
,
216 ToolbarPage
*prefs_toolbar
);
217 static void plugin_selection_changed (GtkComboBox
*action_combo
,
218 ToolbarPage
*prefs_toolbar
);
220 static void func_selection_changed (GtkComboBox
*action_combo
,
221 ToolbarPage
*prefs_toolbar
);
223 static void prefs_toolbar_create (ToolbarPage
*prefs_toolbar
);
225 static GtkWidget
*create_set_list_view (ToolbarPage
*prefs_toolbar
);
227 static gboolean
set_list_selected (GtkTreeSelection
*selector
,
230 gboolean currently_selected
,
231 ToolbarPage
*prefs_toolbar
);
233 static void icon_chooser_create (GtkButton
*button
,
234 ToolbarPage
*prefs_toolbar
);
237 static GHashTable
** get_plugin_hash_from_toolbar_type(ToolbarType toolbar_type
)
239 if (toolbar_type
== TOOLBAR_MAIN
)
240 return &plugin_items_mainwin
;
241 else if (toolbar_type
== TOOLBAR_COMPOSE
)
242 return &plugin_items_compose
;
243 else if (toolbar_type
== TOOLBAR_MSGVIEW
)
244 return &plugin_items_msgview
;
249 static void prefs_toolbar_create_widget(PrefsPage
*_page
, GtkWindow
*window
, gpointer data
)
251 ToolbarPage
*prefs_toolbar
= (ToolbarPage
*) _page
;
253 prefs_toolbar
->window
= GTK_WIDGET(window
);
255 toolbar_read_config_file(prefs_toolbar
->source
);
257 prefs_toolbar_create(prefs_toolbar
);
258 prefs_toolbar_populate(prefs_toolbar
);
261 static void prefs_toolbar_save(PrefsPage
*_page
)
263 ToolbarPage
*prefs_toolbar
= (ToolbarPage
*) _page
;
264 GtkTreeView
*list_view
= GTK_TREE_VIEW(prefs_toolbar
->list_view_set
);
265 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
268 toolbar_clear_list(prefs_toolbar
->source
);
270 if (!gtk_tree_model_iter_n_children(model
, NULL
)
271 || !gtk_tree_model_get_iter_first(model
, &iter
))
272 toolbar_set_default(prefs_toolbar
->source
);
276 gchar
*fname
, *text
, *event
;
278 item
= g_new0(ToolbarItem
, 1);
280 gtk_tree_model_get(model
, &iter
,
281 SET_FILENAME
, &fname
,
286 /* XXX: remember that G_TYPE_STRING returned by model
287 * is owned by caller of gtk_tree_model_get() */
290 item
->index
= toolbar_ret_val_from_descr(event
);
293 toolbar_set_list_item(item
, prefs_toolbar
->source
);
298 } while (gtk_tree_model_iter_next(model
, &iter
));
301 toolbar_save_config_file(prefs_toolbar
->source
);
303 if (prefs_toolbar
->source
== TOOLBAR_MAIN
)
304 toolbar_update(TOOLBAR_MAIN
, mainwindow_get_mainwindow());
305 else if (prefs_toolbar
->source
== TOOLBAR_COMPOSE
)
306 compose_reflect_prefs_pixmap_theme();
307 else if (prefs_toolbar
->source
== TOOLBAR_MSGVIEW
)
308 messageview_reflect_prefs_pixmap_theme();
311 static void prefs_toolbar_destroy_widget(PrefsPage
*_page
)
313 ToolbarPage
*prefs_toolbar
= (ToolbarPage
*) _page
;
315 g_list_free(prefs_toolbar
->combo_action_list
);
316 prefs_toolbar
->combo_action_list
= NULL
;
319 static void prefs_toolbar_set_displayed(ToolbarPage
*prefs_toolbar
)
322 GtkTreeView
*list_view_set
= GTK_TREE_VIEW(prefs_toolbar
->list_view_set
);
323 GtkListStore
*store
= GTK_LIST_STORE(gtk_tree_view_get_model
325 GSList
*toolbar_list
= toolbar_get_list(prefs_toolbar
->source
);
328 gtk_list_store_clear(store
);
330 /* set currently active toolbar entries */
331 for (cur
= toolbar_list
; cur
!= NULL
; cur
= cur
->next
) {
332 ToolbarItem
*item
= (ToolbarItem
*) cur
->data
;
334 gtk_list_store_append(store
, &iter
);
336 if (item
->index
!= A_SEPARATOR
) {
338 StockPixmap icon
= stock_pixmap_get_icon(item
->file
);
340 stock_pixbuf_gdk(icon
, &pix
);
342 gtk_list_store_set(store
, &iter
,
344 SET_FILENAME
, item
->file
,
345 SET_TEXT
, item
->text
,
346 SET_EVENT
, toolbar_ret_descr_from_val(item
->index
),
348 SET_ICON_IS_TEXT
, FALSE
,
351 gtk_list_store_set(store
, &iter
,
353 SET_FILENAME
, toolbar_ret_descr_from_val(A_SEPARATOR
),
354 SET_TEXT
, (const gchar
*) "",
355 SET_EVENT
, toolbar_ret_descr_from_val(A_SEPARATOR
),
356 SET_ICON_TEXT
, (const gchar
*) SEPARATOR_PIXMAP
,
357 SET_ICON_IS_TEXT
, TRUE
,
363 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store
), &iter
);
364 gtk_tree_selection_select_iter(gtk_tree_view_get_selection
369 static void add_item_to_plugin_combo(gpointer key
, gpointer data
, gpointer combo_box
)
371 #if !GTK_CHECK_VERSION(2, 24, 0)
372 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box
), (const gchar
*)key
);
374 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box
), (const gchar
*)key
);
378 static void prefs_toolbar_populate(ToolbarPage
*prefs_toolbar
)
381 gchar
*act
, *act_name
;
384 prefs_toolbar
->combo_action_list
= toolbar_get_action_items(prefs_toolbar
->source
);
385 #if !GTK_CHECK_VERSION(2, 24, 0)
386 combobox_set_popdown_strings(GTK_COMBO_BOX(prefs_toolbar
->item_func_combo
),
387 prefs_toolbar
->combo_action_list
);
389 combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(prefs_toolbar
->item_func_combo
),
390 prefs_toolbar
->combo_action_list
);
393 /* get currently defined sylpheed actions */
394 if (prefs_common
.actions_list
!= NULL
) {
395 for (cur
= prefs_common
.actions_list
; cur
!= NULL
; cur
= cur
->next
) {
396 act
= (gchar
*)cur
->data
;
397 get_action_name(act
, &act_name
);
399 #if !GTK_CHECK_VERSION(2, 24, 0)
400 gtk_combo_box_append_text(
401 GTK_COMBO_BOX(prefs_toolbar
->item_action_combo
),
403 gtk_combo_box_text_append_text(
404 GTK_COMBO_BOX_TEXT(prefs_toolbar
->item_action_combo
),
412 combobox_set_sensitive(GTK_COMBO_BOX(prefs_toolbar
->item_type_combo
),
413 ITEM_USER_ACTION
, FALSE
);
415 /* items registered by plugins */
416 hash
= get_plugin_hash_from_toolbar_type(prefs_toolbar
->source
);
418 g_hash_table_foreach(*hash
, add_item_to_plugin_combo
,
419 prefs_toolbar
->item_plugin_combo
);
421 combobox_set_sensitive(GTK_COMBO_BOX(prefs_toolbar
->item_type_combo
),
424 gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar
->item_func_combo
), 0);
425 gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar
->item_action_combo
), 0);
426 gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar
->item_plugin_combo
), 0);
428 prefs_toolbar_set_displayed(prefs_toolbar
);
430 toolbar_clear_list(prefs_toolbar
->source
);
433 static gboolean
is_duplicate(ToolbarPage
*prefs_toolbar
, gchar
*chosen_action
)
435 GtkTreeView
*list_view_set
= GTK_TREE_VIEW
436 (prefs_toolbar
->list_view_set
);
437 GtkTreeModel
*model_set
= gtk_tree_view_get_model(list_view_set
);
442 cm_return_val_if_fail(chosen_action
!= NULL
, TRUE
);
444 if (!gtk_tree_model_iter_n_children(model_set
, NULL
))
447 if (!gtk_tree_model_get_iter_first(model_set
, &iter
))
452 gtk_tree_model_get(model_set
, &iter
,
455 if (g_utf8_collate(chosen_action
, entry
) == 0)
458 } while (!result
&& gtk_tree_model_iter_next(model_set
, &iter
));
463 static void prefs_toolbar_default(GtkButton
*button
, ToolbarPage
*prefs_toolbar
)
465 toolbar_clear_list(prefs_toolbar
->source
);
466 toolbar_set_default(prefs_toolbar
->source
);
467 prefs_toolbar_set_displayed(prefs_toolbar
);
471 *\return String that should be freed by caller.
473 static void get_action_name(const gchar
*entry
, gchar
**menu
)
479 if (prefs_common
.actions_list
!= NULL
) {
481 act
= g_strdup(entry
);
482 act_p
= strstr(act
, ": ");
485 /* freed by calling func */
490 static void prefs_toolbar_register(GtkButton
*button
, ToolbarPage
*prefs_toolbar
)
492 GtkTreeView
*list_view_set
= GTK_TREE_VIEW(prefs_toolbar
->list_view_set
);
493 gint item_type
= gtk_combo_box_get_active(GTK_COMBO_BOX(prefs_toolbar
->item_type_combo
));
494 GtkListStore
*store_set
;
497 store_set
= GTK_LIST_STORE(gtk_tree_view_get_model(list_view_set
));
499 /* SEPARATOR or other ? */
500 if (item_type
== ITEM_SEPARATOR
) {
501 gtk_list_store_append(store_set
, &iter
);
502 gtk_list_store_set(store_set
, &iter
,
504 SET_FILENAME
, prefs_toolbar
->item_icon_file
,
506 SET_EVENT
, toolbar_ret_descr_from_val(A_SEPARATOR
),
507 SET_ICON_TEXT
, (const gchar
*) SEPARATOR_PIXMAP
,
508 SET_ICON_IS_TEXT
, TRUE
,
514 if (prefs_toolbar
->item_icon_file
== NULL
) {
515 alertpanel_error(ERROR_MSG_NO_ICON
);
519 stock_pixmap_get_icon(prefs_toolbar
->item_icon_file
),
522 alertpanel_error(ERROR_MSG_NO_ICON
);
526 if (item_type
== ITEM_FUNCTION
) {
527 #if !GTK_CHECK_VERSION(2, 24, 0)
528 event
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(
530 event
= gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
532 prefs_toolbar
->item_func_combo
));
534 if (is_duplicate(prefs_toolbar
, event
)) {
535 alertpanel_error(ERROR_MSG
);
539 } else if(item_type
== ITEM_PLUGIN
)
540 event
= toolbar_ret_descr_from_val(A_CLAWS_PLUGINS
);
542 event
= toolbar_ret_descr_from_val(A_CLAWS_ACTIONS
);
544 text
= gtk_editable_get_chars(
545 GTK_EDITABLE(prefs_toolbar
->item_text_entry
), 0 , -1);
548 gtk_list_store_append(store_set
, &iter
);
549 gtk_list_store_set(store_set
, &iter
,
551 SET_FILENAME
, prefs_toolbar
->item_icon_file
,
555 SET_ICON_IS_TEXT
, FALSE
,
558 alertpanel_error(ERROR_MSG_NO_TEXT
);
563 if((item_type
!= ITEM_USER_ACTION
) && (item_type
!= ITEM_PLUGIN
))
567 gtk_tree_selection_select_iter(gtk_tree_view_get_selection
572 static void prefs_toolbar_substitute(GtkButton
*button
, ToolbarPage
*prefs_toolbar
)
574 GtkTreeView
*list_view_set
= GTK_TREE_VIEW(prefs_toolbar
->list_view_set
);
575 GtkListStore
*store_set
= GTK_LIST_STORE(gtk_tree_view_get_model(list_view_set
));
576 gint item_type
= gtk_combo_box_get_active(GTK_COMBO_BOX(prefs_toolbar
->item_type_combo
));
577 GtkTreeSelection
*sel_set
;
578 GtkTreeIter iter_set
;
580 if (!gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store_set
), NULL
))
583 sel_set
= gtk_tree_view_get_selection(list_view_set
);
584 if (!gtk_tree_selection_get_selected(sel_set
, NULL
, &iter_set
))
587 if (item_type
== ITEM_SEPARATOR
) {
588 gtk_list_store_set(store_set
, &iter_set
,
591 SET_EVENT
, toolbar_ret_descr_from_val(A_SEPARATOR
),
592 SET_FILENAME
, prefs_toolbar
->item_icon_file
,
593 SET_ICON_TEXT
, (const gchar
*) SEPARATOR_PIXMAP
,
594 SET_ICON_IS_TEXT
, TRUE
,
598 gchar
*icon_event
, *set_event
, *text
;
600 if (prefs_toolbar
->item_icon_file
== NULL
) {
601 alertpanel_error(ERROR_MSG_NO_ICON
);
605 stock_pixmap_get_icon(prefs_toolbar
->item_icon_file
),
608 alertpanel_error(ERROR_MSG_NO_ICON
);
612 gtk_tree_model_get(GTK_TREE_MODEL(store_set
), &iter_set
,
613 SET_EVENT
, &set_event
,
616 if (item_type
== ITEM_FUNCTION
) {
617 #if !GTK_CHECK_VERSION(2, 24, 0)
618 icon_event
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(
620 icon_event
= gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
622 prefs_toolbar
->item_func_combo
));
624 if (is_duplicate(prefs_toolbar
, icon_event
)
625 && g_utf8_collate(icon_event
, set_event
) != 0){
626 alertpanel_error(ERROR_MSG
);
631 } else if(item_type
== ITEM_PLUGIN
)
632 icon_event
= toolbar_ret_descr_from_val(A_CLAWS_PLUGINS
);
634 icon_event
= toolbar_ret_descr_from_val(A_CLAWS_ACTIONS
);
636 text
= gtk_editable_get_chars(
637 GTK_EDITABLE(prefs_toolbar
->item_text_entry
), 0 , -1);
641 gtk_list_store_set(store_set
, &iter_set
,
643 SET_FILENAME
, prefs_toolbar
->item_icon_file
,
645 SET_EVENT
, icon_event
,
647 SET_ICON_IS_TEXT
, FALSE
,
650 alertpanel_error(ERROR_MSG_NO_TEXT
);
654 if((item_type
!= ITEM_USER_ACTION
) && (item_type
!= ITEM_PLUGIN
))
659 static void prefs_toolbar_delete(GtkButton
*button
, ToolbarPage
*prefs_toolbar
)
661 GtkTreeView
*list_view_set
= GTK_TREE_VIEW(prefs_toolbar
->list_view_set
);
662 GtkTreeModel
*store_set
= gtk_tree_view_get_model(list_view_set
);
663 GtkTreeIter iter_set
;
666 if (!gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store_set
), NULL
))
669 if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection
675 /* select prev list item, if deleted was first select next */
676 path
= gtk_tree_model_get_path(store_set
, &iter_set
);
677 gtk_tree_path_prev(path
);
679 gtk_list_store_remove(GTK_LIST_STORE(store_set
), &iter_set
);
681 gtk_tree_selection_select_path(
682 gtk_tree_view_get_selection(list_view_set
),
685 gtk_tree_path_free(path
);
688 static void prefs_toolbar_up(GtkButton
*button
, ToolbarPage
*prefs_toolbar
)
690 GtkTreePath
*prev
, *sel
;
692 GtkListStore
*store
= NULL
;
693 GtkTreeModel
*model
= NULL
;
696 if (!gtk_tree_selection_get_selected
697 (gtk_tree_view_get_selection
698 (GTK_TREE_VIEW(prefs_toolbar
->list_view_set
)),
702 store
= (GtkListStore
*)model
;
704 sel
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
), &isel
);
708 /* no move if we're at row 0... */
709 prev
= gtk_tree_path_copy(sel
);
710 if (!gtk_tree_path_prev(prev
)) {
711 gtk_tree_path_free(prev
);
712 gtk_tree_path_free(sel
);
716 gtk_tree_model_get_iter(GTK_TREE_MODEL(store
),
718 gtk_tree_path_free(sel
);
719 gtk_tree_path_free(prev
);
721 gtk_list_store_swap(store
, &iprev
, &isel
);
724 static void prefs_toolbar_down(GtkButton
*button
, ToolbarPage
*prefs_toolbar
)
726 GtkListStore
*store
= NULL
;
727 GtkTreeModel
*model
= NULL
;
728 GtkTreeIter next
, sel
;
730 if (!gtk_tree_selection_get_selected
731 (gtk_tree_view_get_selection
732 (GTK_TREE_VIEW(prefs_toolbar
->list_view_set
)),
737 store
= (GtkListStore
*)model
;
739 if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(store
), &next
))
742 gtk_list_store_swap(store
, &next
, &sel
);
745 static void item_type_changed(GtkComboBox
*item_type_combo
,
746 ToolbarPage
*prefs_toolbar
)
748 gint active
= gtk_combo_box_get_active(item_type_combo
);
752 gtk_widget_show(prefs_toolbar
->item_func_combo
);
753 gtk_widget_hide(prefs_toolbar
->item_action_combo
);
754 gtk_widget_hide(prefs_toolbar
->item_plugin_combo
);
755 gtk_combo_box_set_active(
756 GTK_COMBO_BOX(prefs_toolbar
->item_func_combo
), 0);
757 gtk_button_set_label(GTK_BUTTON(prefs_toolbar
->icon_button
), "");
758 gtk_widget_set_sensitive(prefs_toolbar
->item_text_entry
, TRUE
);
759 gtk_widget_set_sensitive(prefs_toolbar
->item_func_combo
, TRUE
);
760 gtk_widget_set_sensitive(prefs_toolbar
->icon_button
, TRUE
);
762 func_selection_changed(GTK_COMBO_BOX(prefs_toolbar
->item_func_combo
),
765 case ITEM_USER_ACTION
:
766 gtk_widget_show(prefs_toolbar
->item_action_combo
);
767 gtk_widget_hide(prefs_toolbar
->item_func_combo
);
768 gtk_widget_hide(prefs_toolbar
->item_plugin_combo
);
769 gtk_combo_box_set_active(
770 GTK_COMBO_BOX(prefs_toolbar
->item_action_combo
), 0);
771 gtk_button_set_label(GTK_BUTTON(prefs_toolbar
->icon_button
), "");
772 gtk_widget_set_sensitive(prefs_toolbar
->item_text_entry
, FALSE
);
773 gtk_widget_set_sensitive(prefs_toolbar
->item_action_combo
, TRUE
);
774 gtk_widget_set_sensitive(prefs_toolbar
->icon_button
, TRUE
);
776 action_selection_changed(GTK_COMBO_BOX(prefs_toolbar
->item_action_combo
),
780 gtk_button_set_label(GTK_BUTTON(prefs_toolbar
->icon_button
), _("None"));
781 gtk_button_set_image(GTK_BUTTON(prefs_toolbar
->icon_button
), NULL
);
782 g_free(prefs_toolbar
->item_icon_file
);
783 prefs_toolbar
->item_icon_file
= NULL
;
784 gtk_combo_box_set_active(
785 GTK_COMBO_BOX(prefs_toolbar
->item_func_combo
), -1);
786 gtk_combo_box_set_active(
787 GTK_COMBO_BOX(prefs_toolbar
->item_action_combo
), -1);
788 gtk_combo_box_set_active(
789 GTK_COMBO_BOX(prefs_toolbar
->item_plugin_combo
), -1);
790 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar
->item_text_entry
), "");
791 gtk_widget_set_sensitive(prefs_toolbar
->item_action_combo
, FALSE
);
792 gtk_widget_set_sensitive(prefs_toolbar
->item_text_entry
, FALSE
);
793 gtk_widget_set_sensitive(prefs_toolbar
->item_plugin_combo
, FALSE
);
794 gtk_widget_set_sensitive(prefs_toolbar
->item_func_combo
, FALSE
);
795 gtk_widget_set_sensitive(prefs_toolbar
->icon_button
, FALSE
);
798 gtk_widget_show(prefs_toolbar
->item_plugin_combo
);
799 gtk_widget_hide(prefs_toolbar
->item_func_combo
);
800 gtk_widget_hide(prefs_toolbar
->item_action_combo
);
801 gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar
->item_plugin_combo
), 0);
802 gtk_button_set_label(GTK_BUTTON(prefs_toolbar
->icon_button
), "");
803 gtk_widget_set_sensitive(prefs_toolbar
->item_text_entry
, FALSE
);
804 gtk_widget_set_sensitive(prefs_toolbar
->item_plugin_combo
, TRUE
);
805 gtk_widget_set_sensitive(prefs_toolbar
->icon_button
, TRUE
);
806 plugin_selection_changed(GTK_COMBO_BOX(prefs_toolbar
->item_plugin_combo
), prefs_toolbar
);
812 static void action_selection_changed(GtkComboBox
*action_combo
,
813 ToolbarPage
*prefs_toolbar
)
815 #if !GTK_CHECK_VERSION(2, 24, 0)
816 gchar
*text
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(
818 gchar
*text
= gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
820 prefs_toolbar
->item_action_combo
));
822 if(text
!= NULL
) { /* action */
823 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar
->item_text_entry
), text
);
828 static void plugin_selection_changed(GtkComboBox
*action_combo
,
829 ToolbarPage
*prefs_toolbar
)
831 #if !GTK_CHECK_VERSION(2, 24, 0)
832 gchar
*text
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(prefs_toolbar
->item_plugin_combo
));
834 gchar
*text
= gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(prefs_toolbar
->item_plugin_combo
));
837 if (text
!= NULL
) { /* action */
838 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar
->item_text_entry
), text
);
843 static void func_selection_changed(GtkComboBox
*action_combo
,
844 ToolbarPage
*prefs_toolbar
)
846 #if !GTK_CHECK_VERSION(2, 24, 0)
847 gchar
*text
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(
849 gchar
*text
= gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(
851 prefs_toolbar
->item_func_combo
));
853 if(text
!= NULL
) { /* action */
855 action
= toolbar_ret_val_from_descr(text
);
857 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar
->item_text_entry
),
858 toolbar_get_short_text(action
));
861 StockPixmap stockp
= toolbar_get_icon(action
);
863 g_free(prefs_toolbar
->item_icon_file
);
864 prefs_toolbar
->item_icon_file
= g_strdup(stock_pixmap_get_name(stockp
));
866 gtk_button_set_image(GTK_BUTTON(prefs_toolbar
->icon_button
),
867 stock_pixmap_widget(stockp
));
873 static void prefs_toolbar_create(ToolbarPage
*prefs_toolbar
)
875 GtkWidget
*main_vbox
;
876 GtkWidget
*toolbar_item_hbox
;
877 GtkWidget
*icon_vbox
;
878 GtkWidget
*icon_label
;
879 GtkWidget
*icon_button
;
880 GtkWidget
*icon_hbox
;
881 GtkWidget
*item_type_combo
;
882 GtkListStore
*item_type_model
;
884 GtkWidget
*item_action_combo
;
885 GtkWidget
*item_plugin_combo
;
886 GtkWidget
*item_func_combo
;
894 GtkWidget
*subst_btn
;
896 GtkWidget
*default_btn
;
897 GtkWidget
*vbox_frame
;
899 GtkWidget
*label_icon_text
;
900 GtkWidget
*item_text_entry
;
901 GtkWidget
*vbox_toolbar_items
;
902 GtkWidget
*hbox_bottom
;
903 GtkWidget
*scrolledwindow_list_view_set
;
904 GtkWidget
*list_view_set
;
911 debug_print("Creating custom toolbar window...\n");
913 main_vbox
= gtk_vbox_new(FALSE
, 0);
914 gtk_widget_show(main_vbox
);
916 PACK_FRAME (main_vbox
, vbox_frame
, _("Toolbar item"))
917 gtk_container_set_border_width(GTK_CONTAINER(vbox_frame
), 8);
918 gtk_widget_show(vbox_frame
);
920 toolbar_item_hbox
= gtk_hbox_new (FALSE
, 4);
921 gtk_widget_show(toolbar_item_hbox
);
922 gtk_container_add(GTK_CONTAINER (vbox_frame
), toolbar_item_hbox
);
924 table
= gtk_table_new (3, 3, FALSE
);
925 gtk_box_pack_start(GTK_BOX(toolbar_item_hbox
), table
,
927 gtk_container_set_border_width (GTK_CONTAINER (table
), 8);
928 gtk_table_set_row_spacings (GTK_TABLE (table
), 8);
929 gtk_table_set_col_spacings (GTK_TABLE (table
), 8);
931 /* toolbar item type */
932 label
= gtk_label_new(_("Item type"));
933 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
934 gtk_widget_show(label
);
935 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, 0, 1,
936 (GtkAttachOptions
) (GTK_FILL
),
937 (GtkAttachOptions
) (0), 0, 0);
939 item_type_combo
= gtkut_sc_combobox_create(NULL
, TRUE
);
940 item_type_model
= GTK_LIST_STORE(gtk_combo_box_get_model(
941 GTK_COMBO_BOX(item_type_combo
)));
942 COMBOBOX_ADD(item_type_model
, _("Internal Function"), ITEM_FUNCTION
);
943 COMBOBOX_ADD(item_type_model
, _("User Action"), ITEM_USER_ACTION
);
944 COMBOBOX_ADD(item_type_model
, _("Plugins"), ITEM_PLUGIN
);
945 COMBOBOX_ADD(item_type_model
, _("Separator"), ITEM_SEPARATOR
);
946 gtk_widget_set_size_request(item_type_combo
, 200, -1);
947 gtk_table_attach(GTK_TABLE(table
), item_type_combo
, 1, 3, 0, 1,
948 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
949 (GtkAttachOptions
) (0), 0, 0);
951 /* available actions */
952 label
= gtk_label_new(_("Event executed on click"));
953 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
954 gtk_table_attach (GTK_TABLE (table
), label
, 0, 1, 1, 2,
955 (GtkAttachOptions
) (GTK_FILL
),
956 (GtkAttachOptions
) (0), 0, 0);
958 #if !GTK_CHECK_VERSION(2, 24, 0)
959 item_action_combo
= gtk_combo_box_new_text();
961 item_action_combo
= gtk_combo_box_text_new();
963 gtk_widget_set_size_request(item_action_combo
, 200, -1);
964 gtk_table_attach (GTK_TABLE (table
), item_action_combo
, 1, 3, 1, 2,
965 (GtkAttachOptions
) (GTK_FILL
),
966 (GtkAttachOptions
) (0), 0, 0);
968 /* available internal functions */
969 #if !GTK_CHECK_VERSION(2, 24, 0)
970 item_func_combo
= gtk_combo_box_new_text();
972 item_func_combo
= gtk_combo_box_text_new();
974 gtk_widget_set_size_request(item_func_combo
, 200, -1);
975 gtk_table_attach (GTK_TABLE (table
), item_func_combo
, 1, 3, 1, 2,
976 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
977 (GtkAttachOptions
) (0), 0, 0);
979 /* plugin-registered items */
980 #if !GTK_CHECK_VERSION(2, 24, 0)
981 item_plugin_combo
= gtk_combo_box_new_text();
983 item_plugin_combo
= gtk_combo_box_text_new();
985 gtk_widget_set_size_request(item_plugin_combo
, 200, -1);
986 gtk_table_attach(GTK_TABLE(table
), item_plugin_combo
, 1, 3, 1, 2,
987 (GtkAttachOptions
) (GTK_FILL
),
988 (GtkAttachOptions
) (0), 0, 0);
990 /* toolbar item description */
991 label_icon_text
= gtk_label_new(_("Toolbar text"));
992 gtk_misc_set_alignment(GTK_MISC(label_icon_text
), 0, 0.5);
993 gtk_widget_show (label_icon_text
);
994 gtk_table_attach (GTK_TABLE (table
), label_icon_text
, 0, 1, 2, 3,
995 (GtkAttachOptions
) (GTK_FILL
),
996 (GtkAttachOptions
) (0), 0, 0);
998 item_text_entry
= gtk_entry_new();
999 gtk_table_attach (GTK_TABLE (table
), item_text_entry
, 1, 3, 2, 3,
1000 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
1001 (GtkAttachOptions
) (0), 0, 0);
1003 icon_vbox
= gtk_vbox_new(FALSE
, VBOX_BORDER
);
1004 gtk_widget_show(icon_vbox
);
1006 icon_label
= gtk_label_new(_("Icon"));
1007 gtk_widget_set_size_request(icon_label
, 100, -1);
1008 gtk_box_pack_start(GTK_BOX(icon_vbox
), icon_label
, FALSE
, FALSE
, 0);
1010 icon_hbox
= gtk_hbox_new(FALSE
, 0);
1011 gtk_widget_show(icon_hbox
);
1013 label
= gtk_label_new("");
1014 gtk_box_pack_start(GTK_BOX(icon_hbox
), label
, TRUE
, TRUE
, 0);
1016 icon_button
= gtk_button_new();
1017 gtk_widget_show(icon_button
);
1018 gtk_widget_set_size_request(icon_button
, 50, 50);
1019 g_signal_connect(G_OBJECT(icon_button
), "clicked",
1020 G_CALLBACK(icon_chooser_create
), prefs_toolbar
);
1021 gtk_box_pack_start(GTK_BOX(icon_hbox
), icon_button
, FALSE
, FALSE
, 8);
1023 label
= gtk_label_new("");
1024 gtk_box_pack_start(GTK_BOX(icon_hbox
), label
, TRUE
, TRUE
, 0);
1026 gtk_box_pack_start(GTK_BOX(icon_vbox
), icon_hbox
, FALSE
, FALSE
, 0);
1028 gtk_box_pack_start(GTK_BOX(toolbar_item_hbox
), icon_vbox
, FALSE
, FALSE
, 0);
1030 /* register / substitute / delete */
1031 reg_hbox
= gtk_hbox_new(FALSE
, 4);
1032 gtk_box_pack_start(GTK_BOX(main_vbox
), reg_hbox
, FALSE
, FALSE
, 0);
1033 gtk_container_set_border_width(GTK_CONTAINER(reg_hbox
), 10);
1035 arrow
= gtk_arrow_new(GTK_ARROW_DOWN
, GTK_SHADOW_OUT
);
1036 gtk_box_pack_start(GTK_BOX(reg_hbox
), arrow
, FALSE
, FALSE
, 0);
1037 gtk_widget_set_size_request(arrow
, -1, 16);
1039 btn_hbox
= gtk_hbox_new(TRUE
, 4);
1040 gtk_box_pack_start(GTK_BOX(reg_hbox
), btn_hbox
, FALSE
, FALSE
, 0);
1042 reg_btn
= gtk_button_new_with_mnemonic (_("A_dd"));
1043 gtk_button_set_image(GTK_BUTTON(reg_btn
),
1044 gtk_image_new_from_stock(GTK_STOCK_ADD
,GTK_ICON_SIZE_BUTTON
));
1045 gtk_box_pack_start(GTK_BOX(btn_hbox
), reg_btn
, FALSE
, TRUE
, 0);
1046 g_signal_connect(G_OBJECT(reg_btn
), "clicked",
1047 G_CALLBACK(prefs_toolbar_register
),
1050 subst_btn
= gtkut_get_replace_btn(_("_Replace"));
1051 gtk_box_pack_start(GTK_BOX(btn_hbox
), subst_btn
, FALSE
, TRUE
, 0);
1052 g_signal_connect(G_OBJECT(subst_btn
), "clicked",
1053 G_CALLBACK(prefs_toolbar_substitute
),
1056 del_btn
= gtk_button_new_with_mnemonic (_("D_elete"));
1057 gtk_button_set_image(GTK_BUTTON(del_btn
),
1058 gtk_image_new_from_stock(GTK_STOCK_REMOVE
,GTK_ICON_SIZE_BUTTON
));
1059 gtk_box_pack_start(GTK_BOX(btn_hbox
), del_btn
, FALSE
, TRUE
, 0);
1060 g_signal_connect(G_OBJECT(del_btn
), "clicked",
1061 G_CALLBACK(prefs_toolbar_delete
),
1064 default_btn
= gtk_button_new_with_label(_(" Use default "));
1065 #ifndef GENERIC_UMPC
1066 gtk_box_pack_end(GTK_BOX(reg_hbox
), default_btn
, FALSE
, TRUE
, 0);
1068 hbox
= gtk_hbox_new(FALSE
, 0);
1069 gtk_box_pack_start(GTK_BOX(main_vbox
), hbox
, FALSE
, FALSE
, 0);
1070 gtk_box_pack_start(GTK_BOX(hbox
), default_btn
, FALSE
, FALSE
, 0);
1072 g_signal_connect(G_OBJECT(default_btn
), "clicked",
1073 G_CALLBACK(prefs_toolbar_default
),
1076 /* currently active toolbar items */
1077 vbox_toolbar_items
= gtk_vbox_new(FALSE
, VBOX_BORDER
);
1078 gtk_box_pack_start(GTK_BOX(main_vbox
), vbox_toolbar_items
, TRUE
, TRUE
, 0);
1080 hbox_bottom
= gtk_hbox_new(FALSE
, 0);
1081 gtk_container_add(GTK_CONTAINER(vbox_toolbar_items
), hbox_bottom
);
1083 scrolledwindow_list_view_set
= gtk_scrolled_window_new(NULL
, NULL
);
1084 gtk_box_pack_start(GTK_BOX(hbox_bottom
), scrolledwindow_list_view_set
, TRUE
, TRUE
, 0);
1085 gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_list_view_set
), 8);
1086 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_set
),
1087 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
1088 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_set
),
1091 list_view_set
= create_set_list_view(prefs_toolbar
);
1092 gtk_widget_show(list_view_set
);
1093 gtk_container_add(GTK_CONTAINER(scrolledwindow_list_view_set
), list_view_set
);
1094 gtk_widget_set_size_request(list_view_set
, 225, 120);
1096 btn_vbox
= gtk_vbox_new(FALSE
, 0);
1097 gtk_widget_show(btn_vbox
);
1098 gtk_box_pack_start(GTK_BOX(hbox_bottom
), btn_vbox
, FALSE
, FALSE
, 0);
1100 up_btn
= gtk_button_new_from_stock(GTK_STOCK_GO_UP
);
1101 gtk_widget_show(up_btn
);
1102 gtk_box_pack_start(GTK_BOX(btn_vbox
), up_btn
, FALSE
, FALSE
, 4);
1104 down_btn
= gtk_button_new_from_stock(GTK_STOCK_GO_DOWN
);
1105 gtk_widget_show(down_btn
);
1106 gtk_box_pack_start(GTK_BOX(btn_vbox
), down_btn
, FALSE
, FALSE
, 0);
1107 gtk_container_set_border_width(GTK_CONTAINER(btn_vbox
), 8);
1109 g_signal_connect(G_OBJECT(item_type_combo
), "changed",
1110 G_CALLBACK(item_type_changed
), prefs_toolbar
);
1111 g_signal_connect(G_OBJECT(item_action_combo
), "changed",
1112 G_CALLBACK(action_selection_changed
), prefs_toolbar
);
1113 g_signal_connect(G_OBJECT(item_plugin_combo
), "changed",
1114 G_CALLBACK(plugin_selection_changed
), prefs_toolbar
);
1115 g_signal_connect(G_OBJECT(item_func_combo
), "changed",
1116 G_CALLBACK(func_selection_changed
), prefs_toolbar
);
1117 g_signal_connect(G_OBJECT(up_btn
), "clicked",
1118 G_CALLBACK(prefs_toolbar_up
), prefs_toolbar
);
1119 g_signal_connect(G_OBJECT(down_btn
), "clicked",
1120 G_CALLBACK(prefs_toolbar_down
), prefs_toolbar
);
1122 gtk_widget_show_all(main_vbox
);
1124 prefs_toolbar
->list_view_set
= list_view_set
;
1125 prefs_toolbar
->item_text_entry
= item_text_entry
;
1126 prefs_toolbar
->item_type_combo
= item_type_combo
;
1127 prefs_toolbar
->item_func_combo
= item_func_combo
;
1128 prefs_toolbar
->item_action_combo
= item_action_combo
;
1129 prefs_toolbar
->item_plugin_combo
= item_plugin_combo
;
1130 prefs_toolbar
->icon_button
= icon_button
;
1131 prefs_toolbar
->item_icon_file
= NULL
;
1133 prefs_toolbar
->page
.widget
= main_vbox
;
1136 ToolbarPage
*prefs_toolbar_mainwindow
;
1137 ToolbarPage
*prefs_toolbar_composewindow
;
1138 ToolbarPage
*prefs_toolbar_messageview
;
1140 static void toolbar_unregister_plugin_item_real(GHashTable
*hash
,
1141 const gchar
*plugin_name
,
1142 const gchar
*item_name
)
1149 key
= g_strdup_printf(plugin_name
, "/", item_name
, NULL
);
1150 g_hash_table_remove(hash
, key
);
1154 void prefs_toolbar_unregister_plugin_item(ToolbarType toolbar_type
,
1155 const gchar
*plugin_name
,
1156 const gchar
*item_name
)
1159 hash
= get_plugin_hash_from_toolbar_type(toolbar_type
);
1161 toolbar_unregister_plugin_item_real(*hash
, plugin_name
, item_name
);
1164 static void prefs_toolbar_execute_plugin_item_real(gpointer parent
,
1165 GHashTable
*hash
, const gchar
*id
)
1167 ToolbarPluginItem
*value
;
1172 debug_print("No plugin registered toolbar items yet\n");
1176 value
= g_hash_table_lookup(hash
, id
);
1178 debug_print("Could not find plugin toolbar item with id %s\n", id
);
1182 /* check if corresponding plugin is currently loaded */
1184 for (walk
= plugin_get_list(); walk
; walk
= walk
->next
) {
1185 const gchar
*plugin_name
;
1186 Plugin
*plugin
= walk
->data
;
1187 plugin_name
= plugin_get_name(plugin
);
1188 if (!strcmp(plugin_name
, value
->plugin
)) {
1194 debug_print("Plugin '%s' is currently not loaded, cannot execute toolbar action\n", value
->plugin
);
1198 value
->cb(parent
, value
->item_name
, value
->cb_data
);
1201 void prefs_toolbar_execute_plugin_item(gpointer parent
,
1202 ToolbarType toolbar_type
, const gchar
*id
)
1205 hash
= get_plugin_hash_from_toolbar_type(toolbar_type
);
1207 prefs_toolbar_execute_plugin_item_real(parent
, *hash
, id
);
1210 static void destroy_plugin_item_hash_value(ToolbarPluginItem
*item
)
1212 g_free(item
->plugin
);
1213 g_free(item
->item_name
);
1217 static void prefs_toolbar_register_plugin_item_real(GHashTable
**hash
,
1218 const gchar
*plugin_name
,
1219 const gchar
*item_name
,
1220 ToolbarPluginCallback cb
,
1224 ToolbarPluginItem
*value
;
1226 cm_return_if_fail(plugin_name
&& item_name
);
1229 *hash
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
,
1230 (GDestroyNotify
) destroy_plugin_item_hash_value
);
1235 key
= g_strconcat(plugin_name
, "/", item_name
, NULL
);
1236 value
= g_new0(ToolbarPluginItem
, 1);
1237 value
->plugin
= g_strdup(plugin_name
);
1238 value
->item_name
= g_strdup(item_name
);
1240 value
->cb_data
= cb_data
;
1241 g_hash_table_insert(*hash
, key
, value
);
1244 void prefs_toolbar_register_plugin_item(ToolbarType toolbar_type
,
1245 const gchar
*plugin_name
,
1246 const gchar
*item_name
,
1247 ToolbarPluginCallback cb
,
1251 hash
= get_plugin_hash_from_toolbar_type(toolbar_type
);
1253 prefs_toolbar_register_plugin_item_real(hash
, plugin_name
,
1254 item_name
, cb
, cb_data
);
1257 void prefs_toolbar_init(void)
1260 static gchar
*mainpath
[3], *messagepath
[3], *composepath
[3];
1262 mainpath
[0] = _("Toolbars");
1263 mainpath
[1] = _("Main Window");
1266 page
= g_new0(ToolbarPage
, 1);
1267 page
->page
.path
= mainpath
;
1268 page
->page
.create_widget
= prefs_toolbar_create_widget
;
1269 page
->page
.destroy_widget
= prefs_toolbar_destroy_widget
;
1270 page
->page
.save_page
= prefs_toolbar_save
;
1271 page
->source
= TOOLBAR_MAIN
;
1272 page
->page
.weight
= 50.0;
1273 prefs_gtk_register_page((PrefsPage
*) page
);
1274 prefs_toolbar_mainwindow
= page
;
1276 messagepath
[0] = _("Toolbars");
1277 messagepath
[1] = _("Message Window");
1278 messagepath
[2] = NULL
;
1280 page
= g_new0(ToolbarPage
, 1);
1281 page
->page
.path
= messagepath
;
1282 page
->page
.create_widget
= prefs_toolbar_create_widget
;
1283 page
->page
.destroy_widget
= prefs_toolbar_destroy_widget
;
1284 page
->page
.save_page
= prefs_toolbar_save
;
1285 page
->source
= TOOLBAR_MSGVIEW
;
1286 page
->page
.weight
= 45.0;
1287 prefs_gtk_register_page((PrefsPage
*) page
);
1288 prefs_toolbar_messageview
= page
;
1290 composepath
[0] = _("Toolbars");
1291 composepath
[1] = _("Compose Window");
1292 composepath
[2] = NULL
;
1294 page
= g_new0(ToolbarPage
, 1);
1295 page
->page
.path
= composepath
;
1296 page
->page
.create_widget
= prefs_toolbar_create_widget
;
1297 page
->page
.destroy_widget
= prefs_toolbar_destroy_widget
;
1298 page
->page
.save_page
= prefs_toolbar_save
;
1299 page
->source
= TOOLBAR_COMPOSE
;
1300 page
->page
.weight
= 40.0;
1301 prefs_gtk_register_page((PrefsPage
*) page
);
1302 prefs_toolbar_composewindow
= page
;
1305 void prefs_toolbar_done(void)
1307 prefs_gtk_unregister_page((PrefsPage
*) prefs_toolbar_mainwindow
);
1308 g_free(prefs_toolbar_mainwindow
->item_icon_file
);
1309 g_free(prefs_toolbar_mainwindow
);
1310 prefs_gtk_unregister_page((PrefsPage
*) prefs_toolbar_composewindow
);
1311 g_free(prefs_toolbar_composewindow
->item_icon_file
);
1312 g_free(prefs_toolbar_composewindow
);
1313 prefs_gtk_unregister_page((PrefsPage
*) prefs_toolbar_messageview
);
1314 g_free(prefs_toolbar_messageview
->item_icon_file
);
1315 g_free(prefs_toolbar_messageview
);
1318 void prefs_toolbar_update_action_btns(void)
1320 if (toolbar_check_action_btns(TOOLBAR_MAIN
)) {
1321 toolbar_save_config_file(TOOLBAR_MAIN
);
1322 toolbar_update(TOOLBAR_MAIN
, mainwindow_get_mainwindow());
1325 if (toolbar_check_action_btns(TOOLBAR_COMPOSE
)) {
1326 toolbar_save_config_file(TOOLBAR_COMPOSE
);
1327 compose_reflect_prefs_pixmap_theme();
1330 if (toolbar_check_action_btns(TOOLBAR_MSGVIEW
)) {
1331 toolbar_save_config_file(TOOLBAR_MSGVIEW
);
1332 messageview_reflect_prefs_pixmap_theme();
1336 static void set_visible_if_not_text(GtkTreeViewColumn
*col
,
1337 GtkCellRenderer
*renderer
,
1338 GtkTreeModel
*model
,
1345 gtk_tree_model_get(model
, iter
, SET_ICON_IS_TEXT
, &is_text
, -1);
1347 g_object_set(renderer
, "visible", FALSE
, NULL
);
1350 gtk_tree_model_get(model
, iter
,
1353 /* note getting a pixbuf from a tree model increases
1354 * its refcount ... */
1355 g_object_unref(pixbuf
);
1357 g_object_set(renderer
, "visible", TRUE
, NULL
);
1358 g_object_set(renderer
, "pixbuf", pixbuf
, NULL
);
1362 static GtkWidget
*create_set_list_view(ToolbarPage
*prefs_toolbar
)
1364 GtkTreeView
*list_view
;
1365 GtkListStore
*store
;
1366 GtkCellRenderer
*renderer
;
1367 GtkTreeViewColumn
*column
;
1368 GtkTreeSelection
*selector
;
1370 store
= gtk_list_store_new(N_SET_COLUMNS
,
1378 list_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
)));
1379 g_object_unref(G_OBJECT(store
));
1381 column
= gtk_tree_view_column_new();
1382 gtk_tree_view_column_set_title(column
, _("Icon"));
1383 renderer
= gtk_cell_renderer_pixbuf_new();
1384 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
1385 gtk_tree_view_set_reorderable(list_view
, TRUE
);
1386 /* tell pixbuf renderer it is only visible if
1387 * the icon is not represented by text */
1388 gtk_tree_view_column_set_cell_data_func(column
, renderer
,
1389 set_visible_if_not_text
,
1392 renderer
= gtk_cell_renderer_text_new();
1393 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
1395 /* tell the text renderer it is only visible if the icon
1396 * is represented by an image */
1397 gtk_tree_view_column_set_attributes(column
, renderer
,
1398 "visible", SET_ICON_IS_TEXT
,
1399 "text", SET_ICON_TEXT
,
1402 gtk_tree_view_append_column(list_view
, column
);
1404 column
= gtk_tree_view_column_new();
1405 gtk_tree_view_column_set_title(column
, _("Icon text"));
1406 renderer
= gtk_cell_renderer_text_new();
1407 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
1408 gtk_tree_view_column_set_attributes(column
, renderer
,
1411 gtk_tree_view_append_column(list_view
, column
);
1413 column
= gtk_tree_view_column_new();
1414 gtk_tree_view_column_set_title(column
, _("Mapped event"));
1415 renderer
= gtk_cell_renderer_text_new();
1416 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
1417 gtk_tree_view_column_set_attributes(column
, renderer
,
1420 gtk_tree_view_append_column(list_view
, column
);
1422 /* various other tree view attributes */
1423 gtk_tree_view_set_rules_hint(list_view
, prefs_common
.use_stripes_everywhere
);
1425 selector
= gtk_tree_view_get_selection(list_view
);
1426 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
1427 gtk_tree_selection_set_select_function
1428 (selector
, (GtkTreeSelectionFunc
) set_list_selected
,
1429 prefs_toolbar
, NULL
);
1431 return GTK_WIDGET(list_view
);
1435 static gboolean
set_list_selected(GtkTreeSelection
*selector
,
1436 GtkTreeModel
*model
,
1438 gboolean currently_selected
,
1439 ToolbarPage
*prefs_toolbar
)
1443 gchar
*icon_text
, *icon_file
, *descr
;
1449 if (currently_selected
|| !gtk_tree_model_get_iter(model
, &iter
, path
))
1452 gtk_tree_model_get(model
, &iter
,
1454 SET_TEXT
, &icon_text
,
1456 SET_FILENAME
, &icon_file
,
1459 g_free(prefs_toolbar
->item_icon_file
);
1460 prefs_toolbar
->item_icon_file
= icon_file
;
1461 gtk_button_set_image(GTK_BUTTON(prefs_toolbar
->icon_button
),
1462 gtk_image_new_from_pixbuf(pix
));
1464 if (g_utf8_collate(toolbar_ret_descr_from_val(A_SEPARATOR
), descr
) == 0) {
1465 gtk_button_set_label(GTK_BUTTON(prefs_toolbar
->icon_button
),
1467 g_free(prefs_toolbar
->item_icon_file
);
1468 prefs_toolbar
->item_icon_file
= NULL
;
1469 gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar
->item_type_combo
),
1477 gtk_button_set_label(GTK_BUTTON(prefs_toolbar
->icon_button
), "");
1478 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar
->item_text_entry
),
1481 if (g_utf8_collate(toolbar_ret_descr_from_val(A_CLAWS_ACTIONS
), descr
) == 0) {
1482 gtk_combo_box_set_active(GTK_COMBO_BOX(
1483 prefs_toolbar
->item_type_combo
), ITEM_USER_ACTION
);
1485 for(cur2
= prefs_common
.actions_list
, item_num
= 0; cur2
!= NULL
;
1486 cur2
= cur2
->next
) {
1488 get_action_name((gchar
*)cur2
->data
, &item_string
);
1490 if(g_utf8_collate(item_string
, icon_text
) == 0) {
1491 gtk_combo_box_set_active(
1492 GTK_COMBO_BOX(prefs_toolbar
->item_action_combo
),
1494 g_free(item_string
);
1499 g_free(item_string
);
1503 gtk_widget_show(prefs_toolbar
->item_action_combo
);
1504 gtk_widget_hide(prefs_toolbar
->item_func_combo
);
1505 gtk_widget_hide(prefs_toolbar
->item_plugin_combo
);
1513 if (g_utf8_collate(toolbar_ret_descr_from_val(A_CLAWS_PLUGINS
), descr
) == 0) {
1514 gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar
->item_type_combo
), ITEM_PLUGIN
);
1516 gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar
->item_plugin_combo
), 0);
1518 gtk_widget_show(prefs_toolbar
->item_plugin_combo
);
1519 gtk_widget_hide(prefs_toolbar
->item_func_combo
);
1520 gtk_widget_hide(prefs_toolbar
->item_action_combo
);
1527 /* scan combo list for selected description an set combo item accordingly */
1528 for (cur
= prefs_toolbar
->combo_action_list
, item_num
= 0; cur
!= NULL
;
1530 gchar
*item_str
= (gchar
*)cur
->data
;
1531 if (g_utf8_collate(item_str
, descr
) == 0) {
1532 gtk_combo_box_set_active(
1533 GTK_COMBO_BOX(prefs_toolbar
->item_func_combo
),
1542 gtk_combo_box_set_active(GTK_COMBO_BOX(
1543 prefs_toolbar
->item_type_combo
),ITEM_FUNCTION
);
1544 gtk_widget_hide(prefs_toolbar
->item_action_combo
);
1545 gtk_widget_show(prefs_toolbar
->item_func_combo
);
1553 static void icon_chooser_ok_clicked(GtkButton
*button
,
1554 ToolbarPage
*prefs_toolbar
)
1556 GtkTreeModel
*model
;
1562 cm_return_if_fail(prefs_toolbar
!= NULL
);
1564 model
= gtk_icon_view_get_model(GTK_ICON_VIEW(prefs_toolbar
->icon_chooser_view
));
1565 list
= gtk_icon_view_get_selected_items(GTK_ICON_VIEW(prefs_toolbar
->icon_chooser_view
));
1569 if(!gtk_tree_model_get_iter(model
, &iter
, (GtkTreePath
*)list
->data
)) {
1570 gtk_tree_path_free(list
->data
);
1575 gtk_tree_model_get(model
, &iter
,
1577 SET_FILENAME
, &icon_file
,
1580 g_free(prefs_toolbar
->item_icon_file
);
1581 prefs_toolbar
->item_icon_file
= icon_file
;
1582 gtk_button_set_image(GTK_BUTTON(prefs_toolbar
->icon_button
),
1583 gtk_image_new_from_pixbuf(pix
));
1585 gtk_widget_destroy(prefs_toolbar
->icon_chooser_win
);
1586 prefs_toolbar
->icon_chooser_win
= NULL
;
1587 prefs_toolbar
->icon_chooser_view
= NULL
;
1589 gtk_tree_path_free(list
->data
);
1593 static void icon_chooser_cancel_clicked(GtkButton
*button
,
1594 ToolbarPage
*prefs_toolbar
)
1596 cm_return_if_fail(prefs_toolbar
!= NULL
);
1598 gtk_widget_destroy(prefs_toolbar
->icon_chooser_win
);
1599 prefs_toolbar
->icon_chooser_win
= NULL
;
1600 prefs_toolbar
->icon_chooser_view
= NULL
;
1603 static gboolean
icon_chooser_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
1604 ToolbarPage
*prefs_toolbar
)
1606 if (event
&& event
->keyval
== GDK_KEY_Escape
) {
1607 icon_chooser_cancel_clicked(NULL
, prefs_toolbar
);
1614 static gboolean
icon_list_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
1615 ToolbarPage
*prefs_toolbar
)
1618 if (event
->keyval
== GDK_KEY_KP_Enter
||
1619 event
->keyval
== GDK_KEY_Return
||
1620 event
->keyval
== GDK_KEY_space
) {
1621 icon_chooser_ok_clicked(NULL
, prefs_toolbar
);
1628 static gboolean
ok_cb(gpointer data
)
1630 ToolbarPage
*prefs_toolbar
= (ToolbarPage
*)data
;
1631 icon_chooser_ok_clicked(NULL
, prefs_toolbar
);
1635 static gboolean
icon_list_button_release(GtkWidget
*widget
,
1636 GdkEventButton
*event
,
1637 ToolbarPage
*prefs_toolbar
)
1639 static guint id
= 0;
1641 g_source_remove(id
);
1644 id
= g_timeout_add(100, ok_cb
, prefs_toolbar
);
1648 static gboolean
icon_window_button_press(GtkWidget
*widget
,
1649 GdkEventButton
*event
,
1650 ToolbarPage
*prefs_toolbar
)
1652 GtkWidget
*event_widget
;
1653 gboolean restore
= TRUE
;
1655 /* Test where mouse was clicked */
1656 event_widget
= gtk_get_event_widget((GdkEvent
*)event
);
1657 if (event_widget
!= widget
) {
1658 while (event_widget
) {
1659 if (event_widget
== widget
)
1661 else if (event_widget
== prefs_toolbar
->icon_chooser_win
) {
1665 event_widget
= gtk_widget_get_parent(event_widget
);
1670 icon_chooser_cancel_clicked(NULL
, prefs_toolbar
);
1676 static void icon_chooser_activated(GtkTreeView
*treeview
, GtkTreePath
*path
,
1677 ToolbarPage
*prefs_toolbar
)
1679 icon_chooser_ok_clicked(NULL
, prefs_toolbar
);
1682 static void icon_chooser_create(GtkButton
*button
, ToolbarPage
*prefs_toolbar
)
1684 GtkAllocation allocation
;
1685 GtkWidget
*icon_chooser_win
;
1686 GtkWidget
*scrollwin
;
1687 GtkWidget
*icon_view
;
1688 GtkListStore
*store
;
1692 store
= gtk_list_store_new(2,
1697 gtk_list_store_clear(store
);
1699 for (i
= 0; ToolbarIcons
[i
] != STOCK_PIXMAP_EMPTY
; i
++) {
1701 stock_pixbuf_gdk(ToolbarIcons
[i
], &pixbuf
);
1703 gtk_list_store_append(store
, &iter
);
1704 gtk_list_store_set(store
, &iter
,
1706 SET_FILENAME
, stock_pixmap_get_name((StockPixmap
) ToolbarIcons
[i
]),
1710 icon_chooser_win
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "prefs_toolbar");
1711 gtk_window_set_title(GTK_WINDOW(icon_chooser_win
), _("Toolbar item icon"));
1712 gtk_window_set_decorated(GTK_WINDOW(icon_chooser_win
), FALSE
);
1713 gdk_window_get_origin(gtk_widget_get_window(
1714 GTK_WIDGET(prefs_toolbar
->icon_button
)),
1716 gtk_widget_get_allocation(GTK_WIDGET(prefs_toolbar
->icon_button
), &allocation
);
1721 gtk_window_move(GTK_WINDOW(icon_chooser_win
), x
, y
);
1722 gtk_window_set_resizable(GTK_WINDOW(icon_chooser_win
), FALSE
);
1723 gtk_widget_set_size_request(icon_chooser_win
, 300, 320);
1725 scrollwin
= gtk_scrolled_window_new(NULL
, NULL
);
1726 gtk_container_add(GTK_CONTAINER(icon_chooser_win
), scrollwin
);
1727 gtk_widget_show(scrollwin
);
1728 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin
),
1729 GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
1730 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwin
),
1733 icon_view
= gtk_icon_view_new_with_model(GTK_TREE_MODEL(store
));
1734 gtk_icon_view_set_selection_mode(GTK_ICON_VIEW(icon_view
), GTK_SELECTION_SINGLE
);
1735 gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW(icon_view
), SET_ICON
);
1736 gtk_container_add(GTK_CONTAINER(scrollwin
), GTK_WIDGET(icon_view
));
1738 g_signal_connect(G_OBJECT(icon_chooser_win
), "key_press_event",
1739 G_CALLBACK(icon_chooser_key_pressed
), prefs_toolbar
);
1740 g_signal_connect(G_OBJECT(icon_view
), "item-activated",
1741 G_CALLBACK(icon_chooser_activated
), prefs_toolbar
);
1742 g_signal_connect(G_OBJECT(icon_chooser_win
),
1743 "button-press-event",
1744 G_CALLBACK(icon_window_button_press
),
1746 g_signal_connect(G_OBJECT(icon_view
),
1747 "button-release-event",
1748 G_CALLBACK(icon_list_button_release
),
1750 g_signal_connect(G_OBJECT(icon_view
), "key_press_event",
1751 G_CALLBACK(icon_list_key_pressed
), prefs_toolbar
);
1753 gtk_widget_show_all(icon_chooser_win
);
1754 gtk_widget_grab_focus(GTK_WIDGET(icon_view
));
1755 manage_window_set_transient(GTK_WINDOW(icon_chooser_win
));
1756 gtk_window_set_modal(GTK_WINDOW(icon_chooser_win
), TRUE
);
1758 prefs_toolbar
->icon_chooser_win
= icon_chooser_win
;
1759 prefs_toolbar
->icon_chooser_view
= icon_view
;