Statistics
| Revision:

root / src / plugin_manager.c @ 2164

History | View | Annotate | Download (6.62 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 "gtkutils.h"
35

    
36
static struct PluginManagerWindow {
37
        GtkWidget *window;
38
        GtkWidget *close_btn;
39

    
40
        GtkWidget *treeview;
41
        GtkListStore *store;
42
        GtkTreeSelection *selection;
43
} pm_window;
44

    
45
enum {
46
        COL_INFO,
47
        N_COLS
48
};
49

    
50
static void plugin_manager_create        (void);
51
static void plugin_manager_set_list_row        (GtkTreeIter        *iter,
52
                                         SylPluginInfo        *info,
53
                                         const gchar        *filename);
54
static gint plugin_manager_deleted        (GtkWidget        *widget,
55
                                         GdkEventAny        *event,
56
                                         gpointer         data);
57
static gboolean key_pressed                (GtkWidget        *widget,
58
                                         GdkEventKey        *event,
59
                                         gpointer         data);
60

    
61
void plugin_manager_open(void)
62
{
63
        GSList *list, *cur;
64
        SylPluginInfo *info;
65
        GModule *module;
66
        const gchar *filename;
67

    
68
        if (!pm_window.window)
69
                plugin_manager_create();
70
        else
71
                gtk_window_present(GTK_WINDOW(pm_window.window));
72

    
73
        list = syl_plugin_get_module_list();
74

    
75
        gtk_list_store_clear(pm_window.store);
76

    
77
        for (cur = list; cur != NULL; cur = cur->next) {
78
                module = (GModule *)cur->data;
79

    
80
                filename = g_module_name(module);
81
                info = syl_plugin_get_info(module);
82
                if (info) {
83
                        debug_print("------------------------------\n");
84
                        debug_print("filename      : %s\n", filename);
85
                        debug_print("plugin name   : %s\n", info->name);
86
                        debug_print("plugin version: %s\n", info->version);
87
                        debug_print("plugin author : %s\n", info->author);
88
                        debug_print("description   : %s\n", info->description ? info->description : "");
89
                        debug_print("------------------------------\n");
90
                        plugin_manager_set_list_row(NULL, info, filename);
91
                } else {
92
                        debug_print("info not found: %s\n", filename);
93
                }
94
        }
95

    
96
        gtk_widget_show(pm_window.window);
97
        manage_window_focus_in(pm_window.window, NULL, NULL);
98
}
99

    
100
static void plugin_manager_create(void)
101
{
102
        GtkWidget *window;
103
        GtkWidget *vbox;
104
        GtkWidget *close_btn;
105
        GtkWidget *confirm_area;
106

    
107
        GtkWidget *scrolledwin;
108
        GtkWidget *treeview;
109
        GtkListStore *store;
110
        GtkTreeSelection *selection;
111
        GtkTreeViewColumn *column;
112
        GtkCellRenderer *renderer;
113

    
114
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
115
        gtk_window_set_title(GTK_WINDOW(window), _("Plug-in manager"));
116
        gtk_widget_set_size_request(window, 600, 400);
117
        gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
118
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
119

    
120
        vbox = gtk_vbox_new(FALSE, 6);
121
        gtk_widget_show(vbox);
122
        gtk_container_add(GTK_CONTAINER(window), vbox);
123

    
124
        gtkut_stock_button_set_create(&confirm_area,
125
                                      &close_btn, GTK_STOCK_CLOSE,
126
                                      NULL, NULL, NULL, NULL);
127
        gtk_widget_show(confirm_area);
128
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
129
        gtk_widget_grab_default(close_btn);
130

    
131
        g_signal_connect(G_OBJECT(window), "delete_event",
132
                         G_CALLBACK(plugin_manager_deleted), NULL);
133
        g_signal_connect(G_OBJECT(window), "key_press_event",
134
                         G_CALLBACK(key_pressed), NULL);
135
        g_signal_connect(G_OBJECT(close_btn), "clicked",
136
                         G_CALLBACK(plugin_manager_deleted), NULL);
137

    
138
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
139
        gtk_widget_show(scrolledwin);
140
        gtk_widget_set_size_request(scrolledwin, -1, -1);
141
        gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
142
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
143
                                       GTK_POLICY_AUTOMATIC,
144
                                       GTK_POLICY_AUTOMATIC);
145
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
146
                                            GTK_SHADOW_IN);
147

    
148
        store = gtk_list_store_new(N_COLS, G_TYPE_STRING);
149

    
150
        treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
151
        g_object_unref(G_OBJECT(store));
152
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE);
153
        gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
154
        gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), COL_INFO);
155
#if GTK_CHECK_VERSION(2, 10, 0)
156
        gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(treeview),
157
                                     GTK_TREE_VIEW_GRID_LINES_HORIZONTAL);
158
#endif
159

    
160
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
161
        gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
162

    
163
        renderer = gtk_cell_renderer_text_new();
164
        column = gtk_tree_view_column_new_with_attributes
165
                (_("Plug-in information"), renderer, "text", COL_INFO, NULL);
166
        gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
167
        gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
168

    
169
        gtk_widget_show(treeview);
170
        gtk_container_add(GTK_CONTAINER(scrolledwin), treeview);
171

    
172
        gtk_widget_show_all(window);
173

    
174
        pm_window.window = window;
175
        pm_window.close_btn = close_btn;
176

    
177
        pm_window.treeview = treeview;
178
        pm_window.store = store;
179
        pm_window.selection = selection;
180
}
181

    
182
static void plugin_manager_set_list_row(GtkTreeIter *iter, SylPluginInfo *info,
183
                                        const gchar *filename)
184
{
185
        GtkListStore *store = pm_window.store;
186
        GtkTreeIter iter_;
187
        gchar *plugin_info;
188

    
189
        g_return_if_fail(info != NULL);
190
        g_return_if_fail(filename != NULL);
191

    
192
        plugin_info = g_strconcat(info->name ? info->name : _("(Unknown)"),
193
                                  "  ", info->version ? info->version : "", "\n",
194
                                  _("Author: "), info->author ? info->author : _("(Unknown)"), "\n",
195
                                  _("File: "), filename ? filename : _("(Unknown)"),
196
                                  info->description ? "\n" : "",
197
                                  info->description ? _("Description: ") : "",
198
                                  info->description ? info->description : "",
199
                                  NULL);
200

    
201
        if (iter)
202
                iter_ = *iter;
203
        else
204
                gtk_list_store_append(store, &iter_);
205

    
206
        gtk_list_store_set(store, &iter_, COL_INFO, plugin_info, -1);
207

    
208
        g_free(plugin_info);
209
}
210

    
211
static gint plugin_manager_deleted(GtkWidget *widget, GdkEventAny *event,
212
                                   gpointer data)
213
{
214
        gtk_widget_hide(pm_window.window);
215
        return TRUE;
216
}
217

    
218
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
219
                            gpointer data)
220
{
221
        if (event && event->keyval == GDK_Escape) {
222
                gtk_widget_hide(pm_window.window);
223
                return TRUE;
224
        }
225

    
226
        return FALSE;
227
}