Use custom get_default_font_size() and _name()
[claws.git] / src / addrgather.c
blobe9d876d602d7c2d4e72b34a80c862aa04b4c7a64
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2022 the Claws Mail team and Match Grun
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/>.
20 * Dialog for gathering EMail addresses from mail folder.
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #include "claws-features.h"
26 #endif
28 #include "defs.h"
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtk.h>
35 #include "main.h"
36 #include "inc.h"
37 #include "mbox.h"
38 #include "filesel.h"
39 #include "foldersel.h"
40 #include "gtkutils.h"
41 #include "alertpanel.h"
42 #include "manage_window.h"
43 #include "folder.h"
44 #include "utils.h"
45 #include "prefs_common.h"
46 #include "prefs_gtk.h"
48 #include "addrharvest.h"
49 #ifndef USE_ALT_ADDRBOOK
50 #include "addrindex.h"
51 #include "addrbook.h"
52 #else
53 #include "addressbook-dbus.h"
54 #endif
55 #define PAGE_FIELDS 0
56 #define PAGE_FINISH 1
58 #define NUM_FIELDS 6
60 #define FIELDS_N_COLS 2
61 #define FIELDS_COL_WIDTH_HEADER 100
62 #define FIELDS_COL_WIDTH_COUNT 140
64 #define MIN_FOLDER_SIZE 20
65 #define DFL_FOLDER_SIZE 50
67 typedef enum {
68 FIELD_COL_HEADER = 0,
69 FIELD_COL_COUNT = 1
70 } AddrHarvest;
73 * The dialog.
75 static struct _AddrHarvest {
76 GtkWidget *window;
77 GtkWidget *notebook;
78 GtkWidget *labelFolder;
79 GtkWidget *entryBook;
80 GtkWidget *checkHeader[ NUM_FIELDS ];
81 #ifndef USE_ALT_ADDRBOOK
82 GtkWidget *spinbtnFolder;
83 #endif
84 GtkWidget *checkRecurse;
85 GtkWidget *btnOk;
86 GtkWidget *btnCancel;
87 GtkWidget *statusbar;
88 gint status_cid;
89 gboolean cancelled;
90 gboolean done;
91 gchar *folderPath;
92 GtkWidget *viewCount;
93 } addrgather_dlg;
95 #ifndef USE_ALT_ADDRBOOK
96 static AddressIndex *_harv_addressIndex_;
97 static AddressBookFile *_harv_addressBook_;
98 #endif
99 static gchar *_harv_headerNames_[] = {
100 HEADER_FROM,
101 HEADER_REPLY_TO,
102 HEADER_SENDER,
103 HEADER_TO,
104 HEADER_CC,
105 HEADER_ERRORS_TO
107 static GList *_harv_messageList_;
109 enum {
110 ADDRGATHER_COL_HEADER,
111 ADDRGATHER_COL_COUNT,
112 N_ADDRGATHER_COLS
115 static void addrgather_dlg_status_show( gchar *msg ) {
116 if( addrgather_dlg.statusbar != NULL ) {
117 gtk_statusbar_pop( GTK_STATUSBAR(addrgather_dlg.statusbar),
118 addrgather_dlg.status_cid );
119 if( msg ) {
120 gtk_statusbar_push(
121 GTK_STATUSBAR(addrgather_dlg.statusbar),
122 addrgather_dlg.status_cid, msg );
127 static gint addrgather_dlg_delete_event(
128 GtkWidget *widget, GdkEventAny *event, gpointer data )
130 addrgather_dlg.cancelled = TRUE;
131 gtk_main_quit();
132 return TRUE;
135 static gboolean addrgather_dlg_key_pressed(
136 GtkWidget *widget, GdkEventKey *event, gpointer data )
138 if( event && event->keyval == GDK_KEY_Escape ) {
139 addrgather_dlg.cancelled = TRUE;
140 gtk_main_quit();
142 return FALSE;
145 static void addrgather_size_allocate(
146 GtkWidget *widget, GtkAllocation *allocation )
148 cm_return_if_fail( allocation != NULL );
150 gtk_window_get_size(GTK_WINDOW(widget),
151 &prefs_common.addrgather_width, &prefs_common.addrgather_height);
154 #define FMT_BUFSIZE 32
156 static gboolean addrgather_dlg_harvest() {
157 GtkWidget *view;
158 GtkTreeModel *model;
159 GtkTreeIter iter;
160 AddressHarvester *harvester;
161 gchar *name;
162 #ifndef USE_ALT_ADDRBOOK
163 AddressBookFile *abf;
164 gchar *newFile;
165 #else
166 GList* list;
167 ContactData* contact;
168 GError* error = NULL;
169 #endif
170 gchar str[ FMT_BUFSIZE ];
171 gint cnt;
172 gint i;
173 #ifndef USE_ALT_ADDRBOOK
174 gint sz;
176 name = gtk_editable_get_chars( GTK_EDITABLE(addrgather_dlg.entryBook), 0, -1 );
177 if( name == NULL || strlen( name ) < 1 ) {
178 addrgather_dlg_status_show(
179 _( "Please specify name for address book." ) );
180 g_free( name );
181 return FALSE;
182 #else
183 name = gtk_editable_get_chars( GTK_EDITABLE(addrgather_dlg.entryBook), 0, -1 );
184 if( name == NULL || strlen( name ) < 1 ) {
185 addrgather_dlg_status_show(
186 _("No available address book."));
187 g_free( name );
188 return FALSE;
189 #endif
192 /* Create harvest helper */
193 harvester = addrharvest_create();
194 addrharvest_set_path( harvester, addrgather_dlg.folderPath );
196 for( i = 0; i < NUM_FIELDS; i++ ) {
197 addrharvest_set_header( harvester, _harv_headerNames_[i],
198 gtk_toggle_button_get_active(
199 GTK_TOGGLE_BUTTON(addrgather_dlg.checkHeader[i]) ) );
201 addrharvest_set_recurse( harvester,
202 gtk_toggle_button_get_active(
203 GTK_TOGGLE_BUTTON( addrgather_dlg.checkRecurse ) ) );
205 if( addrharvest_check_header( harvester ) == FALSE ) {
206 addrgather_dlg_status_show(
207 _( "Please select the mail headers to search." ) );
208 addrharvest_free( harvester );
209 g_free( name );
210 return FALSE;
213 /* Go fer it */
214 addrgather_dlg_status_show( _( "Collecting addresses..." ) );
215 GTK_EVENTS_FLUSH();
216 #ifndef USE_ALT_ADDRBOOK
217 sz = gtk_spin_button_get_value_as_int(
218 GTK_SPIN_BUTTON( addrgather_dlg.spinbtnFolder ) );
219 addrharvest_set_folder_size( harvester, sz );
220 #endif
222 #ifndef USE_ALT_ADDRBOOK
223 /* Create address book */
224 abf = addrbook_create_book();
225 addrbook_set_path( abf, _harv_addressIndex_->filePath );
226 newFile = addrbook_guess_next_file( abf );
227 addrbook_set_file( abf, newFile );
228 addrbook_set_name( abf, name );
229 g_free( newFile );
230 g_free( name );
231 #endif
233 /* Harvest addresses */
234 #ifndef USE_ALT_ADDRBOOK
235 addrharvest_harvest(
236 harvester, abf->addressCache, _harv_messageList_ );
237 /* save address book */
238 addrbook_save_data( abf );
239 _harv_addressBook_ = abf;
240 #else
241 addrharvest_harvest(
242 harvester, NULL, _harv_messageList_ );
243 list = g_hash_table_get_values(harvester->dupTable);
244 for (; list; list = g_list_next(list)) {
245 contact = g_new0(ContactData, 1);
246 ContactEntry* person = (ContactEntry *) list->data;
247 if (person->first_name)
248 contact->name = g_strconcat(
249 person->first_name, " ", person->last_name, NULL);
250 else
251 contact->name = g_strdup(person->last_name);
252 if (! contact->name || strlen(contact->name) < 1)
253 contact->name = g_strdup(person->email);
254 contact->remarks = g_strdup(N_("address added by Claws Mail"));
255 contact->email = g_strdup(person->email);
256 contact->book = g_strdup(name);
257 addressbook_dbus_add_contact(contact, &error);
258 contact_data_free(&contact);
260 g_list_free(list);
261 g_free(name);
262 #endif
264 /* Update summary count */
265 view = addrgather_dlg.viewCount;
266 model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
267 gtk_list_store_clear( GTK_LIST_STORE(model) );
268 for( i = 0; i < NUM_FIELDS; i++ ) {
269 cnt = addrharvest_get_count( harvester, _harv_headerNames_[i] );
270 if( cnt < 1 ) {
271 strcpy( str, "-" );
273 else {
274 snprintf( str, FMT_BUFSIZE, "%d", cnt );
276 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
277 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
278 ADDRGATHER_COL_HEADER, _harv_headerNames_[i],
279 ADDRGATHER_COL_COUNT, str,
280 -1);
283 addrharvest_free( harvester );
285 addrgather_dlg_status_show(_("Addresses collected successfully."));
287 /* Display summary page */
288 gtk_notebook_set_current_page(
289 GTK_NOTEBOOK(addrgather_dlg.notebook), PAGE_FINISH );
290 addrgather_dlg.done = TRUE;
291 gtk_widget_set_sensitive( addrgather_dlg.btnCancel, FALSE );
292 gtk_widget_grab_default( addrgather_dlg.btnOk );
294 return TRUE;
297 static void addrgather_dlg_ok( GtkWidget *widget, gpointer data ) {
298 if(addrgather_dlg.done) {
299 addrgather_dlg.done = FALSE;
300 gtk_main_quit();
301 return;
303 if( addrgather_dlg_harvest() ) {
304 addrgather_dlg.cancelled = FALSE;
308 static void addrgather_dlg_cancel( GtkWidget *widget, gpointer data ) {
309 gtk_main_quit();
313 * Create notebook page for mail headers.
314 * Enter: pageNum Page number.
315 * pageLbl Page label.
317 static void addrgather_page_fields(gint pageNum, gchar *pageLbl)
319 GtkWidget *vbox;
320 GtkWidget *vboxf;
321 GtkWidget *table;
322 GtkWidget *label;
323 GtkWidget *labelFolder;
324 GtkWidget *entryBook;
325 GtkWidget *frameHeader;
326 GtkWidget *checkHeader[NUM_FIELDS];
327 #ifndef USE_ALT_ADDRBOOK
328 GtkWidget *hboxs;
329 GtkWidget *spinbtnFolder;
330 GtkAdjustment *adjFolder;
331 #endif
332 GtkWidget *checkRecurse;
333 gint i;
334 #ifdef USE_ALT_ADDRBOOK
335 GError* error = NULL;
336 GSList *books, *cur;
337 #endif
339 /* Container */
340 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
341 gtk_container_add(GTK_CONTAINER(addrgather_dlg.notebook), vbox);
342 gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
344 /* Notebook page */
345 label = gtk_label_new(pageLbl);
346 gtk_widget_show(label);
347 gtk_notebook_set_tab_label(GTK_NOTEBOOK(addrgather_dlg.notebook),
348 gtk_notebook_get_nth_page(GTK_NOTEBOOK(addrgather_dlg.notebook),
349 pageNum), label);
351 /* Upper area - Field list */
352 table = gtk_grid_new();
353 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
354 gtk_grid_set_row_spacing(GTK_GRID(table), VSPACING_NARROW);
355 gtk_grid_set_column_spacing(GTK_GRID(table), HSPACING_NARROW);
357 /* First row */
358 label = gtk_label_new(_("Current folder:"));
359 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
360 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
362 labelFolder = gtk_label_new("");
363 gtk_grid_attach(GTK_GRID(table), labelFolder, 1, 0, 1, 1);
364 gtk_label_set_xalign(GTK_LABEL(labelFolder), 0.0);
366 /* Second row */
367 label = gtk_label_new(_("Address book name:"));
368 gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
369 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
371 #ifndef USE_ALT_ADDRBOOK
372 entryBook = gtk_entry_new();
373 #else
374 books = addressbook_dbus_get_books(&error);
375 entryBook = gtk_combo_box_text_new();
376 if (books) {
377 for (cur = books; cur; cur = g_slist_next(cur)) {
378 gchar* book = (gchar *) cur->data;
379 gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(entryBook), book);
380 g_free(book);
382 g_slist_free(books);
384 else
385 gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(entryBook), "");
386 gtk_combo_box_set_active(GTK_COMBO_BOX(entryBook), 0);
387 #endif
388 gtk_grid_attach(GTK_GRID(table), entryBook, 1, 1, 2, 1);
389 gtk_widget_set_hexpand(entryBook, TRUE);
390 gtk_widget_set_halign(entryBook, GTK_ALIGN_FILL);
393 #ifndef USE_ALT_ADDRBOOK
394 /* Third row */
395 label = gtk_label_new(_("Address book folder size:"));
396 gtk_grid_attach(GTK_GRID(table), label, 0, 2, 1, 1);
397 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
398 CLAWS_SET_TIP(label,
399 _("Maximum amount of entries per folder within the newly created address book"));
401 hboxs = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
402 adjFolder = GTK_ADJUSTMENT(gtk_adjustment_new(DFL_FOLDER_SIZE, MIN_FOLDER_SIZE, G_MAXINT, 1, 10, 0));
403 spinbtnFolder = gtk_spin_button_new(GTK_ADJUSTMENT(adjFolder), 1, 0);
404 gtk_box_pack_start(GTK_BOX(hboxs), spinbtnFolder, FALSE, FALSE, 0);
405 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spinbtnFolder), TRUE);
406 gtk_grid_attach(GTK_GRID(table), hboxs, 1, 2, 1, 1);
408 CLAWS_SET_TIP(spinbtnFolder,
409 _("Maximum amount of entries per folder within the newly created address book"));
410 #endif
411 /* Fourth row */
412 frameHeader = gtk_frame_new(_("Process these mail header fields"));
413 gtk_widget_show(frameHeader);
414 gtk_grid_attach(GTK_GRID(table), frameHeader, 0, 3, 1, 1);
415 gtk_widget_set_hexpand(frameHeader, TRUE);
416 gtk_widget_set_halign(frameHeader, GTK_ALIGN_FILL);
417 gtk_frame_set_label_align(GTK_FRAME(frameHeader), 0.01, 0.5);
419 /* Check boxes */
420 vboxf = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
421 gtk_widget_show(vboxf);
422 gtk_container_add(GTK_CONTAINER(frameHeader), vboxf);
423 gtk_container_set_border_width(GTK_CONTAINER(vboxf), 8);
425 for (i = 0; i < NUM_FIELDS; i++) {
426 PACK_CHECK_BUTTON(vboxf, checkHeader[i],
427 prefs_common_translated_header_name(_harv_headerNames_[i]));
428 addrgather_dlg.checkHeader[i] = checkHeader[i];
431 /* Recurse folders */
432 checkRecurse = gtk_check_button_new_with_label( _("Include subfolders" ) );
433 gtk_grid_attach(GTK_GRID(table), checkRecurse, 0, 4, 1, 1);
435 addrgather_dlg.labelFolder = labelFolder;
436 addrgather_dlg.entryBook = entryBook;
437 #ifndef USE_ALT_ADDRBOOK
438 addrgather_dlg.spinbtnFolder = spinbtnFolder;
439 #endif
440 addrgather_dlg.checkRecurse = checkRecurse;
444 * Create notebook page for summary counts.
445 * Enter: pageNum Page number.
446 * pageLbl Page label.
448 static void addrgather_page_finish( gint pageNum, gchar *pageLbl ) {
449 GtkWidget *label;
450 GtkWidget *vbox;
451 GtkWidget *scrollwin;
452 GtkWidget *viewCount;
453 GtkTreeViewColumn *col;
454 GtkCellRenderer *rdr;
455 GtkTreeSelection *sel;
456 GtkTreeModel *model;
458 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
459 gtk_container_add( GTK_CONTAINER( addrgather_dlg.notebook ), vbox );
460 gtk_container_set_border_width( GTK_CONTAINER (vbox), 8 );
462 label = gtk_label_new( pageLbl );
463 gtk_widget_show( label );
464 gtk_notebook_set_tab_label(
465 GTK_NOTEBOOK( addrgather_dlg.notebook ),
466 gtk_notebook_get_nth_page( GTK_NOTEBOOK( addrgather_dlg.notebook ), pageNum ),
467 label );
469 /* Summary count */
470 scrollwin = gtk_scrolled_window_new( NULL, NULL );
471 gtk_container_add( GTK_CONTAINER(vbox), scrollwin );
472 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
473 GTK_POLICY_AUTOMATIC,
474 GTK_POLICY_AUTOMATIC);
475 gtk_widget_set_vexpand(GTK_WIDGET(scrollwin), TRUE);
477 /* Treeview */
478 model = GTK_TREE_MODEL(gtk_list_store_new(N_ADDRGATHER_COLS,
479 G_TYPE_STRING, G_TYPE_STRING, -1));
481 viewCount = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
482 g_object_unref(model);
483 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(viewCount), TRUE);
484 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(viewCount), FALSE);
485 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(viewCount));
486 gtk_tree_selection_set_mode(sel, GTK_SELECTION_NONE);
488 /* Columns for the treeview */
489 rdr = gtk_cell_renderer_text_new();
490 col = gtk_tree_view_column_new_with_attributes(_("Header Name"), rdr,
491 "markup", ADDRGATHER_COL_HEADER,
492 NULL);
493 gtk_tree_view_column_set_min_width(col, FIELDS_COL_WIDTH_HEADER);
494 gtk_tree_view_append_column(GTK_TREE_VIEW(viewCount), col);
496 col = gtk_tree_view_column_new_with_attributes(_("Address Count"), rdr,
497 "text", ADDRGATHER_COL_COUNT,
498 NULL);
499 gtk_tree_view_column_set_min_width(col, FIELDS_COL_WIDTH_COUNT);
500 gtk_tree_view_append_column(GTK_TREE_VIEW(viewCount), col);
502 gtk_container_add( GTK_CONTAINER(scrollwin), viewCount );
504 addrgather_dlg.viewCount = viewCount;
508 * Create notebook page for warning message.
509 * Enter: pageNum Page number.
510 * pageLbl Page label.
512 static void addrgather_dlg_create(void)
514 GtkWidget *window;
515 GtkWidget *notebook;
516 GtkWidget *btnOk;
517 GtkWidget *btnCancel;
518 GtkWidget *statusbar;
519 GtkWidget *vbox;
520 GtkWidget *hbbox;
521 GtkWidget *hsbox;
522 static GdkGeometry geometry;
524 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "addrgather");
525 gtk_container_set_border_width(GTK_CONTAINER(window), 4);
526 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
527 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
528 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
530 g_signal_connect(G_OBJECT(window), "delete_event",
531 G_CALLBACK(addrgather_dlg_delete_event), NULL);
532 g_signal_connect(G_OBJECT(window), "key_press_event",
533 G_CALLBACK(addrgather_dlg_key_pressed), NULL);
534 g_signal_connect(G_OBJECT(window), "size_allocate",
535 G_CALLBACK(addrgather_size_allocate), NULL);
537 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
538 gtk_container_add(GTK_CONTAINER(window), vbox);
540 /* Notebook */
541 notebook = gtk_notebook_new();
542 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
543 gtk_widget_show(notebook);
544 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
545 gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
547 /* Status line */
548 hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
549 gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, 0);
550 statusbar = gtk_statusbar_new();
551 gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, 0);
553 /* Button panel */
554 gtkut_stock_button_set_create(&hbbox, &btnCancel, NULL, _("_Cancel"),
555 &btnOk, NULL, _("_OK"),
556 NULL, NULL, NULL);
557 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
559 /* Signal handlers */
560 g_signal_connect(G_OBJECT(btnOk), "clicked",
561 G_CALLBACK(addrgather_dlg_ok), NULL);
562 g_signal_connect(G_OBJECT(btnCancel), "clicked",
563 G_CALLBACK(addrgather_dlg_cancel), NULL);
565 if (!geometry.min_width) {
566 geometry.min_width = 450;
567 geometry.min_height = -1;
570 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
571 GDK_HINT_MIN_SIZE);
572 gtk_window_set_default_size(GTK_WINDOW(window), prefs_common.addrgather_width,
573 prefs_common.addrgather_height);
575 addrgather_dlg.window = window;
576 addrgather_dlg.notebook = notebook;
577 addrgather_dlg.btnOk = btnOk;
578 addrgather_dlg.btnCancel = btnCancel;
579 addrgather_dlg.statusbar = statusbar;
580 addrgather_dlg.status_cid = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar),
581 "Collect Email Address Dialog");
583 /* Create notebook pages */
584 addrgather_page_fields(PAGE_FIELDS, _("Header Fields"));
585 addrgather_page_finish(PAGE_FINISH, _("Finish"));
586 gtk_widget_show_all(addrgather_dlg.window);
590 * Harvest addresses main window.
591 * Enter: folderItem Source folder.
592 * addrIndex Address index.
593 * sourceInd Source indicator: FALSE - Folder, TRUE - Messages.
594 * msgList List of message numbers, or NULL to process folder.
595 * Return: Populated address book file, or NULL if none created.
597 #ifndef USE_ALT_ADDRBOOK
598 AddressBookFile *addrgather_dlg_execute(FolderItem *folderItem, AddressIndex *addrIndex,
599 gboolean sourceInd, GList *msgList)
600 #else
601 void addrgather_dlg_execute(FolderItem *folderItem, gboolean sourceInd, GList *msgList)
602 #endif
604 gint i;
606 #ifndef USE_ALT_ADDRBOOK
607 _harv_addressIndex_ = addrIndex;
608 _harv_addressBook_ = NULL;
609 #endif
610 _harv_messageList_ = msgList;
612 /* Create dialog */
613 if (!addrgather_dlg.window)
614 addrgather_dlg_create();
616 addrgather_dlg.done = FALSE;
618 gtk_notebook_set_current_page(GTK_NOTEBOOK(addrgather_dlg.notebook), PAGE_FIELDS);
619 addrgather_dlg.folderPath = folder_item_get_path(folderItem);
621 /* Setup some default values */
623 gtk_label_set_text(GTK_LABEL(addrgather_dlg.labelFolder), folderItem->path);
624 #ifndef USE_ALT_ADDRBOOK
625 gtk_entry_set_text(GTK_ENTRY(addrgather_dlg.entryBook), folderItem->path);
626 #endif
628 for (i = 0; i < NUM_FIELDS; i++) {
629 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(addrgather_dlg.checkHeader[i]),
630 FALSE);
631 if (g_utf8_collate(_harv_headerNames_[i], HEADER_FROM) == 0)
632 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(addrgather_dlg.checkHeader[i]),
633 TRUE);
636 gtk_widget_set_sensitive(addrgather_dlg.btnOk, TRUE);
637 gtk_widget_set_sensitive(addrgather_dlg.btnCancel, TRUE);
638 gtk_widget_grab_default(addrgather_dlg.btnOk);
640 /* Apply window title */
641 if (sourceInd) {
642 gtk_window_set_title(GTK_WINDOW(addrgather_dlg.window),
643 _("Collect email addresses from selected messages"));
644 gtk_widget_set_sensitive(addrgather_dlg.checkRecurse, FALSE);
645 } else {
646 gtk_window_set_title(GTK_WINDOW(addrgather_dlg.window),
647 _("Collect email addresses from folder"));
648 gtk_widget_set_sensitive(addrgather_dlg.checkRecurse, TRUE);
650 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(addrgather_dlg.checkRecurse), FALSE);
652 addrgather_dlg_status_show("");
653 gtk_widget_show(addrgather_dlg.window);
654 gtk_window_set_modal(GTK_WINDOW(addrgather_dlg.window), TRUE);
655 gtk_widget_grab_focus(addrgather_dlg.entryBook);
656 manage_window_set_transient(GTK_WINDOW(addrgather_dlg.window));
657 gtk_main();
659 g_free(addrgather_dlg.folderPath);
660 addrgather_dlg.folderPath = NULL;
661 gtk_widget_hide(addrgather_dlg.window);
662 gtk_window_set_modal(GTK_WINDOW(addrgather_dlg.window), FALSE);
663 #ifndef USE_ALT_ADDRBOOK
664 _harv_addressIndex_ = NULL;
666 if (addrgather_dlg.cancelled == TRUE)
667 return NULL;
669 return _harv_addressBook_;
670 #endif
673 * End of Source.