Statistics
| Revision:

root / plugin / test / test.c @ 2886

History | View | Annotate | Download (7.99 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.1.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

    
58
static void create_window(void);
59
static void create_folderview_sub_widget(void);
60

    
61
gulong app_exit_handler_id = 0;
62

    
63
void plugin_load(void)
64
{
65
        GList *list, *cur;
66
        const gchar *ver;
67
        gpointer mainwin;
68

    
69
        g_print("test plug-in loaded!\n");
70

    
71
        list = folder_get_list();
72
        g_print("folder list = %p\n", list);
73
        for (cur = list; cur != NULL; cur = cur->next) {
74
                Folder *folder = FOLDER(cur->data);
75
                gchar *id = folder_get_identifier(folder);
76
                g_print("folder id = %s\n", id);
77
        }
78

    
79
        ver = syl_plugin_get_prog_version();
80
        g_print("program ver: %s\n", ver);
81

    
82
        mainwin = syl_plugin_main_window_get();
83
        g_print("mainwin: %p\n", mainwin);
84
        syl_plugin_main_window_popup(mainwin);
85

    
86
        create_folderview_sub_widget();
87

    
88
        syl_plugin_add_menuitem("/Tools", NULL, NULL, NULL);
89
        syl_plugin_add_menuitem("/Tools", "Plugin test", create_window, NULL);
90

    
91
        g_signal_connect_after(syl_app_get(), "init-done", G_CALLBACK(init_done_cb),
92
                         NULL);
93
        app_exit_handler_id =
94
        g_signal_connect(syl_app_get(), "app-exit", G_CALLBACK(app_exit_cb),
95
                         NULL);
96
        syl_plugin_signal_connect("folderview-menu-popup",
97
                                  G_CALLBACK(folderview_menu_popup_cb), NULL);
98
        syl_plugin_signal_connect("summaryview-menu-popup",
99
                                  G_CALLBACK(summaryview_menu_popup_cb), NULL);
100
        syl_plugin_signal_connect("textview-menu-popup",
101
                                  G_CALLBACK(textview_menu_popup_cb), NULL);
102
        syl_plugin_signal_connect("compose-created",
103
                                  G_CALLBACK(compose_created_cb), NULL);
104
        syl_plugin_signal_connect("compose-destroy",
105
                                  G_CALLBACK(compose_destroy_cb), NULL);
106
        syl_plugin_signal_connect("compose-send",
107
                                  G_CALLBACK(compose_send_cb), NULL);
108

    
109
        syl_plugin_add_factory_item("<SummaryView>", "/---", NULL, NULL);
110
        syl_plugin_add_factory_item("<SummaryView>", "/Test Plug-in menu",
111
                                    menu_selected_cb, NULL);
112

    
113
        g_print("test plug-in loading done\n");
114
}
115

    
116
void plugin_unload(void)
117
{
118
        g_print("test plug-in unloaded!\n");
119
        g_signal_handler_disconnect(syl_app_get(), app_exit_handler_id);
120
}
121

    
122
SylPluginInfo *plugin_info(void)
123
{
124
        return &info;
125
}
126

    
127
gint plugin_interface_version(void)
128
{
129
        return SYL_PLUGIN_INTERFACE_VERSION;
130
}
131

    
132
static void init_done_cb(GObject *obj, gpointer data)
133
{
134
        syl_plugin_update_check_set_check_url("http://localhost/version_pro.txt?");
135
        syl_plugin_update_check_set_download_url("http://localhost/download.php?sno=123&ver=VER&os=win");
136
        syl_plugin_update_check_set_jump_url("http://localhost/index.html");
137
        syl_plugin_update_check_set_check_plugin_url("http://localhost/plugin_version.txt");
138
        syl_plugin_update_check_set_jump_plugin_url("http://localhost/plugin.html");
139
        g_print("test: %p: app init done\n", obj);
140
}
141

    
142
static void app_exit_cb(GObject *obj, gpointer data)
143
{
144
        g_print("test: %p: app will exit\n", obj);
145
}
146

    
147
static void folderview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory,
148
                                     gpointer data)
149
{
150
        g_print("test: %p: folderview menu popup\n", obj);
151
}
152

    
153
static void summaryview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory,
154
                                      gpointer data)
155
{
156
        GtkWidget *widget;
157

    
158
        g_print("test: %p: summaryview menu popup\n", obj);
159
        widget = gtk_item_factory_get_item(ifactory, "/Test Plug-in menu");
160
        if (widget)
161
                gtk_widget_set_sensitive(widget, TRUE);
162
}
163

    
164
static void activate_menu_cb(GtkMenuItem *menuitem, gpointer data)
165
{
166
        g_print("menu activated\n");
167
}
168

    
169
static void textview_menu_popup_cb(GObject *obj, GtkMenu *menu,
170
                                   GtkTextView *textview,
171
                                   const gchar *uri,
172
                                   const gchar *selected_text,
173
                                   MsgInfo *msginfo)
174
{
175
        GtkWidget *separator, *menuitem;
176

    
177
        g_print("test: %p: textview menu popup\n", obj);
178
        g_print("test: %p: uri: %s, text: %s\n", obj, uri ? uri : "(none)",
179
                selected_text ? selected_text : "(none)");
180
        g_print("test: %p: msg: %s\n", obj,
181
                msginfo && msginfo->subject ? msginfo->subject : "");
182

    
183
        separator = gtk_separator_menu_item_new();
184
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), separator);
185
        gtk_widget_show(separator);
186

    
187
        menuitem = gtk_menu_item_new_with_mnemonic("Test menu");
188
        g_signal_connect(menuitem, "activate", G_CALLBACK(activate_menu_cb), NULL);
189
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
190
        gtk_widget_show(menuitem);
191
}
192

    
193
static void menu_selected_cb(void)
194
{
195
        gint sel;
196
        GSList *mlist;
197

    
198
        g_print("test: summary menu selected\n");
199
        sel = syl_plugin_summary_get_selection_type();
200
        mlist = syl_plugin_summary_get_selected_msg_list();
201
        g_print("test: selection type: %d\n", sel);
202
        g_print("test: number of selected summary message: %d\n",
203
                g_slist_length(mlist));
204
        g_slist_free(mlist);
205
}
206

    
207
static void compose_created_cb(GObject *obj, gpointer compose)
208
{
209
        gchar *text;
210

    
211
        g_print("test: %p: compose created (%p)\n", obj, compose);
212

    
213
        text = syl_plugin_compose_entry_get_text(compose, 0);
214
        g_print("test: compose To: %s\n", text);
215
        g_free(text);
216
#if 0
217
        syl_plugin_compose_entry_set(compose, "test-plugin@test", 1);
218
        syl_plugin_compose_entry_append(compose, "second@test", 1);
219
#endif
220
}
221

    
222
static void compose_destroy_cb(GObject *obj, gpointer compose)
223
{
224
        g_print("test: %p: compose will be destroyed (%p)\n", obj, compose);
225
}
226

    
227
static gboolean compose_send_cb(GObject *obj, gpointer compose,
228
                                gint compose_mode, gint send_mode,
229
                                const gchar *msg_file, GSList *to_list)
230
{
231
        g_print("test: %p: composed message will be sent (%p)\n", obj, compose);
232
        g_print("test: compose_mode: %d, send_mode: %d, file: %s\n",
233
                compose_mode, send_mode, msg_file);
234

    
235
        return TRUE; /* return FALSE to cancel sending */
236
}
237

    
238
static void button_clicked(GtkWidget *widget, gpointer data)
239
{
240
        g_print("button_clicked\n");
241
        /* syl_plugin_app_will_exit(TRUE); */
242
}
243

    
244
static void create_window(void)
245
{
246
        GtkWidget *window;
247
        GtkWidget *button;
248

    
249
        g_print("creating window\n");
250

    
251
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
252
        button = gtk_button_new_with_label("Click this button");
253
        gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);
254
        gtk_container_add(GTK_CONTAINER(window), button);
255
        g_signal_connect(G_OBJECT(button), "clicked",
256
                         G_CALLBACK(button_clicked), NULL);
257
        gtk_widget_show_all(window);
258
}
259

    
260
static void create_folderview_sub_widget(void)
261
{
262
        GtkWidget *vbox;
263
        GtkWidget *button;
264

    
265
        g_print("creating sub widget\n");
266

    
267
        vbox = gtk_vbox_new(FALSE, 2);
268
        button = gtk_button_new_with_label("Test");
269
        gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
270
        gtk_widget_show_all(vbox);
271
        syl_plugin_folderview_add_sub_widget(vbox);
272
}