expldifdlg.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /*
  2. * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
  3. * Copyright (C) 2003-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 LDIF 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 "exportldif.h"
  42. #include "utils.h"
  43. #include "manage_window.h"
  44. #include "filesel.h"
  45. #define PAGE_FILE_INFO 0
  46. #define PAGE_DN 1
  47. #define PAGE_FINISH 2
  48. #define EXPORTLDIF_WIDTH 480
  49. #define EXPORTLDIF_HEIGHT -1
  50. /**
  51. * Dialog object.
  52. */
  53. static struct _ExpLdif_Dlg {
  54. GtkWidget *window;
  55. GtkWidget *notebook;
  56. GtkWidget *labelBook;
  57. GtkWidget *entryLdif;
  58. GtkWidget *entrySuffix;
  59. GtkWidget *optmenuRDN;
  60. GtkWidget *checkUseDN;
  61. GtkWidget *checkEMail;
  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. } expldif_dlg;
  71. static struct _AddressFileSelection _exp_ldif_file_selector_;
  72. static ExportLdifCtl *_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_ldif_status_show( gchar *msg ) {
  79. if( expldif_dlg.statusbar != NULL ) {
  80. gtk_statusbar_pop(
  81. GTK_STATUSBAR(expldif_dlg.statusbar),
  82. expldif_dlg.status_cid );
  83. if( msg ) {
  84. gtk_statusbar_push(
  85. GTK_STATUSBAR(expldif_dlg.statusbar),
  86. expldif_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_ldif_message( void ) {
  94. gchar *sMsg = NULL;
  95. gint pageNum;
  96. pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
  97. if( pageNum == PAGE_FILE_INFO ) {
  98. sMsg = _( "Please specify output directory and LDIF filename to create." );
  99. }
  100. else if( pageNum == PAGE_DN ) {
  101. sMsg = _( "Specify parameters to format distinguished name." );
  102. }
  103. else if( pageNum == PAGE_FINISH ) {
  104. sMsg = _( "File exported successfully." );
  105. }
  106. export_ldif_status_show( sMsg );
  107. }
  108. /**
  109. * Callback function to cancel LDIF file selection dialog.
  110. * \param widget Widget (button).
  111. * \param data User data.
  112. */
  113. static void export_ldif_cancel( GtkWidget *widget, gpointer data ) {
  114. gint pageNum;
  115. pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
  116. if( pageNum != PAGE_FINISH ) {
  117. expldif_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_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
  128. export_ldif_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_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
  138. if (event && event->keyval == GDK_Escape) {
  139. export_ldif_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_ldif_move_file( void ) {
  148. gchar *sFile, *msg, *reason;
  149. gboolean errFlag = FALSE;
  150. AlertValue aval;
  151. sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
  152. g_strchug( sFile ); g_strchomp( sFile );
  153. gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile );
  154. exportldif_parse_filespec( _exportCtl_, sFile );
  155. /* Test that something was supplied */
  156. if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
  157. gtk_widget_grab_focus( expldif_dlg.entryLdif );
  158. errFlag = TRUE;
  159. }
  160. g_free( sFile );
  161. if( errFlag ) return FALSE;
  162. /* Test for directory */
  163. if( exportldif_test_dir( _exportCtl_ ) ) {
  164. return TRUE;
  165. }
  166. /* Prompt to create */
  167. msg = g_strdup_printf( _(
  168. "LDIF Output Directory '%s'\n" \
  169. "does not exist. OK to create new directory?" ),
  170. _exportCtl_->dirOutput );
  171. aval = alertpanel( _("Create Directory" ),
  172. msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
  173. g_free( msg );
  174. if( aval != G_ALERTALTERNATE ) return FALSE;
  175. /* Create directory */
  176. if( ! exportldif_create_dir( _exportCtl_ ) ) {
  177. reason = exportldif_get_create_msg( _exportCtl_ );
  178. msg = g_strdup_printf( _(
  179. "Could not create output directory for LDIF file:\n%s" ),
  180. reason );
  181. aval = alertpanel_full(_("Failed to Create Directory"), msg,
  182. GTK_STOCK_CLOSE, NULL, NULL, FALSE,
  183. NULL, ALERT_ERROR, G_ALERTDEFAULT);
  184. g_free( msg );
  185. return FALSE;
  186. }
  187. return TRUE;
  188. }
  189. /**
  190. * Test whether we can move off distinguished name page.
  191. * \return <i>TRUE</i> if OK to move off page.
  192. */
  193. static gboolean exp_ldif_move_dn( void ) {
  194. gboolean retVal = FALSE;
  195. gboolean errFlag = FALSE;
  196. gchar *suffix;
  197. GtkWidget *menu, *menuItem;
  198. gint id;
  199. /* Set suffix */
  200. suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
  201. g_strchug( suffix ); g_strchomp( suffix );
  202. /* Set RDN format */
  203. menu = gtk_option_menu_get_menu( GTK_OPTION_MENU( expldif_dlg.optmenuRDN ) );
  204. menuItem = gtk_menu_get_active( GTK_MENU( menu ) );
  205. id = GPOINTER_TO_INT( gtk_object_get_user_data(GTK_OBJECT(menuItem)) );
  206. exportldif_set_rdn( _exportCtl_, id );
  207. exportldif_set_suffix( _exportCtl_, suffix );
  208. exportldif_set_use_dn( _exportCtl_,
  209. gtk_toggle_button_get_active(
  210. GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) );
  211. exportldif_set_exclude_email( _exportCtl_,
  212. gtk_toggle_button_get_active(
  213. GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) );
  214. if( *suffix == '\0' || strlen( suffix ) < 1 ) {
  215. AlertValue aval;
  216. aval = alertpanel(
  217. _( "Suffix was not supplied" ),
  218. _(
  219. "A suffix is required if data is to be used " \
  220. "for an LDAP server. Are you sure you wish " \
  221. "to proceed without a suffix?"
  222. ),
  223. GTK_STOCK_NO, GTK_STOCK_YES, NULL );
  224. if( aval != G_ALERTALTERNATE ) {
  225. gtk_widget_grab_focus( expldif_dlg.entrySuffix );
  226. errFlag = TRUE;
  227. }
  228. }
  229. if( ! errFlag ) {
  230. /* Process export */
  231. exportldif_process( _exportCtl_, _addressCache_ );
  232. if( _exportCtl_->retVal == MGU_SUCCESS ) {
  233. retVal = TRUE;
  234. }
  235. else {
  236. export_ldif_status_show( _( "Error creating LDIF file" ) );
  237. }
  238. }
  239. return retVal;
  240. }
  241. /**
  242. * Display finish page.
  243. */
  244. static void exp_ldif_finish_show( void ) {
  245. gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutFile), _exportCtl_->path );
  246. gtk_widget_set_sensitive( expldif_dlg.btnNext, FALSE );
  247. gtk_widget_grab_focus( expldif_dlg.btnCancel );
  248. }
  249. /**
  250. * Callback function to select previous page.
  251. * \param widget Widget (button).
  252. */
  253. static void export_ldif_prev( GtkWidget *widget ) {
  254. gint pageNum;
  255. pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
  256. if( pageNum == PAGE_DN ) {
  257. /* Goto file page stuff */
  258. gtk_notebook_set_current_page(
  259. GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
  260. gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
  261. }
  262. else if( pageNum == PAGE_FINISH ) {
  263. /* Goto format page */
  264. gtk_notebook_set_current_page(
  265. GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
  266. gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
  267. }
  268. export_ldif_message();
  269. }
  270. /**
  271. * Callback function to select next page.
  272. * \param widget Widget (button).
  273. */
  274. static void export_ldif_next( GtkWidget *widget ) {
  275. gint pageNum;
  276. pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
  277. if( pageNum == PAGE_FILE_INFO ) {
  278. /* Goto distinguished name page */
  279. if( exp_ldif_move_file() ) {
  280. gtk_notebook_set_current_page(
  281. GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
  282. gtk_widget_set_sensitive( expldif_dlg.btnPrev, TRUE );
  283. }
  284. export_ldif_message();
  285. }
  286. else if( pageNum == PAGE_DN ) {
  287. /* Goto finish page */
  288. if( exp_ldif_move_dn() ) {
  289. gtk_notebook_set_current_page(
  290. GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FINISH );
  291. gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
  292. GTK_STOCK_CLOSE);
  293. exp_ldif_finish_show();
  294. exportldif_save_settings( _exportCtl_ );
  295. export_ldif_message();
  296. }
  297. }
  298. }
  299. /**
  300. * Create LDIF file selection dialog.
  301. * \param afs Address file selection data.
  302. */
  303. static void exp_ldif_file_select_create( AddressFileSelection *afs ) {
  304. gchar *file = filesel_select_file_save(_("Select LDIF output file"), NULL);
  305. if (file == NULL)
  306. afs->cancelled = TRUE;
  307. else {
  308. afs->cancelled = FALSE;
  309. gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), file );
  310. g_free(file);
  311. }
  312. }
  313. /**
  314. * Callback function to display LDIF file selection dialog.
  315. */
  316. static void exp_ldif_file_select( void ) {
  317. exp_ldif_file_select_create( & _exp_ldif_file_selector_ );
  318. }
  319. /**
  320. * Format notebook file specification page.
  321. * \param pageNum Page (tab) number.
  322. * \param pageLbl Page (tab) label.
  323. */
  324. static void export_ldif_page_file( gint pageNum, gchar *pageLbl ) {
  325. GtkWidget *vbox;
  326. GtkWidget *table;
  327. GtkWidget *label;
  328. GtkWidget *labelBook;
  329. GtkWidget *entryLdif;
  330. GtkWidget *btnFile;
  331. gint top;
  332. vbox = gtk_vbox_new(FALSE, 8);
  333. gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
  334. gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
  335. label = gtk_label_new( pageLbl );
  336. gtk_widget_show( label );
  337. gtk_notebook_set_tab_label(
  338. GTK_NOTEBOOK( expldif_dlg.notebook ),
  339. gtk_notebook_get_nth_page(
  340. GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
  341. label );
  342. table = gtk_table_new( 3, 3, FALSE );
  343. gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
  344. gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
  345. gtk_table_set_row_spacings(GTK_TABLE(table), 8);
  346. gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
  347. /* First row */
  348. top = 0;
  349. label = gtk_label_new( _( "Address Book" ) );
  350. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
  351. GTK_FILL, 0, 0, 0);
  352. gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  353. labelBook = gtk_label_new( "Address book name goes here" );
  354. gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
  355. GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
  356. gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
  357. /* Second row */
  358. top++;
  359. label = gtk_label_new( _( "LDIF Output File" ) );
  360. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
  361. GTK_FILL, 0, 0, 0);
  362. gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  363. entryLdif = gtk_entry_new();
  364. gtk_table_attach(GTK_TABLE(table), entryLdif, 1, 2, top, (top + 1),
  365. GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
  366. btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
  367. gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
  368. GTK_FILL, 0, 3, 0);
  369. gtk_widget_show_all(vbox);
  370. /* Button handler */
  371. g_signal_connect(G_OBJECT(btnFile), "clicked",
  372. G_CALLBACK(exp_ldif_file_select), NULL);
  373. expldif_dlg.labelBook = labelBook;
  374. expldif_dlg.entryLdif = entryLdif;
  375. }
  376. /**
  377. * Format notebook distinguished name page.
  378. * \param pageNum Page (tab) number.
  379. * \param pageLbl Page (tab) label.
  380. */
  381. static void export_ldif_page_dn( gint pageNum, gchar *pageLbl ) {
  382. GtkWidget *vbox;
  383. GtkWidget *table;
  384. GtkWidget *label;
  385. GtkWidget *entrySuffix;
  386. GtkWidget *optmenuRDN;
  387. GtkWidget *checkUseDN;
  388. GtkWidget *checkEMail;
  389. GtkWidget *menu;
  390. GtkWidget *menuItem;
  391. GtkTooltips *toolTip;
  392. gint top;
  393. vbox = gtk_vbox_new(FALSE, 8);
  394. gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
  395. gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
  396. label = gtk_label_new( pageLbl );
  397. gtk_widget_show( label );
  398. gtk_notebook_set_tab_label(
  399. GTK_NOTEBOOK( expldif_dlg.notebook ),
  400. gtk_notebook_get_nth_page(
  401. GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
  402. label );
  403. table = gtk_table_new( 5, 2, FALSE );
  404. gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
  405. gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
  406. gtk_table_set_row_spacings(GTK_TABLE(table), 8);
  407. gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
  408. /* First row */
  409. top = 0;
  410. label = gtk_label_new( _( "Suffix" ) );
  411. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
  412. GTK_FILL, 0, 0, 0);
  413. gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  414. entrySuffix = gtk_entry_new();
  415. gtk_table_attach(GTK_TABLE(table), entrySuffix, 1, 2, top, (top + 1),
  416. GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
  417. toolTip = gtk_tooltips_new();
  418. gtk_tooltips_set_tip(
  419. GTK_TOOLTIPS(toolTip), entrySuffix, _(
  420. "The suffix is used to create a \"Distinguished Name\" " \
  421. "(or DN) for an LDAP entry. Examples include:\n" \
  422. " dc=sylpheed,dc=org\n" \
  423. " ou=people,dc=domainname,dc=com\n" \
  424. " o=Organization Name,c=Country\n"
  425. ), NULL );
  426. /* Second row */
  427. top++;
  428. label = gtk_label_new( _( "Relative DN" ) );
  429. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
  430. GTK_FILL, 0, 0, 0);
  431. gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
  432. menu = gtk_menu_new();
  433. menuItem = gtk_menu_item_new_with_label( _( "Unique ID" ) );
  434. gtk_object_set_user_data( GTK_OBJECT( menuItem ),
  435. GINT_TO_POINTER( EXPORT_LDIF_ID_UID ) );
  436. gtk_menu_append( GTK_MENU(menu), menuItem );
  437. gtk_widget_show( menuItem );
  438. toolTip = gtk_tooltips_new();
  439. gtk_tooltips_set_tip(
  440. GTK_TOOLTIPS(toolTip), menuItem, _(
  441. "The address book Unique ID is used to create a DN that is " \
  442. "formatted similar to:\n" \
  443. " uid=102376,ou=people,dc=sylpheed,dc=org"
  444. ), NULL );
  445. menuItem = gtk_menu_item_new_with_label( _( "Display Name" ) );
  446. gtk_object_set_user_data( GTK_OBJECT( menuItem ),
  447. GINT_TO_POINTER( EXPORT_LDIF_ID_DNAME ) );
  448. gtk_menu_append( GTK_MENU(menu), menuItem );
  449. gtk_widget_show( menuItem );
  450. toolTip = gtk_tooltips_new();
  451. gtk_tooltips_set_tip(
  452. GTK_TOOLTIPS(toolTip), menuItem, _(
  453. "The address book Display Name is used to create a DN that " \
  454. "is formatted similar to:\n" \
  455. " cn=John Doe,ou=people,dc=sylpheed,dc=org"
  456. ), NULL );
  457. menuItem = gtk_menu_item_new_with_label( _( "Email Address" ) );
  458. gtk_object_set_user_data( GTK_OBJECT( menuItem ),
  459. GINT_TO_POINTER( EXPORT_LDIF_ID_EMAIL ) );
  460. gtk_menu_append( GTK_MENU(menu), menuItem );
  461. gtk_widget_show( menuItem );
  462. toolTip = gtk_tooltips_new();
  463. gtk_tooltips_set_tip(
  464. GTK_TOOLTIPS(toolTip), menuItem, _(
  465. "The first Email Address belonging to a person is used to " \
  466. "create a DN that is formatted similar to:\n" \
  467. " mail=john.doe@domain.com,ou=people,dc=sylpheed,dc=org"
  468. ), NULL );
  469. optmenuRDN = gtk_option_menu_new();
  470. gtk_option_menu_set_menu( GTK_OPTION_MENU( optmenuRDN ), menu );
  471. gtk_table_attach(GTK_TABLE(table), optmenuRDN, 1, 2, top, (top + 1),
  472. GTK_FILL, 0, 0, 0);
  473. toolTip = gtk_tooltips_new();
  474. gtk_tooltips_set_tip(
  475. GTK_TOOLTIPS(toolTip), optmenuRDN, _(
  476. "The LDIF file contains several data records that " \
  477. "are usually loaded into an LDAP server. Each data " \
  478. "record in the LDIF file is uniquely identified by " \
  479. "a \"Distinguished Name\" (or DN). The suffix is " \
  480. "appended to the \"Relative Distinguished Name\" "\
  481. "(or RDN) to create the DN. Please select one of " \
  482. "the available RDN options that will be used to " \
  483. "create the DN."
  484. ), NULL );
  485. /* Third row */
  486. top++;
  487. checkUseDN = gtk_check_button_new_with_label(
  488. _( "Use DN attribute if present in data" ) );
  489. gtk_table_attach(GTK_TABLE(table), checkUseDN, 1, 2, top, (top + 1),
  490. GTK_FILL, 0, 0, 0);
  491. toolTip = gtk_tooltips_new();
  492. gtk_tooltips_set_tip(
  493. GTK_TOOLTIPS(toolTip), checkUseDN, _(
  494. "The addressbook may contain entries that were " \
  495. "previously imported from an LDIF file. The " \
  496. "\"Distinguished Name\" (DN) user attribute, if " \
  497. "present in the address book data, may be used in " \
  498. "the exported LDIF file. The RDN selected above " \
  499. "will be used if the DN user attribute is not found."
  500. ), NULL );
  501. /* Fourth row */
  502. top++;
  503. checkEMail = gtk_check_button_new_with_label(
  504. _( "Exclude record if no Email Address" ) );
  505. gtk_table_attach(GTK_TABLE(table), checkEMail, 1, 2, top, (top + 1),
  506. GTK_FILL, 0, 0, 0);
  507. toolTip = gtk_tooltips_new();
  508. gtk_tooltips_set_tip(
  509. GTK_TOOLTIPS(toolTip), checkEMail, _(
  510. "An addressbook may contain entries without " \
  511. "Email Addresses. Check this option to ignore " \
  512. "these records."
  513. ), NULL );
  514. gtk_widget_show_all(vbox);
  515. expldif_dlg.entrySuffix = entrySuffix;
  516. expldif_dlg.optmenuRDN = optmenuRDN;
  517. expldif_dlg.checkUseDN = checkUseDN;
  518. expldif_dlg.checkEMail = checkEMail;
  519. }
  520. /**
  521. * Format notebook finish page.
  522. * \param pageNum Page (tab) number.
  523. * \param pageLbl Page (tab) label.
  524. */
  525. static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
  526. GtkWidget *vbox;
  527. GtkWidget *table;
  528. GtkWidget *label;
  529. GtkWidget *labelBook;
  530. GtkWidget *labelFile;
  531. gint top;
  532. vbox = gtk_vbox_new(FALSE, 8);
  533. gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
  534. gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
  535. label = gtk_label_new( pageLbl );
  536. gtk_widget_show( label );
  537. gtk_notebook_set_tab_label(
  538. GTK_NOTEBOOK( expldif_dlg.notebook ),
  539. gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label );
  540. table = gtk_table_new( 3, 3, FALSE );
  541. gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
  542. gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
  543. gtk_table_set_row_spacings(GTK_TABLE(table), 8);
  544. gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
  545. /* First row */
  546. top = 0;
  547. label = gtk_label_new( _( "Address Book :" ) );
  548. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
  549. gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
  550. labelBook = gtk_label_new("Full name of address book goes here");
  551. gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
  552. gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
  553. /* Second row */
  554. top++;
  555. label = gtk_label_new( _( "File Name :" ) );
  556. gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
  557. gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
  558. labelFile = gtk_label_new("File name goes here");
  559. gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
  560. gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
  561. gtk_widget_show_all(vbox);
  562. expldif_dlg.labelOutBook = labelBook;
  563. expldif_dlg.labelOutFile = labelFile;
  564. }
  565. /**
  566. * Create main dialog decorations (excluding notebook pages).
  567. */
  568. static void export_ldif_dialog_create( void ) {
  569. GtkWidget *window;
  570. GtkWidget *vbox;
  571. GtkWidget *vnbox;
  572. GtkWidget *notebook;
  573. GtkWidget *hbbox;
  574. GtkWidget *btnPrev;
  575. GtkWidget *btnNext;
  576. GtkWidget *btnCancel;
  577. GtkWidget *hsbox;
  578. GtkWidget *statusbar;
  579. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  580. gtk_widget_set_size_request(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT );
  581. gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
  582. gtk_window_set_title( GTK_WINDOW(window),
  583. _("Export Address Book to LDIF File") );
  584. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  585. gtk_window_set_modal(GTK_WINDOW(window), TRUE);
  586. g_signal_connect(G_OBJECT(window), "delete_event",
  587. G_CALLBACK(export_ldif_delete_event),
  588. NULL );
  589. g_signal_connect(G_OBJECT(window), "key_press_event",
  590. G_CALLBACK(export_ldif_key_pressed),
  591. NULL );
  592. vbox = gtk_vbox_new(FALSE, 4);
  593. gtk_widget_show(vbox);
  594. gtk_container_add(GTK_CONTAINER(window), vbox);
  595. vnbox = gtk_vbox_new(FALSE, 4);
  596. gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
  597. gtk_widget_show(vnbox);
  598. gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
  599. /* Notebook */
  600. notebook = gtk_notebook_new();
  601. gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
  602. /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
  603. gtk_widget_show(notebook);
  604. gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
  605. gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
  606. /* Status line */
  607. hsbox = gtk_hbox_new(FALSE, 0);
  608. gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
  609. statusbar = gtk_statusbar_new();
  610. gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
  611. /* Button panel */
  612. gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
  613. &btnNext, GTK_STOCK_GO_FORWARD,
  614. &btnCancel, GTK_STOCK_CANCEL);
  615. gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
  616. gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
  617. gtk_widget_grab_default(btnNext);
  618. /* Button handlers */
  619. g_signal_connect(G_OBJECT(btnPrev), "clicked",
  620. G_CALLBACK(export_ldif_prev), NULL);
  621. g_signal_connect(G_OBJECT(btnNext), "clicked",
  622. G_CALLBACK(export_ldif_next), NULL);
  623. g_signal_connect(G_OBJECT(btnCancel), "clicked",
  624. G_CALLBACK(export_ldif_cancel), NULL);
  625. gtk_widget_show_all(vbox);
  626. expldif_dlg.window = window;
  627. expldif_dlg.notebook = notebook;
  628. expldif_dlg.btnPrev = btnPrev;
  629. expldif_dlg.btnNext = btnNext;
  630. expldif_dlg.btnCancel = btnCancel;
  631. expldif_dlg.statusbar = statusbar;
  632. expldif_dlg.status_cid = gtk_statusbar_get_context_id(
  633. GTK_STATUSBAR(statusbar), "Export LDIF Dialog" );
  634. }
  635. /**
  636. * Create export LDIF dialog.
  637. */
  638. static void export_ldif_create( void ) {
  639. export_ldif_dialog_create();
  640. export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
  641. export_ldif_page_dn( PAGE_DN, _( "Distguished Name" ) );
  642. export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
  643. gtk_widget_show_all( expldif_dlg.window );
  644. }
  645. /**
  646. * Populate fields from control data.
  647. * \param ctl Export control data.
  648. */
  649. static void export_ldif_fill_fields( ExportLdifCtl *ctl ) {
  650. gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" );
  651. if( ctl->path ) {
  652. gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif),
  653. ctl->path );
  654. }
  655. gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" );
  656. if( ctl->suffix ) {
  657. gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix),
  658. ctl->suffix );
  659. }
  660. gtk_option_menu_set_history(
  661. GTK_OPTION_MENU( expldif_dlg.optmenuRDN ), ctl->rdnIndex );
  662. gtk_toggle_button_set_active(
  663. GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN );
  664. gtk_toggle_button_set_active(
  665. GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail );
  666. }
  667. /**
  668. * Process export address dialog.
  669. * \param cache Address book/data source cache.
  670. */
  671. void addressbook_exp_ldif( AddressCache *cache ) {
  672. /* Set references to control data */
  673. _addressCache_ = cache;
  674. _exportCtl_ = exportldif_create();
  675. exportldif_load_settings( _exportCtl_ );
  676. /* Setup GUI */
  677. if( ! expldif_dlg.window )
  678. export_ldif_create();
  679. gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
  680. GTK_STOCK_CANCEL);
  681. expldif_dlg.cancelled = FALSE;
  682. gtk_widget_show(expldif_dlg.window);
  683. manage_window_set_transient(GTK_WINDOW(expldif_dlg.window));
  684. gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name );
  685. gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name );
  686. export_ldif_fill_fields( _exportCtl_ );
  687. gtk_widget_grab_default(expldif_dlg.btnNext);
  688. gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
  689. gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
  690. gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
  691. export_ldif_message();
  692. gtk_widget_grab_focus(expldif_dlg.entryLdif);
  693. gtk_main();
  694. gtk_widget_hide(expldif_dlg.window);
  695. exportldif_free( _exportCtl_ );
  696. _exportCtl_ = NULL;
  697. _addressCache_ = NULL;
  698. }
  699. /*
  700. * ============================================================================
  701. * End of Source.
  702. * ============================================================================
  703. */