Statistics
| Revision:

root / src / export.c @ 422

History | View | Annotate | Download (7.5 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 31 hiro
 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
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
#ifdef HAVE_CONFIG_H
21 1 hiro
#  include "config.h"
22 1 hiro
#endif
23 1 hiro
24 1 hiro
#include "defs.h"
25 1 hiro
26 1 hiro
#include <glib.h>
27 92 hiro
#include <glib/gi18n.h>
28 1 hiro
#include <gdk/gdkkeysyms.h>
29 1 hiro
#include <gtk/gtkmain.h>
30 1 hiro
#include <gtk/gtkwidget.h>
31 1 hiro
#include <gtk/gtkwindow.h>
32 1 hiro
#include <gtk/gtkvbox.h>
33 1 hiro
#include <gtk/gtktable.h>
34 1 hiro
#include <gtk/gtklabel.h>
35 1 hiro
#include <gtk/gtkentry.h>
36 1 hiro
#include <gtk/gtkhbbox.h>
37 1 hiro
#include <gtk/gtkbutton.h>
38 1 hiro
#include <gtk/gtkfilesel.h>
39 1 hiro
#include <gtk/gtksignal.h>
40 1 hiro
41 1 hiro
#include "main.h"
42 1 hiro
#include "inc.h"
43 1 hiro
#include "mbox.h"
44 1 hiro
#include "filesel.h"
45 1 hiro
#include "foldersel.h"
46 1 hiro
#include "gtkutils.h"
47 1 hiro
#include "manage_window.h"
48 1 hiro
#include "folder.h"
49 1 hiro
#include "utils.h"
50 1 hiro
51 1 hiro
static GtkWidget *window;
52 1 hiro
static GtkWidget *src_entry;
53 1 hiro
static GtkWidget *file_entry;
54 1 hiro
static GtkWidget *src_button;
55 1 hiro
static GtkWidget *file_button;
56 1 hiro
static GtkWidget *ok_button;
57 1 hiro
static GtkWidget *cancel_button;
58 1 hiro
static gboolean export_ack;
59 1 hiro
60 1 hiro
static void export_create(void);
61 1 hiro
static void export_ok_cb(GtkWidget *widget, gpointer data);
62 1 hiro
static void export_cancel_cb(GtkWidget *widget, gpointer data);
63 1 hiro
static void export_srcsel_cb(GtkWidget *widget, gpointer data);
64 1 hiro
static void export_filesel_cb(GtkWidget *widget, gpointer data);
65 1 hiro
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data);
66 1 hiro
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
67 1 hiro
68 1 hiro
gint export_mbox(FolderItem *default_src)
69 1 hiro
{
70 1 hiro
        gint ok = 0;
71 1 hiro
        gchar *src_id = NULL;
72 1 hiro
73 1 hiro
        if (!window)
74 1 hiro
                export_create();
75 1 hiro
        else
76 1 hiro
                gtk_widget_show(window);
77 1 hiro
78 1 hiro
        change_dir(startup_dir);
79 1 hiro
80 1 hiro
        if (default_src && default_src->path)
81 1 hiro
                src_id = folder_item_get_identifier(default_src);
82 1 hiro
83 1 hiro
        if (src_id) {
84 1 hiro
                gtk_entry_set_text(GTK_ENTRY(src_entry), src_id);
85 1 hiro
                g_free(src_id);
86 1 hiro
        } else
87 1 hiro
                gtk_entry_set_text(GTK_ENTRY(src_entry), "");
88 1 hiro
        gtk_entry_set_text(GTK_ENTRY(file_entry), "");
89 1 hiro
        gtk_widget_grab_focus(file_entry);
90 1 hiro
91 1 hiro
        manage_window_set_transient(GTK_WINDOW(window));
92 1 hiro
93 1 hiro
        gtk_main();
94 1 hiro
95 1 hiro
        if (export_ack) {
96 1 hiro
                const gchar *srcdir, *utf8mbox;
97 1 hiro
                FolderItem *src;
98 1 hiro
99 1 hiro
                srcdir = gtk_entry_get_text(GTK_ENTRY(src_entry));
100 1 hiro
                utf8mbox = gtk_entry_get_text(GTK_ENTRY(file_entry));
101 1 hiro
102 1 hiro
                if (utf8mbox && *utf8mbox) {
103 1 hiro
                        gchar *mbox;
104 1 hiro
105 1 hiro
                        mbox = g_filename_from_utf8
106 1 hiro
                                (utf8mbox, -1, NULL, NULL, NULL);
107 1 hiro
                        if (!mbox) {
108 1 hiro
                                g_warning("faild to convert character set\n");
109 1 hiro
                                mbox = g_strdup(utf8mbox);
110 1 hiro
                        }
111 1 hiro
112 1 hiro
                        src = folder_find_item_from_identifier(srcdir);
113 1 hiro
                        if (!src)
114 1 hiro
                                g_warning("Can't find the folder.\n");
115 1 hiro
                        else
116 1 hiro
                                ok = export_to_mbox(src, mbox);
117 1 hiro
118 1 hiro
                        g_free(mbox);
119 1 hiro
                }
120 1 hiro
        }
121 1 hiro
122 1 hiro
        gtk_widget_hide(window);
123 1 hiro
124 1 hiro
        return ok;
125 1 hiro
}
126 1 hiro
127 1 hiro
static void export_create(void)
128 1 hiro
{
129 1 hiro
        GtkWidget *vbox;
130 1 hiro
        GtkWidget *hbox;
131 1 hiro
        GtkWidget *desc_label;
132 1 hiro
        GtkWidget *table;
133 1 hiro
        GtkWidget *file_label;
134 1 hiro
        GtkWidget *src_label;
135 1 hiro
        GtkWidget *confirm_area;
136 1 hiro
137 1 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
138 1 hiro
        gtk_window_set_title(GTK_WINDOW(window), _("Export"));
139 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(window), 5);
140 1 hiro
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
141 1 hiro
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
142 1 hiro
        gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
143 1 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
144 1 hiro
                         G_CALLBACK(delete_event), NULL);
145 1 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
146 1 hiro
                         G_CALLBACK(key_pressed), NULL);
147 1 hiro
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
148 1 hiro
149 1 hiro
        vbox = gtk_vbox_new(FALSE, 4);
150 1 hiro
        gtk_container_add(GTK_CONTAINER(window), vbox);
151 1 hiro
152 1 hiro
        hbox = gtk_hbox_new(FALSE, 0);
153 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
154 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
155 1 hiro
156 1 hiro
        desc_label = gtk_label_new
157 1 hiro
                (_("Specify target folder and mbox file."));
158 1 hiro
        gtk_box_pack_start(GTK_BOX(hbox), desc_label, FALSE, FALSE, 0);
159 1 hiro
160 1 hiro
        table = gtk_table_new(2, 3, FALSE);
161 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
162 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(table), 8);
163 1 hiro
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
164 1 hiro
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
165 1 hiro
        gtk_widget_set_size_request(table, 420, -1);
166 1 hiro
167 1 hiro
        src_label = gtk_label_new(_("Source dir:"));
168 1 hiro
        gtk_table_attach(GTK_TABLE(table), src_label, 0, 1, 0, 1,
169 1 hiro
                         GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
170 1 hiro
        gtk_misc_set_alignment(GTK_MISC(src_label), 1, 0.5);
171 1 hiro
172 1 hiro
        file_label = gtk_label_new(_("Exporting file:"));
173 1 hiro
        gtk_table_attach(GTK_TABLE(table), file_label, 0, 1, 1, 2,
174 1 hiro
                         GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
175 1 hiro
        gtk_misc_set_alignment(GTK_MISC(file_label), 1, 0.5);
176 1 hiro
177 1 hiro
        src_entry = gtk_entry_new();
178 1 hiro
        gtk_table_attach(GTK_TABLE(table), src_entry, 1, 2, 0, 1,
179 1 hiro
                         GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
180 1 hiro
181 1 hiro
        file_entry = gtk_entry_new();
182 1 hiro
        gtk_table_attach(GTK_TABLE(table), file_entry, 1, 2, 1, 2,
183 1 hiro
                         GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
184 1 hiro
185 1 hiro
        src_button = gtk_button_new_with_label(_(" Select... "));
186 1 hiro
        gtk_table_attach(GTK_TABLE(table), src_button, 2, 3, 0, 1,
187 1 hiro
                         0, 0, 0, 0);
188 1 hiro
        g_signal_connect(G_OBJECT(src_button), "clicked",
189 1 hiro
                         G_CALLBACK(export_srcsel_cb), NULL);
190 1 hiro
191 1 hiro
        file_button = gtk_button_new_with_label(_(" Select... "));
192 1 hiro
        gtk_table_attach(GTK_TABLE(table), file_button, 2, 3, 1, 2,
193 1 hiro
                         0, 0, 0, 0);
194 1 hiro
        g_signal_connect(G_OBJECT(file_button), "clicked",
195 1 hiro
                         G_CALLBACK(export_filesel_cb), NULL);
196 1 hiro
197 31 hiro
        gtkut_stock_button_set_create(&confirm_area,
198 31 hiro
                                      &ok_button, GTK_STOCK_OK,
199 31 hiro
                                      &cancel_button, GTK_STOCK_CANCEL,
200 31 hiro
                                      NULL, NULL);
201 1 hiro
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
202 1 hiro
        gtk_widget_grab_default(ok_button);
203 1 hiro
204 1 hiro
        g_signal_connect(G_OBJECT(ok_button), "clicked",
205 1 hiro
                         G_CALLBACK(export_ok_cb), NULL);
206 1 hiro
        g_signal_connect(G_OBJECT(cancel_button), "clicked",
207 1 hiro
                         G_CALLBACK(export_cancel_cb), NULL);
208 1 hiro
209 1 hiro
        gtk_widget_show_all(window);
210 1 hiro
}
211 1 hiro
212 1 hiro
static void export_ok_cb(GtkWidget *widget, gpointer data)
213 1 hiro
{
214 1 hiro
        export_ack = TRUE;
215 1 hiro
        if (gtk_main_level() > 1)
216 1 hiro
                gtk_main_quit();
217 1 hiro
}
218 1 hiro
219 1 hiro
static void export_cancel_cb(GtkWidget *widget, gpointer data)
220 1 hiro
{
221 1 hiro
        export_ack = FALSE;
222 1 hiro
        if (gtk_main_level() > 1)
223 1 hiro
                gtk_main_quit();
224 1 hiro
}
225 1 hiro
226 1 hiro
static void export_filesel_cb(GtkWidget *widget, gpointer data)
227 1 hiro
{
228 128 hiro
        gchar *filename;
229 1 hiro
        gchar *utf8_filename;
230 1 hiro
231 128 hiro
        filename = filesel_select_file(_("Select exporting file"), NULL,
232 128 hiro
                                       GTK_FILE_CHOOSER_ACTION_SAVE);
233 1 hiro
        if (!filename) return;
234 1 hiro
235 1 hiro
        utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
236 1 hiro
        if (!utf8_filename) {
237 1 hiro
                g_warning("export_filesel_cb(): faild to convert character set.\n");
238 1 hiro
                utf8_filename = g_strdup(filename);
239 1 hiro
        }
240 1 hiro
        gtk_entry_set_text(GTK_ENTRY(file_entry), utf8_filename);
241 1 hiro
        g_free(utf8_filename);
242 128 hiro
243 128 hiro
        g_free(filename);
244 1 hiro
}
245 1 hiro
246 1 hiro
static void export_srcsel_cb(GtkWidget *widget, gpointer data)
247 1 hiro
{
248 1 hiro
        FolderItem *src;
249 1 hiro
250 1 hiro
        src = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
251 1 hiro
        if (src && src->path)
252 1 hiro
                gtk_entry_set_text(GTK_ENTRY(src_entry), src->path);
253 1 hiro
}
254 1 hiro
255 1 hiro
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
256 1 hiro
{
257 1 hiro
        export_cancel_cb(NULL, NULL);
258 1 hiro
        return TRUE;
259 1 hiro
}
260 1 hiro
261 1 hiro
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
262 1 hiro
{
263 1 hiro
        if (event && event->keyval == GDK_Escape)
264 1 hiro
                export_cancel_cb(NULL, NULL);
265 1 hiro
        return FALSE;
266 1 hiro
}