| | 1 | /* TMut |
|---|
| | 2 | * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org> |
|---|
| | 3 | * |
|---|
| | 4 | * This library is free software; you can redistribute it and/or |
|---|
| | 5 | * modify it under the terms of the GNU Lesser General Public |
|---|
| | 6 | * License as published by the Free Software Foundation; either |
|---|
| | 7 | * version 2 of the License, or (at your option) any later version. |
|---|
| | 8 | * |
|---|
| | 9 | * This library is distributed in the hope that it will be useful, |
|---|
| | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| | 12 | * Lesser General Public License for more details. |
|---|
| | 13 | * |
|---|
| | 14 | * You should have received a copy of the GNU Lesser General Public |
|---|
| | 15 | * License along with self library; if not, write to the |
|---|
| | 16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|---|
| | 17 | * Boston, MA 02110-1301, USA. |
|---|
| | 18 | */ |
|---|
| | 19 | |
|---|
| | 20 | #include "tmut-folder-view.h" |
|---|
| | 21 | |
|---|
| | 22 | #include <tny-folder-monitor.h> |
|---|
| | 23 | #include <tny-gtk-header-list-model.h> |
|---|
| | 24 | |
|---|
| | 25 | static GObjectClass *parent_class = NULL; |
|---|
| | 26 | |
|---|
| | 27 | typedef struct _TMutFolderViewPriv TMutFolderViewPriv; |
|---|
| | 28 | |
|---|
| | 29 | struct _TMutFolderViewPriv |
|---|
| | 30 | { |
|---|
| | 31 | GtkProgress *progress; |
|---|
| | 32 | GtkTreeView *headers_treeview; |
|---|
| | 33 | TnyFolderMonitor *monitor; |
|---|
| | 34 | TnyFolder *folder; |
|---|
| | 35 | }; |
|---|
| | 36 | |
|---|
| | 37 | #define TMUT_FOLDER_VIEW_GET_PRIVATE(o) \ |
|---|
| | 38 | (G_TYPE_INSTANCE_GET_PRIVATE ((o), TMUT_TYPE_FOLDER_VIEW, TMutFolderViewPriv)) |
|---|
| | 39 | |
|---|
| | 40 | |
|---|
| | 41 | static void |
|---|
| | 42 | status_update (GObject *sender, TnyStatus *status, gpointer user_data) |
|---|
| | 43 | { |
|---|
| | 44 | TMutFolderViewPriv *priv = TMUT_FOLDER_VIEW_GET_PRIVATE (user_data); |
|---|
| | 45 | |
|---|
| | 46 | if (priv->progress) { |
|---|
| | 47 | gtk_progress_set_percentage (priv->progress, |
|---|
| | 48 | tny_status_get_fraction (status)); |
|---|
| | 49 | } |
|---|
| | 50 | |
|---|
| | 51 | return; |
|---|
| | 52 | } |
|---|
| | 53 | |
|---|
| | 54 | static void |
|---|
| | 55 | on_active_folder_set (TnyFolder *folder, gboolean cancelled, GError *err, gpointer user_data) |
|---|
| | 56 | { |
|---|
| | 57 | return; |
|---|
| | 58 | } |
|---|
| | 59 | |
|---|
| | 60 | void |
|---|
| | 61 | tmut_folder_view_set_active_folder (TMutFolderView *self, TnyFolder *folder) |
|---|
| | 62 | { |
|---|
| | 63 | TMutFolderViewPriv *priv = TMUT_FOLDER_VIEW_GET_PRIVATE (self); |
|---|
| | 64 | GtkTreeModel *model = NULL; |
|---|
| | 65 | |
|---|
| | 66 | if (priv->folder) |
|---|
| | 67 | g_object_unref (priv->folder); |
|---|
| | 68 | priv->folder = TNY_FOLDER (g_object_ref (folder)); |
|---|
| | 69 | |
|---|
| | 70 | model = tny_gtk_header_list_model_new (); |
|---|
| | 71 | |
|---|
| | 72 | tny_gtk_header_list_model_set_folder (TNY_GTK_HEADER_LIST_MODEL (model), |
|---|
| | 73 | folder, FALSE, NULL, status_update, self); |
|---|
| | 74 | |
|---|
| | 75 | if (priv->monitor) { |
|---|
| | 76 | tny_folder_monitor_stop (priv->monitor); |
|---|
| | 77 | g_object_unref (priv->monitor); |
|---|
| | 78 | } |
|---|
| | 79 | |
|---|
| | 80 | priv->monitor = TNY_FOLDER_MONITOR (tny_folder_monitor_new (folder)); |
|---|
| | 81 | tny_folder_monitor_add_list (priv->monitor, TNY_LIST (model)); |
|---|
| | 82 | tny_folder_monitor_start (priv->monitor); |
|---|
| | 83 | |
|---|
| | 84 | tny_folder_refresh_async (folder, on_active_folder_set, |
|---|
| | 85 | status_update, self); |
|---|
| | 86 | |
|---|
| | 87 | gtk_tree_view_set_model (priv->headers_treeview, model); |
|---|
| | 88 | |
|---|
| | 89 | return; |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | static void |
|---|
| | 93 | on_msg_selected (GtkTreeSelection *selection, gpointer user_data) |
|---|
| | 94 | { |
|---|
| | 95 | TMutFolderView *self = TMUT_FOLDER_VIEW (user_data); |
|---|
| | 96 | TMutFolderViewPriv *priv = TMUT_FOLDER_VIEW_GET_PRIVATE (self); |
|---|
| | 97 | |
|---|
| | 98 | return; |
|---|
| | 99 | } |
|---|
| | 100 | |
|---|
| | 101 | |
|---|
| | 102 | |
|---|
| | 103 | static void |
|---|
| | 104 | tmut_folder_view_instance_init (GTypeInstance *instance, gpointer g_class) |
|---|
| | 105 | { |
|---|
| | 106 | TMutFolderView *self = (TMutFolderView *) instance; |
|---|
| | 107 | TMutFolderViewPriv *priv = TMUT_FOLDER_VIEW_GET_PRIVATE (self); |
|---|
| | 108 | GtkWindow *window = GTK_WINDOW (self); |
|---|
| | 109 | GtkCellRenderer *renderer; |
|---|
| | 110 | GtkTreeViewColumn *column; |
|---|
| | 111 | GtkTreeSelection *select; |
|---|
| | 112 | GtkWidget *widget, *sw; |
|---|
| | 113 | |
|---|
| | 114 | priv->progress = NULL; |
|---|
| | 115 | priv->monitor = NULL; |
|---|
| | 116 | |
|---|
| | 117 | sw = gtk_scrolled_window_new (NULL, NULL); |
|---|
| | 118 | gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), |
|---|
| | 119 | GTK_SHADOW_NONE); |
|---|
| | 120 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), |
|---|
| | 121 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
|---|
| | 122 | gtk_container_add (GTK_CONTAINER (window), sw); |
|---|
| | 123 | gtk_widget_show (sw); |
|---|
| | 124 | |
|---|
| | 125 | priv->headers_treeview = GTK_TREE_VIEW (gtk_tree_view_new ()); |
|---|
| | 126 | gtk_tree_view_set_headers_visible (priv->headers_treeview, FALSE); |
|---|
| | 127 | gtk_tree_view_set_rules_hint (priv->headers_treeview, TRUE); |
|---|
| | 128 | gtk_tree_view_set_fixed_height_mode (priv->headers_treeview, TRUE); |
|---|
| | 129 | gtk_widget_show (GTK_WIDGET (priv->headers_treeview)); |
|---|
| | 130 | gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (priv->headers_treeview)); |
|---|
| | 131 | |
|---|
| | 132 | renderer = gtk_cell_renderer_text_new (); |
|---|
| | 133 | column = gtk_tree_view_column_new_with_attributes ("Subject", renderer, |
|---|
| | 134 | "text", TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN, NULL); |
|---|
| | 135 | gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED); |
|---|
| | 136 | gtk_tree_view_append_column (GTK_TREE_VIEW(priv->headers_treeview), column); |
|---|
| | 137 | |
|---|
| | 138 | select = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->headers_treeview)); |
|---|
| | 139 | gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE); |
|---|
| | 140 | |
|---|
| | 141 | g_signal_connect (G_OBJECT (select), "changed", |
|---|
| | 142 | G_CALLBACK (on_msg_selected), self); |
|---|
| | 143 | |
|---|
| | 144 | return; |
|---|
| | 145 | } |
|---|
| | 146 | |
|---|
| | 147 | static void |
|---|
| | 148 | tmut_folder_view_finalize (GObject *object) |
|---|
| | 149 | { |
|---|
| | 150 | TMutFolderViewPriv *priv = TMUT_FOLDER_VIEW_GET_PRIVATE (object); |
|---|
| | 151 | |
|---|
| | 152 | if (priv->monitor) { |
|---|
| | 153 | tny_folder_monitor_stop (priv->monitor); |
|---|
| | 154 | g_object_unref (priv->monitor); |
|---|
| | 155 | } |
|---|
| | 156 | |
|---|
| | 157 | if (priv->progress) |
|---|
| | 158 | g_object_unref (priv->progress); |
|---|
| | 159 | |
|---|
| | 160 | (*parent_class->finalize) (object); |
|---|
| | 161 | return; |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | |
|---|
| | 165 | static void |
|---|
| | 166 | tmut_folder_view_class_init (TMutFolderViewClass *class) |
|---|
| | 167 | { |
|---|
| | 168 | GObjectClass *object_class; |
|---|
| | 169 | |
|---|
| | 170 | parent_class = g_type_class_peek_parent (class); |
|---|
| | 171 | object_class = (GObjectClass*) class; |
|---|
| | 172 | |
|---|
| | 173 | object_class->finalize = tmut_folder_view_finalize; |
|---|
| | 174 | |
|---|
| | 175 | g_type_class_add_private (object_class, sizeof (TMutFolderViewPriv)); |
|---|
| | 176 | |
|---|
| | 177 | return; |
|---|
| | 178 | } |
|---|
| | 179 | |
|---|
| | 180 | /** |
|---|
| | 181 | * tmut_folder_view_new: |
|---|
| | 182 | * |
|---|
| | 183 | * |
|---|
| | 184 | * Return value: A new #TnySummaryView instance implemented for TMUT |
|---|
| | 185 | **/ |
|---|
| | 186 | TMutFolderView* |
|---|
| | 187 | tmut_folder_view_new (GtkProgress *progress) |
|---|
| | 188 | { |
|---|
| | 189 | TMutFolderView *self = g_object_new (TMUT_TYPE_FOLDER_VIEW, NULL); |
|---|
| | 190 | TMutFolderViewPriv *priv = TMUT_FOLDER_VIEW_GET_PRIVATE (self); |
|---|
| | 191 | |
|---|
| | 192 | priv->progress = GTK_PROGRESS (g_object_ref (progress)); |
|---|
| | 193 | |
|---|
| | 194 | return TMUT_FOLDER_VIEW (self); |
|---|
| | 195 | } |
|---|
| | 196 | |
|---|
| | 197 | GType |
|---|
| | 198 | tmut_folder_view_get_type (void) |
|---|
| | 199 | { |
|---|
| | 200 | static GType type = 0; |
|---|
| | 201 | |
|---|
| | 202 | if (G_UNLIKELY(type == 0)) |
|---|
| | 203 | { |
|---|
| | 204 | static const GTypeInfo info = |
|---|
| | 205 | { |
|---|
| | 206 | sizeof (TMutFolderViewClass), |
|---|
| | 207 | NULL, /* base_init */ |
|---|
| | 208 | NULL, /* base_finalize */ |
|---|
| | 209 | (GClassInitFunc) tmut_folder_view_class_init, /* class_init */ |
|---|
| | 210 | NULL, /* class_finalize */ |
|---|
| | 211 | NULL, /* class_data */ |
|---|
| | 212 | sizeof (TMutFolderView), |
|---|
| | 213 | 0, /* n_preallocs */ |
|---|
| | 214 | tmut_folder_view_instance_init /* instance_init */ |
|---|
| | 215 | }; |
|---|
| | 216 | |
|---|
| | 217 | type = g_type_register_static (GTK_TYPE_WINDOW, |
|---|
| | 218 | "TMutFolderView", |
|---|
| | 219 | &info, 0); |
|---|
| | 220 | } |
|---|
| | 221 | |
|---|
| | 222 | return type; |
|---|
| | 223 | } |
|---|
| | 224 | |
|---|