Statistics
| Revision:

root / plugin / test / test.c @ 2821

History | View | Annotate | Download (7.39 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

    
55
static void create_window(void);
56
static void create_folderview_sub_widget(void);
57

    
58
gulong app_exit_handler_id = 0;
59

    
60
void plugin_load(void)
61
{
62
        GList *list, *cur;
63
        const gchar *ver;
64
        gpointer mainwin;
65

    
66
        g_print("test plug-in loaded!\n");
67

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

    
76
        ver = syl_plugin_get_prog_version();
77
        g_print("program ver: %s\n", ver);
78

    
79
        mainwin = syl_plugin_main_window_get();
80
        g_print("mainwin: %p\n", mainwin);
81
        syl_plugin_main_window_popup(mainwin);
82

    
83
        create_folderview_sub_widget();
84

    
85
        syl_plugin_add_menuitem("/Tools", NULL, NULL, NULL);
86
        syl_plugin_add_menuitem("/Tools", "Plugin test", create_window, NULL);
87

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

    
104
        syl_plugin_add_factory_item("<SummaryView>", "/---", NULL, NULL);
105
        syl_plugin_add_factory_item("<SummaryView>", "/Test Plug-in menu",
106
                                    menu_selected_cb, NULL);
107

    
108
        g_print("test plug-in loading done\n");
109
}
110

    
111
void plugin_unload(void)
112
{
113
        g_print("test plug-in unloaded!\n");
114
        g_signal_handler_disconnect(syl_app_get(), app_exit_handler_id);
115
}
116

    
117
SylPluginInfo *plugin_info(void)
118
{
119
        return &info;
120
}
121

    
122
gint plugin_interface_version(void)
123
{
124
        return SYL_PLUGIN_INTERFACE_VERSION;
125
}
126

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

    
137
static void app_exit_cb(GObject *obj, gpointer data)
138
{
139
        g_print("test: %p: app will exit\n", obj);
140
}
141

    
142
static void folderview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory,
143
                                     gpointer data)
144
{
145
        g_print("test: %p: folderview menu popup\n", obj);
146
}
147

    
148
static void summaryview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory,
149
                                      gpointer data)
150
{
151
        GtkWidget *widget;
152

    
153
        g_print("test: %p: summaryview menu popup\n", obj);
154
        widget = gtk_item_factory_get_item(ifactory, "/Test Plug-in menu");
155
        if (widget)
156
                gtk_widget_set_sensitive(widget, TRUE);
157
}
158

    
159
static void activate_menu_cb(GtkMenuItem *menuitem, gpointer data)
160
{
161
        g_print("menu activated\n");
162
}
163

    
164
static void textview_menu_popup_cb(GObject *obj, GtkMenu *menu,
165
                                   GtkTextView *textview,
166
                                   const gchar *uri,
167
                                   const gchar *selected_text,
168
                                   MsgInfo *msginfo)
169
{
170
        GtkWidget *separator, *menuitem;
171

    
172
        g_print("test: %p: textview menu popup\n", obj);
173
        g_print("test: %p: uri: %s, text: %s\n", obj, uri ? uri : "(none)",
174
                selected_text ? selected_text : "(none)");
175
        g_print("test: %p: msg: %s\n", obj,
176
                msginfo && msginfo->subject ? msginfo->subject : "");
177

    
178
        separator = gtk_separator_menu_item_new();
179
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), separator);
180
        gtk_widget_show(separator);
181

    
182
        menuitem = gtk_menu_item_new_with_mnemonic("Test menu");
183
        g_signal_connect(menuitem, "activate", G_CALLBACK(activate_menu_cb), NULL);
184
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
185
        gtk_widget_show(menuitem);
186
}
187

    
188
static void menu_selected_cb(void)
189
{
190
        gint sel;
191
        GSList *mlist;
192

    
193
        g_print("test: summary menu selected\n");
194
        sel = syl_plugin_summary_get_selection_type();
195
        mlist = syl_plugin_summary_get_selected_msg_list();
196
        g_print("test: selection type: %d\n", sel);
197
        g_print("test: number of selected summary message: %d\n",
198
                g_slist_length(mlist));
199
        g_slist_free(mlist);
200
}
201

    
202
static void compose_created_cb(GObject *obj, gpointer compose)
203
{
204
        gchar *text;
205

    
206
        g_print("test: %p: compose created (%p)\n", obj, compose);
207

    
208
        text = syl_plugin_compose_entry_get_text(compose, 0);
209
        g_print("test: compose To: %s\n", text);
210
        g_free(text);
211
#if 0
212
        syl_plugin_compose_entry_set(compose, "test-plugin@test", 1);
213
        syl_plugin_compose_entry_append(compose, "second@test", 1);
214
#endif
215
}
216

    
217
static void compose_destroy_cb(GObject *obj, gpointer compose)
218
{
219
        g_print("test: %p: compose will be destroyed (%p)\n", obj, compose);
220
}
221

    
222
static void button_clicked(GtkWidget *widget, gpointer data)
223
{
224
        g_print("button_clicked\n");
225
        /* syl_plugin_app_will_exit(TRUE); */
226
}
227

    
228
static void create_window(void)
229
{
230
        GtkWidget *window;
231
        GtkWidget *button;
232

    
233
        g_print("creating window\n");
234

    
235
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
236
        button = gtk_button_new_with_label("Click this button");
237
        gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);
238
        gtk_container_add(GTK_CONTAINER(window), button);
239
        g_signal_connect(G_OBJECT(button), "clicked",
240
                         G_CALLBACK(button_clicked), NULL);
241
        gtk_widget_show_all(window);
242
}
243

    
244
static void create_folderview_sub_widget(void)
245
{
246
        GtkWidget *vbox;
247
        GtkWidget *button;
248

    
249
        g_print("creating sub widget\n");
250

    
251
        vbox = gtk_vbox_new(FALSE, 2);
252
        button = gtk_button_new_with_label("Test");
253
        gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
254
        gtk_widget_show_all(vbox);
255
        syl_plugin_folderview_add_sub_widget(vbox);
256
}