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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* Evolution calendar - Alarm page of the calendar component dialogs
*
* Copyright (C) 2001-2003 Ximian, Inc.
*
* Authors: Federico Mena-Quintero <federico@ximian.com>
* Miguel de Icaza <miguel@ximian.com>
* Seth Alves <alves@hungry.com>
* JP Rosevear <jpr@ximian.com>
* Hans Petter Jansson <hpj@ximian.com>
*
* This program 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 program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtksignal.h>
#include <gtk/gtktreeview.h>
#include <gtk/gtktreeselection.h>
#include <gtk/gtkoptionmenu.h>
#include <glib/gi18n.h>
#include <glade/glade.h>
#include <libedataserver/e-time-utils.h>
#include "e-util/e-dialog-widgets.h"
#include <libecal/e-cal-util.h>
#include <libecal/e-cal-time-util.h>
#include "e-util/e-dialog-widgets.h"
#include "e-util/e-icon-factory.h"
#include "e-util/e-util-private.h"
#include "alarm-dialog.h"
#include "alarm-list-dialog.h"
typedef struct {
/* Glade XML data */
GladeXML *xml;
/* The client */
ECal *ecal;
/* The list store */
EAlarmList *list_store;
/* Toplevel */
GtkWidget *toplevel;
GtkWidget *list;
GtkWidget *add;
GtkWidget *edit;
GtkWidget *delete;
GtkWidget *box;
} Dialog;
/* Gets the widgets from the XML file and returns TRUE if they are all available. */
static gboolean
get_widgets (Dialog *dialog)
{
#define GW(name) glade_xml_get_widget (dialog->xml, name)
dialog->toplevel = GW ("alarm-list-dialog");
if (!dialog->toplevel)
return FALSE;
dialog->box = GW ("vbox53");
dialog->list = GW ("list");
dialog->add = GW ("add");
dialog->edit = GW ("edit");
dialog->delete = GW ("delete");
#undef GW
return (dialog->list
&& dialog->add
&& dialog->edit
&& dialog->delete);
}
static void
sensitize_buttons (Dialog *dialog)
{
GtkTreeSelection *selection;
GtkTreeIter iter;
gboolean have_selected, read_only = FALSE;
GError *error = NULL;
if (!e_cal_is_read_only (dialog->ecal, &read_only, &error)) {
if (error->code != E_CALENDAR_STATUS_BUSY)
read_only = TRUE;
g_error_free (error);
}
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list));
have_selected = gtk_tree_selection_get_selected (selection, NULL, &iter);
if ((e_cal_get_one_alarm_only (dialog->ecal) && have_selected) || read_only)
gtk_widget_set_sensitive (dialog->add, FALSE);
else
gtk_widget_set_sensitive (dialog->add, TRUE);
gtk_widget_set_sensitive (dialog->delete, have_selected && !read_only);
gtk_widget_set_sensitive (dialog->edit, have_selected && !read_only);
}
/* Callback used for the "add reminder" button */
static void
add_clicked_cb (GtkButton *button, gpointer data)
{
Dialog *dialog = data;
ECalComponentAlarm *alarm;
GtkTreeView *view;
GtkTreeIter iter;
icalcomponent *icalcomp;
icalproperty *icalprop;
view = GTK_TREE_VIEW (dialog->list);
alarm = e_cal_component_alarm_new ();
icalcomp = e_cal_component_alarm_get_icalcomponent (alarm);
icalprop = icalproperty_new_x ("1");
icalproperty_set_x_name (icalprop, "X-EVOLUTION-NEEDS-DESCRIPTION");
icalcomponent_add_property (icalcomp, icalprop);
if (alarm_dialog_run (dialog->toplevel, dialog->ecal, alarm)) {
e_alarm_list_append (dialog->list_store, &iter, alarm);
gtk_tree_selection_select_iter (gtk_tree_view_get_selection (view), &iter);
} else {
e_cal_component_alarm_free (alarm);
}
sensitize_buttons (dialog);
}
/* Callback used for the "edit reminder" button */
static void
edit_clicked_cb (GtkButton *button, gpointer data)
{
Dialog *dialog = data;
GtkTreeSelection *selection;
GtkTreeIter iter;
GtkTreePath *path;
ECalComponentAlarm *alarm;
GtkTreeView *view;
view = GTK_TREE_VIEW (dialog->list);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list));
if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
g_warning ("Could not get a selection to delete.");
return;
}
alarm = (ECalComponentAlarm *)e_alarm_list_get_alarm (dialog->list_store, &iter);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->list_store), &iter);
if (alarm_dialog_run (dialog->toplevel, dialog->ecal, alarm)) {
gtk_tree_selection_select_iter (gtk_tree_view_get_selection (view), &iter);
gtk_tree_model_row_changed (GTK_TREE_MODEL (dialog->list_store), path, &iter);
}
}
/* Callback used for the "delete reminder" button */
static void
delete_clicked_cb (GtkButton *button, gpointer data)
{
Dialog *dialog = data;
GtkTreeSelection *selection;
GtkTreeIter iter;
GtkTreePath *path;
gboolean valid_iter;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list));
if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
g_warning ("Could not get a selection to delete.");
return;
}
path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->list_store), &iter);
e_alarm_list_remove (dialog->list_store, &iter);
/* Select closest item after removal */
valid_iter = gtk_tree_model_get_iter (GTK_TREE_MODEL (dialog->list_store), &iter, path);
if (!valid_iter) {
gtk_tree_path_prev (path);
valid_iter = gtk_tree_model_get_iter (GTK_TREE_MODEL (dialog->list_store), &iter, path);
}
if (valid_iter)
gtk_tree_selection_select_iter (selection, &iter);
sensitize_buttons (dialog);
gtk_tree_path_free (path);
}
static void
selection_changed_cb (GtkTreeSelection *selection, gpointer data)
{
Dialog *dialog = data;
sensitize_buttons (dialog);
}
void
alarm_list_dialog_set_client (GtkWidget *dlg_box, ECal *client)
{
Dialog *dialog;
if (!dlg_box) return;
dialog = g_object_get_data (G_OBJECT (dlg_box), "dialog");
if (dialog) {
dialog->ecal = client;
sensitize_buttons (dialog);
}
}
/* Hooks the widget signals */
static void
init_widgets (Dialog *dialog)
{
GtkTreeViewColumn *column;
GtkCellRenderer *cell_renderer;
/* View */
gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->list),
GTK_TREE_MODEL (dialog->list_store));
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, _("Action/Trigger"));
cell_renderer = GTK_CELL_RENDERER (gtk_cell_renderer_text_new ());
gtk_tree_view_column_pack_start (column, cell_renderer, TRUE);
gtk_tree_view_column_add_attribute (column, cell_renderer, "text", E_ALARM_LIST_COLUMN_DESCRIPTION);
gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->list), column);
/* Reminder buttons */
g_signal_connect (dialog->add, "clicked",
G_CALLBACK (add_clicked_cb), dialog);
g_signal_connect (dialog->delete, "clicked",
G_CALLBACK (delete_clicked_cb), dialog);
g_signal_connect (dialog->edit, "clicked",
G_CALLBACK (edit_clicked_cb), dialog);
g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list)), "changed",
G_CALLBACK (selection_changed_cb), dialog);
}
gboolean
alarm_list_dialog_run (GtkWidget *parent, ECal *ecal, EAlarmList *list_store)
{
Dialog dialog;
int response_id;
GList *icon_list;
char *gladefile;
dialog.ecal = ecal;
dialog.list_store = list_store;
gladefile = g_build_filename (EVOLUTION_GLADEDIR,
"alarm-list-dialog.glade",
NULL);
dialog.xml = glade_xml_new (gladefile, NULL, NULL);
g_free (gladefile);
if (!dialog.xml) {
g_message (G_STRLOC ": Could not load the Glade XML file!");
return FALSE;
}
if (!get_widgets (&dialog)) {
g_object_unref(dialog.xml);
return FALSE;
}
init_widgets (&dialog);
sensitize_buttons (&dialog);
gtk_widget_ensure_style (dialog.toplevel);
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog.toplevel)->vbox), 0);
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog.toplevel)->action_area), 12);
icon_list = e_icon_factory_get_icon_list ("stock_calendar");
if (icon_list) {
gtk_window_set_icon_list (GTK_WINDOW (dialog.toplevel), icon_list);
g_list_foreach (icon_list, (GFunc) g_object_unref, NULL);
g_list_free (icon_list);
}
gtk_window_set_transient_for (GTK_WINDOW (dialog.toplevel),
GTK_WINDOW (parent));
response_id = gtk_dialog_run (GTK_DIALOG (dialog.toplevel));
gtk_widget_hide (dialog.toplevel);
gtk_widget_destroy (dialog.toplevel);
g_object_unref (dialog.xml);
return response_id == GTK_RESPONSE_OK ? TRUE : FALSE;
}
GtkWidget *
alarm_list_dialog_peek (ECal *ecal, EAlarmList *list_store)
{
Dialog *dialog;
char *gladefile;
dialog = (Dialog *)g_new (Dialog, 1);
dialog->ecal = ecal;
dialog->list_store = list_store;
gladefile = g_build_filename (EVOLUTION_GLADEDIR,
"alarm-list-dialog.glade",
NULL);
dialog->xml = glade_xml_new (gladefile, NULL, NULL);
g_free (gladefile);
if (!dialog->xml) {
g_message (G_STRLOC ": Could not load the Glade XML file!");
return NULL;
}
if (!get_widgets (dialog)) {
g_object_unref(dialog->xml);
return NULL;
}
init_widgets (dialog);
sensitize_buttons (dialog);
g_object_unref (dialog->xml);
/* Free the other stuff when the parent really gets destroyed. */
g_object_set_data_full (G_OBJECT (dialog->box), "toplevel", dialog->toplevel, (GDestroyNotify) gtk_widget_destroy);
g_object_set_data_full (G_OBJECT (dialog->box), "dialog", dialog, g_free);
return dialog->box;
}
|