1 /* Claws Mail -- a GTK based, lightweight, and fast e-mail client
2 * Copyright (C) 2007-2024 Holger Berndt <hb@claws-mail.org>
3 * 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"
25 #include <gdk/gdkkeysyms.h>
26 #include <glib/gi18n.h>
32 #include "ldapserver.h"
33 #include "ldapupdate.h"
35 #include "addrduplicates.h"
37 #include "addressbook.h"
38 #include "editaddress.h"
39 #include "alertpanel.h"
43 #include "prefs_common.h"
48 AddressDataSource
*ds
;
61 static gboolean
create_dialog();
62 static void refresh_addr_hash(void);
63 static void refresh_stores(gchar
*,GSList
*);
64 static void present_finder_results(GtkWindow
*);
65 static void cb_finder_results_dialog_destroy(GtkWindow
*, gpointer
);
66 static gboolean
cb_finder_results_dialog_key_pressed(GtkWidget
*, GdkEventKey
*,
68 static void destroy_addr_hash_val(gpointer
);
69 static AddrDupListEntry
*copy_hash_val(AddrDupListEntry
*);
70 static void fill_hash_table();
71 static gint
collect_emails(ItemPerson
*, AddressDataSource
*);
72 static gboolean
is_not_duplicate(gpointer
, gpointer
, gpointer
);
73 static gint
books_compare(gconstpointer
, gconstpointer
);
74 static GtkWidget
* create_email_view(GtkListStore
*);
75 static GtkWidget
* create_detail_view(GtkListStore
*);
76 static void append_to_email_store(gpointer
,gpointer
,gpointer
);
77 static void email_selection_changed(GtkTreeSelection
*,gpointer
);
78 static void detail_selection_changed(GtkTreeSelection
*,gpointer
);
79 static void detail_row_activated(GtkTreeView
*,GtkTreePath
*,
82 static gboolean
detail_focus_in(GtkWidget
*,GdkEventFocus
*,gpointer
);
83 static gboolean
detail_focus_out(GtkWidget
*,GdkEventFocus
*,gpointer
);
85 static void cb_del_btn_clicked(GtkButton
*, gpointer
);
86 static void cb_edit_btn_clicked(GtkButton
*, gpointer
);
87 static gchar
* get_bookpath(ItemPerson
*,AddressDataSource
*);
88 static gboolean
is_editing_entry_only_selection(void);
89 static void edit_post_update_cb(ItemPerson
*);
91 static GHashTable
*addr_hash
;
92 static gboolean include_same_book
= TRUE
;
93 static gboolean include_other_books
= TRUE
;
95 static GtkListStore
*email_store
;
96 static GtkListStore
*detail_store
;
97 static GtkWidget
*email_view
;
98 static GtkWidget
*detail_view
;
99 static GtkWidget
*inline_edit_vbox
;
101 static GtkWidget
*del_btn
;
102 static GtkWidget
*edit_btn
;
104 static GtkWidget
*dialog
;
105 static gchar
*editing_uid
;
106 static gboolean detail_view_has_focus
;
108 void addrduplicates_find(GtkWindow
*parent
)
110 if(create_dialog()) {
112 present_finder_results(parent
);
116 static gboolean
create_dialog()
118 gboolean want_search
;
120 GtkWidget
*check_same_book
;
121 GtkWidget
*check_other_book
;
126 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
127 check_same_book
= gtk_check_button_new_with_label(_("Show duplicates in "
129 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_same_book
),
131 gtk_box_pack_start(GTK_BOX(vbox
), check_same_book
, FALSE
, FALSE
, 0);
132 gtk_widget_show(check_same_book
);
133 check_other_book
= gtk_check_button_new_with_label(_("Show duplicates in "
135 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_other_book
),
136 include_other_books
);
137 gtk_box_pack_start(GTK_BOX(vbox
), check_other_book
, FALSE
, FALSE
, 0);
138 gtk_widget_show(check_other_book
);
140 /* prevent checkboxes from being destroyed on dialog close */
141 g_object_ref(check_same_book
);
142 g_object_ref(check_other_book
);
144 val
= alertpanel_full(_("Find address book email duplicates"),
145 _("Claws Mail will now search for duplicate email "
146 "addresses in the address book."),
147 NULL
, _("_Cancel"), "edit-find", _("_Find"), NULL
, NULL
,
148 ALERTFOCUS_SECOND
, FALSE
, vbox
, ALERT_NOTICE
);
149 if(val
== G_ALERTALTERNATE
) {
154 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_same_book
));
155 include_other_books
=
156 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_other_book
));
160 g_object_unref(check_same_book
);
161 g_object_unref(check_other_book
);
165 static void refresh_addr_hash(void)
168 g_hash_table_destroy(addr_hash
);
169 addr_hash
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
170 g_free
, destroy_addr_hash_val
);
174 static void destroy_addr_hash_val(gpointer value
)
176 GSList
*list
= (GSList
*) value
;
179 for(walk
= list
; walk
; walk
= walk
->next
) {
180 AddrDupListEntry
*entry
= (AddrDupListEntry
*) walk
->data
;
181 if(entry
&& entry
->book_path
)
182 g_free(entry
->book_path
);
190 static AddrDupListEntry
*copy_hash_val(AddrDupListEntry
*entry
)
192 AddrDupListEntry
*new = g_new0(AddrDupListEntry
, 1);
193 new->person
= entry
->person
;
195 new->book_path
= g_strdup(entry
->book_path
);
200 static void fill_hash_table()
202 addrindex_load_person_ds(collect_emails
);
203 g_hash_table_foreach_remove(addr_hash
,is_not_duplicate
, NULL
);
206 static gboolean
is_not_duplicate(gpointer key
, gpointer value
,
209 gboolean is_in_same_book
;
210 gboolean is_in_other_books
;
214 GSList
*list
= value
;
216 /* remove everything that is just in one book */
217 if(g_slist_length(list
) <= 1)
220 /* work on a shallow copy */
221 books
= g_slist_copy(list
);
223 /* sorting the list makes it easier to check for books */
224 books
= g_slist_sort(books
, books_compare
);
226 /* check if a book appears twice */
227 is_in_same_book
= FALSE
;
228 for(walk
= books
; walk
&& walk
->next
; walk
= walk
->next
) {
229 if(books_compare(walk
->data
, walk
->next
->data
) == 0) {
230 is_in_same_book
= TRUE
;
235 /* check is at least two different books appear in the list */
236 is_in_other_books
= FALSE
;
237 if(books
&& books
->next
) {
238 for(walk
= books
->next
; walk
; walk
= walk
->next
) {
239 if(books_compare(walk
->data
, books
->data
) != 0) {
240 is_in_other_books
= TRUE
;
246 /* delete the shallow copy */
250 if(is_in_same_book
&& include_same_book
)
252 if(is_in_other_books
&& include_other_books
)
259 static gint
collect_emails(ItemPerson
*itemperson
, AddressDataSource
*ds
)
265 AddrDupListEntry
*entry
;
267 /* Process each E-Mail address */
268 nodeM
= itemperson
->listEMail
;
270 ItemEMail
*email
= nodeM
->data
;
272 addr
= g_utf8_strdown(email
->address
, -1);
273 old_val
= g_hash_table_lookup(addr_hash
, addr
);
275 new_val
= g_slist_copy_deep(old_val
, (GCopyFunc
)copy_hash_val
, NULL
);
279 entry
= g_new0(AddrDupListEntry
,1);
280 entry
->person
= itemperson
;
282 entry
->book_path
= get_bookpath(itemperson
, ds
);
284 new_val
= g_slist_prepend(new_val
, entry
);
285 g_hash_table_insert(addr_hash
, addr
, new_val
);
287 nodeM
= g_list_next(nodeM
);
292 static gint
books_compare(gconstpointer a
, gconstpointer b
)
294 const AddrDupListEntry
*entry1
;
295 const AddrDupListEntry
*entry2
;
298 return strcmp(entry1
->book_path
, entry2
->book_path
);
301 static void present_finder_results(GtkWindow
*parent
)
303 GtkWidget
*scrolled_win
;
310 GtkTreeSelection
*email_select
;
311 GtkTreeSelection
*detail_select
;
312 static GdkGeometry geometry
;
314 if(g_hash_table_size(addr_hash
) == 0) {
315 alertpanel_notice(_("No duplicate email addresses found in the address book"));
319 email_store
= gtk_list_store_new(1, G_TYPE_STRING
);
320 refresh_stores(NULL
,NULL
);
321 email_view
= create_email_view(email_store
);
322 email_select
= gtk_tree_view_get_selection(GTK_TREE_VIEW(email_view
));
323 gtk_tree_selection_set_mode(email_select
,GTK_SELECTION_SINGLE
);
325 g_signal_connect(email_select
, "changed",
326 (GCallback
)email_selection_changed
, NULL
);
328 detail_store
= gtk_list_store_new(NUM_COLS
, G_TYPE_STRING
, G_TYPE_STRING
,
329 G_TYPE_POINTER
, G_TYPE_POINTER
);
330 detail_view
= create_detail_view(detail_store
);
331 detail_select
= gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view
));
332 gtk_tree_selection_set_mode(detail_select
,GTK_SELECTION_MULTIPLE
);
334 g_signal_connect(detail_select
, "changed",
335 (GCallback
)detail_selection_changed
, NULL
);
337 dialog
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "address_dupes_finder");
338 gtk_window_set_type_hint(GTK_WINDOW(dialog
), GDK_WINDOW_TYPE_HINT_DIALOG
);
339 gtk_window_set_transient_for(GTK_WINDOW(dialog
),parent
);
340 gtk_window_set_modal(GTK_WINDOW(dialog
),TRUE
);
341 if(!geometry
.min_height
) {
342 geometry
.min_width
= 600;
343 geometry
.min_height
= 400;
345 gtk_window_set_geometry_hints(GTK_WINDOW(dialog
), NULL
, &geometry
,
347 gtk_window_set_title(GTK_WINDOW(dialog
), _("Duplicate email addresses"));
349 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
350 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
352 hpaned
= gtk_paned_new(GTK_ORIENTATION_HORIZONTAL
);
353 gtk_box_pack_start(GTK_BOX(vbox
), hpaned
, TRUE
, TRUE
, 0);
355 scrolled_win
= gtk_scrolled_window_new(NULL
,NULL
);
356 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win
),
357 GTK_POLICY_AUTOMATIC
,
358 GTK_POLICY_AUTOMATIC
);
359 gtk_container_add(GTK_CONTAINER(scrolled_win
), email_view
);
361 gtk_paned_add1(GTK_PANED(hpaned
), scrolled_win
);
363 scrolled_win
= gtk_scrolled_window_new(NULL
,NULL
);
364 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win
),
365 GTK_POLICY_AUTOMATIC
,
366 GTK_POLICY_AUTOMATIC
);
367 gtk_container_add(GTK_CONTAINER(scrolled_win
), detail_view
);
369 if (prefs_common
.addressbook_use_editaddress_dialog
) {
370 gtk_paned_add2(GTK_PANED(hpaned
), scrolled_win
);
371 inline_edit_vbox
= NULL
;
373 inline_edit_vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 4);
374 vpaned
= gtk_paned_new(GTK_ORIENTATION_VERTICAL
);
375 gtk_paned_pack1(GTK_PANED(vpaned
), scrolled_win
, FALSE
, FALSE
);
376 gtk_paned_pack2(GTK_PANED(vpaned
), inline_edit_vbox
, TRUE
, FALSE
);
377 gtk_paned_pack2(GTK_PANED(hpaned
), vpaned
, TRUE
, FALSE
);
380 g_object_get(G_OBJECT(hpaned
),
381 "position", &pos
, NULL
);
383 gtk_paned_set_position(GTK_PANED(hpaned
), 200);
385 hbox
= gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL
);
386 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox
), GTK_BUTTONBOX_END
);
387 gtk_box_set_spacing(GTK_BOX(hbox
), 2);
388 gtk_container_set_border_width(GTK_CONTAINER(hbox
), 4);
389 gtk_box_pack_end(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
391 edit_btn
= gtk_button_new_with_mnemonic(_("_Edit"));
392 gtk_box_pack_start(GTK_BOX(hbox
), edit_btn
, TRUE
, TRUE
, 0);
393 gtk_widget_set_sensitive(edit_btn
, FALSE
);
395 del_btn
= gtkut_stock_button("edit-delete", _("D_elete"));
396 gtk_box_pack_start(GTK_BOX(hbox
), del_btn
, TRUE
, TRUE
, 0);
397 gtk_widget_set_sensitive(del_btn
, FALSE
);
399 close
= gtkut_stock_button("window-close", _("_Close"));
400 gtk_box_pack_start(GTK_BOX(hbox
), close
, TRUE
, TRUE
, 0);
402 g_signal_connect(dialog
, "destroy",
403 G_CALLBACK(cb_finder_results_dialog_destroy
), NULL
);
404 g_signal_connect(G_OBJECT(dialog
), "key-press-event",
405 G_CALLBACK(cb_finder_results_dialog_key_pressed
), NULL
);
406 g_signal_connect_swapped(close
, "clicked",
407 G_CALLBACK(gtk_widget_destroy
), dialog
);
408 g_signal_connect(del_btn
, "clicked",
409 G_CALLBACK(cb_del_btn_clicked
), detail_view
);
410 g_signal_connect(edit_btn
, "clicked",
411 G_CALLBACK(cb_edit_btn_clicked
), detail_view
);
414 gtk_widget_show_all(dialog
);
417 static void cb_finder_results_dialog_destroy(GtkWindow
*win
, gpointer data
)
422 inline_edit_vbox
= NULL
;
425 g_hash_table_destroy(addr_hash
);
429 addressbook_refresh();
433 static GtkWidget
* create_email_view(GtkListStore
*store
)
436 GtkCellRenderer
*renderer
;
438 view
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
));
439 renderer
= gtk_cell_renderer_text_new();
440 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view
),
446 g_object_unref(store
);
450 static GtkWidget
* create_detail_view(GtkListStore
*store
)
453 GtkCellRenderer
*renderer
;
457 view
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
));
458 renderer
= gtk_cell_renderer_text_new();
461 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view
),
463 _("Address book path"),
465 "text", COL_BOOKPATH
,
468 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view
),
475 cols
= gtk_tree_view_get_columns(GTK_TREE_VIEW(view
));
476 for(walk
= cols
; walk
; walk
= walk
->next
)
477 gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(walk
->data
),
481 g_signal_connect(view
, "row-activated",
482 G_CALLBACK(detail_row_activated
), NULL
);
484 g_signal_connect(view
, "focus-in-event",
485 G_CALLBACK(detail_focus_in
), NULL
);
486 g_signal_connect(view
, "focus-out-event",
487 G_CALLBACK(detail_focus_out
), NULL
);
493 static void append_to_email_store(gpointer key
,gpointer value
,gpointer data
)
496 GtkListStore
*store
= (GtkListStore
*) data
;
498 gtk_list_store_append(store
, &iter
);
499 gtk_list_store_set(store
, &iter
, 0, (gchar
*) key
, -1);
502 static gboolean
is_editing_entry_only_selection(void)
504 GtkTreeSelection
*sel_detail
;
510 sel_detail
= gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view
));
512 if(gtk_tree_selection_count_selected_rows(sel_detail
) > 1)
515 selected
= gtk_tree_selection_get_selected_rows(sel_detail
,&model
);
516 cm_return_val_if_fail(selected
, FALSE
);
518 gtk_tree_model_get_iter(model
, &iter
, (GtkTreePath
*)selected
->data
);
519 g_list_foreach(selected
, (GFunc
)gtk_tree_path_free
, NULL
);
520 g_list_free(selected
);
522 gtk_tree_model_get(model
, &iter
, COL_ITEM
, &item
,-1);
523 if(ADDRITEM_ID(item
) && editing_uid
&&
524 strcmp(ADDRITEM_ID(item
),editing_uid
) == 0)
530 static void detail_selection_changed(GtkTreeSelection
*selection
, gpointer data
)
533 num_selected
= gtk_tree_selection_count_selected_rows(selection
);
536 gtk_widget_set_sensitive(del_btn
,TRUE
);
538 gtk_widget_set_sensitive(del_btn
,FALSE
);
540 if(num_selected
== 1)
541 gtk_widget_set_sensitive(edit_btn
,TRUE
);
543 gtk_widget_set_sensitive(edit_btn
,FALSE
);
545 if(!is_editing_entry_only_selection())
546 addressbook_edit_person_widgetset_hide();
549 static void email_selection_changed(GtkTreeSelection
*selection
, gpointer data
)
555 if(gtk_tree_selection_get_selected(selection
, &model
, &iter
)) {
559 gtk_tree_model_get(model
, &iter
, 0, &email
, -1);
561 hashval
= g_hash_table_lookup(addr_hash
, email
);
562 gtk_list_store_clear(detail_store
);
563 for(walk
= hashval
; walk
; walk
= walk
->next
) {
564 AddrDupListEntry
*entry
= walk
->data
;
567 gtk_list_store_append(detail_store
, &iter
);
568 gtk_list_store_set(detail_store
, &iter
,
569 COL_BOOKPATH
, entry
->book_path
,
570 COL_NAME
, addressbook_set_col_name_guard(ADDRITEM_NAME(entry
->person
)),
571 COL_ITEM
, entry
->person
,
579 static gchar
* get_bookpath(ItemPerson
*itemPerson
, AddressDataSource
*ds
)
583 AddrItemObject
*item
;
585 item
= (AddrItemObject
*)itemPerson
;
587 while((item
= ADDRITEM_PARENT(item
)) != NULL
) {
589 if(ADDRITEM_TYPE(item
) == ITEMTYPE_FOLDER
) {
590 ItemFolder
*folder
= (ItemFolder
*) item
;
592 path
= g_strdup_printf("%s%s%s",
593 folder
->isRoot
? addrindex_ds_get_name(ds
) :
594 ADDRITEM_NAME(folder
),
595 (*tmp
== '\0') ? "" : "/", tmp
);
601 /* prepend bookpath */
602 if(ds
&& ds
->interface
&& ds
->interface
->name
) {
604 path
= g_strdup_printf("%s%s%s", ds
->interface
->name
,
605 (*tmp
== '\0') ? "" : "/", tmp
);
612 static void refresh_stores(gchar
*email_to_select
, GSList
*detail_to_select
)
616 gtk_list_store_clear(email_store
);
618 gtk_list_store_clear(detail_store
);
619 g_hash_table_foreach(addr_hash
,append_to_email_store
,email_store
);
621 /* sort the email store */
622 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(email_store
),
623 0, GTK_SORT_ASCENDING
);
625 /* try to select email address */
626 if(email_to_select
) {
627 /* Search email in email store */
629 GtkTreeSelection
*selection
;
631 if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(email_store
), &iter
))
633 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(email_view
));
639 gtk_tree_model_get(GTK_TREE_MODEL(email_store
), &iter
, 0, &email
, -1);
640 retVal
= g_ascii_strncasecmp(email
,email_to_select
,strlen(email
));
643 gtk_tree_selection_select_iter(selection
,&iter
);
646 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(email_store
), &iter
));
650 /* try to select detail rows */
651 if(detail_to_select
) {
653 GtkTreeSelection
*sel
;
654 if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(detail_store
), &iter
))
656 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view
));
661 gtk_tree_model_get(GTK_TREE_MODEL(detail_store
), &iter
,
662 COL_ITEM
, &person
, -1);
663 for(walk
= detail_to_select
; walk
; walk
= walk
->next
) {
664 gchar
*uid
= walk
->data
;
665 if(uid
&& ADDRITEM_ID(person
) &&
666 (strcmp(uid
,ADDRITEM_ID(person
)) == 0))
667 gtk_tree_selection_select_iter(sel
,&iter
);
669 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(detail_store
), &iter
));
673 static void detail_row_activated(GtkTreeView
*tree_view
,
675 GtkTreeViewColumn
*column
,
680 AddressDataSource
*ds
;
682 AddressBookFile
*abf
;
684 model
= gtk_tree_view_get_model(tree_view
);
686 if(!gtk_tree_model_get_iter(model
,&iter
,path
))
689 gtk_tree_model_get(model
, &iter
, COL_ITEM
, &person
, COL_DS
, &ds
, -1);
692 if(!((ds
->type
== ADDR_IF_BOOK
) || ds
->type
== ADDR_IF_LDAP
)) {
693 debug_print("Unsupported address datasource type for editing\n");
697 abf
= ds
->rawDataSource
;
699 gtk_widget_show_all(inline_edit_vbox
);
702 editing_uid
= g_strdup(ADDRITEM_ID(person
));
703 addressbook_edit_person(abf
,NULL
,person
,FALSE
,inline_edit_vbox
,
704 edit_post_update_cb
,FALSE
);
707 static void edit_post_update_cb(ItemPerson
*item
)
709 GtkTreeSelection
*sel
;
718 /* save selection for after the update */
720 /* email -> string of email address */
721 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(email_view
));
722 if(gtk_tree_selection_get_selected(sel
,NULL
,&iter
))
723 gtk_tree_model_get(GTK_TREE_MODEL(email_store
), &iter
, 0, &email
, -1);
727 /* detail -> GSList of ItemPerson UIDs */
729 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view
));
730 detail_sel
= gtk_tree_selection_get_selected_rows(sel
, &model
);
731 for(walk
= detail_sel
; walk
; walk
= walk
->next
) {
732 GtkTreePath
*path
= walk
->data
;
733 if(!gtk_tree_model_get_iter(model
,&iter
,path
))
735 gtk_tree_model_get(model
, &iter
, COL_ITEM
, &person
,-1);
736 detail
= g_slist_prepend(detail
, g_strdup(ADDRITEM_ID(person
)));
738 g_list_foreach(detail_sel
, (GFunc
)gtk_tree_path_free
, NULL
);
739 g_list_free(detail_sel
);
741 /* now refresh the stores, trying to keep the selections active */
742 refresh_stores(email
,detail
);
747 g_slist_foreach(detail
, (GFunc
)g_free
, NULL
);
748 g_slist_free(detail
);
751 static void cb_edit_btn_clicked(GtkButton
*button
, gpointer data
)
753 GtkTreeSelection
*selection
;
757 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view
));
758 selected
= gtk_tree_selection_get_selected_rows(selection
,&model
);
759 cm_return_if_fail(selected
);
761 /* we are guaranteed to have exactly one row selected */
762 gtk_tree_view_row_activated(GTK_TREE_VIEW(detail_view
),(GtkTreePath
*)selected
->data
,
763 gtk_tree_view_get_column(GTK_TREE_VIEW(detail_view
),0));
765 g_list_foreach(selected
, (GFunc
)gtk_tree_path_free
, NULL
);
766 g_list_free(selected
);
769 static void cb_del_btn_clicked(GtkButton
*button
, gpointer data
)
773 GtkTreeSelection
*selection
;
775 AddressDataSource
*ds
;
779 GtkTreeRowReference
*ref
;
781 GtkTreeSelection
*sel
;
784 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view
));
786 list
= gtk_tree_selection_get_selected_rows(selection
, &model
);
787 cm_return_if_fail(list
);
789 aval
= alertpanel(_("Delete address(es)"),
790 _("Really delete the address(es)?"),
791 NULL
, _("_Cancel"), "edit-delete", _("D_elete"),
792 NULL
, NULL
, ALERTFOCUS_SECOND
);
793 if(aval
!= G_ALERTALTERNATE
)
797 for(walk
= list
; walk
; walk
= walk
->next
) {
798 ref
= gtk_tree_row_reference_new(model
,(GtkTreePath
*)(walk
->data
));
799 ref_list
= g_list_prepend(ref_list
, ref
);
801 g_list_foreach(list
, (GFunc
)gtk_tree_path_free
, NULL
);
804 for(walk
= ref_list
; walk
; walk
= walk
->next
) {
807 if(!gtk_tree_row_reference_valid(ref
))
809 path
= gtk_tree_row_reference_get_path(ref
);
810 if(gtk_tree_model_get_iter(model
, &iter
, path
)) {
811 gtk_tree_model_get(model
, &iter
, COL_ITEM
, &item
, COL_DS
, &ds
, -1);
812 addrduplicates_delete_item_person(item
,ds
);
814 gtk_tree_path_free(path
);
817 g_list_foreach(ref_list
, (GFunc
)gtk_tree_row_reference_free
, NULL
);
818 g_list_free(ref_list
);
820 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(email_view
));
821 if(gtk_tree_selection_get_selected(sel
,NULL
,&iter
))
822 gtk_tree_model_get(GTK_TREE_MODEL(email_store
), &iter
, 0, &email
, -1);
825 refresh_stores(email
,NULL
);
830 gboolean
addrduplicates_delete_item_person(ItemPerson
*item
, AddressDataSource
*ds
)
832 AddressBookFile
*abf
;
833 AddressInterface
*iface
;
836 /* Test for read only */
837 iface
= ds
->interface
;
838 if( iface
&& iface
->readOnly
) {
839 alertpanel(_("Delete address"),
840 _("This address data is read-only and cannot be deleted."),
841 "window-close", _("_Close"), NULL
, NULL
, NULL
, NULL
,
846 if(!(abf
= ds
->rawDataSource
))
849 item
->status
= DELETE_ENTRY
;
850 item
= addrbook_remove_person(abf
, item
);
854 if (ds
&& ds
->type
== ADDR_IF_LDAP
) {
855 LdapServer
*server
= ds
->rawDataSource
;
856 ldapsvr_set_modified(server
, TRUE
);
857 ldapsvr_update_book(server
, item
);
863 addritem_person_remove_picture(item
);
864 addritem_free_item_person(item
);
869 static gboolean
cb_finder_results_dialog_key_pressed(GtkWidget
*widget
,
874 if(event
->keyval
== GDK_KEY_Delete
&& detail_view_has_focus
)
875 cb_del_btn_clicked(NULL
,NULL
);
876 else if(event
->keyval
== GDK_KEY_Escape
)
877 gtk_widget_destroy(dialog
);
883 static gboolean
detail_focus_in(GtkWidget
*widget
,
884 GdkEventFocus
*event
,gpointer data
)
886 detail_view_has_focus
= TRUE
;
890 static gboolean
detail_focus_out(GtkWidget
*widget
,
891 GdkEventFocus
*event
,gpointer data
)
893 detail_view_has_focus
= FALSE
;