plugin_list.c

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /*
00003  *  plugin_list.c
00004  *  manage the plugin_list_window window
00005  * 
00006  *  (C) Copyright 2007 - 2009 Olivier Delhomme
00007  *  e-mail : heraia@delhomme.org
00008  *  URL    : http://heraia.tuxfamily.org
00009  * 
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2, or  (at your option) 
00013  *  any later version.
00014  * 
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY;  without even the implied warranty of
00017  *  MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  * 
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
00023  */
00024 /**
00025  * @file plugin_list.c
00026  * This file manage plugin list window's behavior
00027  */
00028 #include <libheraia.h>
00029 
00030 static gboolean delete_plw_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data);
00031 static void destroy_plw_window(GtkWidget *widget, GdkEvent  *event, gpointer data);
00032 static void plw_close_clicked(GtkWidget *widget, gpointer data);
00033 static void plw_refresh_clicked(GtkWidget *widget, gpointer data);
00034 static void mw_cmi_plw_toggle(GtkWidget *widget, gpointer data);
00035 static void pn_treeview_selection_changed_cb(GtkTreeSelection *selection, gpointer data);
00036 
00037 static void plugin_list_window_connect_signals(heraia_window_t *main_window);
00038 
00039 static void init_plugin_name_tv(heraia_window_t *main_window);
00040 static void print_plugin_basics(GtkTextView *textview, heraia_plugin_t *plugin);
00041 static void print_plugin_interface(GtkTextView *textview, heraia_plugin_t *plugin);
00042 static void print_plugin_filter_structure(GtkTextView *textview, heraia_plugin_t *plugin);
00043 static void print_plugin_functions(GtkTextView *textview, heraia_plugin_t *plugin);
00044 static void print_plugin_info_structure(GtkTextView *textview, heraia_plugin_t *plugin);
00045 static void print_plugin_extra_structure(GtkTextView *textview, heraia_plugin_t *plugin);
00046 static void print_plugin_state(GtkTextView *textview, heraia_plugin_t *plugin);
00047 
00048 /*** call back function for the plugins_window ***/
00049 /**
00050  * @fn gboolean delete_plw_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data)
00051  *  Signal handler called when the user closes the window 
00052  * @param widget : calling widget 
00053  * @param event : event associated (may be NULL as we don't use this here)
00054  * @param data : MUST be heraia_window_t *main_window main structure and not NULL
00055  * @return Always returns TRUE in order to propagate the signal 
00056  */
00057 static gboolean delete_plw_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data)
00058 {
00059         plw_close_clicked(widget, data);
00060 
00061         return TRUE;
00062 }
00063 
00064 /**
00065  * @fn void destroy_plw_window(GtkWidget *widget, GdkEvent  *event, gpointer data)
00066  * When the window is destroyed (Gtk's doc says that we may never get there)
00067  * @param widget : calling widget 
00068  * @param event : event associated (may be NULL as we don't use this here)
00069  * @param data : MUST be heraia_window_t *main_window main structure and not NULL
00070  */
00071 static void destroy_plw_window(GtkWidget *widget, GdkEvent  *event, gpointer data)
00072 {
00073         plw_close_clicked(widget, data);
00074 }
00075 
00076 /**
00077  * @fn void plw_close_clicked(GtkWidget *widget, gpointer data)
00078  *  Closing the window effectively
00079  * @param widget : calling widget 
00080  * @param data : MUST be heraia_window_t *main_window main structure and not NULL
00081  */
00082 static void plw_close_clicked(GtkWidget *widget, gpointer data)
00083 {
00084         heraia_window_t *main_window = (heraia_window_t *) data;
00085         GtkCheckMenuItem *cmi = GTK_CHECK_MENU_ITEM(heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list"));
00086 
00087         record_and_hide_dialog_box(GTK_WIDGET(heraia_get_widget(main_window->xmls->main, "plugin_list_window")), main_window->win_prop->plugin_list);
00088         gtk_check_menu_item_set_active(cmi, FALSE);
00089 }
00090 
00091 
00092 /**
00093  * @fn void plw_refresh_clicked(GtkWidget *widget, gpointer data)
00094  *  Refreshing the window effectively
00095  * @param widget : calling widget 
00096  * @param data : MUST be heraia_window_t *main_window main structure and not NULL 
00097  */
00098 static void plw_refresh_clicked(GtkWidget *widget, gpointer data)
00099 {
00100         heraia_window_t *main_window = (heraia_window_t *) data;
00101         GtkTextView *textview = GTK_TEXT_VIEW(heraia_get_widget(main_window->xmls->main, "plugin_info_textview"));
00102 
00103         init_plugin_name_tv(main_window);
00104         kill_text_from_textview(textview);      
00105 }
00106 
00107 
00108 /**
00109  * @fn void mw_cmi_plw_toggle(GtkWidget *widget, gpointer data)
00110  *  When the toggle button 'Liste des plugins' is toggled !
00111  * @param widget : calling widget (may be NULL as we do not even bother here)
00112  * @param data : MUST be heraia_window_t *main_window main structure and not NULL 
00113  */
00114 static void mw_cmi_plw_toggle(GtkWidget *widget, gpointer data)
00115 {
00116         heraia_window_t *main_window = (heraia_window_t *) data;
00117         GtkCheckMenuItem *cmi = GTK_CHECK_MENU_ITEM(heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list"));
00118         GtkPaned *paned = GTK_PANED(heraia_get_widget(main_window->xmls->main, "plw_hpaned"));
00119         gint pos = 0;
00120 
00121         if (gtk_check_menu_item_get_active(cmi) == TRUE)
00122                 {
00123                         pos = gtk_paned_get_position(paned);
00124                         if (pos < 15)
00125                                 {
00126                                         pos = 100;
00127                                         gtk_paned_set_position(paned, pos);
00128                                 }
00129                         move_and_show_dialog_box(heraia_get_widget(main_window->xmls->main, "plugin_list_window"), main_window->win_prop->plugin_list);
00130                 }
00131         else
00132             {
00133                         record_and_hide_dialog_box(GTK_WIDGET(heraia_get_widget(main_window->xmls->main, "plugin_list_window")), main_window->win_prop->plugin_list);
00134             }
00135 }
00136 
00137 
00138 /**
00139  * @fn void print_plugin_info_structure(GtkTextView *textview, heraia_plugin_t *plugin)
00140  *  adds to the textview the relevant informations about the plugin info structure !
00141  * @param textview : the specified textview (the one in the window)
00142  * @param plugin : the plugin we want to print information on
00143  */
00144 static void print_plugin_info_structure(GtkTextView *textview, heraia_plugin_t *plugin)
00145 {
00146         if (plugin->info != NULL)
00147                 {
00148                         switch (plugin->info->type)
00149                                 {
00150                                 case HERAIA_PLUGIN_UNKNOWN:
00151                                         add_text_to_textview(textview, "Type        : Unknown\n");
00152                                         break;
00153 
00154                                 case HERAIA_PLUGIN_FILTER:
00155                                         add_text_to_textview(textview, "Type        : Filter\n");
00156                                         break;
00157 
00158                                 case HERAIA_PLUGIN_ACTION:
00159                                         add_text_to_textview(textview, "Type        : Action\n");
00160                                         break;
00161 
00162                                 default:
00163                                         add_text_to_textview(textview, "Type        : Unknown\n");
00164                                 }
00165 
00166                         add_text_to_textview(textview, "Priority    : %d\n", plugin->info->priority);
00167                         add_text_to_textview(textview, "Id          : %d\n", plugin->info->id);
00168 
00169                         if (plugin->info->name != NULL)
00170                                 {
00171                                         add_text_to_textview(textview, "Name        : %s\n", plugin->info->name);
00172                                 }
00173 
00174                         if (plugin->info->version != NULL)
00175                                 {
00176                                         add_text_to_textview(textview, "Version     : %s\n", plugin->info->version);
00177                                 }
00178 
00179                         if (plugin->info->summary != NULL)
00180                                 {
00181                                         add_text_to_textview(textview, "Summary     : %s\n", plugin->info->summary);
00182                                 }
00183 
00184                         if (plugin->info->description != NULL)
00185                                 {
00186                                         add_text_to_textview(textview, "Description : %s\n", plugin->info->description);
00187                                 }
00188 
00189                         if (plugin->info->author != NULL)
00190                                 {
00191                                         add_text_to_textview(textview, "Author      : %s\n", plugin->info->author);
00192                                 }
00193 
00194                         if (plugin->info->homepage != NULL)
00195                                 {
00196                                         add_text_to_textview(textview, "Web site    : %s\n", plugin->info->homepage);
00197                                 }
00198                 }
00199         else
00200                 {
00201                         add_text_to_textview(textview, "The 'info' structure is not initialized !\n");
00202                 }
00203 }
00204 
00205 /**
00206  * @fn void print_plugin_functions(GtkTextView *textview, heraia_plugin_t *plugin)
00207  *  adds to the textview the relevant informations about the plugin functions !
00208  * @param textview : the specified textview (the one in the window)
00209  * @param plugin : the plugin we want to print information on
00210  */
00211 static void print_plugin_functions(GtkTextView *textview, heraia_plugin_t *plugin)
00212 {
00213 
00214         if (plugin->init_proc != NULL || 
00215                 plugin->run_proc != NULL  ||
00216                 plugin->quit_proc != NULL ||
00217                 plugin->refresh_proc != NULL)
00218                 {
00219                         add_text_to_textview(textview, "\nPlugin's defined functions :\n");
00220 
00221                         if (plugin->init_proc != NULL)
00222                                 {
00223                                         add_text_to_textview(textview, "    - Initialization function : %p\n", plugin->init_proc);
00224                                 }
00225                         
00226                         if (plugin->run_proc != NULL)
00227                                 {
00228                                         add_text_to_textview(textview, "    - Main function           : %p\n", plugin->run_proc);
00229                                 }
00230 
00231                         if (plugin->quit_proc != NULL)
00232                                 {
00233                                         add_text_to_textview(textview, "    - Exit function           : %p\n", plugin->quit_proc);
00234                                 }
00235 
00236                         if (plugin->refresh_proc != NULL)
00237                                 {
00238                                         add_text_to_textview(textview, "    - Refresh function        : %p\n", plugin->refresh_proc);
00239                                 }
00240                 }
00241         else
00242                 {
00243                         add_text_to_textview(textview, "\nThis plugin does not provide any function !!\n");
00244                 }
00245 }
00246 
00247 /**
00248  * @fn void print_plugin_filter_structure(GtkTextView *textview, heraia_plugin_t *plugin)
00249  *  adds to the textview the relevant informations about the plugin filter structure !
00250  * @param textview : the specified textview (the one in the window)
00251  * @param plugin : the plugin we want to print information on
00252  */
00253 static void print_plugin_filter_structure(GtkTextView *textview, heraia_plugin_t *plugin)
00254 {
00255         if (plugin->filter != NULL)
00256                 {
00257                         if (plugin->filter->import != NULL || 
00258                                 plugin->filter->export != NULL)
00259                                 {
00260                                         add_text_to_textview(textview, "\nFilter functions :\n");
00261 
00262                                         if (plugin->filter->import != NULL)
00263                                                 {
00264                                                         add_text_to_textview(textview, "    - Import function : %p\n", plugin->filter->import);
00265                                                 }
00266 
00267                                         if (plugin->filter->export != NULL)
00268                                                 {
00269                                                         add_text_to_textview(textview, "    - Export function : %p\n", plugin->filter->export);
00270                                                 }
00271                                 }
00272                         else
00273                                 {
00274                                         add_text_to_textview(textview, "\nThis plugin does not provide any filter function\n");
00275                                 }
00276                 }
00277         else
00278                 {
00279                         add_text_to_textview(textview, "\nThe structure 'filter' is not initialized !");
00280                 }
00281 }
00282 
00283 /**
00284  * @fn void print_plugin_interface(GtkTextView *textview, heraia_plugin_t *plugin)
00285  *  adds to the textview the relevant informations about the plugin interface (xml) !
00286  * @param textview : the specified textview (the one in the window)
00287  * @param plugin : the plugin we want to print information on
00288  */
00289 static void print_plugin_interface(GtkTextView *textview, heraia_plugin_t *plugin)
00290 {
00291         add_text_to_textview(textview, "\nThis plugin provides :\n");
00292 
00293         if (plugin->cmi_entry != NULL)
00294                 {
00295                         add_text_to_textview(textview, "  - a menu entry in the plugins menu.\n");
00296                 }
00297         else
00298                 {
00299                         add_text_to_textview(textview, "  - no menu entry.\n");
00300                 }
00301           
00302         if (plugin->xml != NULL)
00303                 {
00304                         add_text_to_textview(textview, "  - an xml interface.\n");
00305                 }
00306         else
00307                 {
00308                         add_text_to_textview(textview, "  - no xml interface.\n");
00309                 }
00310 }
00311 
00312 /**
00313  * @fn void print_plugin_basics(GtkTextView *textview, heraia_plugin_t *plugin)
00314  *  adds to the textview the relevant informations about the plugin basics !
00315  * @param textview : the specified textview (the one in the window)
00316  * @param plugin : the plugin we want to print information on
00317  */
00318 static void print_plugin_basics(GtkTextView *textview, heraia_plugin_t *plugin)
00319 {
00320         if (plugin->info != NULL)
00321                 {
00322                         add_text_to_textview(textview, "API version : %d\n", plugin->info->api_version);
00323                 }
00324 
00325         if (plugin->filename != NULL)
00326                 {
00327                         add_text_to_textview(textview, "File        : %s\n", plugin->filename);
00328                 }
00329 
00330         if (plugin->path != NULL)
00331                 {
00332                         add_text_to_textview(textview, "Directory  : %s\n", plugin->path);
00333                 }
00334 
00335         if (plugin->handle != NULL)
00336                 {
00337                         add_text_to_textview(textview, "Handle      : %p\n", plugin->handle);
00338                 }
00339         else
00340                 {
00341                         add_text_to_textview(textview, "Handle      : NONE <-- Is there anything normal ?\n");
00342                 }
00343 }
00344 
00345 /**
00346  * @fn void print_plugin_extra_structure(GtkTextView *textview, heraia_plugin_t *plugin)
00347  *  adds to the textview the relevant informations about the plugin extra structure !
00348  * @param textview : the specified textview (the one in the window)
00349  * @param plugin : the plugin we want to print information on
00350  */
00351 static void print_plugin_extra_structure(GtkTextView *textview, heraia_plugin_t *plugin)
00352 {
00353 
00354         if (plugin->extra != NULL)
00355                 {
00356                         add_text_to_textview(textview, "\nThis plugin has an additionnal 'extra' structure (%p) sized %d bytes.\n", 
00357                                                                  plugin->extra, sizeof(*(plugin->extra)));
00358                 }
00359         else
00360                 {
00361                         add_text_to_textview(textview, "\nThis plugin does not have any additionnal structure.\n");
00362                 }
00363 
00364 }
00365 
00366 /**
00367  * @fn void print_plugin_state(GtkTextView *textview, heraia_plugin_t *plugin)
00368  *  adds to the textview the relevant informations about the plugin state !
00369  * @param textview : the specified textview (the one in the window)
00370  * @param plugin : the plugin we want to print information on
00371  */
00372 static void print_plugin_state(GtkTextView *textview, heraia_plugin_t *plugin)
00373 {
00374 
00375         add_text_to_textview(textview, "Plugin's state : ");
00376         switch (plugin->state)
00377                 {
00378                 case PLUGIN_STATE_RUNNING:
00379                         add_text_to_textview(textview, "Running\n");
00380                         break;
00381 
00382                 case PLUGIN_STATE_INITIALIZING:
00383                         add_text_to_textview(textview, "Initialiazing or initialized\n");
00384                         break;
00385                 case PLUGIN_STATE_LOADED:
00386                         add_text_to_textview(textview, "Loaded\n");
00387                         break;
00388 
00389                 case PLUGIN_STATE_NEW:
00390                         add_text_to_textview(textview, "Creating itself\n");
00391                         break;
00392 
00393                 case PLUGIN_STATE_EXITING:
00394                         add_text_to_textview(textview, "Exiting\n");
00395                         break;
00396 
00397                 case PLUGIN_STATE_NONE:
00398                         add_text_to_textview(textview, "Waiting\n");
00399                         break;
00400 
00401                 default:
00402                         add_text_to_textview(textview, "Unknown\n");
00403                 }
00404 }
00405 
00406 /**
00407  * @fn void pn_treeview_selection_changed_cb(GtkTreeSelection *selection, gpointer data)
00408  *  Function called when the selection changes in the treeview
00409  *  Displays informations about the selected plugin
00410  * @param selection : user selection in the treeview
00411  * @param data : MUST be heraia_window_t *main_window main structure (must not be NULL)
00412  */
00413 static void pn_treeview_selection_changed_cb(GtkTreeSelection *selection, gpointer data)
00414 {
00415         GtkTreeIter iter;            
00416         GtkTreeModel *model = NULL;
00417         heraia_window_t *main_window = (heraia_window_t *) data;
00418         gchar *name = NULL;
00419         heraia_plugin_t *plugin = NULL;
00420         GtkTextView *textview = GTK_TEXT_VIEW(heraia_get_widget(main_window->xmls->main, "plugin_info_textview"));
00421 
00422         if (gtk_tree_selection_get_selected(selection, &model, &iter))
00423                 {
00424                         gtk_tree_model_get(model, &iter, PNTV_COLUMN_NAME, &name, -1);
00425                         plugin = find_plugin_by_name(main_window->plugins_list, name);
00426 
00427                         if (plugin != NULL)
00428                                 {
00429                                         kill_text_from_textview(textview);
00430                                         
00431                                         print_plugin_basics(textview, plugin);
00432                                                                                 
00433                                         print_plugin_info_structure(textview, plugin);
00434 
00435                                         print_plugin_functions(textview, plugin);
00436 
00437                                         print_plugin_filter_structure(textview, plugin);
00438 
00439                                         print_plugin_interface(textview, plugin);
00440 
00441                                         print_plugin_extra_structure(textview, plugin);
00442 
00443                                         print_plugin_state(textview, plugin);
00444                                 }
00445                 }
00446 }
00447 /*** End of callback functions that handle the plugins window ***/
00448 
00449 /**
00450  * @fn void plugin_list_window_connect_signals(heraia_window_t *main_window)
00451  *  Connecting all signals to the right functions
00452  * @param main_window : main structure
00453  */
00454 static void plugin_list_window_connect_signals(heraia_window_t *main_window)
00455 {
00456         GtkTreeSelection *select = NULL;
00457  
00458         if (main_window != NULL)
00459                 {
00460                         /* When the plugin list window is destroyed or killed */
00461                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "plugin_list_window")), "delete_event", 
00462                                                          G_CALLBACK(delete_plw_window_event), main_window);
00463 
00464                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "plugin_list_window")), "destroy", 
00465                                                          G_CALLBACK(destroy_plw_window), main_window);
00466         
00467                         /* Close button */
00468                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "plw_close_b")), "clicked", 
00469                                                          G_CALLBACK(plw_close_clicked), main_window);
00470 
00471                         /* The toogle button */
00472                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list")), "toggled",
00473                                                          G_CALLBACK(mw_cmi_plw_toggle), main_window);
00474      
00475                         /* Selection has changed for the pn_treeview */
00476                         select = gtk_tree_view_get_selection(GTK_TREE_VIEW(heraia_get_widget(main_window->xmls->main, "pn_treeview")));
00477                         gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
00478                         g_signal_connect(G_OBJECT(select), "changed", G_CALLBACK (pn_treeview_selection_changed_cb), main_window);
00479 
00480                         /* Refresh button */
00481                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "plw_refresh_b")), "clicked", 
00482                                                          G_CALLBACK(plw_refresh_clicked), main_window);
00483                 }
00484 }
00485 
00486 /**
00487  * @fn void init_plugin_name_tv(heraia_window_t *main_window)
00488  *  Function to init the first treeview (plugin names)
00489  * @param main_window : main structure
00490  */
00491 static void init_plugin_name_tv(heraia_window_t *main_window)
00492 {
00493         GtkListStore *list_store = NULL;  /**< Treeview Stuff for rendering */
00494         GtkTreeIter iter;                 /**< the text in it.              */
00495         GtkCellRenderer *renderer = NULL; 
00496 
00497         GtkTreeViewColumn *column = NULL;  
00498         heraia_plugin_t *plugin = NULL;   /**< plugin interface structure   */
00499         GList *p_list = NULL;             /**< plugin list                  */
00500         GtkTreeView *treeview = NULL;     /**< Treeview where plugin names are to be displayed */
00501 
00502         if (main_window != NULL)
00503                 {
00504                         treeview = GTK_TREE_VIEW(heraia_get_widget(main_window->xmls->main, "pn_treeview"));
00505 
00506                         p_list = g_list_first(main_window->plugins_list);
00507 
00508                         list_store = gtk_list_store_new(PNTV_N_COLUMNS, G_TYPE_STRING);
00509       
00510                         while (p_list != NULL)
00511                                 {
00512                                         plugin = (heraia_plugin_t *) p_list->data;
00513                                         log_message(main_window, G_LOG_LEVEL_INFO, "%s", plugin->info->name);
00514 
00515                                         gtk_list_store_append(list_store, &iter);
00516                                         gtk_list_store_set(list_store, &iter, PNTV_COLUMN_NAME, plugin->info->name, -1);
00517                         
00518                                         p_list = p_list->next;
00519                                 }
00520                    
00521                         gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(list_store));
00522 
00523                         column = gtk_tree_view_get_column(treeview, PNTV_COLUMN_NAME);
00524 
00525                         if (column != NULL)
00526                                 {
00527                                         gtk_tree_view_remove_column(treeview, column);
00528                                 }
00529                    
00530                         renderer = gtk_cell_renderer_text_new();
00531                         column = gtk_tree_view_column_new_with_attributes("Name", renderer, "text", PNTV_COLUMN_NAME, NULL);
00532                         gtk_tree_view_append_column(treeview, column);
00533                 }
00534 }
00535 
00536 
00537 /**
00538  * @fn plugin_list_window_init_interface(heraia_window_t *main_window)
00539  *  the function to init the plugin_list_window interface 
00540  * @param main_window : main structure
00541  */
00542 void plugin_list_window_init_interface(heraia_window_t *main_window)
00543 {
00544 
00545         plugin_list_window_connect_signals(main_window);
00546 
00547         init_plugin_name_tv(main_window);
00548 }
00549 
00550 
00551 
00552 
00553 
00554 

Generated on Sat Feb 14 11:44:16 2009 for Heraia by  doxygen 1.5.6