From 441b184056b95fcf0ce22a1f61c7e8ce779949cc Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 21 Jan 2010 06:08:37 +0000 Subject: added new plug-in APIs for compose window. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2436 ee746299-78ed-0310-b773-934348b2243d --- ChangeLog | 12 +++++++++ plugin/test/test.c | 58 ++++++++++++++++++++++++++++++++++++----- src/compose.c | 21 +++++++++++++++ src/compose.h | 5 ++-- src/main.c | 7 +++++ src/plugin.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/plugin.h | 23 +++++++++++++++++ 7 files changed, 194 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61c5555b..ba95ac9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-01-21 + + * src/compose.[ch] + src/plugin.[ch] + src/main.c: added new plug-in APIs for compose window: + syl_plugin_compose_new, syl_plugin_compose_entry_set, + syl_plugin_compose_entry_append, syl_plugin_compose_entry_get_text, + syl_plugin_compose_lock, syl_plugin_compose_unlock + * src/compose.h: made GtkSpell members non-conditional for binary + compatibility. + * plugin/test/test.c: added tests for new signals. + 2010-01-19 * src/summaryview.c: summary_show(): prevent beep when changing to diff --git a/plugin/test/test.c b/plugin/test/test.c index 3de6ee62..3526e960 100644 --- a/plugin/test/test.c +++ b/plugin/test/test.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2009 Hiroyuki Yamamoto + * Copyright (C) 1999-2010 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ #include #include +#include "sylmain.h" #include "plugin.h" #include "test.h" #include "folder.h" @@ -31,6 +32,13 @@ static SylPluginInfo info = { "Test plug-in for Sylpheed plug-in system" }; +static void init_done_cb(GObject *obj, gpointer data); +static void app_exit_cb(GObject *obj, gpointer data); +static void menu_popup_cb(GObject *obj, GtkItemFactory *ifactory, + gpointer data); +static void compose_created_cb(GObject *obj, gpointer compose); +static void compose_destroy_cb(GObject *obj, gpointer compose); + static void create_window(void); void plugin_load(void) @@ -40,16 +48,17 @@ void plugin_load(void) gpointer mainwin; g_print("test plug-in loaded!\n"); + list = folder_get_list(); - g_print("list = %p\n", list); + g_print("folder list = %p\n", list); for (cur = list; cur != NULL; cur = cur->next) { Folder *folder = FOLDER(cur->data); gchar *id = folder_get_identifier(folder); - g_print("id = %s\n", id); + g_print("folder id = %s\n", id); } ver = syl_plugin_get_prog_version(); - g_print("ver: %s\n", ver); + g_print("program ver: %s\n", ver); mainwin = syl_plugin_main_window_get(); g_print("mainwin: %p\n", mainwin); @@ -58,6 +67,17 @@ void plugin_load(void) syl_plugin_add_menuitem("/Tools", NULL, NULL, NULL); syl_plugin_add_menuitem("/Tools", "Plugin test", create_window, NULL); + g_signal_connect(syl_app_get(), "init-done", G_CALLBACK(init_done_cb), + NULL); + g_signal_connect(syl_app_get(), "app-exit", G_CALLBACK(app_exit_cb), + NULL); + syl_plugin_signal_connect("folderview-menu-popup", + G_CALLBACK(menu_popup_cb), NULL); + syl_plugin_signal_connect("compose-created", + G_CALLBACK(compose_created_cb), NULL); + syl_plugin_signal_connect("compose-destroy", + G_CALLBACK(compose_destroy_cb), NULL); + g_print("test plug-in loading done\n"); } @@ -76,10 +96,36 @@ gint plugin_interface_version(void) return SYL_PLUGIN_INTERFACE_VERSION; } +static void init_done_cb(GObject *obj, gpointer data) +{ + g_print("test: %p: app init done\n", obj); +} + +static void app_exit_cb(GObject *obj, gpointer data) +{ + g_print("test: %p: app will exit\n", obj); +} + +static void menu_popup_cb(GObject *obj, GtkItemFactory *ifactory, + gpointer data) +{ + g_print("test: %p: folderview menu popup\n", obj); +} + +static void compose_created_cb(GObject *obj, gpointer compose) +{ + g_print("test: %p: compose created (%p)\n", obj, compose); +} + +static void compose_destroy_cb(GObject *obj, gpointer compose) +{ + g_print("test: %p: compose will be destroyed (%p)\n", obj, compose); +} + static void button_clicked(GtkWidget *widget, gpointer data) { g_print("button_clicked\n"); - syl_plugin_app_will_exit(TRUE); + /* syl_plugin_app_will_exit(TRUE); */ } static void create_window(void) @@ -90,7 +136,7 @@ static void create_window(void) g_print("creating window\n"); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - button = gtk_button_new_with_label("Click this to quit"); + button = gtk_button_new_with_label("Click this button"); gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); gtk_container_add(GTK_CONTAINER(window), button); g_signal_connect(G_OBJECT(button), "clicked", diff --git a/src/compose.c b/src/compose.c index 41ab17a9..3b528c19 100644 --- a/src/compose.c +++ b/src/compose.c @@ -133,6 +133,7 @@ #include "quote_fmt.h" #include "template.h" #include "undo.h" +#include "plugin.h" #if USE_GPGME # include "rfc2015.h" @@ -803,6 +804,8 @@ Compose *compose_new(PrefsAccount *account, FolderItem *item, compose_connect_changed_callbacks(compose); compose_set_title(compose); + syl_plugin_signal_emit("compose-created", compose); + if (prefs_common.enable_autosave && prefs_common.autosave_itv > 0) compose->autosave_tag = g_timeout_add(prefs_common.autosave_itv * 60 * 1000, @@ -908,6 +911,8 @@ void compose_reply(MsgInfo *msginfo, FolderItem *item, ComposeMode mode, procmsg_msginfo_free(replyinfo); + syl_plugin_signal_emit("compose-created", compose); + if (prefs_common.enable_autosave && prefs_common.autosave_itv > 0) compose->autosave_tag = g_timeout_add(prefs_common.autosave_itv * 60 * 1000, @@ -1041,6 +1046,8 @@ void compose_forward(GSList *mlist, FolderItem *item, gboolean as_attach, else gtk_widget_grab_focus(compose->newsgroups_entry); + syl_plugin_signal_emit("compose-created", compose); + if (prefs_common.enable_autosave && prefs_common.autosave_itv > 0) compose->autosave_tag = g_timeout_add(prefs_common.autosave_itv * 60 * 1000, @@ -1110,6 +1117,8 @@ void compose_redirect(MsgInfo *msginfo, FolderItem *item) compose_connect_changed_callbacks(compose); compose_set_title(compose); + + syl_plugin_signal_emit("compose-created", compose); } void compose_reedit(MsgInfo *msginfo) @@ -1208,6 +1217,8 @@ void compose_reedit(MsgInfo *msginfo) menu_set_active(ifactory, "/Tools/Request disposition notification", TRUE); } + syl_plugin_signal_emit("compose-created", compose); + if (prefs_common.enable_autosave && prefs_common.autosave_itv > 0) compose->autosave_tag = g_timeout_add(prefs_common.autosave_itv * 60 * 1000, @@ -1318,6 +1329,14 @@ void compose_entry_append(Compose *compose, const gchar *text, gtk_editable_insert_text(GTK_EDITABLE(entry), text, -1, &pos); } +gchar *compose_entry_get_text(Compose *compose, ComposeEntryType type) +{ + GtkEntry *entry; + + entry = compose_get_entry(compose, type); + return gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); +} + static void compose_entries_set(Compose *compose, const gchar *mailto) { gchar *to = NULL; @@ -6008,6 +6027,8 @@ static void compose_destroy(Compose *compose) if (compose->autosave_tag > 0) g_source_remove(compose->autosave_tag); + syl_plugin_signal_emit("compose-destroy", compose); + /* NOTE: address_completion_end() does nothing with the window * however this may change. */ address_completion_end(compose->window); diff --git a/src/compose.h b/src/compose.h index 10b4900b..d73c94b9 100644 --- a/src/compose.h +++ b/src/compose.h @@ -132,12 +132,11 @@ struct _Compose GtkWidget *tmpl_menu; -#if USE_GTKSPELL + /* GtkSpell */ GtkWidget *spell_menu; gchar *spell_lang; gboolean check_spell; GSList *dict_list; -#endif ComposeMode mode; @@ -233,6 +232,8 @@ void compose_entry_set (Compose *compose, void compose_entry_append (Compose *compose, const gchar *text, ComposeEntryType type); +gchar *compose_entry_get_text (Compose *compose, + ComposeEntryType type); void compose_lock (Compose *compose); void compose_unlock (Compose *compose); diff --git a/src/main.c b/src/main.c index 65a0e475..d250cedc 100644 --- a/src/main.c +++ b/src/main.c @@ -1125,6 +1125,13 @@ static void plugin_init(void) messageview_create_with_new_window); syl_plugin_add_symbol("messageview_show", messageview_show); + syl_plugin_add_symbol("compose_new", compose_new); + syl_plugin_add_symbol("compose_entry_set", compose_entry_set); + syl_plugin_add_symbol("compose_entry_append", compose_entry_append); + syl_plugin_add_symbol("compose_entry_get_text", compose_entry_get_text); + syl_plugin_add_symbol("compose_lock", compose_lock); + syl_plugin_add_symbol("compose_unlock", compose_unlock); + syl_plugin_add_symbol("foldersel_folder_sel", foldersel_folder_sel); syl_plugin_add_symbol("foldersel_folder_sel_full", diff --git a/src/plugin.c b/src/plugin.c index 51968572..108573b7 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -31,6 +31,8 @@ enum { PLUGIN_LOAD, PLUGIN_UNLOAD, FOLDERVIEW_MENU_POPUP, + COMPOSE_CREATED, + COMPOSE_DESTROY, LAST_SIGNAL }; @@ -103,6 +105,26 @@ static void syl_plugin_class_init(SylPluginClass *klass) G_TYPE_NONE, 1, G_TYPE_POINTER); + plugin_signals[COMPOSE_CREATED] = + g_signal_new("compose-created", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(SylPluginClass, compose_created), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, + 1, + G_TYPE_POINTER); + plugin_signals[COMPOSE_DESTROY] = + g_signal_new("compose-destroy", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(SylPluginClass, compose_destroy), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, + 1, + G_TYPE_POINTER); } void syl_plugin_signal_connect(const gchar *name, GCallback callback, @@ -648,6 +670,60 @@ void syl_plugin_open_message_by_new_window(MsgInfo *msginfo) } } + +gpointer syl_plugin_compose_new(PrefsAccount *account, FolderItem *item, + const gchar *mailto, GPtrArray *attach_files) +{ + gpointer (*func)(PrefsAccount *, FolderItem *, const gchar *, + GPtrArray *); + + func = syl_plugin_lookup_symbol("compose_new"); + return SAFE_CALL_ARG4_RET(func, account, item, mailto, attach_files); +} + +void syl_plugin_compose_entry_set(gpointer compose, const gchar *text, + gint type) +{ + void (*func)(gpointer, const gchar *, gint); + + func = syl_plugin_lookup_symbol("compose_entry_set"); + SAFE_CALL_ARG3(func, compose, text, type); +} + +void syl_plugin_compose_entry_append(gpointer compose, const gchar *text, + gint type) +{ + void (*func)(gpointer, const gchar *, gint); + + func = syl_plugin_lookup_symbol("compose_entry_append"); + SAFE_CALL_ARG3(func, compose, text, type); +} + +gchar *syl_plugin_compose_entry_get_text(gpointer compose, gint type) +{ + gchar * (*func)(gpointer, gint); + + func = syl_plugin_lookup_symbol("compose_entry_get_text"); + return SAFE_CALL_ARG2_RET(func, compose, type); +} + +void syl_plugin_compose_lock(gpointer compose) +{ + void (*func)(gpointer); + + func = syl_plugin_lookup_symbol("compose_lock"); + SAFE_CALL_ARG1(func, compose); +} + +void syl_plugin_compose_unlock(gpointer compose) +{ + void (*func)(gpointer); + + func = syl_plugin_lookup_symbol("compose_unlock"); + SAFE_CALL_ARG1(func, compose); +} + + FolderItem *syl_plugin_folder_sel(Folder *cur_folder, gint sel_type, const gchar *default_folder) { diff --git a/src/plugin.h b/src/plugin.h index 94ea652d..50f5738b 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -58,7 +58,11 @@ struct _SylPluginClass void (* plugin_load) (GObject *obj, GModule *module); void (* plugin_unload) (GObject *obj, GModule *module); + void (* folderview_menu_popup) (GObject *obj, gpointer ifactory); + + void (* compose_created) (GObject *obj, gpointer compose); + void (* compose_destroy) (GObject *obj, gpointer compose); }; struct _SylPluginInfo @@ -155,6 +159,25 @@ gpointer syl_plugin_messageview_create_with_new_window (void); void syl_plugin_open_message_by_new_window (MsgInfo *msginfo); +/* Compose */ +gpointer syl_plugin_compose_new (PrefsAccount *account, + FolderItem *item, + const gchar *mailto, + GPtrArray *attach_files); + +/* entry type: + 0: To 1: Cc 2: Bcc 3: Reply-To 4: Subject 5: Newsgroups 6: Followup-To */ +void syl_plugin_compose_entry_set (gpointer compose, + const gchar *text, + gint type); +void syl_plugin_compose_entry_append (gpointer compose, + const gchar *text, + gint type); +gchar *syl_plugin_compose_entry_get_text (gpointer compose, + gint type); +void syl_plugin_compose_lock (gpointer compose); +void syl_plugin_compose_unlock (gpointer compose); + /* Others */ FolderItem *syl_plugin_folder_sel (Folder *cur_folder, gint sel_type, -- cgit v1.2.3