aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/ChangeLog
blob: 8ad855ab865f887facf97e51260f52bcc7a5ddce (plain) (blame)
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
2002-11-03  Ettore Perazzoli  <ettore@ximian.com>

    * e-timezone-dialog/e-timezone-dialog.c
    (e_timezone_dialog_get_builtin_timezone): Constify arg
    display_name.

2002-11-01  Ettore Perazzoli  <ettore@ximian.com>

    * menus/gal-view-menus.c (build_stuff): Add some casts.

2002-10-30  Ettore Perazzoli  <ettore@ximian.com>

    * e-timezone-dialog/e-timezone-dialog.c
    (e_timezone_dialog_construct): Pass NULL as the domain arg to
    glade_xml_new().
    (e_timezone_dialog_get_timezone): Make arg display_name const.
    (find_selected_point): Constify local variable timezone.

    * e-timezone-dialog/e-timezone-dialog.h: Do not #include
    <libgnome/gnome-defs.h>.

2002-08-15  Mike Kestner  <mkestner@ximian.com>

    * menus/gal-view-menus.c (build_stuff): ref/unref the gvm

2002-07-09  Peter Williams  <peterw@ximian.com>

    * e-timezone-dialog/Makefile.am: Add -I$(top_builddir)/libical/src/libical;
    some headers that we rely on get installed, so they point to the ical.h that
    gets generated and installed; consequently we need to be able to find the
    generated ical.h

    * misc/Makefile.am: Install libemiscwidgets.a and its headers. However,
    break EFilterBar into a separate libefilterbar.a because we don't want
    the installed library to depend on libfilter.

2002-07-05  Ettore Perazzoli  <ettore@ximian.com>

    * e-timezone-dialog/e-timezone-dialog.c (e_timezone_dialog_init):
    Make not floating.

2002-06-04  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c, menus/gal-view-menus.h
    (gal_view_menus_set_show_define_views): Added this function to let
    you disable the define views dialog.

2002-06-04  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c (define_views): Don't show this dialog
    more than once per collection.

2002-05-14  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c (build_menus): Made it so that if the
    current_id doesn't match any of the given ids, it treats it the
    same as a NULL id.
    (gal_view_menus_apply): Added a check for gvm->priv == NULL here.
    (gal_view_menus_apply, collection_changed, instance_changed):
    Removed calls to set_radio after build_stuff, since the last thing
    build_stuff does is calls set_radio.

2002-02-27  Larry Ewing  <lewing@ximian.com>

    * misc/e-combo-button.c (impl_button_press_event): make a right
    click bring up the popup menu.

2002-02-07  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c, menus/gal-view-menus.h
    (gal_view_menus_unmerge): New function to handle unmerging menus
    at control deactivation time.
    (d): Turned off debugging output here.
    (build_menus): Gave the separators names and marked them with f=""
    to make them work better with bonobo 1.

2002-02-07  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c, menus/gal-view-menus.h
    (gal_view_menus_new): Made this take a GalViewInstance instead of
    a GalViewCollection.  Reworked most of this to utilize the
    interfaces provided by GalViewInstance.

2002-01-27  Ettore Perazzoli  <ettore@ximian.com>

    * menus/Makefile.am: Use `GNOME_FULL_CFLAGS'.

2002-01-11  Damon Chaplin  <damon@ximian.com>

    * e-timezone-dialog/e-timezone-dialog.[hc]: translate timezone names,
    and provide a function to get back to the English version.

2001-10-24  Jon Trowbridge  <trow@ximian.com>

    * menus/gal-view-menus.c (gal_view_menus_apply): Ref the
    BonoboUIComponent that we are holding.
    (gvm_destroy): Unref our BonoboUIComponent.

2001-10-21  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c: Make this not be a radio button, but
    instead just a normal menu.

2001-10-18  Jeffrey Stedfast  <fejj@ximian.com>

    * menus/gal-view-menus.c: #include bonobo-ui-util.h

2001-10-04  Rodrigo Moya <rodrigo@ximian.com>

    * misc/Makefile.am:
    * menus/Makefile.am: added BONOBO_GNOME_CFLAGS to make it compile
    with latest Bonobo

2001-09-19  JP Rosevear  <jpr@ximian.com>

    * Makefile.am: the meeting-time-sel dir is dead, relevant pieces
    moved to calendar/gui

2001-08-26  Zbigniew Chyla  <cyba@gnome.pl>

    Fixes #2465

    * menus/gal-view-menus.c (build_menus):
    Encode the label using bonobo_ui_util_encode_str and set "label"
    attribute, not "_label".
    I have no idea what the previous code was trying to do but it was
    definitely wrong.

2001-08-27  Ettore Perazzoli  <ettore@ximian.com>

    * e-timezone-dialog/e-timezone-dialog.h
    (e_timezone_dialog_reparent): New prototype here.

2001-08-27  Iain Holmes  <iain@ximian.com>

    * e-timezone-dialog/e-timezone.h: Add a prototype for 
    e_timezone_dialog_reparent

2001-08-18  Iain Holmes  <iain@ximian.com>

    * Makefile.am: Add the e-timezone-dialog dir.

    * e-timezone-dialog/*: Add new files.

2001-08-10  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c (build_menus): Don't display the Define
    Views dialog.

2001-07-02 Anna Marie Dirks <anna@ximian.com>

    * misc/e-filter-bar.c (option_changed): Specified a default size
    for the Advanced Search dialog such that when it first appear, it
    is large enough to view all parts of a search clause without the
    user needing to resize it.

2001-05-31  Federico Mena Quintero  <federico@ximian.com>

    * menus/gal-view-menus.c (gal_view_menus_construct): Store the
    connection ID of the "changed" signal in the collection.
    (gal_view_menus_new): Added preconditions.
    (gal_view_menus_construct): Added preconditions.

2001-05-21  Chris Toshok  <toshok@ximian.com>

    * menus/gal-view-menus.c (build_menus): make the view menuitems
    radio items of the same group, and allocate the closure here.
    (free_verbs): only need to free the one DefineViews verb here.
    (closure_free): new function - EListFreeFunc for our
    listenerClosure list.
    (remove_listeners): new function, free our listener list.
    (gvm_destroy): call remove_listeners.
    (gvm_init): init listenerClosures list.
    (toggled_cb): callback for radio items.
    (build_verbs): strip out almost all the code since there's only 1
    verb now.
    (build_stuff): call remove_listeners.

2001-05-08  Gediminas Paulauskas <menesis@delfi.lt>

    * misc/e-search-bar.c (add_dropdown), (set_option): first try to
    translate, then if not suceeded -- convert from utf8. This handles
    cases when menuitem needs to be translated (it is passed as N_()), or is
    utf8 search title. However you cannot have a search like "Folders" -- it
    is translated. Part of fix for #2253.
    
    * misc/e-filter-bar.c: d() debugging strings. Use E_FILTERBAR_ADVANCED
    macro instead of own "Advanced ..." for consistency.

2001-05-07  Gediminas Paulauskas <menesis@delfi.lt>
    
    * menus/gal-view-menus.c (build_menus): convert label to locale
    encoding. Still displays truncated strings.
    
    * menus/Makefile.am: removed -DEVOLUTION_VERSION.

2001-04-21  Gediminas Paulauskas <menesis@delfi.lt>

    * menus/gal-view-menus.c: bonobo_ui_node_set_attr expects unstranslated
    strings, so change _() to N_().

2001-04-12  Dan Winship  <danw@ximian.com>

    * menus/gal-view-menus.c (build_menus): Fix a memory leak.
    (Doesn't anyone ever change any other file in this directory? :)

2001-04-10  Gediminas Paulauskas <menesis@delfi.lt>

    * menus/gal-view-menus.c: convert label to utf8.

2001-04-04  Kjartan Maraas  <kmaraas@gnome.org>

    * menus/gal-view-menus.c: Fix headers.
    
2001-03-28  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c (build_menus): Don't print the xml tree
    here.

2001-03-16  Miguel de Icaza  <miguel@ximian.com>

    * menus/gal-view-menus.c (build_menus): Hook this up under the
    "ViewBegin" node.

2001-02-28  Miguel de Icaza  <miguel@ximian.com>

    * menus/gal-view-menus.c (build_menus): Add translation string
    here. 

2001-03-05  Christopher James Lahey  <clahey@ximian.com>

    * menus/gal-view-menus.c (collection_changed): Rebuild when the
    collection changes.

2001-01-27  Jason Leach  <jasonleach@usa.net>

    * cvs remove all files in shortcut-bar/, this widget is now in
    gal, will be maintained there.
    
    * Makefile.am (SUBDIRS): Remove shortcut-bar from here.

2001-01-25  Christopher James Lahey  <clahey@helixcode.com>

    * menus/gal-view-menus.c: Make this actually deploy the titles
    from the GalViewCollection and emit the display_view signals and
    such.

2001-01-22  Jon Trowbridge  <trow@gnu.org>

    * menus/gal-view-menus.c (define_views): Fixed
    gal_define_views_dialog_new to be called with its proper argument.

2000-12-06  Christopher James Lahey  <clahey@helixcode.com>

    * menus/gal-view-menus.c, menus/gal-view-menus.h: Added a
    GalViewCollection argument to the new function here.

2000-12-04  Dan Winship  <danw@helixcode.com>

    * menus/gal-view-menus.c: NULL-terminate gal_view_menus_apply's
    BonoboUIVerb array to prevent a crash. (Why are there gal* things
    in the evolution sources?)

2000-11-05  Christopher James Lahey  <clahey@helixcode.com>

    * e-paned/.cvsignore, e-table/.cvsignore, e-text/.cvsignore:
    Removed unnecessary .cvsignore files.

2000-09-18  Christopher James Lahey  <clahey@helixcode.com>

    * Makefile.am: Removed directories that have been moved to gal.

    * e-paned/.cvsignore, e-paned/Makefile.am, e-paned/e-hpaned.c,
    e-paned/e-hpaned.h, e-paned/e-paned.c, e-paned/e-paned.h,
    e-paned/e-vpaned.c, e-paned/e-vpaned.h: Moved to gal.

    * e-reflow/.cvsignore, e-reflow/Makefile.am,
    e-reflow/e-reflow-sorted.c, e-reflow/e-reflow-sorted.h,
    e-reflow/e-reflow.c, e-reflow/e-reflow.h: Moved to gal.

    * e-table/.cvsignore, e-table/ChangeLog, e-table/LICENSE,
    e-table/Makefile.am, e-table/ROADMAP.e-table, e-table/TODO,
    e-table/add-col.xpm, e-table/arrow-down.xpm, e-table/arrow-up.xpm,
    e-table/check-empty.xpm, e-table/check-filled.xpm,
    e-table/clip.png, e-table/e-cell-checkbox.c,
    e-table/e-cell-checkbox.h, e-table/e-cell-string.c,
    e-table/e-cell-text.c, e-table/e-cell-text.h,
    e-table/e-cell-toggle.c, e-table/e-cell-toggle.h,
    e-table/e-cell-tree.c, e-table/e-cell-tree.h, e-table/e-cell.c,
    e-table/e-cell.h, e-table/e-table-click-to-add.c,
    e-table/e-table-click-to-add.h, e-table/e-table-col-dnd.h,
    e-table/e-table-col.c, e-table/e-table-col.h,
    e-table/e-table-column-model.h, e-table/e-table-column.c,
    e-table/e-table-config.c, e-table/e-table-config.glade,
    e-table/e-table-config.glade.h, e-table/e-table-config.h,
    e-table/e-table-defines.h, e-table/e-table-example-1.c,
    e-table/e-table-example-2.c,
    e-table/e-table-field-chooser-dialog.c,
    e-table/e-table-field-chooser-dialog.h,
    e-table/e-table-field-chooser-item.c,
    e-table/e-table-field-chooser-item.h,
    e-table/e-table-field-chooser.c,
    e-table/e-table-field-chooser.glade,
    e-table/e-table-field-chooser.glade.h,
    e-table/e-table-field-chooser.h,
    e-table/e-table-group-container.c,
    e-table/e-table-group-container.h, e-table/e-table-group-leaf.c,
    e-table/e-table-group-leaf.h, e-table/e-table-group.c,
    e-table/e-table-group.glade, e-table/e-table-group.glade.h,
    e-table/e-table-group.h, e-table/e-table-header-item.c,
    e-table/e-table-header-item.h, e-table/e-table-header.c,
    e-table/e-table-header.h, e-table/e-table-item.c,
    e-table/e-table-item.h, e-table/e-table-model.c,
    e-table/e-table-model.h, e-table/e-table-one.c,
    e-table/e-table-one.h, e-table/e-table-scrolled.c,
    e-table/e-table-scrolled.h, e-table/e-table-selection-model.c,
    e-table/e-table-selection-model.h, e-table/e-table-simple.c,
    e-table/e-table-simple.h, e-table/e-table-size-test.c,
    e-table/e-table-sort-info.c, e-table/e-table-sort-info.h,
    e-table/e-table-sorted-variable.c,
    e-table/e-table-sorted-variable.h, e-table/e-table-sorted.c,
    e-table/e-table-sorted.h, e-table/e-table-sorter.c,
    e-table/e-table-sorter.h, e-table/e-table-subset-variable.c,
    e-table/e-table-subset-variable.h, e-table/e-table-subset.c,
    e-table/e-table-subset.h, e-table/e-table-text-model.c,
    e-table/e-table-text-model.h, e-table/e-table-tooltip.h,
    e-table/e-table-tree.h, e-table/e-table.c, e-table/e-table.h,
    e-table/e-tree-example-1.c, e-table/e-tree-example-2.c,
    e-table/e-tree-model.c, e-table/e-tree-model.h,
    e-table/e-tree-simple.c, e-table/e-tree-simple.h,
    e-table/image1.png, e-table/image2.png, e-table/image3.png,
    e-table/remove-col.xpm, e-table/sample.table,
    e-table/table-test.c, e-table/table-test.h, e-table/test-check.c,
    e-table/test-cols.c, e-table/test-table.c: Moved to gal.

    * e-text/.cvsignore, e-text/Makefile.am, e-text/e-entry-test.c,
    e-text/e-entry.c, e-text/e-entry.h,
    e-text/e-text-event-processor-emacs-like.c,
    e-text/e-text-event-processor-emacs-like.h,
    e-text/e-text-event-processor-types.h,
    e-text/e-text-event-processor.c, e-text/e-text-event-processor.h,
    e-text/e-text-model.c, e-text/e-text-model.h,
    e-text/e-text-test.c, e-text/e-text.c, e-text/e-text.h: Moved to
    gal.

2000-09-14  Michael Meeks  <michael@helixcode.com>

    * e-reflow/e-reflow-sorted.h: fix include.

2000-09-13  Christopher James Lahey  <clahey@helixcode.com>

    * Makefile.am (SUBDIRS): Added e-reflow.

    * e-reflow/e-reflow.c, e-reflow/e-reflow.h: Moved from
    addressbook/gui/minicard/.

    * e-reflow/Makefile.am, e-reflow/.cvsignore: New files for a new
    directory.

2000-09-08  Lauris Kaplinski  <lauris@helixcode.com>

    * e-text/e-text.c (calc_line_widths): Fix byte/char confusion

2000-08-30  Federico Mena Quintero  <federico@helixcode.com>

    * e-paned/e-hpaned.c (e_hpaned_motion): Do not flicker while
    trying to resize a quantized pane.

    * e-paned/e-vpaned.c (e_vpaned_motion): Likewise.

2000-08-30  Federico Mena Quintero  <federico@helixcode.com>

    * widgets/e-paned/e-vpaned.c (e_vpaned_size_allocate): Ensure that
    the child's allocation height is >= 1.

    * widgets/e-paned/e-hpaned.c (e_hpaned_size_allocate): Ensure that
    the child's allocation width is >= 1.

2000-08-30  Federico Mena Quintero  <federico@helixcode.com>

    * ChangeLog: Started a ChangeLog here.
='n819' href='#n819'>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 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * e-table-field-chooser.c
 * Copyright (C) 2000  Ximian, Inc.
 * Author: Chris Lahey <clahey@ximian.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * 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 library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>

#include <gtk/gtkinvisible.h>

#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <gal/e-table/e-table-scrolled.h>
#include <gal/e-table/e-table-model.h>
#include <gal/widgets/e-scroll-frame.h>
#include <gal/widgets/e-popup-menu.h>
#include <gal/widgets/e-gui-utils.h>
#include <gal/widgets/e-unicode.h>
#include <gal/menus/gal-view-factory-etable.h>
#include <gal/menus/gal-view-etable.h>
#include <gal/util/e-xml-utils.h>
#include <libgnomeui/gnome-dialog-util.h>

#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-master.h>
#include <libgnomeprintui/gnome-print-dialog.h>
#include <libgnomeprintui/gnome-print-master-preview.h>

#include "addressbook/printing/e-contact-print.h"
#include "addressbook/printing/e-contact-print-envelope.h"

#include "gal-view-factory-minicard.h"
#include "gal-view-minicard.h"

#include "e-addressbook-marshal.h"
#include "e-addressbook-view.h"
#include "e-addressbook-model.h"
#include "e-addressbook-util.h"
#include "e-addressbook-table-adapter.h"
#include "e-addressbook-reflow-adapter.h"
#include "e-minicard-view-widget.h"
#include "e-contact-save-as.h"
#include "e-card-merging.h"

#include "e-contact-editor.h"
#include <gdk/gdkkeysyms.h>
#include <ctype.h>

#include <gnome-xml/tree.h>
#include <gnome-xml/parser.h>

#define SHOW_ALL_SEARCH "(contains \"x-evolution-any-field\" \"\")"

#define d(x)

static void e_addressbook_view_init     (EAddressbookView        *card);
static void e_addressbook_view_class_init   (EAddressbookViewClass   *klass);
static void e_addressbook_view_set_arg (GtkObject *o, GtkArg *arg, guint arg_id);
static void e_addressbook_view_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
static void e_addressbook_view_destroy (GtkObject *object);
static void change_view_type (EAddressbookView *view, EAddressbookViewType view_type);

static void status_message     (GtkObject *object, const gchar *status, EAddressbookView *eav);
static void search_result      (GtkObject *object, EBookViewStatus status, EAddressbookView *eav);
static void folder_bar_message (GtkObject *object, const gchar *status, EAddressbookView *eav);
static void stop_state_changed (GtkObject *object, EAddressbookView *eav);
static void writable_status (GtkObject *object, gboolean writable, EAddressbookView *eav);
static void backend_died (GtkObject *object, EAddressbookView *eav);
static void command_state_change (EAddressbookView *eav);
static void alphabet_state_change (EAddressbookView *eav, gunichar letter);

static void selection_clear_event (GtkWidget *invisible, GdkEventSelection *event,
                   EAddressbookView *view);
static void selection_received (GtkWidget *invisible, GtkSelectionData *selection_data,
                guint time, EAddressbookView *view);
static void selection_get (GtkWidget *invisible, GtkSelectionData *selection_data,
               guint info, guint time_stamp, EAddressbookView *view);
static void invisible_destroyed (GtkWidget *invisible, EAddressbookView *view);

static GtkTableClass *parent_class = NULL;

/* The arguments we take */
enum {
    ARG_0,
    ARG_BOOK,
    ARG_QUERY,
    ARG_TYPE,
};

enum {
    STATUS_MESSAGE,
    SEARCH_RESULT,
    FOLDER_BAR_MESSAGE,
    COMMAND_STATE_CHANGE,
    ALPHABET_STATE_CHANGE,
    LAST_SIGNAL
};

enum DndTargetType {
    DND_TARGET_TYPE_VCARD,
};
#define VCARD_TYPE "text/x-vcard"
static GtkTargetEntry drag_types[] = {
    { VCARD_TYPE, 0, DND_TARGET_TYPE_VCARD },
};
static const int num_drag_types = sizeof (drag_types) / sizeof (drag_types[0]);

static guint e_addressbook_view_signals [LAST_SIGNAL] = {0, };

static GdkAtom clipboard_atom = GDK_NONE;

static GalViewCollection *collection = NULL;

GtkType
e_addressbook_view_get_type (void)
{
    static GtkType type = 0;

    if (!type) {
        static const GtkTypeInfo info =
        {
            "EAddressbookView",
            sizeof (EAddressbookView),
            sizeof (EAddressbookViewClass),
            (GtkClassInitFunc) e_addressbook_view_class_init,
            (GtkObjectInitFunc) e_addressbook_view_init,
            /* reserved_1 */ NULL,
                /* reserved_2 */ NULL,
            (GtkClassInitFunc) NULL,
        };
        
        type = gtk_type_unique (gtk_table_get_type (), &info);
    }

    return type;
}

static void
e_addressbook_view_class_init (EAddressbookViewClass *klass)
{
    GtkObjectClass *object_class;
    GtkWidgetClass *widget_class;

    object_class = GTK_OBJECT_CLASS(klass);
    widget_class = GTK_WIDGET_CLASS(klass);

    parent_class = gtk_type_class (gtk_table_get_type ());

    object_class->set_arg = e_addressbook_view_set_arg;
    object_class->get_arg = e_addressbook_view_get_arg;
    object_class->destroy = e_addressbook_view_destroy;

    gtk_object_add_arg_type ("EAddressbookView::book", GTK_TYPE_OBJECT,
                 GTK_ARG_READWRITE, ARG_BOOK);
    gtk_object_add_arg_type ("EAddressbookView::query", GTK_TYPE_STRING,
                 GTK_ARG_READWRITE, ARG_QUERY);
    gtk_object_add_arg_type ("EAddressbookView::type", GTK_TYPE_ENUM,
                 GTK_ARG_READWRITE, ARG_TYPE);

    e_addressbook_view_signals [STATUS_MESSAGE] =
        g_signal_new ("status_message",
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (EAddressbookViewClass, status_message),
                  NULL, NULL,
                  e_addressbook_marshal_NONE__POINTER,
                  G_TYPE_NONE, 1, G_TYPE_POINTER);

    e_addressbook_view_signals [SEARCH_RESULT] =
        g_signal_new ("search_result",
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (EAddressbookViewClass, search_result),
                  NULL, NULL,
                  e_addressbook_marshal_NONE__ENUM,
                  G_TYPE_NONE, 1, G_TYPE_ENUM);

    e_addressbook_view_signals [FOLDER_BAR_MESSAGE] =
        g_signal_new ("folder_bar_message",
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (EAddressbookViewClass, folder_bar_message),
                  NULL, NULL,
                  e_addressbook_marshal_NONE__POINTER,
                  G_TYPE_NONE, 1, G_TYPE_POINTER);

    e_addressbook_view_signals [COMMAND_STATE_CHANGE] =
        g_signal_new ("command_state_change",
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (EAddressbookViewClass, command_state_change),
                  NULL, NULL,
                  e_addressbook_marshal_NONE__NONE,
                  G_TYPE_NONE, 0);

    e_addressbook_view_signals [ALPHABET_STATE_CHANGE] =
        g_signal_new ("alphabet_state_change",
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (EAddressbookViewClass, alphabet_state_change),
                  NULL, NULL,
                  e_addressbook_marshal_NONE__UINT,
                  G_TYPE_NONE, 1, G_TYPE_UINT);


    if (!clipboard_atom)
        clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE);
}

static void
e_addressbook_view_init (EAddressbookView *eav)
{
    eav->view_type = E_ADDRESSBOOK_VIEW_NONE;

    eav->model = e_addressbook_model_new ();

    g_signal_connect (eav->model,
              "status_message",
              G_CALLBACK (status_message),
              eav);

    g_signal_connect (eav->model,
              "search_result",
              G_CALLBACK (search_result),
              eav);

    g_signal_connect (eav->model,
              "folder_bar_message",
              G_CALLBACK (folder_bar_message),
              eav);

    g_signal_connect (eav->model,
              "stop_state_changed",
              G_CALLBACK (stop_state_changed),
              eav);

    g_signal_connect (eav->model,
              "writable_status",
              G_CALLBACK (writable_status),
              eav);

    g_signal_connect (eav->model,
              "backend_died",
              G_CALLBACK (backend_died),
              eav);

    eav->editable = FALSE;
    eav->book = NULL;
    eav->query = g_strdup (SHOW_ALL_SEARCH);

    eav->object = NULL;
    eav->widget = NULL;

    eav->view_instance = NULL;
    eav->view_menus = NULL;
    eav->uic = NULL;
    eav->current_alphabet_widget = NULL;

    eav->invisible = gtk_invisible_new ();

    gtk_selection_add_target (eav->invisible,
                  clipboard_atom,
                  GDK_SELECTION_TYPE_STRING,
                  0);
        
    g_signal_connect (eav->invisible, "selection_get",
              G_CALLBACK (selection_get), 
              eav);
    g_signal_connect (eav->invisible, "selection_clear_event",
              G_CALLBACK (selection_clear_event),
              eav);
    g_signal_connect (eav->invisible, "selection_received",
              G_CALLBACK (selection_received),
              eav);
    g_signal_connect (eav->invisible, "destroy",
              G_CALLBACK (invisible_destroyed),
              eav);
}

static void
e_addressbook_view_destroy (GtkObject *object)
{
    EAddressbookView *eav = E_ADDRESSBOOK_VIEW(object);

    if (eav->model) {
        g_object_unref (eav->model);
        eav->model = NULL;
    }

    if (eav->book) {
        g_object_unref (eav->book);
        eav->book = NULL;
    }

    g_free(eav->query);
    eav->query = NULL;

    eav->uic = NULL;

    if (eav->view_instance) {
        g_object_unref (eav->view_instance);
        eav->view_instance = NULL;
    }

    if (eav->view_menus) {
        g_object_unref (eav->view_menus);
        eav->view_menus = NULL;
    }

    if (eav->clipboard_cards) {
        g_list_foreach (eav->clipboard_cards, (GFunc)g_object_unref, NULL);
        g_list_free (eav->clipboard_cards);
        eav->clipboard_cards = NULL;
    }
        
    if (eav->invisible) {
        gtk_widget_destroy (eav->invisible);
        eav->invisible = NULL;
    }

    if (GTK_OBJECT_CLASS(parent_class)->destroy)
        GTK_OBJECT_CLASS(parent_class)->destroy(object);
}

GtkWidget*
e_addressbook_view_new (void)
{
    GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_addressbook_view_get_type ()));
    return widget;
}

static void
writable_status (GtkObject *object, gboolean writable, EAddressbookView *eav)
{
    eav->editable = writable;
    command_state_change (eav);
}

static void
init_collection (void)
{
    GalViewFactory *factory;
    ETableSpecification *spec;
    char *galview;

    if (collection == NULL) {
        collection = gal_view_collection_new();

        gal_view_collection_set_title (collection, _("Addressbook"));

        galview = gnome_util_prepend_user_home("/evolution/views/addressbook/");
        gal_view_collection_set_storage_directories
            (collection,
             EVOLUTION_DATADIR "/evolution/views/addressbook/",
             galview);
        g_free(galview);

        spec = e_table_specification_new();
        e_table_specification_load_from_file (spec, EVOLUTION_ETSPECDIR "/e-addressbook-view.etspec");

        factory = gal_view_factory_etable_new (spec);
        g_object_unref (spec);
        gal_view_collection_add_factory (collection, factory);
        g_object_unref (factory);

        factory = gal_view_factory_minicard_new ();
        gal_view_collection_add_factory (collection, factory);
        g_object_unref (factory);

        gal_view_collection_load(collection);
    }
}

static void
display_view(GalViewInstance *instance,
         GalView *view,
         gpointer data)
{
    EAddressbookView *address_view = data;
    if (GAL_IS_VIEW_ETABLE(view)) {
        change_view_type (address_view, E_ADDRESSBOOK_VIEW_TABLE);
        gal_view_etable_attach_table (GAL_VIEW_ETABLE(view), e_table_scrolled_get_table(E_TABLE_SCROLLED(address_view->widget)));
    } else if (GAL_IS_VIEW_MINICARD(view)) {
        change_view_type (address_view, E_ADDRESSBOOK_VIEW_MINICARD);
        gal_view_minicard_attach (GAL_VIEW_MINICARD(view), E_MINICARD_VIEW_WIDGET (address_view->object));
    }
    address_view->current_view = view;
}

static void
setup_menus (EAddressbookView *view)
{
    if (view->book && view->view_instance == NULL) {
        init_collection ();
        view->view_instance = gal_view_instance_new (collection, e_book_get_uri (view->book));
    }

    if (view->view_instance && view->uic) {
        view->view_menus = gal_view_menus_new(view->view_instance);
        gal_view_menus_apply(view->view_menus, view->uic, NULL);

        display_view (view->view_instance, gal_view_instance_get_current_view (view->view_instance), view);

        g_signal_connect(view->view_instance, "display_view",
                 G_CALLBACK (display_view), view);
    }
}

static void
e_addressbook_view_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
    EAddressbookView *eav = E_ADDRESSBOOK_VIEW(object);

    switch (arg_id){
    case ARG_BOOK:
        if (eav->book) {
            g_object_unref (eav->book);
        }
        if (GTK_VALUE_OBJECT(*arg)) {
            eav->book = E_BOOK(GTK_VALUE_OBJECT(*arg));
            g_object_ref (eav->book);
        }
        else
            eav->book = NULL;

        if (eav->view_instance) {
            g_object_unref (eav->view_instance);
            eav->view_instance = NULL;
        }

        g_object_set(eav->model,
                 "book", eav->book,
                 NULL);

        setup_menus (eav);

        break;
    case ARG_QUERY:
#if 0 /* This code will mess up ldap a bit.  We need to think about the ramifications of this more. */
        if ((GTK_VALUE_STRING (*arg) == NULL && !strcmp (eav->query, SHOW_ALL_SEARCH)) ||
            (GTK_VALUE_STRING (*arg) != NULL && !strcmp (eav->query, GTK_VALUE_STRING (*arg))))
            break;
#endif
        g_free(eav->query);
        eav->query = g_strdup(GTK_VALUE_STRING(*arg));
        if (!eav->query)
            eav->query = g_strdup (SHOW_ALL_SEARCH);
        g_object_set(eav->model,
                 "query", eav->query,
                 NULL);
        if (eav->current_alphabet_widget != NULL) {
            GtkWidget *current = eav->current_alphabet_widget;

            eav->current_alphabet_widget = NULL;
            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (current), FALSE);
        }
        break;
    case ARG_TYPE:
        change_view_type(eav, GTK_VALUE_ENUM(*arg));
        break;
    default:
        break;
    }
}

static void
e_addressbook_view_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
    EAddressbookView *eav = E_ADDRESSBOOK_VIEW(object);

    switch (arg_id) {
    case ARG_BOOK:
        if (eav->book)
            GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(eav->book);
        else
            GTK_VALUE_OBJECT (*arg) = NULL;
        break;
    case ARG_QUERY:
        GTK_VALUE_STRING (*arg) = eav->query;
        break;
    case ARG_TYPE:
        GTK_VALUE_ENUM (*arg) = eav->view_type;
        break;
    default:
        arg->type = GTK_TYPE_INVALID;
        break;
    }
}

static ESelectionModel*
get_selection_model (EAddressbookView *view)
{
    if (view->view_type == E_ADDRESSBOOK_VIEW_MINICARD)
        return e_minicard_view_widget_get_selection_model (E_MINICARD_VIEW_WIDGET(view->object));
    else
        return e_table_get_selection_model (e_table_scrolled_get_table (E_TABLE_SCROLLED(view->widget)));
}

/* Popup menu stuff */
typedef struct {
    EAddressbookView *view;
    EPopupMenu *submenu;
    gpointer closure;
} CardAndBook;

static ESelectionModel*
card_and_book_get_selection_model (CardAndBook *card_and_book)
{
    return get_selection_model (card_and_book->view);
}

static void
card_and_book_free (CardAndBook *card_and_book)
{
    EAddressbookView *view = card_and_book->view;
    ESelectionModel *selection;

    if (card_and_book->submenu)
        gal_view_instance_free_popup_menu (view->view_instance,
                           card_and_book->submenu);

    selection = card_and_book_get_selection_model (card_and_book);
    if (selection)
        e_selection_model_right_click_up(selection);

    g_object_unref (view);
}

static void
get_card_list_1(gint model_row,
              gpointer closure)
{
    CardAndBook *card_and_book;
    GList **list;
    EAddressbookView *view;
    ECard *card;

    card_and_book = closure;
    list = card_and_book->closure;
    view = card_and_book->view;

    card = e_addressbook_model_get_card(view->model, model_row);
    *list = g_list_prepend(*list, card);
}

static GList *
get_card_list (CardAndBook *card_and_book)
{
    GList *list = NULL;
    ESelectionModel *selection;

    selection = card_and_book_get_selection_model (card_and_book);

    if (selection) {
        card_and_book->closure = &list;
        e_selection_model_foreach (selection, get_card_list_1, card_and_book);
    }

    return list;
}

static void
has_email_address_1(gint model_row,
              gpointer closure)
{
    CardAndBook *card_and_book;
    gboolean *has_email;
    EAddressbookView *view;
    const ECard *card;
    EList *email;

    card_and_book = closure;
    has_email = card_and_book->closure;
    view = card_and_book->view;

    if (*has_email)
        return;

    card = e_addressbook_model_peek_card(view->model, model_row);

    gtk_object_get (GTK_OBJECT (card),
            "email", &email,
            NULL);

    if (e_list_length (email) > 0)
        *has_email = TRUE;
}

static gboolean
get_has_email_address (CardAndBook *card_and_book)
{
    ESelectionModel *selection;
    gboolean has_email = FALSE;

    selection = card_and_book_get_selection_model (card_and_book);

    if (selection) {
        card_and_book->closure = &has_email;
        e_selection_model_foreach (selection, has_email_address_1, card_and_book);
    }

    return has_email;
}

static void
save_as (GtkWidget *widget, CardAndBook *card_and_book)
{
    GList *cards = get_card_list (card_and_book);
    if (cards) {
        e_contact_list_save_as(_("Save as VCard"), cards, NULL);
        e_free_object_list(cards);
    }
}

static void
send_as (GtkWidget *widget, CardAndBook *card_and_book)
{
    GList *cards = get_card_list (card_and_book);
    if (cards) {
        e_card_list_send(cards, E_CARD_DISPOSITION_AS_ATTACHMENT);
        e_free_object_list(cards);
    }
}

static void
send_to (GtkWidget *widget, CardAndBook *card_and_book)

{
    GList *cards = get_card_list (card_and_book);

    if (cards) {
        e_card_list_send(cards, E_CARD_DISPOSITION_AS_TO);
        e_free_object_list(cards);
    }
}

static void
print (GtkWidget *widget, CardAndBook *card_and_book)
{
#ifdef PENDING_PORT_WORK
    GList *cards = get_card_list (card_and_book);
    if (cards) {
        if (cards->next)
            gtk_widget_show(e_contact_print_card_list_dialog_new(cards));
        else
            gtk_widget_show(e_contact_print_card_dialog_new(cards->data));
        e_free_object_list(cards);
    }
#endif
}

#if 0 /* Envelope printing is disabled for Evolution 1.0. */
static void
print_envelope (GtkWidget *widget, CardAndBook *card_and_book)
{
    GList *cards = get_card_list (card_and_book);
    if (cards) {
        gtk_widget_show(e_contact_list_print_envelope_dialog_new(card_and_book->card));
        e_free_object_list(cards);
    }
}
#endif

static void
copy (GtkWidget *widget, CardAndBook *card_and_book)
{
    e_addressbook_view_copy (card_and_book->view);
}

static void
paste (GtkWidget *widget, CardAndBook *card_and_book)
{
    e_addressbook_view_paste (card_and_book->view);
}

static void
cut (GtkWidget *widget, CardAndBook *card_and_book)
{
    e_addressbook_view_cut (card_and_book->view);
}

static void
delete (GtkWidget *widget, CardAndBook *card_and_book)
{
    if (e_contact_editor_confirm_delete(GTK_WINDOW(gtk_widget_get_toplevel(card_and_book->view->widget)))) {
        EBook *book;

        GList *list = get_card_list(card_and_book);
        GList *iterator;

        gtk_object_get(GTK_OBJECT(card_and_book->view->model),
                   "book", &book,
                   NULL);

        for (iterator = list; iterator; iterator = iterator->next) {
            ECard *card = iterator->data;
            /* Remove the card. */
            e_book_remove_card (book,
                        card,
                        NULL,
                        NULL);
        }
        e_free_object_list(list);
    }
}

static void
copy_to_folder (GtkWidget *widget, CardAndBook *card_and_book)
{
    e_addressbook_view_copy_to_folder (card_and_book->view);
}

static void
move_to_folder (GtkWidget *widget, CardAndBook *card_and_book)
{
    e_addressbook_view_move_to_folder (card_and_book->view);
}

static void
free_popup_info (GtkWidget *w, CardAndBook *card_and_book)
{
    card_and_book_free (card_and_book);
}

static void
new_card (GtkWidget *widget, CardAndBook *card_and_book)
{
    EBook *book;

    gtk_object_get(GTK_OBJECT(card_and_book->view->model),
               "book", &book,
               NULL);
    e_addressbook_show_contact_editor (book, e_card_new(""), TRUE, TRUE);
}

static void
new_list (GtkWidget *widget, CardAndBook *card_and_book)
{
    EBook *book;

    gtk_object_get(GTK_OBJECT(card_and_book->view->model),
               "book", &book,
               NULL);
    e_addressbook_show_contact_list_editor (book, e_card_new(""), TRUE, TRUE);
}

#if 0
static void
sources (GtkWidget *widget, CardAndBook *card_and_book)
{
    BonoboControl *control;
    GNOME_Evolution_ShellView shell_view;
    CORBA_Environment ev;

    control = gtk_object_get_data (GTK_OBJECT (gcal), "control");
    if (control == NULL)
        return;

    shell_view = get_shell_view_interface (control);
    if (shell_view == CORBA_OBJECT_NIL)
        return;

    CORBA_exception_init (&ev);
    
    GNOME_Evolution_ShellView_showSettings (shell_view, &ev);
    
    if (BONOBO_EX (&ev))
        g_message ("control_util_show_settings(): Could not show settings");

    CORBA_exception_free (&ev);
}
#endif

#define POPUP_READONLY_MASK 0x1
#define POPUP_NOSELECTION_MASK 0x2
#define POPUP_NOEMAIL_MASK 0x4

static void
do_popup_menu(EAddressbookView *view, GdkEvent *event)
{
    CardAndBook *card_and_book;
    GtkMenu *popup;
    EPopupMenu *submenu = NULL;
    ESelectionModel *selection_model;
    gboolean selection = FALSE;

    EPopupMenu menu[] = {
        E_POPUP_ITEM (N_("New Contact..."), G_CALLBACK(new_card), POPUP_READONLY_MASK),
        E_POPUP_ITEM (N_("New Contact List..."), G_CALLBACK(new_list), POPUP_READONLY_MASK),
        E_POPUP_SEPARATOR,
#if 0
        E_POPUP_ITEM (N_("Go to Folder..."), G_CALLBACK (goto_folder), 0),
        E_POPUP_ITEM (N_("Import..."), G_CALLBACK (import), POPUP_READONLY_MASK),
        E_POPUP_SEPARATOR,
        E_POPUP_ITEM (N_("Search for Contacts..."), G_CALLBACK (search), 0),
        E_POPUP_ITEM (N_("Addressbook Sources..."), G_CALLBACK (sources), 0),
        E_POPUP_SEPARATOR,
        E_POPUP_ITEM (N_("Pilot Settings..."), G_CALLBACK (pilot_settings), 0),
#endif
        E_POPUP_SEPARATOR,
        E_POPUP_ITEM (N_("Save as VCard"), G_CALLBACK(save_as), POPUP_NOSELECTION_MASK),
        E_POPUP_ITEM (N_("Forward Contact"), G_CALLBACK(send_as), POPUP_NOSELECTION_MASK),
        E_POPUP_ITEM (N_("Send Message to Contact"), G_CALLBACK(send_to), POPUP_NOSELECTION_MASK | POPUP_NOEMAIL_MASK),
        E_POPUP_ITEM (N_("Print"), G_CALLBACK(print), POPUP_NOSELECTION_MASK),
#if 0 /* Envelope printing is disabled for Evolution 1.0. */
        E_POPUP_ITEM (N_("Print Envelope"), G_CALLBACK(print_envelope), POPUP_NOSELECTION_MASK),
#endif
        E_POPUP_SEPARATOR,

        E_POPUP_ITEM (N_("Copy to folder..."), G_CALLBACK(copy_to_folder), POPUP_NOSELECTION_MASK), 
        E_POPUP_ITEM (N_("Move to folder..."), G_CALLBACK(move_to_folder), POPUP_READONLY_MASK | POPUP_NOSELECTION_MASK),
        E_POPUP_SEPARATOR,

        E_POPUP_ITEM (N_("Cut"), G_CALLBACK (cut), POPUP_READONLY_MASK | POPUP_NOSELECTION_MASK),
        E_POPUP_ITEM (N_("Copy"), G_CALLBACK (copy), POPUP_NOSELECTION_MASK),
        E_POPUP_ITEM (N_("Paste"), G_CALLBACK (paste), POPUP_READONLY_MASK),
        E_POPUP_ITEM (N_("Delete"), G_CALLBACK(delete), POPUP_READONLY_MASK | POPUP_NOSELECTION_MASK),
        E_POPUP_SEPARATOR,

#if 0
        E_POPUP_SUBMENU (N_("Current View"), submenu = gal_view_instance_get_popup_menu (view->view_instance), 0),
#endif
        E_POPUP_TERMINATOR
    };

    card_and_book = g_new(CardAndBook, 1);
    card_and_book->view = view;
    card_and_book->submenu = submenu;

    g_object_ref (card_and_book->view);

    selection_model = card_and_book_get_selection_model (card_and_book);
    if (selection_model)
        selection = e_selection_model_selected_count (selection_model) > 0;

    popup = e_popup_menu_create (menu,
                     0,
                     (e_addressbook_model_editable (view->model) ? 0 : POPUP_READONLY_MASK) +
                     (selection ? 0 : POPUP_NOSELECTION_MASK) +
                     (get_has_email_address (card_and_book) ? 0 : POPUP_NOEMAIL_MASK),
                     card_and_book);

    g_signal_connect (popup, "selection-done",
              G_CALLBACK (free_popup_info), card_and_book);
    e_popup_menu (popup, event);

}


/* Minicard view stuff */

/* Translators: put here a list of labels you want to see on buttons in
   addressbook. You may use any character to separate labels but it must
   also be placed at the begining ot the string */
const char *button_labels = N_(",123,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z");
/* Translators: put here a list of characters that correspond to buttons
   in addressbook. You may use any character to separate labels but it
   must also be placed at the begining ot the string.
   Use lower case letters if possible. */
const char *button_letters = N_(",0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z");

typedef struct {
    EAddressbookView *view;
    GtkWidget *button;
    GtkWidget *vbox;
    gchar *letters;
} LetterClosure;

static char **
e_utf8_split (const char *utf8_str, gunichar delim)
{
    GSList *str_list = NULL, *sl;
    int n = 0;
    const char *str, *s;
    char **str_array;

    g_return_val_if_fail (utf8_str != NULL, NULL);

    str = utf8_str;
    while (*str != '\0') {
        int len;
        char *new_str;

        for (s = str; *s != '\0' && g_utf8_get_char (s) != delim; s = g_utf8_next_char (s))
            ;
        len = s - str;
        new_str = g_new (char, len + 1);
        if (len > 0) {
            memcpy (new_str, str, len);
        }
        new_str[len] = '\0';
        str_list = g_slist_prepend (str_list, new_str);
        n++;
        if (*s != '\0') {
            str = g_utf8_next_char (s);
        } else {
            str = s;
        }       
    }

    str_array = g_new (char *, n + 1);
    str_array[n--] = NULL;
    for (sl = str_list; sl != NULL; sl = sl->next) {
        str_array[n--] = sl->data;
    }
    g_slist_free (str_list);

    return str_array;
}

static void
jump_to_letters (EAddressbookView *view, gchar* l)
{
    char *query;
    char *s;
    char buf[6 + 1];

    if (g_unichar_isdigit (g_utf8_get_char(l))) {
        const char *letters = _(button_letters);
        char **letter_v;
        GString *gstr;
        char **p;

        letter_v = e_utf8_split (g_utf8_next_char (letters),
                                 g_utf8_get_char (letters));
        g_assert (letter_v != NULL && letter_v[0] != NULL);
        gstr = g_string_new ("(not (or ");
        for (p = letter_v + 1; *p != NULL; p++) {
            for (s = *p; *s != '\0'; s = g_utf8_next_char (s)) {
                buf [g_unichar_to_utf8 (g_utf8_get_char(s), buf)] = '\0';
                g_string_sprintfa (gstr, "(beginswith \"file_as\" \"%s\")", buf);
            }
        }
        g_string_append (gstr, "))");
        query = gstr->str;
        g_strfreev (letter_v);
        g_string_free (gstr, FALSE);
    } else {
        GString *gstr;

        gstr = g_string_new ("(or ");

        for (s = l; *s != '\0'; s = g_utf8_next_char (s)) {
            buf [g_unichar_to_utf8 (g_utf8_get_char(s), buf)] = '\0';
            g_string_sprintfa (gstr, "(beginswith \"file_as\" \"%s\")", buf);
        }

        g_string_append (gstr, ")");
        query = gstr->str;
        g_string_free (gstr, FALSE);
    }
    g_object_set (view,
              "query", query,
              NULL);
    g_free (query);
}

static void
button_toggled(GtkWidget *button, LetterClosure *closure)
{
    EAddressbookView *view = closure->view;

    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
        GtkWidget *current = view->current_alphabet_widget;

        view->current_alphabet_widget = NULL;
        if (current && current != button)
            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (current), FALSE);
        jump_to_letters (view, closure->letters);
        view->current_alphabet_widget = button;
        alphabet_state_change (view, g_utf8_get_char(closure->letters));
    } else {
        if (view->current_alphabet_widget != NULL &&
            view->current_alphabet_widget == button) {
            view->current_alphabet_widget = NULL;
            g_object_set (view,
                      "query", NULL,
                      NULL);
            alphabet_state_change (view, 0);
        }
    }
}

static void
free_closure(GtkWidget *button, LetterClosure *closure)
{
    if (button != NULL &&
        button == closure->view->current_alphabet_widget) {
        closure->view->current_alphabet_widget = NULL;
    }
    g_free (closure->letters);
    g_free (closure);
}

static GtkWidget *
create_alphabet (EAddressbookView *view)
{
    GtkWidget *widget, *viewport, *vbox;
    const char *labels, *letters;
    char **label_v, **letter_v;
    char **pl, **pc;
    gunichar sep;

    widget = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (widget),
                                    GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

    viewport = gtk_viewport_new (NULL, NULL);
    gtk_container_add (GTK_CONTAINER (widget), viewport);
    gtk_container_set_border_width (GTK_CONTAINER (viewport), 4);
    gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);

    vbox = gtk_vbox_new (FALSE, 4);
    gtk_container_add (GTK_CONTAINER (viewport), vbox);
    gtk_widget_set_usize (vbox, 27, 0);

    labels = _(button_labels);
    sep = g_utf8_get_char (labels);
    label_v = e_utf8_split (g_utf8_next_char (labels), sep);
    letters = _(button_letters);
    sep = g_utf8_get_char (letters);
    letter_v = e_utf8_split (g_utf8_next_char (letters), sep);
    g_assert (label_v != NULL && letter_v != NULL);
    for (pl = label_v, pc = letter_v; *pl != NULL && *pc != NULL; pl++, pc++) {
        GtkWidget *button;
        LetterClosure *closure;
        char *label;

        label = e_utf8_to_locale_string (*pl);
        button = gtk_toggle_button_new_with_label (label);
        g_free (label);
        gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

        closure = g_new (LetterClosure, 1);
        closure->view = view;
        closure->letters = g_strdup (*pc);
        closure->button = button;
        closure->vbox = vbox;
        g_signal_connect(button, "toggled",
                 G_CALLBACK (button_toggled), closure);
        g_signal_connect(button, "destroy",
                 G_CALLBACK (free_closure), closure);

    }
    g_strfreev (label_v);
    g_strfreev (letter_v);

    gtk_widget_show_all (widget);

    return widget;
}

static void
minicard_selection_change (EMinicardViewWidget *widget, EAddressbookView *view)
{
    command_state_change (view);
}

static void
minicard_button_press (GtkWidget *widget, GdkEventButton *event, EAddressbookView *view)
{
    d(g_print ("Button %d pressed with event type %d\n", event->button, event->type));
}

static void
minicard_right_click (EMinicardView *minicard_view_item, GdkEvent *event, EAddressbookView *view)
{
    do_popup_menu(view, event);
}

static void
create_minicard_view (EAddressbookView *view)
{
    GtkWidget *scrollframe;
    GtkWidget *alphabet;
    GtkWidget *minicard_view;
    GtkWidget *minicard_hbox;
    EAddressbookReflowAdapter *adapter;

    gtk_widget_push_visual (gdk_rgb_get_visual ());
    gtk_widget_push_colormap (gdk_rgb_get_cmap ());

    minicard_hbox = gtk_hbox_new(FALSE, 0);

    adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(e_addressbook_reflow_adapter_new (view->model));
    minicard_view = e_minicard_view_widget_new(adapter);

    /* A hack */
    g_object_set_data (G_OBJECT (adapter), "view", view);

    g_signal_connect(minicard_view, "selection_change",
             G_CALLBACK(minicard_selection_change), view);

    g_signal_connect(minicard_view, "button_press_event",
             G_CALLBACK(minicard_button_press), view);

    g_signal_connect(minicard_view, "right_click",
             G_CALLBACK(minicard_right_click), view);


    view->object = GTK_OBJECT(minicard_view);
    view->widget = minicard_hbox;

    scrollframe = e_scroll_frame_new (NULL, NULL);
    e_scroll_frame_set_policy (E_SCROLL_FRAME (scrollframe),
                   GTK_POLICY_AUTOMATIC,
                   GTK_POLICY_AUTOMATIC);

    gtk_container_add (GTK_CONTAINER (scrollframe), minicard_view);


    gtk_box_pack_start(GTK_BOX(minicard_hbox), scrollframe, TRUE, TRUE, 0);

    alphabet = create_alphabet(view);
    if (alphabet) {
        g_object_ref (alphabet);
        gtk_widget_unparent(alphabet);
        gtk_box_pack_start(GTK_BOX(minicard_hbox), alphabet, FALSE, FALSE, 0);
        g_object_unref (alphabet);
    }

    gtk_table_attach(GTK_TABLE(view), minicard_hbox,
             0, 1,
             0, 1,
             GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND,
             0, 0);

    gtk_widget_show_all( GTK_WIDGET(minicard_hbox) );

    gtk_widget_pop_visual ();
    gtk_widget_pop_colormap ();

    e_reflow_model_changed (E_REFLOW_MODEL (adapter));

    g_object_unref (adapter);
}

static void
table_double_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, EAddressbookView *view)
{
    if (E_IS_ADDRESSBOOK_TABLE_ADAPTER(view->object)) {
        EAddressbookModel *model = view->model;
        ECard *card = e_addressbook_model_get_card(model, row);
        EBook *book;

        gtk_object_get(GTK_OBJECT(model),
                   "book", &book,
                   NULL);
        
        g_assert (E_IS_BOOK (book));

        if (e_card_evolution_list (card))
            e_addressbook_show_contact_list_editor (book, card, FALSE, view->editable);
        else
            e_addressbook_show_contact_editor (book, card, FALSE, view->editable);
    }
}

static gint
table_right_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, EAddressbookView *view)
{
    do_popup_menu(view, event);
    return TRUE;
}

static gint
table_white_space_event(ETableScrolled *table, GdkEvent *event, EAddressbookView *view)
{
    if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton *)event)->button == 3) {
        do_popup_menu(view, event);
        return TRUE;
    } else {
        return FALSE;
    }
}

static void
table_selection_change(ETableScrolled *table, EAddressbookView *view)
{
    command_state_change (view);
}

static void
table_drag_data_get (ETable             *table,
             int                 row,
             int                 col,
             GdkDragContext     *context,
             GtkSelectionData   *selection_data,
             guint               info,
             guint               time,
             gpointer            user_data)
{
    EAddressbookView *view = user_data;

    if (!E_IS_ADDRESSBOOK_TABLE_ADAPTER(view->object))
        return;

    switch (info) {
    case DND_TARGET_TYPE_VCARD: {
        char *value;

        row = e_table_view_to_model_row (table, row);
        value = e_card_get_vcard(view->model->data[row]);

        gtk_selection_data_set (selection_data,
                    selection_data->target,
                    8,
                    value, strlen (value));
        break;
    }
    }
}

static void
emit_status_message (EAddressbookView *eav, const gchar *status)
{
    g_signal_emit (eav,
               e_addressbook_view_signals [STATUS_MESSAGE], 0,
               status);
}

static void
emit_search_result (EAddressbookView *eav, EBookViewStatus status)
{
    g_signal_emit (eav,
               e_addressbook_view_signals [SEARCH_RESULT], 0,
               status);
}

static void
emit_folder_bar_message (EAddressbookView *eav, const gchar *message)
{
    g_signal_emit (eav,
               e_addressbook_view_signals [FOLDER_BAR_MESSAGE], 0,
               message);
}

static void
status_message (GtkObject *object, const gchar *status, EAddressbookView *eav)
{
    emit_status_message (eav, status);
}

static void
search_result (GtkObject *object, EBookViewStatus status, EAddressbookView *eav)
{
    emit_search_result (eav, status);
}

static void
folder_bar_message (GtkObject *object, const gchar *status, EAddressbookView *eav)
{
    emit_folder_bar_message (eav, status);
}

static void
stop_state_changed (GtkObject *object, EAddressbookView *eav)
{
    command_state_change (eav);
}

static void
command_state_change (EAddressbookView *eav)
{
    /* Reffing during emission is unnecessary.  Gtk automatically refs during an emission. */
    g_signal_emit (eav, e_addressbook_view_signals [COMMAND_STATE_CHANGE], 0);
}

static void
alphabet_state_change (EAddressbookView *eav, gunichar letter)
{
    g_signal_emit (eav, e_addressbook_view_signals [ALPHABET_STATE_CHANGE], 0, letter);
}

static void
backend_died (GtkObject *object, EAddressbookView *eav)
{
    char *message = g_strdup_printf (_("The addressbook backend for\n%s\nhas crashed. "
                       "You will have to restart Evolution in order "
                       "to use it again"),
                     e_book_get_uri (eav->book));
        gnome_error_dialog_parented (message, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (eav))));
        g_free (message);
}

static void
create_table_view (EAddressbookView *view)
{
    ETableModel *adapter;
    ECardSimple *simple;
    GtkWidget *table;
    
    simple = e_card_simple_new(NULL);

    adapter = e_addressbook_table_adapter_new(view->model);

    /* Here we create the table.  We give it the three pieces of
       the table we've created, the header, the model, and the
       initial layout.  It does the rest.  */
    table = e_table_scrolled_new_from_spec_file (adapter, NULL, EVOLUTION_ETSPECDIR "/e-addressbook-view.etspec", NULL);

    view->object = GTK_OBJECT(adapter);
    view->widget = table;

    g_signal_connect(e_table_scrolled_get_table(E_TABLE_SCROLLED(table)), "double_click",
             G_CALLBACK(table_double_click), view);
    g_signal_connect(e_table_scrolled_get_table(E_TABLE_SCROLLED(table)), "right_click",
             G_CALLBACK(table_right_click), view);
    g_signal_connect(e_table_scrolled_get_table(E_TABLE_SCROLLED(table)), "white_space_event",
             G_CALLBACK(table_white_space_event), view);
    g_signal_connect(e_table_scrolled_get_table(E_TABLE_SCROLLED(table)), "selection_change",
             G_CALLBACK(table_selection_change), view);

    /* drag & drop signals */
    e_table_drag_source_set (E_TABLE(E_TABLE_SCROLLED(table)->table), GDK_BUTTON1_MASK,
                 drag_types, num_drag_types, GDK_ACTION_MOVE);
    
    g_signal_connect (E_TABLE_SCROLLED(table)->table,
              "table_drag_data_get",
              G_CALLBACK (table_drag_data_get),
              view);

    gtk_table_attach(GTK_TABLE(view), table,
             0, 1,
             0, 1,
             GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND,
             0, 0);

    gtk_widget_show( GTK_WIDGET(table) );

    g_object_unref (simple);
}


static void
change_view_type (EAddressbookView *view, EAddressbookViewType view_type)
{
    if (view_type == view->view_type)
        return;

    if (view->widget) {
        gtk_widget_destroy (view->widget);
        view->widget = NULL;
    }
    view->object = NULL;

    switch (view_type) {
    case E_ADDRESSBOOK_VIEW_MINICARD:
        create_minicard_view (view);
        break;
    case E_ADDRESSBOOK_VIEW_TABLE:
        create_table_view (view);
        break;
    default:
        g_warning ("view_type must be either TABLE or MINICARD\n");
        return;
    }

    view->view_type = view_type;

    command_state_change (view);
}

static void
e_contact_print_destroy(GnomeDialog *dialog, gpointer data)
{
    ETableScrolled *table = gtk_object_get_data(GTK_OBJECT(dialog), "table");
    EPrintable *printable = gtk_object_get_data(GTK_OBJECT(dialog), "printable");
    g_object_unref (printable);
    g_object_unref (table);
}

static void
e_contact_print_button(GnomeDialog *dialog, gint button, gpointer data)
{
    GnomePrintMaster *master;
    GnomePrintContext *pc;
    EPrintable *printable = gtk_object_get_data(GTK_OBJECT(dialog), "printable");
    GtkWidget *preview;
    switch( button ) {
    case GNOME_PRINT_DIALOG_RESPONSE_PRINT:
        master = gnome_print_master_new_from_config (gnome_print_dialog_get_config ( GNOME_PRINT_DIALOG(dialog) ));
        pc = gnome_print_master_get_context( master );
        e_printable_reset(printable);
        while (e_printable_data_left(printable)) {
            if (gnome_print_gsave(pc) == -1)
                /* FIXME */;
            if (gnome_print_translate(pc, 72, 72) == -1)
                /* FIXME */;
            e_printable_print_page(printable,
                           pc,
                           6.5 * 72,
                           5 * 72,
                           TRUE);
            if (gnome_print_grestore(pc) == -1)
                /* FIXME */;
            if (gnome_print_showpage(pc) == -1)
                /* FIXME */;
        }
        gnome_print_master_close(master);
        gnome_print_master_print(master);
        g_object_unref (master);
        gnome_dialog_close(dialog);
        break;
    case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
        master = gnome_print_master_new_from_config (gnome_print_dialog_get_config ( GNOME_PRINT_DIALOG(dialog) ));
        pc = gnome_print_master_get_context( master );
        e_printable_reset(printable);
        while (e_printable_data_left(printable)) {
            if (gnome_print_gsave(pc) == -1)
                /* FIXME */;
            if (gnome_print_translate(pc, 72, 72) == -1)
                /* FIXME */;
            e_printable_print_page(printable,
                           pc,
                           6.5 * 72,
                           9 * 72,
                           TRUE);
            if (gnome_print_grestore(pc) == -1)
                /* FIXME */;
            if (gnome_print_showpage(pc) == -1)
                /* FIXME */;
        }
        gnome_print_master_close(master);
        preview = GTK_WIDGET(gnome_print_master_preview_new(master, "Print Preview"));
        gtk_widget_show_all(preview);
        g_object_unref (master);
        break;
    case GNOME_PRINT_DIALOG_RESPONSE_CANCEL:
        gnome_dialog_close(dialog);
        break;
    }
}

void
e_addressbook_view_setup_menus (EAddressbookView *view,
                BonoboUIComponent *uic)
{

    g_return_if_fail (view != NULL);
    g_return_if_fail (E_IS_ADDRESSBOOK_VIEW (view));
    g_return_if_fail (uic != NULL);
    g_return_if_fail (BONOBO_IS_UI_COMPONENT (uic));

    init_collection ();

    view->uic = uic;

    setup_menus (view);
}

/**
 * e_addressbook_view_discard_menus:
 * @view: An addressbook view.
 * 
 * Makes an addressbook view discard its GAL view menus and its views instance
 * objects.  This should be called when the corresponding Bonobo component is
 * deactivated.
 **/
void
e_addressbook_view_discard_menus (EAddressbookView *view)
{
    g_return_if_fail (view != NULL);
    g_return_if_fail (E_IS_ADDRESSBOOK_VIEW (view));
    g_return_if_fail (view->view_instance);

    if (view->view_menus) {
        gal_view_menus_unmerge (view->view_menus, NULL);

        g_object_unref (view->view_menus);
        view->view_menus = NULL;
    }

    if (view->view_instance) {
        g_object_unref (view->view_instance);
        view->view_instance = NULL;
    }

    view->uic = NULL;
}

void
e_addressbook_view_print(EAddressbookView *view)
{
#ifdef PENDING_PORT_WORK
    if (view->view_type == E_ADDRESSBOOK_VIEW_MINICARD) {
        char *query;
        EBook *book;
        GtkWidget *print;

        gtk_object_get (GTK_OBJECT(view->model),
                "query", &query,
                "book", &book,
                NULL);
        print = e_contact_print_dialog_new(book, query);
        g_free(query);
        gtk_widget_show_all(print);
    } else if (view->view_type == E_ADDRESSBOOK_VIEW_TABLE) {
        GtkWidget *dialog;
        EPrintable *printable;
        ETable *etable;

        dialog = gnome_print_dialog_new("Print cards", GNOME_PRINT_DIALOG_RANGE | GNOME_PRINT_DIALOG_COPIES);
        gnome_print_dialog_construct_range_any(GNOME_PRINT_DIALOG(dialog), GNOME_PRINT_RANGE_ALL | GNOME_PRINT_RANGE_SELECTION,
                               NULL, NULL, NULL);

        gtk_object_get(GTK_OBJECT(view->widget), "table", &etable, NULL);
        printable = e_table_get_printable(etable);

        g_object_ref (view->widget);

        g_object_set_data (G_OBJECT (dialog), "table", view->widget);
        g_object_set_data (G_OBJECT (dialog), "printable", printable);
        
        g_signal_connect(dialog,
                 "clicked", G_CALLBACK(e_contact_print_button), NULL);
        g_signal_connect(dialog,
                 "destroy", G_CALLBACK(e_contact_print_destroy), NULL);
        g_widget_show(dialog);
    }
#endif
}

void
e_addressbook_view_print_preview(EAddressbookView *view)
{
#ifdef PENDING_PORT_WORK
    if (view->view_type == E_ADDRESSBOOK_VIEW_MINICARD) {
        char *query;
        EBook *book;

        gtk_object_get (GTK_OBJECT(view->model),
                "query", &query,
                "book", &book,
                NULL);
        e_contact_print_preview(book, query);
        g_free(query);
    } else if (view->view_type == E_ADDRESSBOOK_VIEW_TABLE) {
        EPrintable *printable;
        ETable *etable;
        GnomePrintMaster *master;
        GnomePrintContext *pc;
        GtkWidget *preview;

        gtk_object_get(GTK_OBJECT(view->widget), "table", &etable, NULL);
        printable = e_table_get_printable(etable);

        master = gnome_print_master_new();
        gnome_print_master_set_copies (master, 1, FALSE);
        pc = gnome_print_master_get_context( master );
        e_printable_reset(printable);
        while (e_printable_data_left(printable)) {
            if (gnome_print_gsave(pc) == -1)
                /* FIXME */;
            if (gnome_print_translate(pc, 72, 72) == -1)
                /* FIXME */;
            e_printable_print_page(printable,
                           pc,
                           6.5 * 72,
                           9 * 72,
                           TRUE);
            if (gnome_print_grestore(pc) == -1)
                /* FIXME */;
            if (gnome_print_showpage(pc) == -1)
                /* FIXME */;
        }
        gnome_print_master_close(master);
        preview = GTK_WIDGET(gnome_print_master_preview_new(master, "Print Preview"));
        gtk_widget_show_all(preview);
        g_object_unref (master);
        g_object_unref (printable);
    }
#endif
}

static void
card_deleted_cb (EBook* book, EBookStatus status, gpointer user_data)
{
    if (status != E_BOOK_STATUS_SUCCESS) {
        e_addressbook_error_dialog (_("Error removing card"), status);
    }
}

static void
do_remove (int i, gpointer user_data)
{
    EBook *book;
    ECard *card;
    EAddressbookView *view = user_data;

    gtk_object_get (GTK_OBJECT(view->model),
            "book", &book,
            NULL);

    card = e_addressbook_model_get_card (view->model, i);

    e_book_remove_card(book, card, card_deleted_cb, view);

    g_object_unref (card);
}

void
e_addressbook_view_delete_selection(EAddressbookView *view)
{
    ESelectionModel *model = get_selection_model (view);

    g_return_if_fail (model);

    e_selection_model_foreach (model,
                   do_remove,
                   view);
}

static void
invisible_destroyed (GtkWidget *invisible, EAddressbookView *view)
{
    view->invisible = NULL;
}

static void
selection_get (GtkWidget *invisible,
           GtkSelectionData *selection_data,
           guint info,
           guint time_stamp,
           EAddressbookView *view)
{
    char *value;

    value = e_card_list_get_vcard(view->clipboard_cards);

    gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING,
                8, value, strlen (value));
                
}

static void
selection_clear_event (GtkWidget *invisible,
               GdkEventSelection *event,
               EAddressbookView *view)
{
    if (view->clipboard_cards) {
        g_list_foreach (view->clipboard_cards, (GFunc)g_object_unref, NULL);
        g_list_free (view->clipboard_cards);
        view->clipboard_cards = NULL;
    }
}

static void
selection_received (GtkWidget *invisible,
            GtkSelectionData *selection_data,
            guint time,
            EAddressbookView *view)
{
    if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) {
        return;
    }
    else {
        /* XXX make sure selection_data->data = \0 terminated */
        GList *card_list = e_card_load_cards_from_string_with_default_charset (selection_data->data, "ISO-8859-1");
        GList *l;
        
        if (!card_list /* it wasn't a vcard list */)
            return;

        for (l = card_list; l; l = l->next) {
            ECard *card = l->data;

            e_card_merging_book_add_card (view->book, card, NULL /* XXX */, NULL);
        }

        g_list_foreach (card_list, (GFunc)g_object_unref, NULL);
        g_list_free (card_list);
    }
}

static void
add_to_list (int model_row, gpointer closure)
{
    GList **list = closure;
    *list = g_list_prepend (*list, GINT_TO_POINTER (model_row));
}

static GList *
get_selected_cards (EAddressbookView *view)
{
    GList *list;
    GList *iterator;
    ESelectionModel *selection = get_selection_model (view);

    list = NULL;
    e_selection_model_foreach (selection, add_to_list, &list);

    for (iterator = list; iterator; iterator = iterator->next) {
        iterator->data = e_addressbook_model_card_at (view->model, GPOINTER_TO_INT (iterator->data));
        if (iterator->data)
            g_object_ref (iterator->data);
    }
    list = g_list_reverse (list);
    return list;
}

#if 0
void
e_addressbook_view_save_state (EAddressbookView *view, const char *filename)
{
    xmlDoc *doc;
    xmlNode *node;