aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-05-24 10:42:49 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-05-24 12:17:34 +0800
commitc6d8a030399f9e3d9f38798e99cdeecaf2d5fbbb (patch)
treed92b5f0f9623e194c9f79b73ff57ba31e00fd257 /mail
parente5bb31aae65efd3dbc1804570849e5495a71daf9 (diff)
downloadgsoc2013-evolution-c6d8a030399f9e3d9f38798e99cdeecaf2d5fbbb.tar
gsoc2013-evolution-c6d8a030399f9e3d9f38798e99cdeecaf2d5fbbb.tar.gz
gsoc2013-evolution-c6d8a030399f9e3d9f38798e99cdeecaf2d5fbbb.tar.bz2
gsoc2013-evolution-c6d8a030399f9e3d9f38798e99cdeecaf2d5fbbb.tar.lz
gsoc2013-evolution-c6d8a030399f9e3d9f38798e99cdeecaf2d5fbbb.tar.xz
gsoc2013-evolution-c6d8a030399f9e3d9f38798e99cdeecaf2d5fbbb.tar.zst
gsoc2013-evolution-c6d8a030399f9e3d9f38798e99cdeecaf2d5fbbb.zip
Let EMFolderSelector create its own EMFolderTree.
Also, minimize the EMFolderSelector API by removing frivolous wrapper functions and unused functions.
Diffstat (limited to 'mail')
-rw-r--r--mail/e-mail-reader.c58
-rw-r--r--mail/em-composer-utils.c33
-rw-r--r--mail/em-folder-selection-button.c42
-rw-r--r--mail/em-folder-selector.c321
-rw-r--r--mail/em-folder-selector.h27
-rw-r--r--mail/em-folder-utils.c37
-rw-r--r--mail/em-vfolder-rule.c19
7 files changed, 285 insertions, 252 deletions
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 18d7621a9d..91e303ec46 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -281,7 +281,8 @@ action_mail_copy_cb (GtkAction *action,
CamelFolder *folder;
EMailBackend *backend;
EMailSession *session;
- GtkWidget *folder_tree;
+ EMFolderSelector *selector;
+ EMFolderTree *folder_tree;
GtkWidget *dialog;
GtkWindow *window;
GPtrArray *uids;
@@ -294,29 +295,27 @@ action_mail_copy_cb (GtkAction *action,
window = e_mail_reader_get_window (reader);
uids = e_mail_reader_get_selected_uids (reader);
- folder_tree = em_folder_tree_new (backend);
- emu_restore_folder_tree_state (EM_FOLDER_TREE (folder_tree));
+ dialog = em_folder_selector_new (
+ window, backend, EM_FOLDER_SELECTOR_CAN_CREATE,
+ _("Copy to Folder"), NULL, _("C_opy"));
+
+ selector = EM_FOLDER_SELECTOR (dialog);
+ folder_tree = em_folder_selector_get_folder_tree (selector);
em_folder_tree_set_excluded (
- EM_FOLDER_TREE (folder_tree),
- EMFT_EXCLUDE_NOSELECT | EMFT_EXCLUDE_VIRTUAL |
+ folder_tree,
+ EMFT_EXCLUDE_NOSELECT |
+ EMFT_EXCLUDE_VIRTUAL |
EMFT_EXCLUDE_VTRASH);
- dialog = em_folder_selector_new (
- window, EM_FOLDER_TREE (folder_tree),
- EM_FOLDER_SELECTOR_CAN_CREATE,
- _("Copy to Folder"), NULL, _("C_opy"));
-
if (default_xfer_messages_uri != NULL)
- em_folder_selector_set_selected (
- EM_FOLDER_SELECTOR (dialog),
- default_xfer_messages_uri);
+ em_folder_tree_set_selected (
+ folder_tree, default_xfer_messages_uri, FALSE);
if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
goto exit;
- uri = em_folder_selector_get_selected_uri (
- EM_FOLDER_SELECTOR (dialog));
+ uri = em_folder_selector_get_selected_uri (selector);
g_free (default_xfer_messages_uri);
default_xfer_messages_uri = g_strdup (uri);
@@ -784,7 +783,8 @@ action_mail_move_cb (GtkAction *action,
CamelFolder *folder;
EMailBackend *backend;
EMailSession *session;
- GtkWidget *folder_tree;
+ EMFolderSelector *selector;
+ EMFolderTree *folder_tree;
GtkWidget *dialog;
GtkWindow *window;
GPtrArray *uids;
@@ -797,29 +797,27 @@ action_mail_move_cb (GtkAction *action,
session = e_mail_backend_get_session (backend);
- folder_tree = em_folder_tree_new (backend);
- emu_restore_folder_tree_state (EM_FOLDER_TREE (folder_tree));
+ dialog = em_folder_selector_new (
+ window, backend, EM_FOLDER_SELECTOR_CAN_CREATE,
+ _("Move to Folder"), NULL, _("_Move"));
+
+ selector = EM_FOLDER_SELECTOR (dialog);
+ folder_tree = em_folder_selector_get_folder_tree (selector);
em_folder_tree_set_excluded (
- EM_FOLDER_TREE (folder_tree),
- EMFT_EXCLUDE_NOSELECT | EMFT_EXCLUDE_VIRTUAL |
+ folder_tree,
+ EMFT_EXCLUDE_NOSELECT |
+ EMFT_EXCLUDE_VIRTUAL |
EMFT_EXCLUDE_VTRASH);
- dialog = em_folder_selector_new (
- window, EM_FOLDER_TREE (folder_tree),
- EM_FOLDER_SELECTOR_CAN_CREATE,
- _("Move to Folder"), NULL, _("_Move"));
-
if (default_xfer_messages_uri != NULL)
- em_folder_selector_set_selected (
- EM_FOLDER_SELECTOR (dialog),
- default_xfer_messages_uri);
+ em_folder_tree_set_selected (
+ folder_tree, default_xfer_messages_uri, FALSE);
if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
goto exit;
- uri = em_folder_selector_get_selected_uri (
- EM_FOLDER_SELECTOR (dialog));
+ uri = em_folder_selector_get_selected_uri (selector);
g_free (default_xfer_messages_uri);
default_xfer_messages_uri = g_strdup (uri);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index f58e8955dd..e8441b7ab9 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -2790,7 +2790,8 @@ post_header_clicked_cb (EComposerPostHeader *header,
EShell *shell;
EShellBackend *shell_backend;
GtkTreeSelection *selection;
- GtkWidget *folder_tree;
+ EMFolderSelector *selector;
+ EMFolderTree *folder_tree;
GtkWidget *dialog;
GList *list;
@@ -2798,29 +2799,28 @@ post_header_clicked_cb (EComposerPostHeader *header,
shell = e_msg_composer_get_shell (composer);
shell_backend = e_shell_get_backend_by_name (shell, "mail");
- folder_tree = em_folder_tree_new (E_MAIL_BACKEND (shell_backend));
- emu_restore_folder_tree_state (EM_FOLDER_TREE (folder_tree));
+ dialog = em_folder_selector_new (
+ GTK_WINDOW (composer),
+ E_MAIL_BACKEND (shell_backend),
+ EM_FOLDER_SELECTOR_CAN_CREATE,
+ _("Posting destination"),
+ _("Choose folders to post the message to."),
+ NULL);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_tree));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+ selector = EM_FOLDER_SELECTOR (dialog);
+ folder_tree = em_folder_selector_get_folder_tree (selector);
em_folder_tree_set_excluded (
- EM_FOLDER_TREE (folder_tree),
+ folder_tree,
EMFT_EXCLUDE_NOSELECT |
EMFT_EXCLUDE_VIRTUAL |
EMFT_EXCLUDE_VTRASH);
- dialog = em_folder_selector_new (
- GTK_WINDOW (composer),
- EM_FOLDER_TREE (folder_tree),
- EM_FOLDER_SELECTOR_CAN_CREATE,
- _("Posting destination"),
- _("Choose folders to post the message to."),
- NULL);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_tree));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
list = e_composer_post_header_get_folders (header);
- em_folder_selector_set_selected_list (
- EM_FOLDER_SELECTOR (dialog), list);
+ em_folder_tree_set_selected_list (folder_tree, list, FALSE);
g_list_foreach (list, (GFunc) g_free, NULL);
g_list_free (list);
@@ -2831,8 +2831,7 @@ post_header_clicked_cb (EComposerPostHeader *header,
goto exit;
}
- list = em_folder_selector_get_selected_uris (
- EM_FOLDER_SELECTOR (dialog));
+ list = em_folder_tree_get_selected_uris (folder_tree);
e_composer_post_header_set_folders (header, list);
g_list_foreach (list, (GFunc) g_free, NULL);
g_list_free (list);
diff --git a/mail/em-folder-selection-button.c b/mail/em-folder-selection-button.c
index c18a62e33a..d4ff9a1127 100644
--- a/mail/em-folder-selection-button.c
+++ b/mail/em-folder-selection-button.c
@@ -222,10 +222,10 @@ static void
folder_selection_button_clicked (GtkButton *button)
{
EMFolderSelectionButtonPrivate *priv;
- EMFolderTree *emft;
+ EMFolderSelector *selector;
+ EMFolderTree *folder_tree;
GtkWidget *dialog;
GtkTreeSelection *selection;
- const gchar *uri;
gpointer parent;
priv = EM_FOLDER_SELECTION_BUTTON (button)->priv;
@@ -233,34 +233,34 @@ folder_selection_button_clicked (GtkButton *button)
parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
- emft = (EMFolderTree *) em_folder_tree_new (priv->backend);
- emu_restore_folder_tree_state (emft);
+ dialog = em_folder_selector_new (
+ parent, priv->backend, EM_FOLDER_SELECTOR_CAN_CREATE,
+ priv->title, priv->caption, NULL);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (emft));
+ selector = EM_FOLDER_SELECTOR (dialog);
+ folder_tree = em_folder_selector_get_folder_tree (selector);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_tree));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
em_folder_tree_set_excluded (
- emft, EMFT_EXCLUDE_NOSELECT |
- EMFT_EXCLUDE_VIRTUAL | EMFT_EXCLUDE_VTRASH);
+ folder_tree,
+ EMFT_EXCLUDE_NOSELECT |
+ EMFT_EXCLUDE_VIRTUAL |
+ EMFT_EXCLUDE_VTRASH);
- dialog = em_folder_selector_new (
- parent, emft, EM_FOLDER_SELECTOR_CAN_CREATE,
- priv->title, priv->caption, NULL);
-
- em_folder_selector_set_selected (
- EM_FOLDER_SELECTOR (dialog), priv->uri);
+ em_folder_tree_set_selected (folder_tree, priv->uri, FALSE);
- if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
- goto exit;
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
+ const gchar *uri;
- uri = em_folder_selector_get_selected_uri (
- EM_FOLDER_SELECTOR (dialog));
- em_folder_selection_button_set_selection (
- EM_FOLDER_SELECTION_BUTTON (button), uri);
+ uri = em_folder_selector_get_selected_uri (selector);
+ em_folder_selection_button_set_selection (
+ EM_FOLDER_SELECTION_BUTTON (button), uri);
- g_signal_emit (button, signals[SELECTED], 0);
+ g_signal_emit (button, signals[SELECTED], 0);
+ }
-exit:
gtk_widget_destroy (dialog);
}
diff --git a/mail/em-folder-selector.c b/mail/em-folder-selector.c
index 71e056e762..24f619d78d 100644
--- a/mail/em-folder-selector.c
+++ b/mail/em-folder-selector.c
@@ -29,22 +29,72 @@
#include "em-folder-tree.h"
#include "em-folder-selector.h"
#include "em-folder-utils.h"
+#include "em-utils.h"
#define d(x)
-static gpointer parent_class;
+#define EM_FOLDER_SELECTOR_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), EM_TYPE_FOLDER_SELECTOR, EMFolderSelectorPrivate))
+
+struct _EMFolderSelectorPrivate {
+ EMailBackend *backend;
+ EMFolderTree *folder_tree; /* not referenced */
+};
+
+enum {
+ PROP_0,
+ PROP_BACKEND
+};
+
+G_DEFINE_TYPE (
+ EMFolderSelector,
+ em_folder_selector,
+ GTK_TYPE_DIALOG)
static void
-folder_selector_finalize (GObject *object)
+folder_selector_set_backend (EMFolderSelector *emfs,
+ EMailBackend *backend)
{
- EMFolderSelector *emfs = EM_FOLDER_SELECTOR (object);
+ g_return_if_fail (E_IS_MAIL_BACKEND (backend));
+ g_return_if_fail (emfs->priv->backend == NULL);
- g_free (emfs->selected_path);
- g_free (emfs->selected_uri);
- g_free (emfs->created_uri);
+ emfs->priv->backend = g_object_ref (backend);
+}
- /* Chain up to parent's finalize() method. */
- G_OBJECT_CLASS (parent_class)->finalize (object);
+static void
+folder_selector_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_BACKEND:
+ folder_selector_set_backend (
+ EM_FOLDER_SELECTOR (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+folder_selector_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_BACKEND:
+ g_value_set_object (
+ value,
+ em_folder_tree_get_backend (
+ EM_FOLDER_TREE (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
@@ -53,75 +103,86 @@ folder_selector_dispose (GObject *object)
EMFolderSelector *emfs = EM_FOLDER_SELECTOR (object);
GtkTreeModel *model;
+ if (emfs->priv->backend != NULL) {
+ g_object_unref (emfs->priv->backend);
+ emfs->priv->backend = NULL;
+ }
+
if (emfs->created_id != 0) {
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (emfs->emft));
+ GtkTreeView *tree_view;
+
+ tree_view = GTK_TREE_VIEW (emfs->priv->folder_tree);
+ model = gtk_tree_view_get_model (tree_view);
g_signal_handler_disconnect (model, emfs->created_id);
emfs->created_id = 0;
}
/* Chain up to parent's dispose() method. */
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ G_OBJECT_CLASS (em_folder_selector_parent_class)->dispose (object);
}
static void
-folder_selector_class_init (EMFolderSelectorClass *class)
+folder_selector_finalize (GObject *object)
{
- GObjectClass *object_class;
+ EMFolderSelector *emfs = EM_FOLDER_SELECTOR (object);
- parent_class = g_type_class_peek_parent (class);
+ g_free (emfs->selected_uri);
+ g_free (emfs->created_uri);
- object_class = G_OBJECT_CLASS (class);
- object_class->finalize = folder_selector_finalize;
- object_class->dispose = folder_selector_dispose;
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (em_folder_selector_parent_class)->finalize (object);
}
static void
-folder_selector_init (EMFolderSelector *emfs)
+em_folder_selector_class_init (EMFolderSelectorClass *class)
{
- emfs->selected_path = NULL;
- emfs->selected_uri = NULL;
+ GObjectClass *object_class;
+
+ g_type_class_add_private (class, sizeof (EMFolderSelectorPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = folder_selector_set_property;
+ object_class->get_property = folder_selector_get_property;
+ object_class->dispose = folder_selector_dispose;
+ object_class->finalize = folder_selector_finalize;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_BACKEND,
+ g_param_spec_object (
+ "backend",
+ NULL,
+ NULL,
+ E_TYPE_MAIL_BACKEND,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
}
-GType
-em_folder_selector_get_type (void)
+static void
+em_folder_selector_init (EMFolderSelector *emfs)
{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- static const GTypeInfo type_info = {
- sizeof (EMFolderSelectorClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) folder_selector_class_init,
- (GClassFinalizeFunc) NULL,
- NULL, /* class_data */
- sizeof (EMFolderSelector),
- 0, /* n_preallocs */
- (GInstanceInitFunc) folder_selector_init,
- NULL /* value_table */
- };
-
- type = g_type_register_static (
- GTK_TYPE_DIALOG, "EMFolderSelector", &type_info, 0);
- }
-
- return type;
+ emfs->priv = EM_FOLDER_SELECTOR_GET_PRIVATE (emfs);
}
static void
emfs_response (GtkWidget *dialog, gint response, EMFolderSelector *emfs)
{
+ EMFolderTree *folder_tree;
EMailBackend *backend;
if (response != EM_FOLDER_SELECTOR_RESPONSE_NEW)
return;
- g_object_set_data ((GObject *)emfs->emft, "select", GUINT_TO_POINTER (1));
+ folder_tree = em_folder_selector_get_folder_tree (emfs);
+
+ g_object_set_data (
+ G_OBJECT (folder_tree), "select", GUINT_TO_POINTER (1));
- backend = em_folder_tree_get_backend (emfs->emft);
+ backend = em_folder_tree_get_backend (folder_tree);
em_folder_utils_create_folder (
- GTK_WINDOW (dialog), backend, emfs->emft, NULL);
+ GTK_WINDOW (dialog), backend, folder_tree, NULL);
g_signal_stop_emission_by_name (emfs, "response");
}
@@ -129,6 +190,7 @@ emfs_response (GtkWidget *dialog, gint response, EMFolderSelector *emfs)
static void
emfs_create_name_changed (GtkEntry *entry, EMFolderSelector *emfs)
{
+ EMFolderTree *folder_tree;
gchar *path;
const gchar *text = NULL;
gboolean active;
@@ -136,11 +198,14 @@ emfs_create_name_changed (GtkEntry *entry, EMFolderSelector *emfs)
if (gtk_entry_get_text_length (emfs->name_entry) > 0)
text = gtk_entry_get_text (emfs->name_entry);
- path = em_folder_tree_get_selected_uri (emfs->emft);
+ folder_tree = em_folder_selector_get_folder_tree (emfs);
+
+ path = em_folder_tree_get_selected_uri (folder_tree);
active = text && path && !strchr (text, '/');
g_free (path);
- gtk_dialog_set_response_sensitive ((GtkDialog *) emfs, GTK_RESPONSE_OK, active);
+ gtk_dialog_set_response_sensitive (
+ GTK_DIALOG (emfs), GTK_RESPONSE_OK, active);
}
static void
@@ -166,24 +231,29 @@ folder_activated_cb (EMFolderTree *emft,
gtk_dialog_response ((GtkDialog *) emfs, GTK_RESPONSE_OK);
}
-void
-em_folder_selector_construct (EMFolderSelector *emfs,
- EMFolderTree *emft,
- guint32 flags,
- const gchar *title,
- const gchar *text,
- const gchar *oklabel)
+static void
+folder_selector_construct (EMFolderSelector *emfs,
+ guint32 flags,
+ const gchar *title,
+ const gchar *text,
+ const gchar *oklabel)
{
+ EMailBackend *backend;
+ GtkWidget *content_area;
GtkWidget *container;
GtkWidget *widget;
+ backend = em_folder_selector_get_backend (emfs);
+
gtk_window_set_default_size (GTK_WINDOW (emfs), 350, 300);
gtk_window_set_title (GTK_WINDOW (emfs), title);
gtk_container_set_border_width (GTK_CONTAINER (emfs), 6);
- container = gtk_dialog_get_content_area (GTK_DIALOG (emfs));
- gtk_box_set_spacing (GTK_BOX (container), 6);
- gtk_container_set_border_width (GTK_CONTAINER (container), 6);
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (emfs));
+ gtk_box_set_spacing (GTK_BOX (content_area), 6);
+ gtk_container_set_border_width (GTK_CONTAINER (content_area), 6);
+
+ container = content_area;
emfs->flags = flags;
if (flags & EM_FOLDER_SELECTOR_CAN_CREATE) {
@@ -214,17 +284,23 @@ em_folder_selector_construct (EMFolderSelector *emfs,
gtk_box_pack_end (GTK_BOX (container), widget, TRUE, TRUE, 6);
gtk_widget_show (widget);
- emfs->emft = emft;
- gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (emft));
- gtk_widget_show (GTK_WIDGET (emft));
+ container = widget;
+
+ widget = em_folder_tree_new (backend);
+ emu_restore_folder_tree_state (EM_FOLDER_TREE (widget));
+ gtk_container_add (GTK_CONTAINER (widget), widget);
+ emfs->priv->folder_tree = EM_FOLDER_TREE (widget);
+ gtk_widget_show (widget);
g_signal_connect (
- emfs->emft, "folder-selected",
+ widget, "folder-selected",
G_CALLBACK (folder_selected_cb), emfs);
g_signal_connect (
- emfs->emft, "folder-activated",
+ widget, "folder-activated",
G_CALLBACK (folder_activated_cb), emfs);
+ container = content_area;
+
if (text != NULL) {
widget = gtk_label_new (text);
gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_LEFT);
@@ -233,12 +309,12 @@ em_folder_selector_construct (EMFolderSelector *emfs,
gtk_box_pack_end (GTK_BOX (container), widget, FALSE, TRUE, 6);
}
- gtk_widget_grab_focus ((GtkWidget *) emfs->emft);
+ gtk_widget_grab_focus (GTK_WIDGET (emfs->priv->folder_tree));
}
GtkWidget *
em_folder_selector_new (GtkWindow *parent,
- EMFolderTree *emft,
+ EMailBackend *backend,
guint32 flags,
const gchar *title,
const gchar *text,
@@ -246,10 +322,13 @@ em_folder_selector_new (GtkWindow *parent,
{
EMFolderSelector *emfs;
+ g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
+
emfs = g_object_new (
EM_TYPE_FOLDER_SELECTOR,
- "transient-for", parent, NULL);
- em_folder_selector_construct (emfs, emft, flags, title, text, oklabel);
+ "transient-for", parent,
+ "backend", backend, NULL);
+ folder_selector_construct (emfs, flags, title, text, oklabel);
return (GtkWidget *) emfs;
}
@@ -258,11 +337,14 @@ static void
emfs_create_name_activate (GtkEntry *entry, EMFolderSelector *emfs)
{
if (gtk_entry_get_text_length (emfs->name_entry) > 0) {
+ EMFolderTree *folder_tree;
gchar *path;
const gchar *text;
text = gtk_entry_get_text (emfs->name_entry);
- path = em_folder_tree_get_selected_uri (emfs->emft);
+
+ folder_tree = em_folder_selector_get_folder_tree (emfs);
+ path = em_folder_tree_get_selected_uri (folder_tree);
if (text && path && !strchr (text, '/'))
g_signal_emit_by_name (emfs, "response", GTK_RESPONSE_OK);
@@ -272,24 +354,30 @@ emfs_create_name_activate (GtkEntry *entry, EMFolderSelector *emfs)
GtkWidget *
em_folder_selector_create_new (GtkWindow *parent,
- EMFolderTree *emft,
+ EMailBackend *backend,
guint32 flags,
const gchar *title,
const gchar *text)
{
EMFolderSelector *emfs;
+ EMFolderTree *folder_tree;
GtkWidget *hbox, *w;
GtkWidget *container;
+ g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
+
/* remove the CREATE flag if it is there since that's the
* whole purpose of this dialog */
flags &= ~EM_FOLDER_SELECTOR_CAN_CREATE;
emfs = g_object_new (
EM_TYPE_FOLDER_SELECTOR,
- "transient-for", parent, NULL);
- em_folder_selector_construct (emfs, emft, flags, title, text, _("C_reate"));
- em_folder_tree_set_excluded (emft, EMFT_EXCLUDE_NOINFERIORS);
+ "transient-for", parent,
+ "backend", backend, NULL);
+ folder_selector_construct (emfs, flags, title, text, _("C_reate"));
+
+ folder_tree = em_folder_selector_get_folder_tree (emfs);
+ em_folder_tree_set_excluded (folder_tree, EMFT_EXCLUDE_NOINFERIORS);
hbox = gtk_hbox_new (FALSE, 0);
w = gtk_label_new_with_mnemonic (_("Folder _name:"));
@@ -316,33 +404,42 @@ em_folder_selector_create_new (GtkWindow *parent,
return (GtkWidget *) emfs;
}
-void
-em_folder_selector_set_selected (EMFolderSelector *emfs, const gchar *uri)
+EMailBackend *
+em_folder_selector_get_backend (EMFolderSelector *emfs)
{
- em_folder_tree_set_selected (emfs->emft, uri, FALSE);
+ g_return_val_if_fail (EM_IS_FOLDER_SELECTOR (emfs), NULL);
+
+ return emfs->priv->backend;
}
-void
-em_folder_selector_set_selected_list (EMFolderSelector *emfs, GList *list)
+EMFolderTree *
+em_folder_selector_get_folder_tree (EMFolderSelector *emfs)
{
- em_folder_tree_set_selected_list (emfs->emft, list, FALSE);
+ g_return_val_if_fail (EM_IS_FOLDER_SELECTOR (emfs), NULL);
+
+ return emfs->priv->folder_tree;
}
const gchar *
em_folder_selector_get_selected_uri (EMFolderSelector *emfs)
{
+ EMFolderTree *folder_tree;
gchar *uri;
const gchar *name;
- if (!(uri = em_folder_tree_get_selected_uri (emfs->emft))) {
+ g_return_val_if_fail (EM_IS_FOLDER_SELECTOR (emfs), NULL);
+
+ folder_tree = em_folder_selector_get_folder_tree (emfs);
+ uri = em_folder_tree_get_selected_uri (folder_tree);
+
+ if (uri == NULL) {
d(printf ("no selected folder?\n"));
return NULL;
}
- if (uri && emfs->name_entry) {
+ if (emfs->name_entry) {
CamelProvider *provider;
CamelURL *url;
- gchar *newpath;
provider = camel_provider_get (uri, NULL);
@@ -350,12 +447,15 @@ em_folder_selector_get_selected_uri (EMFolderSelector *emfs)
url = camel_url_new (uri, NULL);
if (provider && (provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)) {
+ gchar *path;
+
if (url->fragment)
- newpath = g_strdup_printf ("%s/%s", url->fragment, name);
+ path = g_strdup_printf ("%s/%s", url->fragment, name);
else
- newpath = g_strdup (name);
+ path = g_strdup (name);
- camel_url_set_fragment (url, newpath);
+ camel_url_set_fragment (url, path);
+ g_free (path);
} else {
gchar *path;
@@ -364,16 +464,9 @@ em_folder_selector_get_selected_uri (EMFolderSelector *emfs)
strcmp (url->path, "/") == 0) ? "":
url->path, name);
camel_url_set_path (url, path);
- if (path[0] == '/') {
- newpath = g_strdup (path+1);
- g_free (path);
- } else
- newpath = path;
+ g_free (path);
}
- g_free (emfs->selected_path);
- emfs->selected_path = newpath;
-
g_free (emfs->selected_uri);
emfs->selected_uri = camel_url_to_string (url, 0);
@@ -383,49 +476,3 @@ em_folder_selector_get_selected_uri (EMFolderSelector *emfs)
return uri;
}
-
-GList *
-em_folder_selector_get_selected_uris (EMFolderSelector *emfs)
-{
- return em_folder_tree_get_selected_uris (emfs->emft);
-}
-
-GList *
-em_folder_selector_get_selected_paths (EMFolderSelector *emfs)
-{
- return em_folder_tree_get_selected_paths (emfs->emft);
-}
-
-const gchar *
-em_folder_selector_get_selected_path (EMFolderSelector *emfs)
-{
- gchar *uri, *path;
-
- if (emfs->selected_path) {
- /* already did the work in a previous call */
- return emfs->selected_path;
- }
-
- if ((uri = em_folder_tree_get_selected_uri (emfs->emft)) == NULL) {
- d(printf ("no selected folder?\n"));
- return NULL;
- }
- g_free (uri);
-
- path = em_folder_tree_get_selected_path (emfs->emft);
- if (emfs->name_entry) {
- const gchar *name;
- gchar *newpath;
-
- name = gtk_entry_get_text (emfs->name_entry);
- newpath = g_strdup_printf ("%s/%s", path?path:"", name);
-
- g_free (path);
- emfs->selected_path = g_strdup (newpath);
- } else {
- g_free (emfs->selected_path);
- emfs->selected_path = path?path:g_strdup("");
- }
-
- return emfs->selected_path;
-}
diff --git a/mail/em-folder-selector.h b/mail/em-folder-selector.h
index 1056a1145e..456abdc20a 100644
--- a/mail/em-folder-selector.h
+++ b/mail/em-folder-selector.h
@@ -54,12 +54,11 @@ typedef struct _EMFolderSelectorPrivate EMFolderSelectorPrivate;
struct _EMFolderSelector {
GtkDialog parent;
+ EMFolderSelectorPrivate *priv;
guint32 flags;
- EMFolderTree *emft;
GtkEntry *name_entry;
- gchar *selected_path;
gchar *selected_uri;
gchar *created_uri;
@@ -79,35 +78,21 @@ enum {
};
GType em_folder_selector_get_type (void);
-void em_folder_selector_construct (EMFolderSelector *emfs,
- EMFolderTree *emft,
- guint32 flags,
- const gchar *title,
- const gchar *text,
- const gchar *oklabel);
GtkWidget * em_folder_selector_new (GtkWindow *parent,
- EMFolderTree *emft,
+ EMailBackend *backend,
guint32 flags,
const gchar *title,
const gchar *text,
const gchar *oklabel);
GtkWidget * em_folder_selector_create_new (GtkWindow *parent,
- EMFolderTree *emft,
+ EMailBackend *backend,
guint32 flags,
const gchar *title,
const gchar *text);
-void em_folder_selector_set_selected (EMFolderSelector *emfs,
- const gchar *uri);
-void em_folder_selector_set_selected_list
- (EMFolderSelector *emfs,
- GList *list);
-const gchar * em_folder_selector_get_selected_uri
- (EMFolderSelector *emfs);
-const gchar * em_folder_selector_get_selected_path
+EMailBackend * em_folder_selector_get_backend (EMFolderSelector *emfs);
+EMFolderTree * em_folder_selector_get_folder_tree
(EMFolderSelector *emfs);
-GList * em_folder_selector_get_selected_uris
- (EMFolderSelector *emfs);
-GList * em_folder_selector_get_selected_paths
+const gchar * em_folder_selector_get_selected_uri
(EMFolderSelector *emfs);
G_END_DECLS
diff --git a/mail/em-folder-utils.c b/mail/em-folder-utils.c
index 498167d2b4..6bcf06146a 100644
--- a/mail/em-folder-utils.c
+++ b/mail/em-folder-utils.c
@@ -446,7 +446,8 @@ em_folder_utils_copy_folder (GtkWindow *parent,
gint delete)
{
GtkWidget *dialog;
- EMFolderTree *emft;
+ EMFolderSelector *selector;
+ EMFolderTree *folder_tree;
EMailSession *session;
const gchar *label;
const gchar *title;
@@ -472,26 +473,24 @@ em_folder_utils_copy_folder (GtkWindow *parent,
return;
}
- /* XXX Do we leak this reference. */
- emft = (EMFolderTree *) em_folder_tree_new (backend);
- emu_restore_folder_tree_state (emft);
-
- em_folder_tree_set_excluded_func (
- emft, emfu_copy_folder_exclude, cfd);
-
label = delete ? _("_Move") : _("C_opy");
title = delete ? _("Move Folder To") : _("Copy Folder To");
dialog = em_folder_selector_new (
- parent, emft,
+ parent, backend,
EM_FOLDER_SELECTOR_CAN_CREATE,
title, NULL, label);
+ selector = EM_FOLDER_SELECTOR (dialog);
+ folder_tree = em_folder_selector_get_folder_tree (selector);
+
+ em_folder_tree_set_excluded_func (
+ folder_tree, emfu_copy_folder_exclude, cfd);
+
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
const gchar *uri;
- uri = em_folder_selector_get_selected_uri (
- EM_FOLDER_SELECTOR (dialog));
+ uri = em_folder_selector_get_selected_uri (selector);
emfu_copy_folder_selected (backend, uri, cfd);
}
@@ -536,6 +535,7 @@ em_folder_utils_create_folder (GtkWindow *parent,
const gchar *initial_uri)
{
EMailSession *session;
+ EMFolderSelector *selector;
EMFolderTree *folder_tree;
CamelStore *store = NULL;
const gchar *folder_uri;
@@ -548,22 +548,21 @@ em_folder_utils_create_folder (GtkWindow *parent,
session = e_mail_backend_get_session (backend);
- folder_tree = (EMFolderTree *) em_folder_tree_new (backend);
- emu_restore_folder_tree_state (folder_tree);
-
dialog = em_folder_selector_create_new (
- parent, folder_tree, 0,
+ parent, backend, 0,
_("Create Folder"),
_("Specify where to create the folder:"));
+
+ selector = EM_FOLDER_SELECTOR (dialog);
+ folder_tree = em_folder_selector_get_folder_tree (selector);
+
if (initial_uri != NULL)
- em_folder_selector_set_selected (
- EM_FOLDER_SELECTOR (dialog), initial_uri);
+ em_folder_tree_set_selected (folder_tree, initial_uri, FALSE);
if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
goto exit;
- folder_uri = em_folder_selector_get_selected_uri (
- EM_FOLDER_SELECTOR (dialog));
+ folder_uri = em_folder_selector_get_selected_uri (selector);
e_mail_folder_uri_parse (
CAMEL_SESSION (session), folder_uri,
diff --git a/mail/em-vfolder-rule.c b/mail/em-vfolder-rule.c
index 01622711d3..c458cc7648 100644
--- a/mail/em-vfolder-rule.c
+++ b/mail/em-vfolder-rule.c
@@ -589,7 +589,7 @@ vfr_folder_response (EMFolderSelector *selector,
static void
source_add (GtkWidget *widget, struct _source_data *data)
{
- EMFolderTree *emft;
+ EMFolderTree *folder_tree;
EMailBackend *backend;
GtkWidget *dialog;
gpointer parent;
@@ -599,14 +599,19 @@ source_add (GtkWidget *widget, struct _source_data *data)
backend = em_vfolder_rule_get_backend (data->vr);
- emft = (EMFolderTree *) em_folder_tree_new (backend);
- emu_restore_folder_tree_state (emft);
- em_folder_tree_set_excluded (emft, EMFT_EXCLUDE_NOSELECT);
-
dialog = em_folder_selector_new (
- parent, emft, EM_FOLDER_SELECTOR_CAN_CREATE,
+ parent, backend, EM_FOLDER_SELECTOR_CAN_CREATE,
_("Add Folder"), NULL, _("_Add"));
- g_signal_connect(dialog, "response", G_CALLBACK(vfr_folder_response), data);
+
+ folder_tree = em_folder_selector_get_folder_tree (
+ EM_FOLDER_SELECTOR (dialog));
+
+ em_folder_tree_set_excluded (folder_tree, EMFT_EXCLUDE_NOSELECT);
+
+ g_signal_connect (
+ dialog, "response",
+ G_CALLBACK (vfr_folder_response), data);
+
gtk_widget_show (dialog);
}