exphtmldlg.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
  3. * Copyright (C) 2002-2006 Match Grun 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. * Export address book to HTML file.
  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 <gdk/gdkkeysyms.h>
  29. #include <gtk/gtkwindow.h>
  30. #include <gtk/gtksignal.h>
  31. #include <gtk/gtklabel.h>
  32. #include <gtk/gtkentry.h>
  33. #include <gtk/gtktable.h>
  34. #include <gtk/gtkbutton.h>
  35. #include "gtkutils.h"
  36. #include "prefs_common.h"
  37. #include "alertpanel.h"
  38. #include "mgutils.h"
  39. #include "addrcache.h"
  40. #include "addressitem.h"
  41. #include "exporthtml.h"
  42. #include "utils.h"
  43. #include "manage_window.h"
  44. #include "filesel.h"
  45. #include "combobox.h"
  46. #define PAGE_FILE_INFO 0
  47. #define PAGE_FORMAT 1
  48. #define PAGE_FINISH 2
  49. /**
  50. * Dialog object.
  51. */
  52. static struct _ExpHtml_Dlg {
  53. GtkWidget *window;
  54. GtkWidget *notebook;
  55. GtkWidget *labelBook;
  56. GtkWidget *entryHtml;
  57. GtkWidget *optmenuCSS;
  58. GtkWidget *optmenuName;
  59. GtkWidget *checkBanding;
  60. GtkWidget *checkLinkEMail;
  61. GtkWidget *checkAttributes;
  62. GtkWidget *labelOutBook;
  63. GtkWidget *labelOutFile;
  64. GtkWidget *btnPrev;
  65. GtkWidget *btnNext;
  66. GtkWidget *btnCancel;
  67. GtkWidget *statusbar;
  68. gint status_cid;
  69. gboolean cancelled;
  70. } exphtml_dlg;
  71. static struct _AddressFileSelection _exp_html_file_selector_;
  72. static ExportHtmlCtl *_exportCtl_ = NULL;
  73. static AddressCache *_addressCache_ = NULL;
  74. /**
  75. * Display message in status field.
  76. * \param msg Message to display.
  77. */
  78. static void export_html_status_show( gchar *msg ) {
  79. if( exphtml_dlg.statusbar != NULL ) {
  80. gtk_statusbar_pop(
  81. GTK_STATUSBAR(exphtml_dlg.statusbar),
  82. exphtml_dlg.status_cid );
  83. if( msg ) {
  84. gtk_statusbar_push(
  85. GTK_STATUSBAR(exphtml_dlg.statusbar),
  86. exphtml_dlg.status_cid, msg );
  87. }
  88. }
  89. }
  90. /**
  91. * Select and display status message appropriate for the page being displayed.
  92. */
  93. static void export_html_message( void ) {
  94. gchar *sMsg = NULL;
  95. gint pageNum;
  96. pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
  97. if( pageNum == PAGE_FILE_INFO ) {
  98. sMsg = _( "Please specify output directory and file to create." );
  99. }
  100. else if( pageNum == PAGE_FORMAT ) {
  101. sMsg = _( "Select stylesheet and formatting." );
  102. }
  103. else if( pageNum == PAGE_FINISH ) {
  104. sMsg = _( "File exported successfully." );
  105. }
  106. export_html_status_show( sMsg );
  107. }
  108. /**
  109. * Callback function to cancel HTML file selection dialog.
  110. * \param widget Widget (button).
  111. * \param data User data.
  112. */
  113. static void export_html_cancel( GtkWidget *widget, gpointer data ) {
  114. gint pageNum;
  115. pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
  116. if( pageNum != PAGE_FINISH ) {
  117. exphtml_dlg.cancelled = TRUE;
  118. }
  119. gtk_main_quit();
  120. }
  121. /**
  122. * Callback function to handle dialog close event.
  123. * \param widget Widget (dialog).
  124. * \param event Event object.
  125. * \param data User data.
  126. */
  127. static gint export_html_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
  128. export_html_cancel( widget, data );
  129. return TRUE;
  130. }
  131. /**
  132. * Callback function to respond to dialog key press events.
  133. * \param widget Widget.
  134. * \param event Event object.
  135. * \param data User data.
  136. */
  137. static gboolean export_html_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
  138. if (event && event->keyval == GDK_Escape) {
  139. export_html_cancel( widget, data );
  140. }
  141. return FALSE;
  142. }
  143. /**
  144. * Test whether we can move off file page.
  145. * \return <i>TRUE</i> if OK to move off page.
  146. */
  147. static gboolean exp_html_move_file( void ) {
  148. gchar *sFile, *msg, *reason;
  149. AlertValue aval;
  150. sFile = gtk_editable_get_chars( GTK_EDITABLE(exphtml_dlg.entryHtml), 0, -1 );
  151. g_strchug( sFile ); g_strchomp( sFile );
  152. gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), sFile );
  153. exporthtml_parse_filespec( _exportCtl_, sFile );
  154. g_free( sFile );
  155. /* Test for directory */
  156. if( exporthtml_test_dir( _exportCtl_ ) ) {
  157. return TRUE;
  158. }
  159. /* Prompt to create */
  160. msg = g_strdup_printf( _(
  161. "HTML Output Directory '%s'\n" \
  162. "does not exist. OK to create new directory?" ),
  163. _exportCtl_->dirOutput );
  164. aval = alertpanel( _("Create Directory" ),
  165. msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
  166. g_free( msg );
  167. if( aval != G_ALERTALTERNATE ) return FALSE;
  168. /* Create directory */
  169. if( ! exporthtml_create_dir( _exportCtl_ ) ) {
  170. reason = exporthtml_get_create_msg( _exportCtl_ );
  171. msg = g_strdup_printf( _(
  172. "Could not create output directory for HTML file:\n%s" ),
  173. reason );
  174. aval = alertpanel_full(_("Failed to Create Directory"), msg,
  175. GTK_STOCK_CLOSE, NULL, NULL, FALSE,
  176. NULL, ALERT_ERROR, G_ALERTDEFAULT);
  177. g_free( msg );
  178. return FALSE;
  179. }
  180. return TRUE;
  181. }
  182. /**
  183. * Test whether we can move off format page.
  184. * \return <i>TRUE</i> if OK to move off page.
  185. */
  186. static gboolean exp_html_move_format( void ) {
  187. gboolean retVal = FALSE;
  188. gint id;
  189. /* Set stylesheet */
  190. id = combobox_get_active_data(GTK_COMBO_BOX(exphtml_dlg.optmenuCSS));
  191. exporthtml_set_stylesheet( _exportCtl_, id );
  192. /* Set name format */
  193. id = combobox_get_active_data(GTK_COMBO_BOX(exphtml_dlg.optmenuName));
  194. exporthtml_set_name_format( _exportCtl_, id );
  195. exporthtml_set_banding( _exportCtl_,
  196. gtk_toggle_button_get_active(
  197. GTK_TOGGLE_BUTTON( exphtml_dlg.checkBanding ) ) );
  198. exporthtml_set_link_email( _exportCtl_,
  199. gtk_toggle_button_get_active(
  200. GTK_TOGGLE_BUTTON( exphtml_dlg.checkLinkEMail ) ) );
  201. exporthtml_set_attributes( _exportCtl_,
  202. gtk_toggle_button_get_active(
  203. GTK_TOGGLE_BUTTON( exphtml_dlg.checkAttributes ) ) );
  204. /* Process export */
  205. exporthtml_process( _exportCtl_, _addressCache_ );
  206. if( _exportCtl_->retVal == MGU_SUCCESS ) {
  207. retVal = TRUE;
  208. }
  209. else {
  210. export_html_status_show( _( "Error creating HTML file" ) );
  211. }
  212. return retVal;
  213. }
  214. /**
  215. * Display finish page.
  216. */
  217. static void exp_html_finish_show( void ) {
  218. gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelOutFile), _exportCtl_->path );
  219. gtk_widget_set_sensitive( exphtml_dlg.btnNext, FALSE );
  220. gtk_widget_grab_focus( exphtml_dlg.btnCancel );
  221. }
  222. /**
  223. * Callback function to select previous page.
  224. * \param widget Widget (button).
  225. */
  226. static void export_html_prev( GtkWidget *widget ) {
  227. gint pageNum;
  228. pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
  229. if( pageNum == PAGE_FORMAT ) {
  230. /* Goto file page stuff */
  231. gtk_notebook_set_current_page(
  232. GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FILE_INFO );
  233. gtk_widget_set_sensitive( exphtml_dlg.btnPrev, FALSE );
  234. }
  235. else if( pageNum == PAGE_FINISH ) {
  236. /* Goto format page */
  237. gtk_notebook_set_current_page(
  238. GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FORMAT );
  239. gtk_widget_set_sensitive( exphtml_dlg.btnNext, TRUE );
  240. }
  241. export_html_message();
  242. }
  243. /**
  244. * Callback function to select previous page.
  245. * \param widget Widget (button).
  246. */
  247. static void export_html_next( GtkWidget *widget ) {
  248. gint pageNum;
  249. pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
  250. if( pageNum == PAGE_FILE_INFO ) {
  251. /* Goto format page */
  252. if( exp_html_move_file() ) {
  253. gtk_notebook_set_current_page(
  254. GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FORMAT );
  255. gtk_widget_set_sensitive( exphtml_dlg.btnPrev, TRUE );
  256. }
  257. export_html_message();
  258. }
  259. else if( pageNum == PAGE_FORMAT ) {
  260. /* Goto finish page */
  261. if( exp_html_move_format() ) {
  262. gtk_notebook_set_current_page(
  263. GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FINISH );
  264. gtk_button_set_label(GTK_BUTTON(exphtml_dlg.btnCancel),
  265. GTK_STOCK_CLOSE);
  266. exp_html_finish_show();
  267. exporthtml_save_settings( _exportCtl_ );
  268. export_html_message();
  269. }
  270. }
  271. }
  272. /**
  273. * Open file with web browser.
  274. * \param widget Widget (button).
  275. * \param data User data.
  276. */
  277. static void export_html_browse( GtkWidget *widget, gpointer data ) {
  278. gchar *uri;
  279. uri = g_strconcat( "file://", _exportCtl_->path, NULL );
  280. open_uri( uri, prefs_common.uri_cmd );
  281. g_free( uri );
  282. }
  283. /**
  284. * Create HTML file selection dialog.
  285. * \param afs Address file selection data.
  286. */
  287. static void exp_html_file_select_create( AddressFileSelection *afs ) {
  288. gchar *file = filesel_select_file_save(_("Select HTML output file"), NULL);
  289. if (file == NULL)
  290. afs->cancelled = TRUE;
  291. else {
  292. afs->cancelled = FALSE;
  293. gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), file );
  294. g_free(file);
  295. }
  296. }
  297. /**
  298. * Callback function to display HTML file selection dialog.
  299. */
  300. static void exp_html_file_select( void ) {
  301. exp_html_file_select_create( & _exp_html_file_selector_ );
  302. }
  303. /**
  304. * Format notebook file specification page.
  305. * \param pageNum Page (tab) number.
  306. * \param pageLbl Page (tab) label.
  307. */
  308. static void export_html_page_file( gint pageNum, gchar *pageLbl ) {
  309. GtkWidget *vbox;
  310. GtkWidget *table;
  311. GtkWidget *label;
  312. GtkWidget *labelBook;
  313. GtkWidget *entryHtml;
  314. GtkWidget *btnFile;
  315. gint top;
  316. vbox = gtk_vbox_new(FALSE, 8);
  317. gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
  318. gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
  319. label = gtk_label_new( pageLbl );
  320. gtk_widget_show( label );
  321. gtk_notebook_set_tab_label(
  322. GTK_NOTEBOOK( exphtml_dlg.notebook ),
  323. gtk_notebook_get_nth_page(
  324. GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ),
  325. label );
  326. table = gtk_table_new( 3, 3, FALSE );
  327. gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
  328. gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
  329. gtk_table_set_row_spacings(GTK_TABLE(table), 8);
  330. gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
  331. /* First row */
  332. top = 0;
  333. label = gtk_label_new( _( "Address Book" ) );
  334. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
  335. GTK_FILL, 0, 0, 0);
  336. gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  337. labelBook = gtk_label_new( "Address book name goes here" );
  338. gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
  339. GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
  340. gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
  341. /* Second row */
  342. top++;
  343. label = gtk_label_new( _( "HTML Output File" ) );
  344. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
  345. GTK_FILL, 0, 0, 0);
  346. gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  347. entryHtml = gtk_entry_new();
  348. gtk_table_attach(GTK_TABLE(table), entryHtml, 1, 2, top, (top + 1),
  349. GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
  350. btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
  351. gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
  352. GTK_FILL, 0, 3, 0);
  353. gtk_widget_show_all(vbox);
  354. /* Button handler */
  355. g_signal_connect(G_OBJECT(btnFile), "clicked",
  356. G_CALLBACK(exp_html_file_select), NULL);
  357. exphtml_dlg.labelBook = labelBook;
  358. exphtml_dlg.entryHtml = entryHtml;
  359. }
  360. /**
  361. * Format notebook format page.
  362. * \param pageNum Page (tab) number.
  363. * \param pageLbl Page (tab) label.
  364. */
  365. static void export_html_page_format( gint pageNum, gchar *pageLbl ) {
  366. GtkWidget *vbox;
  367. GtkWidget *table;
  368. GtkWidget *label;
  369. GtkWidget *optmenuCSS;
  370. GtkWidget *optmenuName;
  371. GtkListStore *menu;
  372. GtkTreeIter iter;
  373. GtkWidget *checkBanding;
  374. GtkWidget *checkLinkEMail;
  375. GtkWidget *checkAttributes;
  376. gint top;
  377. vbox = gtk_vbox_new(FALSE, 8);
  378. gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
  379. gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
  380. label = gtk_label_new( pageLbl );
  381. gtk_widget_show( label );
  382. gtk_notebook_set_tab_label(
  383. GTK_NOTEBOOK( exphtml_dlg.notebook ),
  384. gtk_notebook_get_nth_page(
  385. GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ),
  386. label );
  387. table = gtk_table_new( 5, 3, FALSE );
  388. gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
  389. gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
  390. gtk_table_set_row_spacings(GTK_TABLE(table), 8);
  391. gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
  392. /* First row */
  393. top = 0;
  394. label = gtk_label_new( _( "Stylesheet" ) );
  395. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
  396. GTK_FILL, 0, 0, 0);
  397. gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  398. optmenuCSS = gtkut_sc_combobox_create(NULL, TRUE);
  399. menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuCSS)));
  400. COMBOBOX_ADD(menu, _("None"), EXPORT_HTML_ID_NONE);
  401. COMBOBOX_ADD(menu, _("Default"), EXPORT_HTML_ID_DEFAULT);
  402. COMBOBOX_ADD(menu, _("Full"), EXPORT_HTML_ID_FULL);
  403. COMBOBOX_ADD(menu, _("Custom"), EXPORT_HTML_ID_CUSTOM);
  404. COMBOBOX_ADD(menu, _("Custom-2"), EXPORT_HTML_ID_CUSTOM2);
  405. COMBOBOX_ADD(menu, _("Custom-3"), EXPORT_HTML_ID_CUSTOM3);
  406. COMBOBOX_ADD(menu, _("Custom-4"), EXPORT_HTML_ID_CUSTOM4);
  407. gtk_table_attach(GTK_TABLE(table), optmenuCSS, 1, 2, top, (top + 1),
  408. GTK_FILL, 0, 0, 0);
  409. /* Second row */
  410. top++;
  411. label = gtk_label_new( _( "Full Name Format" ) );
  412. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
  413. GTK_FILL, 0, 0, 0);
  414. gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  415. optmenuName = gtkut_sc_combobox_create(NULL, TRUE);
  416. menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuName)));
  417. COMBOBOX_ADD(menu, _("First Name, Last Name"), EXPORT_HTML_FIRST_LAST);
  418. COMBOBOX_ADD(menu, _("Last Name, First Name"), EXPORT_HTML_LAST_FIRST);
  419. gtk_table_attach(GTK_TABLE(table), optmenuName, 1, 2, top, (top + 1),
  420. GTK_FILL, 0, 0, 0);
  421. /* Third row */
  422. top++;
  423. checkBanding = gtk_check_button_new_with_label( _( "Color Banding" ) );
  424. gtk_table_attach(GTK_TABLE(table), checkBanding, 1, 2, top, (top + 1),
  425. GTK_FILL, 0, 0, 0);
  426. /* Fourth row */
  427. top++;
  428. checkLinkEMail = gtk_check_button_new_with_label( _( "Format Email Links" ) );
  429. gtk_table_attach(GTK_TABLE(table), checkLinkEMail, 1, 2, top, (top + 1),
  430. GTK_FILL, 0, 0, 0);
  431. /* Fifth row */
  432. top++;
  433. checkAttributes = gtk_check_button_new_with_label( _( "Format User Attributes" ) );
  434. gtk_table_attach(GTK_TABLE(table), checkAttributes, 1, 2, top, (top + 1),
  435. GTK_FILL, 0, 0, 0);
  436. gtk_widget_show_all(vbox);
  437. exphtml_dlg.optmenuCSS = optmenuCSS;
  438. exphtml_dlg.optmenuName = optmenuName;
  439. exphtml_dlg.checkBanding = checkBanding;
  440. exphtml_dlg.checkLinkEMail = checkLinkEMail;
  441. exphtml_dlg.checkAttributes = checkAttributes;
  442. }
  443. /**
  444. * Format notebook finish page.
  445. * \param pageNum Page (tab) number.
  446. * \param pageLbl Page (tab) label.
  447. */
  448. static void export_html_page_finish( gint pageNum, gchar *pageLbl ) {
  449. GtkWidget *vbox;
  450. GtkWidget *table;
  451. GtkWidget *label;
  452. GtkWidget *labelBook;
  453. GtkWidget *labelFile;
  454. GtkWidget *btnBrowse;
  455. gint top;
  456. vbox = gtk_vbox_new(FALSE, 8);
  457. gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
  458. gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
  459. label = gtk_label_new( pageLbl );
  460. gtk_widget_show( label );
  461. gtk_notebook_set_tab_label(
  462. GTK_NOTEBOOK( exphtml_dlg.notebook ),
  463. gtk_notebook_get_nth_page( GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ), label );
  464. table = gtk_table_new( 3, 3, FALSE );
  465. gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
  466. gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
  467. gtk_table_set_row_spacings(GTK_TABLE(table), 8);
  468. gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
  469. /* First row */
  470. top = 0;
  471. label = gtk_label_new( _( "Address Book :" ) );
  472. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
  473. gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
  474. labelBook = gtk_label_new("Full name of address book goes here");
  475. gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
  476. gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
  477. /* Second row */
  478. top++;
  479. label = gtk_label_new( _( "File Name :" ) );
  480. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
  481. gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
  482. labelFile = gtk_label_new("File name goes here");
  483. gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
  484. gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
  485. /* Third row */
  486. top++;
  487. btnBrowse = gtk_button_new_with_label( _( "Open with Web Browser" ) );
  488. gtk_table_attach(GTK_TABLE(table), btnBrowse, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
  489. gtk_widget_show_all(vbox);
  490. /* Button handlers */
  491. g_signal_connect(G_OBJECT(btnBrowse), "clicked",
  492. G_CALLBACK(export_html_browse), NULL);
  493. exphtml_dlg.labelOutBook = labelBook;
  494. exphtml_dlg.labelOutFile = labelFile;
  495. }
  496. /**
  497. * Create main dialog decorations (excluding notebook pages).
  498. */
  499. static void export_html_dialog_create( void ) {
  500. GtkWidget *window;
  501. GtkWidget *vbox;
  502. GtkWidget *vnbox;
  503. GtkWidget *notebook;
  504. GtkWidget *hbbox;
  505. GtkWidget *btnPrev;
  506. GtkWidget *btnNext;
  507. GtkWidget *btnCancel;
  508. GtkWidget *hsbox;
  509. GtkWidget *statusbar;
  510. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  511. gtk_widget_set_size_request(window, -1, -1 );
  512. gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
  513. gtk_window_set_title( GTK_WINDOW(window),
  514. _("Export Address Book to HTML File") );
  515. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  516. gtk_window_set_modal(GTK_WINDOW(window), TRUE);
  517. g_signal_connect(G_OBJECT(window), "delete_event",
  518. G_CALLBACK(export_html_delete_event),
  519. NULL );
  520. g_signal_connect(G_OBJECT(window), "key_press_event",
  521. G_CALLBACK(export_html_key_pressed),
  522. NULL );
  523. vbox = gtk_vbox_new(FALSE, 4);
  524. gtk_widget_show(vbox);
  525. gtk_container_add(GTK_CONTAINER(window), vbox);
  526. vnbox = gtk_vbox_new(FALSE, 4);
  527. gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
  528. gtk_widget_show(vnbox);
  529. gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
  530. /* Notebook */
  531. notebook = gtk_notebook_new();
  532. gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
  533. /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
  534. gtk_widget_show(notebook);
  535. gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
  536. gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
  537. /* Status line */
  538. hsbox = gtk_hbox_new(FALSE, 0);
  539. gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
  540. statusbar = gtk_statusbar_new();
  541. gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
  542. /* Button panel */
  543. gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
  544. &btnNext, GTK_STOCK_GO_FORWARD,
  545. &btnCancel, GTK_STOCK_CANCEL);
  546. gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
  547. gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
  548. gtk_widget_grab_default(btnNext);
  549. /* Button handlers */
  550. g_signal_connect(G_OBJECT(btnPrev), "clicked",
  551. G_CALLBACK(export_html_prev), NULL);
  552. g_signal_connect(G_OBJECT(btnNext), "clicked",
  553. G_CALLBACK(export_html_next), NULL);
  554. g_signal_connect(G_OBJECT(btnCancel), "clicked",
  555. G_CALLBACK(export_html_cancel), NULL);
  556. gtk_widget_show_all(vbox);
  557. exphtml_dlg.window = window;
  558. exphtml_dlg.notebook = notebook;
  559. exphtml_dlg.btnPrev = btnPrev;
  560. exphtml_dlg.btnNext = btnNext;
  561. exphtml_dlg.btnCancel = btnCancel;
  562. exphtml_dlg.statusbar = statusbar;
  563. exphtml_dlg.status_cid = gtk_statusbar_get_context_id(
  564. GTK_STATUSBAR(statusbar), "Export HTML Dialog" );
  565. }
  566. /**
  567. * Create export HTML dialog.
  568. */
  569. static void export_html_create( void ) {
  570. export_html_dialog_create();
  571. export_html_page_file( PAGE_FILE_INFO, _( "File Info" ) );
  572. export_html_page_format( PAGE_FORMAT, _( "Format" ) );
  573. export_html_page_finish( PAGE_FINISH, _( "Finish" ) );
  574. gtk_widget_show_all( exphtml_dlg.window );
  575. }
  576. /**
  577. * Populate fields from control data.
  578. * \param ctl Export control data.
  579. */
  580. static void export_html_fill_fields( ExportHtmlCtl *ctl ) {
  581. gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), "" );
  582. if( ctl->path ) {
  583. gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml),
  584. ctl->path );
  585. }
  586. combobox_select_by_data(
  587. GTK_COMBO_BOX(exphtml_dlg.optmenuCSS), ctl->stylesheet );
  588. combobox_select_by_data(
  589. GTK_COMBO_BOX(exphtml_dlg.optmenuName), ctl->nameFormat );
  590. gtk_toggle_button_set_active(
  591. GTK_TOGGLE_BUTTON( exphtml_dlg.checkBanding ), ctl->banding );
  592. gtk_toggle_button_set_active(
  593. GTK_TOGGLE_BUTTON( exphtml_dlg.checkLinkEMail ), ctl->linkEMail );
  594. gtk_toggle_button_set_active(
  595. GTK_TOGGLE_BUTTON( exphtml_dlg.checkAttributes ), ctl->showAttribs );
  596. }
  597. /**
  598. * Process export address dialog.
  599. * \param cache Address book/data source cache.
  600. */
  601. void addressbook_exp_html( AddressCache *cache ) {
  602. /* Set references to control data */
  603. _addressCache_ = cache;
  604. _exportCtl_ = exporthtml_create();
  605. exporthtml_load_settings( _exportCtl_ );
  606. /* Setup GUI */
  607. if( ! exphtml_dlg.window )
  608. export_html_create();
  609. gtk_button_set_label(GTK_BUTTON(exphtml_dlg.btnCancel),
  610. GTK_STOCK_CANCEL);
  611. exphtml_dlg.cancelled = FALSE;
  612. gtk_widget_show(exphtml_dlg.window);
  613. manage_window_set_transient(GTK_WINDOW(exphtml_dlg.window));
  614. gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelBook), cache->name );
  615. gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelOutBook), cache->name );
  616. export_html_fill_fields( _exportCtl_ );
  617. gtk_widget_grab_default(exphtml_dlg.btnNext);
  618. gtk_notebook_set_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FILE_INFO );
  619. gtk_widget_set_sensitive( exphtml_dlg.btnPrev, FALSE );
  620. gtk_widget_set_sensitive( exphtml_dlg.btnNext, TRUE );
  621. export_html_message();
  622. gtk_widget_grab_focus(exphtml_dlg.entryHtml);
  623. gtk_main();
  624. gtk_widget_hide(exphtml_dlg.window);
  625. exporthtml_free( _exportCtl_ );
  626. _exportCtl_ = NULL;
  627. _addressCache_ = NULL;
  628. }
  629. /*
  630. * ============================================================================
  631. * End of Source.
  632. * ============================================================================
  633. */