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
|
/* Evolution calendar - Command-line client for the alarm notification service
*
* Copyright (C) 2001 Ximian, Inc.
*
* Authors: Federico Mena-Quintero <federico@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 Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <liboaf/liboaf.h>
#include <gnome.h>
#include <bonobo.h>
#include "evolution-calendar.h"
/* Requests that a calendar be added to the alarm notification service */
static void
add_calendar (GNOME_Evolution_Calendar_AlarmNotify an, const char *uri)
{
CORBA_Environment ev;
CORBA_exception_init (&ev);
GNOME_Evolution_Calendar_AlarmNotify_addCalendar (an, uri, &ev);
if (ev._major == CORBA_USER_EXCEPTION) {
char *ex_id;
ex_id = CORBA_exception_id (&ev);
if (strcmp (ex_id, ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI) == 0) {
g_message ("add_calendar(): Invalid URI reported from the "
"alarm notification service");
goto out;
} else if (strcmp (ex_id,
ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError)
== 0) {
g_message ("add_calendar(): The alarm notification service could "
"not contact the backend");
goto out;
}
}
if (ev._major != CORBA_NO_EXCEPTION)
g_message ("add_calendar(): Could not issue the addCalendar request");
out:
CORBA_exception_free (&ev);
}
/* Loads the calendars that the user has configured to be loaded */
static void
load_calendars (void)
{
CORBA_Environment ev;
GNOME_Evolution_Calendar_AlarmNotify an;
char *base_uri;
char *uri;
CORBA_exception_init (&ev);
an = oaf_activate_from_id ("OAFID:GNOME_Evolution_Calendar_AlarmNotify", 0, NULL, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_message ("load_calendars(): Could not activate the alarm notification service");
CORBA_exception_free (&ev);
exit (EXIT_FAILURE);
}
CORBA_exception_free (&ev);
/* FIXME: this should be obtained from the configuration in the Wombat */
base_uri = g_concat_dir_and_file (g_get_home_dir (), "evolution");
uri = g_concat_dir_and_file (base_uri, "local/Calendar/calendar.ics");
add_calendar (an, uri);
g_free (uri);
uri = g_concat_dir_and_file (base_uri, "local/Tasks/tasks.ics");
add_calendar (an, uri);
g_free (uri);
g_free (base_uri);
CORBA_exception_init (&ev);
Bonobo_Unknown_unref (an, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
g_message ("load_calendars(): Could not unref the alarm notification service");
CORBA_exception_free (&ev);
CORBA_exception_init (&ev);
CORBA_Object_release (an, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
g_message ("load_calendars(): Could not release the alarm notification service");
CORBA_exception_free (&ev);
}
/* FIXME: handle the --die option */
int
main (int argc, char **argv)
{
GnomeClient *client;
int flags;
gboolean launch_service;
bindtextdomain (PACKAGE, EVOLUTION_LOCALEDIR);
textdomain (PACKAGE);
if (gnome_init_with_popt_table ("evolution-alarm-client", VERSION,
argc, argv, oaf_popt_options, 0, NULL) != 0) {
g_message ("main(): Could not initialize GNOME");
exit (EXIT_FAILURE);
}
oaf_init (argc, argv);
if (!bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) {
g_message ("main(): Could not initialize Bonobo");
exit (EXIT_FAILURE);
}
/* Ask the session manager to restart us */
client = gnome_master_client ();
flags = gnome_client_get_flags (client);
if (flags & GNOME_CLIENT_IS_CONNECTED) {
char *client_id;
client_id = gnome_client_get_id (client);
g_assert (client_id != NULL);
launch_service = gnome_startup_acquire_token ("EVOLUTION_ALARM_NOTIFY",
client_id);
if (launch_service) {
char *args[3];
args[0] = argv[0];
args[2] = NULL;
gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY);
gnome_client_set_restart_command (client, 2, args);
args[0] = argv[0];
args[1] = "--die";
args[2] = NULL;
gnome_client_set_shutdown_command (client, 2, args);
} else
gnome_client_set_restart_style (client, GNOME_RESTART_NEVER);
gnome_client_flush (client);
} else
launch_service = TRUE;
if (!launch_service)
return EXIT_SUCCESS;
load_calendars ();
return EXIT_SUCCESS;
}
|