2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2007-2024 Colin Leroy and 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 #include "claws-features.h"
27 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
37 #include "prefs_gtk.h"
40 #include "inputdialog.h"
41 #include "manage_window.h"
42 #include "mainwindow.h"
43 #include "prefs_common.h"
44 #include "alertpanel.h"
45 #include "summaryview.h"
51 TAG_SELECTED_INCONSISTENT
,
57 static gint
tag_cmp_func (GtkTreeModel
*model
, GtkTreeIter
*a
, GtkTreeIter
*b
, gpointer userdata
)
62 gtk_tree_model_get(model
, a
, TAG_NAME
, &name1
, -1);
63 gtk_tree_model_get(model
, b
, TAG_NAME
, &name2
, -1);
66 return name2
== NULL
? 0:1;
71 res
= g_utf8_collate(name1
,name2
);
78 static void tags_window_create(void);
80 static struct TagsWindow
93 GdkCursor
*watch_cursor
;
97 #define TAGS_WINDOW_LOCK() { \
98 gdk_window_set_cursor(gtk_widget_get_window(tagswindow.window), tagswindow.watch_cursor); \
99 tagswindow.busy = TRUE; \
102 #define TAGS_WINDOW_UNLOCK() { \
103 gdk_window_set_cursor(gtk_widget_get_window(tagswindow.window), NULL); \
104 tagswindow.busy = FALSE; \
107 static void tags_window_load_tags (void);
108 static void tags_window_insert_check_column(GtkWidget
*list_view
);
109 static void new_tag_set_add_sensitivity(void);
111 void tags_window_open(GSList
*msglist
)
113 if (!tagswindow
.window
)
114 tags_window_create();
116 manage_window_set_transient(GTK_WINDOW(tagswindow
.window
));
117 gtk_widget_grab_focus(tagswindow
.close_btn
);
119 tagswindow
.msglist
= msglist
;
120 tags_window_load_tags();
122 if (msglist
!= NULL
&& !tagswindow
.has_tag_col
) {
123 tags_window_insert_check_column(tagswindow
.taglist
);
124 tagswindow
.has_tag_col
= TRUE
;
126 if (msglist
== NULL
&& tagswindow
.has_tag_col
) {
127 gtk_tree_view_remove_column(GTK_TREE_VIEW(tagswindow
.taglist
),
128 gtk_tree_view_get_column(GTK_TREE_VIEW(tagswindow
.taglist
), 0));
129 tagswindow
.has_tag_col
= FALSE
;
131 if (msglist
== NULL
) {
132 gtk_widget_hide(tagswindow
.label
);
133 gtk_widget_show(tagswindow
.del_btn
);
134 gtk_window_set_title(GTK_WINDOW(tagswindow
.window
),
135 C_("Window title", "Tags configuration"));
137 gtk_widget_show(tagswindow
.label
);
138 gtk_widget_hide(tagswindow
.del_btn
);
139 gtk_window_set_title(GTK_WINDOW(tagswindow
.window
),
140 C_("Window title", "Modify tags"));
143 gtk_widget_show(tagswindow
.window
);
144 gtk_widget_grab_focus(tagswindow
.taglist
);
145 gtk_window_set_modal(GTK_WINDOW(tagswindow
.window
), TRUE
);
148 static GtkListStore
* tags_window_create_data_store(void)
150 GtkListStore
*store
= gtk_list_store_new(N_TAG_EDIT_COLUMNS
,
156 GtkTreeSortable
*sortable
= GTK_TREE_SORTABLE(store
);
158 gtk_tree_sortable_set_sort_func(sortable
, 0, tag_cmp_func
,
164 static void tags_selected_toggled(GtkCellRendererToggle
*widget
,
166 GtkWidget
*list_view
);
167 static void tags_selected_edited(GtkCellRendererText
*widget
,
168 gchar
*arg1
, gchar
*arg2
,
169 GtkWidget
*list_view
);
171 static void tags_window_insert_check_column(GtkWidget
*list_view
)
173 GtkTreeViewColumn
*column
;
174 GtkCellRenderer
*renderer
;
176 renderer
= gtk_cell_renderer_toggle_new();
177 g_object_set(renderer
,
181 column
= gtk_tree_view_column_new_with_attributes
184 "active", TAG_SELECTED
,
185 "inconsistent", TAG_SELECTED_INCONSISTENT
,
187 gtk_tree_view_column_set_alignment (column
, 0.5);
188 gtk_tree_view_insert_column(GTK_TREE_VIEW(list_view
), column
, 0);
189 g_signal_connect(G_OBJECT(renderer
), "toggled",
190 G_CALLBACK(tags_selected_toggled
),
194 static void tags_window_create_list_view_columns(GtkWidget
*list_view
)
196 GtkTreeViewColumn
*column
;
197 GtkCellRenderer
*renderer
;
199 renderer
= gtk_cell_renderer_text_new();
200 g_object_set(G_OBJECT(renderer
), "editable", TRUE
, NULL
);
202 column
= gtk_tree_view_column_new_with_attributes
207 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
208 gtk_tree_view_column_set_resizable(column
, TRUE
);
209 gtk_tree_view_set_search_column(GTK_TREE_VIEW(list_view
),
211 g_signal_connect(G_OBJECT(renderer
), "edited",
212 G_CALLBACK(tags_selected_edited
),
217 static GtkWidget
*tags_popup_menu
= NULL
;
219 static void tags_popup_delete (GtkAction
*action
, gpointer data
)
224 SummaryView
*summaryview
= NULL
;
225 GtkTreeSelection
*selection
= gtk_tree_view_get_selection
226 (GTK_TREE_VIEW(tagswindow
.taglist
));
227 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(tagswindow
.taglist
));
229 if (!gtk_tree_selection_get_selected(selection
, NULL
, &sel
))
232 if (alertpanel(_("Delete tag"),
233 _("Do you really want to delete this tag?"),
234 NULL
, _("_Cancel"), "edit-delete", _("D_elete"), NULL
, NULL
,
235 ALERTFOCUS_FIRST
) != G_ALERTALTERNATE
)
240 /* XXX: Here's the reason why we need to store the original
241 * pointer: we search the slist for it. */
242 gtk_tree_model_get(model
, &sel
,
246 /* Even though this is not documented, gtk_tree_model_get()
247 * seems to invalidate the GtkTreeIter that is passed to it,
248 * so we need to reacquire it. */
249 if (!gtk_tree_selection_get_selected(selection
, NULL
, &sel
))
252 gtk_list_store_remove(GTK_LIST_STORE(model
), &sel
);
253 if (mainwindow_get_mainwindow() != NULL
)
254 summaryview
= mainwindow_get_mainwindow()->summaryview
;
256 summary_set_tag(summaryview
, -id
, NULL
);
259 TAGS_WINDOW_UNLOCK();
262 static void tags_popup_delete_all (GtkAction
*action
, gpointer data
)
266 SummaryView
*summaryview
= NULL
;
268 if (alertpanel(_("Delete all tags"),
269 _("Do you really want to delete all tags?"),
270 NULL
, _("_Cancel"), "edit-delete", _("D_elete"), NULL
, NULL
,
271 ALERTFOCUS_FIRST
) != G_ALERTALTERNATE
)
276 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(tagswindow
.taglist
));
277 gtk_list_store_clear(GTK_LIST_STORE(model
));
279 if (mainwindow_get_mainwindow() != NULL
)
280 summaryview
= mainwindow_get_mainwindow()->summaryview
;
281 cur
= tags
= tags_get_list();
282 for (; cur
; cur
= cur
->next
) {
283 gint id
= GPOINTER_TO_INT(cur
->data
);
285 summary_set_tag(summaryview
, -id
, NULL
);
291 TAGS_WINDOW_UNLOCK();
294 static GtkActionEntry tags_popup_actions
[] =
296 { "EditTags", NULL
, "EditTags", NULL
, NULL
, NULL
},
297 { "EditTags/Delete", NULL
, N_("_Delete"), NULL
, "Delete tag", G_CALLBACK(tags_popup_delete
) },
298 { "EditTags/DeleteAll", NULL
, N_("Delete _all"), NULL
, "Delete all tags", G_CALLBACK(tags_popup_delete_all
) }
301 static gint
tags_list_btn_pressed(GtkWidget
*widget
, GdkEventButton
*event
,
302 GtkTreeView
*list_view
)
304 GtkUIManager
*gui_manager
= gtkut_ui_manager();
309 if (event
&& event
->button
== 3) {
310 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
314 if (!tags_popup_menu
) {
315 (void) cm_menu_create_action_group("EditTags", tags_popup_actions
,
316 G_N_ELEMENTS(tags_popup_actions
), (gpointer
)list_view
);
318 MENUITEM_ADDUI("/Menus", "EditTags", "EditTags", GTK_UI_MANAGER_MENU
)
319 MENUITEM_ADDUI("/Menus/EditTags", "Delete", "EditTags/Delete",
320 GTK_UI_MANAGER_MENUITEM
)
321 MENUITEM_ADDUI("/Menus/EditTags", "DeleteAll", "EditTags/DeleteAll",
322 GTK_UI_MANAGER_MENUITEM
)
324 tags_popup_menu
= gtk_menu_item_get_submenu(GTK_MENU_ITEM(
325 gtk_ui_manager_get_widget(gui_manager
, "/Menus/EditTags")) );
328 /* grey out popup menu items if list is empty */
329 non_empty
= gtk_tree_model_get_iter_first(model
, &iter
);
330 cm_menu_set_sensitive("EditTags/Delete", non_empty
);
331 cm_menu_set_sensitive("EditTags/DeleteAll", non_empty
);
333 gtk_menu_popup_at_pointer(GTK_MENU(tags_popup_menu
), NULL
);
340 static gboolean
tags_list_popup_menu(GtkWidget
*widget
, gpointer data
)
342 GtkTreeView
*list_view
= (GtkTreeView
*)data
;
343 GdkEventButton event
;
346 event
.time
= gtk_get_current_event_time();
348 tags_list_btn_pressed(NULL
, &event
, list_view
);
353 static GtkWidget
*tags_window_list_view_create (void)
355 GtkTreeView
*list_view
;
356 GtkTreeSelection
*selector
;
359 model
= GTK_TREE_MODEL(tags_window_create_data_store());
360 list_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(model
));
361 g_object_unref(model
);
362 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model
), TAG_NAME
, GTK_SORT_ASCENDING
);
364 selector
= gtk_tree_view_get_selection(list_view
);
365 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
367 /* create the columns */
368 tags_window_create_list_view_columns(GTK_WIDGET(list_view
));
370 g_signal_connect(G_OBJECT(list_view
), "popup-menu",
371 G_CALLBACK(tags_list_popup_menu
), list_view
);
372 g_signal_connect(G_OBJECT(list_view
), "button-press-event",
373 G_CALLBACK(tags_list_btn_pressed
), list_view
);
374 return GTK_WIDGET(list_view
);
378 static void tags_window_list_view_clear_tags(GtkWidget
*list_view
);
380 static void tags_window_close(void)
385 if (tagswindow
.msglist
)
386 g_slist_free(tagswindow
.msglist
);
387 tagswindow
.msglist
= NULL
;
389 main_window_reflect_tags_changes(mainwindow_get_mainwindow());
390 TAGS_WINDOW_UNLOCK();
391 tags_window_list_view_clear_tags(tagswindow
.taglist
);
392 gtk_widget_hide(tagswindow
.window
);
393 gtk_window_set_modal(GTK_WINDOW(tagswindow
.window
), FALSE
);
396 static void tags_window_close_cb(GtkWidget
*widget
,
402 static void tags_window_list_view_insert_tag(GtkWidget
*list_view
,
403 GtkTreeIter
*row_iter
,
406 typedef struct FindTagInStore
{
412 static gboolean
find_tag_in_store(GtkTreeModel
*model
,
415 FindTagInStore
*data
)
418 gtk_tree_model_get(model
, iter
, TAG_DATA
, &tmp
, -1);
420 if (data
->tag_id
== GPOINTER_TO_INT(tmp
)) {
421 data
->path
= path
; /* signal we found it */
429 static void tags_window_add_tag(void)
431 gchar
*new_tag
= gtk_editable_get_chars(GTK_EDITABLE(tagswindow
.add_entry
), 0, -1);
438 if (!(IS_NOT_RESERVED_TAG(new_tag
))) {
439 alertpanel_error(_("You entered a reserved tag name, please choose another instead."));
443 id
= tags_get_id_for_str(new_tag
);
446 id
= tags_add_tag(new_tag
);
448 if (mainwindow_get_mainwindow())
450 mainwindow_get_mainwindow()->summaryview
,
452 main_window_reflect_tags_changes(mainwindow_get_mainwindow());
453 tags_window_list_view_insert_tag(tagswindow
.taglist
, NULL
, id
);
457 gtk_tree_model_foreach(gtk_tree_view_get_model
458 (GTK_TREE_VIEW(tagswindow
.taglist
)),
459 (GtkTreeModelForeachFunc
) find_tag_in_store
,
462 GtkTreeSelection
*selection
;
464 GtkTreeModel
*model
= gtk_tree_view_get_model(
465 GTK_TREE_VIEW(tagswindow
.taglist
));
467 if (mainwindow_get_mainwindow())
469 mainwindow_get_mainwindow()->summaryview
,
471 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(tagswindow
.taglist
));
472 gtk_tree_selection_select_iter(selection
, &fis
.iter
);
473 path
= gtk_tree_model_get_path(model
, &fis
.iter
);
474 /* XXX returned path may not be valid??? create new one to be sure */
475 gtk_tree_view_set_cursor(GTK_TREE_VIEW(tagswindow
.taglist
), path
, NULL
, FALSE
);
476 tags_window_list_view_insert_tag(tagswindow
.taglist
, &fis
.iter
, id
);
477 gtk_tree_path_free(path
);
479 TAGS_WINDOW_UNLOCK();
484 static void tags_window_add_tag_cb(GtkWidget
*widget
, gpointer data
)
488 tags_window_add_tag();
489 gtk_entry_set_text(GTK_ENTRY(tagswindow
.add_entry
), "");
490 gtk_widget_grab_focus(tagswindow
.taglist
);
493 static void tags_window_del_tag_cb(GtkWidget
*widget
, gpointer data
)
497 tags_popup_delete(NULL
, NULL
);
498 gtk_widget_grab_focus(tagswindow
.taglist
);
501 static gboolean
tags_window_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
505 if (event
&& event
->keyval
== GDK_KEY_Escape
)
507 else if (event
&& event
->keyval
== GDK_KEY_Delete
)
508 tags_popup_delete(NULL
, NULL
);
512 static gboolean
tags_window_add_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
517 if (event
&& (event
->keyval
== GDK_KEY_KP_Enter
|| event
->keyval
== GDK_KEY_Return
)) {
518 tags_window_add_tag();
519 gtk_entry_set_text(GTK_ENTRY(tagswindow
.add_entry
), "");
520 gtk_widget_grab_focus(tagswindow
.taglist
);
527 *\brief Save Gtk object size to prefs dataset
529 static void tags_window_size_allocate_cb(GtkWidget
*widget
,
530 GtkAllocation
*allocation
)
532 cm_return_if_fail(allocation
!= NULL
);
534 gtk_window_get_size(GTK_WINDOW(widget
),
535 &prefs_common
.tagswin_width
, &prefs_common
.tagswin_height
);
538 static void tags_window_create(void)
545 GtkWidget
*close_btn
;
546 GtkWidget
*scrolledwin
;
547 GtkWidget
*new_tag_label
;
548 GtkWidget
*new_tag_entry
;
551 static GdkGeometry geometry
;
553 window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "tags_window");
555 gtk_container_set_border_width(GTK_CONTAINER(window
), 8);
556 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
557 gtk_window_set_resizable(GTK_WINDOW(window
), TRUE
);
558 gtk_window_set_type_hint(GTK_WINDOW(window
), GDK_WINDOW_TYPE_HINT_DIALOG
);
559 g_signal_connect(G_OBJECT(window
), "delete_event",
560 G_CALLBACK(tags_window_close_cb
), NULL
);
561 g_signal_connect(G_OBJECT(window
), "size_allocate",
562 G_CALLBACK(tags_window_size_allocate_cb
), NULL
);
563 g_signal_connect(G_OBJECT(window
), "key_press_event",
564 G_CALLBACK(tags_window_key_pressed
), NULL
);
565 MANAGE_WINDOW_SIGNALS_CONNECT(window
);
567 vbox1
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 6);
568 hbox1
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 6);
570 new_tag_label
= gtk_label_new(_("New tag:"));
571 gtk_label_set_xalign(GTK_LABEL(new_tag_label
), 0.0);
572 gtk_box_pack_start(GTK_BOX(hbox1
), new_tag_label
, FALSE
, FALSE
, 0);
574 new_tag_entry
= gtk_entry_new();
575 gtk_box_pack_start(GTK_BOX(hbox1
), new_tag_entry
, FALSE
, FALSE
, 0);
576 g_signal_connect(G_OBJECT(new_tag_entry
), "key_press_event",
577 G_CALLBACK(tags_window_add_key_pressed
), NULL
);
579 add_btn
= gtkut_stock_button("list-add", _("_Add"));
580 gtk_box_pack_start(GTK_BOX(hbox1
), add_btn
, FALSE
, FALSE
, 0);
581 CLAWS_SET_TIP(add_btn
,
582 _("Add the new tag"));
584 del_btn
= gtkut_stock_button("edit-delete", _("D_elete"));
585 gtk_box_pack_start(GTK_BOX(hbox1
), del_btn
, FALSE
, FALSE
, 0);
586 CLAWS_SET_TIP(del_btn
,
587 _("Delete the selected tag"));
589 close_btn
= gtkut_stock_button("window-close", _("_Close"));
590 gtk_box_pack_end(GTK_BOX(hbox1
), close_btn
, FALSE
, FALSE
, 0);
592 gtk_widget_show(new_tag_label
);
593 gtk_widget_show(new_tag_entry
);
594 gtk_widget_show(close_btn
);
595 gtk_widget_show(add_btn
);
597 g_signal_connect(G_OBJECT(close_btn
), "clicked",
598 G_CALLBACK(tags_window_close_cb
), NULL
);
599 g_signal_connect(G_OBJECT(add_btn
), "clicked",
600 G_CALLBACK(tags_window_add_tag_cb
), NULL
);
601 g_signal_connect(G_OBJECT(del_btn
), "clicked",
602 G_CALLBACK(tags_window_del_tag_cb
), NULL
);
604 taglist
= tags_window_list_view_create();
606 label
= gtk_label_new(_("Choose the tag(s) for the message(s).\n"
607 "Changes are immediately applied."));
608 gtk_label_set_xalign(GTK_LABEL(label
), 0.0);
609 gtk_box_pack_start(GTK_BOX(vbox1
), label
, FALSE
, TRUE
, 0);
611 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
612 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
613 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
615 gtk_container_add(GTK_CONTAINER(scrolledwin
), taglist
);
616 gtk_box_pack_start(GTK_BOX(vbox1
), scrolledwin
, TRUE
, TRUE
, 0);
617 gtk_box_pack_start(GTK_BOX(vbox1
), hbox1
, FALSE
, FALSE
, 0);
619 gtk_widget_show(scrolledwin
);
620 gtk_widget_show(taglist
);
621 gtk_widget_show(hbox1
);
622 gtk_widget_show(vbox1
);
623 gtk_widget_show(close_btn
);
624 gtk_container_add(GTK_CONTAINER (window
), vbox1
);
626 if (!geometry
.min_height
) {
627 geometry
.min_width
= 500;
628 geometry
.min_height
= 250;
631 gtk_window_set_geometry_hints(GTK_WINDOW(window
), NULL
, &geometry
,
633 gtk_window_set_default_size(GTK_WINDOW(window
), prefs_common
.tagswin_width
,
634 prefs_common
.tagswin_height
);
636 tagswindow
.window
= window
;
637 tagswindow
.hbox1
= hbox1
;
638 tagswindow
.vbox1
= vbox1
;
639 tagswindow
.label
= label
;
640 tagswindow
.taglist
= taglist
;
641 tagswindow
.close_btn
= close_btn
;
642 tagswindow
.add_btn
= add_btn
;
643 tagswindow
.add_entry
= new_tag_entry
;
644 tagswindow
.del_btn
= del_btn
;
645 tagswindow
.has_tag_col
= FALSE
;
646 tagswindow
.watch_cursor
= gdk_cursor_new_for_display(
647 gtk_widget_get_display(window
), GDK_WATCH
);
649 g_signal_connect(G_OBJECT(new_tag_entry
), "changed",
650 G_CALLBACK(new_tag_set_add_sensitivity
), NULL
);
651 new_tag_set_add_sensitivity();
654 static void tags_window_list_view_clear_tags(GtkWidget
*list_view
)
656 GtkListStore
*list_store
= GTK_LIST_STORE(gtk_tree_view_get_model
657 (GTK_TREE_VIEW(list_view
)));
658 gtk_list_store_clear(list_store
);
662 static void tags_selected_toggled(GtkCellRendererToggle
*widget
,
664 GtkWidget
*list_view
)
667 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
668 gboolean enabled
= TRUE
, set
= FALSE
;
671 SummaryView
*summaryview
= NULL
;
676 if (mainwindow_get_mainwindow() != NULL
)
677 summaryview
= mainwindow_get_mainwindow()->summaryview
;
679 if (!gtk_tree_model_get_iter_from_string(model
, &iter
, path
))
682 gtk_tree_model_get(model
, &iter
,
683 TAG_SELECTED
, &enabled
,
688 tag_id
= GPOINTER_TO_INT(tmp
);
690 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
,
692 TAG_SELECTED_INCONSISTENT
, FALSE
,
697 summary_set_tag(summaryview
, set
? tag_id
: -tag_id
, NULL
);
698 TAGS_WINDOW_UNLOCK();
701 static void tags_selected_edited(GtkCellRendererText
*widget
,
702 gchar
*path
, gchar
*new_text
,
703 GtkWidget
*list_view
)
706 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
709 SummaryView
*summaryview
= NULL
;
715 if (mainwindow_get_mainwindow() != NULL
)
716 summaryview
= mainwindow_get_mainwindow()->summaryview
;
718 if (!gtk_tree_model_get_iter_from_string(model
, &iter
, path
))
721 if (!new_text
|| !*new_text
)
724 gtk_tree_model_get(model
, &iter
,
725 TAG_SELECTED
, &selected
,
729 tag_id
= GPOINTER_TO_INT(tmp
);
734 summary_set_tag(summaryview
, -tag_id
, NULL
);
737 tags_update_tag(tag_id
, new_text
);
739 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
,
744 summary_set_tag(summaryview
, tag_id
, NULL
);
747 summary_set_tag(summaryview
, 0, NULL
);
749 TAGS_WINDOW_UNLOCK();
752 static void tags_window_get_selected_state(gint tag
, gboolean
*selected
, gboolean
*selected_inconsistent
)
754 GSList
*cur
= tagswindow
.msglist
;
756 gint num_selected
= 0;
757 for (; cur
; cur
= cur
->next
) {
758 MsgInfo
*msginfo
= (MsgInfo
*)cur
->data
;
760 if (msginfo
->tags
&& g_slist_find(msginfo
->tags
, GINT_TO_POINTER(tag
))) {
765 if (num_selected
> 0 && num_selected
< num_mails
)
766 *selected_inconsistent
= TRUE
;
768 *selected_inconsistent
= FALSE
;
771 static void tags_window_list_view_insert_tag(GtkWidget
*list_view
,
772 GtkTreeIter
*row_iter
,
776 GtkListStore
*list_store
= GTK_LIST_STORE(gtk_tree_view_get_model
777 (GTK_TREE_VIEW(list_view
)));
778 const gchar
*name
= tags_get_tag(tag
);
779 gboolean selected
= FALSE
, selected_inconsistent
= FALSE
;
781 tags_window_get_selected_state(tag
, &selected
, &selected_inconsistent
);
782 if (row_iter
== NULL
) {
784 gtk_list_store_append(list_store
, &iter
);
785 gtk_list_store_set(list_store
, &iter
,
786 TAG_SELECTED
, selected
,
787 TAG_SELECTED_INCONSISTENT
, selected_inconsistent
,
789 TAG_DATA
, GINT_TO_POINTER(tag
),
792 gtk_list_store_set(list_store
, row_iter
,
793 TAG_SELECTED
, selected
,
794 TAG_SELECTED_INCONSISTENT
, selected_inconsistent
,
796 TAG_DATA
, GINT_TO_POINTER(tag
),
801 static void new_tag_set_add_sensitivity()
803 const gchar
*newtag
= gtk_entry_get_text((GtkEntry
*)tagswindow
.add_entry
);
804 gchar
*trim_text
= g_strdup(newtag
);
805 g_strstrip(trim_text
);
806 gtk_widget_set_sensitive(tagswindow
.add_btn
, (*trim_text
!= 0));
811 static void tags_window_load_tags (void)
815 tags_window_list_view_clear_tags(tagswindow
.taglist
);
817 cur
= tags
= tags_get_list();
818 for (; cur
; cur
= cur
->next
) {
819 id
= GPOINTER_TO_INT(cur
->data
);
820 tags_window_list_view_insert_tag(tagswindow
.taglist
, NULL
, id
);