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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Authors: Jeffrey Stedfast <fejj@ximian.com>
*
* Copyright 2002-2003 Ximian, Inc. (www.ximian.com)
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include "em-mailer-prefs.h"
#include "em-format.h"
#include <libedataserver/e-iconv.h>
#include <gtkhtml/gtkhtml-properties.h>
#include <libxml/tree.h>
#include "misc/e-charset-picker.h"
#include <bonobo/bonobo-generic-factory.h>
#include <gtk/gtkcolorbutton.h>
#include <gtk/gtkfilechooserbutton.h>
#include <gtk/gtkfontbutton.h>
#include <glade/glade.h>
#include <gconf/gconf-client.h>
#include <gtk/gtkentry.h>
#include <gtk/gtktreeview.h>
#include <gtk/gtkliststore.h>
#include <gtk/gtktreeselection.h>
#include <gtk/gtkcellrenderertoggle.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkspinbutton.h>
#include <gtk/gtktogglebutton.h>
#include <gtk/gtkoptionmenu.h>
#include <gtk/gtkmenuitem.h>
#include "e-util/e-util-private.h"
#include "mail-config.h"
#include "em-junk-hook.h"
#include "em-config.h"
#include "mail-session.h"
static void em_mailer_prefs_class_init (EMMailerPrefsClass *class);
static void em_mailer_prefs_init (EMMailerPrefs *dialog);
static void em_mailer_prefs_finalise (GObject *obj);
static GtkVBoxClass *parent_class = NULL;
enum {
HEADER_LIST_NAME_COLUMN, /* displayable name of the header (may be a translation) */
HEADER_LIST_ENABLED_COLUMN, /* is the header enabled? */
HEADER_LIST_IS_DEFAULT_COLUMN, /* is this header a default header, eg From: */
HEADER_LIST_HEADER_COLUMN, /* the real name of this header */
HEADER_LIST_N_COLUMNS,
};
static GType col_types[] = {
G_TYPE_STRING,
G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN,
G_TYPE_STRING
};
/* temporarily copied from em-format.c */
static const char *default_headers[] = {
N_("From"),
N_("Reply-To"),
N_("To"),
N_("Cc"),
N_("Bcc"),
N_("Subject"),
N_("Date"),
N_("Newsgroups"),
"x-evolution-mailer", /* DO NOT translate */
};
#define EM_FORMAT_HEADER_XMAILER "x-evolution-mailer"
/* for empty trash on exit frequency */
static const struct {
const char *label;
int days;
} empty_trash_frequency[] = {
{ N_("Every time"), 0 },
{ N_("Once per day"), 1 },
{ N_("Once per week"), 7 },
{ N_("Once per month"), 30 },
};
GtkType
em_mailer_prefs_get_type (void)
{
static GType type = 0;
if (!type) {
GTypeInfo type_info = {
sizeof (EMMailerPrefsClass),
NULL, NULL,
(GClassInitFunc) em_mailer_prefs_class_init,
NULL, NULL,
sizeof (EMMailerPrefs),
0,
(GInstanceInitFunc) em_mailer_prefs_init,
};
type = g_type_register_static (gtk_vbox_get_type (), "EMMailerPrefs", &type_info, 0);
}
return type;
}
static void
em_mailer_prefs_class_init (EMMailerPrefsClass *klass)
{
GObjectClass *object_class;
object_class = (GObjectClass *) klass;
parent_class = g_type_class_ref (gtk_vbox_get_type ());
object_class->finalize = em_mailer_prefs_finalise;
}
static void
em_mailer_prefs_init (EMMailerPrefs *preferences)
{
preferences->gconf = mail_config_get_gconf_client ();
}
static void
em_mailer_prefs_finalise (GObject *obj)
{
EMMailerPrefs *prefs = (EMMailerPrefs *) obj;
g_object_unref (prefs->gui);
((GObjectClass *)(parent_class))->finalize (obj);
}
static void
color_button_set_color (GtkColorButton *color_button, const gchar *spec)
{
GdkColor color;
if (gdk_color_parse (spec, &color))
gtk_color_button_set_color (color_button, &color);
}
static void
citation_color_set (GtkColorButton *color_button, EMMailerPrefs *prefs)
{
GdkColor color;
gchar spec[16];
gtk_color_button_get_color (color_button, &color);
g_snprintf (spec, sizeof (spec), "#%04x%04x%04x",
color.red, color.green, color.blue);
gconf_client_set_string (prefs->gconf,
"/apps/evolution/mail/display/citation_colour",
spec, NULL);
}
static void
labels_changed (EMMailerPrefs *prefs)
{
GSList *l, *n, *list = NULL;
const char *cstring;
char *string;
int i;
for (i = 4; i >= 0; i--) {
GdkColor color;
cstring = gtk_entry_get_text (prefs->labels[i].name);
gtk_color_button_get_color (prefs->labels[i].color, &color);
string = g_strdup_printf ("%s:#%04x%04x%04x", cstring,
color.red, color.green, color.blue);
list = g_slist_prepend (list, string);
}
gconf_client_set_list (prefs->gconf, "/apps/evolution/mail/labels", GCONF_VALUE_STRING, list, NULL);
l = list;
while (l != NULL) {
n = l->next;
g_free (l->data);
g_slist_free_1 (l);
l = n;
}
}
static void
label_color_set (GtkWidget *widget, guint r, guint g, guint b, guint a, EMMailerPrefs *prefs)
{
labels_changed (prefs);
}
static void
label_entry_changed (GtkEntry *entry, EMMailerPrefs *prefs)
{
labels_changed (prefs);
}
static void
restore_labels_clicked (GtkWidget *widget, gpointer user_data)
{
EMMailerPrefs *prefs = (EMMailerPrefs *) user_data;
int i;
for (i = 0; i < 5; i++) {
gtk_entry_set_text (prefs->labels[i].name, _(label_defaults[i].name));
color_button_set_color (prefs->labels[i].color, label_defaults[i].colour);
atk_object_set_name(gtk_widget_get_accessible((GtkWidget *)prefs->labels[i].color), _(label_defaults[i].name));
}
}
static void
emmp_header_remove_sensitivity (EMMailerPrefs *prefs)
{
GtkTreeIter iter;
GtkTreeSelection *selection = gtk_tree_view_get_selection (prefs->header_list);
gboolean is_default;
/* remove button should be sensitive if the currenlty selected entry in the list view
is not a default header. if there are no entries, or none is selected, it should be
disabled
*/
if (gtk_tree_selection_get_selected (selection, NULL, &iter)) {
gtk_tree_model_get (GTK_TREE_MODEL (prefs->header_list_store), &iter,
HEADER_LIST_IS_DEFAULT_COLUMN, &is_default,
-1);
if (is_default)
gtk_widget_set_sensitive (GTK_WIDGET (prefs->remove_header), FALSE);
else
gtk_widget_set_sensitive (GTK_WIDGET (prefs->remove_header), TRUE);
} else {
gtk_widget_set_sensitive (GTK_WIDGET (prefs->remove_header), FALSE);
}
}
static gboolean
emmp_header_is_valid (const char *header)
{
const char *p = header;
if (header[0] == 0)
return FALSE;
while (*p) {
if ((*p == ':') || (*p == ' '))
return FALSE;
p++;
}
return TRUE;
}
static void
emmp_header_add_sensitivity (EMMailerPrefs *prefs)
{
const char *entry_contents;
GtkTreeIter iter;
gboolean valid;
/* the add header button should be sensitive if the text box contains
a valid header string, that is not a duplicate with something already
in the list view
*/
entry_contents = gtk_entry_get_text (GTK_ENTRY (prefs->entry_header));
if (!emmp_header_is_valid (entry_contents)) {
gtk_widget_set_sensitive (GTK_WIDGET (prefs->add_header), FALSE);
return;
}
/* check if this is a duplicate */
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (prefs->header_list_store), &iter);
while (valid) {
char *header_name;
gtk_tree_model_get (GTK_TREE_MODEL (prefs->header_list_store), &iter,
HEADER_LIST_HEADER_COLUMN, &header_name,
-1);
if (g_ascii_strcasecmp (header_name, entry_contents) == 0) {
gtk_widget_set_sensitive (GTK_WIDGET (prefs->add_header), FALSE);
return;
}
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (prefs->header_list_store), &iter);
}
gtk_widget_set_sensitive (GTK_WIDGET (prefs->add_header), TRUE);
}
static void
emmp_save_headers (EMMailerPrefs *prefs)
{
GSList *header_list;
GtkTreeIter iter;
gboolean valid;
/* Headers */
header_list = NULL;
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (prefs->header_list_store), &iter);
while (valid) {
struct _EMMailerPrefsHeader h;
gboolean enabled;
char *xml;
gtk_tree_model_get (GTK_TREE_MODEL (prefs->header_list_store), &iter,
HEADER_LIST_HEADER_COLUMN, &h.name,
HEADER_LIST_ENABLED_COLUMN, &enabled,
-1);
h.enabled = enabled;
if ((xml = em_mailer_prefs_header_to_xml (&h)))
header_list = g_slist_append (header_list, xml);
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (prefs->header_list_store), &iter);
}
gconf_client_set_list (prefs->gconf, "/apps/evolution/mail/display/headers", GCONF_VALUE_STRING, header_list, NULL);
g_slist_foreach (header_list, (GFunc) g_free, NULL);
g_slist_free (header_list);
}
static void
emmp_header_list_enabled_toggled (GtkCellRendererToggle *cell, const char *path_string, EMMailerPrefs *prefs)
{
GtkTreeModel *model = GTK_TREE_MODEL (prefs->header_list_store);
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
GtkTreeIter iter;
int enabled;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, HEADER_LIST_ENABLED_COLUMN, &enabled, -1);
enabled = !enabled;
gtk_list_store_set (GTK_LIST_STORE (model), &iter, HEADER_LIST_ENABLED_COLUMN,
enabled, -1);
gtk_tree_path_free (path);
emmp_save_headers (prefs);
}
static void
emmp_header_add_header (GtkWidget *widget, EMMailerPrefs *prefs)
{
GtkTreeModel *model = GTK_TREE_MODEL (prefs->header_list_store);
GtkTreeIter iter;
const gchar *text = gtk_entry_get_text (prefs->entry_header);
g_strstrip ((gchar *)text);
if (text && (strlen (text)>0)) {
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
HEADER_LIST_NAME_COLUMN, text,
HEADER_LIST_ENABLED_COLUMN, TRUE,
HEADER_LIST_HEADER_COLUMN, text,
HEADER_LIST_IS_DEFAULT_COLUMN, FALSE,
-1);
gtk_entry_set_text (prefs->entry_header, "");
emmp_header_remove_sensitivity (prefs);
emmp_header_add_sensitivity (prefs);
emmp_save_headers (prefs);
}
}
static void
emmp_header_remove_header (GtkWidget *button, gpointer user_data)
{
EMMailerPrefs *prefs = (EMMailerPrefs *) user_data;
GtkTreeModel *model = GTK_TREE_MODEL (prefs->header_list_store);
GtkTreeSelection *selection = gtk_tree_view_get_selection (prefs->header_list);
GtkTreeIter iter;
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
emmp_header_remove_sensitivity (prefs);
emmp_save_headers (prefs);
}
static void
emmp_header_list_row_selected (GtkTreeSelection *selection, gpointer user_data)
{
EMMailerPrefs *prefs = (EMMailerPrefs *) user_data;
emmp_header_remove_sensitivity (prefs);
}
static void
emmp_header_entry_changed (GtkWidget *entry, gpointer user_data)
{
EMMailerPrefs *prefs = (EMMailerPrefs *) user_data;
emmp_header_add_sensitivity (prefs);
}
static void
mark_seen_timeout_changed (GtkSpinButton *spin, EMMailerPrefs *prefs)
{
int timeout;
timeout = (int) (gtk_spin_button_get_value (prefs->timeout) * 1000.0);
gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/display/mark_seen_timeout", timeout, NULL);
}
static void
address_compress_count_changed (GtkSpinButton *spin, EMMailerPrefs *prefs)
{
int count;
count = (int) gtk_spin_button_get_value (prefs->address_count);
gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/display/address_count", count, NULL);
}
static void
mlimit_count_changed (GtkSpinButton *spin, EMMailerPrefs *prefs)
{
int count;
count = (int) gtk_spin_button_get_value (prefs->mlimit_count);
gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/display/message_text_part_limit", count, NULL);
}
static void
spin_button_init (EMMailerPrefs *prefs, GtkSpinButton *spin, const char *key, float div, GCallback value_changed)
{
GError *err = NULL;
double min, max;
char *mkey, *p;
int val;
gtk_spin_button_get_range (spin, &min, &max);
mkey = g_alloca (strlen (key) + 5);
p = g_stpcpy (mkey, key);
*p++ = '_';
/* see if the admin locked down the min value */
strcpy (p, "min");
val = gconf_client_get_int (prefs->gconf, mkey, &err);
if (err == NULL)
g_clear_error (&err);
else
min = (1.0 * val) / div;
/* see if the admin locked down the max value */
strcpy (p, "max");
val = gconf_client_get_int (prefs->gconf, mkey, &err);
if (err == NULL)
g_clear_error (&err);
else
max = (1.0 * val) / div;
gtk_spin_button_set_range (spin, min, max);
/* get the value */
val = gconf_client_get_int (prefs->gconf, key, NULL);
gtk_spin_button_set_value (spin, (1.0 * val) / div);
if (value_changed) {
g_object_set_data ((GObject *) spin, "key", (void *) key);
g_signal_connect (spin, "value-changed", value_changed, prefs);
}
if (!gconf_client_key_is_writable (prefs->gconf, key, NULL))
gtk_widget_set_sensitive ((GtkWidget *) spin, FALSE);
}
static void
toggle_button_toggled (GtkToggleButton *toggle, EMMailerPrefs *prefs)
{
const char *key;
key = g_object_get_data ((GObject *) toggle, "key");
gconf_client_set_bool (prefs->gconf, key, gtk_toggle_button_get_active (toggle), NULL);
}
static void
photo_toggle_changed (GtkToggleButton *toggle, EMMailerPrefs *prefs)
{
toggle_button_toggled (toggle, prefs);
if (gtk_toggle_button_get_active (toggle))
gtk_widget_set_sensitive ((GtkWidget *) prefs->photo_local, TRUE);
else
gtk_widget_set_sensitive ((GtkWidget *) prefs->photo_local, FALSE);
}
#if 0
// not used at the moment, commenting out
static void
toggle_button_toggled_not (GtkToggleButton *toggle, EMMailerPrefs *prefs)
{
const char *key;
key = g_object_get_data ((GObject *) toggle, "key");
gconf_client_set_bool (prefs->gconf, key, !gtk_toggle_button_get_active (toggle), NULL);
}
#endif
static void
custom_font_changed (GtkToggleButton *toggle, EMMailerPrefs *prefs)
{
gboolean use_custom;
use_custom = !gtk_toggle_button_get_active (toggle);
gtk_widget_set_sensitive (GTK_WIDGET (prefs->font_fixed), use_custom);
gtk_widget_set_sensitive (GTK_WIDGET (prefs->font_variable), use_custom);
gconf_client_set_bool (prefs->gconf, "/apps/evolution/mail/display/fonts/use_custom", use_custom, NULL);
}
static void
font_changed (GtkFontButton *font_button, EMMailerPrefs *prefs)
{
const gchar *key;
const gchar *font_name;
key = g_object_get_data (G_OBJECT (font_button), "key");
font_name = gtk_font_button_get_font_name (font_button);
gconf_client_set_string (prefs->gconf, key, font_name, NULL);
}
static void
toggle_button_init (EMMailerPrefs *prefs, GtkToggleButton *toggle, int not, const char *key, GCallback toggled)
{
gboolean bool;
bool = gconf_client_get_bool (prefs->gconf, key, NULL);
gtk_toggle_button_set_active (toggle, not ? !bool : bool);
if (toggled) {
g_object_set_data ((GObject *) toggle, "key", (void *) key);
g_signal_connect (toggle, "toggled", toggled, prefs);
}
if (!gconf_client_key_is_writable (prefs->gconf, key, NULL))
gtk_widget_set_sensitive ((GtkWidget *) toggle, FALSE);
}
static void
charset_activate (GtkWidget *item, EMMailerPrefs *prefs)
{
GtkWidget *menu;
char *string;
menu = gtk_option_menu_get_menu (prefs->charset);
if (!(string = e_charset_picker_get_charset (menu)))
string = g_strdup (e_iconv_locale_charset ());
gconf_client_set_string (prefs->gconf, "/apps/evolution/mail/display/charset", string, NULL);
g_free (string);
}
static void
charset_menu_init (EMMailerPrefs *prefs)
{
GtkWidget *menu, *item;
GList *items;
char *buf;
buf = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/display/charset", NULL);
menu = e_charset_picker_new (buf && *buf ? buf : e_iconv_locale_charset ());
gtk_option_menu_set_menu (prefs->charset, GTK_WIDGET (menu));
g_free (buf);
items = GTK_MENU_SHELL (menu)->children;
while (items) {
item = items->data;
g_signal_connect (item, "activate", G_CALLBACK (charset_activate), prefs);
items = items->next;
}
if (!gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/display/charset", NULL))
gtk_widget_set_sensitive ((GtkWidget *) prefs->charset, FALSE);
}
static void
trash_days_activate (GtkWidget *item, EMMailerPrefs *prefs)
{
int days;
days = GPOINTER_TO_INT (g_object_get_data ((GObject *) item, "days"));
gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/trash/empty_on_exit_days", days, NULL);
}
static void
emmp_empty_trash_init (EMMailerPrefs *prefs)
{
int locked, days, hist = 0, i;
GtkWidget *menu, *item;
toggle_button_init (prefs, prefs->empty_trash, FALSE,
"/apps/evolution/mail/trash/empty_on_exit",
G_CALLBACK (toggle_button_toggled));
days = gconf_client_get_int(prefs->gconf, "/apps/evolution/mail/trash/empty_on_exit_days", NULL);
menu = gtk_menu_new();
for (i = 0; i < G_N_ELEMENTS (empty_trash_frequency); i++) {
if (days >= empty_trash_frequency[i].days)
hist = i;
item = gtk_menu_item_new_with_label (_(empty_trash_frequency[i].label));
g_object_set_data ((GObject *) item, "days", GINT_TO_POINTER (empty_trash_frequency[i].days));
g_signal_connect (item, "activate", G_CALLBACK (trash_days_activate), prefs);
gtk_widget_show (item);
gtk_menu_shell_append((GtkMenuShell *)menu, item);
}
gtk_widget_show(menu);
gtk_option_menu_set_menu((GtkOptionMenu *)prefs->empty_trash_days, menu);
gtk_option_menu_set_history((GtkOptionMenu *)prefs->empty_trash_days, hist);
locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/trash/empty_on_exit_days", NULL);
gtk_widget_set_sensitive ((GtkWidget *) prefs->empty_trash_days, !locked);
}
static void
junk_days_activate (GtkWidget *item, EMMailerPrefs *prefs)
{
int days;
days = GPOINTER_TO_INT (g_object_get_data ((GObject *) item, "days"));
gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/junk/empty_on_exit_days", days, NULL);
}
static void
emmp_empty_junk_init (EMMailerPrefs *prefs)
{
int locked, days, hist = 0, i;
GtkWidget *menu, *item;
toggle_button_init (prefs, prefs->empty_junk, FALSE,
"/apps/evolution/mail/junk/empty_on_exit",
G_CALLBACK (toggle_button_toggled));
days = gconf_client_get_int(prefs->gconf, "/apps/evolution/mail/junk/empty_on_exit_days", NULL);
menu = gtk_menu_new();
for (i = 0; i < G_N_ELEMENTS (empty_trash_frequency); i++) {
if (days >= empty_trash_frequency[i].days)
hist = i;
item = gtk_menu_item_new_with_label (_(empty_trash_frequency[i].label));
g_object_set_data ((GObject *) item, "days", GINT_TO_POINTER (empty_trash_frequency[i].days));
g_signal_connect (item, "activate", G_CALLBACK (junk_days_activate), prefs);
gtk_widget_show (item);
gtk_menu_shell_append((GtkMenuShell *)menu, item);
}
gtk_widget_show(menu);
gtk_option_menu_set_menu((GtkOptionMenu *)prefs->empty_junk_days, menu);
gtk_option_menu_set_history((GtkOptionMenu *)prefs->empty_junk_days, hist);
locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/junk/empty_on_exit_days", NULL);
gtk_widget_set_sensitive ((GtkWidget *) prefs->empty_junk_days, !locked);
}
static void
http_images_changed (GtkWidget *widget, EMMailerPrefs *prefs)
{
int when;
if (gtk_toggle_button_get_active (prefs->images_always))
when = MAIL_CONFIG_HTTP_ALWAYS;
else if (gtk_toggle_button_get_active (prefs->images_sometimes))
when = MAIL_CONFIG_HTTP_SOMETIMES;
else
when = MAIL_CONFIG_HTTP_NEVER;
gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/display/load_http_images", when, NULL);
}
static void
notify_type_changed (GtkWidget *widget, EMMailerPrefs *prefs)
{
int type;
if (gtk_toggle_button_get_active (prefs->notify_not))
type = MAIL_CONFIG_NOTIFY_NOT;
else if (gtk_toggle_button_get_active (prefs->notify_beep))
type = MAIL_CONFIG_NOTIFY_BEEP;
else
type = MAIL_CONFIG_NOTIFY_PLAY_SOUND;
if (type == MAIL_CONFIG_NOTIFY_PLAY_SOUND)
gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_sound_file, TRUE);
else
gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_sound_file, FALSE);
gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/notify/type", type, NULL);
}
static void
notify_sound_changed (GtkWidget *widget, EMMailerPrefs *prefs)
{
const char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (prefs->notify_sound_file));
/* When we startup the file name will be NULL*/
gconf_client_set_string (prefs->gconf, "/apps/evolution/mail/notify/sound", filename ? filename : "", NULL);
}
static GtkWidget *
emmp_widget_glade(EConfig *ec, EConfigItem *item, struct _GtkWidget *parent, struct _GtkWidget *old, void *data)
{
EMMailerPrefs *prefs = data;
return glade_xml_get_widget(prefs->gui, item->label);
}
/* plugin meta-data */
static EMConfigItem emmp_items[] = {
{ E_CONFIG_BOOK, "", "preferences_toplevel", emmp_widget_glade },
{ E_CONFIG_PAGE, "00.general", "vboxGeneral", emmp_widget_glade },
{ E_CONFIG_SECTION, "00.general/00.fonts", "vboxMessageFonts", emmp_widget_glade },
{ E_CONFIG_SECTION, "00.general/10.display", "vboxMessageDisplay", emmp_widget_glade },
{ E_CONFIG_SECTION, "00.general/20.delete", "vboxDeletingMail", emmp_widget_glade },
{ E_CONFIG_SECTION, "00.general/30.newmail", "vboxNewMailNotify", emmp_widget_glade },
{ E_CONFIG_PAGE, "10.html", "vboxHtmlMail", emmp_widget_glade },
{ E_CONFIG_SECTION, "10.html/00.general", "vbox173", emmp_widget_glade },
{ E_CONFIG_SECTION, "10.html/10.images", "vbox190", emmp_widget_glade },
{ E_CONFIG_PAGE, "20.labels", "frameColours", emmp_widget_glade },
/* this is a table, so we can't use it { E_CONFIG_SECTION, "20.labels/00.labels", "tableColours", emmp_widget_glade }, */
{ E_CONFIG_PAGE, "30.headers", "vboxHeaderTab", emmp_widget_glade },
/* no subvbox for section { E_CONFIG_PAGE, "30.headers/00.headers", "vbox199", emmp_widget_glade }, */
{ E_CONFIG_PAGE, "40.junk", "vbox161", emmp_widget_glade },
/* no subvbox for section { E_CONFIG_SECTION, "40.junk/00.general", xxx, emmp_widget_glade } */
{ E_CONFIG_SECTION, "40.junk/10.options", "vbox204", emmp_widget_glade },
};
static void
emmp_free(EConfig *ec, GSList *items, void *data)
{
/* the prefs data is freed automagically */
g_slist_free(items);
}
static void
junk_plugin_changed (GtkWidget *combo, EMMailerPrefs *prefs)
{
char *def_plugin = gtk_combo_box_get_active_text(GTK_COMBO_BOX (combo));
const GList *plugins = mail_session_get_junk_plugins();
gconf_client_set_string (prefs->gconf, "/apps/evolution/mail/junk/default_plugin", def_plugin, NULL);
while (plugins) {
struct _EMJunkHookItem *item = plugins->data;;
if (item->plugin_name && def_plugin && !strcmp (item->plugin_name, def_plugin)) {
session->junk_plugin = CAMEL_JUNK_PLUGIN (&(item->csp));
void *status = e_plugin_invoke(item->hook->hook.plugin, item->validate_binary, NULL);
if ((gboolean)status == TRUE) {
char *text, *html;
gtk_image_set_from_stock (prefs->plugin_image, "gtk-dialog-info", GTK_ICON_SIZE_MENU);
text = g_strdup_printf (_("%s plugin is available and the binary is installed."), item->plugin_name);
html = g_strdup_printf ("<i>%s</i>", text);
gtk_label_set_markup (prefs->plugin_status, html);
g_free (html);
g_free (text);
} else {
char *text, *html;
gtk_image_set_from_stock (prefs->plugin_image, "gtk-dialog-warning", GTK_ICON_SIZE_MENU);
text = g_strdup_printf (_("%s plugin is not available. Please check whether the package is installed."), item->plugin_name);
html = g_strdup_printf ("<i>%s</i>", text);
gtk_label_set_markup (prefs->plugin_status, html);
g_free (html);
g_free (text);
}
break;
}
plugins = plugins->next;
}
}
static void
junk_plugin_setup (GtkWidget *combo, EMMailerPrefs *prefs)
{
int index = 0;
gboolean def_set = FALSE;
const GList *plugins = mail_session_get_junk_plugins();
char *pdefault = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/junk/default_plugin", NULL);
if (!plugins || !g_list_length ((GList *)plugins)) {
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("No Junk plugin available"));
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
gtk_widget_set_sensitive (GTK_WIDGET (combo), FALSE);
gtk_widget_hide (GTK_WIDGET (prefs->plugin_image));
gtk_widget_hide (GTK_WIDGET (prefs->plugin_status));
gtk_image_set_from_stock (prefs->plugin_image, NULL, 0);
g_free (pdefault);
return;
}
while (plugins) {
struct _EMJunkHookItem *item = plugins->data;;
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), item->plugin_name);
if (!def_set && pdefault && item->plugin_name && !strcmp(pdefault, item->plugin_name)) {
gboolean status;
def_set = TRUE;
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), index);
status = (gboolean)e_plugin_invoke(item->hook->hook.plugin, item->validate_binary, NULL);
if (status) {
char *text, *html;
gtk_image_set_from_stock (prefs->plugin_image, "gtk-dialog-info", GTK_ICON_SIZE_MENU);
/* May be a better text */
text = g_strdup_printf ("%s plugin is available and the binary is installed.", item->plugin_name);
html = g_strdup_printf ("<i>%s</i>", text);
gtk_label_set_markup (prefs->plugin_status, html);
g_free (html);
g_free (text);
} else {
char *text, *html;
gtk_image_set_from_stock (prefs->plugin_image, "gtk-dialog-warning", GTK_ICON_SIZE_MENU);
/* May be a better text */
text = g_strdup_printf ("%s plugin is not available. Please check whether the package is installed.", item->plugin_name);
html = g_strdup_printf ("<i>%s</i>", text);
gtk_label_set_markup (prefs->plugin_status, html);
g_free (html);
g_free (text);
}
}
plugins = plugins->next;
index++;
}
g_signal_connect (combo, "changed", G_CALLBACK(junk_plugin_changed), prefs);
g_free (pdefault);
}
GtkWidget *
create_combo_text_widget () {
return gtk_combo_box_new_text ();
}
static void
em_mailer_prefs_construct (EMMailerPrefs *prefs)
{
GSList *list, *header_config_list, *header_add_list, *p;
GHashTable *default_header_hash;
GtkWidget *toplevel;
GtkTreeSelection *selection;
GtkCellRenderer *renderer;
GtkTreeIter iter;
char *font, *buf;
GladeXML *gui;
gboolean locked;
int val, i;
EMConfig *ec;
EMConfigTargetPrefs *target;
GSList *l;
char *gladefile;
gladefile = g_build_filename (EVOLUTION_GLADEDIR,
"mail-config.glade",
NULL);
gui = glade_xml_new (gladefile, "preferences_toplevel", NULL);
g_free (gladefile);
prefs->gui = gui;
/** @HookPoint-EMConfig: Mail Preferences Page
* @Id: org.gnome.evolution.mail.prefs
* @Type: E_CONFIG_BOOK
* @Class: org.gnome.evolution.mail.config:1.0
* @Target: EMConfigTargetPrefs
*
* The main mail preferences page.
*/
ec = em_config_new(E_CONFIG_BOOK, "org.gnome.evolution.mail.prefs");
l = NULL;
for (i=0;i<sizeof(emmp_items)/sizeof(emmp_items[0]);i++)
l = g_slist_prepend(l, &emmp_items[i]);
e_config_add_items((EConfig *)ec, l, NULL, NULL, emmp_free, prefs);
/* General tab */
/* Message Display */
prefs->timeout_toggle = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkMarkTimeout"));
toggle_button_init (prefs, prefs->timeout_toggle, FALSE,
"/apps/evolution/mail/display/mark_seen",
G_CALLBACK (toggle_button_toggled));
prefs->timeout = GTK_SPIN_BUTTON (glade_xml_get_widget (gui, "spinMarkTimeout"));
spin_button_init (prefs, prefs->timeout,
"/apps/evolution/mail/display/mark_seen_timeout",
1000.0, G_CALLBACK (mark_seen_timeout_changed));
prefs->mlimit_toggle = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "mlimit_checkbutton"));
toggle_button_init (prefs, prefs->mlimit_toggle, FALSE,
"/apps/evolution/mail/display/force_message_limit",
G_CALLBACK (toggle_button_toggled));
prefs->mlimit_count = GTK_SPIN_BUTTON (glade_xml_get_widget (gui, "mlimit_spin"));
spin_button_init (prefs, prefs->mlimit_count,
"/apps/evolution/mail/display/message_text_part_limit",
1, G_CALLBACK (mlimit_count_changed));
prefs->address_toggle = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "address_checkbox"));
toggle_button_init (prefs, prefs->address_toggle, FALSE,
"/apps/evolution/mail/display/address_compress",
G_CALLBACK (toggle_button_toggled));
prefs->address_count = GTK_SPIN_BUTTON (glade_xml_get_widget (gui, "address_spin"));
spin_button_init (prefs, prefs->address_count,
"/apps/evolution/mail/display/address_count",
1, G_CALLBACK (address_compress_count_changed));
prefs->charset = GTK_OPTION_MENU (glade_xml_get_widget (gui, "omenuCharset"));
charset_menu_init (prefs);
prefs->citation_highlight = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkHighlightCitations"));
toggle_button_init (prefs, prefs->citation_highlight, FALSE,
"/apps/evolution/mail/display/mark_citations",
G_CALLBACK (toggle_button_toggled));
prefs->citation_color = GTK_COLOR_BUTTON (glade_xml_get_widget (gui, "colorButtonHighlightCitations"));
buf = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/display/citation_colour", NULL);
color_button_set_color (prefs->citation_color, buf ? buf : "#737373");
g_signal_connect (prefs->citation_color, "color-set", G_CALLBACK (citation_color_set), prefs);
if (!gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/display/citation_colour", NULL))
gtk_widget_set_sensitive ((GtkWidget *) prefs->citation_color, FALSE);
g_free (buf);
/* Deleting Mail */
prefs->empty_trash = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkEmptyTrashOnExit"));
prefs->empty_trash_days = GTK_OPTION_MENU (glade_xml_get_widget (gui, "omenuEmptyTrashDays"));
emmp_empty_trash_init (prefs);
prefs->confirm_expunge = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkConfirmExpunge"));
toggle_button_init (prefs, prefs->confirm_expunge, FALSE,
"/apps/evolution/mail/prompts/expunge",
G_CALLBACK (toggle_button_toggled));
/* New Mail Notification */
locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/notify/type", NULL);
val = gconf_client_get_int (prefs->gconf, "/apps/evolution/mail/notify/type", NULL);
prefs->notify_not = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radNotifyNot"));
gtk_toggle_button_set_active (prefs->notify_not, val == MAIL_CONFIG_NOTIFY_NOT);
g_signal_connect (prefs->notify_not, "toggled", G_CALLBACK (notify_type_changed), prefs);
if (locked)
gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_not, FALSE);
prefs->notify_beep = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radNotifyBeep"));
prefs->notify_sound_file = GTK_FILE_CHOOSER_BUTTON (glade_xml_get_widget (gui, "fileNotifyPlaySoundButton"));
gtk_toggle_button_set_active (prefs->notify_beep, val == MAIL_CONFIG_NOTIFY_BEEP);
g_signal_connect (prefs->notify_beep, "toggled", G_CALLBACK (notify_type_changed), prefs);
if (locked)
gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_beep, FALSE);
prefs->notify_play_sound = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radNotifyPlaySound"));
gtk_toggle_button_set_active (prefs->notify_play_sound, val == MAIL_CONFIG_NOTIFY_PLAY_SOUND);
g_signal_connect (prefs->notify_play_sound, "toggled", G_CALLBACK (notify_type_changed), prefs);
if (locked)
gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_play_sound, FALSE);
buf = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/notify/sound", NULL);
if (buf && *buf)
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (prefs->notify_sound_file), buf);
g_signal_connect (GTK_FILE_CHOOSER_BUTTON (prefs->notify_sound_file), "selection-changed",
G_CALLBACK (notify_sound_changed), prefs);
if (val != MAIL_CONFIG_NOTIFY_PLAY_SOUND)
gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_sound_file, FALSE);
g_free (buf);
/* Mail Fonts */
font = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/display/fonts/monospace", NULL);
prefs->font_fixed = GTK_FONT_BUTTON (glade_xml_get_widget (gui, "FontFixed"));
gtk_font_button_set_font_name (prefs->font_fixed, font);
g_free (font);
g_object_set_data ((GObject *) prefs->font_fixed, "key", "/apps/evolution/mail/display/fonts/monospace");
g_signal_connect (prefs->font_fixed, "font-set", G_CALLBACK (font_changed), prefs);
if (!gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/display/fonts/monospace", NULL))
gtk_widget_set_sensitive ((GtkWidget *) prefs->font_fixed, FALSE);
font = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/display/fonts/variable", NULL);
prefs->font_variable = GTK_FONT_BUTTON (glade_xml_get_widget (gui, "FontVariable"));
gtk_font_button_set_font_name (prefs->font_variable, font);
g_free (font);
g_object_set_data ((GObject *) prefs->font_variable, "key", "/apps/evolution/mail/display/fonts/variable");
g_signal_connect (prefs->font_variable, "font-set", G_CALLBACK (font_changed), prefs);
if (!gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/display/fonts/variable", NULL))
gtk_widget_set_sensitive ((GtkWidget *) prefs->font_variable, FALSE);
prefs->font_share = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radFontUseSame"));
toggle_button_init (prefs, prefs->font_share, TRUE,
"/apps/evolution/mail/display/fonts/use_custom",
G_CALLBACK (custom_font_changed));
custom_font_changed (prefs->font_share, prefs);
/* HTML Mail tab */
/* Loading Images */
locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/display/load_http_images", NULL);
val = gconf_client_get_int (prefs->gconf, "/apps/evolution/mail/display/load_http_images", NULL);
prefs->images_never = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radImagesNever"));
gtk_toggle_button_set_active (prefs->images_never, val == MAIL_CONFIG_HTTP_NEVER);
if (locked)
gtk_widget_set_sensitive ((GtkWidget *) prefs->images_never, FALSE);
prefs->images_sometimes = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radImagesSometimes"));
gtk_toggle_button_set_active (prefs->images_sometimes, val == MAIL_CONFIG_HTTP_SOMETIMES);
if (locked)
gtk_widget_set_sensitive ((GtkWidget *) prefs->images_sometimes, FALSE);
prefs->images_always = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radImagesAlways"));
gtk_toggle_button_set_active (prefs->images_always, val == MAIL_CONFIG_HTTP_ALWAYS);
if (locked)
gtk_widget_set_sensitive ((GtkWidget *) prefs->images_always, FALSE);
g_signal_connect (prefs->images_never, "toggled", G_CALLBACK (http_images_changed), prefs);
g_signal_connect (prefs->images_sometimes, "toggled", G_CALLBACK (http_images_changed), prefs);
g_signal_connect (prefs->images_always, "toggled", G_CALLBACK (http_images_changed), prefs);
prefs->show_animated = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkShowAnimatedImages"));
toggle_button_init (prefs, prefs->show_animated, FALSE,
"/apps/evolution/mail/display/animate_images",
G_CALLBACK (toggle_button_toggled));
prefs->prompt_unwanted_html = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkPromptWantHTML"));
toggle_button_init (prefs, prefs->prompt_unwanted_html, FALSE,
"/apps/evolution/mail/prompts/unwanted_html",
G_CALLBACK (toggle_button_toggled));
/* Labels... */
locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/labels", NULL);
i = 0;
list = mail_config_get_labels ();
while (list != NULL && i < 5) {
MailConfigLabel *label;
char *widget_name;
label = list->data;
widget_name = g_strdup_printf ("txtLabel%d", i);
prefs->labels[i].name = GTK_ENTRY (glade_xml_get_widget (gui, widget_name));
gtk_widget_set_sensitive ((GtkWidget *) prefs->labels[i].name, !locked);
g_free (widget_name);
widget_name = g_strdup_printf ("colorLabel%d", i);
prefs->labels[i].color = GTK_COLOR_BUTTON (glade_xml_get_widget (gui, widget_name));
gtk_widget_set_sensitive ((GtkWidget *) prefs->labels[i].color, !locked);
g_free (widget_name);
gtk_entry_set_text (prefs->labels[i].name, label->name);
g_signal_connect (prefs->labels[i].name, "changed", G_CALLBACK (label_entry_changed), prefs);
color_button_set_color (prefs->labels[i].color, label->colour);
g_signal_connect (prefs->labels[i].color, "color-set", G_CALLBACK (label_color_set), prefs);
atk_object_set_name(gtk_widget_get_accessible((GtkWidget *)prefs->labels[i].color), label->name);
i++;
list = list->next;
}
prefs->restore_labels = GTK_BUTTON (glade_xml_get_widget (gui, "cmdRestoreLabels"));
gtk_widget_set_sensitive ((GtkWidget *) prefs->restore_labels, !locked);
g_signal_connect (prefs->restore_labels, "clicked", G_CALLBACK (restore_labels_clicked), prefs);
/* headers */
locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/display/headers", NULL);
prefs->photo_show= GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "photo_show"));
toggle_button_init (prefs, prefs->photo_show, FALSE,
"/apps/evolution/mail/display/sender_photo",
G_CALLBACK (photo_toggle_changed));
prefs->photo_local = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "photo_local"));
toggle_button_init (prefs, prefs->photo_local, FALSE,
"/apps/evolution/mail/display/photo_local",
G_CALLBACK (toggle_button_toggled));
if (!gtk_toggle_button_get_active (prefs->photo_show))
gtk_widget_set_sensitive ((GtkWidget *) prefs->photo_local, FALSE);
/* always de-sensitised until the user types something in the entry */
prefs->add_header = GTK_BUTTON (glade_xml_get_widget (gui, "cmdHeadersAdd"));
gtk_widget_set_sensitive ((GtkWidget *) prefs->add_header, FALSE);
/* always de-sensitised until the user selects a header in the list */
prefs->remove_header = GTK_BUTTON (glade_xml_get_widget (gui, "cmdHeadersRemove"));
gtk_widget_set_sensitive ((GtkWidget *) prefs->remove_header, FALSE);
prefs->entry_header = GTK_ENTRY (glade_xml_get_widget (gui, "txtHeaders"));
gtk_widget_set_sensitive ((GtkWidget *) prefs->entry_header, !locked);
prefs->header_list = GTK_TREE_VIEW (glade_xml_get_widget (gui, "treeHeaders"));
gtk_widget_set_sensitive ((GtkWidget *) prefs->header_list, !locked);
selection = gtk_tree_view_get_selection (prefs->header_list);
g_signal_connect (selection, "changed", G_CALLBACK (emmp_header_list_row_selected), prefs);
g_signal_connect (prefs->entry_header, "changed", G_CALLBACK (emmp_header_entry_changed), prefs);
g_signal_connect (prefs->entry_header, "activate", G_CALLBACK (emmp_header_add_header), prefs);
/* initialise the tree with appropriate headings */
prefs->header_list_store = gtk_list_store_newv (HEADER_LIST_N_COLUMNS, col_types);
g_signal_connect (prefs->add_header, "clicked", G_CALLBACK (emmp_header_add_header), prefs);
g_signal_connect (prefs->remove_header, "clicked", G_CALLBACK (emmp_header_remove_header), prefs);
gtk_tree_view_set_model (prefs->header_list, GTK_TREE_MODEL (prefs->header_list_store));
renderer = gtk_cell_renderer_toggle_new ();
g_object_set (renderer, "activatable", TRUE, NULL);
g_signal_connect (renderer, "toggled", G_CALLBACK (emmp_header_list_enabled_toggled), prefs);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (prefs->header_list), -1,
"Enabled", renderer,
"active", HEADER_LIST_ENABLED_COLUMN,
NULL);
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (prefs->header_list), -1,
"Name", renderer,
"text", HEADER_LIST_NAME_COLUMN,
NULL);
/* populated the listview with entries; firstly we add all the default headers, and then
we add read header configuration out of gconf. If a header in gconf is a default header,
we update the enabled flag accordingly
*/
header_add_list = NULL;
default_header_hash = g_hash_table_new (g_str_hash, g_str_equal);
for (i = 0; i < G_N_ELEMENTS (default_headers); i++) {
struct _EMMailerPrefsHeader *h;
h = g_malloc (sizeof (struct _EMMailerPrefsHeader));
h->is_default = TRUE;
h->name = g_strdup (default_headers[i]);
h->enabled = strcmp ((char *)default_headers[i], "x-evolution-mailer") != 0;
g_hash_table_insert (default_header_hash, (gpointer) default_headers[i], h);
header_add_list = g_slist_append (header_add_list, h);
}
/* read stored headers from gconf */
header_config_list = gconf_client_get_list (prefs->gconf, "/apps/evolution/mail/display/headers", GCONF_VALUE_STRING, NULL);
p = header_config_list;
while (p) {
struct _EMMailerPrefsHeader *h, *def;
char *xml = (char *) p->data;
h = em_mailer_prefs_header_from_xml (xml);
if (h) {
def = g_hash_table_lookup (default_header_hash, h->name);
if (def) {
def->enabled = h->enabled;
em_mailer_prefs_header_free (h);
} else {
h->is_default = FALSE;
header_add_list = g_slist_append (header_add_list, h);
}
}
p = p->next;
}
g_hash_table_destroy (default_header_hash);
g_slist_foreach (header_config_list, (GFunc) g_free, NULL);
g_slist_free (header_config_list);
p = header_add_list;
while (p) {
struct _EMMailerPrefsHeader *h = (struct _EMMailerPrefsHeader *) p->data;
const char *name;
if (g_ascii_strcasecmp (h->name, EM_FORMAT_HEADER_XMAILER) == 0)
name = _("Mailer");
else
name = _(h->name);
gtk_list_store_append (prefs->header_list_store, &iter);
gtk_list_store_set (prefs->header_list_store, &iter,
HEADER_LIST_NAME_COLUMN, name,
HEADER_LIST_ENABLED_COLUMN, h->enabled,
HEADER_LIST_IS_DEFAULT_COLUMN, h->is_default,
HEADER_LIST_HEADER_COLUMN, h->name,
-1);
em_mailer_prefs_header_free (h);
p = p->next;
}
g_slist_free (header_add_list);
/* Junk prefs */
prefs->check_incoming = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkCheckIncomingMail"));
toggle_button_init (prefs, prefs->check_incoming, FALSE,
"/apps/evolution/mail/junk/check_incoming",
G_CALLBACK (toggle_button_toggled));
prefs->empty_junk = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "junk_empty_check"));
prefs->empty_junk_days = GTK_OPTION_MENU (glade_xml_get_widget (gui, "junk_empty_combo"));
emmp_empty_junk_init (prefs);
prefs->default_junk_plugin = GTK_COMBO_BOX (glade_xml_get_widget (gui, "default_junk_plugin"));
prefs->plugin_status = GTK_LABEL (glade_xml_get_widget (gui, "plugin_status"));
prefs->plugin_image = GTK_IMAGE (glade_xml_get_widget (gui, "plugin_image"));
junk_plugin_setup (GTK_WIDGET (prefs->default_junk_plugin), prefs);
/* get our toplevel widget */
target = em_config_target_new_prefs(ec, prefs->gconf);
e_config_set_target((EConfig *)ec, (EConfigTarget *)target);
toplevel = e_config_create_widget((EConfig *)ec);
gtk_container_add (GTK_CONTAINER (prefs), toplevel);
}
GtkWidget *
em_mailer_prefs_new (void)
{
EMMailerPrefs *new;
new = (EMMailerPrefs *) g_object_new (em_mailer_prefs_get_type (), NULL);
em_mailer_prefs_construct (new);
return (GtkWidget *) new;
}
static struct _EMMailerPrefsHeader *
emmp_header_from_xmldoc (xmlDocPtr doc)
{
struct _EMMailerPrefsHeader *h;
xmlNodePtr root;
xmlChar *name;
if (doc == NULL)
return NULL;
root = doc->children;
if (strcmp ((char *)root->name, "header") != 0)
return NULL;
name = xmlGetProp (root, (const unsigned char *)"name");
if (name == NULL)
return NULL;
h = g_malloc0 (sizeof (struct _EMMailerPrefsHeader));
h->name = g_strdup ((gchar *)name);
xmlFree (name);
if (xmlHasProp (root, (const unsigned char *)"enabled"))
h->enabled = 1;
else
h->enabled = 0;
return h;
}
/**
* em_mailer_prefs_header_from_xml
* @xml: XML configuration data
*
* Parses passed XML data, which should be of
* the format <header name="foo" enabled />, and
* returns a EMMailerPrefs structure, or NULL if there
* is an error.
**/
struct _EMMailerPrefsHeader *
em_mailer_prefs_header_from_xml (const char *xml)
{
struct _EMMailerPrefsHeader *header;
xmlDocPtr doc;
if (!(doc = xmlParseDoc ((unsigned char *) xml)))
return NULL;
header = emmp_header_from_xmldoc (doc);
xmlFreeDoc (doc);
return header;
}
/**
* em_mailer_prefs_header_free
* @header: header to free
*
* Frees the memory associated with the passed header
* structure.
*/
void
em_mailer_prefs_header_free (struct _EMMailerPrefsHeader *header)
{
if (header == NULL)
return;
g_free (header->name);
g_free (header);
}
/**
* em_mailer_prefs_header_to_xml
* @header: header from which to generate XML
*
* Returns the passed header as a XML structure,
* or NULL on error
*/
char *
em_mailer_prefs_header_to_xml (struct _EMMailerPrefsHeader *header)
{
xmlDocPtr doc;
xmlNodePtr root;
xmlChar *xml;
char *out;
int size;
g_return_val_if_fail (header != NULL, NULL);
g_return_val_if_fail (header->name != NULL, NULL);
doc = xmlNewDoc ((const unsigned char *)"1.0");
root = xmlNewDocNode (doc, NULL, (const unsigned char *)"header", NULL);
xmlSetProp (root, (const unsigned char *)"name", (unsigned char *)header->name);
if (header->enabled)
xmlSetProp (root, (const unsigned char *)"enabled", NULL);
xmlDocSetRootElement (doc, root);
xmlDocDumpMemory (doc, &xml, &size);
xmlFreeDoc (doc);
out = g_malloc (size + 1);
memcpy (out, xml, size);
out[size] = '\0';
xmlFree (xml);
return out;
}
|