[evolution] Try to preselect source type when creating new source
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Try to preselect source type when creating new source
- Date: Fri, 8 Jun 2018 12:10:09 +0000 (UTC)
commit 9d6b57ed60ec59ade4f468acf162f2668f301395
Author: Milan Crha <mcrha redhat com>
Date: Fri Jun 8 14:06:28 2018 +0200
Try to preselect source type when creating new source
When creating new Address Book, Calendar, Memo List or Task List,
try to preselect the source type based on the currently selected
source in the active view, accounting also the clicked source
in the source selector.
This way, when creating a new calendar in the Calendar view the type
will match the one selected in the source selector, or when called
from the context menu of the source selector and it had been clicked
on the group name, then there will be preselected that group type,
if possible.
src/e-util/e-source-config.c | 45 ++++++++++++++++++++++
src/e-util/e-source-config.h | 5 +++
src/modules/addressbook/e-book-shell-backend.c | 7 ++++
.../addressbook/e-book-shell-view-actions.c | 2 +
src/modules/addressbook/e-book-shell-view.c | 35 +++++++++++++++++
src/modules/addressbook/e-book-shell-view.h | 3 ++
src/modules/calendar/e-cal-base-shell-backend.c | 18 +++++++++
src/modules/calendar/e-cal-base-shell-view.c | 39 +++++++++++++++++++
src/modules/calendar/e-cal-base-shell-view.h | 3 ++
src/modules/calendar/e-cal-shell-view-actions.c | 2 +
src/modules/calendar/e-memo-shell-view-actions.c | 2 +
src/modules/calendar/e-task-shell-view-actions.c | 2 +
12 files changed, 163 insertions(+)
---
diff --git a/src/e-util/e-source-config.c b/src/e-util/e-source-config.c
index 8ba8dd7d66..f943db4197 100644
--- a/src/e-util/e-source-config.c
+++ b/src/e-util/e-source-config.c
@@ -38,6 +38,7 @@ struct _ESourceConfigPrivate {
ESource *original_source;
ESource *collection_source;
ESourceRegistry *registry;
+ gchar *preselect_type;
GHashTable *backends;
GPtrArray *candidates;
@@ -461,6 +462,28 @@ source_config_init_for_adding_source (ESourceConfig *config)
source_config_init_for_adding_source_foreach, config);
g_tree_unref (scratch_source_tree);
+
+ if (config->priv->preselect_type) {
+ Candidate *candidate;
+ GPtrArray *array;
+ gint index;
+
+ array = config->priv->candidates;
+
+ for (index = 0; index < array->len; index++) {
+ ESourceConfigBackendClass *backend_class;
+
+ candidate = g_ptr_array_index (array, index);
+ backend_class = E_SOURCE_CONFIG_BACKEND_GET_CLASS (candidate->backend);
+
+ if (backend_class && (
+ g_strcmp0 (config->priv->preselect_type, backend_class->backend_name) == 0 ||
+ g_strcmp0 (config->priv->preselect_type, backend_class->parent_uid) == 0)) {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (config->priv->type_combo), index);
+ break;
+ }
+ }
+ }
}
static void
@@ -642,6 +665,8 @@ source_config_dispose (GObject *object)
g_hash_table_remove_all (priv->backends);
g_ptr_array_set_size (priv->candidates, 0);
+ g_clear_pointer (&priv->preselect_type, g_free);
+
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_source_config_parent_class)->dispose (object);
}
@@ -1061,6 +1086,26 @@ e_source_config_new (ESourceRegistry *registry,
"original-source", original_source, NULL);
}
+void
+e_source_config_set_preselect_type (ESourceConfig *config,
+ const gchar *source_uid)
+{
+ g_return_if_fail (E_IS_SOURCE_CONFIG (config));
+
+ if (config->priv->preselect_type != source_uid) {
+ g_free (config->priv->preselect_type);
+ config->priv->preselect_type = g_strdup (source_uid);
+ }
+}
+
+const gchar *
+e_source_config_get_preselect_type (ESourceConfig *config)
+{
+ g_return_val_if_fail (E_IS_SOURCE_CONFIG (config), NULL);
+
+ return config->priv->preselect_type;
+}
+
void
e_source_config_insert_widget (ESourceConfig *config,
ESource *scratch_source,
diff --git a/src/e-util/e-source-config.h b/src/e-util/e-source-config.h
index 596f62e935..bd5b1c4836 100644
--- a/src/e-util/e-source-config.h
+++ b/src/e-util/e-source-config.h
@@ -77,6 +77,11 @@ struct _ESourceConfigClass {
GType e_source_config_get_type (void) G_GNUC_CONST;
GtkWidget * e_source_config_new (ESourceRegistry *registry,
ESource *original_source);
+void e_source_config_set_preselect_type
+ (ESourceConfig *config,
+ const gchar *source_uid);
+const gchar * e_source_config_get_preselect_type
+ (ESourceConfig *config);
void e_source_config_insert_widget (ESourceConfig *config,
ESource *scratch_source,
const gchar *caption,
diff --git a/src/modules/addressbook/e-book-shell-backend.c b/src/modules/addressbook/e-book-shell-backend.c
index 99884e6a7d..31b92658da 100644
--- a/src/modules/addressbook/e-book-shell-backend.c
+++ b/src/modules/addressbook/e-book-shell-backend.c
@@ -251,6 +251,13 @@ action_address_book_new_cb (GtkAction *action,
registry = e_shell_get_registry (shell);
config = e_book_source_config_new (registry, NULL);
+ if (g_strcmp0 (e_shell_window_get_active_view (shell_window), "addressbook") == 0) {
+ EShellView *shell_view = e_shell_window_peek_shell_view (shell_window, "addressbook");
+
+ if (shell_view)
+ e_book_shell_view_preselect_source_config (shell_view, config);
+ }
+
dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
gtk_window_set_transient_for (
diff --git a/src/modules/addressbook/e-book-shell-view-actions.c
b/src/modules/addressbook/e-book-shell-view-actions.c
index 5b98a38a92..1966a6eaef 100644
--- a/src/modules/addressbook/e-book-shell-view-actions.c
+++ b/src/modules/addressbook/e-book-shell-view-actions.c
@@ -126,6 +126,8 @@ action_address_book_new_cb (GtkAction *action,
registry = book_shell_view->priv->registry;
config = e_book_source_config_new (registry, NULL);
+ e_book_shell_view_preselect_source_config (shell_view, config);
+
dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
gtk_window_set_transient_for (
diff --git a/src/modules/addressbook/e-book-shell-view.c b/src/modules/addressbook/e-book-shell-view.c
index 9eb898aaa5..2671afd86d 100644
--- a/src/modules/addressbook/e-book-shell-view.c
+++ b/src/modules/addressbook/e-book-shell-view.c
@@ -592,3 +592,38 @@ e_book_shell_view_get_clicked_source (EShellView *shell_view)
return book_shell_view->priv->clicked_source;
}
+
+void
+e_book_shell_view_preselect_source_config (EShellView *shell_view,
+ GtkWidget *source_config)
+{
+ ESource *clicked_source, *primary_source, *use_source = NULL;
+
+ g_return_if_fail (E_IS_BOOK_SHELL_VIEW (shell_view));
+ g_return_if_fail (E_IS_SOURCE_CONFIG (source_config));
+
+ clicked_source = e_book_shell_view_get_clicked_source (shell_view);
+ primary_source = e_source_selector_ref_primary_selection (e_book_shell_sidebar_get_selector (
+ E_BOOK_SHELL_SIDEBAR (e_shell_view_get_shell_sidebar (shell_view))));
+
+ if (clicked_source && clicked_source != primary_source)
+ use_source = clicked_source;
+ else if (primary_source)
+ use_source = primary_source;
+
+ if (use_source) {
+ ESourceBackend *source_backend = NULL;
+
+ if (e_source_has_extension (use_source, E_SOURCE_EXTENSION_COLLECTION))
+ source_backend = e_source_get_extension (use_source, E_SOURCE_EXTENSION_COLLECTION);
+ else if (e_source_has_extension (use_source, E_SOURCE_EXTENSION_ADDRESS_BOOK))
+ source_backend = e_source_get_extension (use_source, E_SOURCE_EXTENSION_ADDRESS_BOOK);
+
+ if (source_backend)
+ e_source_config_set_preselect_type (E_SOURCE_CONFIG (source_config),
e_source_backend_get_backend_name (source_backend));
+ else if (use_source == clicked_source)
+ e_source_config_set_preselect_type (E_SOURCE_CONFIG (source_config), e_source_get_uid
(use_source));
+ }
+
+ g_clear_object (&primary_source);
+}
diff --git a/src/modules/addressbook/e-book-shell-view.h b/src/modules/addressbook/e-book-shell-view.h
index 7fadff305f..024bed3f29 100644
--- a/src/modules/addressbook/e-book-shell-view.h
+++ b/src/modules/addressbook/e-book-shell-view.h
@@ -66,6 +66,9 @@ void e_book_shell_view_maybe_prefill_list_with_selection
(EShellView *shell_view,
EContact *contact);
ESource * e_book_shell_view_get_clicked_source (EShellView *shell_view);
+void e_book_shell_view_preselect_source_config
+ (EShellView *shell_view,
+ GtkWidget *source_config);
G_END_DECLS
diff --git a/src/modules/calendar/e-cal-base-shell-backend.c b/src/modules/calendar/e-cal-base-shell-backend.c
index 6de48a89fb..d42de383a0 100644
--- a/src/modules/calendar/e-cal-base-shell-backend.c
+++ b/src/modules/calendar/e-cal-base-shell-backend.c
@@ -30,6 +30,7 @@
#include "shell/e-shell-view.h"
#include "shell/e-shell-window.h"
+#include "e-cal-base-shell-view.h"
#include "e-cal-base-shell-backend.h"
/*
@@ -85,6 +86,17 @@ cal_base_shell_backend_handle_webcal_uri (EShellBackend *shell_backend,
config = e_cal_source_config_new (registry, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS);
source_config = E_SOURCE_CONFIG (config);
+ if (E_IS_SHELL_WINDOW (active_window)) {
+ EShellWindow *shell_window;
+ EShellView *shell_view;
+
+ shell_window = E_SHELL_WINDOW (active_window);
+ shell_view = e_shell_window_peek_shell_view (shell_window, e_shell_window_get_active_view
(shell_window));
+
+ if (shell_view && E_IS_CAL_BASE_SHELL_VIEW (shell_view))
+ e_cal_base_shell_view_preselect_source_config (shell_view, config);
+ }
+
extension_name = e_source_config_get_backend_extension_name (source_config);
dialog = e_source_config_dialog_new (source_config);
@@ -295,6 +307,7 @@ e_cal_base_shell_backend_util_new_source (EShellWindow *shell_window,
ECalClientSourceType source_type)
{
EShell *shell;
+ EShellView *shell_view;
ESourceRegistry *registry;
GtkWidget *config;
GtkWidget *dialog;
@@ -327,6 +340,11 @@ e_cal_base_shell_backend_util_new_source (EShellWindow *shell_window,
registry = e_shell_get_registry (shell);
config = e_cal_source_config_new (registry, NULL, source_type);
+ shell_view = e_shell_window_peek_shell_view (shell_window, e_shell_window_get_active_view
(shell_window));
+
+ if (shell_view && E_IS_CAL_BASE_SHELL_VIEW (shell_view))
+ e_cal_base_shell_view_preselect_source_config (shell_view, config);
+
dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
window = GTK_WINDOW (dialog);
diff --git a/src/modules/calendar/e-cal-base-shell-view.c b/src/modules/calendar/e-cal-base-shell-view.c
index eb98d0d8ec..924d64ef8d 100644
--- a/src/modules/calendar/e-cal-base-shell-view.c
+++ b/src/modules/calendar/e-cal-base-shell-view.c
@@ -454,3 +454,42 @@ e_cal_base_shell_view_refresh_backend (EShellView *shell_view,
g_object_unref (cancellable);
}
+
+void
+e_cal_base_shell_view_preselect_source_config (EShellView *shell_view,
+ GtkWidget *source_config)
+{
+ ESource *clicked_source, *primary_source, *use_source = NULL;
+
+ g_return_if_fail (E_IS_CAL_BASE_SHELL_VIEW (shell_view));
+ g_return_if_fail (E_IS_SOURCE_CONFIG (source_config));
+
+ clicked_source = e_cal_base_shell_view_get_clicked_source (shell_view);
+ primary_source = e_source_selector_ref_primary_selection (e_cal_base_shell_sidebar_get_selector (
+ E_CAL_BASE_SHELL_SIDEBAR (e_shell_view_get_shell_sidebar (shell_view))));
+
+ if (clicked_source && clicked_source != primary_source)
+ use_source = clicked_source;
+ else if (primary_source)
+ use_source = primary_source;
+
+ if (use_source) {
+ ESourceBackend *source_backend = NULL;
+
+ if (e_source_has_extension (use_source, E_SOURCE_EXTENSION_COLLECTION))
+ source_backend = e_source_get_extension (use_source, E_SOURCE_EXTENSION_COLLECTION);
+ else if (e_source_has_extension (use_source, E_SOURCE_EXTENSION_CALENDAR))
+ source_backend = e_source_get_extension (use_source, E_SOURCE_EXTENSION_CALENDAR);
+ else if (e_source_has_extension (use_source, E_SOURCE_EXTENSION_MEMO_LIST))
+ source_backend = e_source_get_extension (use_source, E_SOURCE_EXTENSION_MEMO_LIST);
+ else if (e_source_has_extension (use_source, E_SOURCE_EXTENSION_TASK_LIST))
+ source_backend = e_source_get_extension (use_source, E_SOURCE_EXTENSION_TASK_LIST);
+
+ if (source_backend)
+ e_source_config_set_preselect_type (E_SOURCE_CONFIG (source_config),
e_source_backend_get_backend_name (source_backend));
+ else if (use_source == clicked_source)
+ e_source_config_set_preselect_type (E_SOURCE_CONFIG (source_config), e_source_get_uid
(use_source));
+ }
+
+ g_clear_object (&primary_source);
+}
diff --git a/src/modules/calendar/e-cal-base-shell-view.h b/src/modules/calendar/e-cal-base-shell-view.h
index 8ea5246cf5..7caaaedd6f 100644
--- a/src/modules/calendar/e-cal-base-shell-view.h
+++ b/src/modules/calendar/e-cal-base-shell-view.h
@@ -79,6 +79,9 @@ ESource * e_cal_base_shell_view_get_clicked_source
(EShellView *shell_view);
void e_cal_base_shell_view_refresh_backend (EShellView *shell_view,
ESource *collection_source);
+void e_cal_base_shell_view_preselect_source_config
+ (EShellView *shell_view,
+ GtkWidget *source_config);
G_END_DECLS
diff --git a/src/modules/calendar/e-cal-shell-view-actions.c b/src/modules/calendar/e-cal-shell-view-actions.c
index 835d32d40b..91f6831116 100644
--- a/src/modules/calendar/e-cal-shell-view-actions.c
+++ b/src/modules/calendar/e-cal-shell-view-actions.c
@@ -167,6 +167,8 @@ action_calendar_new_cb (GtkAction *action,
source_type = E_CAL_CLIENT_SOURCE_TYPE_EVENTS;
config = e_cal_source_config_new (registry, NULL, source_type);
+ e_cal_base_shell_view_preselect_source_config (shell_view, config);
+
dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
gtk_window_set_transient_for (
diff --git a/src/modules/calendar/e-memo-shell-view-actions.c
b/src/modules/calendar/e-memo-shell-view-actions.c
index 50e13781ca..d2d3fc6ec3 100644
--- a/src/modules/calendar/e-memo-shell-view-actions.c
+++ b/src/modules/calendar/e-memo-shell-view-actions.c
@@ -167,6 +167,8 @@ action_memo_list_new_cb (GtkAction *action,
source_type = E_CAL_CLIENT_SOURCE_TYPE_MEMOS;
config = e_cal_source_config_new (registry, NULL, source_type);
+ e_cal_base_shell_view_preselect_source_config (shell_view, config);
+
dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
gtk_window_set_transient_for (
diff --git a/src/modules/calendar/e-task-shell-view-actions.c
b/src/modules/calendar/e-task-shell-view-actions.c
index fb62f59f17..e7f730eef0 100644
--- a/src/modules/calendar/e-task-shell-view-actions.c
+++ b/src/modules/calendar/e-task-shell-view-actions.c
@@ -191,6 +191,8 @@ action_task_list_new_cb (GtkAction *action,
source_type = E_CAL_CLIENT_SOURCE_TYPE_TASKS;
config = e_cal_source_config_new (registry, NULL, source_type);
+ e_cal_base_shell_view_preselect_source_config (shell_view, config);
+
dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
gtk_window_set_transient_for (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]