/
dialog-imap-editor.c
775 lines (616 loc) · 24.3 KB
/
dialog-imap-editor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
/********************************************************************\
* dialog-imap-editor.c -- Import Map Editor dialog *
* Copyright (C) 2015 Robert Fewell *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
#include "config.h"
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "dialog-imap-editor.h"
#include "dialog-utils.h"
#include "gnc-component-manager.h"
#include "gnc-session.h"
#include "gnc-ui-util.h"
#include "Account.h"
#define DIALOG_IMAP_CM_CLASS "dialog-imap-edit"
#define GNC_PREFS_GROUP "dialogs.imap-editor"
#define IMAP_FRAME_BAYES "import-map-bayes"
#define IMAP_FRAME "import-map"
#define IMAP_FRAME_DESC "desc"
#define IMAP_FRAME_MEMO "memo"
#define IMAP_FRAME_CSV "csv-account-map"
/** Enumeration for the tree-store */
enum GncImapColumn {SOURCE_FULL_ACC, SOURCE_ACCOUNT, BASED_ON, MATCH_STRING,
MAP_FULL_ACC, MAP_ACCOUNT, FULL_CATEGORY, COUNT, FILTER};
typedef enum
{
BAYES,
NBAYES,
ONLINE
}GncListType;
typedef struct
{
GtkWidget *dialog;
QofSession *session;
GtkWidget *view;
GncListType type;
GtkWidget *radio_bayes;
GtkWidget *radio_nbayes;
GtkWidget *radio_online;
GtkWidget *filter_button;
GtkWidget *filter_text_entry;
GtkWidget *filter_label;
GtkWidget *expand_button;
GtkWidget *collapse_button;
}ImapDialog;
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_GUI;
void gnc_imap_dialog_window_destroy_cb (GtkWidget *object, gpointer user_data);
void gnc_imap_dialog_close_cb (GtkDialog *dialog, gpointer user_data);
void gnc_imap_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data);
static void get_account_info (ImapDialog *imap_dialog);
void
gnc_imap_dialog_window_destroy_cb (GtkWidget *object, gpointer user_data)
{
ImapDialog *imap_dialog = user_data;
ENTER(" ");
gnc_unregister_gui_component_by_data (DIALOG_IMAP_CM_CLASS, imap_dialog);
if (imap_dialog->dialog)
{
gtk_widget_destroy (imap_dialog->dialog);
imap_dialog->dialog = NULL;
}
g_free (imap_dialog);
LEAVE(" ");
}
void
gnc_imap_dialog_close_cb (GtkDialog *dialog, gpointer user_data)
{
ImapDialog *imap_dialog = user_data;
ENTER(" ");
gnc_close_gui_component_by_data (DIALOG_IMAP_CM_CLASS, imap_dialog);
LEAVE(" ");
}
static gboolean
are_you_sure (ImapDialog *imap_dialog)
{
GtkWidget *dialog;
gint response;
const char *title = _("Are you sure you want to delete the entries ?");
dialog = gtk_message_dialog_new (GTK_WINDOW (imap_dialog->dialog),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_CANCEL,
"%s", title);
gtk_dialog_add_button (GTK_DIALOG(dialog), _("_Delete"), GTK_RESPONSE_ACCEPT);
gtk_widget_grab_focus (gtk_dialog_get_widget_for_response (GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT));
response = gtk_dialog_run (GTK_DIALOG(dialog));
gtk_widget_destroy (dialog);
if (response == GTK_RESPONSE_ACCEPT)
return TRUE;
else
return FALSE;
}
static void
delete_info_bayes (Account *source_account, gchar *match_string, gint depth)
{
gchar *full_category;
full_category = g_strdup_printf (IMAP_FRAME_BAYES "/%s", match_string);
gnc_account_delete_map_entry (source_account, full_category, TRUE);
full_category = g_strdup_printf (IMAP_FRAME_BAYES);
if (depth == 1) // top level, delete all below
gnc_account_delete_map_entry (source_account, full_category, FALSE);
else
gnc_account_delete_map_entry (source_account, full_category, TRUE);
}
static void
delete_info_nbayes (Account *source_account, gint depth)
{
gchar *full_category;
full_category = g_strdup_printf (IMAP_FRAME "/%s", IMAP_FRAME_DESC);
gnc_account_delete_map_entry (source_account, full_category, TRUE);
full_category = g_strdup_printf (IMAP_FRAME "/%s", IMAP_FRAME_MEMO);
gnc_account_delete_map_entry (source_account, full_category, TRUE);
full_category = g_strdup_printf (IMAP_FRAME "/%s", IMAP_FRAME_CSV);
gnc_account_delete_map_entry (source_account, full_category, TRUE);
full_category = g_strdup_printf (IMAP_FRAME);
if (depth == 1) // top level, delete all below
gnc_account_delete_map_entry (source_account, full_category, FALSE);
else
gnc_account_delete_map_entry (source_account, full_category, TRUE);
}
static void
delete_selected_row (GtkTreeModel *model, GtkTreeIter *iter, ImapDialog *imap_dialog)
{
Account *source_account = NULL;
gchar *full_source_account;
gchar *full_category;
gchar *match_string;
gtk_tree_model_get (model, iter, SOURCE_ACCOUNT, &source_account, SOURCE_FULL_ACC, &full_source_account,
FULL_CATEGORY, &full_category, MATCH_STRING, &match_string, -1);
PINFO("Account is '%s', Full Category is '%s', Match String is '%s'", full_source_account, full_category, match_string);
if (source_account != NULL)
{
GtkTreePath *tree_path;
gint depth;
// Get the level we are at in the tree-model
tree_path = gtk_tree_model_get_path (model, iter);
depth = gtk_tree_path_get_depth (tree_path);
gtk_tree_path_free (tree_path);
gnc_account_delete_map_entry (source_account, full_category, FALSE);
if (imap_dialog->type == BAYES)
delete_info_bayes (source_account, match_string, depth);
if (imap_dialog->type == NBAYES)
delete_info_nbayes (source_account, depth);
}
else
g_free (full_category);
g_free (match_string);
g_free (full_source_account);
}
static void
gnc_imap_dialog_delete (ImapDialog *imap_dialog)
{
GList *list, *row;
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreeSelection *selection;
model = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(imap_dialog->view));
list = gtk_tree_selection_get_selected_rows (selection, &model);
// Make sure we have some rows selected
if (g_list_length (list) == 0)
return;
// Are we sure we want to delete the entries
if (are_you_sure (imap_dialog) == FALSE)
return;
// reverse list
list = g_list_reverse (list);
// Walk the list
for (row = g_list_first (list); row; row = g_list_next (row))
{
if (gtk_tree_model_get_iter (model, &iter, row->data))
delete_selected_row (model, &iter, imap_dialog);
}
g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
g_list_free (list);
get_account_info (imap_dialog);
}
void
gnc_imap_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
{
ImapDialog *imap_dialog = user_data;
switch (response_id)
{
case GTK_RESPONSE_APPLY:
gnc_imap_dialog_delete (imap_dialog);
return;
case GTK_RESPONSE_CLOSE:
default:
gnc_close_gui_component_by_data (DIALOG_IMAP_CM_CLASS, imap_dialog);
return;
}
}
static gboolean
filter_test_and_move_next (GtkTreeModel *model, GtkTreeIter *iter, ImapDialog *imap_dialog)
{
GtkTreePath *tree_path;
gint depth;
gboolean valid;
const gchar *filter_text;
const gchar *match_string;
const gchar *map_full_acc;
// Read the row
gtk_tree_model_get (model, iter, MATCH_STRING, &match_string, MAP_FULL_ACC, &map_full_acc, -1);
filter_text = gtk_entry_get_text (GTK_ENTRY(imap_dialog->filter_text_entry));
// Get the level we are at in the tree-model
tree_path = gtk_tree_model_get_path (model, iter);
depth = gtk_tree_path_get_depth (tree_path);
// Reset filter to TRUE
gtk_tree_store_set (GTK_TREE_STORE(model), iter, FILTER, TRUE, -1);
// Check for a filter_text entry
if (g_strcmp0 (filter_text, "") != 0)
{
if (match_string != NULL) // Check for match_string is not NULL, valid line
{
if ((g_strrstr (match_string, filter_text) == NULL) &&
(g_strrstr (map_full_acc, filter_text) == NULL ))
gtk_tree_store_set (GTK_TREE_STORE(model), iter, FILTER, FALSE, -1);
else
gtk_tree_view_expand_to_path (GTK_TREE_VIEW(imap_dialog->view), tree_path);
}
}
// Select next entry based on path
if (depth == 1)
gtk_tree_path_down (tree_path);
else
{
gtk_tree_path_next (tree_path);
if (!gtk_tree_model_get_iter (model, iter, tree_path))
{
gtk_tree_path_prev (tree_path);
gtk_tree_path_up (tree_path);
gtk_tree_path_next (tree_path);
}
}
valid = gtk_tree_model_get_iter (model, iter, tree_path);
gtk_tree_path_free (tree_path);
return valid;
}
static void
filter_button_cb (GtkButton *button, ImapDialog *imap_dialog)
{
GtkTreeModel *model, *filter;
GtkTreeIter iter;
gboolean valid;
filter = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(filter));
// Collapse all nodes
gtk_tree_view_collapse_all (GTK_TREE_VIEW(imap_dialog->view));
valid = gtk_tree_model_get_iter_first (model, &iter);
while (valid)
{
valid = filter_test_and_move_next (model, &iter, imap_dialog);
}
}
static void
expand_button_cb (GtkButton *button, ImapDialog *imap_dialog)
{
// Clear the filter
gtk_entry_set_text (GTK_ENTRY(imap_dialog->filter_text_entry), "");
filter_button_cb (button, imap_dialog);
gtk_tree_view_expand_all (GTK_TREE_VIEW(imap_dialog->view));
}
static void
collapse_button_cb (GtkButton *button, ImapDialog *imap_dialog)
{
// Clear the filter
gtk_entry_set_text (GTK_ENTRY(imap_dialog->filter_text_entry), "");
filter_button_cb (button, imap_dialog);
gtk_tree_view_collapse_all (GTK_TREE_VIEW(imap_dialog->view));
}
static void
list_type_selected_cb (GtkToggleButton* button, ImapDialog *imap_dialog)
{
GncListType type;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(imap_dialog->radio_bayes)))
type = BAYES;
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(imap_dialog->radio_nbayes)))
type = NBAYES;
else
type = ONLINE;
// Lets do this only on change of list type
if (type != imap_dialog->type)
{
imap_dialog->type = type;
get_account_info (imap_dialog);
}
}
static void
show_count_column (ImapDialog *imap_dialog, gboolean show)
{
GtkTreeViewColumn *tree_column;
// Show Count Column
tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW(imap_dialog->view), 4);
gtk_tree_view_column_set_visible (tree_column, show);
// Hide Based on Column
tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW(imap_dialog->view), 1);
gtk_tree_view_column_set_visible (tree_column, !show);
gtk_tree_view_columns_autosize (GTK_TREE_VIEW(imap_dialog->view));
}
static void
add_to_store (GtkTreeModel *model, GtkTreeIter *iter, const gchar *text, GncImapInfo *imapInfo)
{
gchar *fullname = NULL;
gchar *map_fullname = NULL;
fullname = gnc_account_get_full_name (imapInfo->source_account);
// Do we have a valid map account
if (imapInfo->map_account == NULL)
map_fullname = g_strdup (_("Map Account NOT found"));
else
map_fullname = gnc_account_get_full_name (imapInfo->map_account);
PINFO("Add to Store: Source Acc '%s', Match '%s', Map Acc '%s'", fullname, imapInfo->match_string, map_fullname);
gtk_tree_store_set (GTK_TREE_STORE(model), iter,
SOURCE_FULL_ACC, fullname, SOURCE_ACCOUNT, imapInfo->source_account,
BASED_ON, text,
MATCH_STRING, imapInfo->match_string,
MAP_FULL_ACC, map_fullname, MAP_ACCOUNT, imapInfo->map_account,
FULL_CATEGORY, imapInfo->full_category, COUNT, imapInfo->count,
FILTER, TRUE, -1);
g_free (fullname);
g_free (map_fullname);
}
static void
get_imap_info (Account *acc, const gchar *category, GtkTreeModel *model, const gchar *text)
{
GtkTreeIter toplevel, child;
GList *imap_list, *node;
gchar *acc_name = NULL;
acc_name = gnc_account_get_full_name (acc);
PINFO("Source Acc '%s', Based on '%s', Path Head '%s'", acc_name, text, category);
if (category == NULL) // For Bayesian, category is NULL
imap_list = gnc_account_imap_get_info_bayes (acc);
else
imap_list = gnc_account_imap_get_info (acc, category);
if (g_list_length (imap_list) > 0)
{
PINFO("List length is %d", g_list_length (imap_list));
// Add top level entry of Source full Account and Based on.
gtk_tree_store_append (GTK_TREE_STORE(model), &toplevel, NULL);
gtk_tree_store_set (GTK_TREE_STORE(model), &toplevel,
SOURCE_ACCOUNT, acc, SOURCE_FULL_ACC, acc_name, BASED_ON, text, FILTER, TRUE, -1);
for (node = imap_list; node; node = g_list_next (node))
{
GncImapInfo *imapInfo = node->data;
// First add a child entry and pass iter to add_to_store
gtk_tree_store_append (GTK_TREE_STORE(model), &child, &toplevel);
add_to_store (model, &child, text, imapInfo);
// Free the members and structure
g_free (imapInfo->category_head);
g_free (imapInfo->full_category);
g_free (imapInfo->match_string);
g_free (imapInfo->count);
g_free (imapInfo);
}
}
g_free (acc_name);
g_list_free (imap_list); // Free the List
}
static void
show_first_row (ImapDialog *imap_dialog)
{
GtkTreeModel *model, *filter;
GtkTreeIter iter;
filter = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(filter));
// See if there are any entries
if (gtk_tree_model_get_iter_first (model, &iter))
{
GtkTreePath *path;
path = gtk_tree_path_new_first (); // Set Path to first entry
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(imap_dialog->view), path, NULL, TRUE, 0.0, 0.0);
gtk_tree_path_free (path);
}
}
static void
get_account_info_bayes (GList *accts, GtkTreeModel *model)
{
GList *ptr;
/* Go through list of accounts */
for (ptr = accts; ptr; ptr = g_list_next (ptr))
{
Account *acc = ptr->data;
get_imap_info (acc, NULL, model, _("Bayesian"));
}
}
static void
get_account_info_nbayes (GList *accts, GtkTreeModel *model)
{
GList *ptr;
/* Go through list of accounts */
for (ptr = accts; ptr; ptr = g_list_next (ptr))
{
Account *acc = ptr->data;
// Description
get_imap_info (acc, IMAP_FRAME_DESC, model, _("Description Field"));
// Memo
get_imap_info (acc, IMAP_FRAME_MEMO, model, _("Memo Field"));
// CSV Account Map
get_imap_info (acc, IMAP_FRAME_CSV, model, _("CSV Account Map"));
}
}
static void
get_account_info_online (GList *accts, GtkTreeModel *model)
{
GList *ptr;
GtkTreeIter toplevel;
GncImapInfo imapInfo;
/* Go through list of accounts */
for (ptr = accts; ptr; ptr = g_list_next (ptr))
{
gchar *text = NULL;
Account *acc = ptr->data;
// Save source account
imapInfo.source_account = acc;
imapInfo.full_category = "online_id";
text = gnc_account_get_map_entry (acc, imapInfo.full_category);
if (text != NULL)
{
if (g_strcmp0 (text, "") == 0)
imapInfo.map_account = NULL;
else
imapInfo.map_account = imapInfo.source_account;
imapInfo.match_string = text;
imapInfo.count = " ";
// Add top level entry and pass iter to add_to_store
gtk_tree_store_append (GTK_TREE_STORE(model), &toplevel, NULL);
add_to_store (model, &toplevel, _("Online Id"), &imapInfo);
}
g_free (text);
}
}
static void
show_filter_option (ImapDialog *imap_dialog, gboolean show)
{
if (show)
{
gtk_widget_show (imap_dialog->filter_text_entry);
gtk_widget_show (imap_dialog->filter_button);
gtk_widget_show (imap_dialog->filter_label);
gtk_widget_show (imap_dialog->expand_button);
gtk_widget_show (imap_dialog->collapse_button);
}
else
{
gtk_widget_hide (imap_dialog->filter_text_entry);
gtk_widget_hide (imap_dialog->filter_button);
gtk_widget_hide (imap_dialog->filter_label);
gtk_widget_hide (imap_dialog->expand_button);
gtk_widget_hide (imap_dialog->collapse_button);
}
}
static void
get_account_info (ImapDialog *imap_dialog)
{
Account *root;
GList *accts;
GtkTreeModel *model, *filter;
GtkTreeIter iter;
/* Get list of Accounts */
root = gnc_book_get_root_account (gnc_get_current_book());
accts = gnc_account_get_descendants_sorted (root);
filter = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(filter));
// Clear the tree store
gtk_tree_store_clear (GTK_TREE_STORE(model));
// Clear the filter
gtk_entry_set_text (GTK_ENTRY(imap_dialog->filter_text_entry), "");
// Hide Count Column
show_count_column (imap_dialog, FALSE);
// Show Filter Option
show_filter_option (imap_dialog, TRUE);
if (imap_dialog->type == BAYES)
{
get_account_info_bayes (accts, model);
// Show Count Column
show_count_column (imap_dialog, TRUE);
}
else if (imap_dialog->type == NBAYES)
get_account_info_nbayes (accts, model);
else if (imap_dialog->type == ONLINE)
{
// Hide Filter Option
show_filter_option (imap_dialog, FALSE);
get_account_info_online (accts, model);
}
// if there are any entries, show first row
show_first_row (imap_dialog);
g_list_free (accts);
}
static void
gnc_imap_dialog_create (GtkWidget *parent, ImapDialog *imap_dialog)
{
GtkWidget *dialog;
GtkBuilder *builder;
GtkTreeModel *filter;
GtkTreeSelection *selection;
ENTER(" ");
builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "dialog-imap-editor.glade", "tree-store");
gnc_builder_add_from_file (builder, "dialog-imap-editor.glade", "treemodelfilter");
gnc_builder_add_from_file (builder, "dialog-imap-editor.glade", "Import Map Dialog");
dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Import Map Dialog"));
imap_dialog->dialog = dialog;
imap_dialog->session = gnc_get_current_session();
imap_dialog->type = BAYES;
/* parent */
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(parent));
/* Connect the radio buttons...*/
imap_dialog->radio_bayes = GTK_WIDGET(gtk_builder_get_object (builder, "radio-bayes"));
imap_dialog->radio_nbayes = GTK_WIDGET(gtk_builder_get_object (builder, "radio-nbayes"));
imap_dialog->radio_online = GTK_WIDGET(gtk_builder_get_object (builder, "radio-online"));
g_signal_connect (imap_dialog->radio_bayes, "toggled",
G_CALLBACK(list_type_selected_cb), (gpointer)imap_dialog);
g_signal_connect (imap_dialog->radio_nbayes, "toggled",
G_CALLBACK(list_type_selected_cb), (gpointer)imap_dialog);
imap_dialog->filter_text_entry = GTK_WIDGET(gtk_builder_get_object (builder, "filter-text-entry"));
imap_dialog->filter_label = GTK_WIDGET(gtk_builder_get_object (builder, "filter-label"));
imap_dialog->filter_button = GTK_WIDGET(gtk_builder_get_object (builder, "filter-button"));
g_signal_connect (imap_dialog->filter_button, "clicked",
G_CALLBACK(filter_button_cb), (gpointer)imap_dialog);
imap_dialog->expand_button = GTK_WIDGET(gtk_builder_get_object (builder, "expand-button"));
g_signal_connect (imap_dialog->expand_button, "clicked",
G_CALLBACK(expand_button_cb), (gpointer)imap_dialog);
imap_dialog->collapse_button = GTK_WIDGET(gtk_builder_get_object (builder, "collapse-button"));
g_signal_connect (imap_dialog->collapse_button, "clicked",
G_CALLBACK(collapse_button_cb), (gpointer)imap_dialog);
imap_dialog->view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));
// Set filter column
filter = gtk_tree_view_get_model (GTK_TREE_VIEW(imap_dialog->view));
gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER(filter), FILTER);
/* Enable alternative line colors */
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(imap_dialog->view), TRUE);
/* default to 'close' button */
gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(imap_dialog->view));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, imap_dialog);
g_object_unref (G_OBJECT(builder));
gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(imap_dialog->dialog));
get_account_info (imap_dialog);
LEAVE(" ");
}
static void
close_handler (gpointer user_data)
{
ImapDialog *imap_dialog = user_data;
ENTER(" ");
gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(imap_dialog->dialog));
gtk_widget_destroy (GTK_WIDGET(imap_dialog->dialog));
LEAVE(" ");
}
static void
refresh_handler (GHashTable *changes, gpointer user_data)
{
ENTER(" ");
LEAVE(" ");
}
static gboolean
show_handler (const char *klass, gint component_id,
gpointer user_data, gpointer iter_data)
{
ImapDialog *imap_dialog = user_data;
ENTER(" ");
if (!imap_dialog)
{
LEAVE("No data strucure");
return(FALSE);
}
gtk_window_present (GTK_WINDOW(imap_dialog->dialog));
LEAVE(" ");
return(TRUE);
}
/********************************************************************\
* gnc_imap_dialog *
* opens a window showing Bayesian and Non-Bayesian information *
* *
* Args: parent - the parent of the window to be created *
* Return: nothing *
\********************************************************************/
void
gnc_imap_dialog (GtkWidget *parent)
{
ImapDialog *imap_dialog;
gint component_id;
ENTER(" ");
if (gnc_forall_gui_components (DIALOG_IMAP_CM_CLASS, show_handler, NULL))
{
LEAVE("Existing dialog raised");
return;
}
imap_dialog = g_new0 (ImapDialog, 1);
gnc_imap_dialog_create (parent, imap_dialog);
component_id = gnc_register_gui_component (DIALOG_IMAP_CM_CLASS,
refresh_handler, close_handler,
imap_dialog);
gnc_gui_component_set_session (component_id, imap_dialog->session);
gtk_widget_show (imap_dialog->dialog);
LEAVE(" ");
}