+/* Dispaly a file selection dialogue to let user select a library, then call
+ * lttv_library_load().
+ */
+
+void
+on_load_library_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
+
+ gchar load_module_path_alter[PATH_MAX];
+ {
+ GPtrArray *name;
+ guint nb,i;
+ gchar *load_module_path;
+ name = g_ptr_array_new();
+ nb = lttv_library_path_number();
+ /* ask for the library path */
+
+ for(i=0;i<nb;i++){
+ gchar *path;
+ path = lttv_library_path_get(i);
+ g_ptr_array_add(name, path);
+ }
+
+ load_module_path = get_selection((char **)(name->pdata), name->len,
+ "Select a library path", "Library paths");
+ if(load_module_path != NULL)
+ strncpy(load_module_path_alter, load_module_path, PATH_MAX-1); // -1 for /
+
+ g_ptr_array_free(name, TRUE);
+
+ if(load_module_path == NULL) return;
+ }
+
+ {
+ /* Make sure the module path ends with a / */
+ gchar *ptr = load_module_path_alter;
+
+ ptr = strchr(ptr, '\0');
+
+ if(*(ptr-1) != '/') {
+ *ptr = '/';
+ *(ptr+1) = '\0';
+ }
+ }
+
+ {
+ /* Ask for the library to load : list files in the previously selected
+ * directory */
+ gchar str[PATH_MAX];
+ gchar ** dir;
+ gint id;
+ GtkFileSelection * file_selector =
+ (GtkFileSelection *)gtk_file_selection_new("Select a module");
+ gtk_file_selection_set_filename(file_selector, load_module_path_alter);
+ gtk_file_selection_hide_fileop_buttons(file_selector);
+
+ str[0] = '\0';
+ id = gtk_dialog_run(GTK_DIALOG(file_selector));
+ switch(id){
+ case GTK_RESPONSE_ACCEPT:
+ case GTK_RESPONSE_OK:
+ dir = gtk_file_selection_get_selections (file_selector);
+ strncpy(str,dir[0],PATH_MAX);
+ strncpy(remember_plugins_dir,dir[0],PATH_MAX);
+ /* only keep file name */
+ gchar *str1;
+ str1 = strrchr(str,'/');
+ if(str1)str1++;
+ else{
+ str1 = strrchr(str,'\\');
+ str1++;
+ }
+#if 0
+ /* remove "lib" */
+ if(*str1 == 'l' && *(str1+1)== 'i' && *(str1+2)=='b')
+ str1=str1+3;
+ remove info after . */
+ {
+ gchar *str2 = str1;
+
+ str2 = strrchr(str2, '.');
+ if(str2 != NULL) *str2 = '\0';
+ }
+ lttv_module_require(str1, &error);
+#endif //0
+ lttv_library_load(str1, &error);
+ if(error != NULL) g_warning(error->message);
+ else g_printf("Load library: %s\n", str);
+ g_strfreev(dir);
+ case GTK_RESPONSE_REJECT:
+ case GTK_RESPONSE_CANCEL:
+ default:
+ gtk_widget_destroy((GtkWidget*)file_selector);
+ break;
+ }
+
+ }
+
+
+
+}
+
+
+/* Display all loaded modules, let user to select a module to unload
+ * by calling lttv_module_unload
+ */
+
+void
+on_unload_library_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
+
+ LttvLibrary *library;
+ {
+ GPtrArray *name;
+ guint nb,i;
+ gchar *lib_name;
+ name = g_ptr_array_new();
+ nb = lttv_library_number();
+ LttvLibraryInfo *lib_info = g_new(LttvLibraryInfo,nb);
+ /* ask for the library name */
+
+ for(i=0;i<nb;i++){
+ LttvLibrary *iter_lib = lttv_library_get(i);
+ lttv_library_info(iter_lib, &lib_info[i]);
+
+ gchar *path = lib_info[i].name;
+ g_ptr_array_add(name, lib_info[i].name);
+ }
+ lib_name = get_selection((char **)(name->pdata), name->len,
+ "Select a library", "Libraries");
+ if(lib_name != NULL) {
+ for(i=0;i<nb;i++){
+ if(strcmp(lib_name, lib_info[i].name) == 0) {
+ library = lttv_library_get(i);
+ break;
+ }
+ }
+ }
+ g_ptr_array_free(name, TRUE);
+ g_free(lib_info);
+
+ if(lib_name == NULL) return;
+ }
+
+ lttv_library_unload(library);
+}
+
+