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