root / plugin / test / test.c @ 3220
History | View | Annotate | Download (9.2 kB)
| 1 | /*
|
|---|---|
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | * Copyright (C) 1999-2013 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.4.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 | |
| 150 | syl_plugin_notification_window_open("Sylpheed app init done", "Normal text\n<b>Bold</b>\n<s>Strikethrough</s>\n<b>This is a long text and will be truncated:</b> ABCDEFGHIJKLMNOPQRSTUVWXYZ", 5); |
| 151 | |
| 152 | g_print("test: %p: app init done\n", obj);
|
| 153 | } |
| 154 | |
| 155 | static void app_exit_cb(GObject *obj, gpointer data) |
| 156 | {
|
| 157 | g_print("test: %p: app will exit\n", obj);
|
| 158 | } |
| 159 | |
| 160 | static void folderview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory, |
| 161 | gpointer data) |
| 162 | {
|
| 163 | g_print("test: %p: folderview menu popup\n", obj);
|
| 164 | } |
| 165 | |
| 166 | static void summaryview_menu_popup_cb(GObject *obj, GtkItemFactory *ifactory, |
| 167 | gpointer data) |
| 168 | {
|
| 169 | GtkWidget *widget; |
| 170 | |
| 171 | g_print("test: %p: summaryview menu popup\n", obj);
|
| 172 | widget = gtk_item_factory_get_item(ifactory, "/Test Plug-in menu");
|
| 173 | if (widget)
|
| 174 | gtk_widget_set_sensitive(widget, TRUE); |
| 175 | } |
| 176 | |
| 177 | static void activate_menu_cb(GtkMenuItem *menuitem, gpointer data) |
| 178 | {
|
| 179 | g_print("menu activated\n");
|
| 180 | } |
| 181 | |
| 182 | static void textview_menu_popup_cb(GObject *obj, GtkMenu *menu, |
| 183 | GtkTextView *textview, |
| 184 | const gchar *uri,
|
| 185 | const gchar *selected_text,
|
| 186 | MsgInfo *msginfo) |
| 187 | {
|
| 188 | GtkWidget *separator, *menuitem; |
| 189 | |
| 190 | g_print("test: %p: textview menu popup\n", obj);
|
| 191 | g_print("test: %p: uri: %s, text: %s\n", obj, uri ? uri : "(none)", |
| 192 | selected_text ? selected_text : "(none)");
|
| 193 | g_print("test: %p: msg: %s\n", obj,
|
| 194 | msginfo && msginfo->subject ? msginfo->subject : "");
|
| 195 | |
| 196 | separator = gtk_separator_menu_item_new(); |
| 197 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), separator); |
| 198 | gtk_widget_show(separator); |
| 199 | |
| 200 | menuitem = gtk_menu_item_new_with_mnemonic("Test menu");
|
| 201 | g_signal_connect(menuitem, "activate", G_CALLBACK(activate_menu_cb), NULL); |
| 202 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
| 203 | gtk_widget_show(menuitem); |
| 204 | } |
| 205 | |
| 206 | static void menu_selected_cb(void) |
| 207 | {
|
| 208 | gint sel; |
| 209 | GSList *mlist; |
| 210 | |
| 211 | g_print("test: summary menu selected\n");
|
| 212 | sel = syl_plugin_summary_get_selection_type(); |
| 213 | mlist = syl_plugin_summary_get_selected_msg_list(); |
| 214 | g_print("test: selection type: %d\n", sel);
|
| 215 | g_print("test: number of selected summary message: %d\n",
|
| 216 | g_slist_length(mlist)); |
| 217 | g_slist_free(mlist); |
| 218 | } |
| 219 | |
| 220 | static void compose_created_cb(GObject *obj, gpointer compose) |
| 221 | {
|
| 222 | gchar *text; |
| 223 | |
| 224 | g_print("test: %p: compose created (%p)\n", obj, compose);
|
| 225 | |
| 226 | text = syl_plugin_compose_entry_get_text(compose, 0);
|
| 227 | g_print("test: compose To: %s\n", text);
|
| 228 | g_free(text); |
| 229 | #if 0
|
| 230 | syl_plugin_compose_entry_set(compose, "test-plugin@test", 1); |
| 231 | syl_plugin_compose_entry_append(compose, "second@test", 1); |
| 232 | #endif |
| 233 | } |
| 234 | |
| 235 | static void compose_destroy_cb(GObject *obj, gpointer compose) |
| 236 | {
|
| 237 | g_print("test: %p: compose will be destroyed (%p)\n", obj, compose);
|
| 238 | } |
| 239 | |
| 240 | static gboolean compose_send_cb(GObject *obj, gpointer compose,
|
| 241 | gint compose_mode, gint send_mode, |
| 242 | const gchar *msg_file, GSList *to_list)
|
| 243 | {
|
| 244 | g_print("test: %p: composed message will be sent (%p)\n", obj, compose);
|
| 245 | g_print("test: compose_mode: %d, send_mode: %d, file: %s\n",
|
| 246 | compose_mode, send_mode, msg_file); |
| 247 | |
| 248 | return FALSE; /* return TRUE to cancel sending */ |
| 249 | } |
| 250 | |
| 251 | static void messageview_show_cb(GObject *obj, gpointer msgview, |
| 252 | MsgInfo *msginfo, gboolean all_headers) |
| 253 | {
|
| 254 | g_print("test: %p: messageview_show (%p), all_headers: %d: %s\n",
|
| 255 | obj, msgview, all_headers, |
| 256 | msginfo && msginfo->subject ? msginfo->subject : "");
|
| 257 | } |
| 258 | |
| 259 | static void inc_start_cb(GObject *obj, PrefsAccount *ac) |
| 260 | {
|
| 261 | if (ac)
|
| 262 | g_print("test: receive start: account: %s\n", ac->account_name);
|
| 263 | else
|
| 264 | g_print("test: receive start: all accounts\n");
|
| 265 | } |
| 266 | |
| 267 | static void inc_finished_cb(GObject *obj, gint new_messages) |
| 268 | {
|
| 269 | g_print("test: received %d new messages\n", new_messages);
|
| 270 | } |
| 271 | |
| 272 | static void button_clicked(GtkWidget *widget, gpointer data) |
| 273 | {
|
| 274 | g_print("button_clicked\n");
|
| 275 | /* syl_plugin_app_will_exit(TRUE); */
|
| 276 | } |
| 277 | |
| 278 | static void create_window(void) |
| 279 | {
|
| 280 | GtkWidget *window; |
| 281 | GtkWidget *button; |
| 282 | |
| 283 | g_print("creating window\n");
|
| 284 | |
| 285 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 286 | button = gtk_button_new_with_label("Click this button");
|
| 287 | gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); |
| 288 | gtk_container_add(GTK_CONTAINER(window), button); |
| 289 | g_signal_connect(G_OBJECT(button), "clicked",
|
| 290 | G_CALLBACK(button_clicked), NULL);
|
| 291 | gtk_widget_show_all(window); |
| 292 | } |
| 293 | |
| 294 | static void create_folderview_sub_widget(void) |
| 295 | {
|
| 296 | GtkWidget *vbox; |
| 297 | GtkWidget *button; |
| 298 | |
| 299 | g_print("creating sub widget\n");
|
| 300 | |
| 301 | vbox = gtk_vbox_new(FALSE, 2);
|
| 302 | button = gtk_button_new_with_label("Test");
|
| 303 | gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
|
| 304 | gtk_widget_show_all(vbox); |
| 305 | syl_plugin_folderview_add_sub_widget(vbox); |
| 306 | } |