1 : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 : /*
3 : * plugin_list.c
4 : * manage the plugin_list_window window
5 : *
6 : * (C) Copyright 2007 Olivier Delhomme
7 : * e-mail : heraia@delhomme.org
8 : * URL : http://heraia.tuxfamily.org
9 : *
10 : * This program is free software; you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License as published by
12 : * the Free Software Foundation; either version 2, or (at your option)
13 : * any later version.
14 : *
15 : * This program is distributed in the hope that it will be useful,
16 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : * GNU General Public License for more details.
19 : *
20 : * You should have received a copy of the GNU General Public License
21 : * along with this program; if not, write to the Free Software
22 : * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 : */
24 :
25 : #include "heraia_types.h"
26 :
27 : static gboolean delete_plw_window_event(GtkWidget *widget, GdkEvent *event, gpointer data);
28 : static void destroy_plw_window(GtkWidget *widget, GdkEvent *event, gpointer data);
29 : static void plw_close_clicked(GtkWidget *widget, gpointer data);
30 : static void plw_refresh_clicked(GtkWidget *widget, gpointer data);
31 : static void mw_cmi_plw_toggle(GtkWidget *widget, gpointer data);
32 : static void pn_treeview_selection_changed_cb(GtkTreeSelection *selection, gpointer data);
33 :
34 : static void plugin_list_window_connect_signals(heraia_window_t *main_window);
35 :
36 : static void init_plugin_name_tv(heraia_window_t *main_window);
37 : static void print_plugin_basics(GtkTextView *textview, heraia_plugin_t *plugin);
38 : static void print_plugin_interface(GtkTextView *textview, heraia_plugin_t *plugin);
39 : static void print_plugin_filter_structure(GtkTextView *textview, heraia_plugin_t *plugin);
40 : static void print_plugin_functions(GtkTextView *textview, heraia_plugin_t *plugin);
41 : static void print_plugin_info_structure(GtkTextView *textview, heraia_plugin_t *plugin);
42 : static void print_plugin_extra_structure(GtkTextView *textview, heraia_plugin_t *plugin);
43 : static void print_plugin_state(GtkTextView *textview, heraia_plugin_t *plugin);
44 :
45 : /*** call back function for the plugins_window ***/
46 : /**
47 : * Signal handler called when the user closes the window */
48 : static gboolean delete_plw_window_event(GtkWidget *widget, GdkEvent *event, gpointer data)
49 0 : {
50 0 : plw_close_clicked(widget, data);
51 :
52 0 : return TRUE;
53 : }
54 :
55 : static void destroy_plw_window(GtkWidget *widget, GdkEvent *event, gpointer data)
56 0 : {
57 0 : plw_close_clicked(widget, data);
58 0 : }
59 :
60 : /**
61 : * Closing the window effectively
62 : */
63 : static void plw_close_clicked(GtkWidget *widget, gpointer data)
64 0 : {
65 0 : heraia_window_t *main_window = (heraia_window_t *) data;
66 0 : GtkCheckMenuItem *cmi = GTK_CHECK_MENU_ITEM(heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list"));
67 :
68 0 : record_and_hide_dialog_box(GTK_WIDGET(heraia_get_widget(main_window->xmls->main, "plugin_list_window")), main_window->win_prop->plugin_list);
69 0 : gtk_check_menu_item_set_active(cmi, FALSE);
70 0 : }
71 :
72 :
73 : /**
74 : * Refreshing the window effectively
75 : */
76 : static void plw_refresh_clicked(GtkWidget *widget, gpointer data)
77 0 : {
78 0 : heraia_window_t *main_window = (heraia_window_t *) data;
79 0 : GtkTextView *textview = GTK_TEXT_VIEW(heraia_get_widget(main_window->xmls->main, "plugin_info_textview"));
80 :
81 0 : init_plugin_name_tv(main_window);
82 0 : kill_text_from_textview(textview);
83 0 : }
84 :
85 :
86 : /**
87 : * When the toggle button 'Liste des plugins' is toggled !
88 : */
89 : static void mw_cmi_plw_toggle(GtkWidget *widget, gpointer data)
90 0 : {
91 0 : heraia_window_t *main_window = (heraia_window_t *) data;
92 0 : GtkCheckMenuItem *cmi = GTK_CHECK_MENU_ITEM(heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list"));
93 0 : GtkPaned *paned = GTK_PANED(heraia_get_widget(main_window->xmls->main, "plw_hpaned"));
94 0 : gint pos = 0;
95 :
96 0 : if (gtk_check_menu_item_get_active(cmi) == TRUE)
97 : {
98 0 : pos = gtk_paned_get_position(paned);
99 0 : if (pos < 15)
100 : {
101 0 : pos = 100;
102 0 : gtk_paned_set_position(paned, pos);
103 : }
104 0 : move_and_show_dialog_box(heraia_get_widget(main_window->xmls->main, "plugin_list_window"), main_window->win_prop->plugin_list);
105 : }
106 : else
107 : {
108 0 : record_and_hide_dialog_box(GTK_WIDGET(heraia_get_widget(main_window->xmls->main, "plugin_list_window")), main_window->win_prop->plugin_list);
109 : }
110 :
111 : /* show_hide_widget(GTK_WIDGET(heraia_get_widget(main_window->xmls->main, "plugin_list_window")),
112 : gtk_check_menu_item_get_active(cmi));*/
113 0 : }
114 :
115 :
116 : /**
117 : * adds to the textview the relevant informations about the plugin info structure !
118 : */
119 : static void print_plugin_info_structure(GtkTextView *textview, heraia_plugin_t *plugin)
120 0 : {
121 0 : if (plugin->info != NULL)
122 : {
123 0 : switch (plugin->info->type)
124 : {
125 : case HERAIA_PLUGIN_UNKNOWN:
126 0 : add_text_to_textview(textview, "Type : Unknown\n");
127 0 : break;
128 :
129 : case HERAIA_PLUGIN_FILTER:
130 0 : add_text_to_textview(textview, "Type : Filter\n");
131 0 : break;
132 :
133 : case HERAIA_PLUGIN_ACTION:
134 0 : add_text_to_textview(textview, "Type : Action\n");
135 0 : break;
136 :
137 : default:
138 0 : add_text_to_textview(textview, "Type : Unknown\n");
139 : }
140 :
141 0 : add_text_to_textview(textview, "Priority : %d\n", plugin->info->priority);
142 0 : add_text_to_textview(textview, "Id : %d\n", plugin->info->id);
143 :
144 0 : if (plugin->info->name != NULL)
145 : {
146 0 : add_text_to_textview(textview, "Name : %s\n", plugin->info->name);
147 : }
148 :
149 0 : if (plugin->info->version != NULL)
150 : {
151 0 : add_text_to_textview(textview, "Version : %s\n", plugin->info->version);
152 : }
153 :
154 0 : if (plugin->info->summary != NULL)
155 : {
156 0 : add_text_to_textview(textview, "Summary : %s\n", plugin->info->summary);
157 : }
158 :
159 0 : if (plugin->info->description != NULL)
160 : {
161 0 : add_text_to_textview(textview, "Description : %s\n", plugin->info->description);
162 : }
163 :
164 0 : if (plugin->info->author != NULL)
165 : {
166 0 : add_text_to_textview(textview, "Author : %s\n", plugin->info->author);
167 : }
168 :
169 0 : if (plugin->info->homepage != NULL)
170 : {
171 0 : add_text_to_textview(textview, "Web site : %s\n", plugin->info->homepage);
172 : }
173 : }
174 : else
175 : {
176 0 : add_text_to_textview(textview, "The 'info' structure is not initialized !\n");
177 : }
178 0 : }
179 :
180 : /**
181 : * adds to the textview the relevant informations about the plugin functions !
182 : */
183 : static void print_plugin_functions(GtkTextView *textview, heraia_plugin_t *plugin)
184 : {
185 :
186 0 : if (plugin->init_proc != NULL ||
187 : plugin->run_proc != NULL ||
188 : plugin->quit_proc != NULL ||
189 : plugin->refresh_proc != NULL)
190 : {
191 0 : add_text_to_textview(textview, "\nPlugin's defined functions :\n");
192 :
193 0 : if (plugin->init_proc != NULL)
194 : {
195 0 : add_text_to_textview(textview, " - Initialization function : %p\n", plugin->init_proc);
196 : }
197 :
198 0 : if (plugin->run_proc != NULL)
199 : {
200 0 : add_text_to_textview(textview, " - Main function : %p\n", plugin->run_proc);
201 : }
202 :
203 0 : if (plugin->quit_proc != NULL)
204 : {
205 0 : add_text_to_textview(textview, " - Exit function : %p\n", plugin->quit_proc);
206 : }
207 :
208 0 : if (plugin->refresh_proc != NULL)
209 : {
210 0 : add_text_to_textview(textview, " - Refresh function : %p\n", plugin->refresh_proc);
211 : }
212 : }
213 : else
214 : {
215 0 : add_text_to_textview(textview, "\nThis plugin does not provide any function !!\n");
216 : }
217 : }
218 :
219 : /**
220 : * adds to the textview the relevant informations about the plugin filter structure !
221 : */
222 : static void print_plugin_filter_structure(GtkTextView *textview, heraia_plugin_t *plugin)
223 : {
224 0 : if (plugin->filter != NULL)
225 : {
226 0 : if (plugin->filter->import != NULL ||
227 : plugin->filter->export != NULL)
228 : {
229 0 : add_text_to_textview(textview, "\nFilter functions :\n");
230 :
231 0 : if (plugin->filter->import != NULL)
232 : {
233 0 : add_text_to_textview(textview, " - Import function : %p\n", plugin->filter->import);
234 : }
235 :
236 0 : if (plugin->filter->export != NULL)
237 : {
238 0 : add_text_to_textview(textview, " - Export function : %p\n", plugin->filter->export);
239 : }
240 : }
241 : else
242 : {
243 0 : add_text_to_textview(textview, "\nThis plugin does not provide any filter function\n");
244 : }
245 : }
246 : else
247 : {
248 0 : add_text_to_textview(textview, "\nThe structure 'filter' is not initialized !");
249 : }
250 : }
251 :
252 : /**
253 : * adds to the textview the relevant informations about the plugin interface (xml) !
254 : */
255 : static void print_plugin_interface(GtkTextView *textview, heraia_plugin_t *plugin)
256 : {
257 0 : add_text_to_textview(textview, "\nThis plugin provides :\n");
258 :
259 0 : if (plugin->cmi_entry != NULL)
260 : {
261 0 : add_text_to_textview(textview, " - a menu entry in the plugins menu.\n");
262 : }
263 : else
264 : {
265 0 : add_text_to_textview(textview, " - no menu entry.\n");
266 : }
267 :
268 0 : if (plugin->xml != NULL)
269 : {
270 0 : add_text_to_textview(textview, " - an xml interface.\n");
271 : }
272 : else
273 : {
274 0 : add_text_to_textview(textview, " - no xml interface.\n");
275 : }
276 : }
277 :
278 : /**
279 : * adds to the textview the relevant informations about the plugin basics !
280 : */
281 : static void print_plugin_basics(GtkTextView *textview, heraia_plugin_t *plugin)
282 : {
283 0 : if (plugin->info != NULL)
284 : {
285 0 : add_text_to_textview(textview, "API version : %d\n", plugin->info->api_version);
286 : }
287 :
288 0 : if (plugin->filename != NULL)
289 : {
290 0 : add_text_to_textview(textview, "File : %s\n", plugin->filename);
291 : }
292 :
293 0 : if (plugin->path != NULL)
294 : {
295 0 : add_text_to_textview(textview, "Directory : %s\n", plugin->path);
296 : }
297 :
298 0 : if (plugin->handle != NULL)
299 : {
300 0 : add_text_to_textview(textview, "Handle : %p\n", plugin->handle);
301 : }
302 : else
303 : {
304 0 : add_text_to_textview(textview, "Handle : NONE <-- Is there anything normal ?\n");
305 : }
306 : }
307 :
308 : /**
309 : * adds to the textview the relevant informations about the plugin extra structure !
310 : */
311 : static void print_plugin_extra_structure(GtkTextView *textview, heraia_plugin_t *plugin)
312 : {
313 :
314 0 : if (plugin->extra != NULL)
315 : {
316 0 : add_text_to_textview(textview, "\nThis plugin has an additionnal 'extra' structure (%p) sized %d bytes.\n",
317 : plugin->extra, sizeof(*(plugin->extra)));
318 : }
319 : else
320 : {
321 0 : add_text_to_textview(textview, "\nThis plugin does not have any additionnal structure.\n");
322 : }
323 :
324 : }
325 :
326 : /**
327 : * adds to the textview the relevant informations about the plugin state !
328 : */
329 : static void print_plugin_state(GtkTextView *textview, heraia_plugin_t *plugin)
330 0 : {
331 :
332 0 : add_text_to_textview(textview, "Plugin's state : ");
333 0 : switch (plugin->state)
334 : {
335 : case PLUGIN_STATE_RUNNING:
336 0 : add_text_to_textview(textview, "Running\n");
337 0 : break;
338 :
339 : case PLUGIN_STATE_INITIALIZING:
340 0 : add_text_to_textview(textview, "Initialiazing or initialized\n");
341 0 : break;
342 : case PLUGIN_STATE_LOADED:
343 0 : add_text_to_textview(textview, "Loaded\n");
344 0 : break;
345 :
346 : case PLUGIN_STATE_NEW:
347 0 : add_text_to_textview(textview, "Creating itself\n");
348 0 : break;
349 :
350 : case PLUGIN_STATE_EXITING:
351 0 : add_text_to_textview(textview, "Exiting\n");
352 0 : break;
353 :
354 : case PLUGIN_STATE_NONE:
355 0 : add_text_to_textview(textview, "Waiting\n");
356 0 : break;
357 :
358 : default:
359 0 : add_text_to_textview(textview, "Unknown\n");
360 : }
361 0 : }
362 :
363 : /**
364 : * Function called when the selection changes in the treeview
365 : * Displays informations about the selected plugin
366 : */
367 : static void pn_treeview_selection_changed_cb(GtkTreeSelection *selection, gpointer data)
368 1 : {
369 : GtkTreeIter iter;
370 1 : GtkTreeModel *model = NULL;
371 1 : heraia_window_t *main_window = (heraia_window_t *) data;
372 1 : gchar *name = NULL;
373 1 : heraia_plugin_t *plugin = NULL;
374 1 : GtkTextView *textview = GTK_TEXT_VIEW(heraia_get_widget(main_window->xmls->main, "plugin_info_textview"));
375 :
376 1 : if (gtk_tree_selection_get_selected(selection, &model, &iter))
377 : {
378 0 : gtk_tree_model_get(model, &iter, PNTV_COLUMN_NAME, &name, -1);
379 0 : plugin = find_plugin_by_name(main_window->plugins_list, name);
380 :
381 0 : if (plugin != NULL)
382 : {
383 0 : kill_text_from_textview(textview);
384 :
385 : print_plugin_basics(textview, plugin);
386 :
387 0 : print_plugin_info_structure(textview, plugin);
388 :
389 : print_plugin_functions(textview, plugin);
390 :
391 : print_plugin_filter_structure(textview, plugin);
392 :
393 : print_plugin_interface(textview, plugin);
394 :
395 : print_plugin_extra_structure(textview, plugin);
396 :
397 0 : print_plugin_state(textview, plugin);
398 : }
399 : }
400 1 : }
401 : /*** End of callback functions that handle the plugins window ***/
402 :
403 :
404 : static void plugin_list_window_connect_signals(heraia_window_t *main_window)
405 1 : {
406 1 : GtkTreeSelection *select = NULL;
407 :
408 1 : if (main_window != NULL)
409 : {
410 : /* When the plugin list window is destroyed or killed */
411 1 : g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "plugin_list_window")), "delete_event",
412 : G_CALLBACK(delete_plw_window_event), main_window);
413 :
414 1 : g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "plugin_list_window")), "destroy",
415 : G_CALLBACK(destroy_plw_window), main_window);
416 :
417 : /* Close button */
418 1 : g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "plw_close_b")), "clicked",
419 : G_CALLBACK(plw_close_clicked), main_window);
420 :
421 : /* The toogle button */
422 1 : g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list")), "toggled",
423 : G_CALLBACK(mw_cmi_plw_toggle), main_window);
424 :
425 : /* Selection has changed for the pn_treeview */
426 1 : select = gtk_tree_view_get_selection(GTK_TREE_VIEW(heraia_get_widget(main_window->xmls->main, "pn_treeview")));
427 1 : gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
428 1 : g_signal_connect(G_OBJECT(select), "changed", G_CALLBACK (pn_treeview_selection_changed_cb), main_window);
429 :
430 : /* Refresh button */
431 1 : g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "plw_refresh_b")), "clicked",
432 : G_CALLBACK(plw_refresh_clicked), main_window);
433 : }
434 1 : }
435 :
436 : /**
437 : * the function to init the first treeview (plugin names)
438 : */
439 : static void init_plugin_name_tv(heraia_window_t *main_window)
440 1 : {
441 1 : GtkListStore *list_store = NULL; /* Treeview Stuff for rendering */
442 : GtkTreeIter iter; /* the text in it. */
443 1 : GtkCellRenderer *renderer = NULL;
444 :
445 1 : GtkTreeViewColumn *column = NULL;
446 1 : heraia_plugin_t *plugin = NULL; /* plugin interface structure */
447 1 : GList *p_list = NULL; /* plugin list */
448 1 : GtkTreeView *treeview = NULL; /* Treeview where plugin names are to be displayed */
449 :
450 1 : if (main_window != NULL)
451 : {
452 1 : treeview = GTK_TREE_VIEW(heraia_get_widget(main_window->xmls->main, "pn_treeview"));
453 :
454 1 : p_list = g_list_first(main_window->plugins_list);
455 :
456 1 : list_store = gtk_list_store_new(PNTV_N_COLUMNS, G_TYPE_STRING);
457 :
458 3 : while (p_list != NULL)
459 : {
460 1 : plugin = (heraia_plugin_t *) p_list->data;
461 1 : log_message(main_window, G_LOG_LEVEL_INFO, "%s", plugin->info->name);
462 :
463 1 : gtk_list_store_append(list_store, &iter);
464 1 : gtk_list_store_set(list_store, &iter, PNTV_COLUMN_NAME, plugin->info->name, -1);
465 :
466 1 : p_list = p_list->next;
467 : }
468 :
469 1 : gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(list_store));
470 :
471 1 : column = gtk_tree_view_get_column(treeview, PNTV_COLUMN_NAME);
472 :
473 1 : if (column != NULL)
474 : {
475 0 : gtk_tree_view_remove_column(treeview, column);
476 : }
477 :
478 1 : renderer = gtk_cell_renderer_text_new();
479 1 : column = gtk_tree_view_column_new_with_attributes("Name", renderer, "text", PNTV_COLUMN_NAME, NULL);
480 1 : gtk_tree_view_append_column(treeview, column);
481 : }
482 1 : }
483 :
484 :
485 : /**
486 : * the function to init the plugin_list_window interface
487 : */
488 : void plugin_list_window_init_interface(heraia_window_t *main_window)
489 1 : {
490 :
491 1 : plugin_list_window_connect_signals(main_window);
492 :
493 1 : init_plugin_name_tv(main_window);
494 1 : }
495 :
496 :
497 :
498 :
499 :
500 :
|