Statistics
| Revision:

root / src / plugin_manager.c @ 2811

History | View | Annotate | Download (7.3 kB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2009 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
103
#ifdef USE_UPDATE_CHECK_PLUGIN
104
static gint plugin_manager_update_check(void)
105
{
106
        update_check_plugin(TRUE);
107
        return TRUE;
108
}
109
#endif /* USE_UPDATE_CHECK_PLUGIN */
110
111
static void plugin_manager_create(void)
112
{
113
        GtkWidget *window;
114
        GtkWidget *vbox;
115
#ifdef USE_UPDATE_CHECK_PLUGIN
116
        GtkWidget *update_check_btn;
117
#endif
118
        GtkWidget *close_btn;
119
        GtkWidget *confirm_area;
120
121
        GtkWidget *scrolledwin;
122
        GtkWidget *treeview;
123
        GtkListStore *store;
124
        GtkTreeSelection *selection;
125
        GtkTreeViewColumn *column;
126
        GtkCellRenderer *renderer;
127
128
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
129
        gtk_window_set_title(GTK_WINDOW(window), _("Plug-in manager"));
130
        gtk_widget_set_size_request(window, 600, 400);
131
        gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
132
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
133
134
        vbox = gtk_vbox_new(FALSE, 6);
135
        gtk_widget_show(vbox);
136
        gtk_container_add(GTK_CONTAINER(window), vbox);
137
138
        gtkut_stock_button_set_create(&confirm_area,
139
#ifdef USE_UPDATE_CHECK_PLUGIN
140
                                      &update_check_btn, _("Check for _update"),
141
                                      &close_btn, GTK_STOCK_CLOSE,
142
                                      NULL, NULL);
143
        gtkut_box_set_reverse_order(GTK_BOX(confirm_area), TRUE);
144
#else
145
                                      &close_btn, GTK_STOCK_CLOSE,
146
                                      NULL, NULL,
147
                                      NULL, NULL);
148
#endif
149
        gtk_widget_show(confirm_area);
150
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
151
        gtk_widget_grab_default(close_btn);
152
153
        g_signal_connect(G_OBJECT(window), "delete_event",
154
                         G_CALLBACK(plugin_manager_deleted), NULL);
155
        g_signal_connect(G_OBJECT(window), "key_press_event",
156
                         G_CALLBACK(key_pressed), NULL);
157
#ifdef USE_UPDATE_CHECK_PLUGIN
158
        g_signal_connect(G_OBJECT(update_check_btn), "clicked",
159
                         G_CALLBACK(plugin_manager_update_check), NULL);
160
#endif
161
        g_signal_connect(G_OBJECT(close_btn), "clicked",
162
                         G_CALLBACK(plugin_manager_deleted), NULL);
163
164
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
165
        gtk_widget_show(scrolledwin);
166
        gtk_widget_set_size_request(scrolledwin, -1, -1);
167
        gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
168
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
169
                                       GTK_POLICY_AUTOMATIC,
170
                                       GTK_POLICY_AUTOMATIC);
171
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
172
                                            GTK_SHADOW_IN);
173
174
        store = gtk_list_store_new(N_COLS, G_TYPE_STRING);
175
176
        treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
177
        g_object_unref(G_OBJECT(store));
178
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE);
179
        gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
180
        gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), COL_INFO);
181
#if GTK_CHECK_VERSION(2, 10, 0)
182
        gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(treeview),
183
                                     GTK_TREE_VIEW_GRID_LINES_HORIZONTAL);
184
#endif
185
186
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
187
        gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
188
189
        renderer = gtk_cell_renderer_text_new();
190
        column = gtk_tree_view_column_new_with_attributes
191
                (_("Plug-in information"), renderer, "text", COL_INFO, NULL);
192
        gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
193
        gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
194
195
        gtk_widget_show(treeview);
196
        gtk_container_add(GTK_CONTAINER(scrolledwin), treeview);
197
198
        gtk_widget_show_all(window);
199
200
        pm_window.window = window;
201
        pm_window.close_btn = close_btn;
202
203
        pm_window.treeview = treeview;
204
        pm_window.store = store;
205
        pm_window.selection = selection;
206
}
207
208
static void plugin_manager_set_list_row(GtkTreeIter *iter, SylPluginInfo *info,
209
                                        const gchar *filename)
210
{
211
        GtkListStore *store = pm_window.store;
212
        GtkTreeIter iter_;
213
        gchar *plugin_info;
214
215
        g_return_if_fail(info != NULL);
216
        g_return_if_fail(filename != NULL);
217
218
        plugin_info = g_strconcat(info->name ? info->name : _("(Unknown)"),
219
                                  "  ", info->version ? info->version : "", "\n",
220
                                  _("Author: "), info->author ? info->author : _("(Unknown)"), "\n",
221
                                  _("File: "), filename ? filename : _("(Unknown)"),
222
                                  info->description ? "\n" : "",
223
                                  info->description ? _("Description: ") : "",
224
                                  info->description ? info->description : "",
225
                                  NULL);
226
227
        if (iter)
228
                iter_ = *iter;
229
        else
230
                gtk_list_store_append(store, &iter_);
231
232
        gtk_list_store_set(store, &iter_, COL_INFO, plugin_info, -1);
233
234
        g_free(plugin_info);
235
}
236
237
static gint plugin_manager_deleted(GtkWidget *widget, GdkEventAny *event,
238
                                   gpointer data)
239
{
240
        gtk_widget_hide(pm_window.window);
241
        return TRUE;
242
}
243
244
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
245
                            gpointer data)
246
{
247
        if (event && event->keyval == GDK_Escape) {
248
                gtk_widget_hide(pm_window.window);
249
                return TRUE;
250
        }
251
252
        return FALSE;
253
}