[evolution] EMFolderSelector: Add a "model" construct-only property.



commit daa63adeb7ec56169c24651b74a0e96fa4b92fd3
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Aug 9 22:25:53 2011 -0400

    EMFolderSelector: Add a "model" construct-only property.

 mail/e-mail-reader.c              |   14 +++++-
 mail/em-composer-utils.c          |    6 ++-
 mail/em-folder-selection-button.c |    6 ++-
 mail/em-folder-selector.c         |   83 ++++++++++++++++++++++++++++++------
 mail/em-folder-selector.h         |    4 ++
 mail/em-folder-utils.c            |   10 ++++-
 mail/em-vfolder-rule.c            |    6 ++-
 7 files changed, 107 insertions(+), 22 deletions(-)
---
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 313e0f5..fad5415 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -287,6 +287,7 @@ action_mail_copy_cb (GtkAction *action,
 	EMailSession *session;
 	EMFolderSelector *selector;
 	EMFolderTree *folder_tree;
+	EMFolderTreeModel *model;
 	GtkWidget *dialog;
 	GtkWindow *window;
 	GPtrArray *uids;
@@ -299,8 +300,11 @@ action_mail_copy_cb (GtkAction *action,
 	window = e_mail_reader_get_window (reader);
 	uids = e_mail_reader_get_selected_uids (reader);
 
+	model = em_folder_tree_model_get_default ();
+
 	dialog = em_folder_selector_new (
-		window, backend, EM_FOLDER_SELECTOR_CAN_CREATE,
+		window, backend, model,
+		EM_FOLDER_SELECTOR_CAN_CREATE,
 		_("Copy to Folder"), NULL, _("C_opy"));
 
 	selector = EM_FOLDER_SELECTOR (dialog);
@@ -789,20 +793,24 @@ action_mail_move_cb (GtkAction *action,
 	EMailSession *session;
 	EMFolderSelector *selector;
 	EMFolderTree *folder_tree;
+	EMFolderTreeModel *model;
 	GtkWidget *dialog;
 	GtkWindow *window;
 	GPtrArray *uids;
 	const gchar *uri;
 
 	backend = e_mail_reader_get_backend (reader);
+	session = e_mail_backend_get_session (backend);
+
 	folder = e_mail_reader_get_folder (reader);
 	uids = e_mail_reader_get_selected_uids (reader);
 	window = e_mail_reader_get_window (reader);
 
-	session = e_mail_backend_get_session (backend);
+	model = em_folder_tree_model_get_default ();
 
 	dialog = em_folder_selector_new (
-		window, backend, EM_FOLDER_SELECTOR_CAN_CREATE,
+		window, backend, model,
+		EM_FOLDER_SELECTOR_CAN_CREATE,
 		_("Move to Folder"), NULL, _("_Move"));
 
 	selector = EM_FOLDER_SELECTOR (dialog);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 1a964e7..529c9c5 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -2922,6 +2922,7 @@ post_header_clicked_cb (EComposerPostHeader *header,
 	EShellBackend *shell_backend;
 	GtkTreeSelection *selection;
 	EMFolderSelector *selector;
+	EMFolderTreeModel *model;
 	EMFolderTree *folder_tree;
 	GtkWidget *dialog;
 	GList *list;
@@ -2930,10 +2931,13 @@ post_header_clicked_cb (EComposerPostHeader *header,
 	shell = e_msg_composer_get_shell (composer);
 	shell_backend = e_shell_get_backend_by_name (shell, "mail");
 
+	/* FIXME Limit the folder tree to the NNTP account? */
+	model = em_folder_tree_model_get_default ();
+
 	dialog = em_folder_selector_new (
 		GTK_WINDOW (composer),
 		E_MAIL_BACKEND (shell_backend),
-		EM_FOLDER_SELECTOR_CAN_CREATE,
+		model, EM_FOLDER_SELECTOR_CAN_CREATE,
 		_("Posting destination"),
 		_("Choose folders to post the message to."),
 		NULL);
diff --git a/mail/em-folder-selection-button.c b/mail/em-folder-selection-button.c
index ec0479d..5bdf5d2 100644
--- a/mail/em-folder-selection-button.c
+++ b/mail/em-folder-selection-button.c
@@ -239,6 +239,7 @@ folder_selection_button_clicked (GtkButton *button)
 	EMFolderSelectionButtonPrivate *priv;
 	EMFolderSelector *selector;
 	EMFolderTree *folder_tree;
+	EMFolderTreeModel *model;
 	GtkWidget *dialog;
 	GtkTreeSelection *selection;
 	gpointer parent;
@@ -248,8 +249,11 @@ folder_selection_button_clicked (GtkButton *button)
 	parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
 	parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
 
+	model = em_folder_tree_model_get_default ();
+
 	dialog = em_folder_selector_new (
-		parent, priv->backend, EM_FOLDER_SELECTOR_CAN_CREATE,
+		parent, priv->backend, model,
+		EM_FOLDER_SELECTOR_CAN_CREATE,
 		priv->title, priv->caption, NULL);
 
 	selector = EM_FOLDER_SELECTOR (dialog);
diff --git a/mail/em-folder-selector.c b/mail/em-folder-selector.c
index 0ff74c0..d8acab7 100644
--- a/mail/em-folder-selector.c
+++ b/mail/em-folder-selector.c
@@ -44,11 +44,13 @@
 struct _EMFolderSelectorPrivate {
 	EMailBackend *backend;
 	EMFolderTree *folder_tree;  /* not referenced */
+	EMFolderTreeModel *model;
 };
 
 enum {
 	PROP_0,
-	PROP_BACKEND
+	PROP_BACKEND,
+	PROP_MODEL
 };
 
 /* XXX EMFolderSelector is an EAlertSink, but it just uses the default
@@ -71,6 +73,16 @@ folder_selector_set_backend (EMFolderSelector *emfs,
 }
 
 static void
+folder_selector_set_model (EMFolderSelector *emfs,
+                           EMFolderTreeModel *model)
+{
+	g_return_if_fail (EM_IS_FOLDER_TREE_MODEL (model));
+	g_return_if_fail (emfs->priv->model == NULL);
+
+	emfs->priv->model = g_object_ref (model);
+}
+
+static void
 folder_selector_set_property (GObject *object,
                               guint property_id,
                               const GValue *value,
@@ -82,6 +94,12 @@ folder_selector_set_property (GObject *object,
 				EM_FOLDER_SELECTOR (object),
 				g_value_get_object (value));
 			return;
+
+		case PROP_MODEL:
+			folder_selector_set_model (
+				EM_FOLDER_SELECTOR (object),
+				g_value_get_object (value));
+			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -97,8 +115,15 @@ folder_selector_get_property (GObject *object,
 		case PROP_BACKEND:
 			g_value_set_object (
 				value,
-				em_folder_tree_get_backend (
-				EM_FOLDER_TREE (object)));
+				em_folder_selector_get_backend (
+				EM_FOLDER_SELECTOR (object)));
+			return;
+
+		case PROP_MODEL:
+			g_value_set_object (
+				value,
+				em_folder_selector_get_model (
+				EM_FOLDER_SELECTOR (object)));
 			return;
 	}
 
@@ -109,20 +134,21 @@ static void
 folder_selector_dispose (GObject *object)
 {
 	EMFolderSelector *emfs = EM_FOLDER_SELECTOR (object);
-	GtkTreeModel *model;
+
+	if (emfs->created_id != 0) {
+		g_signal_handler_disconnect (
+			emfs->priv->model, emfs->created_id);
+		emfs->created_id = 0;
+	}
 
 	if (emfs->priv->backend != NULL) {
 		g_object_unref (emfs->priv->backend);
 		emfs->priv->backend = NULL;
 	}
 
-	if (emfs->created_id != 0) {
-		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;
+	if (emfs->priv->model != NULL) {
+		g_object_unref (emfs->priv->model);
+		emfs->priv->model = NULL;
 	}
 
 	/* Chain up to parent's dispose() method. */
@@ -165,6 +191,18 @@ em_folder_selector_class_init (EMFolderSelectorClass *class)
 			G_PARAM_READWRITE |
 			G_PARAM_CONSTRUCT_ONLY |
 			G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_MODEL,
+		g_param_spec_object (
+			"model",
+			NULL,
+			NULL,
+			EM_TYPE_FOLDER_TREE_MODEL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT_ONLY |
+			G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -247,11 +285,13 @@ folder_selector_construct (EMFolderSelector *emfs,
                            const gchar *oklabel)
 {
 	EMailBackend *backend;
+	EMFolderTreeModel *model;
 	GtkWidget *content_area;
 	GtkWidget *container;
 	GtkWidget *widget;
 
 	backend = em_folder_selector_get_backend (emfs);
+	model = em_folder_selector_get_model (emfs);
 
 	gtk_window_set_default_size (GTK_WINDOW (emfs), 350, 300);
 	gtk_window_set_title (GTK_WINDOW (emfs), title);
@@ -294,7 +334,8 @@ folder_selector_construct (EMFolderSelector *emfs,
 
 	container = widget;
 
-	widget = em_folder_tree_new (backend, E_ALERT_SINK (emfs));
+	widget = em_folder_tree_new_with_model (
+		backend, E_ALERT_SINK (emfs), model);
 	emu_restore_folder_tree_state (EM_FOLDER_TREE (widget));
 	gtk_container_add (GTK_CONTAINER (container), widget);
 	emfs->priv->folder_tree = EM_FOLDER_TREE (widget);
@@ -323,6 +364,7 @@ folder_selector_construct (EMFolderSelector *emfs,
 GtkWidget *
 em_folder_selector_new (GtkWindow *parent,
                         EMailBackend *backend,
+                        EMFolderTreeModel *model,
                         guint32 flags,
                         const gchar *title,
                         const gchar *text,
@@ -331,11 +373,13 @@ em_folder_selector_new (GtkWindow *parent,
 	EMFolderSelector *emfs;
 
 	g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
+	g_return_val_if_fail (EM_IS_FOLDER_TREE_MODEL (model), NULL);
 
 	emfs = g_object_new (
 		EM_TYPE_FOLDER_SELECTOR,
 		"transient-for", parent,
-		"backend", backend, NULL);
+		"backend", backend,
+		"model", model, NULL);
 	folder_selector_construct (emfs, flags, title, text, oklabel);
 
 	return (GtkWidget *) emfs;
@@ -363,6 +407,7 @@ emfs_create_name_activate (GtkEntry *entry, EMFolderSelector *emfs)
 GtkWidget *
 em_folder_selector_create_new (GtkWindow *parent,
                                EMailBackend *backend,
+                               EMFolderTreeModel *model,
                                guint32 flags,
                                const gchar *title,
                                const gchar *text)
@@ -373,6 +418,7 @@ em_folder_selector_create_new (GtkWindow *parent,
 	GtkWidget *container;
 
 	g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
+	g_return_val_if_fail (EM_IS_FOLDER_TREE_MODEL (model), NULL);
 
 	/* remove the CREATE flag if it is there since that's the
 	 * whole purpose of this dialog */
@@ -381,7 +427,8 @@ em_folder_selector_create_new (GtkWindow *parent,
 	emfs = g_object_new (
 		EM_TYPE_FOLDER_SELECTOR,
 		"transient-for", parent,
-		"backend", backend, NULL);
+		"backend", backend,
+		"model", model, NULL);
 	folder_selector_construct (emfs, flags, title, text, _("C_reate"));
 
 	folder_tree = em_folder_selector_get_folder_tree (emfs);
@@ -420,6 +467,14 @@ em_folder_selector_get_backend (EMFolderSelector *emfs)
 	return emfs->priv->backend;
 }
 
+EMFolderTreeModel *
+em_folder_selector_get_model (EMFolderSelector *emfs)
+{
+	g_return_val_if_fail (EM_IS_FOLDER_SELECTOR (emfs), NULL);
+
+	return emfs->priv->model;
+}
+
 EMFolderTree *
 em_folder_selector_get_folder_tree (EMFolderSelector *emfs)
 {
diff --git a/mail/em-folder-selector.h b/mail/em-folder-selector.h
index 456abdc..dd26adf 100644
--- a/mail/em-folder-selector.h
+++ b/mail/em-folder-selector.h
@@ -80,16 +80,20 @@ enum {
 GType		em_folder_selector_get_type	(void);
 GtkWidget *	em_folder_selector_new		(GtkWindow *parent,
 						 EMailBackend *backend,
+						 EMFolderTreeModel *model,
 						 guint32 flags,
 						 const gchar *title,
 						 const gchar *text,
 						 const gchar *oklabel);
 GtkWidget *	em_folder_selector_create_new	(GtkWindow *parent,
 						 EMailBackend *backend,
+						 EMFolderTreeModel *model,
 						 guint32 flags,
 						 const gchar *title,
 						 const gchar *text);
 EMailBackend *	em_folder_selector_get_backend	(EMFolderSelector *emfs);
+EMFolderTreeModel *
+		em_folder_selector_get_model	(EMFolderSelector *emfs);
 EMFolderTree *	em_folder_selector_get_folder_tree
 						(EMFolderSelector *emfs);
 const gchar *	em_folder_selector_get_selected_uri
diff --git a/mail/em-folder-utils.c b/mail/em-folder-utils.c
index 4650405..f43a929 100644
--- a/mail/em-folder-utils.c
+++ b/mail/em-folder-utils.c
@@ -452,6 +452,7 @@ em_folder_utils_copy_folder (GtkWindow *parent,
 	GtkWidget *dialog;
 	EMFolderSelector *selector;
 	EMFolderTree *folder_tree;
+	EMFolderTreeModel *model;
 	EMailSession *session;
 	const gchar *label;
 	const gchar *title;
@@ -480,8 +481,10 @@ em_folder_utils_copy_folder (GtkWindow *parent,
 	label = delete ? _("_Move") : _("C_opy");
 	title = delete ? _("Move Folder To") : _("Copy Folder To");
 
+	model = em_folder_tree_model_get_default ();
+
 	dialog = em_folder_selector_new (
-		parent, backend,
+		parent, backend, model,
 		EM_FOLDER_SELECTOR_CAN_CREATE,
 		title, NULL, label);
 
@@ -541,6 +544,7 @@ em_folder_utils_create_folder (GtkWindow *parent,
 	EMailSession *session;
 	EMFolderSelector *selector;
 	EMFolderTree *folder_tree;
+	EMFolderTreeModel *model;
 	CamelStore *store = NULL;
 	gchar *folder_name = NULL;
 	GtkWidget *dialog;
@@ -551,8 +555,10 @@ em_folder_utils_create_folder (GtkWindow *parent,
 
 	session = e_mail_backend_get_session (backend);
 
+	model = em_folder_tree_model_get_default ();
+
 	dialog = em_folder_selector_create_new (
-		parent, backend, 0,
+		parent, backend, model, 0,
 		_("Create Folder"),
 		_("Specify where to create the folder:"));
 
diff --git a/mail/em-vfolder-rule.c b/mail/em-vfolder-rule.c
index 2f9cc9d..4c3a150 100644
--- a/mail/em-vfolder-rule.c
+++ b/mail/em-vfolder-rule.c
@@ -590,6 +590,7 @@ static void
 source_add (GtkWidget *widget, struct _source_data *data)
 {
 	EMFolderTree *folder_tree;
+	EMFolderTreeModel *model;
 	EMailBackend *backend;
 	GtkWidget *dialog;
 	gpointer parent;
@@ -599,8 +600,11 @@ source_add (GtkWidget *widget, struct _source_data *data)
 
 	backend = em_vfolder_rule_get_backend (data->vr);
 
+	model = em_folder_tree_model_get_default ();
+
 	dialog = em_folder_selector_new (
-		parent, backend, EM_FOLDER_SELECTOR_CAN_CREATE,
+		parent, backend, model,
+		EM_FOLDER_SELECTOR_CAN_CREATE,
 		_("Add Folder"), NULL, _("_Add"));
 
 	folder_tree = em_folder_selector_get_folder_tree (



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]