claws-mail/src/import.c

251 lines
7.2 KiB
C
Raw Normal View History

2001-04-19 14:21:46 +02:00
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
2002-02-23 11:52:54 +01:00
* Copyright (C) 1999-2002 Hiroyuki Yamamoto
2001-04-19 14:21:46 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "defs.h"
#include <glib.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkwidget.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtktable.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkhbbox.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkfilesel.h>
#include <gtk/gtksignal.h>
#include "intl.h"
#include "main.h"
#include "inc.h"
#include "mbox.h"
#include "folderview.h"
#include "filesel.h"
#include "foldersel.h"
#include "gtkutils.h"
#include "manage_window.h"
#include "folder.h"
static GtkWidget *window;
static GtkWidget *file_entry;
static GtkWidget *dest_entry;
static GtkWidget *file_button;
static GtkWidget *dest_button;
static GtkWidget *ok_button;
static GtkWidget *cancel_button;
static gboolean import_ack;
static void import_create(void);
static void import_ok_cb(GtkWidget *widget, gpointer data);
static void import_cancel_cb(GtkWidget *widget, gpointer data);
static void import_filesel_cb(GtkWidget *widget, gpointer data);
static void import_destsel_cb(GtkWidget *widget, gpointer data);
2001-05-08 00:13:03 +02:00
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data);
2001-04-19 14:21:46 +02:00
static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
2001-04-21 01:24:31 +02:00
gint import_mbox(FolderItem *default_dest)
2001-04-19 14:21:46 +02:00
{
gint ok = 0;
2002-04-05 10:20:10 +02:00
gchar *dest_id = NULL;
2001-04-19 14:21:46 +02:00
if (!window)
import_create();
else
gtk_widget_show(window);
2001-04-21 01:24:31 +02:00
gtk_entry_set_text(GTK_ENTRY(file_entry), "");
2002-04-05 10:20:10 +02:00
if (default_dest && default_dest->path)
dest_id = folder_item_get_identifier(default_dest);
2002-04-05 10:20:10 +02:00
if (dest_id) {
gtk_entry_set_text(GTK_ENTRY(dest_entry), dest_id);
g_free(dest_id);
} else
2001-04-21 01:24:31 +02:00
gtk_entry_set_text(GTK_ENTRY(dest_entry), "");
gtk_widget_grab_focus(file_entry);
2001-04-19 14:21:46 +02:00
manage_window_set_transient(GTK_WINDOW(window));
gtk_main();
if (import_ack) {
gchar *filename, *destdir;
FolderItem *dest;
filename = gtk_entry_get_text(GTK_ENTRY(file_entry));
destdir = gtk_entry_get_text(GTK_ENTRY(dest_entry));
if (filename && *filename) {
if (!destdir || !*destdir) {
dest = folder_find_item_from_path(INBOX_DIR);
} else
2002-04-05 10:20:10 +02:00
dest = folder_find_item_from_identifier
(destdir);
2001-04-19 14:21:46 +02:00
if (!dest) {
g_warning("Can't find the folder.\n");
} else {
ok = proc_mbox(dest, filename);
2001-04-19 14:21:46 +02:00
}
}
}
gtk_widget_hide(window);
return ok;
}
static void import_create(void)
{
GtkWidget *vbox;
2001-04-21 01:24:31 +02:00
GtkWidget *hbox;
GtkWidget *desc_label;
2001-04-19 14:21:46 +02:00
GtkWidget *table;
GtkWidget *file_label;
GtkWidget *dest_label;
GtkWidget *confirm_area;
window = gtk_window_new(GTK_WINDOW_DIALOG);
gtk_window_set_title(GTK_WINDOW(window), _("Import"));
2001-04-21 01:24:31 +02:00
gtk_container_set_border_width(GTK_CONTAINER(window), 5);
2001-04-19 14:21:46 +02:00
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
2001-04-21 01:24:31 +02:00
gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
2001-04-19 14:21:46 +02:00
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2001-05-08 00:13:03 +02:00
GTK_SIGNAL_FUNC(delete_event), NULL);
2001-04-19 14:21:46 +02:00
gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
GTK_SIGNAL_FUNC(key_pressed), NULL);
2002-02-23 11:52:54 +01:00
MANAGE_WINDOW_SIGNALS_CONNECT(window);
2001-04-19 14:21:46 +02:00
2001-04-21 01:24:31 +02:00
vbox = gtk_vbox_new(FALSE, 4);
2001-04-19 14:21:46 +02:00
gtk_container_add(GTK_CONTAINER(window), vbox);
2001-04-21 01:24:31 +02:00
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
desc_label = gtk_label_new
(_("Specify target mbox file and destination folder."));
gtk_box_pack_start(GTK_BOX(hbox), desc_label, FALSE, FALSE, 0);
2001-04-19 14:21:46 +02:00
table = gtk_table_new(2, 3, FALSE);
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(table), 8);
2001-04-21 01:24:31 +02:00
gtk_table_set_row_spacings(GTK_TABLE(table), 8);
2001-04-19 14:21:46 +02:00
gtk_table_set_col_spacings(GTK_TABLE(table), 8);
2001-04-21 01:24:31 +02:00
gtk_widget_set_usize(table, 420, -1);
2001-04-19 14:21:46 +02:00
file_label = gtk_label_new(_("Importing file:"));
gtk_table_attach(GTK_TABLE(table), file_label, 0, 1, 0, 1,
GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC(file_label), 1, 0.5);
dest_label = gtk_label_new(_("Destination dir:"));
gtk_table_attach(GTK_TABLE(table), dest_label, 0, 1, 1, 2,
GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
gtk_misc_set_alignment(GTK_MISC(dest_label), 1, 0.5);
file_entry = gtk_entry_new();
gtk_table_attach(GTK_TABLE(table), file_entry, 1, 2, 0, 1,
GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
dest_entry = gtk_entry_new();
gtk_table_attach(GTK_TABLE(table), dest_entry, 1, 2, 1, 2,
GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
file_button = gtk_button_new_with_label(_(" Select... "));
gtk_table_attach(GTK_TABLE(table), file_button, 2, 3, 0, 1,
0, 0, 0, 0);
gtk_signal_connect(GTK_OBJECT(file_button), "clicked",
GTK_SIGNAL_FUNC(import_filesel_cb), NULL);
dest_button = gtk_button_new_with_label(_(" Select... "));
gtk_table_attach(GTK_TABLE(table), dest_button, 2, 3, 1, 2,
0, 0, 0, 0);
gtk_signal_connect(GTK_OBJECT(dest_button), "clicked",
GTK_SIGNAL_FUNC(import_destsel_cb), NULL);
gtkut_button_set_create(&confirm_area,
&ok_button, _("OK"),
&cancel_button, _("Cancel"),
NULL, NULL);
gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
gtk_widget_grab_default(ok_button);
gtk_signal_connect(GTK_OBJECT(ok_button), "clicked",
GTK_SIGNAL_FUNC(import_ok_cb), NULL);
gtk_signal_connect(GTK_OBJECT(cancel_button), "clicked",
GTK_SIGNAL_FUNC(import_cancel_cb), NULL);
gtk_widget_show_all(window);
}
static void import_ok_cb(GtkWidget *widget, gpointer data)
{
import_ack = TRUE;
2001-04-21 01:24:31 +02:00
if (gtk_main_level() > 1)
gtk_main_quit();
2001-04-19 14:21:46 +02:00
}
static void import_cancel_cb(GtkWidget *widget, gpointer data)
{
import_ack = FALSE;
2001-04-21 01:24:31 +02:00
if (gtk_main_level() > 1)
gtk_main_quit();
2001-04-19 14:21:46 +02:00
}
static void import_filesel_cb(GtkWidget *widget, gpointer data)
{
gchar *filename;
filename = filesel_select_file(_("Select importing file"), NULL);
if (filename)
gtk_entry_set_text(GTK_ENTRY(file_entry), filename);
}
static void import_destsel_cb(GtkWidget *widget, gpointer data)
{
FolderItem *dest;
gchar *path;
2001-04-19 14:21:46 +02:00
2002-02-07 11:14:25 +01:00
dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
if (!dest)
return;
path = folder_item_get_identifier(dest);
gtk_entry_set_text(GTK_ENTRY(dest_entry), path);
g_free(path);
2001-04-19 14:21:46 +02:00
}
2001-05-08 00:13:03 +02:00
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
{
import_cancel_cb(NULL, NULL);
return TRUE;
}
2001-04-19 14:21:46 +02:00
static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
if (event && event->keyval == GDK_Escape)
import_cancel_cb(NULL, NULL);
}