2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2007-2022 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 gtk_tree_view_set_rules_hint(list_view
, prefs_common
.use_stripes_everywhere
);
366 selector
= gtk_tree_view_get_selection(list_view
);
367 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
369 /* create the columns */
370 tags_window_create_list_view_columns(GTK_WIDGET(list_view
));
372 g_signal_connect(G_OBJECT(list_view
), "popup-menu",
373 G_CALLBACK(tags_list_popup_menu
), list_view
);
374 g_signal_connect(G_OBJECT(list_view
), "button-press-event",
375 G_CALLBACK(tags_list_btn_pressed
), list_view
);
376 return GTK_WIDGET(list_view
);
380 static void tags_window_list_view_clear_tags(GtkWidget
*list_view
);
382 static void tags_window_close(void)
387 if (tagswindow
.msglist
)
388 g_slist_free(tagswindow
.msglist
);
389 tagswindow
.msglist
= NULL
;
391 main_window_reflect_tags_changes(mainwindow_get_mainwindow());
392 TAGS_WINDOW_UNLOCK();
393 tags_window_list_view_clear_tags(tagswindow
.taglist
);
394 gtk_widget_hide(tagswindow
.window
);
395 gtk_window_set_modal(GTK_WINDOW(tagswindow
.window
), FALSE
);
398 static void tags_window_close_cb(GtkWidget
*widget
,
404 static void tags_window_list_view_insert_tag(GtkWidget
*list_view
,
405 GtkTreeIter
*row_iter
,
408 typedef struct FindTagInStore
{
414 static gboolean
find_tag_in_store(GtkTreeModel
*model
,
417 FindTagInStore
*data
)
420 gtk_tree_model_get(model
, iter
, TAG_DATA
, &tmp
, -1);
422 if (data
->tag_id
== GPOINTER_TO_INT(tmp
)) {
423 data
->path
= path
; /* signal we found it */
431 static void tags_window_add_tag(void)
433 gchar
*new_tag
= gtk_editable_get_chars(GTK_EDITABLE(tagswindow
.add_entry
), 0, -1);
440 if (!(IS_NOT_RESERVED_TAG(new_tag
))) {
441 alertpanel_error(_("You entered a reserved tag name, please choose another instead."));
445 id
= tags_get_id_for_str(new_tag
);
448 id
= tags_add_tag(new_tag
);
450 if (mainwindow_get_mainwindow())
452 mainwindow_get_mainwindow()->summaryview
,
454 main_window_reflect_tags_changes(mainwindow_get_mainwindow());
455 tags_window_list_view_insert_tag(tagswindow
.taglist
, NULL
, id
);
459 gtk_tree_model_foreach(gtk_tree_view_get_model
460 (GTK_TREE_VIEW(tagswindow
.taglist
)),
461 (GtkTreeModelForeachFunc
) find_tag_in_store
,
464 GtkTreeSelection
*selection
;
466 GtkTreeModel
*model
= gtk_tree_view_get_model(
467 GTK_TREE_VIEW(tagswindow
.taglist
));
469 if (mainwindow_get_mainwindow())
471 mainwindow_get_mainwindow()->summaryview
,
473 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(tagswindow
.taglist
));
474 gtk_tree_selection_select_iter(selection
, &fis
.iter
);
475 path
= gtk_tree_model_get_path(model
, &fis
.iter
);
476 /* XXX returned path may not be valid??? create new one to be sure */
477 gtk_tree_view_set_cursor(GTK_TREE_VIEW(tagswindow
.taglist
), path
, NULL
, FALSE
);
478 tags_window_list_view_insert_tag(tagswindow
.taglist
, &fis
.iter
, id
);
479 gtk_tree_path_free(path
);
481 TAGS_WINDOW_UNLOCK();
486 static void tags_window_add_tag_cb(GtkWidget
*widget
, gpointer data
)
490 tags_window_add_tag();
491 gtk_entry_set_text(GTK_ENTRY(tagswindow
.add_entry
), "");
492 gtk_widget_grab_focus(tagswindow
.taglist
);
495 static void tags_window_del_tag_cb(GtkWidget
*widget
, gpointer data
)
499 tags_popup_delete(NULL
, NULL
);
500 gtk_widget_grab_focus(tagswindow
.taglist
);
503 static gboolean
tags_window_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
507 if (event
&& event
->keyval
== GDK_KEY_Escape
)
509 else if (event
&& event
->keyval
== GDK_KEY_Delete
)
510 tags_popup_delete(NULL
, NULL
);
514 static gboolean
tags_window_add_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
519 if (event
&& (event
->keyval
== GDK_KEY_KP_Enter
|| event
->keyval
== GDK_KEY_Return
)) {
520 tags_window_add_tag();
521 gtk_entry_set_text(GTK_ENTRY(tagswindow
.add_entry
), "");
522 gtk_widget_grab_focus(tagswindow
.taglist
);
529 *\brief Save Gtk object size to prefs dataset
531 static void tags_window_size_allocate_cb(GtkWidget
*widget
,
532 GtkAllocation
*allocation
)
534 cm_return_if_fail(allocation
!= NULL
);
536 gtk_window_get_size(GTK_WINDOW(widget
),
537 &prefs_common
.tagswin_width
, &prefs_common
.tagswin_height
);
540 static void tags_window_create(void)
547 GtkWidget
*close_btn
;
548 GtkWidget
*scrolledwin
;
549 GtkWidget
*new_tag_label
;
550 GtkWidget
*new_tag_entry
;
553 static GdkGeometry geometry
;
555 window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "tags_window");
557 gtk_container_set_border_width(GTK_CONTAINER(window
), 8);
558 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
559 gtk_window_set_resizable(GTK_WINDOW(window
), TRUE
);
560 gtk_window_set_type_hint(GTK_WINDOW(window
), GDK_WINDOW_TYPE_HINT_DIALOG
);
561 g_signal_connect(G_OBJECT(window
), "delete_event",
562 G_CALLBACK(tags_window_close_cb
), NULL
);
563 g_signal_connect(G_OBJECT(window
), "size_allocate",
564 G_CALLBACK(tags_window_size_allocate_cb
), NULL
);
565 g_signal_connect(G_OBJECT(window
), "key_press_event",
566 G_CALLBACK(tags_window_key_pressed
), NULL
);
567 MANAGE_WINDOW_SIGNALS_CONNECT(window
);
569 vbox1
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 6);
570 hbox1
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 6);
572 new_tag_label
= gtk_label_new(_("New tag:"));
573 gtk_label_set_xalign(GTK_LABEL(new_tag_label
), 0.0);
574 gtk_box_pack_start(GTK_BOX(hbox1
), new_tag_label
, FALSE
, FALSE
, 0);
576 new_tag_entry
= gtk_entry_new();
577 gtk_box_pack_start(GTK_BOX(hbox1
), new_tag_entry
, FALSE
, FALSE
, 0);
578 g_signal_connect(G_OBJECT(new_tag_entry
), "key_press_event",
579 G_CALLBACK(tags_window_add_key_pressed
), NULL
);
581 add_btn
= gtkut_stock_button("list-add", _("_Add"));
582 gtk_box_pack_start(GTK_BOX(hbox1
), add_btn
, FALSE
, FALSE
, 0);
583 CLAWS_SET_TIP(add_btn
,
584 _("Add the new tag"));
586 del_btn
= gtkut_stock_button("edit-delete", _("D_elete"));
587 gtk_box_pack_start(GTK_BOX(hbox1
), del_btn
, FALSE
, FALSE
, 0);
588 CLAWS_SET_TIP(del_btn
,
589 _("Delete the selected tag"));
591 close_btn
= gtkut_stock_button("window-close", _("_Close"));
592 gtk_box_pack_end(GTK_BOX(hbox1
), close_btn
, FALSE
, FALSE
, 0);
594 gtk_widget_show(new_tag_label
);
595 gtk_widget_show(new_tag_entry
);
596 gtk_widget_show(close_btn
);
597 gtk_widget_show(add_btn
);
599 g_signal_connect(G_OBJECT(close_btn
), "clicked",
600 G_CALLBACK(tags_window_close_cb
), NULL
);
601 g_signal_connect(G_OBJECT(add_btn
), "clicked",
602 G_CALLBACK(tags_window_add_tag_cb
), NULL
);
603 g_signal_connect(G_OBJECT(del_btn
), "clicked",
604 G_CALLBACK(tags_window_del_tag_cb
), NULL
);
606 taglist
= tags_window_list_view_create();
608 label
= gtk_label_new(_("Choose the tag(s) for the message(s).\n"
609 "Changes are immediately applied."));
610 gtk_label_set_xalign(GTK_LABEL(label
), 0.0);
611 gtk_box_pack_start(GTK_BOX(vbox1
), label
, FALSE
, TRUE
, 0);
613 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
614 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
615 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
617 gtk_container_add(GTK_CONTAINER(scrolledwin
), taglist
);
618 gtk_box_pack_start(GTK_BOX(vbox1
), scrolledwin
, TRUE
, TRUE
, 0);
619 gtk_box_pack_start(GTK_BOX(vbox1
), hbox1
, FALSE
, FALSE
, 0);
621 gtk_widget_show(scrolledwin
);
622 gtk_widget_show(taglist
);
623 gtk_widget_show(hbox1
);
624 gtk_widget_show(vbox1
);
625 gtk_widget_show(close_btn
);
626 gtk_container_add(GTK_CONTAINER (window
), vbox1
);
628 if (!geometry
.min_height
) {
629 geometry
.min_width
= 500;
630 geometry
.min_height
= 250;
633 gtk_window_set_geometry_hints(GTK_WINDOW(window
), NULL
, &geometry
,
635 gtk_window_set_default_size(GTK_WINDOW(window
), prefs_common
.tagswin_width
,
636 prefs_common
.tagswin_height
);
638 tagswindow
.window
= window
;
639 tagswindow
.hbox1
= hbox1
;
640 tagswindow
.vbox1
= vbox1
;
641 tagswindow
.label
= label
;
642 tagswindow
.taglist
= taglist
;
643 tagswindow
.close_btn
= close_btn
;
644 tagswindow
.add_btn
= add_btn
;
645 tagswindow
.add_entry
= new_tag_entry
;
646 tagswindow
.del_btn
= del_btn
;
647 tagswindow
.has_tag_col
= FALSE
;
648 tagswindow
.watch_cursor
= gdk_cursor_new_for_display(
649 gtk_widget_get_display(window
), GDK_WATCH
);
651 g_signal_connect(G_OBJECT(new_tag_entry
), "changed",
652 G_CALLBACK(new_tag_set_add_sensitivity
), NULL
);
653 new_tag_set_add_sensitivity();
656 static void tags_window_list_view_clear_tags(GtkWidget
*list_view
)
658 GtkListStore
*list_store
= GTK_LIST_STORE(gtk_tree_view_get_model
659 (GTK_TREE_VIEW(list_view
)));
660 gtk_list_store_clear(list_store
);
664 static void tags_selected_toggled(GtkCellRendererToggle
*widget
,
666 GtkWidget
*list_view
)
669 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
670 gboolean enabled
= TRUE
, set
= FALSE
;
673 SummaryView
*summaryview
= NULL
;
678 if (mainwindow_get_mainwindow() != NULL
)
679 summaryview
= mainwindow_get_mainwindow()->summaryview
;
681 if (!gtk_tree_model_get_iter_from_string(model
, &iter
, path
))
684 gtk_tree_model_get(model
, &iter
,
685 TAG_SELECTED
, &enabled
,
690 tag_id
= GPOINTER_TO_INT(tmp
);
692 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
,
694 TAG_SELECTED_INCONSISTENT
, FALSE
,
699 summary_set_tag(summaryview
, set
? tag_id
: -tag_id
, NULL
);
700 TAGS_WINDOW_UNLOCK();
703 static void tags_selected_edited(GtkCellRendererText
*widget
,
704 gchar
*path
, gchar
*new_text
,
705 GtkWidget
*list_view
)
708 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
711 SummaryView
*summaryview
= NULL
;
717 if (mainwindow_get_mainwindow() != NULL
)
718 summaryview
= mainwindow_get_mainwindow()->summaryview
;
720 if (!gtk_tree_model_get_iter_from_string(model
, &iter
, path
))
723 if (!new_text
|| !*new_text
)
726 gtk_tree_model_get(model
, &iter
,
727 TAG_SELECTED
, &selected
,
731 tag_id
= GPOINTER_TO_INT(tmp
);
736 summary_set_tag(summaryview
, -tag_id
, NULL
);
739 tags_update_tag(tag_id
, new_text
);
741 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
,
746 summary_set_tag(summaryview
, tag_id
, NULL
);
749 summary_set_tag(summaryview
, 0, NULL
);
751 TAGS_WINDOW_UNLOCK();
754 static void tags_window_get_selected_state(gint tag
, gboolean
*selected
, gboolean
*selected_inconsistent
)
756 GSList
*cur
= tagswindow
.msglist
;
758 gint num_selected
= 0;
759 for (; cur
; cur
= cur
->next
) {
760 MsgInfo
*msginfo
= (MsgInfo
*)cur
->data
;
762 if (msginfo
->tags
&& g_slist_find(msginfo
->tags
, GINT_TO_POINTER(tag
))) {
767 if (num_selected
> 0 && num_selected
< num_mails
)
768 *selected_inconsistent
= TRUE
;
770 *selected_inconsistent
= FALSE
;
773 static void tags_window_list_view_insert_tag(GtkWidget
*list_view
,
774 GtkTreeIter
*row_iter
,
778 GtkListStore
*list_store
= GTK_LIST_STORE(gtk_tree_view_get_model
779 (GTK_TREE_VIEW(list_view
)));
780 const gchar
*name
= tags_get_tag(tag
);
781 gboolean selected
= FALSE
, selected_inconsistent
= FALSE
;
783 tags_window_get_selected_state(tag
, &selected
, &selected_inconsistent
);
784 if (row_iter
== NULL
) {
786 gtk_list_store_append(list_store
, &iter
);
787 gtk_list_store_set(list_store
, &iter
,
788 TAG_SELECTED
, selected
,
789 TAG_SELECTED_INCONSISTENT
, selected_inconsistent
,
791 TAG_DATA
, GINT_TO_POINTER(tag
),
794 gtk_list_store_set(list_store
, row_iter
,
795 TAG_SELECTED
, selected
,
796 TAG_SELECTED_INCONSISTENT
, selected_inconsistent
,
798 TAG_DATA
, GINT_TO_POINTER(tag
),
803 static void new_tag_set_add_sensitivity()
805 const gchar
*newtag
= gtk_entry_get_text((GtkEntry
*)tagswindow
.add_entry
);
806 gchar
*trim_text
= g_strdup(newtag
);
807 g_strstrip(trim_text
);
808 gtk_widget_set_sensitive(tagswindow
.add_btn
, (*trim_text
!= 0));
813 static void tags_window_load_tags (void)
817 tags_window_list_view_clear_tags(tagswindow
.taglist
);
819 cur
= tags
= tags_get_list();
820 for (; cur
; cur
= cur
->next
) {
821 id
= GPOINTER_TO_INT(cur
->data
);
822 tags_window_list_view_insert_tag(tagswindow
.taglist
, NULL
, id
);