diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-09-26 20:36:01 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-09-26 22:28:30 +0800 |
commit | 02c2097ea67846b0ff697f6222539d852da87a40 (patch) | |
tree | 0897fe189bf59ca124ade5030f7d7035e0d283c8 /widgets | |
parent | 43a11452262d7826e2341558a085ca5cee7b2ffb (diff) | |
download | gsoc2013-evolution-02c2097ea67846b0ff697f6222539d852da87a40.tar gsoc2013-evolution-02c2097ea67846b0ff697f6222539d852da87a40.tar.gz gsoc2013-evolution-02c2097ea67846b0ff697f6222539d852da87a40.tar.bz2 gsoc2013-evolution-02c2097ea67846b0ff697f6222539d852da87a40.tar.lz gsoc2013-evolution-02c2097ea67846b0ff697f6222539d852da87a40.tar.xz gsoc2013-evolution-02c2097ea67846b0ff697f6222539d852da87a40.tar.zst gsoc2013-evolution-02c2097ea67846b0ff697f6222539d852da87a40.zip |
More import assistant cleanup.
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/misc/e-import-assistant.c | 287 |
1 files changed, 153 insertions, 134 deletions
diff --git a/widgets/misc/e-import-assistant.c b/widgets/misc/e-import-assistant.c index 4db3d55353..8815fd9228 100644 --- a/widgets/misc/e-import-assistant.c +++ b/widgets/misc/e-import-assistant.c @@ -31,7 +31,6 @@ #include <gdk/gdkkeysyms.h> #include "e-util/e-error.h" -#include "e-util/e-icon-factory.h" #include "e-util/e-import.h" #include "e-util/e-util-private.h" @@ -45,7 +44,6 @@ typedef struct _ImportTypePage ImportTypePage; typedef struct _ImportSelectionPage ImportSelectionPage; struct _ImportFilePage { - GtkWidget *vbox; GtkWidget *filename; GtkWidget *filetype; @@ -54,20 +52,15 @@ struct _ImportFilePage { }; struct _ImportDestinationPage { - GtkWidget *vbox; - GtkWidget *control; }; struct _ImportTypePage { - GtkWidget *vbox; GtkWidget *intelligent; GtkWidget *file; }; struct _ImportSelectionPage { - GtkWidget *vbox; - GSList *importers; GSList *current; EImportTargetHome *target; @@ -90,6 +83,15 @@ struct _EImportAssistantPrivate { }; enum { + PAGE_START, + PAGE_INTELI_OR_DIRECT, + PAGE_INTELI_SOURCE, + PAGE_FILE_CHOOSE, + PAGE_FILE_DEST, + PAGE_FINISH +}; + +enum { FINISHED, LAST_SIGNAL }; @@ -175,28 +177,31 @@ filename_changed (GtkWidget *widget, } } - gtk_assistant_set_page_complete (assistant, page->vbox, fileok); + widget = gtk_assistant_get_nth_page (assistant, PAGE_FILE_CHOOSE); + gtk_assistant_set_page_complete (assistant, widget, fileok); } static void -filetype_changed_cb (GtkWidget *combobox, +filetype_changed_cb (GtkComboBox *combo_box, GtkAssistant *assistant) { EImportAssistantPrivate *priv; + GtkTreeModel *model; GtkTreeIter iter; priv = E_IMPORT_ASSISTANT_GET_PRIVATE (assistant); - g_return_if_fail (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &iter)); + g_return_if_fail (gtk_combo_box_get_active_iter (combo_box, &iter)); - gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combobox)), &iter, 2, &priv->file_page.importer, -1); + model = gtk_combo_box_get_model (combo_box); + gtk_tree_model_get (model, &iter, 2, &priv->file_page.importer, -1); filename_changed (priv->file_page.filename, assistant); } -static void +static GtkWidget * import_assistant_file_page_init (EImportAssistant *import_assistant) { - ImportFilePage *page; + GtkWidget *page; GtkWidget *label; GtkWidget *container; GtkWidget *widget; @@ -205,14 +210,11 @@ import_assistant_file_page_init (EImportAssistant *import_assistant) const gchar *text; gint row = 0; - page = &import_assistant->priv->file_page; - - widget = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - page->vbox = widget; - gtk_widget_show (widget); + page = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + gtk_widget_show (page); - container = widget; + container = page; text = _("Choose the file that you want to import into Evolution, " "and select what type of file it is from the list."); @@ -246,7 +248,7 @@ import_assistant_file_page_init (EImportAssistant *import_assistant) gtk_table_attach ( GTK_TABLE (container), widget, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); - page->filename = widget; + import_assistant->priv->file_page.filename = widget; gtk_widget_show (widget); g_signal_connect ( @@ -271,7 +273,7 @@ import_assistant_file_page_init (EImportAssistant *import_assistant) gtk_table_attach ( GTK_TABLE (container), widget, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); - page->filetype = widget; + import_assistant->priv->file_page.filetype = widget; gtk_widget_show (widget); g_object_unref (store); @@ -280,24 +282,23 @@ import_assistant_file_page_init (EImportAssistant *import_assistant) gtk_cell_layout_set_attributes ( GTK_CELL_LAYOUT (widget), cell, "text", 0, "sensitive", 1, NULL); + + return page; } -static void +static GtkWidget * import_assistant_destination_page_init (EImportAssistant *import_assistant) { - ImportDestinationPage *page; + GtkWidget *page; GtkWidget *container; GtkWidget *widget; const gchar *text; - page = &import_assistant->priv->destination_page; - - widget = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - page->vbox = widget; - gtk_widget_show (widget); + page = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + gtk_widget_show (page); - container = widget; + container = page; text = _("Choose the destination for this import"); @@ -305,24 +306,24 @@ import_assistant_destination_page_init (EImportAssistant *import_assistant) gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, TRUE, 0); gtk_widget_show (widget); + + return page; } -static void +static GtkWidget * import_assistant_type_page_init (EImportAssistant *import_assistant) { - ImportTypePage *page; + GtkRadioButton *radio_button; + GtkWidget *page; GtkWidget *container; GtkWidget *widget; const gchar *text; - page = &import_assistant->priv->type_page; + page = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + gtk_widget_show (page); - widget = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - page->vbox = widget; - gtk_widget_show (widget); - - container = widget; + container = page; text = _("Choose the type of importer to run:"); @@ -334,33 +335,33 @@ import_assistant_type_page_init (EImportAssistant *import_assistant) widget = gtk_radio_button_new_with_mnemonic ( NULL, _("Import data and settings from _older programs")); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); - page->intelligent = widget; + import_assistant->priv->type_page.intelligent = widget; gtk_widget_show (widget); + radio_button = GTK_RADIO_BUTTON (widget); + widget = gtk_radio_button_new_with_mnemonic_from_widget ( - GTK_RADIO_BUTTON (page->intelligent), - _("Import a _single file")); + radio_button, _("Import a _single file")); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); - page->file = widget; + import_assistant->priv->type_page.file = widget; gtk_widget_show (widget); + + return page; } -static void +static GtkWidget * import_assistant_selection_page_init (EImportAssistant *import_assistant) { - ImportSelectionPage *page; + GtkWidget *page; GtkWidget *container; GtkWidget *widget; const gchar *text; - page = &import_assistant->priv->selection_page; - - widget = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - page->vbox = widget; - gtk_widget_show (widget); + page = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (page), 12); + gtk_widget_show (page); - container = widget; + container = page; text = _("Please select the information " "that you would like to import:"); @@ -373,10 +374,13 @@ import_assistant_selection_page_init (EImportAssistant *import_assistant) widget = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); gtk_widget_show (widget); + + return page; } static void -prepare_intelligent_page (GtkAssistant *assistant) +prepare_intelligent_page (GtkAssistant *assistant, + GtkWidget *vbox) { EImportAssistantPrivate *priv; GSList *l; @@ -388,7 +392,7 @@ prepare_intelligent_page (GtkAssistant *assistant) page = &priv->selection_page; if (page->target != NULL) { - gtk_assistant_set_page_complete (assistant, page->vbox, FALSE); + gtk_assistant_set_page_complete (assistant, vbox, FALSE); return; } @@ -412,11 +416,10 @@ prepare_intelligent_page (GtkAssistant *assistant) widget = gtk_label_new (text); gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE); - gtk_box_pack_start ( - GTK_BOX (page->vbox), widget, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, TRUE, 0); gtk_widget_show (widget); - gtk_assistant_set_page_complete (assistant, page->vbox, FALSE); + gtk_assistant_set_page_complete (assistant, vbox, FALSE); return; } @@ -436,18 +439,22 @@ prepare_intelligent_page (GtkAssistant *assistant) gtk_widget_show (label); g_free (str); - gtk_misc_set_alignment ((GtkMisc *)label, 0, .5); + gtk_misc_set_alignment (GTK_MISC (label), 0, .5); - gtk_table_attach ((GtkTable *)table, label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0); + gtk_table_attach ( + GTK_TABLE (table), label, + 0, 1, row, row+1, GTK_FILL, 0, 0, 0); if (w) - gtk_table_attach ((GtkTable *)table, w, 1, 2, row, row+1, GTK_FILL, 0, 3, 0); + gtk_table_attach ( + GTK_TABLE (table), w, + 1, 2, row, row+1, GTK_FILL, 0, 3, 0); row++; } gtk_widget_show (table); - gtk_box_pack_start (GTK_BOX (page->vbox), table, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); - gtk_assistant_set_page_complete (assistant, page->vbox, TRUE); + gtk_assistant_set_page_complete (assistant, vbox, TRUE); } static void @@ -491,18 +498,26 @@ import_intelligent_done (EImport *ei, gpointer user_data) { EImportAssistant *import_assistant = user_data; + ImportSelectionPage *page; + + page = &import_assistant->priv->selection_page; - if (import_assistant->priv->selection_page.current - && (import_assistant->priv->selection_page.current = import_assistant->priv->selection_page.current->next)) { + if (page->current && (page->current = page->current->next)) { import_status (ei, "", 0, import_assistant); - import_assistant->priv->import_importer = import_assistant->priv->selection_page.current->data; - e_import_import (import_assistant->priv->import, (EImportTarget *)import_assistant->priv->selection_page.target, import_assistant->priv->import_importer, import_status, import_intelligent_done, import_assistant); + import_assistant->priv->import_importer = page->current->data; + e_import_import ( + import_assistant->priv->import, + (EImportTarget *) page->target, + import_assistant->priv->import_importer, + import_status, import_intelligent_done, + import_assistant); } else import_done (ei, import_assistant); } static void -prepare_file_page (GtkAssistant *assistant) +prepare_file_page (GtkAssistant *assistant, + GtkWidget *vbox) { EImportAssistantPrivate *priv; GSList *importers, *imp; @@ -548,7 +563,8 @@ prepare_file_page (GtkAssistant *assistant) } static gboolean -prepare_destination_page (GtkAssistant *assistant) +prepare_destination_page (GtkAssistant *assistant, + GtkWidget *vbox) { EImportAssistantPrivate *priv; ImportDestinationPage *page; @@ -557,34 +573,24 @@ prepare_destination_page (GtkAssistant *assistant) page = &priv->destination_page; if (page->control) - gtk_container_remove ((GtkContainer *)page->vbox, page->control); + gtk_container_remove (GTK_CONTAINER (vbox), page->control); page->control = e_import_get_widget ( priv->import, (EImportTarget *) priv->file_page.target, priv->file_page.importer); if (page->control == NULL) { /* Coding error, not needed for translators */ - page->control = gtk_label_new ("** PLUGIN ERROR ** No settings for importer"); + page->control = gtk_label_new ( + "** PLUGIN ERROR ** No settings for importer"); gtk_widget_show (page->control); } - gtk_box_pack_start ( - GTK_BOX (priv->destination_page.vbox), - page->control, TRUE, TRUE, 0); - gtk_assistant_set_page_complete (assistant, page->vbox, TRUE); + gtk_box_pack_start (GTK_BOX (vbox), page->control, TRUE, TRUE, 0); + gtk_assistant_set_page_complete (assistant, vbox, TRUE); return FALSE; } -enum { - PAGE_START, - PAGE_INTELI_OR_DIRECT, - PAGE_INTELI_SOURCE, - PAGE_FILE_CHOOSE, - PAGE_FILE_DEST, - PAGE_FINISH -}; - static gint forward_cb (gint current_page, EImportAssistant *import_assistant) @@ -652,7 +658,7 @@ import_assistant_finalize (GObject *object) static gboolean import_assistant_key_press_event (GtkWidget *widget, - GdkEventKey *event) + GdkEventKey *event) { GtkWidgetClass *widget_class; @@ -668,18 +674,21 @@ import_assistant_key_press_event (GtkWidget *widget, static void import_assistant_prepare (GtkAssistant *assistant, - GtkWidget *page) + GtkWidget *page) { - EImportAssistantPrivate *priv; - - priv = E_IMPORT_ASSISTANT_GET_PRIVATE (assistant); - - if (page == priv->selection_page.vbox) - prepare_intelligent_page (assistant); - else if (page == priv->file_page.vbox) - prepare_file_page (assistant); - else if (page == priv->destination_page.vbox) - prepare_destination_page (assistant); + switch (gtk_assistant_get_current_page (assistant)) { + case PAGE_INTELI_SOURCE: + prepare_intelligent_page (assistant, page); + break; + case PAGE_FILE_CHOOSE: + prepare_file_page (assistant, page); + break; + case PAGE_FILE_DEST: + prepare_destination_page (assistant, page); + break; + default: + break; + } } static void @@ -687,38 +696,56 @@ import_assistant_apply (GtkAssistant *assistant) { EImportAssistantPrivate *priv; EImportCompleteFunc done = NULL; + GtkToggleButton *toggle_button; + ImportSelectionPage *page; gchar *msg = NULL; priv = E_IMPORT_ASSISTANT_GET_PRIVATE (assistant); + page = &priv->selection_page; + + toggle_button = GTK_TOGGLE_BUTTON (priv->type_page.intelligent); - if (gtk_toggle_button_get_active ((GtkToggleButton *)priv->type_page.intelligent)) { - priv->selection_page.current = priv->selection_page.importers; - if (priv->selection_page.current) { - priv->import_target = (EImportTarget *)priv->selection_page.target; - priv->import_importer = priv->selection_page.current->data; + if (gtk_toggle_button_get_active (toggle_button)) { + page->current = page->importers; + if (page->current) { + priv->import_target = (EImportTarget *) page->target; + priv->import_importer = page->current->data; done = import_intelligent_done; - msg = g_strdup_printf (_("Importing data.")); + msg = g_strdup (_("Importing Data")); } } else { if (priv->file_page.importer) { priv->import_importer = priv->file_page.importer; priv->import_target = (EImportTarget *)priv->file_page.target; done = import_done; - msg = g_strdup_printf (_("Importing `%s'"), priv->file_page.target->uri_src); + msg = g_strdup_printf ( + _("Importing \"%s\""), + priv->file_page.target->uri_src); } } if (done) { + GtkWidget *content_area; + priv->import_dialog = e_error_new ( GTK_WINDOW (assistant), "shell:importing", msg, NULL); g_signal_connect (priv->import_dialog, "response", G_CALLBACK(import_dialog_response), assistant); priv->import_label = gtk_label_new (_("Please wait")); priv->import_progress = gtk_progress_bar_new (); - gtk_box_pack_start (GTK_BOX(((GtkDialog *)priv->import_dialog)->vbox), priv->import_label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(((GtkDialog *)priv->import_dialog)->vbox), priv->import_progress, FALSE, FALSE, 0); + content_area = gtk_dialog_get_content_area ( + GTK_DIALOG (priv->import_dialog)); + gtk_box_pack_start ( + GTK_BOX (content_area), + priv->import_label, FALSE, FALSE, 0); + gtk_box_pack_start ( + GTK_BOX (content_area), + priv->import_progress, FALSE, FALSE, 0); gtk_widget_show_all (priv->import_dialog); - e_import_import (priv->import, priv->import_target, priv->import_importer, import_status, import_done, assistant); + e_import_import ( + priv->import, priv->import_target, + priv->import_importer, import_status, + import_done, assistant); } else { import_assistant_emit_finished (E_IMPORT_ASSISTANT (assistant)); } @@ -759,25 +786,24 @@ import_assistant_class_init (EImportAssistantClass *class) static void import_assistant_init (EImportAssistant *import_assistant) { - const gchar *empty_xpm_img[] = { - "48 1 2 1", - " c None", - ". c #FFFFFF", - " "}; - GtkAssistant *assistant; + GtkIconTheme *icon_theme; GtkWidget *page; - GdkPixbuf *icon, *spacer; + GdkPixbuf *pixbuf; + gint size; assistant = GTK_ASSISTANT (import_assistant); - import_assistant->priv = E_IMPORT_ASSISTANT_GET_PRIVATE (import_assistant); + import_assistant->priv = + E_IMPORT_ASSISTANT_GET_PRIVATE (import_assistant); import_assistant->priv->import = e_import_new ("org.gnome.evolution.shell.importer"); - icon = e_icon_factory_get_icon ("stock_mail-import", GTK_ICON_SIZE_DIALOG); - spacer = gdk_pixbuf_new_from_xpm_data (empty_xpm_img); + icon_theme = gtk_icon_theme_get_default (); + gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, NULL); + pixbuf = gtk_icon_theme_load_icon ( + icon_theme, "stock_mail-import", size, 0, NULL); gtk_window_set_position (GTK_WINDOW (assistant), GTK_WIN_POS_CENTER); gtk_window_set_title (GTK_WINDOW (assistant), _("Evolution Import Assistant")); @@ -795,46 +821,41 @@ import_assistant_init (EImportAssistant *import_assistant) gtk_widget_show (page); gtk_assistant_append_page (assistant, page); - gtk_assistant_set_page_header_image (assistant, page, icon); + gtk_assistant_set_page_header_image (assistant, page, pixbuf); gtk_assistant_set_page_title (assistant, page, _("Evolution Import Assistant")); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_INTRO); - gtk_assistant_set_page_side_image (assistant, page, spacer); gtk_assistant_set_page_complete (assistant, page, TRUE); /* Intelligent or direct import page */ - import_assistant_type_page_init (import_assistant); - page = import_assistant->priv->type_page.vbox; + page = import_assistant_type_page_init (import_assistant); gtk_assistant_append_page (assistant, page); - gtk_assistant_set_page_header_image (assistant, page, icon); + gtk_assistant_set_page_header_image (assistant, page, pixbuf); gtk_assistant_set_page_title (assistant, page, _("Importer Type")); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT); gtk_assistant_set_page_complete (assistant, page, TRUE); /* Intelligent importer source page */ - import_assistant_selection_page_init (import_assistant); - page = import_assistant->priv->selection_page.vbox; + page = import_assistant_selection_page_init (import_assistant); gtk_assistant_append_page (assistant, page); - gtk_assistant_set_page_header_image (assistant, page, icon); + gtk_assistant_set_page_header_image (assistant, page, pixbuf); gtk_assistant_set_page_title (assistant, page, _("Select Information to Import")); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT); /* File selection and file type page */ - import_assistant_file_page_init (import_assistant); - page = import_assistant->priv->file_page.vbox; + page = import_assistant_file_page_init (import_assistant); gtk_assistant_append_page (assistant, page); - gtk_assistant_set_page_header_image (assistant, page, icon); + gtk_assistant_set_page_header_image (assistant, page, pixbuf); gtk_assistant_set_page_title (assistant, page, _("Select a File")); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT); /* File destination page */ - import_assistant_destination_page_init (import_assistant); - page = import_assistant->priv->destination_page.vbox; + page = import_assistant_destination_page_init (import_assistant); gtk_assistant_append_page (assistant, page); - gtk_assistant_set_page_header_image (assistant, page, icon); + gtk_assistant_set_page_header_image (assistant, page, pixbuf); gtk_assistant_set_page_title (assistant, page, _("Import Location")); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT); @@ -847,18 +868,16 @@ import_assistant_init (EImportAssistant *import_assistant) gtk_widget_show (page); gtk_assistant_append_page (assistant, page); - gtk_assistant_set_page_header_image (assistant, page, icon); + gtk_assistant_set_page_header_image (assistant, page, pixbuf); gtk_assistant_set_page_title (assistant, page, _("Import File")); gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM); - gtk_assistant_set_page_side_image (assistant, page, spacer); gtk_assistant_set_page_complete (assistant, page, TRUE); gtk_assistant_set_forward_page_func ( assistant, (GtkAssistantPageFunc) forward_cb, import_assistant, NULL); - g_object_unref (icon); - g_object_unref (spacer); + g_object_unref (pixbuf); gtk_assistant_update_buttons_state (assistant); } |