X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-folder-tree-view.c;h=119f944afa859b052515cbe37f80d5a85fd3ab90;hp=7ecca2d9d0c7be4816362fe597cd1ccc16c4c649;hb=0cc6cd8e2173a6f8aa2cf486a6ef2b2e2d2a127f;hpb=c7f3aa3526f98676511dbc8db9d8a23e07fb79c0 diff --git a/src/modest-tny-folder-tree-view.c b/src/modest-tny-folder-tree-view.c index 7ecca2d..119f944 100644 --- a/src/modest-tny-folder-tree-view.c +++ b/src/modest-tny-folder-tree-view.c @@ -1,6 +1,32 @@ -/* 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 @@ -40,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; @@ -90,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); @@ -143,25 +171,34 @@ guess_folder_type (const gchar* name) 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) + 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"))) + 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"))) + 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"))) + 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"))) + 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"))) + 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"))) + 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"))) + else if (g_str_has_prefix(folder, "calendar") || + g_str_has_prefix(folder, _("calendar"))) type = TNY_MSG_FOLDER_TYPE_CALENDAR; g_free (folder); @@ -217,7 +254,6 @@ icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, 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); @@ -313,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; @@ -323,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); @@ -365,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 @@ -429,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;