Statistics
| Revision:

root / src / plugin_manager.c @ 3014

History | View | Annotate | Download (7.3 kB)

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