Mercurial > pidgin
annotate src/gtkplugin.c @ 11744:628dd7aa6509
[gaim-migrate @ 14035]
Make the plugin preference dialog non-modal
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Sun, 23 Oct 2005 08:56:39 +0000 |
| parents | 935278abb386 |
| children | b8bf638cc4aa |
| rev | line source |
|---|---|
| 5205 | 1 /** |
|
6927
ee51189dfe76
[gaim-migrate @ 7474]
Christian Hammond <chipx86@chipx86.com>
parents:
5982
diff
changeset
|
2 * @file gtkplugin.c GTK+ Plugins support |
|
ee51189dfe76
[gaim-migrate @ 7474]
Christian Hammond <chipx86@chipx86.com>
parents:
5982
diff
changeset
|
3 * @ingroup gtkui |
| 5205 | 4 * |
| 5 * gaim | |
| 6 * | |
| 8046 | 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. | |
|
6927
ee51189dfe76
[gaim-migrate @ 7474]
Christian Hammond <chipx86@chipx86.com>
parents:
5982
diff
changeset
|
10 * |
| 5205 | 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 */ | |
| 11740 | 25 #include "internal.h" |
| 9791 | 26 #include "gtkgaim.h" |
| 5205 | 27 #include "gtkplugin.h" |
|
5981
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
28 #include "debug.h" |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
29 #include "prefs.h" |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
30 |
| 5205 | 31 #include <string.h> |
| 32 | |
| 11740 | 33 static GtkWidget *plugin_dialog = NULL; |
| 34 static GtkWidget *plugin_details = NULL; | |
| 35 static GtkWidget *pref_button = NULL; | |
| 5205 | 36 GtkWidget * |
| 37 gaim_gtk_plugin_get_config_frame(GaimPlugin *plugin) | |
| 38 { | |
| 39 GaimGtkPluginUiInfo *ui_info; | |
| 40 | |
| 41 g_return_val_if_fail(plugin != NULL, NULL); | |
| 42 g_return_val_if_fail(GAIM_IS_GTK_PLUGIN(plugin), NULL); | |
| 43 | |
| 44 if (plugin->info->ui_info == NULL) | |
| 45 return NULL; | |
| 46 | |
| 47 ui_info = GAIM_GTK_PLUGIN_UI_INFO(plugin); | |
| 48 | |
| 49 if (ui_info->get_config_frame == NULL) | |
| 50 return NULL; | |
| 51 | |
| 52 return ui_info->get_config_frame(plugin); | |
| 53 } | |
|
5981
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
54 |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
55 void |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
56 gaim_gtk_plugins_save(void) |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
57 { |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
58 GList *pl; |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
59 GList *files = NULL; |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
60 GaimPlugin *p; |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
61 |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
62 for (pl = gaim_plugins_get_loaded(); pl != NULL; pl = pl->next) { |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
63 p = pl->data; |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
64 |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
65 if (p->info->type != GAIM_PLUGIN_PROTOCOL && |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
66 p->info->type != GAIM_PLUGIN_LOADER) { |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
67 |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
68 files = g_list_append(files, p->path); |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
69 } |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
70 } |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
71 |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
72 gaim_prefs_set_string_list("/gaim/gtk/plugins/loaded", files); |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
73 g_list_free(files); |
|
81564bb4db68
[gaim-migrate @ 6429]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
74 } |
| 11740 | 75 |
| 76 static void | |
| 77 update_plugin_list(void *data) | |
| 78 { | |
| 79 GtkListStore *ls = GTK_LIST_STORE(data); | |
| 80 GtkTreeIter iter; | |
| 81 GList *probes; | |
| 82 GaimPlugin *plug; | |
| 83 | |
| 84 gtk_list_store_clear(ls); | |
| 85 gaim_plugins_probe(GAIM_PLUGIN_EXT); | |
| 86 | |
| 87 for (probes = gaim_plugins_get_all(); | |
| 88 probes != NULL; | |
| 89 probes = probes->next) | |
| 90 { | |
| 91 char *desc; | |
| 92 plug = probes->data; | |
| 93 | |
| 94 if (plug->info->type != GAIM_PLUGIN_STANDARD || | |
| 95 (plug->info->flags & GAIM_PLUGIN_FLAG_INVISIBLE)) | |
| 96 { | |
| 97 continue; | |
| 98 } | |
| 99 | |
| 100 gtk_list_store_append (ls, &iter); | |
| 101 desc = g_strdup_printf("<b>%s</b> %s\n%s", plug->info->name ? _(plug->info->name) : g_basename(plug->path), | |
| 102 plug->info->version, | |
| 103 plug->info->summary); | |
| 104 gtk_list_store_set(ls, &iter, | |
| 105 0, gaim_plugin_is_loaded(plug), | |
| 106 1, desc, | |
| 107 2, plug, -1); | |
| 108 g_free(desc); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 static void plugin_load (GtkCellRendererToggle *cell, gchar *pth, gpointer data) | |
| 113 { | |
| 114 GtkTreeModel *model = (GtkTreeModel *)data; | |
| 115 GtkTreeIter iter; | |
| 116 GtkTreePath *path = gtk_tree_path_new_from_string(pth); | |
| 117 GaimPlugin *plug; | |
| 118 gchar buf[1024]; | |
| 119 gchar *name = NULL, *description = NULL; | |
| 120 | |
| 121 GdkCursor *wait = gdk_cursor_new (GDK_WATCH); | |
| 11742 | 122 gdk_window_set_cursor(plugin_dialog->window, wait); |
| 11740 | 123 gdk_cursor_unref(wait); |
| 124 | |
| 125 gtk_tree_model_get_iter (model, &iter, path); | |
| 126 gtk_tree_model_get (model, &iter, 2, &plug, -1); | |
| 127 | |
| 128 if (!gaim_plugin_is_loaded(plug)) | |
| 129 gaim_plugin_load(plug); | |
| 130 else | |
| 131 gaim_plugin_unload(plug); | |
| 132 | |
| 133 | |
| 11742 | 134 gdk_window_set_cursor(plugin_dialog->window, NULL); |
| 11740 | 135 |
| 136 name = g_markup_escape_text(_(plug->info->name), -1); | |
| 137 description = g_markup_escape_text(_(plug->info->description), -1); | |
| 138 | |
| 139 if (plug->error != NULL) { | |
| 140 gchar *error = g_markup_escape_text(plug->error, -1); | |
| 141 gchar *desc; | |
| 142 g_snprintf(buf, sizeof(buf), | |
| 143 "<span size=\"larger\">%s %s</span>\n\n" | |
| 144 "<span weight=\"bold\" color=\"red\">%s</span>\n\n" | |
| 145 "%s", | |
| 146 name, plug->info->version, error, description); | |
| 147 desc = g_strdup_printf("<b>%s</b> %s\n<span weight=\"bold\" color=\"red\"%s</span>", | |
| 148 plug->info->name, plug->info->version, error); | |
| 149 gtk_list_store_set (GTK_LIST_STORE (model), &iter, | |
| 150 1, desc, | |
| 151 -1); | |
| 152 g_free(desc); | |
| 153 g_free(error); | |
| 154 } else { | |
| 155 g_snprintf(buf, sizeof(buf), | |
| 156 "<span size=\"larger\">%s %s</span>\n\n%s", | |
| 157 name, plug->info->version, description); | |
| 158 } | |
| 159 g_free(name); | |
| 160 g_free(description); | |
| 161 | |
| 162 | |
| 163 gtk_list_store_set (GTK_LIST_STORE (model), &iter, | |
| 164 0, gaim_plugin_is_loaded(plug), | |
| 165 -1); | |
| 166 | |
| 167 gtk_label_set_markup(GTK_LABEL(plugin_details), buf); | |
| 168 gtk_tree_path_free(path); | |
| 169 gaim_gtk_plugins_save(); | |
| 170 } | |
| 171 | |
| 172 static void prefs_plugin_sel (GtkTreeSelection *sel, GtkTreeModel *model) | |
| 173 { | |
| 11741 | 174 gchar *buf, *pname, *pdesc, *pauth, *pweb; |
| 11740 | 175 GtkTreeIter iter; |
| 176 GValue val = { 0, }; | |
| 177 GaimPlugin *plug; | |
| 178 | |
| 179 if (! gtk_tree_selection_get_selected (sel, &model, &iter)) | |
| 180 return; | |
| 181 gtk_tree_model_get_value (model, &iter, 2, &val); | |
| 182 plug = g_value_get_pointer(&val); | |
| 183 | |
| 184 pname = g_markup_escape_text(_(plug->info->name), -1); | |
| 185 pdesc = (plug->info->description) ? | |
| 186 g_markup_escape_text(_(plug->info->description), -1) : NULL; | |
| 187 pauth = (plug->info->author) ? | |
| 188 g_markup_escape_text(_(plug->info->author), -1) : NULL; | |
| 189 pweb = (plug->info->homepage) ? | |
| 190 g_markup_escape_text(_(plug->info->homepage), -1) : NULL; | |
| 191 buf = g_strdup_printf( | |
| 192 #ifndef _WIN32 | |
| 193 _("<span size=\"larger\">%s %s</span>\n\n" | |
| 194 "%s%s" | |
| 195 "<span weight=\"bold\">Written by:</span>\t%s\n" | |
| 196 "<span weight=\"bold\">Web site:</span>\t\t%s\n" | |
| 197 "<span weight=\"bold\">File name:</span>\t%s"), | |
| 198 #else | |
| 199 _("<span size=\"larger\">%s %s</span>\n\n" | |
| 200 "%s%s" | |
| 201 "<span weight=\"bold\">Written by:</span> %s\n" | |
| 202 "<span weight=\"bold\">Web site:</span> %s\n" | |
| 203 "<span weight=\"bold\">File name:</span> %s"), | |
| 204 #endif | |
| 205 pname, plug->info->version, pdesc ? pdesc : "", pdesc ? "\n\n" : "", | |
| 206 pauth ? pauth : "", pweb ? pweb : "", plug->path); | |
| 207 | |
| 208 gtk_widget_set_sensitive(pref_button, | |
| 209 plug->info->ui_info != NULL && | |
| 210 GAIM_GTK_PLUGIN_UI_INFO(plug)->get_config_frame != NULL); | |
| 211 gtk_label_set_markup(GTK_LABEL(plugin_details), buf); | |
| 212 g_value_unset(&val); | |
| 213 g_free(buf); | |
| 214 g_free(pname); | |
| 215 g_free(pdesc); | |
| 216 g_free(pauth); | |
| 217 g_free(pweb); | |
| 218 } | |
| 219 | |
| 11741 | 220 static void pref_dialog_response_cb(GtkWidget *d, int response, void *null) |
| 11740 | 221 { |
| 222 switch (response) { | |
| 223 case GTK_RESPONSE_CLOSE: | |
| 224 case GTK_RESPONSE_DELETE_EVENT: | |
| 225 gtk_widget_destroy(d); | |
| 226 plugin_dialog = NULL; | |
| 227 break; | |
| 228 } | |
| 229 } | |
| 11741 | 230 static void plugin_dialog_response_cb(GtkWidget *d, int response, GtkTreeSelection *sel) |
| 11740 | 231 { |
| 232 GaimPlugin *plug; | |
| 233 GtkWidget *dialog, *box; | |
| 234 GtkTreeModel *model; | |
| 11743 | 235 GValue val = { 0, }; |
| 11740 | 236 GtkTreeIter iter; |
| 237 | |
| 238 switch (response) { | |
| 239 case GTK_RESPONSE_CLOSE: | |
| 240 case GTK_RESPONSE_DELETE_EVENT: | |
| 241 gtk_widget_destroy(d); | |
| 242 plugin_dialog = NULL; | |
| 243 break; | |
| 244 case 98121: | |
| 245 if (! gtk_tree_selection_get_selected (sel, &model, &iter)) | |
| 246 return; | |
| 247 gtk_tree_model_get_value (model, &iter, 2, &val); | |
| 248 plug = g_value_get_pointer(&val); | |
| 249 if (plug == NULL) | |
| 250 break; | |
| 251 box = gaim_gtk_plugin_get_config_frame(plug); | |
| 252 if (box == NULL) | |
| 253 break; | |
| 254 | |
| 11741 | 255 dialog = gtk_dialog_new_with_buttons(GAIM_ALERT_TITLE, GTK_WINDOW(d), |
| 11744 | 256 GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, |
| 11740 | 257 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
| 258 NULL); | |
| 259 g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(pref_dialog_response_cb), NULL); | |
| 260 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box); | |
| 261 gtk_widget_show_all(dialog); | |
| 262 break; | |
| 263 } | |
| 264 } | |
| 265 | |
| 266 void gaim_gtk_plugin_dialog_show() | |
| 267 { | |
| 11741 | 268 GtkWidget *sw; |
| 11740 | 269 GtkWidget *event_view; |
| 270 GtkListStore *ls; | |
| 271 GtkCellRenderer *rend, *rendt; | |
| 272 GtkTreeViewColumn *col; | |
| 273 GtkTreeSelection *sel; | |
| 274 GtkWidget *expander; | |
| 275 | |
| 276 if (plugin_dialog != NULL) { | |
| 277 gtk_window_present(GTK_WINDOW(plugin_dialog)); | |
| 278 return; | |
| 279 } | |
| 280 | |
| 281 plugin_dialog = gtk_dialog_new_with_buttons(_("Plugins"), | |
| 282 NULL, | |
| 283 GTK_DIALOG_NO_SEPARATOR, | |
| 284 NULL); | |
| 285 pref_button = gtk_dialog_add_button(GTK_DIALOG(plugin_dialog), GTK_STOCK_PREFERENCES, 98121); | |
| 286 gtk_dialog_add_button(GTK_DIALOG(plugin_dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); | |
| 287 | |
| 288 sw = gtk_scrolled_window_new(NULL,NULL); | |
| 289 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
| 290 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
| 291 | |
| 292 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(plugin_dialog)->vbox), sw, TRUE, TRUE, 0); | |
| 293 | |
| 294 ls = gtk_list_store_new (3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER); | |
| 295 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(ls), | |
| 296 1, GTK_SORT_ASCENDING); | |
| 297 | |
| 298 update_plugin_list(ls); | |
| 299 | |
| 300 event_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(ls)); | |
| 301 | |
| 302 rend = gtk_cell_renderer_toggle_new(); | |
| 303 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (event_view)); | |
| 304 | |
| 305 col = gtk_tree_view_column_new_with_attributes (_("Enabled"), | |
| 306 rend, | |
| 307 "active", 0, | |
| 308 NULL); | |
| 309 gtk_tree_view_append_column (GTK_TREE_VIEW(event_view), col); | |
| 310 g_signal_connect (G_OBJECT(rend), "toggled", | |
| 311 G_CALLBACK(plugin_load), ls); | |
| 312 | |
| 313 rendt = gtk_cell_renderer_text_new(); | |
| 314 col = gtk_tree_view_column_new_with_attributes (_("Name"), | |
| 315 rendt, | |
| 316 "markup", 1, | |
| 317 NULL); | |
| 318 #if GTK_CHECK_VERSION(2,6,0) | |
| 319 gtk_tree_view_column_set_expand (col, TRUE); | |
| 320 g_object_set(rendt, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
| 321 #endif | |
| 322 gtk_tree_view_append_column (GTK_TREE_VIEW(event_view), col); | |
| 323 g_object_unref(G_OBJECT(ls)); | |
| 324 gtk_container_add(GTK_CONTAINER(sw), event_view); | |
| 325 | |
| 326 expander = gtk_expander_new(_("<b>Plugin Details</b>")); | |
| 327 gtk_expander_set_use_markup(GTK_EXPANDER(expander), TRUE); | |
| 328 plugin_details = gtk_label_new(NULL); | |
| 329 gtk_label_set_line_wrap(GTK_LABEL(plugin_details), TRUE); | |
| 330 gtk_container_add(GTK_CONTAINER(expander), plugin_details); | |
| 331 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(plugin_dialog)->vbox), expander, FALSE, FALSE, 0); | |
| 332 | |
| 333 g_signal_connect (G_OBJECT (sel), "changed", G_CALLBACK (prefs_plugin_sel), NULL); | |
| 334 g_signal_connect(G_OBJECT(plugin_dialog), "response", G_CALLBACK(plugin_dialog_response_cb), sel); | |
| 335 gtk_window_set_default_size(GTK_WINDOW(plugin_dialog), 430, 430); | |
| 336 gtk_widget_show_all(plugin_dialog); | |
| 337 } |
