aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/helper.c259
-rw-r--r--src/core/main.c136
-rw-r--r--src/include/gnunetgtk_common.h7
-rw-r--r--src/plugins/fs/search.c2
-rw-r--r--src/plugins/fs/upload.c4
5 files changed, 180 insertions, 228 deletions
diff --git a/src/common/helper.c b/src/common/helper.c
index 59c10bf8..c4aa8e18 100644
--- a/src/common/helper.c
+++ b/src/common/helper.c
@@ -29,25 +29,33 @@
29 29
30#define HELPER_DEBUG NO 30#define HELPER_DEBUG NO
31 31
32typedef struct {
33 Semaphore * sem;
34 void * args;
35 SimpleCallback func;
36} SaveCall;
37
38typedef struct Plugin {
39 struct Plugin * next;
40 char * name;
41 void * library;
42} Plugin;
43
32static GladeXML * mainXML; 44static GladeXML * mainXML;
33 45
34static char * gladeFile; 46static char * gladeFile;
35 47
48static GladeXML * statusXML;
49
36static GtkWidget * infoWindow; 50static GtkWidget * infoWindow;
37 51
38static GtkWidget * infoText; 52static GtkWidget * infoWindowTextView;
39 53
40/** 54/**
41 * the main thread 55 * the main thread
42 */ 56 */
43static PTHREAD_T mainThread; 57static PTHREAD_T mainThread;
44 58
45typedef struct {
46 Semaphore * sem;
47 void * args;
48 SimpleCallback func;
49} SaveCall;
50
51static SaveCall ** psc; 59static SaveCall ** psc;
52 60
53static unsigned int pscCount; 61static unsigned int pscCount;
@@ -56,6 +64,9 @@ static Mutex sclock;
56 64
57static int saveCallsUp; 65static int saveCallsUp;
58 66
67static Plugin * plugin;
68
69
59static gboolean saveCallWrapper(gpointer data) { 70static gboolean saveCallWrapper(gpointer data) {
60 SaveCall * call = data; 71 SaveCall * call = data;
61 72
@@ -138,19 +149,12 @@ int gtkRunSomeSaveCalls() {
138/** 149/**
139 * Callback for handling "delete_event": close the window 150 * Callback for handling "delete_event": close the window
140 */ 151 */
141static gint 152gint on_statusWindow_delete_event(GtkWidget * widget,
142deleteEvent(GtkWidget * widget, 153 GdkEvent * event,
143 GdkEvent * event, 154 gpointer data) {
144 gpointer data) {
145 return FALSE; 155 return FALSE;
146} 156}
147 157
148static void hideWindow(GtkWidget * widget,
149 gpointer data) {
150 if (widget != NULL)
151 gtk_widget_hide(widget);
152}
153
154/** 158/**
155 * Closure for doInfoMessage. 159 * Closure for doInfoMessage.
156 */ 160 */
@@ -161,84 +165,16 @@ typedef struct {
161 165
162/** 166/**
163 * Callback for infoMessage() 167 * Callback for infoMessage()
164 *
165 * FIXME: use GLADE (or direct GTK functionality) here!
166 */ 168 */
167static void doInfoMessage(void * args) { 169static void doInfoMessage(void * args) {
168 const InfoMessage * info = args; 170 const InfoMessage * info = args;
169 GtkTextIter iter; 171 GtkTextIter iter;
170 GtkTextBuffer * buffer; 172 GtkTextBuffer * buffer;
171 173
172 if (! infoWindow) {
173 GtkWidget * box1;
174 GtkWidget * button;
175 GtkWidget * scrolled_window;
176
177 infoWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
178 gtk_signal_connect(GTK_OBJECT(infoWindow),
179 "delete_event",
180 GTK_SIGNAL_FUNC(deleteEvent),
181 NULL);
182
183 gtk_window_set_title(GTK_WINDOW(infoWindow),
184 _("Messages"));
185 gtk_widget_set_usize(GTK_WIDGET(infoWindow),
186 780,
187 300);
188
189 box1 = gtk_vbox_new(FALSE, 0);
190 gtk_container_add(GTK_CONTAINER (infoWindow),
191 box1);
192 gtk_widget_show(box1);
193
194 /* create a scrollable window */
195 scrolled_window = gtk_scrolled_window_new(NULL, NULL);
196 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
197 GTK_POLICY_AUTOMATIC,
198 GTK_POLICY_ALWAYS);
199 gtk_box_pack_start(GTK_BOX(box1),
200 scrolled_window,
201 TRUE,
202 TRUE,
203 0);
204 gtk_widget_show(scrolled_window);
205
206 /* create a text widget */
207 infoText = gtk_text_view_new();
208
209 gtk_text_view_set_editable(GTK_TEXT_VIEW (infoText),
210 FALSE);
211 gtk_container_add(GTK_CONTAINER(scrolled_window),
212 infoText);
213 gtk_widget_show(infoText);
214 gtk_widget_realize(infoText);
215
216 /* finish with a close button */
217 button = gtk_button_new_with_label(_("Close"));
218 gtk_box_pack_start(GTK_BOX (box1),
219 button,
220 FALSE,
221 FALSE,
222 0);
223 gtk_signal_connect_object(GTK_OBJECT(button),
224 "clicked",
225 GTK_SIGNAL_FUNC(hideWindow),
226 GTK_OBJECT(infoWindow));
227 gtk_signal_connect_object(GTK_OBJECT(infoWindow),
228 "delete_event",
229 GTK_SIGNAL_FUNC(hideWindow),
230 GTK_OBJECT(infoWindow));
231 gtk_signal_connect_object(GTK_OBJECT(infoWindow),
232 "destroy",
233 GTK_SIGNAL_FUNC(hideWindow),
234 GTK_OBJECT(infoWindow));
235 gtk_widget_show(button);
236 }
237 if (info->doPopup==YES) 174 if (info->doPopup==YES)
238 gtk_widget_show(infoWindow); 175 gtk_widget_show(infoWindow);
239 176 buffer
240 /* append the text */ 177 = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoWindowTextView));
241 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoText));
242 gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1); 178 gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
243 gtk_text_buffer_insert(buffer, 179 gtk_text_buffer_insert(buffer,
244 &iter, 180 &iter,
@@ -311,7 +247,120 @@ GladeXML * getMainXML() {
311 return mainXML; 247 return mainXML;
312} 248}
313 249
250static void connector(const gchar *handler_name,
251 GObject *object,
252 const gchar *signal_name,
253 const gchar *signal_data,
254 GObject *connect_object,
255 gboolean after,
256 gpointer user_data) {
257 Plugin * plug = user_data;
258 void * method;
259
260 while (plug != NULL) {
261 method = trybindDynamicMethod(plug->library,
262 "",
263 handler_name);
264 if (method != NULL)
265 break;
266 plug = plug->next;
267 }
268 if (method == NULL) {
269 LOG(LOG_DEBUG,
270 _("Failed to find handler for '%s'\n"),
271 handler_name);
272 return;
273 }
274 glade_xml_signal_connect(getMainXML(),
275 handler_name,
276 (GCallback) method);
277}
278
279void connectGladeWithPlugins(GladeXML * xml) {
280 glade_xml_signal_autoconnect_full(xml,
281 &connector, plugin);
282}
283
284typedef void (*PlainCall)();
285
286static Plugin * loadPlugin(const char * name,
287 Plugin * next) {
288 Plugin * p;
289 void * lib;
290 PlainCall init;
291
292 lib = loadDynamicLibrary("libgnunetgtkmodule_",
293 name);
294 if (lib == NULL) {
295 LOG(LOG_WARNING,
296 _("Failed to load plugin '%s'\n"),
297 name);
298 return next;
299 }
300 p = MALLOC(sizeof(Plugin));
301 p->name = STRDUP(name);
302 p->next = next;
303 p->library = lib;
304 init = trybindDynamicMethod(lib,
305 "init_",
306 name);
307 if (init != NULL)
308 init();
309
310 return p;
311}
312
313static Plugin * loadPlugins(const char * names,
314 Plugin * plug) {
315 char * dup;
316 char * next;
317 const char * pos;
318
319 if (names == NULL)
320 return plug;
321
322 dup = STRDUP(names);
323 next = dup;
324 do {
325 while (*next == ' ')
326 next++;
327 pos = next;
328 while ( (*next != '\0') &&
329 (*next != ' ') )
330 next++;
331 if (*next == '\0') {
332 next = NULL; /* terminate! */
333 } else {
334 *next = '\0'; /* add 0-termination for pos */
335 next++;
336 }
337 if (strlen(pos) > 0) {
338 LOG(LOG_DEBUG,
339 "Loading plugin '%s'\n",
340 pos);
341 plug = loadPlugin(pos, plug);
342 }
343 } while (next != NULL);
344 FREE(dup);
345 return plug;
346}
347
348static void unloadPlugin(Plugin * plug) {
349 PlainCall done;
350
351 done = trybindDynamicMethod(plug->library,
352 "done_",
353 plug->name);
354 if (done != NULL)
355 done();
356 unloadDynamicLibrary(plug->library);
357 FREE(plug->name);
358 FREE(plug);
359}
360
314void initGNUnetGTKCommon() { 361void initGNUnetGTKCommon() {
362 char * load;
363
315 MUTEX_CREATE_RECURSIVE(&sclock); 364 MUTEX_CREATE_RECURSIVE(&sclock);
316 PTHREAD_GET_SELF(&mainThread); 365 PTHREAD_GET_SELF(&mainThread);
317 saveCallsUp = YES; 366 saveCallsUp = YES;
@@ -319,7 +368,8 @@ void initGNUnetGTKCommon() {
319 /* load the interface */ 368 /* load the interface */
320#ifdef MINGW 369#ifdef MINGW
321 gladeFile = MALLOC(_MAX_PATH + 1); 370 gladeFile = MALLOC(_MAX_PATH + 1);
322 plibc_conv_to_win_path(PACKAGE_DATA_DIR"/gnunet-gtk.glade", gladeFile); 371 plibc_conv_to_win_path(PACKAGE_DATA_DIR"/gnunet-gtk.glade",
372 gladeFile);
323#else 373#else
324 gladeFile = STRDUP(PACKAGE_DATA_DIR"/gnunet-gtk.glade"); 374 gladeFile = STRDUP(PACKAGE_DATA_DIR"/gnunet-gtk.glade");
325#endif 375#endif
@@ -327,11 +377,43 @@ void initGNUnetGTKCommon() {
327 mainXML = glade_xml_new(gladeFile, 377 mainXML = glade_xml_new(gladeFile,
328 "mainWindow", 378 "mainWindow",
329 NULL); 379 NULL);
380 statusXML
381 = glade_xml_new(getGladeFileName(),
382 "statusWindow",
383 NULL);
384 infoWindow
385 = glade_xml_get_widget(statusXML,
386 "statusWindow");
387 infoWindowTextView
388 = glade_xml_get_widget(statusXML,
389 "messageWindowTextView");
390 /* load the plugins */
391 load = getConfigurationString("GNUNET-GTK",
392 "PLUGINS");
393 if (load == NULL)
394 load = STRDUP("about daemon fs");
395 plugin = loadPlugins(load, NULL);
396 FREE(load);
397
398 connectGladeWithPlugins(mainXML);
399 connectGladeWithPlugins(statusXML);
330} 400}
331 401
332void doneGNUnetGTKCommon() { 402void doneGNUnetGTKCommon() {
333 int i; 403 int i;
334 404
405 /* unload the plugins */
406 while (plugin != NULL) {
407 Plugin * next;
408
409 next = plugin->next;
410 unloadPlugin(plugin);
411 plugin = next;
412 }
413
414 gtk_widget_destroy(infoWindow);
415 infoWindow = NULL;
416 UNREF(statusXML);
335 UNREF(mainXML); 417 UNREF(mainXML);
336 mainXML = NULL; 418 mainXML = NULL;
337 FREE(gladeFile); 419 FREE(gladeFile);
@@ -354,7 +436,6 @@ void doneGNUnetGTKCommon() {
354 MUTEX_UNLOCK(&sclock); 436 MUTEX_UNLOCK(&sclock);
355 } 437 }
356 MUTEX_DESTROY(&sclock); 438 MUTEX_DESTROY(&sclock);
357
358} 439}
359 440
360/* end of helper.c */ 441/* end of helper.c */
diff --git a/src/core/main.c b/src/core/main.c
index ca756bdc..87e84772 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -88,122 +88,8 @@ static int parseOptions(int argc,
88 return OK; 88 return OK;
89} 89}
90 90
91typedef struct Plugin {
92 struct Plugin * next;
93 char * name;
94 void * library;
95} Plugin;
96
97static void connector(const gchar *handler_name,
98 GObject *object,
99 const gchar *signal_name,
100 const gchar *signal_data,
101 GObject *connect_object,
102 gboolean after,
103 gpointer user_data) {
104 Plugin * plug = user_data;
105 void * method;
106
107 while (plug != NULL) {
108 method = trybindDynamicMethod(plug->library,
109 "",
110 handler_name);
111 if (method != NULL)
112 break;
113 plug = plug->next;
114 }
115 if (method == NULL) {
116 LOG(LOG_DEBUG,
117 _("Failed to find handler for '%s'\n"),
118 handler_name);
119 return;
120 }
121 glade_xml_signal_connect(getMainXML(),
122 handler_name,
123 (GCallback) method);
124}
125
126typedef void (*PlainCall)();
127
128static Plugin * loadPlugin(const char * name,
129 Plugin * next) {
130 Plugin * p;
131 void * lib;
132 PlainCall init;
133
134 lib = loadDynamicLibrary("libgnunetgtkmodule_",
135 name);
136 if (lib == NULL) {
137 LOG(LOG_WARNING,
138 _("Failed to load plugin '%s'\n"),
139 name);
140 return next;
141 }
142 p = MALLOC(sizeof(Plugin));
143 p->name = STRDUP(name);
144 p->next = next;
145 p->library = lib;
146 init = trybindDynamicMethod(lib,
147 "init_",
148 name);
149 if (init != NULL)
150 init();
151
152 return p;
153}
154
155static Plugin * loadPlugins(const char * names,
156 Plugin * plug) {
157 char * dup;
158 char * next;
159 const char * pos;
160
161 if (names == NULL)
162 return plug;
163
164 dup = STRDUP(names);
165 next = dup;
166 do {
167 while (*next == ' ')
168 next++;
169 pos = next;
170 while ( (*next != '\0') &&
171 (*next != ' ') )
172 next++;
173 if (*next == '\0') {
174 next = NULL; /* terminate! */
175 } else {
176 *next = '\0'; /* add 0-termination for pos */
177 next++;
178 }
179 if (strlen(pos) > 0) {
180 LOG(LOG_DEBUG,
181 "Loading plugin '%s'\n",
182 pos);
183 plug = loadPlugin(pos, plug);
184 }
185 } while (next != NULL);
186 FREE(dup);
187 return plug;
188}
189
190static void unloadPlugin(Plugin * plug) {
191 PlainCall done;
192
193 done = trybindDynamicMethod(plug->library,
194 "done_",
195 plug->name);
196 if (done != NULL)
197 done();
198 unloadDynamicLibrary(plug->library);
199 FREE(plug->name);
200 FREE(plug);
201}
202
203int main(int argc, 91int main(int argc,
204 char *argv[]) { 92 char *argv[]) {
205 Plugin * plugin;
206 char * load;
207 GtkWidget * root; 93 GtkWidget * root;
208 94
209 g_thread_init(NULL); 95 g_thread_init(NULL);
@@ -217,22 +103,9 @@ int main(int argc,
217 root 103 root
218 = glade_xml_get_widget(getMainXML(), 104 = glade_xml_get_widget(getMainXML(),
219 "mainWindow"); 105 "mainWindow");
220
221 /* load the plugins */
222 load = getConfigurationString("GNUNET-GTK",
223 "PLUGINS");
224 if (load == NULL)
225 load = STRDUP("about daemon fs");
226 plugin = loadPlugins(load, NULL);
227 FREE(load);
228
229 gtk_window_maximize(GTK_WINDOW(root)); 106 gtk_window_maximize(GTK_WINDOW(root));
230 gtk_widget_show(root); 107 gtk_widget_show(root);
231 /* connect the signals in the interface */
232 setCustomLogProc(&addLogEntry); 108 setCustomLogProc(&addLogEntry);
233 glade_xml_signal_autoconnect_full(getMainXML(),
234 &connector, plugin);
235
236 /* start the event loop */ 109 /* start the event loop */
237 gdk_threads_enter(); 110 gdk_threads_enter();
238 gtk_main(); 111 gtk_main();
@@ -240,15 +113,6 @@ int main(int argc,
240 setCustomLogProc(NULL); 113 setCustomLogProc(NULL);
241 stopCron(); 114 stopCron();
242 115
243 /* unload the plugins */
244 while (plugin != NULL) {
245 Plugin * next;
246
247 next = plugin->next;
248 unloadPlugin(plugin);
249 plugin = next;
250 }
251
252 doneGNUnetGTKCommon(); 116 doneGNUnetGTKCommon();
253 doneUtil(); 117 doneUtil();
254 118
diff --git a/src/include/gnunetgtk_common.h b/src/include/gnunetgtk_common.h
index ee3e53c4..d3b7c265 100644
--- a/src/include/gnunetgtk_common.h
+++ b/src/include/gnunetgtk_common.h
@@ -78,5 +78,12 @@ void gtkSaveCall(SimpleCallback func,
78 * still continue. 78 * still continue.
79 */ 79 */
80int gtkRunSomeSaveCalls(); 80int gtkRunSomeSaveCalls();
81
82/**
83 * Bind handlers defined by the various
84 * plugins to the signals defined by the
85 * Glade XML.
86 */
87void connectGladeWithPlugins(GladeXML * xml);
81 88
82#endif 89#endif
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c
index b5b95f77..2e97b940 100644
--- a/src/plugins/fs/search.c
+++ b/src/plugins/fs/search.c
@@ -374,7 +374,7 @@ static GtkWidget * makeResultFrame(GtkWidget ** treeview,
374 = glade_xml_new(getGladeFileName(), 374 = glade_xml_new(getGladeFileName(),
375 "searchResultsFrame", 375 "searchResultsFrame",
376 NULL); 376 NULL);
377 glade_xml_signal_autoconnect(searchXML); 377 connectGladeWithPlugins(searchXML);
378 window = glade_xml_get_widget(searchXML, 378 window = glade_xml_get_widget(searchXML,
379 "searchResultsFrame"); 379 "searchResultsFrame");
380 resultList = glade_xml_get_widget(searchXML, 380 resultList = glade_xml_get_widget(searchXML,
diff --git a/src/plugins/fs/upload.c b/src/plugins/fs/upload.c
index 112935a1..96f95ed5 100644
--- a/src/plugins/fs/upload.c
+++ b/src/plugins/fs/upload.c
@@ -415,7 +415,7 @@ void on_fsinsertuploadbutton_clicked(gpointer dummy,
415 = glade_xml_new(getGladeFileName(), 415 = glade_xml_new(getGladeFileName(),
416 "metaDataDialog", 416 "metaDataDialog",
417 NULL); 417 NULL);
418 glade_xml_signal_autoconnect(metaXML); 418 connectGladeWithPlugins(metaXML);
419 dialog = glade_xml_get_widget(metaXML, 419 dialog = glade_xml_get_widget(metaXML,
420 "metaDataDialog"); 420 "metaDataDialog");
421 metamodel 421 metamodel
@@ -684,7 +684,7 @@ static char *selectFile() {
684 = glade_xml_new(getGladeFileName(), 684 = glade_xml_new(getGladeFileName(),
685 "uploadfilechooserdialog", 685 "uploadfilechooserdialog",
686 NULL); 686 NULL);
687 glade_xml_signal_autoconnect(uploadXML); 687 connectGladeWithPlugins(uploadXML);
688 dialog = glade_xml_get_widget(uploadXML, 688 dialog = glade_xml_get_widget(uploadXML,
689 "uploadfilechooserdialog"); 689 "uploadfilechooserdialog");
690 690