From fd244132adb4225b6982422632bd69bc57b4e589 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 13 Nov 2003 19:02:07 +0000 Subject: New folder-tree widget that replaces the shell's folder-tree widget. 2003-11-13 Jeffrey Stedfast * em-folder-tree.[c,h]: New folder-tree widget that replaces the shell's folder-tree widget. * em-folder-tree-model.[c,h]: New source files subclassing GtkTreeStore for handling the mess that is drag&drop. * em-folder-selection-button.c: Ported to use EMFolderTree. * em-folder-selection.c: Ported to use EMFolderTree. * em-folder-selector.c: Ported to use EMFolderTree. * mail-component.c: Ported to use EMFolderTree. * mail-offline-handler.c (storage_go_online): Updated to not pass a storage argument. * mail-folder-cache.c: Removed storage stuff. * mail-send-recv.c (receive_update_got_store): Don't do EStorage* stuff anymore. svn path=/trunk/; revision=23331 --- mail/em-folder-selection-button.c | 322 ++++++++++++++++++++------------------ 1 file changed, 171 insertions(+), 151 deletions(-) (limited to 'mail/em-folder-selection-button.c') diff --git a/mail/em-folder-selection-button.c b/mail/em-folder-selection-button.c index ac5a6e1d06..42964a10b2 100644 --- a/mail/em-folder-selection-button.c +++ b/mail/em-folder-selection-button.c @@ -1,51 +1,60 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* em-folder-selection-button.c +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast * - * Copyright (C) 2003 Ximian, Inc. + * Copyright 2003 Ximian, Inc. (www.ximian.com) * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * 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 - * General Public License for more details. + * 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 General Public License for more details. * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. * - * Author: Ettore Perazzoli */ + +#ifdef HAVE_CONFIG_H #include +#endif #include -#include "em-folder-selection-button.h" +#include +#include +#include + +#include #include "mail-component.h" +#include "em-folder-tree.h" #include "em-folder-selector.h" -#include +#include "em-folder-selection-button.h" -#include -#include -#include +static void em_folder_selection_button_class_init (EMFolderSelectionButtonClass *klass); +static void em_folder_selection_button_init (EMFolderSelectionButton *emfsb); +static void em_folder_selection_button_destroy (GtkObject *obj); +static void em_folder_selection_button_finalize (GObject *obj); +static void em_folder_selection_button_clicked (GtkButton *button); -#define PARENT_TYPE gtk_button_get_type () static GtkButtonClass *parent_class = NULL; struct _EMFolderSelectionButtonPrivate { GtkWidget *icon; GtkWidget *label; - + char *uri; - + char *title; char *caption; }; @@ -54,10 +63,55 @@ enum { SELECTED, LAST_SIGNAL }; + static guint signals[LAST_SIGNAL] = { 0 }; -/* Utility functions. */ +GType +em_folder_selection_button_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (EMFolderSelectionButtonClass), + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) em_folder_selection_button_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (EMFolderSelectionButton), + 0, /* n_preallocs */ + (GInstanceInitFunc) em_folder_selection_button_init, + }; + + type = g_type_register_static (GTK_TYPE_BUTTON, "EMFolderSelectionButton", &info, 0); + } + + return type; +} + +static void +em_folder_selection_button_class_init (EMFolderSelectionButtonClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass); + GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass); + + parent_class = g_type_class_ref (GTK_TYPE_BUTTON); + + object_class->finalize = em_folder_selection_button_finalize; + gtk_object_class->destroy = em_folder_selection_button_destroy; + button_class->clicked = em_folder_selection_button_clicked; + + signals[SELECTED] = g_signal_new ("selected", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EMFolderSelectionButtonClass, selected), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} static void set_contents_unselected (EMFolderSelectionButton *button) @@ -69,174 +123,140 @@ set_contents_unselected (EMFolderSelectionButton *button) static void set_contents (EMFolderSelectionButton *button) { - EMFolderSelectionButtonPrivate *priv = button->priv; - char *path, *tmp, *label; - - if (priv->uri == NULL) - goto unset; - - /* We set the button name directly from the storage set path, which is /accountname/path/foldername */ - path = e_storage_set_get_path_for_physical_uri(mail_component_peek_storage_set(mail_component_peek()), priv->uri); - - if (path == NULL) - goto unknown; - - tmp = strchr(path+1, '/'); - if (tmp == NULL) - goto unknown; - *tmp++ = 0; - - label = g_strdup_printf(_("\"%s\" in \"%s\""), tmp, path+1); - gtk_label_set_text (GTK_LABEL (priv->label), label); - g_free (label); - - g_free(path); - return; + struct _EMFolderSelectionButtonPrivate *priv = button->priv; + const char *path; + CamelURL *url; + + if (priv->uri == NULL) { + set_contents_unselected (button); + return; + } + + url = camel_url_new (priv->uri, NULL); + path = url->fragment ? url->fragment : url->path; + + if (path == NULL) { + camel_url_free (url); + set_contents_unselected (button); + return; + } + + gtk_label_set_text (GTK_LABEL (priv->label), path); + camel_url_free (url); +} -unknown: - g_free(path); -unset: - set_contents_unselected(button); +static void +em_folder_selection_button_init (EMFolderSelectionButton *emfsb) +{ + struct _EMFolderSelectionButtonPrivate *priv; + GtkWidget *box; + + priv = g_new0 (struct _EMFolderSelectionButtonPrivate, 1); + emfsb->priv = priv; + + box = gtk_hbox_new (FALSE, 4); + + priv->icon = gtk_image_new (); + gtk_widget_show (priv->icon); + gtk_box_pack_start (GTK_BOX (box), priv->icon, FALSE, TRUE, 0); + + priv->label = gtk_label_new (""); + gtk_widget_show (priv->label); + gtk_label_set_justify (GTK_LABEL (priv->label), GTK_JUSTIFY_LEFT); + gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0); + gtk_box_pack_start (GTK_BOX (box), priv->label, TRUE, TRUE, 0); + + gtk_widget_show (box); + gtk_container_add (GTK_CONTAINER (emfsb), box); + + set_contents (emfsb); } static void -impl_finalize (GObject *object) +em_folder_selection_button_destroy (GtkObject *obj) { - EMFolderSelectionButtonPrivate *priv = EM_FOLDER_SELECTION_BUTTON (object)->priv; + GTK_OBJECT_CLASS (parent_class)->destroy (obj); +} +static void +em_folder_selection_button_finalize (GObject *obj) +{ + struct _EMFolderSelectionButtonPrivate *priv = ((EMFolderSelectionButton *) obj)->priv; + g_free (priv->title); g_free (priv->caption); - g_free(priv->uri); + g_free (priv->uri); g_free (priv); - - (* G_OBJECT_CLASS (parent_class)->finalize) (object); + + G_OBJECT_CLASS (parent_class)->finalize (obj); } static void -emfsb_selector_response(EMFolderSelector *emfs, int response, EMFolderSelectionButton *button) +emfsb_selector_response (EMFolderSelector *emfs, int response, EMFolderSelectionButton *button) { if (response == GTK_RESPONSE_OK) { - const char *uri = em_folder_selector_get_selected_uri(emfs); - - em_folder_selection_button_set_selection(button, uri); - g_signal_emit(button, signals[SELECTED], 0); + const char *uri = em_folder_selector_get_selected_uri (emfs); + + em_folder_selection_button_set_selection (button, uri); + g_signal_emit (button, signals[SELECTED], 0); } - - gtk_widget_destroy((GtkWidget *)emfs); + + gtk_widget_destroy ((GtkWidget *) emfs); } static void -impl_clicked (GtkButton *button) +em_folder_selection_button_clicked (GtkButton *button) { - EMFolderSelectionButtonPrivate *priv = EM_FOLDER_SELECTION_BUTTON (button)->priv; - EStorageSet *ess; - GtkWidget *w; - GtkWidget *toplevel; - + struct _EMFolderSelectionButtonPrivate *priv = EM_FOLDER_SELECTION_BUTTON (button)->priv; + EMFolderTreeModel *model; + EMFolderTree *emft; + GtkWidget *dialog; + if (GTK_BUTTON_CLASS (parent_class)->clicked != NULL) (* GTK_BUTTON_CLASS (parent_class)->clicked) (button); - - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button)); - ess = mail_component_peek_storage_set(mail_component_peek()); - w = em_folder_selector_new(ess, EM_FOLDER_SELECTOR_CAN_CREATE, priv->title, priv->caption); - em_folder_selector_set_selected_uri((EMFolderSelector *)w, priv->uri); - g_signal_connect(w, "response", G_CALLBACK(emfsb_selector_response), button); - gtk_widget_show(w); -} -#if 0 -{ - uri = em_folder_selection_run_dialog_uri((GtkWindow *)toplevel, - priv->title, - priv->caption, - priv->uri); - - em_folder_selection_button_set_selection (EM_FOLDER_SELECTION_BUTTON (button), uri); - g_free(uri); - - g_signal_emit (button, signals[SELECTED], 0); -} -#endif - -static void -class_init (EMFolderSelectionButtonClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - GtkButtonClass *button_class = GTK_BUTTON_CLASS (class); - - object_class->finalize = impl_finalize; - - button_class->clicked = impl_clicked; - - parent_class = g_type_class_peek_parent (class); - - signals[SELECTED] = g_signal_new ("selected", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EMFolderSelectionButtonClass, selected), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); + + model = mail_component_get_tree_model (mail_component_peek ()); + emft = em_folder_tree_new_with_model (model); + + dialog = em_folder_selector_new (emft, EM_FOLDER_SELECTOR_CAN_CREATE, priv->title, priv->caption); + em_folder_selector_set_selected ((EMFolderSelector *) dialog, priv->uri); + g_signal_connect (dialog, "response", G_CALLBACK (emfsb_selector_response), button); + gtk_widget_show (dialog); } -static void -init (EMFolderSelectionButton *folder_selection_button) -{ - EMFolderSelectionButtonPrivate *priv; - GtkWidget *box; - - priv = g_new0 (EMFolderSelectionButtonPrivate, 1); - folder_selection_button->priv = priv; - - box = gtk_hbox_new (FALSE, 4); - - priv->icon = gtk_image_new (); - gtk_box_pack_start (GTK_BOX (box), priv->icon, FALSE, TRUE, 0); - - priv->label = gtk_label_new (""); - gtk_label_set_justify (GTK_LABEL (priv->label), GTK_JUSTIFY_LEFT); - gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0); - gtk_box_pack_start (GTK_BOX (box), priv->label, TRUE, TRUE, 0); - - gtk_widget_show_all (box); - gtk_container_add (GTK_CONTAINER (folder_selection_button), box); - - set_contents (folder_selection_button); -} GtkWidget * -em_folder_selection_button_new(const char *title, const char *caption) +em_folder_selection_button_new (const char *title, const char *caption) { EMFolderSelectionButton *button = g_object_new (EM_TYPE_FOLDER_SELECTION_BUTTON, NULL); - + button->priv->title = g_strdup (title); button->priv->caption = g_strdup (caption); - + return GTK_WIDGET (button); } void -em_folder_selection_button_set_selection(EMFolderSelectionButton *button, const char *uri) +em_folder_selection_button_set_selection (EMFolderSelectionButton *button, const char *uri) { - EMFolderSelectionButtonPrivate *p = button->priv; - - g_return_if_fail(EM_IS_FOLDER_SELECTION_BUTTON(button)); - - if (p->uri != uri) { - g_free(p->uri); - p->uri = g_strdup(uri); + struct _EMFolderSelectionButtonPrivate *priv = button->priv; + + g_return_if_fail (EM_IS_FOLDER_SELECTION_BUTTON (button)); + + if (priv->uri != uri) { + g_free (priv->uri); + priv->uri = g_strdup (uri); } - - set_contents(button); + + set_contents (button); } const char * -em_folder_selection_button_get_selection(EMFolderSelectionButton *button) +em_folder_selection_button_get_selection (EMFolderSelectionButton *button) { g_return_val_if_fail (EM_IS_FOLDER_SELECTION_BUTTON (button), NULL); - + return button->priv->uri; } - -E_MAKE_TYPE (em_folder_selection_button, "EMFolderSelectionButton", EMFolderSelectionButton, class_init, init, PARENT_TYPE) -- cgit v1.2.3