Statistics
| Revision:

root / src / editjpilot.c @ 1573

History | View | Annotate | Download (12.7 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 1 hiro
 * Copyright (C) 2001 Match Grun
4 1 hiro
 *
5 1 hiro
 * This program is free software; you can redistribute it and/or modify
6 1 hiro
 * it under the terms of the GNU General Public License as published by
7 1 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 1 hiro
 * (at your option) any later version.
9 1 hiro
 *
10 1 hiro
 * This program is distributed in the hope that it will be useful,
11 1 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 1 hiro
 * GNU General Public License for more details.
14 1 hiro
 *
15 1 hiro
 * You should have received a copy of the GNU General Public License
16 1 hiro
 * along with this program; if not, write to the Free Software
17 1 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 1 hiro
 */
19 1 hiro
20 1 hiro
/*
21 1 hiro
 * Edit JPilot address book data.
22 1 hiro
 */
23 1 hiro
24 1 hiro
#ifdef HAVE_CONFIG_H
25 1 hiro
#  include "config.h"
26 1 hiro
#endif
27 1 hiro
28 1 hiro
#ifdef USE_JPILOT
29 1 hiro
30 1 hiro
#include "defs.h"
31 1 hiro
32 1 hiro
#include <glib.h>
33 92 hiro
#include <glib/gi18n.h>
34 1 hiro
#include <gdk/gdkkeysyms.h>
35 1 hiro
#include <gtk/gtkwindow.h>
36 1 hiro
#include <gtk/gtksignal.h>
37 1 hiro
#include <gtk/gtkhbox.h>
38 1 hiro
#include <gtk/gtklabel.h>
39 1 hiro
#include <gtk/gtkentry.h>
40 1 hiro
#include <gtk/gtkhbbox.h>
41 238 hiro
#include <gtk/gtkvbox.h>
42 238 hiro
#include <gtk/gtktable.h>
43 238 hiro
#include <gtk/gtkframe.h>
44 238 hiro
#include <gtk/gtkhseparator.h>
45 1 hiro
#include <gtk/gtkbutton.h>
46 238 hiro
#include <gtk/gtkstatusbar.h>
47 238 hiro
#include <gtk/gtkcheckbutton.h>
48 238 hiro
#include <gtk/gtkfilesel.h>
49 1 hiro
50 1 hiro
#include "addressbook.h"
51 1 hiro
#include "prefs_common.h"
52 1 hiro
#include "addressitem.h"
53 1 hiro
#include "jpilot.h"
54 1 hiro
#include "mgutils.h"
55 411 hiro
#include "filesel.h"
56 1 hiro
#include "gtkutils.h"
57 411 hiro
#include "codeconv.h"
58 1 hiro
#include "manage_window.h"
59 1 hiro
60 1 hiro
#define ADDRESSBOOK_GUESS_JPILOT "MyJPilot"
61 1 hiro
#define JPILOT_NUM_CUSTOM_LABEL        4
62 1 hiro
63 1 hiro
static struct _JPilotEdit {
64 1 hiro
        GtkWidget *window;
65 1 hiro
        GtkWidget *name_entry;
66 1 hiro
        GtkWidget *file_entry;
67 1 hiro
        GtkWidget *custom_check[JPILOT_NUM_CUSTOM_LABEL];
68 1 hiro
        GtkWidget *custom_label[JPILOT_NUM_CUSTOM_LABEL];
69 405 hiro
        GtkWidget *hbbox;
70 1 hiro
        GtkWidget *ok_btn;
71 1 hiro
        GtkWidget *cancel_btn;
72 1 hiro
        GtkWidget *statusbar;
73 1 hiro
        gint status_cid;
74 1 hiro
} jpilotedit;
75 1 hiro
76 1 hiro
/*
77 1 hiro
* Edit functions.
78 1 hiro
*/
79 1 hiro
void edit_jpilot_status_show( gchar *msg ) {
80 1 hiro
        if( jpilotedit.statusbar != NULL ) {
81 1 hiro
                gtk_statusbar_pop( GTK_STATUSBAR(jpilotedit.statusbar), jpilotedit.status_cid );
82 1 hiro
                if( msg ) {
83 1 hiro
                        gtk_statusbar_push( GTK_STATUSBAR(jpilotedit.statusbar), jpilotedit.status_cid, msg );
84 1 hiro
                }
85 1 hiro
        }
86 1 hiro
}
87 1 hiro
88 1 hiro
static gint edit_jpilot_delete_event( GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) {
89 1 hiro
        *cancelled = TRUE;
90 1 hiro
        gtk_main_quit();
91 1 hiro
        return TRUE;
92 1 hiro
}
93 1 hiro
94 1 hiro
static gboolean edit_jpilot_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) {
95 1 hiro
        if (event && event->keyval == GDK_Escape) {
96 1 hiro
                *cancelled = TRUE;
97 1 hiro
                gtk_main_quit();
98 1 hiro
        }
99 1 hiro
        return FALSE;
100 1 hiro
}
101 1 hiro
102 1 hiro
static void edit_jpilot_ok( GtkWidget *widget, gboolean *cancelled ) {
103 1 hiro
        *cancelled = FALSE;
104 1 hiro
        gtk_main_quit();
105 1 hiro
}
106 1 hiro
107 1 hiro
static void edit_jpilot_cancel( GtkWidget *widget, gboolean *cancelled ) {
108 1 hiro
        *cancelled = TRUE;
109 1 hiro
        gtk_main_quit();
110 1 hiro
}
111 1 hiro
112 1 hiro
static void edit_jpilot_fill_check_box( JPilotFile *jpf ) {
113 1 hiro
        gint i;
114 1 hiro
        GList *node, *customLbl = NULL;
115 1 hiro
        gchar *labelName;
116 1 hiro
        gboolean done, checked;
117 1 hiro
        for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
118 1 hiro
                gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), FALSE );
119 1 hiro
                gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), "" );
120 1 hiro
        }
121 1 hiro
122 1 hiro
        done = FALSE;
123 1 hiro
        i = 0;
124 1 hiro
        customLbl = jpilot_load_custom_label( jpf, customLbl );
125 1 hiro
        node = customLbl;
126 1 hiro
        while( ! done ) {
127 1 hiro
                if( node ) {
128 1 hiro
                        labelName = node->data;
129 1 hiro
                        gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), labelName );
130 1 hiro
                        checked = jpilot_test_custom_label( jpf, labelName );
131 1 hiro
                        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), checked );
132 1 hiro
                        i++;
133 1 hiro
                        if( i >= JPILOT_NUM_CUSTOM_LABEL ) done = TRUE;
134 1 hiro
                        node = g_list_next( node );
135 1 hiro
                }
136 1 hiro
                else {
137 1 hiro
                        done = TRUE;
138 1 hiro
                }
139 1 hiro
        }
140 1 hiro
        mgu_free_dlist( customLbl );
141 1 hiro
        customLbl = NULL;
142 1 hiro
}
143 1 hiro
144 1 hiro
static void edit_jpilot_fill_check_box_new() {
145 1 hiro
        gint i;
146 1 hiro
        for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
147 1 hiro
                gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), FALSE );
148 1 hiro
                gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), "" );
149 1 hiro
        }
150 1 hiro
}
151 1 hiro
152 1 hiro
static void edit_jpilot_read_check_box( JPilotFile *pilotFile ) {
153 1 hiro
        gint i;
154 1 hiro
        gchar *labelName;
155 1 hiro
        jpilot_clear_custom_labels( pilotFile );
156 1 hiro
        for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
157 1 hiro
                if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(jpilotedit.custom_check[i]) ) ) {
158 1 hiro
                        labelName = GTK_LABEL(jpilotedit.custom_label[i])->label;
159 1 hiro
                        jpilot_add_custom_label( pilotFile, labelName );
160 1 hiro
                }
161 1 hiro
        }
162 1 hiro
}
163 1 hiro
164 1 hiro
static void edit_jpilot_file_check( void ) {
165 1 hiro
        gint t = -1;
166 1 hiro
        gchar *sFile;
167 411 hiro
        gchar *sFSFile;
168 1 hiro
        gchar *sMsg;
169 1 hiro
        gboolean flg;
170 1 hiro
171 1 hiro
        flg = FALSE;
172 1 hiro
        sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
173 1 hiro
        if( sFile ) {
174 411 hiro
                sFSFile = conv_filename_from_utf8( sFile );
175 411 hiro
                if( sFSFile && *sFSFile != '\0' ) {
176 1 hiro
                        /* Attempt to read file */
177 411 hiro
                        JPilotFile *jpf;
178 411 hiro
                        jpf = jpilot_create_path( sFSFile );
179 1 hiro
                        t = jpilot_read_data( jpf );
180 1 hiro
                        if( t == MGU_SUCCESS ) {
181 1 hiro
                                /* Set check boxes */
182 1 hiro
                                edit_jpilot_fill_check_box( jpf );
183 1 hiro
                                flg = TRUE;
184 1 hiro
                        }
185 1 hiro
                        jpilot_free( jpf );
186 1 hiro
                        jpf = NULL;
187 1 hiro
                }
188 411 hiro
                g_free( sFSFile );
189 411 hiro
                g_free( sFile );
190 1 hiro
        }
191 1 hiro
        if( ! flg ) {
192 1 hiro
                /* Clear all check boxes */
193 1 hiro
                edit_jpilot_fill_check_box_new();
194 1 hiro
        }
195 1 hiro
196 1 hiro
        /* Display appropriate message */
197 1 hiro
        if( t == MGU_SUCCESS ) {
198 1 hiro
                sMsg = "";
199 1 hiro
        }
200 1 hiro
        else if( t == MGU_BAD_FORMAT || t == MGU_OO_MEMORY ) {
201 1 hiro
                sMsg = _("File does not appear to be JPilot format.");
202 1 hiro
        }
203 1 hiro
        else {
204 1 hiro
                sMsg = _("Could not read file.");
205 1 hiro
        }
206 1 hiro
        edit_jpilot_status_show( sMsg );
207 1 hiro
}
208 1 hiro
209 1 hiro
static void edit_jpilot_file_select( void ) {
210 1 hiro
        gchar *sFile;
211 411 hiro
        gchar *sUTF8File;
212 1 hiro
213 411 hiro
        sFile = filesel_select_file( _("Select JPilot File"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN );
214 1 hiro
215 411 hiro
        if( sFile ) {
216 411 hiro
                sUTF8File = conv_filename_to_utf8( sFile );
217 411 hiro
                gtk_entry_set_text( GTK_ENTRY(jpilotedit.file_entry), sUTF8File );
218 411 hiro
                g_free( sUTF8File );
219 411 hiro
                g_free( sFile );
220 411 hiro
                edit_jpilot_file_check();
221 411 hiro
        }
222 1 hiro
}
223 1 hiro
224 1 hiro
static void addressbook_edit_jpilot_create( gboolean *cancelled ) {
225 1 hiro
        GtkWidget *window;
226 1 hiro
        GtkWidget *vbox;
227 1 hiro
        GtkWidget *table;
228 1 hiro
        GtkWidget *label;
229 1 hiro
        GtkWidget *name_entry;
230 1 hiro
        GtkWidget *file_entry;
231 1 hiro
        GtkWidget *vbox_custom;
232 1 hiro
        GtkWidget *frame_custom;
233 1 hiro
        GtkWidget *custom_check[JPILOT_NUM_CUSTOM_LABEL];
234 1 hiro
        GtkWidget *custom_label[JPILOT_NUM_CUSTOM_LABEL];
235 1 hiro
        GtkWidget *hlbox;
236 1 hiro
        GtkWidget *hbbox;
237 1 hiro
        GtkWidget *hsep;
238 1 hiro
        GtkWidget *ok_btn;
239 1 hiro
        GtkWidget *cancel_btn;
240 1 hiro
        GtkWidget *check_btn;
241 1 hiro
        GtkWidget *file_btn;
242 1 hiro
        GtkWidget *hsbox;
243 1 hiro
        GtkWidget *statusbar;
244 1 hiro
        gint top, i;
245 1 hiro
246 1 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
247 1 hiro
        gtk_widget_set_size_request(window, 450, -1);
248 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(window), 0);
249 1 hiro
        gtk_window_set_title(GTK_WINDOW(window), _("Edit JPilot Entry"));
250 1 hiro
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
251 1 hiro
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
252 1 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
253 1 hiro
                         G_CALLBACK(edit_jpilot_delete_event),
254 1 hiro
                         cancelled);
255 1 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
256 1 hiro
                         G_CALLBACK(edit_jpilot_key_pressed),
257 1 hiro
                         cancelled);
258 1 hiro
259 1 hiro
        vbox = gtk_vbox_new(FALSE, 8);
260 1 hiro
        gtk_container_add(GTK_CONTAINER(window), vbox);
261 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER(vbox), 0 );
262 1 hiro
263 1 hiro
        table = gtk_table_new(2 + JPILOT_NUM_CUSTOM_LABEL, 3, FALSE);
264 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
265 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
266 1 hiro
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
267 1 hiro
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
268 1 hiro
269 1 hiro
        /* First row */
270 1 hiro
        top = 0;
271 1 hiro
        label = gtk_label_new(_("Name"));
272 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
273 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
274 1 hiro
275 1 hiro
        name_entry = gtk_entry_new();
276 1 hiro
        gtk_table_attach(GTK_TABLE(table), name_entry, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
277 1 hiro
278 1 hiro
        check_btn = gtk_button_new_with_label( _(" Check File "));
279 1 hiro
        gtk_table_attach(GTK_TABLE(table), check_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
280 1 hiro
281 1 hiro
        /* Second row */
282 1 hiro
        top = 1;
283 1 hiro
        label = gtk_label_new(_("File"));
284 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
285 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
286 1 hiro
287 1 hiro
        file_entry = gtk_entry_new();
288 1 hiro
        gtk_table_attach(GTK_TABLE(table), file_entry, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
289 1 hiro
290 1 hiro
        file_btn = gtk_button_new_with_label( _(" ... "));
291 1 hiro
        gtk_table_attach(GTK_TABLE(table), file_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
292 1 hiro
293 1 hiro
        /* Third row */
294 1 hiro
        top = 2;
295 1 hiro
        frame_custom = gtk_frame_new(_("Additional e-Mail address item(s)"));
296 1 hiro
        gtk_table_attach(GTK_TABLE(table), frame_custom, 1, 2, top, (top + JPILOT_NUM_CUSTOM_LABEL), GTK_FILL, 0, 0, 0);
297 1 hiro
298 1 hiro
        /* Now do custom labels. */
299 1 hiro
        vbox_custom = gtk_vbox_new (FALSE, 8);
300 1 hiro
        for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
301 1 hiro
                hlbox = gtk_hbox_new( FALSE, 0 );
302 1 hiro
                custom_check[i] = gtk_check_button_new();
303 1 hiro
                custom_label[i] = gtk_label_new( "" );
304 1 hiro
                gtk_box_pack_start( GTK_BOX(hlbox), custom_check[i], FALSE, FALSE, 0 );
305 1 hiro
                gtk_box_pack_start( GTK_BOX(hlbox), custom_label[i], TRUE, TRUE, 0 );
306 1 hiro
                gtk_box_pack_start( GTK_BOX(vbox_custom), hlbox, TRUE, TRUE, 0 );
307 1 hiro
                gtk_misc_set_alignment(GTK_MISC(custom_label[i]), 0, 0.5);
308 1 hiro
                top++;
309 1 hiro
        }
310 1 hiro
        gtk_container_add (GTK_CONTAINER (frame_custom), vbox_custom);
311 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER(vbox_custom), 8 );
312 1 hiro
313 1 hiro
        /* Status line */
314 1 hiro
        hsbox = gtk_hbox_new(FALSE, 0);
315 1040 hiro
        gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, 0);
316 1 hiro
        statusbar = gtk_statusbar_new();
317 1040 hiro
        gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, 0);
318 1 hiro
319 1 hiro
        /* Button panel */
320 31 hiro
        gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
321 31 hiro
                                      &cancel_btn, GTK_STOCK_CANCEL,
322 31 hiro
                                      NULL, NULL);
323 1 hiro
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
324 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER(hbbox), 0 );
325 1 hiro
        gtk_widget_grab_default(ok_btn);
326 1 hiro
327 1 hiro
        hsep = gtk_hseparator_new();
328 1 hiro
        gtk_box_pack_end(GTK_BOX(vbox), hsep, FALSE, FALSE, 0);
329 1 hiro
330 1 hiro
        g_signal_connect(G_OBJECT(ok_btn), "clicked",
331 1 hiro
                         G_CALLBACK(edit_jpilot_ok), cancelled);
332 1 hiro
        g_signal_connect(G_OBJECT(cancel_btn), "clicked",
333 1 hiro
                         G_CALLBACK(edit_jpilot_cancel), cancelled);
334 1 hiro
        g_signal_connect(G_OBJECT(file_btn), "clicked",
335 1 hiro
                         G_CALLBACK(edit_jpilot_file_select), NULL);
336 1 hiro
        g_signal_connect(G_OBJECT(check_btn), "clicked",
337 1 hiro
                         G_CALLBACK(edit_jpilot_file_check), NULL);
338 1 hiro
339 1 hiro
        gtk_widget_show_all(vbox);
340 1 hiro
341 1 hiro
        jpilotedit.window     = window;
342 1 hiro
        jpilotedit.name_entry = name_entry;
343 1 hiro
        jpilotedit.file_entry = file_entry;
344 405 hiro
        jpilotedit.hbbox      = hbbox;
345 1 hiro
        jpilotedit.ok_btn     = ok_btn;
346 1 hiro
        jpilotedit.cancel_btn = cancel_btn;
347 1 hiro
        jpilotedit.statusbar  = statusbar;
348 1 hiro
        jpilotedit.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Edit JPilot Dialog" );
349 1 hiro
        for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
350 1 hiro
                jpilotedit.custom_check[i] = custom_check[i];
351 1 hiro
                jpilotedit.custom_label[i] = custom_label[i];
352 1 hiro
        }
353 1 hiro
}
354 1 hiro
355 1 hiro
AdapterDSource *addressbook_edit_jpilot( AddressIndex *addrIndex, AdapterDSource *ads ) {
356 1 hiro
        static gboolean cancelled;
357 1 hiro
        gchar *sName;
358 1 hiro
        gchar *sFile;
359 411 hiro
        gchar *sFSFile;
360 1 hiro
        AddressDataSource *ds = NULL;
361 1 hiro
        JPilotFile *jpf = NULL;
362 1 hiro
        gboolean fin;
363 1 hiro
364 1 hiro
        if( ! jpilotedit.window )
365 1 hiro
                addressbook_edit_jpilot_create(&cancelled);
366 405 hiro
        gtkut_box_set_reverse_order(GTK_BOX(jpilotedit.hbbox),
367 405 hiro
                                    !prefs_common.comply_gnome_hig);
368 1 hiro
        gtk_widget_grab_focus(jpilotedit.ok_btn);
369 1 hiro
        gtk_widget_grab_focus(jpilotedit.name_entry);
370 1 hiro
        gtk_widget_show(jpilotedit.window);
371 1 hiro
        manage_window_set_transient(GTK_WINDOW(jpilotedit.window));
372 1 hiro
373 1 hiro
        edit_jpilot_status_show( "" );
374 1 hiro
        if( ads ) {
375 1 hiro
                ds = ads->dataSource;
376 1 hiro
                jpf = ds->rawDataSource;
377 1 hiro
                if (jpf->name)
378 1 hiro
                        gtk_entry_set_text(GTK_ENTRY(jpilotedit.name_entry), jpf->name);
379 1 hiro
                if (jpf->path)
380 1 hiro
                        gtk_entry_set_text(GTK_ENTRY(jpilotedit.file_entry), jpf->path);
381 1 hiro
                gtk_window_set_title( GTK_WINDOW(jpilotedit.window), _("Edit JPilot Entry"));
382 1 hiro
                edit_jpilot_fill_check_box( jpf );
383 1 hiro
        }
384 1 hiro
        else {
385 1 hiro
                gchar *guessFile = jpilot_find_pilotdb();
386 1 hiro
                gtk_entry_set_text(GTK_ENTRY(jpilotedit.name_entry), ADDRESSBOOK_GUESS_JPILOT );
387 1 hiro
                gtk_entry_set_text(GTK_ENTRY(jpilotedit.file_entry), guessFile );
388 1 hiro
                gtk_window_set_title( GTK_WINDOW(jpilotedit.window), _("Add New JPilot Entry"));
389 1 hiro
                edit_jpilot_fill_check_box_new();
390 1 hiro
                if( *guessFile != '\0' ) {
391 1 hiro
                        edit_jpilot_file_check();
392 1 hiro
                }
393 1 hiro
        }
394 1 hiro
395 1 hiro
        gtk_main();
396 1 hiro
        gtk_widget_hide(jpilotedit.window);
397 1 hiro
        if (cancelled == TRUE) return NULL;
398 1 hiro
399 1 hiro
        fin = FALSE;
400 1 hiro
        sName = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.name_entry), 0, -1 );
401 1 hiro
        sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
402 411 hiro
        sFSFile = conv_filename_from_utf8( sFile );
403 1 hiro
        if( *sName == '\0' ) fin = TRUE;
404 1 hiro
        if( *sFile == '\0' ) fin = TRUE;
405 411 hiro
        if( ! sFSFile || *sFSFile == '\0' ) fin = TRUE;
406 1 hiro
407 1 hiro
        if( ! fin ) {
408 1 hiro
                if( ! ads ) {
409 1 hiro
                        jpf = jpilot_create();
410 1 hiro
                        ds = addrindex_index_add_datasource( addrIndex, ADDR_IF_JPILOT, jpf );
411 1 hiro
                        ads = addressbook_create_ds_adapter( ds, ADDR_JPILOT, NULL );
412 1 hiro
                }
413 1 hiro
                addressbook_ads_set_name( ads, sName );
414 1 hiro
                jpilot_set_name( jpf, sName );
415 411 hiro
                jpilot_set_file( jpf, sFSFile );
416 1 hiro
                edit_jpilot_read_check_box( jpf );
417 1 hiro
        }
418 411 hiro
        g_free( sFSFile );
419 1 hiro
        g_free( sFile );
420 411 hiro
        g_free( sName );
421 1 hiro
422 1 hiro
        return ads;
423 1 hiro
}
424 1 hiro
425 1 hiro
#endif /* USE_JPILOT */
426 1 hiro
427 1 hiro
/*
428 1 hiro
* End of Source.
429 1 hiro
*/