diff options
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | modules/Makefile.am | 1 | ||||
-rw-r--r-- | modules/imap-features/Makefile.am | 33 | ||||
-rw-r--r-- | modules/imap-features/e-mail-config-header-manager.c | 500 | ||||
-rw-r--r-- | modules/imap-features/e-mail-config-header-manager.h | 72 | ||||
-rw-r--r-- | modules/imap-features/e-mail-config-imap-headers-page.c | 434 | ||||
-rw-r--r-- | modules/imap-features/e-mail-config-imap-headers-page.h | 74 | ||||
-rw-r--r-- | modules/imap-features/evolution-imap-features.c | 116 | ||||
-rw-r--r-- | plugins/imap-features/Makefile.am | 44 | ||||
-rw-r--r-- | plugins/imap-features/imap-headers.c | 363 | ||||
-rw-r--r-- | plugins/imap-features/imap-headers.ui | 327 | ||||
-rw-r--r-- | plugins/imap-features/org-gnome-imap-features.eplug.xml | 18 |
12 files changed, 1232 insertions, 754 deletions
diff --git a/configure.ac b/configure.ac index c54c246533..4f7c151f0b 100644 --- a/configure.ac +++ b/configure.ac @@ -1298,7 +1298,7 @@ AC_ARG_ENABLE([plugins], [enable_plugins="$enableval"],[enable_plugins=all]) dnl Add any new plugins here -plugins_base_always="itip-formatter default-source mark-all-read publish-calendar imap-features" +plugins_base_always="itip-formatter default-source mark-all-read publish-calendar" plugins_base="$plugins_base_always" dist_plugins_base="$plugins_base_always" @@ -1643,6 +1643,7 @@ modules/cal-config-local/Makefile modules/cal-config-weather/Makefile modules/cal-config-webcal/Makefile modules/composer-autosave/Makefile +modules/imap-features/Makefile modules/mailto-handler/Makefile modules/mdn/Makefile modules/online-accounts/Makefile @@ -1664,7 +1665,6 @@ plugins/email-custom-header/Makefile plugins/external-editor/Makefile plugins/face/Makefile plugins/image-inline/Makefile -plugins/imap-features/Makefile plugins/itip-formatter/Makefile plugins/mail-notification/Makefile plugins/mail-to-task/Makefile diff --git a/modules/Makefile.am b/modules/Makefile.am index 46f4720796..67f7b3c20d 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -35,6 +35,7 @@ SUBDIRS = \ $(CONFIG_WEATHER_DIR) \ cal-config-webcal \ composer-autosave \ + imap-features \ mailto-handler \ mdn \ offline-alert \ diff --git a/modules/imap-features/Makefile.am b/modules/imap-features/Makefile.am new file mode 100644 index 0000000000..d49ddfa287 --- /dev/null +++ b/modules/imap-features/Makefile.am @@ -0,0 +1,33 @@ +NULL = + +module_LTLIBRARIES = module-imap-features.la + +module_imap_features_la_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/widgets \ + -DG_LOG_DOMAIN=\"evolution-imap-features\" \ + $(EVOLUTION_DATA_SERVER_CFLAGS) \ + $(GNOME_PLATFORM_CFLAGS) \ + $(NULL) + +module_imap_features_la_SOURCES = \ + evolution-imap-features.c \ + e-mail-config-header-manager.c \ + e-mail-config-header-manager.h \ + e-mail-config-imap-headers-page.c \ + e-mail-config-imap-headers-page.h \ + $(NULL) + +module_imap_features_la_LIBADD = \ + $(top_builddir)/mail/libevolution-mail.la \ + $(top_builddir)/widgets/misc/libemiscwidgets.la \ + $(top_builddir)/libemail-engine/libemail-engine.la \ + $(EVOLUTION_DATA_SERVER_LIBS) \ + $(GNOME_PLATFORM_LIBS) \ + $(NULL) + +module_imap_features_la_LDFLAGS = \ + -module -avoid-version $(NO_UNDEFINED) + +-include $(top_srcdir)/git.mk diff --git a/modules/imap-features/e-mail-config-header-manager.c b/modules/imap-features/e-mail-config-header-manager.c new file mode 100644 index 0000000000..1e8e3ec159 --- /dev/null +++ b/modules/imap-features/e-mail-config-header-manager.c @@ -0,0 +1,500 @@ +/* + * e-mail-config-header-manager.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#include "e-mail-config-header-manager.h" + +#define E_MAIL_CONFIG_HEADER_MANAGER_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MAIL_CONFIG_HEADER_MANAGER, EMailConfigHeaderManagerPrivate)) + +struct _EMailConfigHeaderManagerPrivate { + GHashTable *headers; + + GtkWidget *entry; /* not referenced */ + GtkWidget *tree_view; /* not referenced */ + GtkWidget *add_button; /* not referenced */ + GtkWidget *remove_button; /* not referenced */ +}; + +enum { + PROP_0, + PROP_HEADERS +}; + +G_DEFINE_DYNAMIC_TYPE ( + EMailConfigHeaderManager, + e_mail_config_header_manager, + GTK_TYPE_GRID) + +static gboolean +mail_config_header_manager_header_is_valid (const gchar *header) +{ + gchar *stripped_header; + gboolean is_valid; + glong length; + + if (header == NULL) + return FALSE; + + stripped_header = g_strstrip (g_strdup (header)); + length = g_utf8_strlen (stripped_header, -1); + + is_valid = + (*stripped_header != '\0') && + (g_utf8_strchr (stripped_header, length, ':') == NULL) && + (g_utf8_strchr (stripped_header, length, ' ') == NULL); + + g_free (stripped_header); + + return is_valid; +} + +static gboolean +mail_config_header_manager_header_to_boolean (GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer unused) +{ + gboolean is_valid; + const gchar *string; + + string = g_value_get_string (source_value); + is_valid = mail_config_header_manager_header_is_valid (string); + g_value_set_boolean (target_value, is_valid); + + return TRUE; +} + +static void +mail_config_header_manager_update_list (EMailConfigHeaderManager *manager) +{ + GtkTreeView *tree_view; + GtkTreeModel *tree_model; + GtkListStore *list_store; + GtkTreeSelection *selection; + GtkTreePath *path = NULL; + GList *list, *link; + + tree_view = GTK_TREE_VIEW (manager->priv->tree_view); + selection = gtk_tree_view_get_selection (tree_view); + + list = gtk_tree_selection_get_selected_rows (selection, &tree_model); + if (g_list_length (list) == 1) + path = gtk_tree_path_copy (list->data); + g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); + + list_store = GTK_LIST_STORE (tree_model); + gtk_list_store_clear (list_store); + + list = g_hash_table_get_keys (manager->priv->headers); + list = g_list_sort (list, (GCompareFunc) g_utf8_collate); + + for (link = list; link != NULL; link = g_list_next (link)) { + GtkTreeIter iter; + const gchar *header = link->data; + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, 0, header, -1); + } + + g_list_free (list); + + if (path != NULL) { + gtk_tree_selection_select_path (selection, path); + if (!gtk_tree_selection_path_is_selected (selection, path)) + if (gtk_tree_path_prev (path)) + gtk_tree_selection_select_path (selection, path); + gtk_tree_path_free (path); + } +} + +static gboolean +mail_config_header_manager_add_header (EMailConfigHeaderManager *manager, + const gchar *header) +{ + gchar *stripped_header; + + if (!mail_config_header_manager_header_is_valid (header)) + return FALSE; + + stripped_header = g_strstrip (g_strdup (header)); + + g_hash_table_replace ( + manager->priv->headers, + stripped_header, stripped_header); + + g_object_notify (G_OBJECT (manager), "headers"); + + mail_config_header_manager_update_list (manager); + + return TRUE; +} + +static void +mail_config_header_manager_remove_selected (EMailConfigHeaderManager *manager) +{ + GtkTreeView *tree_view; + GtkTreeModel *tree_model; + GtkTreeSelection *selection; + GList *list, *link; + + tree_view = GTK_TREE_VIEW (manager->priv->tree_view); + selection = gtk_tree_view_get_selection (tree_view); + list = gtk_tree_selection_get_selected_rows (selection, &tree_model); + + for (link = list; link != NULL; link = g_list_next (link)) { + GtkTreePath *path = link->data; + GtkTreeIter iter; + gchar *header; + + gtk_tree_model_get_iter (tree_model, &iter, path); + gtk_tree_model_get (tree_model, &iter, 0, &header, -1); + g_hash_table_remove (manager->priv->headers, header); + } + + g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); + + g_object_notify (G_OBJECT (manager), "headers"); + + mail_config_header_manager_update_list (manager); +} + +static void +mail_config_header_manager_entry_activate (GtkEntry *entry, + EMailConfigHeaderManager *manager) +{ + const gchar *header; + + header = gtk_entry_get_text (entry); + if (mail_config_header_manager_add_header (manager, header)) + gtk_entry_set_text (entry, ""); +} + +static gboolean +mail_config_header_manager_key_press_event (GtkTreeView *tree_view, + GdkEventKey *event, + EMailConfigHeaderManager *manager) +{ + if (event->keyval == GDK_KEY_Delete) { + mail_config_header_manager_remove_selected (manager); + return TRUE; + } + + return FALSE; +} + +static void +mail_config_header_manager_add_clicked (GtkButton *button, + EMailConfigHeaderManager *manager) +{ + GtkEntry *entry; + const gchar *header; + + entry = GTK_ENTRY (manager->priv->entry); + + header = gtk_entry_get_text (entry); + if (mail_config_header_manager_add_header (manager, header)) + gtk_entry_set_text (entry, ""); +} + +static void +mail_config_header_manager_remove_clicked (GtkButton *button, + EMailConfigHeaderManager *manager) +{ + mail_config_header_manager_remove_selected (manager); +} + +static void +mail_config_header_manager_selection_changed (GtkTreeSelection *selection, + EMailConfigHeaderManager *manager) +{ + gint n_rows; + + n_rows = gtk_tree_selection_count_selected_rows (selection); + gtk_widget_set_sensitive (manager->priv->remove_button, n_rows > 0); +} + +static void +mail_config_header_manager_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_HEADERS: + e_mail_config_header_manager_set_headers ( + E_MAIL_CONFIG_HEADER_MANAGER (object), + g_value_get_boxed (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +mail_config_header_manager_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_HEADERS: + g_value_take_boxed ( + value, + e_mail_config_header_manager_dup_headers ( + E_MAIL_CONFIG_HEADER_MANAGER (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +mail_config_header_manager_finalize (GObject *object) +{ + EMailConfigHeaderManagerPrivate *priv; + + priv = E_MAIL_CONFIG_HEADER_MANAGER_GET_PRIVATE (object); + + g_hash_table_destroy (priv->headers); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (e_mail_config_header_manager_parent_class)-> + finalize (object); +} + +static void +mail_config_header_manager_constructed (GObject *object) +{ + EMailConfigHeaderManager *manager; + GtkTreeViewColumn *column; + GtkTreeSelection *selection; + GtkCellRenderer *renderer; + GtkListStore *list_store; + GtkWidget *widget; + GtkWidget *container; + + manager = E_MAIL_CONFIG_HEADER_MANAGER (object); + + /* Chain up to parent's constructed() method. */ + G_OBJECT_CLASS (e_mail_config_header_manager_parent_class)-> + constructed (object); + + gtk_grid_set_row_spacing (GTK_GRID (manager), 6); + gtk_grid_set_column_spacing (GTK_GRID (manager), 12); + + widget = gtk_entry_new (); + gtk_widget_set_hexpand (widget, TRUE); + gtk_grid_attach (GTK_GRID (manager), widget, 0, 0, 1, 1); + manager->priv->entry = widget; /* not referenced */ + gtk_widget_show (widget); + + widget = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy ( + GTK_SCROLLED_WINDOW (widget), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type ( + GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); + gtk_widget_set_hexpand (widget, TRUE); + gtk_widget_set_vexpand (widget, TRUE); + gtk_grid_attach (GTK_GRID (manager), widget, 0, 1, 1, 1); + gtk_widget_show (widget); + + container = widget; + + list_store = gtk_list_store_new (1, G_TYPE_STRING); + widget = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store)); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (widget), FALSE); + gtk_container_add (GTK_CONTAINER (container), widget); + manager->priv->tree_view = widget; /* not referenced */ + gtk_widget_show (widget); + g_object_unref (list_store); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); + + widget = gtk_button_box_new (GTK_ORIENTATION_VERTICAL); + gtk_box_set_spacing (GTK_BOX (widget), 6); + gtk_button_box_set_layout ( + GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_START); + gtk_grid_attach (GTK_GRID (manager), widget, 1, 0, 1, 2); + gtk_widget_show (widget); + + container = widget; + + widget = gtk_button_new_from_stock (GTK_STOCK_ADD); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + manager->priv->add_button = widget; /* not referenced */ + gtk_widget_show (widget); + + widget = gtk_button_new_from_stock (GTK_STOCK_REMOVE); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + manager->priv->remove_button = widget; /* not referenced */ + gtk_widget_show (widget); + + column = gtk_tree_view_column_new (); + gtk_tree_view_append_column ( + GTK_TREE_VIEW (manager->priv->tree_view), column); + + renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_cell_layout_add_attribute ( + GTK_CELL_LAYOUT (column), renderer, "text", 0); + + g_object_bind_property_full ( + manager->priv->entry, "text", + manager->priv->add_button, "sensitive", + G_BINDING_SYNC_CREATE, + mail_config_header_manager_header_to_boolean, + NULL, + NULL, (GDestroyNotify) NULL); + + g_signal_connect ( + manager->priv->entry, "activate", + G_CALLBACK (mail_config_header_manager_entry_activate), + manager); + + g_signal_connect ( + manager->priv->tree_view, "key-press-event", + G_CALLBACK (mail_config_header_manager_key_press_event), + manager); + + g_signal_connect ( + manager->priv->add_button, "clicked", + G_CALLBACK (mail_config_header_manager_add_clicked), + manager); + + g_signal_connect ( + manager->priv->remove_button, "clicked", + G_CALLBACK (mail_config_header_manager_remove_clicked), + manager); + + g_signal_connect ( + selection, "changed", + G_CALLBACK (mail_config_header_manager_selection_changed), + manager); + + mail_config_header_manager_selection_changed (selection, manager); +} + +static void +e_mail_config_header_manager_class_init (EMailConfigHeaderManagerClass *class) +{ + GObjectClass *object_class; + + g_type_class_add_private ( + class, sizeof (EMailConfigHeaderManagerPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = mail_config_header_manager_set_property; + object_class->get_property = mail_config_header_manager_get_property; + object_class->finalize = mail_config_header_manager_finalize; + object_class->constructed = mail_config_header_manager_constructed; + + g_object_class_install_property ( + object_class, + PROP_HEADERS, + g_param_spec_boxed ( + "headers", + "Headers", + "Array of header names", + G_TYPE_STRV, + G_PARAM_READWRITE)); +} + +static void +e_mail_config_header_manager_class_finalize (EMailConfigHeaderManagerClass *class) +{ +} + +static void +e_mail_config_header_manager_init (EMailConfigHeaderManager *manager) +{ + manager->priv = E_MAIL_CONFIG_HEADER_MANAGER_GET_PRIVATE (manager); + + manager->priv->headers = g_hash_table_new_full ( + (GHashFunc) g_str_hash, + (GEqualFunc) g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) NULL); +} + +void +e_mail_config_header_manager_type_register (GTypeModule *type_module) +{ + /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration + * function, so we have to wrap it with a public function in + * order to register types from a separate compilation unit. */ + e_mail_config_header_manager_register_type (type_module); +} + +GtkWidget * +e_mail_config_header_manager_new (void) +{ + return g_object_new (E_TYPE_MAIL_CONFIG_HEADER_MANAGER, NULL); +} + +gchar ** +e_mail_config_header_manager_dup_headers (EMailConfigHeaderManager *manager) +{ + GList *list, *link; + gchar **headers = NULL; + guint ii = 0; + + g_return_val_if_fail (E_IS_MAIL_CONFIG_HEADER_MANAGER (manager), NULL); + + list = g_hash_table_get_keys (manager->priv->headers); + list = g_list_sort (list, (GCompareFunc) g_utf8_collate); + + if (list != NULL) { + headers = g_new0 (gchar *, g_list_length (list) + 1); + for (link = list; link != NULL; link = g_list_next (link)) + headers[ii++] = g_strdup (link->data); + g_list_free (list); + } + + return headers; +} + +void +e_mail_config_header_manager_set_headers (EMailConfigHeaderManager *manager, + const gchar * const *headers) +{ + gint ii = 0; + + g_return_if_fail (E_IS_MAIL_CONFIG_HEADER_MANAGER (manager)); + + g_hash_table_remove_all (manager->priv->headers); + + while (headers != NULL && headers[ii] != NULL) { + gchar *stripped_header; + + stripped_header = g_strstrip (g_strdup (headers[ii++])); + + if (*stripped_header != '\0') + g_hash_table_insert ( + manager->priv->headers, + stripped_header, stripped_header); + else + g_free (stripped_header); + } + + g_object_notify (G_OBJECT (manager), "headers"); + + mail_config_header_manager_update_list (manager); +} + diff --git a/modules/imap-features/e-mail-config-header-manager.h b/modules/imap-features/e-mail-config-header-manager.h new file mode 100644 index 0000000000..27d047fb23 --- /dev/null +++ b/modules/imap-features/e-mail-config-header-manager.h @@ -0,0 +1,72 @@ +/* + * e-mail-config-header-manager.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#ifndef E_MAIL_CONFIG_HEADER_MANAGER_H +#define E_MAIL_CONFIG_HEADER_MANAGER_H + +#include <gtk/gtk.h> + +/* Standard GObject macros */ +#define E_TYPE_MAIL_CONFIG_HEADER_MANAGER \ + (e_mail_config_header_manager_get_type ()) +#define E_MAIL_CONFIG_HEADER_MANAGER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MAIL_CONFIG_HEADER_MANAGER, EMailConfigHeaderManager)) +#define E_MAIL_CONFIG_HEADER_MANAGER_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MAIL_CONFIG_HEADER_MANAGER, EMailConfigHeaderManagerClass)) +#define E_IS_MAIL_CONFIG_HEADER_MANAGER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MAIL_CONFIG_HEADER_MANAGER)) +#define E_IS_MAIL_CONFIG_HEADER_MANAGER_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MAIL_CONFIG_HEADER_MANAGER)) +#define E_MAIL_CONFIG_HEADER_MANAGER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MAIL_CONFIG_HEADER_MANAGER, EMailConfigHeaderManagerClass)) + +G_BEGIN_DECLS + +typedef struct _EMailConfigHeaderManager EMailConfigHeaderManager; +typedef struct _EMailConfigHeaderManagerClass EMailConfigHeaderManagerClass; +typedef struct _EMailConfigHeaderManagerPrivate EMailConfigHeaderManagerPrivate; + +struct _EMailConfigHeaderManager { + GtkGrid parent; + EMailConfigHeaderManagerPrivate *priv; +}; + +struct _EMailConfigHeaderManagerClass { + GtkGridClass parent_class; +}; + +GType e_mail_config_header_manager_get_type + (void) G_GNUC_CONST; +void e_mail_config_header_manager_type_register + (GTypeModule *type_module); +GtkWidget * e_mail_config_header_manager_new + (void); +gchar ** e_mail_config_header_manager_dup_headers + (EMailConfigHeaderManager *manager); +void e_mail_config_header_manager_set_headers + (EMailConfigHeaderManager *manager, + const gchar * const *headers); + +G_END_DECLS + +#endif /* E_MAIL_CONFIG_HEADER_MANAGER_H */ diff --git a/modules/imap-features/e-mail-config-imap-headers-page.c b/modules/imap-features/e-mail-config-imap-headers-page.c new file mode 100644 index 0000000000..6c9eaecbcb --- /dev/null +++ b/modules/imap-features/e-mail-config-imap-headers-page.c @@ -0,0 +1,434 @@ +/* + * e-mail-config-imap-headers-page.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#include "e-mail-config-imap-headers-page.h" + +#include <config.h> +#include <glib/gi18n-lib.h> + +#include <libedataserver/e-source-camel.h> +#include <libedataserver/e-source-mail-account.h> + +#include <mail/e-mail-config-security-page.h> + +#include "e-mail-config-header-manager.h" + +#define E_MAIL_CONFIG_IMAP_HEADERS_PAGE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE, EMailConfigImapHeadersPagePrivate)) + +#define E_MAIL_CONFIG_IMAP_HEADERS_PAGE_SORT_ORDER \ + (E_MAIL_CONFIG_SECURITY_PAGE_SORT_ORDER + 10) + +struct _EMailConfigImapHeadersPagePrivate { + ESource *account_source; + CamelSettings *settings; + + GtkToggleButton *fetch_all_headers; /* not referenced */ + GtkToggleButton *fetch_bas_headers; /* not referenced */ + GtkToggleButton *fetch_bml_headers; /* not referenced */ +}; + +enum { + PROP_0, + PROP_ACCOUNT_SOURCE +}; + +/* Forward Declarations */ +static void e_mail_config_imap_headers_page_interface_init + (EMailConfigPageInterface *interface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED ( + EMailConfigImapHeadersPage, + e_mail_config_imap_headers_page, + GTK_TYPE_BOX, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC ( + E_TYPE_MAIL_CONFIG_PAGE, + e_mail_config_imap_headers_page_interface_init)) + +static void +mail_config_imap_headers_page_all_toggled (GtkToggleButton *toggle_button, + EMailConfigImapHeadersPage *page) +{ + if (gtk_toggle_button_get_active (toggle_button)) { + CamelSettings *settings; + CamelFetchHeadersType fetch_headers; + + settings = page->priv->settings; + fetch_headers = CAMEL_FETCH_HEADERS_ALL; + g_object_set (settings, "fetch-headers", fetch_headers, NULL); + } +} + +static void +mail_config_imap_headers_page_bas_toggled (GtkToggleButton *toggle_button, + EMailConfigImapHeadersPage *page) +{ + if (gtk_toggle_button_get_active (toggle_button)) { + CamelSettings *settings; + CamelFetchHeadersType fetch_headers; + + settings = page->priv->settings; + fetch_headers = CAMEL_FETCH_HEADERS_BASIC; + g_object_set (settings, "fetch-headers", fetch_headers, NULL); + } +} + +static void +mail_config_imap_headers_page_bml_toggled (GtkToggleButton *toggle_button, + EMailConfigImapHeadersPage *page) +{ + if (gtk_toggle_button_get_active (toggle_button)) { + CamelSettings *settings; + CamelFetchHeadersType fetch_headers; + + settings = page->priv->settings; + fetch_headers = CAMEL_FETCH_HEADERS_BASIC_AND_MAILING_LIST; + g_object_set (settings, "fetch-headers", fetch_headers, NULL); + } +} + +static void +mail_config_imap_headers_page_set_account_source (EMailConfigImapHeadersPage *page, + ESource *account_source) +{ + g_return_if_fail (E_IS_SOURCE (account_source)); + g_return_if_fail (page->priv->account_source == NULL); + + page->priv->account_source = g_object_ref (account_source); +} + +static void +mail_config_imap_headers_page_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_ACCOUNT_SOURCE: + mail_config_imap_headers_page_set_account_source ( + E_MAIL_CONFIG_IMAP_HEADERS_PAGE (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +mail_config_imap_headers_page_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_ACCOUNT_SOURCE: + g_value_set_object ( + value, + e_mail_config_imap_headers_page_get_account_source ( + E_MAIL_CONFIG_IMAP_HEADERS_PAGE (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +mail_config_imap_headers_page_dispose (GObject *object) +{ + EMailConfigImapHeadersPagePrivate *priv; + + priv = E_MAIL_CONFIG_IMAP_HEADERS_PAGE_GET_PRIVATE (object); + + if (priv->account_source != NULL) { + g_object_unref (priv->account_source); + priv->account_source = NULL; + } + + if (priv->settings != NULL) { + g_object_unref (priv->settings); + priv->settings = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (e_mail_config_imap_headers_page_parent_class)-> + dispose (object); +} + +static void +mail_config_imap_headers_page_constructed (GObject *object) +{ + EMailConfigImapHeadersPage *page; + ESource *source; + ESourceCamel *camel_ext; + ESourceBackend *backend_ext; + CamelSettings *settings; + CamelFetchHeadersType fetch_headers; + GtkWidget *widget; + GtkWidget *container; + GtkToggleButton *toggle_button; + GSList *group = NULL; + const gchar *backend_name; + const gchar *extension_name; + const gchar *text; + gchar *markup; + + page = E_MAIL_CONFIG_IMAP_HEADERS_PAGE (object); + + /* Chain up to parent's constructed() method. */ + G_OBJECT_CLASS (e_mail_config_imap_headers_page_parent_class)-> + constructed (object); + + source = e_mail_config_imap_headers_page_get_account_source (page); + + extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; + backend_ext = e_source_get_extension (source, extension_name); + backend_name = e_source_backend_get_backend_name (backend_ext); + + extension_name = e_source_camel_get_extension_name (backend_name); + camel_ext = e_source_get_extension (source, extension_name); + settings = e_source_camel_get_settings (camel_ext); + + page->priv->settings = g_object_ref (settings); + + gtk_orientable_set_orientation ( + GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL); + + gtk_box_set_spacing (GTK_BOX (page), 12); + + /*** IMAP Headers ***/ + + /* Use row-spacing=0 so we can pack the "Basic Headers" hint + * label closer to its radio button. Unfortunately this means + * we have to remember to set a top margin on all the children. */ + widget = gtk_grid_new (); + gtk_grid_set_row_spacing (GTK_GRID (widget), 0); + gtk_grid_set_column_spacing (GTK_GRID (widget), 6); + gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + container = widget; + + text = _("IMAP Headers"); + markup = g_markup_printf_escaped ("<b>%s</b>", text); + widget = gtk_label_new (markup); + gtk_label_set_use_markup (GTK_LABEL (widget), TRUE); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); + gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1); + gtk_widget_show (widget); + + text = _("Select a predefined set of IMAP headers to fetch.\n" + "Note, larger sets of headers take longer to download."); + widget = gtk_label_new (text); + gtk_widget_set_margin_top (widget, 6); + gtk_widget_set_margin_left (widget, 12); + gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); + gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1); + gtk_widget_show (widget); + + text = _("_Fetch All Headers"); + widget = gtk_radio_button_new_with_mnemonic (group, text); + gtk_widget_set_margin_top (widget, 6); + gtk_widget_set_margin_left (widget, 12); + gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1); + page->priv->fetch_all_headers = GTK_TOGGLE_BUTTON (widget); + gtk_widget_show (widget); + + g_signal_connect ( + widget, "toggled", + G_CALLBACK (mail_config_imap_headers_page_all_toggled), page); + + group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); + + text = _("_Basic Headers (fastest)"); + widget = gtk_radio_button_new_with_mnemonic (group, text); + gtk_widget_set_margin_top (widget, 6); + gtk_widget_set_margin_left (widget, 12); + gtk_grid_attach (GTK_GRID (container), widget, 0, 3, 1, 1); + page->priv->fetch_bas_headers = GTK_TOGGLE_BUTTON (widget); + gtk_widget_show (widget); + + g_signal_connect ( + widget, "toggled", + G_CALLBACK (mail_config_imap_headers_page_bas_toggled), page); + + group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); + + text = _("Use this if you are not filtering any mailing lists."); + markup = g_markup_printf_escaped ("<small>%s</small>", text); + widget = gtk_label_new (markup); + gtk_widget_set_margin_left (widget, 36); + gtk_label_set_use_markup (GTK_LABEL (widget), TRUE); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); + gtk_grid_attach (GTK_GRID (container), widget, 0, 4, 1, 1); + gtk_widget_show (widget); + g_free (markup); + + text = _("Basic and _Mailing List Headers (default)"); + widget = gtk_radio_button_new_with_mnemonic (group, text); + gtk_widget_set_margin_top (widget, 6); + gtk_widget_set_margin_left (widget, 12); + gtk_grid_attach (GTK_GRID (container), widget, 0, 5, 1, 1); + page->priv->fetch_bml_headers = GTK_TOGGLE_BUTTON (widget); + gtk_widget_show (widget); + + g_signal_connect ( + widget, "toggled", + G_CALLBACK (mail_config_imap_headers_page_bml_toggled), page); + + /* Pick an initial radio button. */ + + g_object_get (settings, "fetch-headers", &fetch_headers, NULL); + + switch (fetch_headers) { + case CAMEL_FETCH_HEADERS_ALL: + toggle_button = page->priv->fetch_all_headers; + break; + + case CAMEL_FETCH_HEADERS_BASIC: + toggle_button = page->priv->fetch_bas_headers; + break; + + case CAMEL_FETCH_HEADERS_BASIC_AND_MAILING_LIST: + default: + toggle_button = page->priv->fetch_bml_headers; + break; + } + + gtk_toggle_button_set_active (toggle_button, TRUE); + + /*** Custom Headers ***/ + + widget = gtk_grid_new (); + gtk_grid_set_row_spacing (GTK_GRID (widget), 6); + gtk_grid_set_column_spacing (GTK_GRID (widget), 6); + gtk_box_pack_start (GTK_BOX (page), widget, TRUE, TRUE, 0); + gtk_widget_show (widget); + + g_object_bind_property ( + page->priv->fetch_all_headers, "active", + widget, "sensitive", + G_BINDING_SYNC_CREATE | + G_BINDING_INVERT_BOOLEAN); + + container = widget; + + text = _("Custom Headers"); + markup = g_markup_printf_escaped ("<b>%s</b>", text); + widget = gtk_label_new (markup); + gtk_label_set_use_markup (GTK_LABEL (widget), TRUE); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); + gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1); + gtk_widget_show (widget); + + text = _("Specify any extra headers to fetch in addition " + "to the predefined set of headers selected above."); + widget = gtk_label_new (text); + gtk_widget_set_margin_left (widget, 12); + gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); + gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1); + gtk_widget_show (widget); + + widget = e_mail_config_header_manager_new (); + gtk_widget_set_hexpand (widget, TRUE); + gtk_widget_set_vexpand (widget, TRUE); + gtk_widget_set_margin_left (widget, 12); + gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1); + gtk_widget_show (widget); + + g_object_bind_property ( + settings, "fetch-headers-extra", + widget, "headers", + G_BINDING_BIDIRECTIONAL | + G_BINDING_SYNC_CREATE); +} + +static void +e_mail_config_imap_headers_page_class_init (EMailConfigImapHeadersPageClass *class) +{ + GObjectClass *object_class; + + g_type_class_add_private ( + class, sizeof (EMailConfigImapHeadersPagePrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = mail_config_imap_headers_page_set_property; + object_class->get_property = mail_config_imap_headers_page_get_property; + object_class->dispose = mail_config_imap_headers_page_dispose; + object_class->constructed = mail_config_imap_headers_page_constructed; + + g_object_class_install_property ( + object_class, + PROP_ACCOUNT_SOURCE, + g_param_spec_object ( + "account-source", + "Account Source", + "Mail account source being edited", + E_TYPE_SOURCE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); +} + +static void +e_mail_config_imap_headers_page_class_finalize (EMailConfigImapHeadersPageClass *class) +{ +} + +static void +e_mail_config_imap_headers_page_interface_init (EMailConfigPageInterface *interface) +{ + interface->title = _("IMAP Headers"); + interface->sort_order = E_MAIL_CONFIG_IMAP_HEADERS_PAGE_SORT_ORDER; +} + +static void +e_mail_config_imap_headers_page_init (EMailConfigImapHeadersPage *page) +{ + page->priv = E_MAIL_CONFIG_IMAP_HEADERS_PAGE_GET_PRIVATE (page); +} + +void +e_mail_config_imap_headers_page_type_register (GTypeModule *type_module) +{ + /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration + * function, so we have to wrap it with a public function in + * order to register types from a separate compilation unit. */ + e_mail_config_imap_headers_page_register_type (type_module); +} + +EMailConfigPage * +e_mail_config_imap_headers_page_new (ESource *account_source) +{ + g_return_val_if_fail (E_IS_SOURCE (account_source), NULL); + + return g_object_new ( + E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE, + "account-source", account_source, NULL); +} + +ESource * +e_mail_config_imap_headers_page_get_account_source (EMailConfigImapHeadersPage *page) +{ + g_return_val_if_fail (E_IS_MAIL_CONFIG_IMAP_HEADERS_PAGE (page), NULL); + + return page->priv->account_source; +} + diff --git a/modules/imap-features/e-mail-config-imap-headers-page.h b/modules/imap-features/e-mail-config-imap-headers-page.h new file mode 100644 index 0000000000..87a1a50ff6 --- /dev/null +++ b/modules/imap-features/e-mail-config-imap-headers-page.h @@ -0,0 +1,74 @@ +/* + * e-mail-config-imap-headers-page.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#ifndef E_MAIL_CONFIG_IMAP_HEADERS_PAGE_H +#define E_MAIL_CONFIG_IMAP_HEADERS_PAGE_H + +#include <gtk/gtk.h> +#include <libedataserver/e-source.h> + +#include <mail/e-mail-config-page.h> + +/* Standard GObject macros */ +#define E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE \ + (e_mail_config_imap_headers_page_get_type ()) +#define E_MAIL_CONFIG_IMAP_HEADERS_PAGE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE, EMailConfigImapHeadersPage)) +#define E_MAIL_CONFIG_IMAP_HEADERS_PAGE_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE, EMailConfigImapHeadersPageClass)) +#define E_IS_MAIL_CONFIG_IMAP_HEADERS_PAGE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE)) +#define E_IS_MAIL_CONFIG_IMAP_HEADERS_PAGE_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE)) +#define E_MAIL_CONFIG_IMAP_HEADERS_PAGE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE, EMailConfigImapHeadersPage)) + +G_BEGIN_DECLS + +typedef struct _EMailConfigImapHeadersPage EMailConfigImapHeadersPage; +typedef struct _EMailConfigImapHeadersPageClass EMailConfigImapHeadersPageClass; +typedef struct _EMailConfigImapHeadersPagePrivate EMailConfigImapHeadersPagePrivate; + +struct _EMailConfigImapHeadersPage { + GtkBox parent; + EMailConfigImapHeadersPagePrivate *priv; +}; + +struct _EMailConfigImapHeadersPageClass { + GtkBoxClass parent_class; +}; + +GType e_mail_config_imap_headers_page_get_type + (void) G_GNUC_CONST; +void e_mail_config_imap_headers_page_type_register + (GTypeModule *type_module); +EMailConfigPage * + e_mail_config_imap_headers_page_new + (ESource *account_source); +ESource * e_mail_config_imap_headers_page_get_account_source + (EMailConfigImapHeadersPage *page); + +G_END_DECLS + +#endif /* E_MAIL_CONFIG_IMAP_HEADERS_PAGE_H */ + diff --git a/modules/imap-features/evolution-imap-features.c b/modules/imap-features/evolution-imap-features.c new file mode 100644 index 0000000000..1b99daf62d --- /dev/null +++ b/modules/imap-features/evolution-imap-features.c @@ -0,0 +1,116 @@ +/* + * evolution-imap-features.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#include <config.h> +#include <glib/gi18n-lib.h> + +#include <libebackend/e-extension.h> +#include <libedataserver/e-source-mail-account.h> + +#include <mail/e-mail-config-notebook.h> + +#include "e-mail-config-header-manager.h" +#include "e-mail-config-imap-headers-page.h" + +typedef EExtension EvolutionImapFeatures; +typedef EExtensionClass EvolutionImapFeaturesClass; + +/* Module Entry Points */ +void e_module_load (GTypeModule *type_module); +void e_module_unload (GTypeModule *type_module); + +/* Forward Declarations */ +GType evolution_imap_features_get_type (void); + +G_DEFINE_DYNAMIC_TYPE ( + EvolutionImapFeatures, + evolution_imap_features, + E_TYPE_EXTENSION) + +static void +evolution_imap_features_constructed (GObject *object) +{ + EExtension *extension; + EExtensible *extensible; + ESource *source; + ESourceBackend *backend_ext; + EMailConfigNotebook *notebook; + const gchar *backend_name; + const gchar *extension_name; + gboolean add_page = FALSE; + + extension = E_EXTENSION (object); + extensible = e_extension_get_extensible (extension); + + /* Chain up to parent's constructed() method. */ + G_OBJECT_CLASS (evolution_imap_features_parent_class)-> + constructed (object); + + notebook = E_MAIL_CONFIG_NOTEBOOK (extensible); + source = e_mail_config_notebook_get_account_source (notebook); + + extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; + backend_ext = e_source_get_extension (source, extension_name); + backend_name = e_source_backend_get_backend_name (backend_ext); + + if (g_strcmp0 (backend_name, "imap") == 0) + add_page = TRUE; + + if (add_page) { + EMailConfigPage *page; + page = e_mail_config_imap_headers_page_new (source); + e_mail_config_notebook_add_page (notebook, page); + } +} + +static void +evolution_imap_features_class_init (EvolutionImapFeaturesClass *class) +{ + GObjectClass *object_class; + EExtensionClass *extension_class; + + object_class = G_OBJECT_CLASS (class); + object_class->constructed = evolution_imap_features_constructed; + + extension_class = E_EXTENSION_CLASS (class); + extension_class->extensible_type = E_TYPE_MAIL_CONFIG_NOTEBOOK; +} + +static void +evolution_imap_features_class_finalize (EvolutionImapFeaturesClass *class) +{ +} + +static void +evolution_imap_features_init (EvolutionImapFeatures *extension) +{ +} + +G_MODULE_EXPORT void +e_module_load (GTypeModule *type_module) +{ + evolution_imap_features_register_type (type_module); + e_mail_config_header_manager_type_register (type_module); + e_mail_config_imap_headers_page_type_register (type_module); +} + +G_MODULE_EXPORT void +e_module_unload (GTypeModule *type_module) +{ +} + diff --git a/plugins/imap-features/Makefile.am b/plugins/imap-features/Makefile.am deleted file mode 100644 index 895f95062b..0000000000 --- a/plugins/imap-features/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -if OS_WIN32 -NO_UNDEFINED_REQUIRED_LIBS = $(top_builddir)/mail/libevolution-mail.la -endif - -@EVO_PLUGIN_RULE@ - -plugin_DATA = org-gnome-imap-features.eplug - -plugin_LTLIBRARIES = liborg-gnome-imap-features.la - -liborg_gnome_imap_features_la_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -I$(top_srcdir) \ - -I$(top_srcdir)/mail \ - $(EVOLUTION_DATA_SERVER_CFLAGS) \ - $(GNOME_PLATFORM_CFLAGS) \ - -DEVOLUTION_UIDIR=\""$(uidir)"\" \ - -DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" - -liborg_gnome_imap_features_la_SOURCES = imap-headers.c - -liborg_gnome_imap_features_la_LIBADD= \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/mail/libevolution-mail.la \ - $(top_builddir)/libevolution-utils/libevolution-utils.la \ - $(EVOLUTION_DATA_SERVER_LIBS) \ - $(GNOME_PLATFORM_LIBS) - -liborg_gnome_imap_features_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED) - -ui_DATA = \ - imap-headers.ui - -errordir = $(privdatadir)/errors - -BUILT_SOURCES = org-gnome-imap-features.eplug $(error_i18n) - -EXTRA_DIST = \ - $(ui_DATA) \ - org-gnome-imap-features.eplug.xml - -CLEANFILES = $(BUILT_SOURCES) - --include $(top_srcdir)/git.mk diff --git a/plugins/imap-features/imap-headers.c b/plugins/imap-features/imap-headers.c deleted file mode 100644 index 56f7e4f5b4..0000000000 --- a/plugins/imap-features/imap-headers.c +++ /dev/null @@ -1,363 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Sankar P <psankar@novell.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <gtk/gtk.h> -#include <glib/gi18n.h> - -#include <e-util/e-util.h> - -#include <libemail-utils/e-account-utils.h> - -#include <mail/em-config.h> - -typedef struct _epif_data EPImapFeaturesData; -struct _epif_data { - GtkWidget *all_headers; - GtkWidget *basic_headers; - GtkWidget *mailing_list_headers; - GtkWidget *custom_headers_box; - - GtkEntry *entry_header; - - GtkButton *add_header; - GtkButton *remove_header; - - GtkTreeView *custom_headers_tree; - GtkTreeStore *store; - - gchar **custom_headers_array; -}; - -static EPImapFeaturesData *ui = NULL; - -void imap_headers_abort (EPlugin *efp, EConfigHookItemFactoryData *data); -void imap_headers_commit (EPlugin *efp, EConfigHookItemFactoryData *data); -GtkWidget * org_gnome_imap_headers (EPlugin *epl, EConfigHookItemFactoryData *data); -gint e_plugin_lib_enable (EPlugin *ep, gint enable); - -gint -e_plugin_lib_enable (EPlugin *ep, - gint enable) -{ - return 0; -} - -void -imap_headers_abort (EPlugin *efp, - EConfigHookItemFactoryData *data) -{ - /* Nothing to do here */ -} - -void -imap_headers_commit (EPlugin *efp, - EConfigHookItemFactoryData *data) -{ - EMConfigTargetSettings *target; - CamelFetchHeadersType fetch_headers; - gboolean use_imap = g_getenv ("USE_IMAP") != NULL; - const gchar *protocol; - - target = (EMConfigTargetSettings *) data->config->target; - protocol = target->storage_protocol; - - if (g_strcmp0 (protocol, "imap") == 0 || - (use_imap && g_strcmp0 (protocol, "groupwise") == 0)) { - - GtkTreeModel *model; - GtkTreeIter iter; - gint n_children; - gchar **strv = NULL; - gboolean valid; - gint ii = 0; - - model = gtk_tree_view_get_model (ui->custom_headers_tree); - n_children = gtk_tree_model_iter_n_children (model, NULL); - - if (n_children > 0) - strv = g_new0 (gchar *, n_children + 1); - - valid = gtk_tree_model_get_iter_first (model, &iter); - - while (valid) { - gchar *header; - - g_warn_if_fail (ii < n_children); - gtk_tree_model_get (model, &iter, 0, &header, -1); - strv[ii++] = g_strstrip (header); - - valid = gtk_tree_model_iter_next (model, &iter); - } - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ui->all_headers))) - fetch_headers = CAMEL_FETCH_HEADERS_ALL; - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ui->basic_headers))) - fetch_headers = CAMEL_FETCH_HEADERS_BASIC; - else - fetch_headers = CAMEL_FETCH_HEADERS_BASIC_AND_MAILING_LIST; - - g_object_set ( - target->storage_settings, - "fetch-headers", fetch_headers, - "fetch-headers-extra", strv, NULL); - - g_strfreev (strv); - } -} - -/* return true is the header is considered valid */ -static gboolean -epif_header_is_valid (const gchar *header) -{ - gint len = g_utf8_strlen (header, -1); - - if (header[0] == 0 - || g_utf8_strchr (header, len, ':') != NULL - || g_utf8_strchr (header, len, ' ') != NULL) - return FALSE; - - return TRUE; -} - -static void -epif_add_sensitivity (EPImapFeaturesData *ui) -{ - const gchar *entry_contents; - GtkTreeIter iter; - gboolean valid; - - /* the add header button should be sensitive if the text box contains - * a valid header string, that is not a duplicate with something already - * in the list view */ - entry_contents = gtk_entry_get_text (GTK_ENTRY (ui->entry_header)); - if (!epif_header_is_valid (entry_contents)) { - gtk_widget_set_sensitive (GTK_WIDGET (ui->add_header), FALSE); - return; - } - - /* check if this is a duplicate */ - valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ui->store), &iter); - while (valid) { - gchar *header_name; - - gtk_tree_model_get (GTK_TREE_MODEL (ui->store), &iter, - 0, &header_name, - -1); - if (g_ascii_strcasecmp (header_name, entry_contents) == 0) { - g_free (header_name); - gtk_widget_set_sensitive (GTK_WIDGET (ui->add_header), FALSE); - return; - } - - g_free (header_name); - valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (ui->store), &iter); - } - - gtk_widget_set_sensitive (GTK_WIDGET (ui->add_header), TRUE); -} - -static void -epif_add_header (GtkButton *button, - EPImapFeaturesData *ui) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GtkTreeSelection *selection; - - model = gtk_tree_view_get_model (ui->custom_headers_tree); - gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL); - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 0, gtk_entry_get_text (ui->entry_header), -1); - - selection = gtk_tree_view_get_selection (ui->custom_headers_tree); - gtk_tree_selection_select_iter (selection, &iter); - - gtk_entry_set_text (ui->entry_header, ""); - epif_add_sensitivity (ui); -} - -static void -epif_tv_selection_changed (GtkTreeSelection *selection, - GtkWidget *button) -{ - g_return_if_fail (selection != NULL); - g_return_if_fail (button != NULL); - - gtk_widget_set_sensitive (button, gtk_tree_selection_get_selected (selection, NULL, NULL)); -} - -static void -epif_remove_header_clicked (GtkButton *button, - EPImapFeaturesData *ui) -{ - GtkTreeSelection *select; - GtkTreeModel *model; - GtkTreeIter iter; - GtkTreePath *path; - gboolean valid = TRUE; - - select = gtk_tree_view_get_selection (ui->custom_headers_tree); - - if (gtk_tree_selection_get_selected (select, &model, &iter)) { - path = gtk_tree_model_get_path (model, &iter); - gtk_tree_store_remove (GTK_TREE_STORE (model), &iter); - - if (gtk_tree_path_prev (path)) { - gtk_tree_model_get_iter (model, &iter, path); - } else { - valid = gtk_tree_model_get_iter_first (model, &iter); - } - - if (valid) - gtk_tree_selection_select_iter (select, &iter); - } - - epif_add_sensitivity (ui); -} - -static void -epif_entry_changed (GtkWidget *entry, - EPImapFeaturesData *ui) -{ - epif_add_sensitivity (ui); -} - -GtkWidget * -org_gnome_imap_headers (EPlugin *epl, - EConfigHookItemFactoryData *data) -{ - EMConfigTargetSettings *target; - GtkWidget *vbox; - GtkBuilder *builder; - GtkWidget *button; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - GtkTreeIter iter; - GtkTreeSelection *selection; - CamelFetchHeadersType fetch_headers = 0; - gchar **extra_headers = NULL; - gboolean use_imap = g_getenv ("USE_IMAP") != NULL; - const gchar *protocol; - guint ii, length = 0; - - ui = g_new0 (EPImapFeaturesData, 1); - - target = (EMConfigTargetSettings *) data->config->target; - protocol = target->storage_protocol; - - if (g_strcmp0 (protocol, "imap") != 0 && - !(use_imap && g_strcmp0 (protocol, "groupwise") == 0)) - return NULL; - - g_object_get ( - target->storage_settings, - "fetch-headers", &fetch_headers, - "fetch-headers-extra", &extra_headers, NULL); - - builder = gtk_builder_new (); - e_load_ui_builder_definition (builder, "imap-headers.ui"); - - vbox = e_builder_get_widget (builder, "vbox2"); - ui->all_headers = e_builder_get_widget (builder, "allHeaders"); - ui->basic_headers = e_builder_get_widget (builder, "basicHeaders"); - ui->mailing_list_headers = e_builder_get_widget (builder, "mailingListHeaders"); - ui->custom_headers_box = e_builder_get_widget (builder, "custHeaderHbox"); - ui->custom_headers_tree = GTK_TREE_VIEW(e_builder_get_widget (builder, "custHeaderTree")); - ui->add_header = GTK_BUTTON(e_builder_get_widget (builder, "addHeader")); - ui->remove_header = GTK_BUTTON(e_builder_get_widget (builder, "removeHeader")); - ui->entry_header = GTK_ENTRY (e_builder_get_widget (builder, "customHeaderEntry")); - - g_object_bind_property ( - ui->all_headers, "active", - ui->custom_headers_box, "sensitive", - G_BINDING_SYNC_CREATE | - G_BINDING_INVERT_BOOLEAN); - - ui->store = gtk_tree_store_new (1, G_TYPE_STRING); - gtk_tree_view_set_model (ui->custom_headers_tree, GTK_TREE_MODEL (ui->store)); - - selection = gtk_tree_view_get_selection (ui->custom_headers_tree); - - if (extra_headers != NULL) - length = g_strv_length (extra_headers); - - for (ii = 0; ii < length; ii++) { - - /* Skip empty strings. */ - g_strstrip (extra_headers[ii]); - if (*extra_headers[ii] == '\0') - continue; - - gtk_tree_store_append (ui->store, &iter, NULL); - gtk_tree_store_set (ui->store, &iter, 0, extra_headers[ii], -1); - } - - switch (fetch_headers) { - case CAMEL_FETCH_HEADERS_ALL: - button = ui->all_headers; - break; - case CAMEL_FETCH_HEADERS_BASIC: - button = ui->basic_headers; - break; - default: - button = ui->mailing_list_headers; - break; - } - - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (button), TRUE); - - g_strfreev (extra_headers); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("Custom Headers"), renderer, "text", 0, NULL); - gtk_tree_view_append_column (ui->custom_headers_tree , column); - - gtk_widget_set_sensitive (GTK_WIDGET (ui->add_header), FALSE); - epif_tv_selection_changed (selection, GTK_WIDGET (ui->remove_header)); - - g_signal_connect ( - ui->add_header, "clicked", - G_CALLBACK (epif_add_header), ui); - g_signal_connect ( - ui->remove_header, "clicked", - G_CALLBACK (epif_remove_header_clicked), ui); - g_signal_connect ( - ui->entry_header, "changed", - G_CALLBACK (epif_entry_changed), ui); - g_signal_connect ( - ui->entry_header, "activate", - G_CALLBACK (epif_add_header), ui); - g_signal_connect ( - selection, "changed", - G_CALLBACK (epif_tv_selection_changed), ui->remove_header); - - gtk_notebook_append_page ((GtkNotebook *)(data->parent), vbox, gtk_label_new(_("IMAP Headers"))); - gtk_container_child_set (GTK_CONTAINER (data->parent), vbox, "tab-fill", FALSE, "tab-expand", FALSE, NULL); - gtk_widget_show_all (vbox); - - return GTK_WIDGET (vbox); -} diff --git a/plugins/imap-features/imap-headers.ui b/plugins/imap-features/imap-headers.ui deleted file mode 100644 index adc6dce515..0000000000 --- a/plugins/imap-features/imap-headers.ui +++ /dev/null @@ -1,327 +0,0 @@ -<?xml version="1.0"?> -<!--*- mode: xml -*--> -<interface> - <object class="GtkVBox" id="vbox2"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - <child> - <object class="GtkFrame" id="frame1"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0</property> - <property name="shadow_type">GTK_SHADOW_NONE</property> - <child> - <object class="GtkAlignment" id="alignment1"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xscale">1</property> - <property name="yscale">1</property> - <property name="top_padding">0</property> - <property name="bottom_padding">0</property> - <property name="left_padding">12</property> - <property name="right_padding">0</property> - <child> - <object class="GtkVBox" id="vbox1"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - <child> - <object class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Select your IMAP Header Preferences. -The more headers you have the more time it will take to download.</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">True</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="allHeaders"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Fetch All Headers</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="basicHeaders"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Basic Headers (Fastest) -Use this if you do not have filters based on mailing lists</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">allHeaders</property> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="mailingListHeaders"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Basic and _Mailing List Headers (Default)</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">allHeaders</property> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </object> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label2"> - <property name="visible">True</property> - <property name="label" translatable="yes">IMAP Headers</property> - <property name="use_underline">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">True</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> - <attributes> - <attribute name="weight" value="bold"/> - </attributes> - </object> - </child> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - <child> - <object class="GtkFrame" id="frame2"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0</property> - <property name="shadow_type">GTK_SHADOW_NONE</property> - <child> - <object class="GtkAlignment" id="alignment2"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xscale">1</property> - <property name="yscale">1</property> - <property name="top_padding">0</property> - <property name="bottom_padding">0</property> - <property name="left_padding">12</property> - <property name="right_padding">0</property> - <child> - <object class="GtkVBox" id="vbox4"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - <child> - <object class="GtkLabel" id="Custom Headers"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Give the extra headers that you need to fetch in addition to the above standard headers. -You can ignore this if you choose "All Headers".</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">True</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="custHeaderHbox"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">5</property> - <child> - <object class="GtkVBox" id="customHeaderVBox"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - <child> - <object class="GtkEntry" id="customHeaderEntry"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"/> - <property name="has_frame">True</property> - <property name="activates_default">False</property> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - <child> - <object class="GtkScrolledWindow" id="scrolledwindow1"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> - <child> - <object class="GtkTreeView" id="custHeaderTree"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="headers_visible">False</property> - <property name="rules_hint">False</property> - <property name="reorderable">False</property> - <property name="enable_search">True</property> - <property name="fixed_height_mode">False</property> - <property name="hover_selection">False</property> - <property name="hover_expand">False</property> - </object> - </child> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - <child> - <object class="GtkVButtonBox" id="vbuttonbox1"> - <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_START</property> - <property name="spacing">6</property> - <child> - <object class="GtkButton" id="addHeader"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-add</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - </object> - </child> - <child> - <object class="GtkButton" id="removeHeader"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-remove</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - </object> - </child> - </object> - <packing> - <property name="padding">4</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </object> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label4"> - <property name="visible">True</property> - <property name="label" translatable="yes">Custom Headers</property> - <property name="use_underline">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">True</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> - <attributes> - <attribute name="weight" value="bold"/> - </attributes> - </object> - </child> - </object> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </object> -</interface> diff --git a/plugins/imap-features/org-gnome-imap-features.eplug.xml b/plugins/imap-features/org-gnome-imap-features.eplug.xml deleted file mode 100644 index c4d27bddd0..0000000000 --- a/plugins/imap-features/org-gnome-imap-features.eplug.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0"?> -<e-plugin-list> - <e-plugin id="org.gnome.evolution.imap_features" type="shlib" _name="IMAP Features" - location="@PLUGINDIR@/liborg-gnome-imap-features@SOEXT@"> - <author name="Sankar P" email="psankar@novell.com"/> - - <_description>Fine-tune your IMAP accounts.</_description> - - <hook class="org.gnome.evolution.mail.config:1.0"> - <group id="org.gnome.evolution.mail.config.accountEditor" - target="settings" commit = "imap_headers_commit" abort="imap_headers_abort"> - <item type="page" path="70.IMAP Headers" label="IMAP Headers" factory="org_gnome_imap_headers"/> - </group> - </hook> - - </e-plugin> - -</e-plugin-list> |