3e234d4879
* AUTHORS * Makefile.am * autogen.sh * configure.ac * config/mkinstalldirs * intl/.cvsignore * intl/ChangeLog * intl/VERSION * intl/bindtextdom.c * intl/config.charset * intl/dcgettext.c * intl/dcigettext.c * intl/dcngettext.c * intl/dgettext.c * intl/dngettext.c * intl/eval-plural.h * intl/explodename.c * intl/finddomain.c * intl/gettext.c * intl/gettextP.h * intl/gmo.h * intl/hash-string.h * intl/intl-compat.c * intl/l10nflist.c * intl/libgnuintl.h.in * intl/loadinfo.h * intl/loadmsgcat.c * intl/localcharset.c * intl/localcharset.h * intl/locale.alias * intl/localealias.c * intl/localename.c * intl/log.c * intl/ngettext.c * intl/os2compat.c * intl/os2compat.h * intl/osdep.c * intl/plural-exp.c * intl/plural-exp.h * intl/plural.c * intl/plural.y * intl/ref-add.sin * intl/ref-del.sin * intl/relocatable.c * intl/relocatable.h * intl/textdomain.c * m4/Makefile.am * po/Makefile.in.in * src/Makefile.am * src/account.c * src/action.c * src/addr_compl.c * src/addressadd.c * src/addressbook.c * src/addrgather.c * src/addrindex.c * src/alertpanel.c * src/browseldap.c * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/crash.c * src/editaddress.c * src/editbook.c * src/editgroup.c * src/editjpilot.c * src/editldap.c * src/editldap_basedn.c * src/editvcard.c * src/exphtmldlg.c * src/expldifdlg.c * src/export.c * src/exporthtml.c * src/filtering.c * src/folder.c * src/folder_item_prefs.c * src/foldersel.c * src/folderview.c * src/grouplistdialog.c * src/headerview.c * src/imap.c * src/imap_gtk.c * src/import.c * src/importldif.c * src/importmutt.c * src/importpine.c * src/inc.c * src/ldif.c * src/main.c * src/mainwindow.c * src/matcher.c * src/mbox.c * src/message_search.c * src/messageview.c * src/mh.c * src/mh_gtk.c * src/mimeview.c * src/msgcache.c * src/news.c * src/news_gtk.c * src/noticeview.c * src/partial_download.c * src/pop.c * src/prefs_account.c * src/prefs_actions.c * src/prefs_common.c * src/prefs_customheader.c * src/prefs_display_header.c * src/prefs_ext_prog.c * src/prefs_filtering.c * src/prefs_filtering_action.c * src/prefs_folder_item.c * src/prefs_fonts.c * src/prefs_gtk.c * src/prefs_matcher.c * src/prefs_msg_colors.c * src/prefs_spelling.c * src/prefs_summary_column.c * src/prefs_template.c * src/prefs_themes.c * src/prefs_toolbar.c * src/prefs_wrapping.c * src/privacy.c * src/procheader.c * src/procmime.c * src/procmsg.c * src/quote_fmt.c * src/recv.c * src/send_message.c * src/setup.c * src/sourcewindow.c * src/ssl_manager.c * src/statusbar.c * src/summary_search.c * src/summaryview.c * src/textview.c * src/toolbar.c * src/wizard.c * src/common/nntp.c * src/common/plugin.c * src/common/smtp.c * src/common/ssl.c * src/common/ssl_certificate.c * src/common/string_match.c * src/common/sylpheed.c * src/common/template.c * src/common/utils.c * src/gtk/about.c * src/gtk/colorlabel.c * src/gtk/description_window.c * src/gtk/filesel.c * src/gtk/foldersort.c * src/gtk/gtkaspell.c * src/gtk/gtkutils.c * src/gtk/inputdialog.c * src/gtk/logwindow.c * src/gtk/menu.c * src/gtk/pluginwindow.c * src/gtk/prefswindow.c * src/gtk/progressdialog.c * src/gtk/quicksearch.c * src/gtk/sslcertwindow.c * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/image_viewer/plugin.c * src/plugins/image_viewer/viewer.c * src/plugins/image_viewer/viewerprefs.c * src/plugins/mathml_viewer/mathml_viewer.c * src/plugins/pgpmime/passphrase.c * src/plugins/pgpmime/plugin.c * src/plugins/pgpmime/prefs_gpg.c * src/plugins/pgpmime/select-keys.c * src/plugins/pgpmime/sgpgme.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c sync with main (revision 104)
272 lines
7.8 KiB
C
272 lines
7.8 KiB
C
/*
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
|
* Copyright (C) 1999-2005 Hiroyuki Yamamoto
|
|
*
|
|
* 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 <glib/gi18n.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 "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"
|
|
#include "codeconv.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);
|
|
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data);
|
|
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
|
|
|
|
gint import_mbox(FolderItem *default_dest)
|
|
{
|
|
gint ok = 0;
|
|
gchar *dest_id = NULL;
|
|
|
|
if (!window)
|
|
import_create();
|
|
else
|
|
gtk_widget_show(window);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(file_entry), "");
|
|
if (default_dest && default_dest->path)
|
|
dest_id = folder_item_get_identifier(default_dest);
|
|
|
|
if (dest_id) {
|
|
gtk_entry_set_text(GTK_ENTRY(dest_entry), dest_id);
|
|
g_free(dest_id);
|
|
} else
|
|
gtk_entry_set_text(GTK_ENTRY(dest_entry), "");
|
|
gtk_widget_grab_focus(file_entry);
|
|
|
|
manage_window_set_transient(GTK_WINDOW(window));
|
|
|
|
gtk_main();
|
|
|
|
if (import_ack) {
|
|
const gchar *utf8filename, *destdir;
|
|
FolderItem *dest;
|
|
|
|
utf8filename = gtk_entry_get_text(GTK_ENTRY(file_entry));
|
|
destdir = gtk_entry_get_text(GTK_ENTRY(dest_entry));
|
|
if (utf8filename && *utf8filename) {
|
|
gchar *filename;
|
|
|
|
filename = g_filename_from_utf8
|
|
(utf8filename, -1, NULL, NULL, NULL);
|
|
if (!filename) {
|
|
g_warning("faild to convert character set\n");
|
|
filename = g_strdup(utf8filename);
|
|
}
|
|
|
|
if (!destdir || !*destdir) {
|
|
dest = folder_find_item_from_path(INBOX_DIR);
|
|
} else
|
|
dest = folder_find_item_from_identifier
|
|
(destdir);
|
|
|
|
if (!dest) {
|
|
g_warning("Can't find the folder.\n");
|
|
} else {
|
|
ok = proc_mbox(dest, filename, FALSE);
|
|
}
|
|
|
|
g_free(filename);
|
|
}
|
|
}
|
|
|
|
gtk_widget_hide(window);
|
|
|
|
return ok;
|
|
}
|
|
|
|
static void import_create(void)
|
|
{
|
|
GtkWidget *vbox;
|
|
GtkWidget *hbox;
|
|
GtkWidget *desc_label;
|
|
GtkWidget *table;
|
|
GtkWidget *file_label;
|
|
GtkWidget *dest_label;
|
|
GtkWidget *confirm_area;
|
|
|
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
gtk_window_set_title(GTK_WINDOW(window), _("Import"));
|
|
gtk_container_set_border_width(GTK_CONTAINER(window), 5);
|
|
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
|
|
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
|
|
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
|
|
g_signal_connect(G_OBJECT(window), "delete_event",
|
|
G_CALLBACK(delete_event), NULL);
|
|
g_signal_connect(G_OBJECT(window), "key_press_event",
|
|
G_CALLBACK(key_pressed), NULL);
|
|
MANAGE_WINDOW_SIGNALS_CONNECT(window);
|
|
|
|
vbox = gtk_vbox_new(FALSE, 4);
|
|
gtk_container_add(GTK_CONTAINER(window), vbox);
|
|
|
|
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);
|
|
|
|
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);
|
|
gtk_table_set_row_spacings(GTK_TABLE(table), 8);
|
|
gtk_table_set_col_spacings(GTK_TABLE(table), 8);
|
|
gtk_widget_set_size_request(table, 420, -1);
|
|
|
|
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_from_stock(GTK_STOCK_OPEN);
|
|
gtk_table_attach(GTK_TABLE(table), file_button, 2, 3, 0, 1,
|
|
0, 0, 0, 0);
|
|
g_signal_connect(G_OBJECT(file_button), "clicked",
|
|
G_CALLBACK(import_filesel_cb), NULL);
|
|
|
|
/* XXX GTK 2.6: GTK_STOCK_DIRECTORY */
|
|
dest_button = gtk_button_new_from_stock(GTK_STOCK_OPEN);
|
|
gtk_table_attach(GTK_TABLE(table), dest_button, 2, 3, 1, 2,
|
|
0, 0, 0, 0);
|
|
g_signal_connect(G_OBJECT(dest_button), "clicked",
|
|
G_CALLBACK(import_destsel_cb), NULL);
|
|
|
|
gtkut_stock_button_set_create(&confirm_area,
|
|
&ok_button, GTK_STOCK_OK,
|
|
&cancel_button, GTK_STOCK_CANCEL,
|
|
NULL, NULL);
|
|
gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
|
|
gtk_widget_grab_default(ok_button);
|
|
|
|
g_signal_connect(G_OBJECT(ok_button), "clicked",
|
|
G_CALLBACK(import_ok_cb), NULL);
|
|
g_signal_connect(G_OBJECT(cancel_button), "clicked",
|
|
G_CALLBACK(import_cancel_cb), NULL);
|
|
|
|
gtk_widget_show_all(window);
|
|
}
|
|
|
|
static void import_ok_cb(GtkWidget *widget, gpointer data)
|
|
{
|
|
import_ack = TRUE;
|
|
if (gtk_main_level() > 1)
|
|
gtk_main_quit();
|
|
}
|
|
|
|
static void import_cancel_cb(GtkWidget *widget, gpointer data)
|
|
{
|
|
import_ack = FALSE;
|
|
if (gtk_main_level() > 1)
|
|
gtk_main_quit();
|
|
}
|
|
|
|
static void import_filesel_cb(GtkWidget *widget, gpointer data)
|
|
{
|
|
gchar *filename;
|
|
gchar *utf8_filename;
|
|
|
|
filename = filesel_select_file_open(_("Select importing file"), NULL);
|
|
if (!filename) return;
|
|
|
|
utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
|
|
if (!utf8_filename) {
|
|
g_warning("import_filesel_cb(): faild to convert characer set.");
|
|
utf8_filename = g_strdup(filename);
|
|
}
|
|
gtk_entry_set_text(GTK_ENTRY(file_entry), utf8_filename);
|
|
g_free(utf8_filename);
|
|
}
|
|
|
|
static void import_destsel_cb(GtkWidget *widget, gpointer data)
|
|
{
|
|
FolderItem *dest;
|
|
gchar *path;
|
|
|
|
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);
|
|
}
|
|
|
|
static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
|
|
{
|
|
import_cancel_cb(NULL, NULL);
|
|
return TRUE;
|
|
}
|
|
|
|
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
|
{
|
|
if (event && event->keyval == GDK_Escape)
|
|
import_cancel_cb(NULL, NULL);
|
|
return FALSE;
|
|
}
|