root / src / export.c @ 2388
History | View | Annotate | Download (13.1 kB)
| 1 | 1 | hiro | /*
|
|---|---|---|---|
| 2 | 1 | hiro | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | 2205 | hiro | * Copyright (C) 1999-2009 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 | 2210 | hiro | #include <gtk/gtkmenu.h> |
| 35 | 2210 | hiro | #include <gtk/gtkmenuitem.h> |
| 36 | 2210 | hiro | #include <gtk/gtkoptionmenu.h> |
| 37 | 1 | hiro | #include <gtk/gtklabel.h> |
| 38 | 1 | hiro | #include <gtk/gtkentry.h> |
| 39 | 1 | hiro | #include <gtk/gtkhbbox.h> |
| 40 | 1 | hiro | #include <gtk/gtkbutton.h> |
| 41 | 2205 | hiro | #include <gtk/gtkprogressbar.h> |
| 42 | 1 | hiro | |
| 43 | 1 | hiro | #include "main.h" |
| 44 | 1 | hiro | #include "inc.h" |
| 45 | 1 | hiro | #include "mbox.h" |
| 46 | 2210 | hiro | #include "folder.h" |
| 47 | 2210 | hiro | #include "procmsg.h" |
| 48 | 2210 | hiro | #include "menu.h" |
| 49 | 1 | hiro | #include "filesel.h" |
| 50 | 1 | hiro | #include "foldersel.h" |
| 51 | 1 | hiro | #include "gtkutils.h" |
| 52 | 1 | hiro | #include "manage_window.h" |
| 53 | 1 | hiro | #include "folder.h" |
| 54 | 1 | hiro | #include "utils.h" |
| 55 | 2205 | hiro | #include "progressdialog.h" |
| 56 | 2205 | hiro | #include "alertpanel.h" |
| 57 | 1 | hiro | |
| 58 | 2210 | hiro | enum
|
| 59 | 2210 | hiro | {
|
| 60 | 2210 | hiro | EXPORT_MBOX, |
| 61 | 2210 | hiro | EXPORT_EML, |
| 62 | 2210 | hiro | EXPORT_MH |
| 63 | 2210 | hiro | }; |
| 64 | 2210 | hiro | |
| 65 | 1 | hiro | static GtkWidget *window;
|
| 66 | 2210 | hiro | static GtkWidget *format_optmenu;
|
| 67 | 2210 | hiro | static GtkWidget *desc_label;
|
| 68 | 2210 | hiro | static GtkWidget *file_label;
|
| 69 | 1 | hiro | static GtkWidget *src_entry;
|
| 70 | 1 | hiro | static GtkWidget *file_entry;
|
| 71 | 1 | hiro | static GtkWidget *src_button;
|
| 72 | 1 | hiro | static GtkWidget *file_button;
|
| 73 | 1 | hiro | static GtkWidget *ok_button;
|
| 74 | 1 | hiro | static GtkWidget *cancel_button;
|
| 75 | 903 | hiro | static gboolean export_finished;
|
| 76 | 1 | hiro | static gboolean export_ack;
|
| 77 | 2205 | hiro | static ProgressDialog *progress;
|
| 78 | 1 | hiro | |
| 79 | 903 | hiro | static void export_create (void); |
| 80 | 2205 | hiro | static gint export_do (void); |
| 81 | 2210 | hiro | static gint export_eml (FolderItem *src,
|
| 82 | 2210 | hiro | const gchar *path,
|
| 83 | 2210 | hiro | gint type); |
| 84 | 2210 | hiro | |
| 85 | 2210 | hiro | static void export_format_menu_cb (GtkWidget *widget, |
| 86 | 2210 | hiro | gpointer data); |
| 87 | 2210 | hiro | |
| 88 | 903 | hiro | static void export_ok_cb (GtkWidget *widget, |
| 89 | 903 | hiro | gpointer data); |
| 90 | 903 | hiro | static void export_cancel_cb (GtkWidget *widget, |
| 91 | 903 | hiro | gpointer data); |
| 92 | 903 | hiro | static void export_srcsel_cb (GtkWidget *widget, |
| 93 | 903 | hiro | gpointer data); |
| 94 | 903 | hiro | static void export_filesel_cb (GtkWidget *widget, |
| 95 | 903 | hiro | gpointer data); |
| 96 | 903 | hiro | static gint delete_event (GtkWidget *widget,
|
| 97 | 903 | hiro | GdkEventAny *event, |
| 98 | 903 | hiro | gpointer data); |
| 99 | 903 | hiro | static gboolean key_pressed (GtkWidget *widget,
|
| 100 | 903 | hiro | GdkEventKey *event, |
| 101 | 903 | hiro | gpointer data); |
| 102 | 1 | hiro | |
| 103 | 2205 | hiro | |
| 104 | 2205 | hiro | static void export_mbox_func(Folder *folder, FolderItem *item, gpointer data) |
| 105 | 1 | hiro | {
|
| 106 | 2205 | hiro | gchar str[64];
|
| 107 | 2205 | hiro | gint count = GPOINTER_TO_INT(data); |
| 108 | 2205 | hiro | static GTimeVal tv_prev = {0, 0}; |
| 109 | 2205 | hiro | GTimeVal tv_cur; |
| 110 | 2205 | hiro | |
| 111 | 2205 | hiro | g_get_current_time(&tv_cur); |
| 112 | 2205 | hiro | if (item->total > 0) |
| 113 | 2205 | hiro | g_snprintf(str, sizeof(str), "%d / %d", count, item->total); |
| 114 | 2205 | hiro | else
|
| 115 | 2205 | hiro | g_snprintf(str, sizeof(str), "%d", count); |
| 116 | 2205 | hiro | gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->progressbar), str); |
| 117 | 2205 | hiro | |
| 118 | 2205 | hiro | if (tv_prev.tv_sec == 0 || |
| 119 | 2205 | hiro | (tv_cur.tv_sec - tv_prev.tv_sec) * G_USEC_PER_SEC + |
| 120 | 2205 | hiro | tv_cur.tv_usec - tv_prev.tv_usec > 100 * 1000) { |
| 121 | 2205 | hiro | if (item->total > 0) |
| 122 | 2205 | hiro | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progressbar), (gdouble)count / item->total); |
| 123 | 2205 | hiro | else
|
| 124 | 2205 | hiro | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress->progressbar)); |
| 125 | 2205 | hiro | ui_update(); |
| 126 | 2205 | hiro | tv_prev = tv_cur; |
| 127 | 2205 | hiro | } |
| 128 | 2205 | hiro | } |
| 129 | 2205 | hiro | |
| 130 | 2205 | hiro | gint export_mail(FolderItem *default_src) |
| 131 | 2205 | hiro | {
|
| 132 | 1 | hiro | gint ok = 0;
|
| 133 | 1 | hiro | gchar *src_id = NULL;
|
| 134 | 1 | hiro | |
| 135 | 903 | hiro | export_create(); |
| 136 | 1 | hiro | |
| 137 | 667 | hiro | change_dir(get_startup_dir()); |
| 138 | 1 | hiro | |
| 139 | 1 | hiro | if (default_src && default_src->path)
|
| 140 | 1 | hiro | src_id = folder_item_get_identifier(default_src); |
| 141 | 1 | hiro | |
| 142 | 1 | hiro | if (src_id) {
|
| 143 | 1 | hiro | gtk_entry_set_text(GTK_ENTRY(src_entry), src_id); |
| 144 | 1 | hiro | g_free(src_id); |
| 145 | 903 | hiro | } |
| 146 | 1 | hiro | gtk_widget_grab_focus(file_entry); |
| 147 | 1 | hiro | |
| 148 | 1 | hiro | manage_window_set_transient(GTK_WINDOW(window)); |
| 149 | 1 | hiro | |
| 150 | 903 | hiro | export_finished = FALSE; |
| 151 | 903 | hiro | export_ack = FALSE; |
| 152 | 1 | hiro | |
| 153 | 2205 | hiro | inc_lock(); |
| 154 | 2205 | hiro | |
| 155 | 903 | hiro | while (!export_finished)
|
| 156 | 903 | hiro | gtk_main_iteration(); |
| 157 | 903 | hiro | |
| 158 | 2205 | hiro | if (export_ack)
|
| 159 | 2205 | hiro | ok = export_do(); |
| 160 | 1 | hiro | |
| 161 | 2205 | hiro | gtk_widget_destroy(window); |
| 162 | 2205 | hiro | window = NULL;
|
| 163 | 2205 | hiro | src_entry = file_entry = NULL;
|
| 164 | 2205 | hiro | src_button = file_button = ok_button = cancel_button = NULL;
|
| 165 | 1 | hiro | |
| 166 | 2205 | hiro | inc_unlock(); |
| 167 | 1 | hiro | |
| 168 | 2205 | hiro | return ok;
|
| 169 | 2205 | hiro | } |
| 170 | 1 | hiro | |
| 171 | 2205 | hiro | static gint export_do(void) |
| 172 | 2205 | hiro | {
|
| 173 | 2205 | hiro | gint ok = 0;
|
| 174 | 2205 | hiro | const gchar *srcdir, *utf8mbox;
|
| 175 | 2205 | hiro | FolderItem *src; |
| 176 | 2205 | hiro | gchar *mbox; |
| 177 | 2205 | hiro | gchar *msg; |
| 178 | 2210 | hiro | gint type; |
| 179 | 1 | hiro | |
| 180 | 2210 | hiro | type = menu_get_option_menu_active_index |
| 181 | 2210 | hiro | (GTK_OPTION_MENU(format_optmenu)); |
| 182 | 2210 | hiro | |
| 183 | 2205 | hiro | srcdir = gtk_entry_get_text(GTK_ENTRY(src_entry)); |
| 184 | 2205 | hiro | utf8mbox = gtk_entry_get_text(GTK_ENTRY(file_entry)); |
| 185 | 2205 | hiro | |
| 186 | 2205 | hiro | if (!utf8mbox || !*utf8mbox)
|
| 187 | 2205 | hiro | return -1; |
| 188 | 2205 | hiro | |
| 189 | 2205 | hiro | mbox = g_filename_from_utf8(utf8mbox, -1, NULL, NULL, NULL); |
| 190 | 2205 | hiro | if (!mbox) {
|
| 191 | 2205 | hiro | g_warning("failed to convert character set.");
|
| 192 | 2205 | hiro | mbox = g_strdup(utf8mbox); |
| 193 | 1 | hiro | } |
| 194 | 1 | hiro | |
| 195 | 2205 | hiro | src = folder_find_item_from_identifier(srcdir); |
| 196 | 2205 | hiro | if (!src) {
|
| 197 | 2205 | hiro | g_warning("Can't find the folder.");
|
| 198 | 2205 | hiro | g_free(mbox); |
| 199 | 2205 | hiro | return -1; |
| 200 | 2205 | hiro | } |
| 201 | 1 | hiro | |
| 202 | 2205 | hiro | msg = g_strdup_printf(_("Exporting %s ..."), g_basename(srcdir));
|
| 203 | 2205 | hiro | progress = progress_dialog_simple_create(); |
| 204 | 2205 | hiro | gtk_window_set_title(GTK_WINDOW(progress->window), _("Exporting"));
|
| 205 | 2205 | hiro | progress_dialog_set_label(progress, msg); |
| 206 | 2205 | hiro | g_free(msg); |
| 207 | 2205 | hiro | gtk_window_set_modal(GTK_WINDOW(progress->window), TRUE); |
| 208 | 2205 | hiro | manage_window_set_transient(GTK_WINDOW(progress->window)); |
| 209 | 2205 | hiro | gtk_widget_hide(progress->cancel_btn); |
| 210 | 2205 | hiro | g_signal_connect(G_OBJECT(progress->window), "delete_event",
|
| 211 | 2205 | hiro | G_CALLBACK(gtk_true), NULL);
|
| 212 | 2205 | hiro | gtk_widget_show(progress->window); |
| 213 | 2205 | hiro | ui_update(); |
| 214 | 2205 | hiro | |
| 215 | 2210 | hiro | if (type == EXPORT_MBOX) {
|
| 216 | 2210 | hiro | folder_set_ui_func(src->folder, export_mbox_func, NULL);
|
| 217 | 2210 | hiro | ok = export_to_mbox(src, mbox); |
| 218 | 2210 | hiro | folder_set_ui_func(src->folder, NULL, NULL); |
| 219 | 2210 | hiro | } else if (type == EXPORT_EML || type == EXPORT_MH) { |
| 220 | 2210 | hiro | ok = export_eml(src, mbox, type); |
| 221 | 2210 | hiro | } |
| 222 | 2205 | hiro | |
| 223 | 2205 | hiro | progress_dialog_destroy(progress); |
| 224 | 2205 | hiro | progress = NULL;
|
| 225 | 2205 | hiro | |
| 226 | 2205 | hiro | g_free(mbox); |
| 227 | 2205 | hiro | |
| 228 | 2205 | hiro | if (ok < 0) |
| 229 | 2205 | hiro | alertpanel_error(_("Error occurred on export."));
|
| 230 | 2205 | hiro | |
| 231 | 1 | hiro | return ok;
|
| 232 | 1 | hiro | } |
| 233 | 1 | hiro | |
| 234 | 2210 | hiro | static gint export_eml(FolderItem *src, const gchar *path, gint type) |
| 235 | 2210 | hiro | {
|
| 236 | 2210 | hiro | const gchar *ext = ""; |
| 237 | 2210 | hiro | GSList *mlist, *cur; |
| 238 | 2210 | hiro | MsgInfo *msginfo; |
| 239 | 2210 | hiro | gchar *file, *dest; |
| 240 | 2210 | hiro | gint count = 0;
|
| 241 | 2210 | hiro | gint ok = 0;
|
| 242 | 2210 | hiro | |
| 243 | 2210 | hiro | g_return_val_if_fail(src != NULL, -1); |
| 244 | 2210 | hiro | g_return_val_if_fail(path != NULL, -1); |
| 245 | 2210 | hiro | |
| 246 | 2210 | hiro | if (type == EXPORT_EML)
|
| 247 | 2210 | hiro | ext = ".eml";
|
| 248 | 2210 | hiro | |
| 249 | 2210 | hiro | if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
|
| 250 | 2210 | hiro | if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
|
| 251 | 2210 | hiro | make_dir_hier(path); |
| 252 | 2210 | hiro | if (!g_file_test(path, G_FILE_TEST_IS_DIR))
|
| 253 | 2210 | hiro | return -1; |
| 254 | 2210 | hiro | } else {
|
| 255 | 2210 | hiro | g_warning("export_eml(): directory %s already exists.",
|
| 256 | 2210 | hiro | path); |
| 257 | 2210 | hiro | return -1; |
| 258 | 2210 | hiro | } |
| 259 | 2210 | hiro | } |
| 260 | 2210 | hiro | |
| 261 | 2210 | hiro | mlist = folder_item_get_msg_list(src, TRUE); |
| 262 | 2210 | hiro | if (!mlist)
|
| 263 | 2210 | hiro | return 0; |
| 264 | 2210 | hiro | |
| 265 | 2210 | hiro | for (cur = mlist; cur != NULL; cur = cur->next) { |
| 266 | 2210 | hiro | msginfo = (MsgInfo *)cur->data; |
| 267 | 2210 | hiro | |
| 268 | 2210 | hiro | count++; |
| 269 | 2210 | hiro | export_mbox_func(src->folder, src, GINT_TO_POINTER(count)); |
| 270 | 2210 | hiro | |
| 271 | 2210 | hiro | file = folder_item_fetch_msg(src, msginfo->msgnum); |
| 272 | 2210 | hiro | if (!file) {
|
| 273 | 2210 | hiro | ok = -1;
|
| 274 | 2210 | hiro | break;
|
| 275 | 2210 | hiro | } |
| 276 | 2210 | hiro | dest = g_strdup_printf("%s%c%d%s", path, G_DIR_SEPARATOR,
|
| 277 | 2210 | hiro | count, ext); |
| 278 | 2213 | hiro | if (g_file_test(dest, G_FILE_TEST_EXISTS)) {
|
| 279 | 2213 | hiro | g_warning("export_eml(): %s already exists.", dest);
|
| 280 | 2213 | hiro | g_free(dest); |
| 281 | 2213 | hiro | g_free(file); |
| 282 | 2213 | hiro | ok = -1;
|
| 283 | 2213 | hiro | break;
|
| 284 | 2213 | hiro | } |
| 285 | 2210 | hiro | if (copy_file(file, dest, FALSE) < 0) { |
| 286 | 2210 | hiro | g_free(dest); |
| 287 | 2210 | hiro | g_free(file); |
| 288 | 2210 | hiro | ok = -1;
|
| 289 | 2210 | hiro | break;
|
| 290 | 2210 | hiro | } |
| 291 | 2210 | hiro | g_free(dest); |
| 292 | 2210 | hiro | g_free(file); |
| 293 | 2210 | hiro | } |
| 294 | 2210 | hiro | |
| 295 | 2210 | hiro | procmsg_msg_list_free(mlist); |
| 296 | 2210 | hiro | |
| 297 | 2210 | hiro | return ok;
|
| 298 | 2210 | hiro | } |
| 299 | 2210 | hiro | |
| 300 | 1 | hiro | static void export_create(void) |
| 301 | 1 | hiro | {
|
| 302 | 1 | hiro | GtkWidget *vbox; |
| 303 | 1 | hiro | GtkWidget *hbox; |
| 304 | 1 | hiro | GtkWidget *table; |
| 305 | 2210 | hiro | GtkWidget *menu; |
| 306 | 2210 | hiro | GtkWidget *menuitem; |
| 307 | 2210 | hiro | GtkWidget *format_label; |
| 308 | 1 | hiro | GtkWidget *src_label; |
| 309 | 1 | hiro | GtkWidget *confirm_area; |
| 310 | 1 | hiro | |
| 311 | 1 | hiro | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 312 | 1 | hiro | gtk_window_set_title(GTK_WINDOW(window), _("Export"));
|
| 313 | 1 | hiro | gtk_container_set_border_width(GTK_CONTAINER(window), 5);
|
| 314 | 1 | hiro | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); |
| 315 | 1 | hiro | gtk_window_set_modal(GTK_WINDOW(window), TRUE); |
| 316 | 1 | hiro | gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE); |
| 317 | 1 | hiro | g_signal_connect(G_OBJECT(window), "delete_event",
|
| 318 | 1 | hiro | G_CALLBACK(delete_event), NULL);
|
| 319 | 1 | hiro | g_signal_connect(G_OBJECT(window), "key_press_event",
|
| 320 | 1 | hiro | G_CALLBACK(key_pressed), NULL);
|
| 321 | 1 | hiro | MANAGE_WINDOW_SIGNALS_CONNECT(window); |
| 322 | 1 | hiro | |
| 323 | 1 | hiro | vbox = gtk_vbox_new(FALSE, 4);
|
| 324 | 1 | hiro | gtk_container_add(GTK_CONTAINER(window), vbox); |
| 325 | 1 | hiro | |
| 326 | 1 | hiro | hbox = gtk_hbox_new(FALSE, 0);
|
| 327 | 1 | hiro | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
| 328 | 1 | hiro | gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
|
| 329 | 1 | hiro | |
| 330 | 1 | hiro | desc_label = gtk_label_new |
| 331 | 2205 | hiro | (_("Specify source folder and destination file."));
|
| 332 | 1 | hiro | gtk_box_pack_start(GTK_BOX(hbox), desc_label, FALSE, FALSE, 0);
|
| 333 | 1 | hiro | |
| 334 | 1 | hiro | table = gtk_table_new(2, 3, FALSE); |
| 335 | 1 | hiro | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
|
| 336 | 1 | hiro | gtk_container_set_border_width(GTK_CONTAINER(table), 8);
|
| 337 | 1 | hiro | gtk_table_set_row_spacings(GTK_TABLE(table), 8);
|
| 338 | 1 | hiro | gtk_table_set_col_spacings(GTK_TABLE(table), 8);
|
| 339 | 1 | hiro | gtk_widget_set_size_request(table, 420, -1); |
| 340 | 1 | hiro | |
| 341 | 2210 | hiro | format_label = gtk_label_new(_("File format:"));
|
| 342 | 2210 | hiro | gtk_table_attach(GTK_TABLE(table), format_label, 0, 1, 0, 1, |
| 343 | 2210 | hiro | GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0); |
| 344 | 2210 | hiro | gtk_misc_set_alignment(GTK_MISC(format_label), 1, 0.5); |
| 345 | 2210 | hiro | |
| 346 | 2205 | hiro | src_label = gtk_label_new(_("Source folder:"));
|
| 347 | 2210 | hiro | gtk_table_attach(GTK_TABLE(table), src_label, 0, 1, 1, 2, |
| 348 | 1 | hiro | GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0); |
| 349 | 1 | hiro | gtk_misc_set_alignment(GTK_MISC(src_label), 1, 0.5); |
| 350 | 1 | hiro | |
| 351 | 2210 | hiro | file_label = gtk_label_new(_("Destination:"));
|
| 352 | 2210 | hiro | gtk_table_attach(GTK_TABLE(table), file_label, 0, 1, 2, 3, |
| 353 | 1 | hiro | GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0); |
| 354 | 1 | hiro | gtk_misc_set_alignment(GTK_MISC(file_label), 1, 0.5); |
| 355 | 1 | hiro | |
| 356 | 2210 | hiro | format_optmenu = gtk_option_menu_new(); |
| 357 | 2210 | hiro | gtk_table_attach(GTK_TABLE(table), format_optmenu, 1, 2, 0, 1, |
| 358 | 2210 | hiro | GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); |
| 359 | 2210 | hiro | |
| 360 | 2210 | hiro | menu = gtk_menu_new(); |
| 361 | 2210 | hiro | MENUITEM_ADD(menu, menuitem, _("UNIX mbox"), EXPORT_MBOX);
|
| 362 | 2210 | hiro | g_signal_connect(G_OBJECT(menuitem), "activate",
|
| 363 | 2210 | hiro | G_CALLBACK(export_format_menu_cb), NULL);
|
| 364 | 2210 | hiro | MENUITEM_ADD(menu, menuitem, _("eml (number + .eml)"), EXPORT_EML);
|
| 365 | 2210 | hiro | g_signal_connect(G_OBJECT(menuitem), "activate",
|
| 366 | 2210 | hiro | G_CALLBACK(export_format_menu_cb), NULL);
|
| 367 | 2210 | hiro | MENUITEM_ADD(menu, menuitem, _("MH (number only)"), EXPORT_MH);
|
| 368 | 2210 | hiro | g_signal_connect(G_OBJECT(menuitem), "activate",
|
| 369 | 2210 | hiro | G_CALLBACK(export_format_menu_cb), NULL);
|
| 370 | 2210 | hiro | |
| 371 | 2210 | hiro | gtk_option_menu_set_menu(GTK_OPTION_MENU(format_optmenu), menu); |
| 372 | 2210 | hiro | |
| 373 | 1 | hiro | src_entry = gtk_entry_new(); |
| 374 | 2210 | hiro | gtk_table_attach(GTK_TABLE(table), src_entry, 1, 2, 1, 2, |
| 375 | 1 | hiro | GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); |
| 376 | 1 | hiro | |
| 377 | 1 | hiro | file_entry = gtk_entry_new(); |
| 378 | 2210 | hiro | gtk_table_attach(GTK_TABLE(table), file_entry, 1, 2, 2, 3, |
| 379 | 1 | hiro | GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); |
| 380 | 1 | hiro | |
| 381 | 1 | hiro | src_button = gtk_button_new_with_label(_(" Select... "));
|
| 382 | 2210 | hiro | gtk_table_attach(GTK_TABLE(table), src_button, 2, 3, 1, 2, |
| 383 | 1 | hiro | 0, 0, 0, 0); |
| 384 | 1 | hiro | g_signal_connect(G_OBJECT(src_button), "clicked",
|
| 385 | 1 | hiro | G_CALLBACK(export_srcsel_cb), NULL);
|
| 386 | 1 | hiro | |
| 387 | 1 | hiro | file_button = gtk_button_new_with_label(_(" Select... "));
|
| 388 | 2210 | hiro | gtk_table_attach(GTK_TABLE(table), file_button, 2, 3, 2, 3, |
| 389 | 1 | hiro | 0, 0, 0, 0); |
| 390 | 1 | hiro | g_signal_connect(G_OBJECT(file_button), "clicked",
|
| 391 | 1 | hiro | G_CALLBACK(export_filesel_cb), NULL);
|
| 392 | 1 | hiro | |
| 393 | 31 | hiro | gtkut_stock_button_set_create(&confirm_area, |
| 394 | 31 | hiro | &ok_button, GTK_STOCK_OK, |
| 395 | 31 | hiro | &cancel_button, GTK_STOCK_CANCEL, |
| 396 | 31 | hiro | NULL, NULL); |
| 397 | 1 | hiro | gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
|
| 398 | 1 | hiro | gtk_widget_grab_default(ok_button); |
| 399 | 1 | hiro | |
| 400 | 1 | hiro | g_signal_connect(G_OBJECT(ok_button), "clicked",
|
| 401 | 1 | hiro | G_CALLBACK(export_ok_cb), NULL);
|
| 402 | 1 | hiro | g_signal_connect(G_OBJECT(cancel_button), "clicked",
|
| 403 | 1 | hiro | G_CALLBACK(export_cancel_cb), NULL);
|
| 404 | 1 | hiro | |
| 405 | 1 | hiro | gtk_widget_show_all(window); |
| 406 | 1 | hiro | } |
| 407 | 1 | hiro | |
| 408 | 2210 | hiro | static void export_format_menu_cb(GtkWidget *widget, gpointer data) |
| 409 | 2210 | hiro | {
|
| 410 | 2210 | hiro | gint type; |
| 411 | 2210 | hiro | |
| 412 | 2210 | hiro | type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), |
| 413 | 2210 | hiro | MENU_VAL_ID)); |
| 414 | 2210 | hiro | if (type == EXPORT_MBOX) {
|
| 415 | 2210 | hiro | gtk_label_set_text(GTK_LABEL(desc_label), |
| 416 | 2210 | hiro | _("Specify source folder and destination file."));
|
| 417 | 2210 | hiro | } else {
|
| 418 | 2210 | hiro | gtk_label_set_text(GTK_LABEL(desc_label), |
| 419 | 2210 | hiro | _("Specify source folder and destination folder."));
|
| 420 | 2210 | hiro | } |
| 421 | 2210 | hiro | } |
| 422 | 2210 | hiro | |
| 423 | 1 | hiro | static void export_ok_cb(GtkWidget *widget, gpointer data) |
| 424 | 1 | hiro | {
|
| 425 | 903 | hiro | export_finished = TRUE; |
| 426 | 1 | hiro | export_ack = TRUE; |
| 427 | 1 | hiro | } |
| 428 | 1 | hiro | |
| 429 | 1 | hiro | static void export_cancel_cb(GtkWidget *widget, gpointer data) |
| 430 | 1 | hiro | {
|
| 431 | 903 | hiro | export_finished = TRUE; |
| 432 | 1 | hiro | export_ack = FALSE; |
| 433 | 1 | hiro | } |
| 434 | 1 | hiro | |
| 435 | 1 | hiro | static void export_filesel_cb(GtkWidget *widget, gpointer data) |
| 436 | 1 | hiro | {
|
| 437 | 128 | hiro | gchar *filename; |
| 438 | 1 | hiro | gchar *utf8_filename; |
| 439 | 2210 | hiro | gint type; |
| 440 | 1 | hiro | |
| 441 | 2210 | hiro | type = menu_get_option_menu_active_index |
| 442 | 2210 | hiro | (GTK_OPTION_MENU(format_optmenu)); |
| 443 | 2210 | hiro | |
| 444 | 2210 | hiro | if (type == EXPORT_MBOX)
|
| 445 | 2210 | hiro | filename = filesel_select_file(_("Select destination file"),
|
| 446 | 2210 | hiro | NULL,
|
| 447 | 2210 | hiro | GTK_FILE_CHOOSER_ACTION_SAVE); |
| 448 | 2210 | hiro | else
|
| 449 | 2210 | hiro | filename = filesel_select_file(_("Select destination folder"),
|
| 450 | 2210 | hiro | NULL,
|
| 451 | 2210 | hiro | GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); |
| 452 | 1 | hiro | if (!filename) return; |
| 453 | 1 | hiro | |
| 454 | 1 | hiro | utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); |
| 455 | 1 | hiro | if (!utf8_filename) {
|
| 456 | 2205 | hiro | g_warning("export_filesel_cb(): failed to convert character set.");
|
| 457 | 1 | hiro | utf8_filename = g_strdup(filename); |
| 458 | 1 | hiro | } |
| 459 | 1 | hiro | gtk_entry_set_text(GTK_ENTRY(file_entry), utf8_filename); |
| 460 | 1 | hiro | g_free(utf8_filename); |
| 461 | 128 | hiro | |
| 462 | 128 | hiro | g_free(filename); |
| 463 | 1 | hiro | } |
| 464 | 1 | hiro | |
| 465 | 1 | hiro | static void export_srcsel_cb(GtkWidget *widget, gpointer data) |
| 466 | 1 | hiro | {
|
| 467 | 1 | hiro | FolderItem *src; |
| 468 | 2205 | hiro | gchar *src_id; |
| 469 | 1 | hiro | |
| 470 | 1 | hiro | src = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL); |
| 471 | 2205 | hiro | if (src && src->path) {
|
| 472 | 2205 | hiro | src_id = folder_item_get_identifier(src); |
| 473 | 2205 | hiro | if (src_id) {
|
| 474 | 2205 | hiro | gtk_entry_set_text(GTK_ENTRY(src_entry), src_id); |
| 475 | 2205 | hiro | g_free(src_id); |
| 476 | 2205 | hiro | } |
| 477 | 2205 | hiro | } |
| 478 | 1 | hiro | } |
| 479 | 1 | hiro | |
| 480 | 1 | hiro | static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
|
| 481 | 1 | hiro | {
|
| 482 | 1 | hiro | export_cancel_cb(NULL, NULL); |
| 483 | 1 | hiro | return TRUE;
|
| 484 | 1 | hiro | } |
| 485 | 1 | hiro | |
| 486 | 1 | hiro | static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
| 487 | 1 | hiro | {
|
| 488 | 1 | hiro | if (event && event->keyval == GDK_Escape)
|
| 489 | 1 | hiro | export_cancel_cb(NULL, NULL); |
| 490 | 1 | hiro | return FALSE;
|
| 491 | 1 | hiro | } |