X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-folder-tree-view.c;h=119f944afa859b052515cbe37f80d5a85fd3ab90;hp=27fb3b8f016bd3b0c851d9be87024b3cd496dca4;hb=0cc6cd8e2173a6f8aa2cf486a6ef2b2e2d2a127f;hpb=5c2f644ca855896754d7e87bcc45665cf31b7e1f diff --git a/src/modest-tny-folder-tree-view.c b/src/modest-tny-folder-tree-view.c index 27fb3b8..119f944 100644 --- a/src/modest-tny-folder-tree-view.c +++ b/src/modest-tny-folder-tree-view.c @@ -1,7 +1,34 @@ -/* modest-tny-folder-tree-view.c */ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ -/* insert (c)/licensing information) */ #include +#include #include #include @@ -39,9 +66,10 @@ struct _ModestTnyFolderTreeViewPrivate { TnyMsgFolderIface *cur_folder; gboolean view_is_empty; }; -#define MODEST_TNY_FOLDER_TREE_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ - MODEST_TYPE_TNY_FOLDER_TREE_VIEW, \ - ModestTnyFolderTreeViewPrivate)) +#define MODEST_TNY_FOLDER_TREE_VIEW_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE((o), \ + MODEST_TYPE_TNY_FOLDER_TREE_VIEW, \ + ModestTnyFolderTreeViewPrivate)) /* globals */ static GObjectClass *parent_class = NULL; @@ -79,6 +107,8 @@ modest_tny_folder_tree_view_class_init (ModestTnyFolderTreeViewClass *klass) parent_class = g_type_class_peek_parent (klass); gobject_class->finalize = modest_tny_folder_tree_view_finalize; + + klass->update_model = modest_tny_folder_tree_view_update_model; g_type_class_add_private (gobject_class, sizeof(ModestTnyFolderTreeViewPrivate)); @@ -87,7 +117,8 @@ modest_tny_folder_tree_view_class_init (ModestTnyFolderTreeViewClass *klass) g_signal_new ("folder_selected", G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (ModestTnyFolderTreeViewClass,folder_selected), + G_STRUCT_OFFSET (ModestTnyFolderTreeViewClass, + folder_selected), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); @@ -101,8 +132,7 @@ text_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, { GObject *rendobj; gchar *fname; - gchar *type_name; - guint unread; + gint unread; TnyMsgFolderType type; gtk_tree_model_get (tree_model, iter, @@ -121,6 +151,60 @@ text_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, g_free (fname); } +/* FIXME: move these to TnyMail */ +enum { + + TNY_MSG_FOLDER_TYPE_NOTES = TNY_MSG_FOLDER_TYPE_SENT + 1, /* urgh */ + TNY_MSG_FOLDER_TYPE_DRAFTS, + TNY_MSG_FOLDER_TYPE_CONTACTS, + TNY_MSG_FOLDER_TYPE_CALENDAR +}; + +static TnyMsgFolderType +guess_folder_type (const gchar* name) +{ + TnyMsgFolderType type; + gchar *folder; + + g_return_val_if_fail (name, TNY_MSG_FOLDER_TYPE_NORMAL); + + type = TNY_MSG_FOLDER_TYPE_NORMAL; + folder = g_utf8_strdown (name, strlen(name)); + + if (strcmp (folder, "inbox") == 0 || + strcmp (folder, _("inbox")) == 0) + type = TNY_MSG_FOLDER_TYPE_INBOX; + else if (strcmp (folder, "outbox") == 0 || + strcmp (folder, _("outbox")) == 0) + type = TNY_MSG_FOLDER_TYPE_OUTBOX; + else if (g_str_has_prefix(folder, "junk") || + g_str_has_prefix(folder, _("junk"))) + type = TNY_MSG_FOLDER_TYPE_JUNK; + else if (g_str_has_prefix(folder, "trash") || + g_str_has_prefix(folder, _("trash"))) + type = TNY_MSG_FOLDER_TYPE_JUNK; + else if (g_str_has_prefix(folder, "sent") || + g_str_has_prefix(folder, _("sent"))) + type = TNY_MSG_FOLDER_TYPE_SENT; + + /* these are not *really* TNY_ types */ + else if (g_str_has_prefix(folder, "draft") || + g_str_has_prefix(folder, _("draft"))) + type = TNY_MSG_FOLDER_TYPE_DRAFTS; + else if (g_str_has_prefix(folder, "notes") || + g_str_has_prefix(folder, _("notes"))) + type = TNY_MSG_FOLDER_TYPE_NOTES; + else if (g_str_has_prefix(folder, "contacts") || + g_str_has_prefix(folder, _("contacts"))) + type = TNY_MSG_FOLDER_TYPE_CONTACTS; + else if (g_str_has_prefix(folder, "calendar") || + g_str_has_prefix(folder, _("calendar"))) + type = TNY_MSG_FOLDER_TYPE_CALENDAR; + + g_free (folder); + return type; +} + static void icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, @@ -129,13 +213,21 @@ icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GObject *rendobj; GdkPixbuf *pixbuf; TnyMsgFolderType type; - int unread; + gchar *fname = NULL; + gint unread; rendobj = G_OBJECT(renderer); gtk_tree_model_get (tree_model, iter, TNY_ACCOUNT_TREE_MODEL_TYPE_COLUMN, &type, + TNY_ACCOUNT_TREE_MODEL_NAME_COLUMN, &fname, TNY_ACCOUNT_TREE_MODEL_UNREAD_COLUMN, &unread, -1); rendobj = G_OBJECT(renderer); + + if (type == TNY_MSG_FOLDER_TYPE_NORMAL) + type = guess_folder_type (fname); + + if (fname); + g_free (fname); switch (type) { case TNY_MSG_FOLDER_TYPE_INBOX: @@ -150,6 +242,18 @@ icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, case TNY_MSG_FOLDER_TYPE_SENT: pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_SENT); break; + case TNY_MSG_FOLDER_TYPE_DRAFTS: + pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_DRAFTS); + break; + case TNY_MSG_FOLDER_TYPE_NOTES: + pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_NOTES); + break; + case TNY_MSG_FOLDER_TYPE_CALENDAR: + pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_CALENDAR); + break; + case TNY_MSG_FOLDER_TYPE_CONTACTS: + pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_CONTACTS); + break; case TNY_MSG_FOLDER_TYPE_NORMAL: default: pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_NORMAL); @@ -211,7 +315,6 @@ modest_tny_folder_tree_view_init (ModestTnyFolderTreeView *obj) static void modest_tny_folder_tree_view_finalize (GObject *obj) { - int i; ModestTnyFolderTreeViewPrivate *priv; g_return_if_fail (obj); @@ -246,8 +349,20 @@ modest_tny_folder_tree_view_set_account_store (TnySummaryWindowIface *self, +static void +on_accounts_update (TnyAccountStoreIface *account_store, const gchar *account, + gpointer user_data) +{ + update_model_empty (MODEST_TNY_FOLDER_TREE_VIEW(user_data)); + + if (!update_model (MODEST_TNY_FOLDER_TREE_VIEW(user_data), account_store)) + g_printerr ("modest: failed to update model for changes in '%s'", + account); +} + + GtkWidget* -modest_tny_folder_tree_view_new (TnyAccountStoreIface *iface) +modest_tny_folder_tree_view_new (TnyAccountStoreIface *account_store) { GObject *self; ModestTnyFolderTreeViewPrivate *priv; @@ -256,11 +371,14 @@ modest_tny_folder_tree_view_new (TnyAccountStoreIface *iface) self = G_OBJECT(g_object_new(MODEST_TYPE_TNY_FOLDER_TREE_VIEW, NULL)); priv = MODEST_TNY_FOLDER_TREE_VIEW_GET_PRIVATE(self); - g_return_val_if_fail (iface, NULL); + g_return_val_if_fail (account_store, NULL); - if (!update_model (MODEST_TNY_FOLDER_TREE_VIEW(self), iface)) - g_warning ("failed or update model"); + if (!update_model (MODEST_TNY_FOLDER_TREE_VIEW(self), account_store)) + g_printerr ("modest: failed to update model"); + g_signal_connect (G_OBJECT(account_store), "update_accounts", + G_CALLBACK (on_accounts_update), self); + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(self)); g_signal_connect (sel, "changed", G_CALLBACK(selection_changed), self); @@ -298,49 +416,35 @@ update_model_empty (ModestTnyFolderTreeView *self) static gboolean -update_model (ModestTnyFolderTreeView *self,TnyAccountStoreIface *iface) +update_model (ModestTnyFolderTreeView *self, TnyAccountStoreIface *account_store) { - const GList *accounts; - TnyAccountTreeModel *folder_model; ModestTnyFolderTreeViewPrivate *priv; - - g_return_val_if_fail (iface, FALSE); - - priv = MODEST_TNY_FOLDER_TREE_VIEW_GET_PRIVATE(self); - priv->view_is_empty = TRUE; - - accounts = tny_account_store_iface_get_store_accounts (iface); - if (!accounts) { - g_warning ("no accounts have been defined yet"); - return update_model_empty (self); - } + TnyListIface *account_list; + GtkTreeModel *model, *sortable; - folder_model = tny_account_tree_model_new (); - if (!folder_model) { - g_warning ("failed to get account tree model"); - return update_model_empty (self); - } + g_return_val_if_fail (account_store, FALSE); - while (accounts) { - TnyStoreAccountIface *account = - TNY_STORE_ACCOUNT_IFACE(accounts->data); - if (!account) { - g_warning ("invalid account"); - g_object_unref (folder_model); - return update_model_empty (self); - } - tny_account_tree_model_add (TNY_ACCOUNT_TREE_MODEL (folder_model), - account); - accounts = accounts->next; - } + priv = MODEST_TNY_FOLDER_TREE_VIEW_GET_PRIVATE(self); + + model = GTK_TREE_MODEL(tny_account_tree_model_new ()); + account_list = TNY_LIST_IFACE(model); + + update_model_empty (self); /* cleanup */ + priv->view_is_empty = TRUE; - gtk_tree_view_set_model (GTK_TREE_VIEW(self), - GTK_TREE_MODEL(folder_model)); - g_object_unref (G_OBJECT(folder_model)); + tny_account_store_iface_get_accounts (account_store, account_list, + TNY_ACCOUNT_STORE_IFACE_STORE_ACCOUNTS); + if (!account_list) /* no store accounts found */ + return TRUE; - priv->view_is_empty = FALSE; /* were not empty anymore! */ + sortable = gtk_tree_model_sort_new_with_model (model); + gtk_tree_view_set_model (GTK_TREE_VIEW(self), sortable); + + priv->view_is_empty = FALSE; + g_object_unref (model); + return TRUE; -} +} void @@ -362,8 +466,8 @@ selection_changed (GtkTreeSelection *sel, gpointer user_data) return; /* folder was _un_selected if true */ - if (!gtk_tree_selection_get_selected (sel, &model, &iter)) - { + if (!gtk_tree_selection_get_selected (sel, &model, &iter)) { + if (priv->cur_folder) tny_msg_folder_iface_expunge (priv->cur_folder); priv->cur_folder = NULL; @@ -387,5 +491,11 @@ selection_changed (GtkTreeSelection *sel, gpointer user_data) } - - +gboolean +modest_tny_folder_tree_view_update_model(ModestTnyFolderTreeView *self, + TnyAccountStoreIface *iface) +{ + g_return_val_if_fail (MODEST_IS_TNY_FOLDER_TREE_VIEW (self), FALSE); + + return update_model (self, iface); +}