Esempio n. 1
0
/**
 * e_shell_utils_import_uris:
 * @shell: The #EShell instance
 * @uris: %NULL-terminated list of URIs to import
 *
 * Imports given URIs to Evolution, giving user a choice what to import
 * if more than one importer can be applied, and where to import it, if
 * the importer itself is configurable.
 *
 * URIs should be either a filename or URI of form file://.
 * All others are skipped.
 *
 * Returns: the number of URIs successfully handled
 **/
guint
e_shell_utils_import_uris (EShell *shell,
                           const gchar * const *uris)
{
    GtkWindow *parent;
    GtkWidget *assistant;

    g_return_val_if_fail (shell != NULL, 0);
    g_return_val_if_fail (uris != NULL, 0);

    parent = e_shell_get_active_window (shell);
    assistant = e_import_assistant_new_simple (parent, uris);

    if (assistant) {
        g_signal_connect_after (
            assistant, "cancel",
            G_CALLBACK (gtk_widget_destroy), NULL);

        g_signal_connect_after (
            assistant, "finished",
            G_CALLBACK (gtk_widget_destroy), NULL);

        gtk_application_add_window (
            GTK_APPLICATION (shell),
            GTK_WINDOW (assistant));

        gtk_widget_show (assistant);
    } else
        g_warning ("Cannot import any of the given URIs");

    return g_strv_length ((gchar **) uris);
}
Esempio n. 2
0
static gboolean
shell_migrate_attempt (EShell *shell,
                       gint major,
                       gint minor,
                       gint micro)
{
	GtkWindow *parent;
	GList *backends;
	gboolean success = TRUE;

	parent = e_shell_get_active_window (shell);
	backends = e_shell_get_shell_backends (shell);

	/* New user accounts have nothing to migrate. */
	if (major == 0 && minor == 0 && micro == 0)
		return TRUE;

	/* We only support migrating from version 2 now. */
	if (major < 2) {
		gchar *version;
		gint response;

		version = g_strdup_printf ("%d.%d", major, minor);
		response = e_alert_run_dialog_for_args (
			parent, "shell:upgrade-version-too-old",
			version, NULL);
		g_free (version);

		return (response == GTK_RESPONSE_OK);
	}

	/* Ask each of the shell backends to migrate their own data.
	 * XXX If something fails the user may end up with only partially
	 *     migrated data.  Need transaction semantics here, but how? */
	while (success && backends != NULL) {
		EShellBackend *shell_backend = backends->data;
		GError *error = NULL;

		success = e_shell_backend_migrate (
			shell_backend, major, minor, micro, &error);

		if (error != NULL) {
			gint response;

			response = e_alert_run_dialog_for_args (
				parent, "shell:upgrade-failed",
				error->message, NULL);

			success = (response == GTK_RESPONSE_OK);

			g_error_free (error);
		}

		backends = g_list_next (backends);
	}

	return success;
}
Esempio n. 3
0
void
e_convert_local_mail (EShell *shell)
{
	CamelSession *session;
	ESource *mbox_source;
	const gchar *user_data_dir;
	const gchar *user_cache_dir;
	gchar *mail_data_dir;
	gchar *mail_cache_dir;
	gchar *local_store;
	gint response;

	user_data_dir = e_get_user_data_dir ();
	user_cache_dir = e_get_user_cache_dir ();

	mail_data_dir = g_build_filename (user_data_dir, "mail", NULL);
	mail_cache_dir = g_build_filename (user_cache_dir, "mail", NULL);

	if (!mail_to_maildir_migration_needed (mail_data_dir))
		goto exit;

	response = e_alert_run_dialog_for_args (
		e_shell_get_active_window (NULL),
		"mail:ask-migrate-store", NULL);

	if (response == GTK_RESPONSE_CANCEL)
		exit (EXIT_SUCCESS);

	mbox_source = e_source_new (NULL, NULL, NULL);

	rename_mbox_dir (mbox_source, mail_data_dir);

	local_store = g_build_filename (mail_data_dir, "local", NULL);

	if (!g_file_test (local_store, G_FILE_TEST_EXISTS))
		g_mkdir_with_parents (local_store, 0700);

	g_free (local_store);

	session = g_object_new (
		CAMEL_TYPE_SESSION,
		"online", FALSE,
		"user-data-dir", mail_data_dir,
		"user-cache-dir", mail_cache_dir,
		NULL);

	migrate_mbox_to_maildir (shell, session, mbox_source);

	g_object_unref (session);

	g_object_unref (mbox_source);

exit:
	g_free (mail_data_dir);
	g_free (mail_cache_dir);
}
Esempio n. 4
0
void
e_shell_utils_run_help_about (EShell *shell)
{
#define EVOLUTION_COPYRIGHT \
		"Copyright \xC2\xA9 1999 - 2008 Novell, Inc. and Others\n" \
		"Copyright \xC2\xA9 2008 - 2016 The Evolution Team"

    /* Authors and Documenters
     *
     * The names below must be in UTF-8.  The breaking of escaped strings
     * is so the hexadecimal sequences don't swallow too many characters.
     *
     * SO THAT MEANS, FOR 8-BIT CHARACTERS USE \xXX HEX ENCODING ONLY!
     *
     * Not all environments are UTF-8 and not all editors can handle it.
     */
    static const gchar *authors[] = {
        "The Evolution Team",
        "",
        "Milan Crha <*****@*****.**>",
        "Fabiano Fid\xC3\xAAncio <*****@*****.**>",
        "",
        "and many past contributors",
        NULL
    };

    static const gchar *documenters[] = {
        "Andre Klapper",
        NULL
    };

    gchar *translator_credits;

    /* The translator-credits string is for translators to list
     * per-language credits for translation, displayed in the
     * about dialog. */
    translator_credits = _("translator-credits");
    if (strcmp (translator_credits, "translator-credits") == 0)
        translator_credits = NULL;

    gtk_show_about_dialog (
        e_shell_get_active_window (shell),
        "program-name", "Evolution",
        "version", VERSION,
        "copyright", EVOLUTION_COPYRIGHT,
        "comments", _("Groupware Suite"),
        "website", PACKAGE_URL,
        "website-label", _("Evolution Website"),
        "authors", authors,
        "documenters", documenters,
        "translator-credits", translator_credits,
        "logo-icon-name", "evolution",
        "license-type", GTK_LICENSE_GPL_2_0,
        NULL);
}
Esempio n. 5
0
void
e_shell_utils_run_preferences (EShell *shell)
{
    GtkWidget *preferences_window;
    GtkWindow *window;

    preferences_window = e_shell_get_preferences_window (shell);
    e_preferences_window_setup (E_PREFERENCES_WINDOW (preferences_window));

    window = e_shell_get_active_window (shell);
    g_return_if_fail (GTK_IS_WINDOW (window));

    gtk_window_set_transient_for (
        GTK_WINDOW (preferences_window),
        window);
    gtk_window_set_position (
        GTK_WINDOW (preferences_window),
        GTK_WIN_POS_CENTER_ON_PARENT);
    gtk_window_present (GTK_WINDOW (preferences_window));

    if (E_IS_SHELL_WINDOW (window)) {
        EShellView *shell_view;
        EShellWindow *shell_window;
        EShellBackend *shell_backend;
        EShellBackendClass *shell_backend_class;
        const gchar *view_name;

        shell_window = E_SHELL_WINDOW (window);
        view_name = e_shell_window_get_active_view (shell_window);
        shell_view = e_shell_window_get_shell_view (shell_window, view_name);

        shell_backend = e_shell_view_get_shell_backend (shell_view);
        shell_backend_class = E_SHELL_BACKEND_GET_CLASS (shell_backend);

        if (shell_backend_class->preferences_page != NULL)
            e_preferences_window_show_page (
                E_PREFERENCES_WINDOW (preferences_window),
                shell_backend_class->preferences_page);
    }
}
Esempio n. 6
0
/**
 * e_shell_run_open_dialog:
 * @shell: an #EShell
 * @title: file chooser dialog title
 * @customize_func: optional dialog customization function
 * @customize_data: optional data to pass to @customize_func
 *
 * Runs a #GtkFileChooserDialog in open mode with the given title and
 * returns the selected #GFile.  If @customize_func is provided, the
 * function is called just prior to running the dialog (the file chooser
 * is the first argument, @customize data is the second).  If the user
 * cancels the dialog the function will return %NULL.
 *
 * Returns: the #GFile to open, or %NULL
 **/
GFile *
e_shell_run_open_dialog (EShell *shell,
                         const gchar *title,
                         GtkCallback customize_func,
                         gpointer customize_data)
{
    GtkFileChooser *file_chooser;
    GFile *chosen_file = NULL;
    GtkWidget *dialog;
    GtkWindow *parent;

    g_return_val_if_fail (E_IS_SHELL (shell), NULL);

    parent = e_shell_get_active_window (shell);

    dialog = gtk_file_chooser_dialog_new (
                 title, parent,
                 GTK_FILE_CHOOSER_ACTION_OPEN,
                 _("_Cancel"), GTK_RESPONSE_CANCEL,
                 _("_Open"), GTK_RESPONSE_ACCEPT, NULL);

    file_chooser = GTK_FILE_CHOOSER (dialog);

    gtk_dialog_set_default_response (
        GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);

    gtk_file_chooser_set_local_only (file_chooser, FALSE);

    /* Allow further customizations before running the dialog. */
    if (customize_func != NULL)
        customize_func (dialog, customize_data);

    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
        chosen_file = gtk_file_chooser_get_file (file_chooser);

    gtk_widget_destroy (dialog);

    return chosen_file;
}
Esempio n. 7
0
void
e_shell_utils_run_help_contents (EShell *shell)
{
#ifdef G_OS_WIN32
    gchar *online_help_url;
#endif
    GtkWindow *window;

    window = e_shell_get_active_window (shell);
#ifdef G_OS_WIN32
    /* On Windows, link to online help instead.
     * See https://bugzilla.gnome.org/show_bug.cgi?id=576478 */

    online_help_url = g_strconcat (
                          "http://library.gnome.org/users/evolution/",
                          BASE_VERSION, NULL);
    e_show_uri (window, online_help_url);
    g_free (online_help_url);
#else
    e_display_help (window, NULL);
#endif
}
static GtkWidget *
mbox_getwidget (EImport *ei,
                EImportTarget *target,
                EImportImporter *im)
{
	EShell *shell;
	EShellBackend *shell_backend;
	EMailBackend *backend;
	EMailSession *session;
	GtkWindow *window;
	GtkWidget *hbox, *w;
	GtkLabel *label;
	gchar *select_uri = NULL;

	/* XXX Dig up the mail backend from the default EShell.
	 *     Since the EImport framework doesn't allow for user
	 *     data, I don't see how else to get to it. */
	shell = e_shell_get_default ();
	shell_backend = e_shell_get_backend_by_name (shell, "mail");

	backend = E_MAIL_BACKEND (shell_backend);
	session = e_mail_backend_get_session (backend);

	/* preselect the folder selected in a mail view */
	window = e_shell_get_active_window (shell);
	if (E_IS_SHELL_WINDOW (window)) {
		EShellWindow *shell_window;
		const gchar *view;

		shell_window = E_SHELL_WINDOW (window);
		view = e_shell_window_get_active_view (shell_window);

		if (view && g_str_equal (view, "mail")) {
			EShellView *shell_view;
			EShellSidebar *shell_sidebar;
			EMFolderTree *folder_tree = NULL;

			shell_view = e_shell_window_get_shell_view (
				shell_window, view);

			shell_sidebar =
				e_shell_view_get_shell_sidebar (shell_view);

			g_object_get (
				shell_sidebar, "folder-tree",
				&folder_tree, NULL);

			select_uri =
				em_folder_tree_get_selected_uri (folder_tree);

			g_object_unref (folder_tree);
		}
	}

	if (!select_uri) {
		const gchar *uri;
		uri = e_mail_session_get_local_folder_uri (
			session, E_MAIL_LOCAL_FOLDER_INBOX);
		select_uri = g_strdup (uri);
	}

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);

	w = gtk_label_new_with_mnemonic (_("_Destination folder:"));
	gtk_box_pack_start ((GtkBox *) hbox, w, FALSE, TRUE, 6);

	label = GTK_LABEL (w);

	w = em_folder_selection_button_new (
		session, _("Select folder"),
		_("Select folder to import into"));
	gtk_label_set_mnemonic_widget (label, w);
	em_folder_selection_button_set_folder_uri (
		EM_FOLDER_SELECTION_BUTTON (w), select_uri);
	folder_selected (
		EM_FOLDER_SELECTION_BUTTON (w), (EImportTargetURI *) target);
	g_signal_connect (
		w, "selected",
		G_CALLBACK (folder_selected), target);
	gtk_box_pack_start ((GtkBox *) hbox, w, FALSE, TRUE, 6);

	w = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	gtk_box_pack_start ((GtkBox *) w, hbox, FALSE, FALSE, 0);
	gtk_widget_show_all (w);

	g_free (select_uri);

	return w;
}
Esempio n. 9
0
/**
 * e_shell_run_save_dialog:
 * @shell: an #EShell
 * @title: file chooser dialog title
 * @suggestion: file name suggestion, or %NULL
 * @filters: Possible filters for dialog, or %NULL
 * @customize_func: optional dialog customization function
 * @customize_data: optional data to pass to @customize_func
 *
 * Runs a #GtkFileChooserDialog in save mode with the given title and
 * returns the selected #GFile.  If @customize_func is provided, the
 * function is called just prior to running the dialog (the file chooser
 * is the first argument, @customize_data is the second).  If the user
 * cancels the dialog the function will return %NULL.
 *
 * With non-%NULL @filters will be added also file filters to the dialog.
 * The string format is "pat1:mt1;pat2:mt2:...", where 'pat' is a pattern
 * and 'mt' is a MIME type for the pattern to be used.  There can be more
 * than one MIME type, those are separated by comma.
 *
 * Returns: the #GFile to save to, or %NULL
 **/
GFile *
e_shell_run_save_dialog (EShell *shell,
                         const gchar *title,
                         const gchar *suggestion,
                         const gchar *filters,
                         GtkCallback customize_func,
                         gpointer customize_data)
{
    GtkFileChooser *file_chooser;
    GFile *chosen_file = NULL;
    GtkWidget *dialog;
    GtkWindow *parent;

    g_return_val_if_fail (E_IS_SHELL (shell), NULL);

    parent = e_shell_get_active_window (shell);

    dialog = gtk_file_chooser_dialog_new (
                 title, parent,
                 GTK_FILE_CHOOSER_ACTION_SAVE,
                 _("_Cancel"), GTK_RESPONSE_CANCEL,
                 _("_Save"), GTK_RESPONSE_ACCEPT, NULL);

    file_chooser = GTK_FILE_CHOOSER (dialog);

    gtk_dialog_set_default_response (
        GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);

    gtk_file_chooser_set_local_only (file_chooser, FALSE);
    gtk_file_chooser_set_do_overwrite_confirmation (file_chooser, TRUE);

    if (suggestion != NULL) {
        gchar *current_name;

        current_name = g_strdup (suggestion);
        e_filename_make_safe (current_name);
        gtk_file_chooser_set_current_name (file_chooser, current_name);
        g_free (current_name);
    }

    if (filters != NULL) {
        gchar **flts = g_strsplit (filters, ";", -1);
        gint i;

        for (i = 0; flts && flts[i]; i++) {
            GtkFileFilter *filter = gtk_file_filter_new ();
            gchar *flt = flts[i];
            gchar *delim = strchr (flt, ':'), *next = NULL;

            if (delim) {
                *delim = 0;
                next = strchr (delim + 1, ',');
            }

            gtk_file_filter_add_pattern (filter, flt);
            if (g_ascii_strcasecmp (flt, "*.mbox") == 0)
                gtk_file_filter_set_name (
                    filter, _("Berkeley Mailbox (mbox)"));
            else if (g_ascii_strcasecmp (flt, "*.vcf") == 0)
                gtk_file_filter_set_name (
                    filter, _("vCard (.vcf)"));
            else if (g_ascii_strcasecmp (flt, "*.ics") == 0)
                gtk_file_filter_set_name (
                    filter, _("iCalendar (.ics)"));
            else
                gtk_file_filter_set_name (filter, flt);

            while (delim) {
                delim++;
                if (next)
                    *next = 0;

                gtk_file_filter_add_mime_type (filter, delim);

                delim = next;
                if (next)
                    next = strchr (next + 1, ',');
            }

            gtk_file_chooser_add_filter (file_chooser, filter);
        }

        if (flts && flts[0]) {
            GtkFileFilter *filter = gtk_file_filter_new ();

            gtk_file_filter_add_pattern (filter, "*");
            gtk_file_filter_set_name (filter, _("All Files (*)"));
            gtk_file_chooser_add_filter (file_chooser, filter);
        }

        g_strfreev (flts);
    }

    /* Allow further customizations before running the dialog. */
    if (customize_func != NULL)
        customize_func (dialog, customize_data);

    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
        chosen_file = gtk_file_chooser_get_file (file_chooser);

    gtk_widget_destroy (dialog);

    return chosen_file;
}
Esempio n. 10
0
static gboolean
report_error_to_ui_cb (gpointer user_data)
{
	struct ReportErrorToUIData *data = user_data;
	EShellView *shell_view = NULL;

	g_return_val_if_fail (data != NULL, FALSE);
	g_return_val_if_fail (data->display_name != NULL, FALSE);
	g_return_val_if_fail (data->error_ident != NULL, FALSE);
	g_return_val_if_fail (data->error != NULL, FALSE);

	if (send_recv_dialog) {
		GtkWidget *parent;

		parent = gtk_widget_get_parent (send_recv_dialog);
		if (parent && E_IS_SHELL_WINDOW (parent)) {
			EShellWindow *shell_window = E_SHELL_WINDOW (parent);

			shell_view = e_shell_window_get_shell_view (shell_window, "mail");
		}
	}

	if (!shell_view) {
		EShell *shell;
		GtkWindow *active_window;

		shell = e_shell_get_default ();
		active_window = e_shell_get_active_window (shell);

		if (E_IS_SHELL_WINDOW (active_window)) {
			EShellWindow *shell_window = E_SHELL_WINDOW (active_window);

			shell_view = e_shell_window_get_shell_view (shell_window, "mail");
		}
	}

	if (shell_view) {
		EShellContent *shell_content;
		EAlertSink *alert_sink;
		EAlert *alert;

		shell_content = e_shell_view_get_shell_content (shell_view);
		alert_sink = E_ALERT_SINK (shell_content);

		alert = e_alert_new (data->error_ident, data->display_name, data->error->message, NULL);

		e_alert_sink_submit_alert (alert_sink, alert);

		g_object_unref (alert);
	} else {
		/* This may not happen, but just in case... */
		g_warning ("%s: %s '%s': %s\n", G_STRFUNC, data->error_ident, data->display_name, data->error->message);
	}

	g_free (data->display_name);
	g_free (data->error_ident);
	g_error_free (data->error);
	g_free (data);

	return FALSE;
}