Statistics
| Revision:

root / plugin / test / test.c @ 3043

History | View | Annotate | Download (9 kB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2011 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
#include <glib.h>
21
#include <gtk/gtk.h>
22
23
#include "sylmain.h"
24
#include "plugin.h"
25
#include "test.h"
26
#include "folder.h"
27
#include "procmsg.h"
28
29
static SylPluginInfo info = {
30
        "Test Plugin",
31
        "3.2.0",
32
        "Hiroyuki Yamamoto",
33
        "Test plug-in for Sylpheed plug-in system"
34
};
35
36
static void init_done_cb(GObject *obj, gpointer data);
37
static void app_exit_cb(GObject *obj, gpointer data);
38
39
static void folderview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory,
40
                                     gpointer data);
41
static void summaryview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory,
42
                                      gpointer data);
43
44
static void textview_menu_popup_cb(GObject *obj, GtkMenu *menu,
45
                                   GtkTextView *textview,
46
                                   const gchar *uri,
47
                                   const gchar *selected_text,
48
                                   MsgInfo *msginfo);
49
50
static void menu_selected_cb(void);
51
52
static void compose_created_cb(GObject *obj, gpointer compose);
53
static void compose_destroy_cb(GObject *obj, gpointer compose);
54
static gboolean compose_send_cb(GObject *obj, gpointer compose,
55
                                gint compose_mode, gint send_mode,
56
                                const gchar *msg_file, GSList *to_list);
57
static void messageview_show_cb(GObject *obj, gpointer msgview,
58
                                MsgInfo *msginfo, gboolean all_headers);
59
static void inc_start_cb(GObject *obj, PrefsAccount *ac);
60
static void inc_finished_cb(GObject *obj, gint new_messages);
61
62
static void create_window(void);
63
static void create_folderview_sub_widget(void);
64
65
gulong app_exit_handler_id = 0;
66
67
void plugin_load(void)
68
{
69
        GList *list, *cur;
70
        const gchar *ver;
71
        gpointer mainwin;
72
73
        g_print("test plug-in loaded!\n");
74
75
        list = folder_get_list();
76
        g_print("folder list = %p\n", list);
77
        for (cur = list; cur != NULL; cur = cur->next) {
78
                Folder *folder = FOLDER(cur->data);
79
                gchar *id = folder_get_identifier(folder);
80
                g_print("folder id = %s\n", id);
81
        }
82
83
        ver = syl_plugin_get_prog_version();
84
        g_print("program ver: %s\n", ver);
85
86
        mainwin = syl_plugin_main_window_get();
87
        g_print("mainwin: %p\n", mainwin);
88
        syl_plugin_main_window_popup(mainwin);
89
90
        create_folderview_sub_widget();
91
92
        syl_plugin_add_menuitem("/Tools", NULL, NULL, NULL);
93
        syl_plugin_add_menuitem("/Tools", "Plugin test", create_window, NULL);
94
95
        g_signal_connect_after(syl_app_get(), "init-done", G_CALLBACK(init_done_cb),
96
                         NULL);
97
        app_exit_handler_id =
98
        g_signal_connect(syl_app_get(), "app-exit", G_CALLBACK(app_exit_cb),
99
                         NULL);
100
        syl_plugin_signal_connect("folderview-menu-popup",
101
                                  G_CALLBACK(folderview_menu_popup_cb), NULL);
102
        syl_plugin_signal_connect("summaryview-menu-popup",
103
                                  G_CALLBACK(summaryview_menu_popup_cb), NULL);
104
        syl_plugin_signal_connect("textview-menu-popup",
105
                                  G_CALLBACK(textview_menu_popup_cb), NULL);
106
        syl_plugin_signal_connect("compose-created",
107
                                  G_CALLBACK(compose_created_cb), NULL);
108
        syl_plugin_signal_connect("compose-destroy",
109
                                  G_CALLBACK(compose_destroy_cb), NULL);
110
        syl_plugin_signal_connect("compose-send",
111
                                  G_CALLBACK(compose_send_cb), NULL);
112
        syl_plugin_signal_connect("messageview-show",
113
                                  G_CALLBACK(messageview_show_cb), NULL);
114
        syl_plugin_signal_connect("inc-mail-start",
115
                                  G_CALLBACK(inc_start_cb), NULL);
116
        syl_plugin_signal_connect("inc-mail-finished",
117
                                  G_CALLBACK(inc_finished_cb), NULL);
118
119
        syl_plugin_add_factory_item("<SummaryView>", "/---", NULL, NULL);
120
        syl_plugin_add_factory_item("<SummaryView>", "/Test Plug-in menu",
121
                                    menu_selected_cb, NULL);
122
123
        g_print("test plug-in loading done\n");
124
}
125
126
void plugin_unload(void)
127
{
128
        g_print("test plug-in unloaded!\n");
129
        g_signal_handler_disconnect(syl_app_get(), app_exit_handler_id);
130
}
131
132
SylPluginInfo *plugin_info(void)
133
{
134
        return &info;
135
}
136
137
gint plugin_interface_version(void)
138
{
139
        return SYL_PLUGIN_INTERFACE_VERSION;
140
}
141
142
static void init_done_cb(GObject *obj, gpointer data)
143
{
144
        syl_plugin_update_check_set_check_url("http://localhost/version_pro.txt?");
145
        syl_plugin_update_check_set_download_url("http://localhost/download.php?sno=123&ver=VER&os=win");
146
        syl_plugin_update_check_set_jump_url("http://localhost/index.html");
147
        syl_plugin_update_check_set_check_plugin_url("http://localhost/plugin_version.txt");
148
        syl_plugin_update_check_set_jump_plugin_url("http://localhost/plugin.html");
149
        g_print("test: %p: app init done\n", obj);
150
}
151
152
static void app_exit_cb(GObject *obj, gpointer data)
153
{
154
        g_print("test: %p: app will exit\n", obj);
155
}
156
157
static void folderview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory,
158
                                     gpointer data)
159
{
160
        g_print("test: %p: folderview menu popup\n", obj);
161
}
162
163
static void summaryview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory,
164
                                      gpointer data)
165
{
166
        GtkWidget *widget;
167
168
        g_print("test: %p: summaryview menu popup\n", obj);
169
        widget = gtk_item_factory_get_item(ifactory, "/Test Plug-in menu");
170
        if (widget)
171
                gtk_widget_set_sensitive(widget, TRUE);
172
}
173
174
static void activate_menu_cb(GtkMenuItem *menuitem, gpointer data)
175
{
176
        g_print("menu activated\n");
177
}
178
179
static void textview_menu_popup_cb(GObject *obj, GtkMenu *menu,
180
                                   GtkTextView *textview,
181
                                   const gchar *uri,
182
                                   const gchar *selected_text,
183
                                   MsgInfo *msginfo)
184
{
185
        GtkWidget *separator, *menuitem;
186
187
        g_print("test: %p: textview menu popup\n", obj);
188
        g_print("test: %p: uri: %s, text: %s\n", obj, uri ? uri : "(none)",
189
                selected_text ? selected_text : "(none)");
190
        g_print("test: %p: msg: %s\n", obj,
191
                msginfo && msginfo->subject ? msginfo->subject : "");
192
193
        separator = gtk_separator_menu_item_new();
194
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), separator);
195
        gtk_widget_show(separator);
196
197
        menuitem = gtk_menu_item_new_with_mnemonic("Test menu");
198
        g_signal_connect(menuitem, "activate", G_CALLBACK(activate_menu_cb), NULL);
199
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
200
        gtk_widget_show(menuitem);
201
}
202
203
static void menu_selected_cb(void)
204
{
205
        gint sel;
206
        GSList *mlist;
207
208
        g_print("test: summary menu selected\n");
209
        sel = syl_plugin_summary_get_selection_type();
210
        mlist = syl_plugin_summary_get_selected_msg_list();
211
        g_print("test: selection type: %d\n", sel);
212
        g_print("test: number of selected summary message: %d\n",
213
                g_slist_length(mlist));
214
        g_slist_free(mlist);
215
}
216
217
static void compose_created_cb(GObject *obj, gpointer compose)
218
{
219
        gchar *text;
220
221
        g_print("test: %p: compose created (%p)\n", obj, compose);
222
223
        text = syl_plugin_compose_entry_get_text(compose, 0);
224
        g_print("test: compose To: %s\n", text);
225
        g_free(text);
226
#if 0
227
        syl_plugin_compose_entry_set(compose, "test-plugin@test", 1);
228
        syl_plugin_compose_entry_append(compose, "second@test", 1);
229
#endif
230
}
231
232
static void compose_destroy_cb(GObject *obj, gpointer compose)
233
{
234
        g_print("test: %p: compose will be destroyed (%p)\n", obj, compose);
235
}
236
237
static gboolean compose_send_cb(GObject *obj, gpointer compose,
238
                                gint compose_mode, gint send_mode,
239
                                const gchar *msg_file, GSList *to_list)
240
{
241
        g_print("test: %p: composed message will be sent (%p)\n", obj, compose);
242
        g_print("test: compose_mode: %d, send_mode: %d, file: %s\n",
243
                compose_mode, send_mode, msg_file);
244
245
        return FALSE; /* return TRUE to cancel sending */
246
}
247
248
static void messageview_show_cb(GObject *obj, gpointer msgview,
249
                                MsgInfo *msginfo, gboolean all_headers)
250
{
251
        g_print("test: %p: messageview_show (%p), all_headers: %d: %s\n",
252
                obj, msgview, all_headers,
253
                msginfo && msginfo->subject ? msginfo->subject : "");
254
}
255
256
static void inc_start_cb(GObject *obj, PrefsAccount *ac)
257
{
258
        if (ac)
259
                g_print("test: receive start: account: %s\n", ac->account_name);
260
        else
261
                g_print("test: receive start: all accounts\n");
262
}
263
264
static void inc_finished_cb(GObject *obj, gint new_messages)
265
{
266
        g_print("test: received %d new messages\n", new_messages);
267
}
268
269
static void button_clicked(GtkWidget *widget, gpointer data)
270
{
271
        g_print("button_clicked\n");
272
        /* syl_plugin_app_will_exit(TRUE); */
273
}
274
275
static void create_window(void)
276
{
277
        GtkWidget *window;
278
        GtkWidget *button;
279
280
        g_print("creating window\n");
281
282
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
283
        button = gtk_button_new_with_label("Click this button");
284
        gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);
285
        gtk_container_add(GTK_CONTAINER(window), button);
286
        g_signal_connect(G_OBJECT(button), "clicked",
287
                         G_CALLBACK(button_clicked), NULL);
288
        gtk_widget_show_all(window);
289
}
290
291
static void create_folderview_sub_widget(void)
292
{
293
        GtkWidget *vbox;
294
        GtkWidget *button;
295
296
        g_print("creating sub widget\n");
297
298
        vbox = gtk_vbox_new(FALSE, 2);
299
        button = gtk_button_new_with_label("Test");
300
        gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
301
        gtk_widget_show_all(vbox);
302
        syl_plugin_folderview_add_sub_widget(vbox);
303
}