root / src / plugin_manager.c @ 3047
History | View | Annotate | Download (7.3 kB)
| 1 | 2145 | hiro | /*
|
|---|---|---|---|
| 2 | 2145 | hiro | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | 3014 | hiro | * Copyright (C) 1999-2012 Hiroyuki Yamamoto |
| 4 | 2145 | hiro | * |
| 5 | 2145 | hiro | * This program is free software; you can redistribute it and/or modify |
| 6 | 2145 | hiro | * it under the terms of the GNU General Public License as published by |
| 7 | 2145 | hiro | * the Free Software Foundation; either version 2 of the License, or |
| 8 | 2145 | hiro | * (at your option) any later version. |
| 9 | 2145 | hiro | * |
| 10 | 2145 | hiro | * This program is distributed in the hope that it will be useful, |
| 11 | 2145 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | 2145 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | 2145 | hiro | * GNU General Public License for more details. |
| 14 | 2145 | hiro | * |
| 15 | 2145 | hiro | * You should have received a copy of the GNU General Public License |
| 16 | 2145 | hiro | * along with this program; if not, write to the Free Software |
| 17 | 2145 | hiro | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | 2145 | hiro | */ |
| 19 | 2145 | hiro | |
| 20 | 2145 | hiro | #ifdef HAVE_CONFIG_H
|
| 21 | 2145 | hiro | # include "config.h" |
| 22 | 2145 | hiro | #endif
|
| 23 | 2145 | hiro | |
| 24 | 2145 | hiro | #include "defs.h" |
| 25 | 2145 | hiro | |
| 26 | 2145 | hiro | #include <glib.h> |
| 27 | 2145 | hiro | #include <glib/gi18n.h> |
| 28 | 2146 | hiro | #include <gdk/gdkkeysyms.h> |
| 29 | 2145 | hiro | #include <gtk/gtk.h> |
| 30 | 2145 | hiro | |
| 31 | 2145 | hiro | #include "plugin.h" |
| 32 | 2145 | hiro | #include "plugin_manager.h" |
| 33 | 2145 | hiro | #include "manage_window.h" |
| 34 | 2707 | hiro | #include "alertpanel.h" |
| 35 | 2149 | hiro | #include "gtkutils.h" |
| 36 | 2707 | hiro | #include "update_check.h" |
| 37 | 2707 | hiro | #include "utils.h" |
| 38 | 2145 | hiro | |
| 39 | 2146 | hiro | static struct PluginManagerWindow { |
| 40 | 2146 | hiro | GtkWidget *window; |
| 41 | 2149 | hiro | GtkWidget *close_btn; |
| 42 | 2149 | hiro | |
| 43 | 2149 | hiro | GtkWidget *treeview; |
| 44 | 2149 | hiro | GtkListStore *store; |
| 45 | 2149 | hiro | GtkTreeSelection *selection; |
| 46 | 2146 | hiro | } pm_window; |
| 47 | 2146 | hiro | |
| 48 | 2149 | hiro | enum {
|
| 49 | 2149 | hiro | COL_INFO, |
| 50 | 2149 | hiro | N_COLS |
| 51 | 2149 | hiro | }; |
| 52 | 2149 | hiro | |
| 53 | 2146 | hiro | static void plugin_manager_create (void); |
| 54 | 2149 | hiro | static void plugin_manager_set_list_row (GtkTreeIter *iter, |
| 55 | 2149 | hiro | SylPluginInfo *info, |
| 56 | 2149 | hiro | const gchar *filename);
|
| 57 | 2146 | hiro | static gint plugin_manager_deleted (GtkWidget *widget,
|
| 58 | 2146 | hiro | GdkEventAny *event, |
| 59 | 2146 | hiro | gpointer data); |
| 60 | 2146 | hiro | static gboolean key_pressed (GtkWidget *widget,
|
| 61 | 2146 | hiro | GdkEventKey *event, |
| 62 | 2146 | hiro | gpointer data); |
| 63 | 2146 | hiro | |
| 64 | 2145 | hiro | void plugin_manager_open(void) |
| 65 | 2145 | hiro | {
|
| 66 | 2145 | hiro | GSList *list, *cur; |
| 67 | 2145 | hiro | SylPluginInfo *info; |
| 68 | 2145 | hiro | GModule *module; |
| 69 | 2145 | hiro | const gchar *filename;
|
| 70 | 2145 | hiro | |
| 71 | 2146 | hiro | if (!pm_window.window)
|
| 72 | 2146 | hiro | plugin_manager_create(); |
| 73 | 2146 | hiro | else
|
| 74 | 2146 | hiro | gtk_window_present(GTK_WINDOW(pm_window.window)); |
| 75 | 2146 | hiro | |
| 76 | 2145 | hiro | list = syl_plugin_get_module_list(); |
| 77 | 2145 | hiro | |
| 78 | 2149 | hiro | gtk_list_store_clear(pm_window.store); |
| 79 | 2149 | hiro | |
| 80 | 2145 | hiro | for (cur = list; cur != NULL; cur = cur->next) { |
| 81 | 2145 | hiro | module = (GModule *)cur->data; |
| 82 | 2145 | hiro | |
| 83 | 2145 | hiro | filename = g_module_name(module); |
| 84 | 2145 | hiro | info = syl_plugin_get_info(module); |
| 85 | 2145 | hiro | if (info) {
|
| 86 | 2149 | hiro | debug_print("------------------------------\n");
|
| 87 | 2149 | hiro | debug_print("filename : %s\n", filename);
|
| 88 | 2149 | hiro | debug_print("plugin name : %s\n", info->name);
|
| 89 | 2149 | hiro | debug_print("plugin version: %s\n", info->version);
|
| 90 | 2149 | hiro | debug_print("plugin author : %s\n", info->author);
|
| 91 | 2151 | hiro | debug_print("description : %s\n", info->description ? info->description : ""); |
| 92 | 2149 | hiro | debug_print("------------------------------\n");
|
| 93 | 2149 | hiro | plugin_manager_set_list_row(NULL, info, filename);
|
| 94 | 2145 | hiro | } else {
|
| 95 | 2149 | hiro | debug_print("info not found: %s\n", filename);
|
| 96 | 2145 | hiro | } |
| 97 | 2145 | hiro | } |
| 98 | 2149 | hiro | |
| 99 | 2149 | hiro | gtk_widget_show(pm_window.window); |
| 100 | 2149 | hiro | manage_window_focus_in(pm_window.window, NULL, NULL); |
| 101 | 3014 | hiro | |
| 102 | 3014 | hiro | syl_plugin_signal_emit("plugin-manager-open", pm_window.window);
|
| 103 | 2145 | hiro | } |
| 104 | 2146 | hiro | |
| 105 | 2707 | hiro | #ifdef USE_UPDATE_CHECK_PLUGIN
|
| 106 | 2707 | hiro | static gint plugin_manager_update_check(void) |
| 107 | 2707 | hiro | {
|
| 108 | 2707 | hiro | update_check_plugin(TRUE); |
| 109 | 2707 | hiro | return TRUE;
|
| 110 | 2707 | hiro | } |
| 111 | 2707 | hiro | #endif /* USE_UPDATE_CHECK_PLUGIN */ |
| 112 | 2707 | hiro | |
| 113 | 2146 | hiro | static void plugin_manager_create(void) |
| 114 | 2146 | hiro | {
|
| 115 | 2146 | hiro | GtkWidget *window; |
| 116 | 2149 | hiro | GtkWidget *vbox; |
| 117 | 2707 | hiro | #ifdef USE_UPDATE_CHECK_PLUGIN
|
| 118 | 2707 | hiro | GtkWidget *update_check_btn; |
| 119 | 2707 | hiro | #endif
|
| 120 | 2149 | hiro | GtkWidget *close_btn; |
| 121 | 2149 | hiro | GtkWidget *confirm_area; |
| 122 | 2146 | hiro | |
| 123 | 2149 | hiro | GtkWidget *scrolledwin; |
| 124 | 2149 | hiro | GtkWidget *treeview; |
| 125 | 2149 | hiro | GtkListStore *store; |
| 126 | 2149 | hiro | GtkTreeSelection *selection; |
| 127 | 2149 | hiro | GtkTreeViewColumn *column; |
| 128 | 2149 | hiro | GtkCellRenderer *renderer; |
| 129 | 2149 | hiro | |
| 130 | 2146 | hiro | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 131 | 2149 | hiro | gtk_window_set_title(GTK_WINDOW(window), _("Plug-in manager"));
|
| 132 | 2146 | hiro | gtk_widget_set_size_request(window, 600, 400); |
| 133 | 2146 | hiro | gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE); |
| 134 | 2146 | hiro | gtk_container_set_border_width(GTK_CONTAINER(window), 8);
|
| 135 | 2149 | hiro | |
| 136 | 2149 | hiro | vbox = gtk_vbox_new(FALSE, 6);
|
| 137 | 2149 | hiro | gtk_widget_show(vbox); |
| 138 | 2149 | hiro | gtk_container_add(GTK_CONTAINER(window), vbox); |
| 139 | 2149 | hiro | |
| 140 | 2149 | hiro | gtkut_stock_button_set_create(&confirm_area, |
| 141 | 2707 | hiro | #ifdef USE_UPDATE_CHECK_PLUGIN
|
| 142 | 2707 | hiro | &update_check_btn, _("Check for _update"),
|
| 143 | 2149 | hiro | &close_btn, GTK_STOCK_CLOSE, |
| 144 | 2707 | hiro | NULL, NULL); |
| 145 | 2718 | hiro | gtkut_box_set_reverse_order(GTK_BOX(confirm_area), TRUE); |
| 146 | 2707 | hiro | #else
|
| 147 | 2707 | hiro | &close_btn, GTK_STOCK_CLOSE, |
| 148 | 2707 | hiro | NULL, NULL, |
| 149 | 2707 | hiro | NULL, NULL); |
| 150 | 2707 | hiro | #endif
|
| 151 | 2149 | hiro | gtk_widget_show(confirm_area); |
| 152 | 2149 | hiro | gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
|
| 153 | 2149 | hiro | gtk_widget_grab_default(close_btn); |
| 154 | 2149 | hiro | |
| 155 | 2146 | hiro | g_signal_connect(G_OBJECT(window), "delete_event",
|
| 156 | 2146 | hiro | G_CALLBACK(plugin_manager_deleted), NULL);
|
| 157 | 2146 | hiro | g_signal_connect(G_OBJECT(window), "key_press_event",
|
| 158 | 2146 | hiro | G_CALLBACK(key_pressed), NULL);
|
| 159 | 2707 | hiro | #ifdef USE_UPDATE_CHECK_PLUGIN
|
| 160 | 2707 | hiro | g_signal_connect(G_OBJECT(update_check_btn), "clicked",
|
| 161 | 2707 | hiro | G_CALLBACK(plugin_manager_update_check), NULL);
|
| 162 | 2707 | hiro | #endif
|
| 163 | 2149 | hiro | g_signal_connect(G_OBJECT(close_btn), "clicked",
|
| 164 | 2149 | hiro | G_CALLBACK(plugin_manager_deleted), NULL);
|
| 165 | 2146 | hiro | |
| 166 | 2149 | hiro | scrolledwin = gtk_scrolled_window_new(NULL, NULL); |
| 167 | 2149 | hiro | gtk_widget_show(scrolledwin); |
| 168 | 2149 | hiro | gtk_widget_set_size_request(scrolledwin, -1, -1); |
| 169 | 2149 | hiro | gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
|
| 170 | 2149 | hiro | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), |
| 171 | 2149 | hiro | GTK_POLICY_AUTOMATIC, |
| 172 | 2149 | hiro | GTK_POLICY_AUTOMATIC); |
| 173 | 2149 | hiro | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), |
| 174 | 2149 | hiro | GTK_SHADOW_IN); |
| 175 | 2149 | hiro | |
| 176 | 2149 | hiro | store = gtk_list_store_new(N_COLS, G_TYPE_STRING); |
| 177 | 2149 | hiro | |
| 178 | 2149 | hiro | treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
| 179 | 2149 | hiro | g_object_unref(G_OBJECT(store)); |
| 180 | 2149 | hiro | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); |
| 181 | 2149 | hiro | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); |
| 182 | 2149 | hiro | gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), COL_INFO); |
| 183 | 2155 | hiro | #if GTK_CHECK_VERSION(2, 10, 0) |
| 184 | 2155 | hiro | gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(treeview), |
| 185 | 2155 | hiro | GTK_TREE_VIEW_GRID_LINES_HORIZONTAL); |
| 186 | 2155 | hiro | #endif
|
| 187 | 2149 | hiro | |
| 188 | 2149 | hiro | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); |
| 189 | 2149 | hiro | gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); |
| 190 | 2149 | hiro | |
| 191 | 2149 | hiro | renderer = gtk_cell_renderer_text_new(); |
| 192 | 2149 | hiro | column = gtk_tree_view_column_new_with_attributes |
| 193 | 2149 | hiro | (_("Plug-in information"), renderer, "text", COL_INFO, NULL); |
| 194 | 2149 | hiro | gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); |
| 195 | 2149 | hiro | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); |
| 196 | 2149 | hiro | |
| 197 | 2149 | hiro | gtk_widget_show(treeview); |
| 198 | 2149 | hiro | gtk_container_add(GTK_CONTAINER(scrolledwin), treeview); |
| 199 | 2149 | hiro | |
| 200 | 2146 | hiro | gtk_widget_show_all(window); |
| 201 | 2146 | hiro | |
| 202 | 2146 | hiro | pm_window.window = window; |
| 203 | 2149 | hiro | pm_window.close_btn = close_btn; |
| 204 | 2149 | hiro | |
| 205 | 2149 | hiro | pm_window.treeview = treeview; |
| 206 | 2149 | hiro | pm_window.store = store; |
| 207 | 2149 | hiro | pm_window.selection = selection; |
| 208 | 2146 | hiro | } |
| 209 | 2146 | hiro | |
| 210 | 2149 | hiro | static void plugin_manager_set_list_row(GtkTreeIter *iter, SylPluginInfo *info, |
| 211 | 2149 | hiro | const gchar *filename)
|
| 212 | 2149 | hiro | {
|
| 213 | 2149 | hiro | GtkListStore *store = pm_window.store; |
| 214 | 2149 | hiro | GtkTreeIter iter_; |
| 215 | 2149 | hiro | gchar *plugin_info; |
| 216 | 2149 | hiro | |
| 217 | 2149 | hiro | g_return_if_fail(info != NULL);
|
| 218 | 2149 | hiro | g_return_if_fail(filename != NULL);
|
| 219 | 2149 | hiro | |
| 220 | 2151 | hiro | plugin_info = g_strconcat(info->name ? info->name : _("(Unknown)"),
|
| 221 | 2151 | hiro | " ", info->version ? info->version : "", "\n", |
| 222 | 2151 | hiro | _("Author: "), info->author ? info->author : _("(Unknown)"), "\n", |
| 223 | 2151 | hiro | _("File: "), filename ? filename : _("(Unknown)"), |
| 224 | 2151 | hiro | info->description ? "\n" : "", |
| 225 | 2151 | hiro | info->description ? _("Description: ") : "", |
| 226 | 2151 | hiro | info->description ? info->description : "",
|
| 227 | 2151 | hiro | NULL);
|
| 228 | 2149 | hiro | |
| 229 | 2151 | hiro | if (iter)
|
| 230 | 2151 | hiro | iter_ = *iter; |
| 231 | 2151 | hiro | else
|
| 232 | 2149 | hiro | gtk_list_store_append(store, &iter_); |
| 233 | 2149 | hiro | |
| 234 | 2151 | hiro | gtk_list_store_set(store, &iter_, COL_INFO, plugin_info, -1);
|
| 235 | 2151 | hiro | |
| 236 | 2149 | hiro | g_free(plugin_info); |
| 237 | 2149 | hiro | } |
| 238 | 2149 | hiro | |
| 239 | 2146 | hiro | static gint plugin_manager_deleted(GtkWidget *widget, GdkEventAny *event,
|
| 240 | 2146 | hiro | gpointer data) |
| 241 | 2146 | hiro | {
|
| 242 | 2146 | hiro | gtk_widget_hide(pm_window.window); |
| 243 | 2146 | hiro | return TRUE;
|
| 244 | 2146 | hiro | } |
| 245 | 2146 | hiro | |
| 246 | 2146 | hiro | static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
|
| 247 | 2146 | hiro | gpointer data) |
| 248 | 2146 | hiro | {
|
| 249 | 2146 | hiro | if (event && event->keyval == GDK_Escape) {
|
| 250 | 2146 | hiro | gtk_widget_hide(pm_window.window); |
| 251 | 2146 | hiro | return TRUE;
|
| 252 | 2146 | hiro | } |
| 253 | 2146 | hiro | |
| 254 | 2146 | hiro | return FALSE;
|
| 255 | 2146 | hiro | } |