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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* intelligent.c
*
* Authors:
* Iain Holmes <iain@ximian.com>
*
* Copyright 2001 Ximian, Inc. (http://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 Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "intelligent.h"
#include <glib.h>
#include <gtk/gtkbox.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkobject.h>
#include <gtk/gtktogglebutton.h>
#include <gtk/gtkwidget.h>
#include <gtk/gtkwindow.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-config.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <libgnomeui/gnome-dialog.h>
#include <libgnomeui/gnome-stock.h>
#include <liboaf/liboaf.h>
#include "GNOME_Evolution_Importer.h"
/* Prototypes */
void intelligent_importer_init (void);
/* End prototypes */
static void
start_importer (const char *iid)
{
CORBA_Object importer;
CORBA_Environment ev;
CORBA_char *name;
CORBA_char *message;
CORBA_boolean can_run;
GtkWidget *dialog, *label, *ask;
gboolean dontaskagain;
char *prefix;
if (iid == NULL || *iid == '\0')
return;
/* Check if we want to show this one again */
prefix = g_strdup_printf ("=%s/evolution/config/Shell=/intelligent-importers/", gnome_util_user_home ());
gnome_config_push_prefix (prefix);
g_free (prefix);
dontaskagain = gnome_config_get_bool (iid);
gnome_config_pop_prefix ();
if (dontaskagain)
return;
CORBA_exception_init (&ev);
importer = oaf_activate_from_id ((char *) iid, 0, NULL, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
CORBA_exception_free (&ev);
g_warning ("Could not start %s", iid);
return;
}
CORBA_exception_free (&ev);
if (importer == CORBA_OBJECT_NIL) {
g_warning ("Could not activate_component %s", iid);
return;
}
CORBA_exception_init (&ev);
can_run = GNOME_Evolution_IntelligentImporter_canImport (importer, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning ("Could not get canImport(%s): %s", iid, CORBA_exception_id (&ev));
CORBA_Object_release (importer, &ev);
CORBA_exception_free (&ev);
return;
}
CORBA_exception_free (&ev);
if (can_run == FALSE) {
return;
}
name = GNOME_Evolution_IntelligentImporter__get_importername (importer,
&ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning ("Could not get name(%s): %s", iid, CORBA_exception_id (&ev));
CORBA_Object_release (importer, &ev);
CORBA_exception_free (&ev);
return;
}
message = GNOME_Evolution_IntelligentImporter__get_message (importer, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning ("Could not get message(%s): %s", iid, CORBA_exception_id (&ev));
CORBA_Object_release (importer, &ev);
CORBA_exception_free (&ev);
return;
}
CORBA_exception_free (&ev);
dialog = gnome_dialog_new ("Import files",
GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO,
NULL);
gtk_window_set_title (GTK_WINDOW (dialog), name);
CORBA_free (name);
label = gtk_label_new (message);
CORBA_free (message);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label,
FALSE, FALSE, 0);
gtk_widget_show (label);
ask = gtk_check_button_new_with_label (_("Don't ask me again"));
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), ask,
FALSE, FALSE, 0);
gtk_widget_show (ask);
switch (gnome_dialog_run (GNOME_DIALOG (dialog))) {
case 0:
/* Yes */
dontaskagain = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ask));
prefix = g_strdup_printf ("=%s/evolution/config/Shell=/intelligent-importers/", gnome_util_user_home ());
gnome_config_push_prefix (prefix);
g_free (prefix);
gnome_config_set_bool (iid, dontaskagain);
gnome_config_sync ();
gnome_config_drop_all ();
gnome_config_pop_prefix ();
gtk_object_destroy (GTK_OBJECT (dialog));
while (gtk_events_pending ())
gtk_main_iteration ();
GNOME_Evolution_IntelligentImporter_importData (importer, &ev);
break;
case 1:
case -1:
default:
/* No */
dontaskagain = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ask));
prefix = g_strdup_printf ("=%s/evolution/config/Shell=/intelligent-importers/", gnome_util_user_home ());
gnome_config_push_prefix (prefix);
g_free (prefix);
gnome_config_set_bool (iid, dontaskagain);
gnome_config_sync ();
gnome_config_drop_all ();
gnome_config_pop_prefix ();
gtk_object_destroy (GTK_OBJECT (dialog));
break;
}
CORBA_exception_init (&ev);
CORBA_Object_release (importer, &ev);
CORBA_exception_free (&ev);
}
static GList *
get_intelligent_importers (void)
{
OAF_ServerInfoList *info_list;
GList *iids_ret = NULL;
CORBA_Environment ev;
int i;
CORBA_exception_init (&ev);
info_list = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/IntelligentImporter:1.0')", NULL, &ev);
CORBA_exception_free (&ev);
for (i = 0; i < info_list->_length; i++) {
const OAF_ServerInfo *info;
info = info_list->_buffer + i;
iids_ret = g_list_prepend (iids_ret, g_strdup (info->iid));
}
return iids_ret;
}
void
intelligent_importer_init (void)
{
GList *importers, *l;
importers = get_intelligent_importers ();
if (importers == NULL)
return; /* No intelligent importers. Easy :) */
/* Loop through each importer, running it. */
for (l = importers; l; l = l->next) {
start_importer (l->data);
g_free (l->data);
}
g_list_free (importers);
}
|