| 1 /** |
|
| 2 * @file gtkplugin.c GTK+ Plugins support |
|
| 3 * @ingroup gtkui |
|
| 4 * |
|
| 5 * gaim |
|
| 6 * |
|
| 7 * Gaim is the legal property of its developers, whose names are too numerous |
|
| 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
| 9 * source distribution. |
|
| 10 * |
|
| 11 * This program is free software; you can redistribute it and/or modify |
|
| 12 * it under the terms of the GNU General Public License as published by |
|
| 13 * the Free Software Foundation; either version 2 of the License, or |
|
| 14 * (at your option) any later version. |
|
| 15 * |
|
| 16 * This program is distributed in the hope that it will be useful, |
|
| 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 * GNU General Public License for more details. |
|
| 20 * |
|
| 21 * You should have received a copy of the GNU General Public License |
|
| 22 * along with this program; if not, write to the Free Software |
|
| 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 24 */ |
|
| 25 #include "internal.h" |
|
| 26 #include "gtkgaim.h" |
|
| 27 #include "gtkplugin.h" |
|
| 28 #include "gtkpluginpref.h" |
|
| 29 #include "gtkutils.h" |
|
| 30 #include "debug.h" |
|
| 31 #include "prefs.h" |
|
| 32 #include "request.h" |
|
| 33 |
|
| 34 #include <string.h> |
|
| 35 |
|
| 36 #define GAIM_RESPONSE_CONFIGURE 98121 |
|
| 37 |
|
| 38 static void plugin_toggled_stage_two(GaimPlugin *plug, GtkTreeModel *model, |
|
| 39 GtkTreeIter *iter, gboolean unload); |
|
| 40 |
|
| 41 static GtkWidget *expander = NULL; |
|
| 42 static GtkWidget *plugin_dialog = NULL; |
|
| 43 static GtkWidget *plugin_details = NULL; |
|
| 44 static GtkWidget *pref_button = NULL; |
|
| 45 static GHashTable *plugin_pref_dialogs = NULL; |
|
| 46 |
|
| 47 GtkWidget * |
|
| 48 gaim_gtk_plugin_get_config_frame(GaimPlugin *plugin) |
|
| 49 { |
|
| 50 GtkWidget *config = NULL; |
|
| 51 |
|
| 52 g_return_val_if_fail(plugin != NULL, NULL); |
|
| 53 |
|
| 54 if (GAIM_IS_GTK_PLUGIN(plugin) && plugin->info->ui_info |
|
| 55 && GAIM_GTK_PLUGIN_UI_INFO(plugin)->get_config_frame) |
|
| 56 { |
|
| 57 GaimGtkPluginUiInfo *ui_info; |
|
| 58 |
|
| 59 ui_info = GAIM_GTK_PLUGIN_UI_INFO(plugin); |
|
| 60 |
|
| 61 config = ui_info->get_config_frame(plugin); |
|
| 62 |
|
| 63 if (plugin->info->prefs_info |
|
| 64 && plugin->info->prefs_info->get_plugin_pref_frame) |
|
| 65 { |
|
| 66 gaim_debug_warning("gtkplugin", |
|
| 67 "Plugin %s contains both, ui_info and " |
|
| 68 "prefs_info preferences; prefs_info will be " |
|
| 69 "ignored.", plugin->info->name); |
|
| 70 } |
|
| 71 } |
|
| 72 |
|
| 73 if (config == NULL && plugin->info->prefs_info |
|
| 74 && plugin->info->prefs_info->get_plugin_pref_frame) |
|
| 75 { |
|
| 76 GaimPluginPrefFrame *frame; |
|
| 77 |
|
| 78 frame = plugin->info->prefs_info->get_plugin_pref_frame(plugin); |
|
| 79 |
|
| 80 config = gaim_gtk_plugin_pref_create_frame(frame); |
|
| 81 |
|
| 82 /* XXX According to bug #1407047 this broke saving pluging preferences, I'll look at fixing it correctly later. |
|
| 83 gaim_plugin_pref_frame_destroy(frame); |
|
| 84 */ |
|
| 85 } |
|
| 86 |
|
| 87 return config; |
|
| 88 } |
|
| 89 |
|
| 90 void |
|
| 91 gaim_gtk_plugins_save(void) |
|
| 92 { |
|
| 93 GList *pl; |
|
| 94 GList *files = NULL; |
|
| 95 GaimPlugin *p; |
|
| 96 |
|
| 97 for (pl = gaim_plugins_get_loaded(); pl != NULL; pl = pl->next) { |
|
| 98 p = pl->data; |
|
| 99 |
|
| 100 if (p->info->type != GAIM_PLUGIN_PROTOCOL && |
|
| 101 p->info->type != GAIM_PLUGIN_LOADER) { |
|
| 102 |
|
| 103 files = g_list_append(files, p->path); |
|
| 104 } |
|
| 105 } |
|
| 106 |
|
| 107 gaim_prefs_set_string_list("/gaim/gtk/plugins/loaded", files); |
|
| 108 g_list_free(files); |
|
| 109 } |
|
| 110 |
|
| 111 static void |
|
| 112 update_plugin_list(void *data) |
|
| 113 { |
|
| 114 GtkListStore *ls = GTK_LIST_STORE(data); |
|
| 115 GtkTreeIter iter; |
|
| 116 GList *probes; |
|
| 117 GaimPlugin *plug; |
|
| 118 |
|
| 119 gtk_list_store_clear(ls); |
|
| 120 gaim_plugins_probe(G_MODULE_SUFFIX); |
|
| 121 |
|
| 122 for (probes = gaim_plugins_get_all(); |
|
| 123 probes != NULL; |
|
| 124 probes = probes->next) |
|
| 125 { |
|
| 126 char *name; |
|
| 127 char *version; |
|
| 128 char *summary; |
|
| 129 char *desc; |
|
| 130 plug = probes->data; |
|
| 131 |
|
| 132 if (plug->info->type != GAIM_PLUGIN_STANDARD || |
|
| 133 (plug->info->flags & GAIM_PLUGIN_FLAG_INVISIBLE)) |
|
| 134 { |
|
| 135 continue; |
|
| 136 } |
|
| 137 |
|
| 138 gtk_list_store_append (ls, &iter); |
|
| 139 |
|
| 140 name = g_markup_escape_text(plug->info->name ? _(plug->info->name) : g_basename(plug->path), -1); |
|
| 141 version = g_markup_escape_text(plug->info->version, -1); |
|
| 142 summary = g_markup_escape_text(_(plug->info->summary), -1); |
|
| 143 |
|
| 144 desc = g_strdup_printf("<b>%s</b> %s\n%s", name, |
|
| 145 version, |
|
| 146 summary); |
|
| 147 g_free(name); |
|
| 148 g_free(version); |
|
| 149 g_free(summary); |
|
| 150 |
|
| 151 gtk_list_store_set(ls, &iter, |
|
| 152 0, gaim_plugin_is_loaded(plug), |
|
| 153 1, desc, |
|
| 154 2, plug, |
|
| 155 3, gaim_plugin_is_unloadable(plug), |
|
| 156 -1); |
|
| 157 g_free(desc); |
|
| 158 } |
|
| 159 } |
|
| 160 |
|
| 161 static void plugin_loading_common(GaimPlugin *plugin, GtkTreeView *view, gboolean loaded) |
|
| 162 { |
|
| 163 GtkTreeIter iter; |
|
| 164 GtkTreeModel *model = gtk_tree_view_get_model(view); |
|
| 165 |
|
| 166 if (gtk_tree_model_get_iter_first(model, &iter)) { |
|
| 167 do { |
|
| 168 GaimPlugin *plug; |
|
| 169 GtkTreeSelection *sel; |
|
| 170 |
|
| 171 gtk_tree_model_get(model, &iter, 2, &plug, -1); |
|
| 172 |
|
| 173 if (plug != plugin) |
|
| 174 continue; |
|
| 175 |
|
| 176 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, loaded, -1); |
|
| 177 |
|
| 178 /* If the loaded/unloaded plugin is the selected row, |
|
| 179 * update the pref_button. */ |
|
| 180 sel = gtk_tree_view_get_selection(view); |
|
| 181 if (gtk_tree_selection_get_selected(sel, &model, &iter)) |
|
| 182 { |
|
| 183 gtk_tree_model_get(model, &iter, 2, &plug, -1); |
|
| 184 if (plug == plugin) |
|
| 185 { |
|
| 186 gtk_widget_set_sensitive(pref_button, |
|
| 187 loaded |
|
| 188 && ((GAIM_IS_GTK_PLUGIN(plug) && plug->info->ui_info |
|
| 189 && GAIM_GTK_PLUGIN_UI_INFO(plug)->get_config_frame) |
|
| 190 || (plug->info->prefs_info |
|
| 191 && plug->info->prefs_info->get_plugin_pref_frame))); |
|
| 192 } |
|
| 193 } |
|
| 194 |
|
| 195 break; |
|
| 196 } while (gtk_tree_model_iter_next(model, &iter)); |
|
| 197 } |
|
| 198 } |
|
| 199 |
|
| 200 static void plugin_load_cb(GaimPlugin *plugin, gpointer data) |
|
| 201 { |
|
| 202 GtkTreeView *view = (GtkTreeView *)data; |
|
| 203 plugin_loading_common(plugin, view, TRUE); |
|
| 204 } |
|
| 205 |
|
| 206 static void plugin_unload_cb(GaimPlugin *plugin, gpointer data) |
|
| 207 { |
|
| 208 GtkTreeView *view = (GtkTreeView *)data; |
|
| 209 plugin_loading_common(plugin, view, FALSE); |
|
| 210 } |
|
| 211 |
|
| 212 static void pref_dialog_response_cb(GtkWidget *d, int response, GaimPlugin *plug) |
|
| 213 { |
|
| 214 switch (response) { |
|
| 215 case GTK_RESPONSE_CLOSE: |
|
| 216 case GTK_RESPONSE_DELETE_EVENT: |
|
| 217 g_hash_table_remove(plugin_pref_dialogs, plug); |
|
| 218 if (g_hash_table_size(plugin_pref_dialogs) == 0) { |
|
| 219 g_hash_table_destroy(plugin_pref_dialogs); |
|
| 220 plugin_pref_dialogs = NULL; |
|
| 221 } |
|
| 222 gtk_widget_destroy(d); |
|
| 223 break; |
|
| 224 } |
|
| 225 } |
|
| 226 |
|
| 227 static void plugin_unload_confirm_cb(gpointer *data) |
|
| 228 { |
|
| 229 GaimPlugin *plugin = (GaimPlugin *)data[0]; |
|
| 230 GtkTreeModel *model = (GtkTreeModel *)data[1]; |
|
| 231 GtkTreeIter *iter = (GtkTreeIter *)data[2]; |
|
| 232 |
|
| 233 plugin_toggled_stage_two(plugin, model, iter, TRUE); |
|
| 234 |
|
| 235 g_free(data); |
|
| 236 } |
|
| 237 |
|
| 238 static void plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data) |
|
| 239 { |
|
| 240 GtkTreeModel *model = (GtkTreeModel *)data; |
|
| 241 GtkTreeIter *iter = g_new(GtkTreeIter, 1); |
|
| 242 GtkTreePath *path = gtk_tree_path_new_from_string(pth); |
|
| 243 GaimPlugin *plug; |
|
| 244 GtkWidget *dialog = NULL; |
|
| 245 |
|
| 246 gtk_tree_model_get_iter(model, iter, path); |
|
| 247 gtk_tree_path_free(path); |
|
| 248 gtk_tree_model_get(model, iter, 2, &plug, -1); |
|
| 249 |
|
| 250 /* Apparently, GTK+ won't honor the sensitive flag on cell renderers for booleans. */ |
|
| 251 if (gaim_plugin_is_unloadable(plug)) |
|
| 252 { |
|
| 253 g_free(iter); |
|
| 254 return; |
|
| 255 } |
|
| 256 |
|
| 257 if (!gaim_plugin_is_loaded(plug)) |
|
| 258 { |
|
| 259 gaim_gtk_set_cursor(plugin_dialog, GDK_WATCH); |
|
| 260 |
|
| 261 gaim_plugin_load(plug); |
|
| 262 plugin_toggled_stage_two(plug, model, iter, FALSE); |
|
| 263 |
|
| 264 gaim_gtk_clear_cursor(plugin_dialog); |
|
| 265 } |
|
| 266 else |
|
| 267 { |
|
| 268 if (plugin_pref_dialogs != NULL && |
|
| 269 (dialog = g_hash_table_lookup(plugin_pref_dialogs, plug))) |
|
| 270 pref_dialog_response_cb(dialog, GTK_RESPONSE_DELETE_EVENT, plug); |
|
| 271 |
|
| 272 if (plug->dependent_plugins != NULL) |
|
| 273 { |
|
| 274 GString *tmp = g_string_new(_("The following plugins will be unloaded.")); |
|
| 275 GList *l; |
|
| 276 gpointer *cb_data; |
|
| 277 |
|
| 278 for (l = plug->dependent_plugins ; l != NULL ; l = l->next) |
|
| 279 { |
|
| 280 const char *dep_name = (const char *)l->data; |
|
| 281 GaimPlugin *dep_plugin = gaim_plugins_find_with_id(dep_name); |
|
| 282 g_return_if_fail(dep_plugin != NULL); |
|
| 283 |
|
| 284 g_string_append_printf(tmp, "\n\t%s\n", _(dep_plugin->info->name)); |
|
| 285 } |
|
| 286 |
|
| 287 cb_data = g_new(gpointer, 3); |
|
| 288 cb_data[0] = plug; |
|
| 289 cb_data[1] = model; |
|
| 290 cb_data[2] = iter; |
|
| 291 |
|
| 292 gaim_request_action(plugin_dialog, NULL, |
|
| 293 _("Multiple plugins will be unloaded."), |
|
| 294 tmp->str, 0, cb_data, 2, |
|
| 295 _("Unload Plugins"), G_CALLBACK(plugin_unload_confirm_cb), |
|
| 296 _("Cancel"), g_free); |
|
| 297 g_string_free(tmp, TRUE); |
|
| 298 } |
|
| 299 else |
|
| 300 plugin_toggled_stage_two(plug, model, iter, TRUE); |
|
| 301 } |
|
| 302 } |
|
| 303 |
|
| 304 static void plugin_toggled_stage_two(GaimPlugin *plug, GtkTreeModel *model, GtkTreeIter *iter, gboolean unload) |
|
| 305 { |
|
| 306 gchar *name = NULL; |
|
| 307 gchar *description = NULL; |
|
| 308 |
|
| 309 if (unload) |
|
| 310 { |
|
| 311 gaim_gtk_set_cursor(plugin_dialog, GDK_WATCH); |
|
| 312 |
|
| 313 gaim_plugin_unload(plug); |
|
| 314 |
|
| 315 gaim_gtk_clear_cursor(plugin_dialog); |
|
| 316 } |
|
| 317 |
|
| 318 gtk_widget_set_sensitive(pref_button, |
|
| 319 gaim_plugin_is_loaded(plug) |
|
| 320 && ((GAIM_IS_GTK_PLUGIN(plug) && plug->info->ui_info |
|
| 321 && GAIM_GTK_PLUGIN_UI_INFO(plug)->get_config_frame) |
|
| 322 || (plug->info->prefs_info |
|
| 323 && plug->info->prefs_info->get_plugin_pref_frame))); |
|
| 324 |
|
| 325 name = g_markup_escape_text(_(plug->info->name), -1); |
|
| 326 description = g_markup_escape_text(_(plug->info->description), -1); |
|
| 327 |
|
| 328 if (plug->error != NULL) { |
|
| 329 gchar *error = g_markup_escape_text(plug->error, -1); |
|
| 330 gchar *desc; |
|
| 331 gchar *text = g_strdup_printf( |
|
| 332 "<span size=\"larger\">%s %s</span>\n\n" |
|
| 333 "<span weight=\"bold\" color=\"red\">%s</span>\n\n" |
|
| 334 "%s", |
|
| 335 name, plug->info->version, error, description); |
|
| 336 desc = g_strdup_printf("<b>%s</b> %s\n<span weight=\"bold\" color=\"red\"%s</span>", |
|
| 337 plug->info->name, plug->info->version, error); |
|
| 338 gtk_list_store_set(GTK_LIST_STORE (model), iter, |
|
| 339 1, desc, |
|
| 340 -1); |
|
| 341 g_free(desc); |
|
| 342 g_free(error); |
|
| 343 gtk_label_set_markup(GTK_LABEL(plugin_details), text); |
|
| 344 g_free(text); |
|
| 345 } |
|
| 346 g_free(name); |
|
| 347 g_free(description); |
|
| 348 |
|
| 349 |
|
| 350 gtk_list_store_set(GTK_LIST_STORE (model), iter, |
|
| 351 0, gaim_plugin_is_loaded(plug), |
|
| 352 -1); |
|
| 353 g_free(iter); |
|
| 354 |
|
| 355 gaim_gtk_plugins_save(); |
|
| 356 } |
|
| 357 |
|
| 358 static gboolean ensure_plugin_visible(void *data) |
|
| 359 { |
|
| 360 GtkTreeSelection *sel = GTK_TREE_SELECTION(data); |
|
| 361 GtkTreeView *tv = gtk_tree_selection_get_tree_view(sel); |
|
| 362 GtkTreeModel *model = gtk_tree_view_get_model(tv); |
|
| 363 GtkTreePath *path; |
|
| 364 GtkTreeIter iter; |
|
| 365 if (!gtk_tree_selection_get_selected (sel, &model, &iter)) |
|
| 366 return FALSE; |
|
| 367 path = gtk_tree_model_get_path(model, &iter); |
|
| 368 gtk_tree_view_scroll_to_cell(gtk_tree_selection_get_tree_view(sel), path, NULL, FALSE, 0, 0); |
|
| 369 gtk_tree_path_free(path); |
|
| 370 return FALSE; |
|
| 371 } |
|
| 372 |
|
| 373 static void prefs_plugin_sel (GtkTreeSelection *sel, GtkTreeModel *model) |
|
| 374 { |
|
| 375 gchar *buf, *pname, *pdesc, *pauth, *pweb; |
|
| 376 GtkTreeIter iter; |
|
| 377 GValue val; |
|
| 378 GaimPlugin *plug; |
|
| 379 |
|
| 380 if (!gtk_tree_selection_get_selected (sel, &model, &iter)) |
|
| 381 { |
|
| 382 /* Clear the old plugin details */ |
|
| 383 gtk_label_set_markup(GTK_LABEL(plugin_details), ""); |
|
| 384 gtk_widget_set_sensitive(pref_button, FALSE); |
|
| 385 |
|
| 386 /* Collapse and disable the expander widget */ |
|
| 387 gtk_expander_set_expanded(GTK_EXPANDER(expander), FALSE); |
|
| 388 gtk_widget_set_sensitive(expander, FALSE); |
|
| 389 |
|
| 390 return; |
|
| 391 } |
|
| 392 |
|
| 393 gtk_widget_set_sensitive(expander, TRUE); |
|
| 394 |
|
| 395 val.g_type = 0; |
|
| 396 gtk_tree_model_get_value (model, &iter, 2, &val); |
|
| 397 plug = g_value_get_pointer(&val); |
|
| 398 |
|
| 399 pname = g_markup_escape_text(_(plug->info->name), -1); |
|
| 400 pdesc = (plug->info->description) ? |
|
| 401 g_markup_escape_text(_(plug->info->description), -1) : NULL; |
|
| 402 pauth = (plug->info->author) ? |
|
| 403 g_markup_escape_text(_(plug->info->author), -1) : NULL; |
|
| 404 pweb = (plug->info->homepage) ? |
|
| 405 g_markup_escape_text(_(plug->info->homepage), -1) : NULL; |
|
| 406 buf = g_strdup_printf( |
|
| 407 _("%s%s" |
|
| 408 "<span weight=\"bold\">Written by:</span>\t%s\n" |
|
| 409 "<span weight=\"bold\">Website:</span>\t\t%s\n" |
|
| 410 "<span weight=\"bold\">Filename:</span>\t\t%s"), |
|
| 411 pdesc ? pdesc : "", pdesc ? "\n\n" : "", |
|
| 412 pauth ? pauth : "", pweb ? pweb : "", plug->path); |
|
| 413 |
|
| 414 if (plug->error != NULL) |
|
| 415 { |
|
| 416 char *tmp = g_strdup_printf( |
|
| 417 _("%s\n" |
|
| 418 "<span foreground=\"#ff0000\" weight=\"bold\">" |
|
| 419 "Error: %s\n" |
|
| 420 "Check the plugin website for an update." |
|
| 421 "</span>"), |
|
| 422 buf, plug->error); |
|
| 423 g_free(buf); |
|
| 424 buf = tmp; |
|
| 425 } |
|
| 426 |
|
| 427 gtk_widget_set_sensitive(pref_button, |
|
| 428 gaim_plugin_is_loaded(plug) |
|
| 429 && ((GAIM_IS_GTK_PLUGIN(plug) && plug->info->ui_info |
|
| 430 && GAIM_GTK_PLUGIN_UI_INFO(plug)->get_config_frame) |
|
| 431 || (plug->info->prefs_info |
|
| 432 && plug->info->prefs_info->get_plugin_pref_frame))); |
|
| 433 |
|
| 434 gtk_label_set_markup(GTK_LABEL(plugin_details), buf); |
|
| 435 |
|
| 436 /* Make sure the selected plugin is still visible */ |
|
| 437 g_idle_add(ensure_plugin_visible, sel); |
|
| 438 |
|
| 439 |
|
| 440 g_value_unset(&val); |
|
| 441 g_free(buf); |
|
| 442 g_free(pname); |
|
| 443 g_free(pdesc); |
|
| 444 g_free(pauth); |
|
| 445 g_free(pweb); |
|
| 446 } |
|
| 447 |
|
| 448 static void plugin_dialog_response_cb(GtkWidget *d, int response, GtkTreeSelection *sel) |
|
| 449 { |
|
| 450 GaimPlugin *plug; |
|
| 451 GtkWidget *dialog, *box; |
|
| 452 GtkTreeModel *model; |
|
| 453 GValue val; |
|
| 454 GtkTreeIter iter; |
|
| 455 |
|
| 456 switch (response) { |
|
| 457 case GTK_RESPONSE_CLOSE: |
|
| 458 case GTK_RESPONSE_DELETE_EVENT: |
|
| 459 gaim_request_close_with_handle(plugin_dialog); |
|
| 460 gaim_signals_disconnect_by_handle(plugin_dialog); |
|
| 461 gtk_widget_destroy(d); |
|
| 462 if (plugin_pref_dialogs != NULL) { |
|
| 463 g_hash_table_destroy(plugin_pref_dialogs); |
|
| 464 plugin_pref_dialogs = NULL; |
|
| 465 } |
|
| 466 plugin_dialog = NULL; |
|
| 467 break; |
|
| 468 case GAIM_RESPONSE_CONFIGURE: |
|
| 469 if (! gtk_tree_selection_get_selected (sel, &model, &iter)) |
|
| 470 return; |
|
| 471 val.g_type = 0; |
|
| 472 gtk_tree_model_get_value(model, &iter, 2, &val); |
|
| 473 plug = g_value_get_pointer(&val); |
|
| 474 if (plug == NULL) |
|
| 475 break; |
|
| 476 if (plugin_pref_dialogs != NULL && |
|
| 477 g_hash_table_lookup(plugin_pref_dialogs, plug)) |
|
| 478 break; |
|
| 479 box = gaim_gtk_plugin_get_config_frame(plug); |
|
| 480 if (box == NULL) |
|
| 481 break; |
|
| 482 |
|
| 483 dialog = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, GTK_WINDOW(d), |
|
| 484 GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, |
|
| 485 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
|
| 486 NULL); |
|
| 487 if (plugin_pref_dialogs == NULL) |
|
| 488 plugin_pref_dialogs = g_hash_table_new(NULL, NULL); |
|
| 489 |
|
| 490 g_hash_table_insert(plugin_pref_dialogs, plug, dialog); |
|
| 491 |
|
| 492 g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(pref_dialog_response_cb), plug); |
|
| 493 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box); |
|
| 494 gtk_window_set_role(GTK_WINDOW(dialog), "plugin_config"); |
|
| 495 gtk_window_set_title(GTK_WINDOW(dialog), _(gaim_plugin_get_name(plug))); |
|
| 496 gtk_widget_show_all(dialog); |
|
| 497 g_value_unset(&val); |
|
| 498 break; |
|
| 499 } |
|
| 500 } |
|
| 501 |
|
| 502 static void |
|
| 503 show_plugin_prefs_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, GtkWidget *dialog) |
|
| 504 { |
|
| 505 GtkTreeSelection *sel; |
|
| 506 GtkTreeIter iter; |
|
| 507 GaimPlugin *plugin; |
|
| 508 GtkTreeModel *model; |
|
| 509 |
|
| 510 sel = gtk_tree_view_get_selection(view); |
|
| 511 |
|
| 512 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) |
|
| 513 return; |
|
| 514 |
|
| 515 gtk_tree_model_get(model, &iter, 2, &plugin, -1); |
|
| 516 |
|
| 517 if (!gaim_plugin_is_loaded(plugin)) |
|
| 518 return; |
|
| 519 |
|
| 520 /* Now show the pref-dialog for the plugin */ |
|
| 521 plugin_dialog_response_cb(dialog, GAIM_RESPONSE_CONFIGURE, sel); |
|
| 522 } |
|
| 523 |
|
| 524 void gaim_gtk_plugin_dialog_show() |
|
| 525 { |
|
| 526 GtkWidget *sw; |
|
| 527 GtkWidget *event_view; |
|
| 528 GtkListStore *ls; |
|
| 529 GtkCellRenderer *rend, *rendt; |
|
| 530 GtkTreeViewColumn *col; |
|
| 531 GtkTreeSelection *sel; |
|
| 532 |
|
| 533 if (plugin_dialog != NULL) { |
|
| 534 gtk_window_present(GTK_WINDOW(plugin_dialog)); |
|
| 535 return; |
|
| 536 } |
|
| 537 |
|
| 538 plugin_dialog = gtk_dialog_new_with_buttons(_("Plugins"), |
|
| 539 NULL, |
|
| 540 GTK_DIALOG_NO_SEPARATOR, |
|
| 541 NULL); |
|
| 542 pref_button = gtk_dialog_add_button(GTK_DIALOG(plugin_dialog), |
|
| 543 _("Configure Pl_ugin"), GAIM_RESPONSE_CONFIGURE); |
|
| 544 gtk_dialog_add_button(GTK_DIALOG(plugin_dialog), |
|
| 545 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); |
|
| 546 gtk_widget_set_sensitive(pref_button, FALSE); |
|
| 547 gtk_window_set_role(GTK_WINDOW(plugin_dialog), "plugins"); |
|
| 548 |
|
| 549 sw = gtk_scrolled_window_new(NULL,NULL); |
|
| 550 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
|
| 551 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); |
|
| 552 |
|
| 553 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(plugin_dialog)->vbox), sw, TRUE, TRUE, 0); |
|
| 554 |
|
| 555 ls = gtk_list_store_new(4, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
|
| 556 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), |
|
| 557 1, GTK_SORT_ASCENDING); |
|
| 558 |
|
| 559 update_plugin_list(ls); |
|
| 560 |
|
| 561 event_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls)); |
|
| 562 |
|
| 563 g_signal_connect(G_OBJECT(event_view), "row-activated", |
|
| 564 G_CALLBACK(show_plugin_prefs_cb), plugin_dialog); |
|
| 565 |
|
| 566 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-load", plugin_dialog, |
|
| 567 GAIM_CALLBACK(plugin_load_cb), event_view); |
|
| 568 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-unload", plugin_dialog, |
|
| 569 GAIM_CALLBACK(plugin_unload_cb), event_view); |
|
| 570 |
|
| 571 rend = gtk_cell_renderer_toggle_new(); |
|
| 572 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (event_view)); |
|
| 573 |
|
| 574 col = gtk_tree_view_column_new_with_attributes (_("Enabled"), |
|
| 575 rend, |
|
| 576 "active", 0, |
|
| 577 NULL); |
|
| 578 gtk_tree_view_append_column (GTK_TREE_VIEW(event_view), col); |
|
| 579 gtk_tree_view_column_set_sort_column_id(col, 0); |
|
| 580 g_signal_connect(G_OBJECT(rend), "toggled", |
|
| 581 G_CALLBACK(plugin_toggled), ls); |
|
| 582 |
|
| 583 rendt = gtk_cell_renderer_text_new(); |
|
| 584 g_object_set(rendt, |
|
| 585 "foreground", "#c0c0c0", |
|
| 586 NULL); |
|
| 587 col = gtk_tree_view_column_new_with_attributes (_("Name"), |
|
| 588 rendt, |
|
| 589 "markup", 1, |
|
| 590 "foreground-set", 3, |
|
| 591 NULL); |
|
| 592 #if GTK_CHECK_VERSION(2,6,0) |
|
| 593 gtk_tree_view_column_set_expand (col, TRUE); |
|
| 594 g_object_set(rendt, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
|
| 595 #endif |
|
| 596 gtk_tree_view_append_column (GTK_TREE_VIEW(event_view), col); |
|
| 597 gtk_tree_view_column_set_sort_column_id(col, 1); |
|
| 598 g_object_unref(G_OBJECT(ls)); |
|
| 599 gtk_container_add(GTK_CONTAINER(sw), event_view); |
|
| 600 |
|
| 601 expander = gtk_expander_new(_("<b>Plugin Details</b>")); |
|
| 602 gtk_expander_set_use_markup(GTK_EXPANDER(expander), TRUE); |
|
| 603 plugin_details = gtk_label_new(NULL); |
|
| 604 gtk_label_set_line_wrap(GTK_LABEL(plugin_details), TRUE); |
|
| 605 gtk_container_add(GTK_CONTAINER(expander), plugin_details); |
|
| 606 gtk_widget_set_sensitive(expander, FALSE); |
|
| 607 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(plugin_dialog)->vbox), expander, FALSE, FALSE, 0); |
|
| 608 |
|
| 609 g_signal_connect (G_OBJECT (sel), "changed", G_CALLBACK (prefs_plugin_sel), NULL); |
|
| 610 g_signal_connect(G_OBJECT(plugin_dialog), "response", G_CALLBACK(plugin_dialog_response_cb), sel); |
|
| 611 gtk_window_set_default_size(GTK_WINDOW(plugin_dialog), 430, 430); |
|
| 612 gtk_widget_show_all(plugin_dialog); |
|
| 613 } |
|