Mercurial > pidgin
comparison src/gtkplugin.c @ 11781:10317f1a2de2
[gaim-migrate @ 14072]
Kevin Stange fixed the plugin prefs to not be accessible until the plugin is loaded
committer: Tailor Script <tailor@pidgin.im>
| author | Daniel Atallah <daniel.atallah@gmail.com> |
|---|---|
| date | Mon, 24 Oct 2005 01:40:51 +0000 |
| parents | 1253620ea5f2 |
| children | b75d8a37e603 |
comparison
equal
deleted
inserted
replaced
| 11780:8cb75ba77f9d | 11781:10317f1a2de2 |
|---|---|
| 31 #include <string.h> | 31 #include <string.h> |
| 32 | 32 |
| 33 static GtkWidget *plugin_dialog = NULL; | 33 static GtkWidget *plugin_dialog = NULL; |
| 34 static GtkWidget *plugin_details = NULL; | 34 static GtkWidget *plugin_details = NULL; |
| 35 static GtkWidget *pref_button = NULL; | 35 static GtkWidget *pref_button = NULL; |
| 36 static GHashTable *plugin_pref_dialogs = NULL; | |
| 36 | 37 |
| 37 GtkWidget * | 38 GtkWidget * |
| 38 gaim_gtk_plugin_get_config_frame(GaimPlugin *plugin) | 39 gaim_gtk_plugin_get_config_frame(GaimPlugin *plugin) |
| 39 { | 40 { |
| 40 GaimGtkPluginUiInfo *ui_info; | 41 GaimGtkPluginUiInfo *ui_info; |
| 108 2, plug, -1); | 109 2, plug, -1); |
| 109 g_free(desc); | 110 g_free(desc); |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 114 static void pref_dialog_response_cb(GtkWidget *d, int response, GaimPlugin *plug) | |
| 115 { | |
| 116 switch (response) { | |
| 117 case GTK_RESPONSE_CLOSE: | |
| 118 case GTK_RESPONSE_DELETE_EVENT: | |
| 119 g_hash_table_remove(plugin_pref_dialogs, plug); | |
| 120 if (g_hash_table_size(plugin_pref_dialogs) == 0) { | |
| 121 g_hash_table_destroy(plugin_pref_dialogs); | |
| 122 plugin_pref_dialogs = NULL; | |
| 123 } | |
| 124 gtk_widget_destroy(d); | |
| 125 break; | |
| 126 } | |
| 127 } | |
| 128 | |
| 113 static void plugin_load (GtkCellRendererToggle *cell, gchar *pth, gpointer data) | 129 static void plugin_load (GtkCellRendererToggle *cell, gchar *pth, gpointer data) |
| 114 { | 130 { |
| 115 GtkTreeModel *model = (GtkTreeModel *)data; | 131 GtkTreeModel *model = (GtkTreeModel *)data; |
| 116 GtkTreeIter iter; | 132 GtkTreeIter iter; |
| 117 GtkTreePath *path = gtk_tree_path_new_from_string(pth); | 133 GtkTreePath *path = gtk_tree_path_new_from_string(pth); |
| 118 GaimPlugin *plug; | 134 GaimPlugin *plug; |
| 119 gchar buf[1024]; | 135 gchar buf[1024]; |
| 120 gchar *name = NULL, *description = NULL; | 136 gchar *name = NULL, *description = NULL; |
| 137 GtkWidget *dialog = NULL; | |
| 121 | 138 |
| 122 GdkCursor *wait = gdk_cursor_new (GDK_WATCH); | 139 GdkCursor *wait = gdk_cursor_new (GDK_WATCH); |
| 123 gdk_window_set_cursor(plugin_dialog->window, wait); | 140 gdk_window_set_cursor(plugin_dialog->window, wait); |
| 124 gdk_cursor_unref(wait); | 141 gdk_cursor_unref(wait); |
| 125 | 142 |
| 126 gtk_tree_model_get_iter (model, &iter, path); | 143 gtk_tree_model_get_iter (model, &iter, path); |
| 127 gtk_tree_model_get (model, &iter, 2, &plug, -1); | 144 gtk_tree_model_get (model, &iter, 2, &plug, -1); |
| 128 | 145 |
| 129 if (!gaim_plugin_is_loaded(plug)) | 146 if (!gaim_plugin_is_loaded(plug)) |
| 130 gaim_plugin_load(plug); | 147 gaim_plugin_load(plug); |
| 131 else | 148 else { |
| 149 if (plugin_pref_dialogs != NULL && | |
| 150 (dialog = g_hash_table_lookup(plugin_pref_dialogs, plug))) | |
| 151 pref_dialog_response_cb(dialog, GTK_RESPONSE_DELETE_EVENT, plug); | |
| 132 gaim_plugin_unload(plug); | 152 gaim_plugin_unload(plug); |
| 133 | 153 } |
| 154 | |
| 155 gtk_widget_set_sensitive(pref_button, | |
| 156 plug->info->ui_info != NULL && | |
| 157 GAIM_GTK_PLUGIN_UI_INFO(plug)->get_config_frame != NULL && | |
| 158 gaim_plugin_is_loaded(plug)); | |
| 134 | 159 |
| 135 gdk_window_set_cursor(plugin_dialog->window, NULL); | 160 gdk_window_set_cursor(plugin_dialog->window, NULL); |
| 136 | 161 |
| 137 name = g_markup_escape_text(_(plug->info->name), -1); | 162 name = g_markup_escape_text(_(plug->info->name), -1); |
| 138 description = g_markup_escape_text(_(plug->info->description), -1); | 163 description = g_markup_escape_text(_(plug->info->description), -1); |
| 139 | 164 |
| 140 if (plug->error != NULL) { | 165 if (plug->error != NULL) { |
| 141 gchar *error = g_markup_escape_text(plug->error, -1); | 166 gchar *error = g_markup_escape_text(plug->error, -1); |
| 142 gchar *desc; | 167 gchar *desc; |
| 143 g_snprintf(buf, sizeof(buf), | 168 g_snprintf(buf, sizeof(buf), |
| 144 "<span size=\"larger\">%s %s</span>\n\n" | 169 "<span size=\"larger\">%s %s</span>\n\n" |
| 145 "<span weight=\"bold\" color=\"red\">%s</span>\n\n" | 170 "<span weight=\"bold\" color=\"red\">%s</span>\n\n" |
| 146 "%s", | 171 "%s", |
| 147 name, plug->info->version, error, description); | 172 name, plug->info->version, error, description); |
| 148 desc = g_strdup_printf("<b>%s</b> %s\n<span weight=\"bold\" color=\"red\"%s</span>", | 173 desc = g_strdup_printf("<b>%s</b> %s\n<span weight=\"bold\" color=\"red\"%s</span>", |
| 149 plug->info->name, plug->info->version, error); | 174 plug->info->name, plug->info->version, error); |
| 150 gtk_list_store_set (GTK_LIST_STORE (model), &iter, | 175 gtk_list_store_set (GTK_LIST_STORE (model), &iter, |
| 151 1, desc, | 176 1, desc, |
| 152 -1); | 177 -1); |
| 153 g_free(desc); | 178 g_free(desc); |
| 154 g_free(error); | 179 g_free(error); |
| 155 } else { | 180 } else { |
| 205 pdesc ? pdesc : "", pdesc ? "\n\n" : "", | 230 pdesc ? pdesc : "", pdesc ? "\n\n" : "", |
| 206 pauth ? pauth : "", pweb ? pweb : "", plug->path); | 231 pauth ? pauth : "", pweb ? pweb : "", plug->path); |
| 207 | 232 |
| 208 gtk_widget_set_sensitive(pref_button, | 233 gtk_widget_set_sensitive(pref_button, |
| 209 plug->info->ui_info != NULL && | 234 plug->info->ui_info != NULL && |
| 210 GAIM_GTK_PLUGIN_UI_INFO(plug)->get_config_frame != NULL); | 235 GAIM_GTK_PLUGIN_UI_INFO(plug)->get_config_frame != NULL && |
| 236 gaim_plugin_is_loaded(plug)); | |
| 211 gtk_label_set_markup(GTK_LABEL(plugin_details), buf); | 237 gtk_label_set_markup(GTK_LABEL(plugin_details), buf); |
| 212 g_value_unset(&val); | 238 g_value_unset(&val); |
| 213 g_free(buf); | 239 g_free(buf); |
| 214 g_free(pname); | 240 g_free(pname); |
| 215 g_free(pdesc); | 241 g_free(pdesc); |
| 216 g_free(pauth); | 242 g_free(pauth); |
| 217 g_free(pweb); | 243 g_free(pweb); |
| 218 } | 244 } |
| 219 | 245 |
| 220 static GSList *plugin_pref_dialogs = NULL; | |
| 221 static void pref_dialog_response_cb(GtkWidget *d, int response, GaimPlugin *plug) | |
| 222 { | |
| 223 switch (response) { | |
| 224 case GTK_RESPONSE_CLOSE: | |
| 225 case GTK_RESPONSE_DELETE_EVENT: | |
| 226 plugin_pref_dialogs = g_slist_remove(plugin_pref_dialogs, plug); | |
| 227 gtk_widget_destroy(d); | |
| 228 break; | |
| 229 } | |
| 230 } | |
| 231 static void plugin_dialog_response_cb(GtkWidget *d, int response, GtkTreeSelection *sel) | 246 static void plugin_dialog_response_cb(GtkWidget *d, int response, GtkTreeSelection *sel) |
| 232 { | 247 { |
| 233 GaimPlugin *plug; | 248 GaimPlugin *plug; |
| 234 GtkWidget *dialog, *box; | 249 GtkWidget *dialog, *box; |
| 235 GtkTreeModel *model; | 250 GtkTreeModel *model; |
| 247 return; | 262 return; |
| 248 gtk_tree_model_get_value (model, &iter, 2, &val); | 263 gtk_tree_model_get_value (model, &iter, 2, &val); |
| 249 plug = g_value_get_pointer(&val); | 264 plug = g_value_get_pointer(&val); |
| 250 if (plug == NULL) | 265 if (plug == NULL) |
| 251 break; | 266 break; |
| 252 if (g_slist_find(plugin_pref_dialogs, plug)) | 267 if (plugin_pref_dialogs != NULL && |
| 268 g_hash_table_lookup(plugin_pref_dialogs, plug)) | |
| 253 break; | 269 break; |
| 254 plugin_pref_dialogs = g_slist_prepend(plugin_pref_dialogs, plug); | |
| 255 box = gaim_gtk_plugin_get_config_frame(plug); | 270 box = gaim_gtk_plugin_get_config_frame(plug); |
| 256 if (box == NULL) | 271 if (box == NULL) |
| 257 break; | 272 break; |
| 258 | 273 |
| 259 dialog = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, GTK_WINDOW(d), | 274 dialog = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, GTK_WINDOW(d), |
| 260 GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, | 275 GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, |
| 261 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, | 276 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
| 262 NULL); | 277 NULL); |
| 278 if (plugin_pref_dialogs == NULL) | |
| 279 plugin_pref_dialogs = g_hash_table_new(NULL, NULL); | |
| 280 | |
| 281 g_hash_table_insert(plugin_pref_dialogs, plug, dialog); | |
| 282 | |
| 263 g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(pref_dialog_response_cb), plug); | 283 g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(pref_dialog_response_cb), plug); |
| 264 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box); | 284 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box); |
| 265 gtk_window_set_role(GTK_WINDOW(dialog), "plugin_config"); | 285 gtk_window_set_role(GTK_WINDOW(dialog), "plugin_config"); |
| 266 gtk_window_set_title(GTK_WINDOW(dialog), gaim_plugin_get_name(plug)); | 286 gtk_window_set_title(GTK_WINDOW(dialog), gaim_plugin_get_name(plug)); |
| 267 gtk_widget_show_all(dialog); | 287 gtk_widget_show_all(dialog); |
