comparison console/gntplugin.c @ 14148:5b9daf111b42

[gaim-migrate @ 16793] Handle the plugin-pref windows better. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 16 Aug 2006 17:10:36 +0000
parents 44ec6c7cbc76
children 81650a27f253
comparison
equal deleted inserted replaced
14147:6a19a83ed49f 14148:5b9daf111b42
15 GntWidget *tree; 15 GntWidget *tree;
16 GntWidget *window; 16 GntWidget *window;
17 GntWidget *aboot; 17 GntWidget *aboot;
18 GntWidget *conf; 18 GntWidget *conf;
19 } plugins; 19 } plugins;
20
21 static GHashTable *confwins;
20 22
21 static void 23 static void
22 decide_conf_button(GaimPlugin *plugin) 24 decide_conf_button(GaimPlugin *plugin)
23 { 25 {
24 if (gaim_plugin_is_loaded(plugin) && 26 if (gaim_plugin_is_loaded(plugin) &&
42 if(!gaim_plugin_load(plugin)) 44 if(!gaim_plugin_load(plugin))
43 gaim_notify_error(NULL, "ERROR", "loading plugin failed", NULL); 45 gaim_notify_error(NULL, "ERROR", "loading plugin failed", NULL);
44 } 46 }
45 else 47 else
46 { 48 {
49 GntWidget *win;
50
47 if (!gaim_plugin_unload(plugin)) 51 if (!gaim_plugin_unload(plugin))
48 gaim_notify_error(NULL, "ERROR", "unloading plugin failed", NULL); 52 gaim_notify_error(NULL, "ERROR", "unloading plugin failed", NULL);
53
54 if ((win = g_hash_table_lookup(confwins, plugin)) != NULL)
55 {
56 gnt_widget_destroy(win);
57 }
49 } 58 }
50 decide_conf_button(plugin); 59 decide_conf_button(plugin);
51 gg_plugins_save_loaded(); 60 gg_plugins_save_loaded();
52 } 61 }
53 62
109 g_free(s2); 118 g_free(s2);
110 return ret; 119 return ret;
111 } 120 }
112 121
113 static void 122 static void
123 confwin_init()
124 {
125 confwins = g_hash_table_new(g_direct_hash, g_direct_equal);
126 }
127
128 static void
129 remove_confwin(GntWidget *window, gpointer plugin)
130 {
131 g_hash_table_remove(confwins, plugin);
132 }
133
134 static void
114 configure_plugin_cb(GntWidget *button, gpointer null) 135 configure_plugin_cb(GntWidget *button, gpointer null)
115 { 136 {
116 GaimPlugin *plugin; 137 GaimPlugin *plugin;
117 GGPluginFrame callback; 138 GGPluginFrame callback;
118 139
123 { 144 {
124 gaim_notify_error(plugin, _("Error"), 145 gaim_notify_error(plugin, _("Error"),
125 _("Plugin need to be loaded before you can configure it."), NULL); 146 _("Plugin need to be loaded before you can configure it."), NULL);
126 return; 147 return;
127 } 148 }
149
150 if (confwins && g_hash_table_lookup(confwins, plugin))
151 return;
128 152
129 if (GAIM_IS_GNT_PLUGIN(plugin) && 153 if (GAIM_IS_GNT_PLUGIN(plugin) &&
130 (callback = GAIM_GNT_PLUGIN_UI_INFO(plugin)) != NULL) 154 (callback = GAIM_GNT_PLUGIN_UI_INFO(plugin)) != NULL)
131 { 155 {
132 GntWidget *window = gnt_vbox_new(FALSE); 156 GntWidget *window = gnt_vbox_new(FALSE);
144 168
145 button = gnt_button_new(_("Close")); 169 button = gnt_button_new(_("Close"));
146 gnt_box_add_widget(GNT_BOX(box), button); 170 gnt_box_add_widget(GNT_BOX(box), button);
147 g_signal_connect_swapped(G_OBJECT(button), "activate", 171 g_signal_connect_swapped(G_OBJECT(button), "activate",
148 G_CALLBACK(gnt_widget_destroy), window); 172 G_CALLBACK(gnt_widget_destroy), window);
149 173 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(remove_confwin), plugin);
150 gnt_widget_show(window); /* XXX: This window needs to be closed when the plugin is unloaded */ 174
175 gnt_widget_show(window);
176
177 if (confwins == NULL)
178 confwin_init();
179 g_hash_table_insert(confwins, plugin, window);
151 } 180 }
152 else if (plugin->info->prefs_info && 181 else if (plugin->info->prefs_info &&
153 plugin->info->prefs_info->get_plugin_pref_frame) 182 plugin->info->prefs_info->get_plugin_pref_frame)
154 { 183 {
155 gaim_notify_info(plugin, _("..."), 184 gaim_notify_info(plugin, _("..."),