toolbar.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237
  1. /*
  2. * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
  3. * Copyright (C) 2001-2006 Hiroyuki Yamamoto and the Claws Mail team
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. /*
  20. * General functions for accessing address book files.
  21. */
  22. #ifdef HAVE_CONFIG_H
  23. # include "config.h"
  24. #endif
  25. #include "defs.h"
  26. #include <glib.h>
  27. #include <glib/gi18n.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <dirent.h>
  31. #include <sys/stat.h>
  32. #include <math.h>
  33. #include <setjmp.h>
  34. #include "mainwindow.h"
  35. #include "summaryview.h"
  36. #include "compose.h"
  37. #include "utils.h"
  38. #include "xml.h"
  39. #include "mgutils.h"
  40. #include "prefs_gtk.h"
  41. #include "codeconv.h"
  42. #include "stock_pixmap.h"
  43. #include "manage_window.h"
  44. #include "gtkutils.h"
  45. #include "toolbar.h"
  46. #include "menu.h"
  47. #include "inc.h"
  48. #include "action.h"
  49. #include "prefs_actions.h"
  50. #include "prefs_common.h"
  51. #include "prefs_toolbar.h"
  52. #include "alertpanel.h"
  53. /* elements */
  54. #define TOOLBAR_TAG_INDEX "toolbar"
  55. #define TOOLBAR_TAG_ITEM "item"
  56. #define TOOLBAR_TAG_SEPARATOR "separator"
  57. #define TOOLBAR_ICON_FILE "file"
  58. #define TOOLBAR_ICON_TEXT "text"
  59. #define TOOLBAR_ICON_ACTION "action"
  60. gboolean toolbar_is_duplicate (gint action,
  61. ToolbarType source);
  62. static void toolbar_parse_item (XMLFile *file,
  63. ToolbarType source);
  64. static gint toolbar_ret_val_from_text (const gchar *text);
  65. static gchar *toolbar_ret_text_from_val (gint val);
  66. static void toolbar_set_default_main (void);
  67. static void toolbar_set_default_compose (void);
  68. static void toolbar_set_default_msgview (void);
  69. static void toolbar_style (ToolbarType type,
  70. guint action,
  71. gpointer data);
  72. static MainWindow *get_mainwin (gpointer data);
  73. static void activate_compose_button (Toolbar *toolbar,
  74. ToolbarStyle style,
  75. ComposeButtonType type);
  76. /* toolbar callbacks */
  77. static void toolbar_reply (gpointer data,
  78. guint action);
  79. static void toolbar_delete_cb (GtkWidget *widget,
  80. gpointer data);
  81. static void toolbar_trash_cb (GtkWidget *widget,
  82. gpointer data);
  83. static void toolbar_compose_cb (GtkWidget *widget,
  84. gpointer data);
  85. static void toolbar_learn_cb (GtkWidget *widget,
  86. gpointer data);
  87. static void toolbar_reply_cb (GtkWidget *widget,
  88. gpointer data);
  89. static void toolbar_reply_to_all_cb (GtkWidget *widget,
  90. gpointer data);
  91. static void toolbar_reply_to_list_cb (GtkWidget *widget,
  92. gpointer data);
  93. static void toolbar_reply_to_sender_cb (GtkWidget *widget,
  94. gpointer data);
  95. static void toolbar_forward_cb (GtkWidget *widget,
  96. gpointer data);
  97. static void toolbar_prev_unread_cb (GtkWidget *widget,
  98. gpointer data);
  99. static void toolbar_next_unread_cb (GtkWidget *widget,
  100. gpointer data);
  101. static void toolbar_ignore_thread_cb (GtkWidget *widget,
  102. gpointer data);
  103. static void toolbar_print_cb (GtkWidget *widget,
  104. gpointer data);
  105. static void toolbar_actions_execute_cb (GtkWidget *widget,
  106. gpointer data);
  107. static void toolbar_send_cb (GtkWidget *widget,
  108. gpointer data);
  109. static void toolbar_send_later_cb (GtkWidget *widget,
  110. gpointer data);
  111. static void toolbar_draft_cb (GtkWidget *widget,
  112. gpointer data);
  113. static void toolbar_insert_cb (GtkWidget *widget,
  114. gpointer data);
  115. static void toolbar_attach_cb (GtkWidget *widget,
  116. gpointer data);
  117. static void toolbar_sig_cb (GtkWidget *widget,
  118. gpointer data);
  119. static void toolbar_ext_editor_cb (GtkWidget *widget,
  120. gpointer data);
  121. static void toolbar_linewrap_current_cb (GtkWidget *widget,
  122. gpointer data);
  123. static void toolbar_linewrap_all_cb (GtkWidget *widget,
  124. gpointer data);
  125. static void toolbar_addrbook_cb (GtkWidget *widget,
  126. gpointer data);
  127. #ifdef USE_ASPELL
  128. static void toolbar_check_spelling_cb (GtkWidget *widget,
  129. gpointer data);
  130. #endif
  131. struct {
  132. gchar *index_str;
  133. const gchar *descr;
  134. } toolbar_text [] = {
  135. { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
  136. { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
  137. { "A_SEND_QUEUED", N_("Send Queued Messages") },
  138. { "A_COMPOSE_EMAIL", N_("Compose Email") },
  139. { "A_COMPOSE_NEWS", N_("Compose News") },
  140. { "A_REPLY_MESSAGE", N_("Reply to Message") },
  141. { "A_REPLY_SENDER", N_("Reply to Sender") },
  142. { "A_REPLY_ALL", N_("Reply to All") },
  143. { "A_REPLY_ML", N_("Reply to Mailing-list") },
  144. { "A_FORWARD", N_("Forward Message") },
  145. { "A_TRASH", N_("Trash Message") },
  146. { "A_DELETE_REAL", N_("Delete Message") },
  147. { "A_EXECUTE", N_("Execute") },
  148. { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
  149. { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
  150. { "A_IGNORE_THREAD", N_("Ignore thread") },
  151. { "A_PRINT", N_("Print") },
  152. { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
  153. { "A_SEND", N_("Send Message") },
  154. { "A_SENDL", N_("Put into queue folder and send later") },
  155. { "A_DRAFT", N_("Save to draft folder") },
  156. { "A_INSERT", N_("Insert file") },
  157. { "A_ATTACH", N_("Attach file") },
  158. { "A_SIG", N_("Insert signature") },
  159. { "A_EXTEDITOR", N_("Edit with external editor") },
  160. { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
  161. { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
  162. { "A_ADDRBOOK", N_("Address book") },
  163. #ifdef USE_ASPELL
  164. { "A_CHECK_SPELLING", N_("Check spelling") },
  165. #endif
  166. { "A_SYL_ACTIONS", N_("Claws Mail Actions Feature") },
  167. { "A_SEPARATOR", "Separator" }
  168. };
  169. /* struct holds configuration files and a list of
  170. * currently active toolbar items
  171. * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
  172. * give us an index
  173. */
  174. struct {
  175. const gchar *conf_file;
  176. GSList *item_list;
  177. } toolbar_config[3] = {
  178. { "toolbar_main.xml", NULL},
  179. { "toolbar_compose.xml", NULL},
  180. { "toolbar_msgview.xml", NULL}
  181. };
  182. static GtkItemFactoryEntry reply_entries[] =
  183. {
  184. {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
  185. {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
  186. };
  187. static GtkItemFactoryEntry replyall_entries[] =
  188. {
  189. {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
  190. {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
  191. };
  192. static GtkItemFactoryEntry replylist_entries[] =
  193. {
  194. {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
  195. {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
  196. };
  197. static GtkItemFactoryEntry replysender_entries[] =
  198. {
  199. {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
  200. {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
  201. };
  202. static GtkItemFactoryEntry forward_entries[] =
  203. {
  204. {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
  205. {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
  206. {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
  207. };
  208. gint toolbar_ret_val_from_descr(const gchar *descr)
  209. {
  210. gint i;
  211. for (i = 0; i < N_ACTION_VAL; i++) {
  212. if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
  213. return i;
  214. }
  215. return -1;
  216. }
  217. gchar *toolbar_ret_descr_from_val(gint val)
  218. {
  219. g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
  220. return gettext(toolbar_text[val].descr);
  221. }
  222. static gint toolbar_ret_val_from_text(const gchar *text)
  223. {
  224. gint i;
  225. for (i = 0; i < N_ACTION_VAL; i++) {
  226. if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
  227. return i;
  228. }
  229. return -1;
  230. }
  231. static gchar *toolbar_ret_text_from_val(gint val)
  232. {
  233. g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
  234. return toolbar_text[val].index_str;
  235. }
  236. gboolean toolbar_is_duplicate(gint action, ToolbarType source)
  237. {
  238. GSList *cur;
  239. if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
  240. return FALSE;
  241. for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
  242. ToolbarItem *item = (ToolbarItem*) cur->data;
  243. if (item->index == action)
  244. return TRUE;
  245. }
  246. return FALSE;
  247. }
  248. /* depending on toolbar type this function
  249. returns a list of available toolbar events being
  250. displayed by prefs_toolbar
  251. */
  252. GList *toolbar_get_action_items(ToolbarType source)
  253. {
  254. GList *items = NULL;
  255. gint i = 0;
  256. if (source == TOOLBAR_MAIN) {
  257. gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
  258. A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
  259. A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
  260. A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
  261. A_GOTO_NEXT, A_IGNORE_THREAD, A_PRINT,
  262. A_ADDRBOOK, A_LEARN_SPAM, A_SYL_ACTIONS };
  263. for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
  264. items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
  265. }
  266. }
  267. else if (source == TOOLBAR_COMPOSE) {
  268. gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
  269. A_INSERT, A_ATTACH, A_SIG,
  270. A_EXTEDITOR, A_LINEWRAP_CURRENT,
  271. A_LINEWRAP_ALL, A_ADDRBOOK,
  272. #ifdef USE_ASPELL
  273. A_CHECK_SPELLING,
  274. #endif
  275. A_SYL_ACTIONS };
  276. for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
  277. items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
  278. }
  279. else if (source == TOOLBAR_MSGVIEW) {
  280. gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
  281. A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
  282. A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
  283. A_ADDRBOOK, A_LEARN_SPAM, A_SYL_ACTIONS };
  284. for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
  285. items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
  286. }
  287. return items;
  288. }
  289. static void toolbar_parse_item(XMLFile *file, ToolbarType source)
  290. {
  291. GList *attr;
  292. gchar *name, *value;
  293. ToolbarItem *item = NULL;
  294. gboolean rewrite = FALSE;
  295. attr = xml_get_current_tag_attr(file);
  296. item = g_new0(ToolbarItem, 1);
  297. while( attr ) {
  298. name = ((XMLAttr *)attr->data)->name;
  299. value = ((XMLAttr *)attr->data)->value;
  300. if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
  301. item->file = g_strdup (value);
  302. else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
  303. item->text = g_strdup (value);
  304. else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
  305. item->index = toolbar_ret_val_from_text(value);
  306. if (item->index == -1 && !strcmp(value, "A_DELETE")) {
  307. /* switch button */
  308. item->index = A_TRASH;
  309. g_free(item->file);
  310. item->file = g_strdup("trash_btn");
  311. g_free(item->text);
  312. item->text = g_strdup(_("Trash"));
  313. rewrite = TRUE;
  314. }
  315. attr = g_list_next(attr);
  316. }
  317. if (item->index != -1) {
  318. if (!toolbar_is_duplicate(item->index, source))
  319. toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
  320. item);
  321. }
  322. if (rewrite) {
  323. toolbar_save_config_file(source);
  324. }
  325. }
  326. static void toolbar_set_default_main(void)
  327. {
  328. struct {
  329. gint action;
  330. gint icon;
  331. gchar *text;
  332. } default_toolbar[] = {
  333. { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get Mail") },
  334. { A_SEPARATOR, 0, ("") },
  335. { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
  336. { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,
  337. (gchar*)Q_("Toolbar|Compose") },
  338. { A_SEPARATOR, 0, ("") },
  339. { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
  340. { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
  341. { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
  342. { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
  343. { A_SEPARATOR, 0, ("") },
  344. { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
  345. #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
  346. { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
  347. #endif
  348. { A_SEPARATOR, 0, ("") },
  349. { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
  350. };
  351. gint i;
  352. for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
  353. ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
  354. if (default_toolbar[i].action != A_SEPARATOR) {
  355. gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
  356. toolbar_item->file = g_strdup(file);
  357. toolbar_item->index = default_toolbar[i].action;
  358. toolbar_item->text = g_strdup(default_toolbar[i].text);
  359. } else {
  360. toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
  361. toolbar_item->index = A_SEPARATOR;
  362. }
  363. if (toolbar_item->index != -1) {
  364. if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
  365. toolbar_config[TOOLBAR_MAIN].item_list =
  366. g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
  367. }
  368. }
  369. }
  370. static void toolbar_set_default_compose(void)
  371. {
  372. struct {
  373. gint action;
  374. gint icon;
  375. gchar *text;
  376. } default_toolbar[] = {
  377. { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
  378. { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
  379. { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
  380. { A_SEPARATOR, 0, ("") },
  381. { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
  382. { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
  383. { A_SEPARATOR, 0, ("") },
  384. { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
  385. };
  386. gint i;
  387. for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
  388. ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
  389. if (default_toolbar[i].action != A_SEPARATOR) {
  390. gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
  391. toolbar_item->file = g_strdup(file);
  392. toolbar_item->index = default_toolbar[i].action;
  393. toolbar_item->text = g_strdup(default_toolbar[i].text);
  394. } else {
  395. toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
  396. toolbar_item->index = A_SEPARATOR;
  397. }
  398. if (toolbar_item->index != -1) {
  399. if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
  400. toolbar_config[TOOLBAR_COMPOSE].item_list =
  401. g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
  402. }
  403. }
  404. }
  405. static void toolbar_set_default_msgview(void)
  406. {
  407. struct {
  408. gint action;
  409. gint icon;
  410. gchar *text;
  411. } default_toolbar[] = {
  412. { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
  413. { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
  414. { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
  415. { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
  416. { A_SEPARATOR, 0, ("") },
  417. { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
  418. #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
  419. { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
  420. #endif
  421. { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
  422. };
  423. gint i;
  424. for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
  425. ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
  426. if (default_toolbar[i].action != A_SEPARATOR) {
  427. gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
  428. toolbar_item->file = g_strdup(file);
  429. toolbar_item->index = default_toolbar[i].action;
  430. toolbar_item->text = g_strdup(default_toolbar[i].text);
  431. } else {
  432. toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
  433. toolbar_item->index = A_SEPARATOR;
  434. }
  435. if (toolbar_item->index != -1) {
  436. if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
  437. toolbar_config[TOOLBAR_MSGVIEW].item_list =
  438. g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
  439. }
  440. }
  441. }
  442. void toolbar_set_default(ToolbarType source)
  443. {
  444. if (source == TOOLBAR_MAIN)
  445. toolbar_set_default_main();
  446. else if (source == TOOLBAR_COMPOSE)
  447. toolbar_set_default_compose();
  448. else if (source == TOOLBAR_MSGVIEW)
  449. toolbar_set_default_msgview();
  450. }
  451. void toolbar_save_config_file(ToolbarType source)
  452. {
  453. GSList *cur;
  454. FILE *fp;
  455. PrefFile *pfile;
  456. gchar *fileSpec = NULL;
  457. debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
  458. fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
  459. pfile = prefs_write_open(fileSpec);
  460. g_free( fileSpec );
  461. if( pfile ) {
  462. fp = pfile->fp;
  463. fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
  464. fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
  465. for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
  466. ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
  467. if (toolbar_item->index != A_SEPARATOR) {
  468. fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
  469. TOOLBAR_TAG_ITEM,
  470. TOOLBAR_ICON_FILE, toolbar_item->file,
  471. TOOLBAR_ICON_TEXT);
  472. xml_file_put_escape_str(fp, toolbar_item->text);
  473. fprintf(fp, "\" %s=\"%s\"/>\n",
  474. TOOLBAR_ICON_ACTION,
  475. toolbar_ret_text_from_val(toolbar_item->index));
  476. } else {
  477. fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
  478. }
  479. }
  480. fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
  481. if (prefs_file_close (pfile) < 0 )
  482. g_warning("failed to write toolbar configuration to file\n");
  483. } else
  484. g_warning("failed to open toolbar configuration file for writing\n");
  485. }
  486. void toolbar_read_config_file(ToolbarType source)
  487. {
  488. XMLFile *file = NULL;
  489. gchar *fileSpec = NULL;
  490. GList *attr;
  491. gboolean retVal;
  492. jmp_buf jumper;
  493. debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
  494. fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
  495. file = xml_open_file(fileSpec);
  496. g_free(fileSpec);
  497. toolbar_clear_list(source);
  498. if (file) {
  499. if ((setjmp(jumper))
  500. || (xml_get_dtd(file))
  501. || (xml_parse_next_tag(file))
  502. || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
  503. xml_close_file(file);
  504. return;
  505. }
  506. attr = xml_get_current_tag_attr(file);
  507. retVal = TRUE;
  508. for (;;) {
  509. if (!file->level)
  510. break;
  511. /* Get item tag */
  512. if (xml_parse_next_tag(file))
  513. longjmp(jumper, 1);
  514. /* Get next tag (icon, icon_text or icon_action) */
  515. if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
  516. toolbar_parse_item(file, source);
  517. } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
  518. ToolbarItem *item = g_new0(ToolbarItem, 1);
  519. item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
  520. item->index = A_SEPARATOR;
  521. toolbar_config[source].item_list =
  522. g_slist_append(toolbar_config[source].item_list, item);
  523. }
  524. }
  525. xml_close_file(file);
  526. }
  527. if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
  528. if (source == TOOLBAR_MAIN)
  529. toolbar_set_default(TOOLBAR_MAIN);
  530. else if (source == TOOLBAR_COMPOSE)
  531. toolbar_set_default(TOOLBAR_COMPOSE);
  532. else if (source == TOOLBAR_MSGVIEW)
  533. toolbar_set_default(TOOLBAR_MSGVIEW);
  534. else {
  535. g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
  536. return;
  537. }
  538. toolbar_save_config_file(source);
  539. }
  540. }
  541. /*
  542. * clears list of toolbar items read from configuration files
  543. */
  544. void toolbar_clear_list(ToolbarType source)
  545. {
  546. while (toolbar_config[source].item_list != NULL) {
  547. ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
  548. toolbar_config[source].item_list =
  549. g_slist_remove(toolbar_config[source].item_list, item);
  550. g_free(item->file);
  551. g_free(item->text);
  552. g_free(item);
  553. }
  554. g_slist_free(toolbar_config[source].item_list);
  555. }
  556. /*
  557. * return list of Toolbar items
  558. */
  559. GSList *toolbar_get_list(ToolbarType source)
  560. {
  561. GSList *list = NULL;
  562. if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
  563. list = toolbar_config[source].item_list;
  564. return list;
  565. }
  566. void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
  567. {
  568. ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
  569. toolbar_item->file = g_strdup(t_item->file);
  570. toolbar_item->text = g_strdup(t_item->text);
  571. toolbar_item->index = t_item->index;
  572. toolbar_config[source].item_list =
  573. g_slist_append(toolbar_config[source].item_list,
  574. toolbar_item);
  575. }
  576. void toolbar_action_execute(GtkWidget *widget,
  577. GSList *action_list,
  578. gpointer data,
  579. gint source)
  580. {
  581. GSList *cur, *lop;
  582. gchar *action, *action_p;
  583. gboolean found = FALSE;
  584. gint i = 0;
  585. for (cur = action_list; cur != NULL; cur = cur->next) {
  586. ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
  587. if (widget == act->widget) {
  588. for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
  589. action = g_strdup((gchar*)lop->data);
  590. action_p = strstr(action, ": ");
  591. action_p[0] = 0x00;
  592. if (g_utf8_collate(act->name, action) == 0) {
  593. found = TRUE;
  594. g_free(action);
  595. break;
  596. } else
  597. i++;
  598. g_free(action);
  599. }
  600. if (found)
  601. break;
  602. }
  603. }
  604. if (found)
  605. actions_execute(data, i, widget, source);
  606. else
  607. g_warning ("Error: did not find Sylpheed Action to execute");
  608. }
  609. static void activate_compose_button (Toolbar *toolbar,
  610. ToolbarStyle style,
  611. ComposeButtonType type)
  612. {
  613. if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
  614. return;
  615. gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
  616. : toolbar->compose_news_btn);
  617. gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
  618. : toolbar->compose_mail_btn);
  619. toolbar->compose_btn_type = type;
  620. }
  621. void toolbar_set_compose_button(Toolbar *toolbar,
  622. ComposeButtonType compose_btn_type)
  623. {
  624. if (toolbar->compose_btn_type != compose_btn_type)
  625. activate_compose_button(toolbar,
  626. prefs_common.toolbar_style,
  627. compose_btn_type);
  628. }
  629. static void activate_learn_button (Toolbar *toolbar,
  630. ToolbarStyle style,
  631. LearnButtonType type)
  632. {
  633. if ((!toolbar->learn_spam_btn) || (!toolbar->learn_ham_btn))
  634. return;
  635. gtk_widget_hide(type == LEARN_SPAM ? toolbar->learn_ham_btn
  636. : toolbar->learn_spam_btn);
  637. gtk_widget_show(type == LEARN_SPAM ? toolbar->learn_spam_btn
  638. : toolbar->learn_ham_btn);
  639. toolbar->learn_btn_type = type;
  640. }
  641. void toolbar_set_learn_button(Toolbar *toolbar,
  642. LearnButtonType learn_btn_type)
  643. {
  644. if (toolbar->learn_btn_type != learn_btn_type)
  645. activate_learn_button(toolbar,
  646. prefs_common.toolbar_style,
  647. learn_btn_type);
  648. }
  649. void toolbar_toggle(guint action, gpointer data)
  650. {
  651. MainWindow *mainwin = (MainWindow*)data;
  652. GList *list;
  653. GList *cur;
  654. g_return_if_fail(mainwin != NULL);
  655. toolbar_style(TOOLBAR_MAIN, action, mainwin);
  656. list = compose_get_compose_list();
  657. for (cur = list; cur != NULL; cur = cur->next) {
  658. toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
  659. }
  660. list = messageview_get_msgview_list();
  661. for (cur = list; cur != NULL; cur = cur->next) {
  662. toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
  663. }
  664. }
  665. void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
  666. {
  667. switch ((ToolbarStyle)action) {
  668. case TOOLBAR_NONE:
  669. gtk_widget_hide(handlebox_wid);
  670. break;
  671. case TOOLBAR_ICON:
  672. gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
  673. GTK_TOOLBAR_ICONS);
  674. break;
  675. case TOOLBAR_TEXT:
  676. gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
  677. GTK_TOOLBAR_TEXT);
  678. break;
  679. case TOOLBAR_BOTH:
  680. gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
  681. GTK_TOOLBAR_BOTH);
  682. break;
  683. case TOOLBAR_BOTH_HORIZ:
  684. gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
  685. GTK_TOOLBAR_BOTH_HORIZ);
  686. break;
  687. default:
  688. return;
  689. }
  690. prefs_common.toolbar_style = (ToolbarStyle)action;
  691. gtk_widget_set_size_request(handlebox_wid, 1, -1);
  692. if (prefs_common.toolbar_style != TOOLBAR_NONE) {
  693. gtk_widget_show(handlebox_wid);
  694. gtk_widget_queue_resize(handlebox_wid);
  695. }
  696. }
  697. /*
  698. * Change the style of toolbar
  699. */
  700. static void toolbar_style(ToolbarType type, guint action, gpointer data)
  701. {
  702. GtkWidget *handlebox_wid;
  703. GtkWidget *toolbar_wid;
  704. MainWindow *mainwin = (MainWindow*)data;
  705. Compose *compose = (Compose*)data;
  706. MessageView *msgview = (MessageView*)data;
  707. g_return_if_fail(data != NULL);
  708. switch (type) {
  709. case TOOLBAR_MAIN:
  710. handlebox_wid = mainwin->handlebox;
  711. toolbar_wid = mainwin->toolbar->toolbar;
  712. break;
  713. case TOOLBAR_COMPOSE:
  714. handlebox_wid = compose->handlebox;
  715. toolbar_wid = compose->toolbar->toolbar;
  716. break;
  717. case TOOLBAR_MSGVIEW:
  718. handlebox_wid = msgview->handlebox;
  719. toolbar_wid = msgview->toolbar->toolbar;
  720. break;
  721. default:
  722. return;
  723. }
  724. toolbar_set_style(toolbar_wid, handlebox_wid, action);
  725. }
  726. /* Toolbar handling */
  727. static void toolbar_inc_cb(GtkWidget *widget,
  728. gpointer data)
  729. {
  730. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  731. MainWindow *mainwin;
  732. g_return_if_fail(toolbar_item != NULL);
  733. switch (toolbar_item->type) {
  734. case TOOLBAR_MAIN:
  735. mainwin = (MainWindow*)toolbar_item->parent;
  736. inc_mail_cb(mainwin, 0, NULL);
  737. break;
  738. default:
  739. break;
  740. }
  741. }
  742. static void toolbar_inc_all_cb(GtkWidget *widget,
  743. gpointer data)
  744. {
  745. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  746. MainWindow *mainwin;
  747. g_return_if_fail(toolbar_item != NULL);
  748. switch (toolbar_item->type) {
  749. case TOOLBAR_MAIN:
  750. mainwin = (MainWindow*)toolbar_item->parent;
  751. inc_all_account_mail_cb(mainwin, 0, NULL);
  752. break;
  753. default:
  754. break;
  755. }
  756. }
  757. static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
  758. {
  759. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  760. MainWindow *mainwin;
  761. g_return_if_fail(toolbar_item != NULL);
  762. switch (toolbar_item->type) {
  763. case TOOLBAR_MAIN:
  764. mainwin = (MainWindow*)toolbar_item->parent;
  765. send_queue_cb(mainwin, 0, NULL);
  766. break;
  767. default:
  768. break;
  769. }
  770. }
  771. static void toolbar_exec_cb(GtkWidget *widget,
  772. gpointer data)
  773. {
  774. MainWindow *mainwin = get_mainwin(data);
  775. g_return_if_fail(mainwin != NULL);
  776. summary_execute(mainwin->summaryview);
  777. }
  778. /*
  779. * Delete current/selected(s) message(s)
  780. */
  781. static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
  782. {
  783. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  784. MainWindow *mainwin;
  785. g_return_if_fail(toolbar_item != NULL);
  786. g_return_if_fail(toolbar_item->parent);
  787. switch (toolbar_item->type) {
  788. case TOOLBAR_MSGVIEW:
  789. messageview_delete((MessageView *)toolbar_item->parent);
  790. break;
  791. case TOOLBAR_MAIN:
  792. mainwin = (MainWindow *)toolbar_item->parent;
  793. summary_delete_trash(mainwin->summaryview);
  794. break;
  795. default:
  796. debug_print("toolbar event not supported\n");
  797. break;
  798. }
  799. }
  800. /*
  801. * Delete current/selected(s) message(s)
  802. */
  803. static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
  804. {
  805. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  806. MainWindow *mainwin;
  807. g_return_if_fail(toolbar_item != NULL);
  808. g_return_if_fail(toolbar_item->parent);
  809. switch (toolbar_item->type) {
  810. case TOOLBAR_MSGVIEW:
  811. messageview_delete((MessageView *)toolbar_item->parent);
  812. break;
  813. case TOOLBAR_MAIN:
  814. mainwin = (MainWindow *)toolbar_item->parent;
  815. summary_delete(mainwin->summaryview);
  816. break;
  817. default:
  818. debug_print("toolbar event not supported\n");
  819. break;
  820. }
  821. }
  822. /*
  823. * Compose new message
  824. */
  825. static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
  826. {
  827. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  828. MainWindow *mainwin;
  829. MessageView *msgview;
  830. g_return_if_fail(toolbar_item != NULL);
  831. switch (toolbar_item->type) {
  832. case TOOLBAR_MAIN:
  833. mainwin = (MainWindow*)toolbar_item->parent;
  834. if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
  835. compose_news_cb(mainwin, 0, NULL);
  836. else
  837. compose_mail_cb(mainwin, 0, NULL);
  838. break;
  839. case TOOLBAR_MSGVIEW:
  840. msgview = (MessageView*)toolbar_item->parent;
  841. compose_new_with_folderitem(NULL,
  842. msgview->msginfo->folder, NULL);
  843. break;
  844. default:
  845. debug_print("toolbar event not supported\n");
  846. }
  847. }
  848. static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
  849. {
  850. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  851. MainWindow *mainwin;
  852. MessageView *msgview;
  853. g_return_if_fail(toolbar_item != NULL);
  854. switch (toolbar_item->type) {
  855. case TOOLBAR_MAIN:
  856. mainwin = (MainWindow*)toolbar_item->parent;
  857. if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
  858. mainwindow_learn(mainwin, TRUE);
  859. else
  860. mainwindow_learn(mainwin, FALSE);
  861. break;
  862. case TOOLBAR_MSGVIEW:
  863. msgview = (MessageView*)toolbar_item->parent;
  864. if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
  865. messageview_learn(msgview, TRUE);
  866. else
  867. messageview_learn(msgview, FALSE);
  868. break;
  869. default:
  870. debug_print("toolbar event not supported\n");
  871. }
  872. }
  873. /*
  874. * Reply Message
  875. */
  876. static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
  877. {
  878. toolbar_reply(data, prefs_common.reply_with_quote ?
  879. COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
  880. }
  881. /*
  882. * Reply message to Sender and All recipients
  883. */
  884. static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
  885. {
  886. toolbar_reply(data,
  887. prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
  888. : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
  889. }
  890. /*
  891. * Reply to Mailing List
  892. */
  893. static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
  894. {
  895. toolbar_reply(data,
  896. prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
  897. : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
  898. }
  899. /*
  900. * Reply to sender of message
  901. */
  902. static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
  903. {
  904. toolbar_reply(data,
  905. prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
  906. : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
  907. }
  908. /*
  909. * Open addressbook
  910. */
  911. static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
  912. {
  913. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  914. Compose *compose;
  915. g_return_if_fail(toolbar_item != NULL);
  916. switch (toolbar_item->type) {
  917. case TOOLBAR_MAIN:
  918. case TOOLBAR_MSGVIEW:
  919. compose = NULL;
  920. break;
  921. case TOOLBAR_COMPOSE:
  922. compose = (Compose *)toolbar_item->parent;
  923. break;
  924. default:
  925. return;
  926. }
  927. addressbook_open(compose);
  928. }
  929. /*
  930. * Forward current/selected(s) message(s)
  931. */
  932. static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
  933. {
  934. toolbar_reply(data, COMPOSE_FORWARD);
  935. }
  936. /*
  937. * Goto Prev Unread Message
  938. */
  939. static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
  940. {
  941. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  942. MainWindow *mainwin;
  943. MessageView *msgview;
  944. g_return_if_fail(toolbar_item != NULL);
  945. switch (toolbar_item->type) {
  946. case TOOLBAR_MAIN:
  947. mainwin = (MainWindow*)toolbar_item->parent;
  948. summary_select_prev_unread(mainwin->summaryview);
  949. break;
  950. case TOOLBAR_MSGVIEW:
  951. msgview = (MessageView*)toolbar_item->parent;
  952. msgview->updating = TRUE;
  953. summary_select_prev_unread(msgview->mainwin->summaryview);
  954. msgview->updating = FALSE;
  955. if (msgview->deferred_destroy) {
  956. debug_print("messageview got away!\n");
  957. messageview_destroy(msgview);
  958. return;
  959. }
  960. /* Now we need to update the messageview window */
  961. if (msgview->mainwin->summaryview->selected) {
  962. MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
  963. if (msginfo)
  964. messageview_show(msgview, msginfo,
  965. msgview->all_headers);
  966. } else {
  967. gtk_widget_destroy(msgview->window);
  968. }
  969. break;
  970. default:
  971. debug_print("toolbar event not supported\n");
  972. }
  973. }
  974. /*
  975. * Goto Next Unread Message
  976. */
  977. static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
  978. {
  979. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  980. MainWindow *mainwin;
  981. MessageView *msgview;
  982. g_return_if_fail(toolbar_item != NULL);
  983. switch (toolbar_item->type) {
  984. case TOOLBAR_MAIN:
  985. mainwin = (MainWindow*)toolbar_item->parent;
  986. summary_select_next_unread(mainwin->summaryview);
  987. break;
  988. case TOOLBAR_MSGVIEW:
  989. msgview = (MessageView*)toolbar_item->parent;
  990. msgview->updating = TRUE;
  991. summary_select_next_unread(msgview->mainwin->summaryview);
  992. msgview->updating = FALSE;
  993. if (msgview->deferred_destroy) {
  994. debug_print("messageview got away!\n");
  995. messageview_destroy(msgview);
  996. return;
  997. }
  998. /* Now we need to update the messageview window */
  999. if (msgview->mainwin->summaryview->selected) {
  1000. MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
  1001. if (msginfo)
  1002. messageview_show(msgview, msginfo,
  1003. msgview->all_headers);
  1004. } else {
  1005. gtk_widget_destroy(msgview->window);
  1006. }
  1007. break;
  1008. default:
  1009. debug_print("toolbar event not supported\n");
  1010. }
  1011. }
  1012. static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
  1013. {
  1014. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  1015. MainWindow *mainwin;
  1016. g_return_if_fail(toolbar_item != NULL);
  1017. switch (toolbar_item->type) {
  1018. case TOOLBAR_MAIN:
  1019. mainwin = (MainWindow *) toolbar_item->parent;
  1020. summary_toggle_ignore_thread(mainwin->summaryview);
  1021. break;
  1022. case TOOLBAR_MSGVIEW:
  1023. /* TODO: see toolbar_next_unread_cb() if you need
  1024. * this in the message view */
  1025. break;
  1026. default:
  1027. debug_print("toolbar event not supported\n");
  1028. break;
  1029. }
  1030. }
  1031. static void toolbar_print_cb(GtkWidget *widget, gpointer data)
  1032. {
  1033. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  1034. MainWindow *mainwin;
  1035. g_return_if_fail(toolbar_item != NULL);
  1036. switch (toolbar_item->type) {
  1037. case TOOLBAR_MAIN:
  1038. mainwin = (MainWindow *) toolbar_item->parent;
  1039. summary_print(mainwin->summaryview);
  1040. break;
  1041. case TOOLBAR_MSGVIEW:
  1042. /* TODO: see toolbar_next_unread_cb() if you need
  1043. * this in the message view */
  1044. break;
  1045. default:
  1046. debug_print("toolbar event not supported\n");
  1047. break;
  1048. }
  1049. }
  1050. static void toolbar_send_cb(GtkWidget *widget, gpointer data)
  1051. {
  1052. compose_toolbar_cb(A_SEND, data);
  1053. }
  1054. static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
  1055. {
  1056. compose_toolbar_cb(A_SENDL, data);
  1057. }
  1058. static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
  1059. {
  1060. compose_toolbar_cb(A_DRAFT, data);
  1061. }
  1062. static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
  1063. {
  1064. compose_toolbar_cb(A_INSERT, data);
  1065. }
  1066. static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
  1067. {
  1068. compose_toolbar_cb(A_ATTACH, data);
  1069. }
  1070. static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
  1071. {
  1072. compose_toolbar_cb(A_SIG, data);
  1073. }
  1074. static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
  1075. {
  1076. compose_toolbar_cb(A_EXTEDITOR, data);
  1077. }
  1078. static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
  1079. {
  1080. compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
  1081. }
  1082. static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
  1083. {
  1084. compose_toolbar_cb(A_LINEWRAP_ALL, data);
  1085. }
  1086. #ifdef USE_ASPELL
  1087. static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
  1088. {
  1089. compose_toolbar_cb(A_CHECK_SPELLING, data);
  1090. }
  1091. #endif
  1092. /*
  1093. * Execute actions from toolbar
  1094. */
  1095. static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
  1096. {
  1097. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  1098. GSList *action_list;
  1099. MainWindow *mainwin;
  1100. Compose *compose;
  1101. MessageView *msgview;
  1102. gpointer parent = toolbar_item->parent;
  1103. g_return_if_fail(toolbar_item != NULL);
  1104. switch (toolbar_item->type) {
  1105. case TOOLBAR_MAIN:
  1106. mainwin = (MainWindow*)parent;
  1107. action_list = mainwin->toolbar->action_list;
  1108. break;
  1109. case TOOLBAR_COMPOSE:
  1110. compose = (Compose*)parent;
  1111. action_list = compose->toolbar->action_list;
  1112. break;
  1113. case TOOLBAR_MSGVIEW:
  1114. msgview = (MessageView*)parent;
  1115. action_list = msgview->toolbar->action_list;
  1116. break;
  1117. default:
  1118. debug_print("toolbar event not supported\n");
  1119. return;
  1120. }
  1121. toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
  1122. }
  1123. static MainWindow *get_mainwin(gpointer data)
  1124. {
  1125. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  1126. MainWindow *mainwin = NULL;
  1127. MessageView *msgview;
  1128. g_return_val_if_fail(toolbar_item != NULL, NULL);
  1129. switch(toolbar_item->type) {
  1130. case TOOLBAR_MAIN:
  1131. mainwin = (MainWindow*)toolbar_item->parent;
  1132. break;
  1133. case TOOLBAR_MSGVIEW:
  1134. msgview = (MessageView*)toolbar_item->parent;
  1135. mainwin = (MainWindow*)msgview->mainwin;
  1136. break;
  1137. default:
  1138. break;
  1139. }
  1140. return mainwin;
  1141. }
  1142. static void toolbar_buttons_cb(GtkWidget *widget,
  1143. ToolbarItem *item)
  1144. {
  1145. gint num_items;
  1146. gint i;
  1147. struct {
  1148. gint index;
  1149. void (*func)(GtkWidget *widget, gpointer data);
  1150. } callbacks[] = {
  1151. { A_RECEIVE_ALL, toolbar_inc_all_cb },
  1152. { A_RECEIVE_CUR, toolbar_inc_cb },
  1153. { A_SEND_QUEUED, toolbar_send_queued_cb },
  1154. { A_COMPOSE_EMAIL, toolbar_compose_cb },
  1155. { A_COMPOSE_NEWS, toolbar_compose_cb },
  1156. { A_REPLY_MESSAGE, toolbar_reply_cb },
  1157. { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
  1158. { A_REPLY_ALL, toolbar_reply_to_all_cb },
  1159. { A_REPLY_ML, toolbar_reply_to_list_cb },
  1160. { A_FORWARD, toolbar_forward_cb },
  1161. { A_TRASH, toolbar_trash_cb },
  1162. { A_DELETE_REAL, toolbar_delete_cb },
  1163. { A_EXECUTE, toolbar_exec_cb },
  1164. { A_GOTO_PREV, toolbar_prev_unread_cb },
  1165. { A_GOTO_NEXT, toolbar_next_unread_cb },
  1166. { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
  1167. { A_PRINT, toolbar_print_cb },
  1168. { A_LEARN_SPAM, toolbar_learn_cb },
  1169. { A_SEND, toolbar_send_cb },
  1170. { A_SENDL, toolbar_send_later_cb },
  1171. { A_DRAFT, toolbar_draft_cb },
  1172. { A_INSERT, toolbar_insert_cb },
  1173. { A_ATTACH, toolbar_attach_cb },
  1174. { A_SIG, toolbar_sig_cb },
  1175. { A_EXTEDITOR, toolbar_ext_editor_cb },
  1176. { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
  1177. { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
  1178. { A_ADDRBOOK, toolbar_addrbook_cb },
  1179. #ifdef USE_ASPELL
  1180. { A_CHECK_SPELLING, toolbar_check_spelling_cb },
  1181. #endif
  1182. { A_SYL_ACTIONS, toolbar_actions_execute_cb }
  1183. };
  1184. num_items = sizeof(callbacks)/sizeof(callbacks[0]);
  1185. for (i = 0; i < num_items; i++) {
  1186. if (callbacks[i].index == item->index) {
  1187. callbacks[i].func(widget, item);
  1188. return;
  1189. }
  1190. }
  1191. }
  1192. /**
  1193. * Create a new toolbar with specified type
  1194. * if a callback list is passed it will be used before the
  1195. * common callback list
  1196. **/
  1197. Toolbar *toolbar_create(ToolbarType type,
  1198. GtkWidget *container,
  1199. gpointer data)
  1200. {
  1201. ToolbarItem *toolbar_item;
  1202. GtkWidget *toolbar;
  1203. GtkWidget *icon_wid = NULL;
  1204. GtkWidget *icon_news;
  1205. GtkWidget *icon_ham;
  1206. GtkWidget *item;
  1207. GtkWidget *item_news;
  1208. GtkWidget *item_ham;
  1209. guint n_menu_entries;
  1210. ComboButton *getall_combo;
  1211. ComboButton *reply_combo;
  1212. ComboButton *replyall_combo;
  1213. ComboButton *replylist_combo;
  1214. ComboButton *replysender_combo;
  1215. ComboButton *fwd_combo;
  1216. ComboButton *compose_combo;
  1217. GtkTooltips *toolbar_tips;
  1218. ToolbarSylpheedActions *action_item;
  1219. GSList *cur;
  1220. GSList *toolbar_list;
  1221. Toolbar *toolbar_data;
  1222. toolbar_tips = gtk_tooltips_new();
  1223. toolbar_read_config_file(type);
  1224. toolbar_list = toolbar_get_list(type);
  1225. toolbar_data = g_new0(Toolbar, 1);
  1226. toolbar = gtk_toolbar_new();
  1227. gtk_container_add(GTK_CONTAINER(container), toolbar);
  1228. gtk_container_set_border_width(GTK_CONTAINER(container), 2);
  1229. gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
  1230. gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
  1231. for (cur = toolbar_list; cur != NULL; cur = cur->next) {
  1232. if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
  1233. gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  1234. continue;
  1235. }
  1236. toolbar_item = g_new0(ToolbarItem, 1);
  1237. toolbar_item->index = ((ToolbarItem*)cur->data)->index;
  1238. toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
  1239. toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
  1240. toolbar_item->parent = data;
  1241. toolbar_item->type = type;
  1242. /* collect toolbar items in list to keep track */
  1243. toolbar_data->item_list =
  1244. g_slist_append(toolbar_data->item_list,
  1245. toolbar_item);
  1246. icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
  1247. item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
  1248. toolbar_item->text,
  1249. (""),
  1250. (""),
  1251. icon_wid, G_CALLBACK(toolbar_buttons_cb),
  1252. toolbar_item);
  1253. switch (toolbar_item->index) {
  1254. case A_RECEIVE_ALL:
  1255. toolbar_data->getall_btn = item;
  1256. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1257. toolbar_data->getall_btn,
  1258. _("Receive Mail on all Accounts"), NULL);
  1259. getall_combo = gtkut_combo_button_create(toolbar_data->getall_btn, NULL, 0,
  1260. "<GetAll>", (gpointer)toolbar_item);
  1261. gtk_button_set_relief(GTK_BUTTON(getall_combo->arrow),
  1262. GTK_RELIEF_NONE);
  1263. gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
  1264. GTK_WIDGET_PTR(getall_combo),
  1265. _("Receive Mail on selected Account"), "Reply");
  1266. toolbar_data->getall_combo = getall_combo;
  1267. break;
  1268. case A_RECEIVE_CUR:
  1269. toolbar_data->get_btn = item;
  1270. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1271. toolbar_data->get_btn,
  1272. _("Receive Mail on current Account"), NULL);
  1273. break;
  1274. case A_SEND_QUEUED:
  1275. toolbar_data->send_btn = item;
  1276. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1277. toolbar_data->send_btn,
  1278. _("Send Queued Messages"), NULL);
  1279. break;
  1280. case A_COMPOSE_EMAIL:
  1281. icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
  1282. item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
  1283. _("Compose"),
  1284. (""),
  1285. (""),
  1286. icon_news, G_CALLBACK(toolbar_buttons_cb),
  1287. toolbar_item);
  1288. toolbar_data->compose_mail_btn = item;
  1289. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1290. toolbar_data->compose_mail_btn,
  1291. _("Compose Email"), NULL);
  1292. toolbar_data->compose_news_btn = item_news;
  1293. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1294. toolbar_data->compose_news_btn,
  1295. _("Compose News"), NULL);
  1296. compose_combo = gtkut_combo_button_create(toolbar_data->compose_mail_btn, NULL, 0,
  1297. "<Compose>", (gpointer)toolbar_item);
  1298. gtk_button_set_relief(GTK_BUTTON(compose_combo->arrow),
  1299. GTK_RELIEF_NONE);
  1300. gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
  1301. GTK_WIDGET_PTR(compose_combo),
  1302. _("Compose with selected Account"), "Compose");
  1303. toolbar_data->compose_combo = compose_combo;
  1304. break;
  1305. case A_LEARN_SPAM:
  1306. icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
  1307. item_ham = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
  1308. _("Ham"),
  1309. (""),
  1310. (""),
  1311. icon_ham, G_CALLBACK(toolbar_buttons_cb),
  1312. toolbar_item);
  1313. toolbar_data->learn_spam_btn = item;
  1314. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1315. toolbar_data->learn_spam_btn,
  1316. _("Learn Spam"), NULL);
  1317. toolbar_data->learn_ham_btn = item_ham;
  1318. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1319. toolbar_data->learn_ham_btn,
  1320. _("Learn Ham"), NULL);
  1321. break;
  1322. case A_REPLY_MESSAGE:
  1323. toolbar_data->reply_btn = item;
  1324. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1325. toolbar_data->reply_btn,
  1326. _("Reply to Message"), NULL);
  1327. n_menu_entries = sizeof(reply_entries) /
  1328. sizeof(reply_entries[0]);
  1329. reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
  1330. reply_entries, n_menu_entries,
  1331. "<Reply>", (gpointer)toolbar_item);
  1332. gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
  1333. GTK_RELIEF_NONE);
  1334. gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
  1335. GTK_WIDGET_PTR(reply_combo),
  1336. _("Reply to Message"), "Reply");
  1337. toolbar_data->reply_combo = reply_combo;
  1338. break;
  1339. case A_REPLY_SENDER:
  1340. toolbar_data->replysender_btn = item;
  1341. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1342. toolbar_data->replysender_btn,
  1343. _("Reply to Sender"), NULL);
  1344. n_menu_entries = sizeof(replysender_entries) /
  1345. sizeof(replysender_entries[0]);
  1346. replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
  1347. replysender_entries, n_menu_entries,
  1348. "<ReplySender>", (gpointer)toolbar_item);
  1349. gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
  1350. GTK_RELIEF_NONE);
  1351. gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
  1352. GTK_WIDGET_PTR(replysender_combo),
  1353. _("Reply to Sender"), "ReplySender");
  1354. toolbar_data->replysender_combo = replysender_combo;
  1355. break;
  1356. case A_REPLY_ALL:
  1357. toolbar_data->replyall_btn = item;
  1358. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1359. toolbar_data->replyall_btn,
  1360. _("Reply to All"), NULL);
  1361. n_menu_entries = sizeof(replyall_entries) /
  1362. sizeof(replyall_entries[0]);
  1363. replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
  1364. replyall_entries, n_menu_entries,
  1365. "<ReplyAll>", (gpointer)toolbar_item);
  1366. gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
  1367. GTK_RELIEF_NONE);
  1368. gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
  1369. GTK_WIDGET_PTR(replyall_combo),
  1370. _("Reply to All"), "ReplyAll");
  1371. toolbar_data->replyall_combo = replyall_combo;
  1372. break;
  1373. case A_REPLY_ML:
  1374. toolbar_data->replylist_btn = item;
  1375. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1376. toolbar_data->replylist_btn,
  1377. _("Reply to Mailing-list"), NULL);
  1378. n_menu_entries = sizeof(replylist_entries) /
  1379. sizeof(replylist_entries[0]);
  1380. replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
  1381. replylist_entries, n_menu_entries,
  1382. "<ReplyList>", (gpointer)toolbar_item);
  1383. gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
  1384. GTK_RELIEF_NONE);
  1385. gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
  1386. GTK_WIDGET_PTR(replylist_combo),
  1387. _("Reply to Mailing-list"), "ReplyList");
  1388. toolbar_data->replylist_combo = replylist_combo;
  1389. break;
  1390. case A_FORWARD:
  1391. toolbar_data->fwd_btn = item;
  1392. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1393. toolbar_data->fwd_btn,
  1394. _("Forward Message"), NULL);
  1395. n_menu_entries = sizeof(forward_entries) /
  1396. sizeof(forward_entries[0]);
  1397. fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
  1398. forward_entries, n_menu_entries,
  1399. "<Forward>", (gpointer)toolbar_item);
  1400. gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
  1401. GTK_RELIEF_NONE);
  1402. gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
  1403. GTK_WIDGET_PTR(fwd_combo),
  1404. _("Forward Message"), "Fwd");
  1405. toolbar_data->fwd_combo = fwd_combo;
  1406. break;
  1407. case A_TRASH:
  1408. toolbar_data->trash_btn = item;
  1409. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1410. toolbar_data->trash_btn,
  1411. _("Trash Message"), NULL);
  1412. break;
  1413. case A_DELETE_REAL:
  1414. toolbar_data->delete_btn = item;
  1415. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1416. toolbar_data->delete_btn,
  1417. _("Delete Message"), NULL);
  1418. break;
  1419. case A_EXECUTE:
  1420. toolbar_data->exec_btn = item;
  1421. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1422. toolbar_data->exec_btn,
  1423. _("Execute"), NULL);
  1424. break;
  1425. case A_GOTO_PREV:
  1426. toolbar_data->prev_btn = item;
  1427. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1428. toolbar_data->prev_btn,
  1429. _("Go to Previous Unread Message"),
  1430. NULL);
  1431. break;
  1432. case A_GOTO_NEXT:
  1433. toolbar_data->next_btn = item;
  1434. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1435. toolbar_data->next_btn,
  1436. _("Go to Next Unread Message"),
  1437. NULL);
  1438. break;
  1439. /* Compose Toolbar */
  1440. case A_SEND:
  1441. toolbar_data->send_btn = item;
  1442. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1443. toolbar_data->send_btn,
  1444. _("Send Message"), NULL);
  1445. break;
  1446. case A_SENDL:
  1447. toolbar_data->sendl_btn = item;
  1448. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1449. toolbar_data->sendl_btn,
  1450. _("Put into queue folder and send later"), NULL);
  1451. break;
  1452. case A_DRAFT:
  1453. toolbar_data->draft_btn = item;
  1454. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1455. toolbar_data->draft_btn,
  1456. _("Save to draft folder"), NULL);
  1457. break;
  1458. case A_INSERT:
  1459. toolbar_data->insert_btn = item;
  1460. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1461. toolbar_data->insert_btn,
  1462. _("Insert file"), NULL);
  1463. break;
  1464. case A_ATTACH:
  1465. toolbar_data->attach_btn = item;
  1466. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1467. toolbar_data->attach_btn,
  1468. _("Attach file"), NULL);
  1469. break;
  1470. case A_SIG:
  1471. toolbar_data->sig_btn = item;
  1472. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1473. toolbar_data->sig_btn,
  1474. _("Insert signature"), NULL);
  1475. break;
  1476. case A_EXTEDITOR:
  1477. toolbar_data->exteditor_btn = item;
  1478. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1479. toolbar_data->exteditor_btn,
  1480. _("Edit with external editor"), NULL);
  1481. break;
  1482. case A_LINEWRAP_CURRENT:
  1483. toolbar_data->linewrap_current_btn = item;
  1484. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1485. toolbar_data->linewrap_current_btn,
  1486. _("Wrap long lines of current paragraph"), NULL);
  1487. break;
  1488. case A_LINEWRAP_ALL:
  1489. toolbar_data->linewrap_all_btn = item;
  1490. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1491. toolbar_data->linewrap_all_btn,
  1492. _("Wrap all long lines"), NULL);
  1493. break;
  1494. case A_ADDRBOOK:
  1495. toolbar_data->addrbook_btn = item;
  1496. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1497. toolbar_data->addrbook_btn,
  1498. _("Address book"), NULL);
  1499. break;
  1500. #ifdef USE_ASPELL
  1501. case A_CHECK_SPELLING:
  1502. toolbar_data->spellcheck_btn = item;
  1503. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1504. toolbar_data->spellcheck_btn,
  1505. _("Check spelling"), NULL);
  1506. break;
  1507. #endif
  1508. case A_SYL_ACTIONS:
  1509. action_item = g_new0(ToolbarSylpheedActions, 1);
  1510. action_item->widget = item;
  1511. action_item->name = g_strdup(toolbar_item->text);
  1512. toolbar_data->action_list =
  1513. g_slist_append(toolbar_data->action_list,
  1514. action_item);
  1515. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1516. item,
  1517. action_item->name, NULL);
  1518. gtk_widget_show(item);
  1519. break;
  1520. default:
  1521. /* find and set the tool tip text */
  1522. gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
  1523. item,
  1524. toolbar_ret_descr_from_val
  1525. (toolbar_item->index),
  1526. NULL);
  1527. break;
  1528. }
  1529. }
  1530. toolbar_data->toolbar = toolbar;
  1531. if (type == TOOLBAR_MAIN)
  1532. activate_compose_button(toolbar_data,
  1533. prefs_common.toolbar_style,
  1534. toolbar_data->compose_btn_type);
  1535. if (type != TOOLBAR_COMPOSE)
  1536. activate_learn_button(toolbar_data, prefs_common.toolbar_style,
  1537. LEARN_SPAM);
  1538. gtk_widget_show_all(toolbar);
  1539. return toolbar_data;
  1540. }
  1541. /**
  1542. * Free toolbar structures
  1543. */
  1544. void toolbar_destroy(Toolbar * toolbar) {
  1545. TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
  1546. TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
  1547. }
  1548. void toolbar_update(ToolbarType type, gpointer data)
  1549. {
  1550. Toolbar *toolbar_data;
  1551. GtkWidget *handlebox;
  1552. MainWindow *mainwin = (MainWindow*)data;
  1553. Compose *compose = (Compose*)data;
  1554. MessageView *msgview = (MessageView*)data;
  1555. switch(type) {
  1556. case TOOLBAR_MAIN:
  1557. toolbar_data = mainwin->toolbar;
  1558. handlebox = mainwin->handlebox;
  1559. break;
  1560. case TOOLBAR_COMPOSE:
  1561. toolbar_data = compose->toolbar;
  1562. handlebox = compose->handlebox;
  1563. break;
  1564. case TOOLBAR_MSGVIEW:
  1565. toolbar_data = msgview->toolbar;
  1566. handlebox = msgview->handlebox;
  1567. break;
  1568. default:
  1569. return;
  1570. }
  1571. gtk_container_remove(GTK_CONTAINER(handlebox),
  1572. GTK_WIDGET(toolbar_data->toolbar));
  1573. toolbar_init(toolbar_data);
  1574. toolbar_data = toolbar_create(type, handlebox, data);
  1575. switch(type) {
  1576. case TOOLBAR_MAIN:
  1577. mainwin->toolbar = toolbar_data;
  1578. break;
  1579. case TOOLBAR_COMPOSE:
  1580. compose->toolbar = toolbar_data;
  1581. break;
  1582. case TOOLBAR_MSGVIEW:
  1583. msgview->toolbar = toolbar_data;
  1584. break;
  1585. }
  1586. toolbar_style(type, prefs_common.toolbar_style, data);
  1587. if (type == TOOLBAR_MAIN) {
  1588. toolbar_main_set_sensitive((MainWindow*)data);
  1589. account_set_menu_only_toolbar();
  1590. }
  1591. }
  1592. #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
  1593. gboolean in_btn = FALSE; \
  1594. if (GTK_IS_BUTTON(widget)) \
  1595. in_btn = GTK_BUTTON(widget)->in_button; \
  1596. gtk_widget_set_sensitive(widget, sensitive); \
  1597. if (GTK_IS_BUTTON(widget)) \
  1598. GTK_BUTTON(widget)->in_button = in_btn; \
  1599. }
  1600. void toolbar_main_set_sensitive(gpointer data)
  1601. {
  1602. SensitiveCond state;
  1603. gboolean sensitive;
  1604. MainWindow *mainwin = (MainWindow*)data;
  1605. Toolbar *toolbar = mainwin->toolbar;
  1606. GSList *cur;
  1607. GSList *entry_list = NULL;
  1608. typedef struct _Entry Entry;
  1609. struct _Entry {
  1610. GtkWidget *widget;
  1611. SensitiveCond cond;
  1612. gboolean empty;
  1613. };
  1614. #define SET_WIDGET_COND(w, c) \
  1615. { \
  1616. Entry *e = g_new0(Entry, 1); \
  1617. e->widget = w; \
  1618. e->cond = c; \
  1619. entry_list = g_slist_append(entry_list, e); \
  1620. }
  1621. if (toolbar->get_btn)
  1622. SET_WIDGET_COND(toolbar->get_btn,
  1623. M_HAVE_ACCOUNT|M_UNLOCKED);
  1624. if (toolbar->getall_btn) {
  1625. SET_WIDGET_COND(toolbar->getall_btn,
  1626. M_HAVE_ACCOUNT|M_UNLOCKED);
  1627. SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->getall_combo),
  1628. M_HAVE_ACCOUNT|M_UNLOCKED);
  1629. }
  1630. if (toolbar->send_btn) {
  1631. SET_WIDGET_COND(toolbar->send_btn,
  1632. M_HAVE_QUEUED_MAILS);
  1633. }
  1634. if (toolbar->compose_mail_btn) {
  1635. SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->compose_combo),
  1636. M_HAVE_ACCOUNT);
  1637. SET_WIDGET_COND(toolbar->compose_news_btn,
  1638. M_HAVE_ACCOUNT);
  1639. }
  1640. if (toolbar->reply_btn) {
  1641. SET_WIDGET_COND(toolbar->reply_btn,
  1642. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1643. SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
  1644. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1645. }
  1646. if (toolbar->replyall_btn) {
  1647. SET_WIDGET_COND(toolbar->replyall_btn,
  1648. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1649. SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
  1650. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1651. }
  1652. if (toolbar->replylist_btn) {
  1653. SET_WIDGET_COND(toolbar->replylist_btn,
  1654. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1655. SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
  1656. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1657. }
  1658. if (toolbar->replysender_btn) {
  1659. SET_WIDGET_COND(toolbar->replysender_btn,
  1660. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1661. SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
  1662. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1663. }
  1664. if (toolbar->fwd_btn) {
  1665. SET_WIDGET_COND(toolbar->fwd_btn,
  1666. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1667. SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
  1668. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1669. }
  1670. if (toolbar->fwd_combo) {
  1671. GtkWidget *submenu = gtk_item_factory_get_widget(toolbar->fwd_combo->factory, "/Redirect");
  1672. SET_WIDGET_COND(submenu,
  1673. M_HAVE_ACCOUNT|M_TARGET_EXIST);
  1674. }
  1675. if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
  1676. SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
  1677. } else {
  1678. SET_WIDGET_COND(toolbar->next_btn, 0);
  1679. }
  1680. if (toolbar->trash_btn)
  1681. SET_WIDGET_COND(toolbar->trash_btn,
  1682. M_TARGET_EXIST|M_ALLOW_DELETE);
  1683. if (toolbar->delete_btn)
  1684. SET_WIDGET_COND(toolbar->delete_btn,
  1685. M_TARGET_EXIST|M_ALLOW_DELETE);
  1686. if (toolbar->exec_btn)
  1687. SET_WIDGET_COND(toolbar->exec_btn,
  1688. M_DELAY_EXEC);
  1689. if (toolbar->learn_ham_btn)
  1690. SET_WIDGET_COND(toolbar->learn_ham_btn,
  1691. M_TARGET_EXIST|M_CAN_LEARN_SPAM);
  1692. if (toolbar->learn_spam_btn)
  1693. SET_WIDGET_COND(toolbar->learn_spam_btn,
  1694. M_TARGET_EXIST|M_CAN_LEARN_SPAM);
  1695. for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
  1696. ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
  1697. SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
  1698. }
  1699. #undef SET_WIDGET_COND
  1700. state = main_window_get_current_state(mainwin);
  1701. for (cur = entry_list; cur != NULL; cur = cur->next) {
  1702. Entry *e = (Entry*) cur->data;
  1703. if (e->widget != NULL) {
  1704. sensitive = ((e->cond & state) == e->cond);
  1705. GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
  1706. }
  1707. }
  1708. while (entry_list != NULL) {
  1709. Entry *e = (Entry*) entry_list->data;
  1710. g_free(e);
  1711. entry_list = g_slist_remove(entry_list, e);
  1712. }
  1713. g_slist_free(entry_list);
  1714. activate_compose_button(toolbar,
  1715. prefs_common.toolbar_style,
  1716. toolbar->compose_btn_type);
  1717. }
  1718. void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
  1719. {
  1720. Compose *compose = (Compose*)data;
  1721. GSList *items = compose->toolbar->action_list;
  1722. if (compose->toolbar->send_btn)
  1723. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
  1724. if (compose->toolbar->sendl_btn)
  1725. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
  1726. if (compose->toolbar->draft_btn )
  1727. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
  1728. if (compose->toolbar->insert_btn )
  1729. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
  1730. if (compose->toolbar->attach_btn)
  1731. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
  1732. if (compose->toolbar->sig_btn)
  1733. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
  1734. if (compose->toolbar->exteditor_btn)
  1735. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
  1736. if (compose->toolbar->linewrap_current_btn)
  1737. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
  1738. if (compose->toolbar->linewrap_all_btn)
  1739. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
  1740. if (compose->toolbar->addrbook_btn)
  1741. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
  1742. #ifdef USE_ASPELL
  1743. if (compose->toolbar->spellcheck_btn)
  1744. GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
  1745. #endif
  1746. for (; items != NULL; items = g_slist_next(items)) {
  1747. ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
  1748. GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
  1749. }
  1750. }
  1751. /**
  1752. * Initialize toolbar structure
  1753. **/
  1754. void toolbar_init(Toolbar * toolbar) {
  1755. toolbar->toolbar = NULL;
  1756. toolbar->get_btn = NULL;
  1757. toolbar->getall_btn = NULL;
  1758. toolbar->getall_combo = NULL;
  1759. toolbar->send_btn = NULL;
  1760. toolbar->compose_mail_btn = NULL;
  1761. toolbar->compose_news_btn = NULL;
  1762. toolbar->compose_combo = NULL;
  1763. toolbar->reply_btn = NULL;
  1764. toolbar->replysender_btn = NULL;
  1765. toolbar->replyall_btn = NULL;
  1766. toolbar->replylist_btn = NULL;
  1767. toolbar->fwd_btn = NULL;
  1768. toolbar->trash_btn = NULL;
  1769. toolbar->delete_btn = NULL;
  1770. toolbar->prev_btn = NULL;
  1771. toolbar->next_btn = NULL;
  1772. toolbar->exec_btn = NULL;
  1773. /* compose buttons */
  1774. toolbar->sendl_btn = NULL;
  1775. toolbar->draft_btn = NULL;
  1776. toolbar->insert_btn = NULL;
  1777. toolbar->attach_btn = NULL;
  1778. toolbar->sig_btn = NULL;
  1779. toolbar->exteditor_btn = NULL;
  1780. toolbar->linewrap_current_btn = NULL;
  1781. toolbar->linewrap_all_btn = NULL;
  1782. toolbar->addrbook_btn = NULL;
  1783. #ifdef USE_ASPELL
  1784. toolbar->spellcheck_btn = NULL;
  1785. #endif
  1786. toolbar_destroy(toolbar);
  1787. }
  1788. /*
  1789. */
  1790. static void toolbar_reply(gpointer data, guint action)
  1791. {
  1792. ToolbarItem *toolbar_item = (ToolbarItem*)data;
  1793. MainWindow *mainwin;
  1794. MessageView *msgview;
  1795. GSList *msginfo_list = NULL;
  1796. g_return_if_fail(toolbar_item != NULL);
  1797. switch (toolbar_item->type) {
  1798. case TOOLBAR_MAIN:
  1799. mainwin = (MainWindow*)toolbar_item->parent;
  1800. msginfo_list = summary_get_selection(mainwin->summaryview);
  1801. msgview = (MessageView*)mainwin->messageview;
  1802. break;
  1803. case TOOLBAR_MSGVIEW:
  1804. msgview = (MessageView*)toolbar_item->parent;
  1805. g_return_if_fail(msgview != NULL);
  1806. msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
  1807. break;
  1808. default:
  1809. return;
  1810. }
  1811. g_return_if_fail(msgview != NULL);
  1812. g_return_if_fail(msginfo_list != NULL);
  1813. compose_reply_from_messageview(msgview, msginfo_list, action);
  1814. g_slist_free(msginfo_list);
  1815. /* TODO: update reply state ion summaryview */
  1816. }
  1817. /* exported functions */
  1818. void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
  1819. {
  1820. MainWindow *mainwin = (MainWindow*)data;
  1821. inc_mail(mainwin, prefs_common.newmail_notify_manu);
  1822. }
  1823. void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
  1824. {
  1825. MainWindow *mainwin = (MainWindow*)data;
  1826. inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
  1827. }
  1828. void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
  1829. {
  1830. GList *list;
  1831. gboolean found;
  1832. gboolean got_error = FALSE;
  1833. gchar *errstr = NULL;
  1834. if (prefs_common.work_offline)
  1835. if (alertpanel(_("Offline warning"),
  1836. _("You're working offline. Override?"),
  1837. GTK_STOCK_NO, GTK_STOCK_YES,
  1838. NULL) != G_ALERTALTERNATE)
  1839. return;
  1840. /* ask for confirmation before sending queued messages only
  1841. in online mode and if there is at least one message queued
  1842. in any of the folder queue
  1843. */
  1844. if (prefs_common.confirm_send_queued_messages) {
  1845. found = FALSE;
  1846. /* check if there's a queued message */
  1847. for (list = folder_get_list(); !found && list != NULL; list = list->next) {
  1848. Folder *folder = list->data;
  1849. found = !procmsg_queue_is_empty(folder->queue);
  1850. }
  1851. /* if necessary, ask for confirmation before sending */
  1852. if (found && !prefs_common.work_offline) {
  1853. if (alertpanel(_("Send queued messages"),
  1854. _("Send all queued messages?"),
  1855. GTK_STOCK_CANCEL, _("_Send"),
  1856. NULL) != G_ALERTALTERNATE)
  1857. return;
  1858. }
  1859. }
  1860. for (list = folder_get_list(); list != NULL; list = list->next) {
  1861. Folder *folder = list->data;
  1862. if (folder->queue) {
  1863. if (procmsg_send_queue(folder->queue,
  1864. prefs_common.savemsg,
  1865. &errstr) < 0)
  1866. got_error = TRUE;
  1867. }
  1868. }
  1869. if (got_error) {
  1870. if (!errstr)
  1871. alertpanel_error_log(_("Some errors occurred while "
  1872. "sending queued messages."));
  1873. else {
  1874. gchar *tmp = g_strdup_printf(_("Some errors occurred "
  1875. "while sending queued messages:\n%s"), errstr);
  1876. g_free(errstr);
  1877. alertpanel_error_log(tmp);
  1878. g_free(tmp);
  1879. }
  1880. }
  1881. }
  1882. void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
  1883. {
  1884. MainWindow *mainwin = (MainWindow*)data;
  1885. PrefsAccount *ac = NULL;
  1886. FolderItem *item = mainwin->summaryview->folder_item;
  1887. GList * list;
  1888. GList * cur;
  1889. if (item) {
  1890. ac = account_find_from_item(item);
  1891. if (ac && ac->protocol != A_NNTP) {
  1892. compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
  1893. return;
  1894. }
  1895. }
  1896. /*
  1897. * CLAWS - use current account
  1898. */
  1899. if (cur_account && (cur_account->protocol != A_NNTP)) {
  1900. compose_new_with_folderitem(cur_account, item, NULL);
  1901. return;
  1902. }
  1903. /*
  1904. * CLAWS - just get the first one
  1905. */
  1906. list = account_get_list();
  1907. for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
  1908. ac = (PrefsAccount *) cur->data;
  1909. if (ac->protocol != A_NNTP) {
  1910. compose_new_with_folderitem(ac, item, NULL);
  1911. return;
  1912. }
  1913. }
  1914. }
  1915. void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
  1916. {
  1917. MainWindow *mainwin = (MainWindow*)data;
  1918. PrefsAccount * ac = NULL;
  1919. GList * list;
  1920. GList * cur;
  1921. if (mainwin->summaryview->folder_item) {
  1922. ac = mainwin->summaryview->folder_item->folder->account;
  1923. if (ac && ac->protocol == A_NNTP) {
  1924. compose_new_with_folderitem(ac,
  1925. mainwin->summaryview->folder_item, NULL);
  1926. return;
  1927. }
  1928. }
  1929. list = account_get_list();
  1930. for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
  1931. ac = (PrefsAccount *) cur->data;
  1932. if (ac->protocol == A_NNTP) {
  1933. compose_new_with_folderitem(ac,
  1934. mainwin->summaryview->folder_item, NULL);
  1935. return;
  1936. }
  1937. }
  1938. }