* added account view widget, a listview with the current
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 20 Jul 2006 14:09:13 +0000 (14:09 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 20 Jul 2006 14:09:13 +0000 (14:09 +0000)
  accounts, and a toggle to enable/disable them.

pmo-trunk-r390

src/modest-account-view.c [new file with mode: 0644]
src/modest-account-view.h [new file with mode: 0644]

diff --git a/src/modest-account-view.c b/src/modest-account-view.c
new file mode 100644 (file)
index 0000000..e06f9b8
--- /dev/null
@@ -0,0 +1,313 @@
+/* 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.
+ */
+
+#include "modest-account-view.h"
+/* include other impl specific header files */
+
+/* 'private'/'protected' functions */
+static void                     modest_account_view_class_init    (ModestAccountViewClass *klass);
+static void                     modest_account_view_init          (ModestAccountView *obj);
+static void                     modest_account_view_finalize      (GObject *obj);
+
+
+enum _AccountViewColumns {
+       ENABLED_COLUMN,
+       NAME_COLUMN,
+       PROTO_COLUMN,
+       N_COLUMNS
+};
+typedef enum _AccountViewColumns AccountViewColumns;
+
+
+/* list my signals */
+enum {
+       /* MY_SIGNAL_1, */
+       /* MY_SIGNAL_2, */
+       LAST_SIGNAL
+};
+
+typedef struct _ModestAccountViewPrivate ModestAccountViewPrivate;
+struct _ModestAccountViewPrivate {
+       ModestAccountMgr *account_mgr;
+};
+#define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+                                                 MODEST_TYPE_ACCOUNT_VIEW, \
+                                                 ModestAccountViewPrivate))
+/* globals */
+static GtkTreeViewClass *parent_class = NULL;
+
+/* uncomment the following if you have defined any signals */
+/* static guint signals[LAST_SIGNAL] = {0}; */
+
+GType
+modest_account_view_get_type (void)
+{
+       static GType my_type = 0;
+       if (!my_type) {
+               static const GTypeInfo my_info = {
+                       sizeof(ModestAccountViewClass),
+                       NULL,           /* base init */
+                       NULL,           /* base finalize */
+                       (GClassInitFunc) modest_account_view_class_init,
+                       NULL,           /* class finalize */
+                       NULL,           /* class data */
+                       sizeof(ModestAccountView),
+                       1,              /* n_preallocs */
+                       (GInstanceInitFunc) modest_account_view_init,
+               };
+               my_type = g_type_register_static (GTK_TYPE_TREE_VIEW,
+                                                 "ModestAccountView",
+                                                 &my_info, 0);
+       }
+       return my_type;
+}
+
+static void
+modest_account_view_class_init (ModestAccountViewClass *klass)
+{
+       GObjectClass *gobject_class;
+       gobject_class = (GObjectClass*) klass;
+
+       parent_class            = g_type_class_peek_parent (klass);
+       gobject_class->finalize = modest_account_view_finalize;
+
+       g_type_class_add_private (gobject_class, sizeof(ModestAccountViewPrivate));
+
+       /* signal definitions go here, e.g.: */
+/*     signals[MY_SIGNAL_1] = */
+/*             g_signal_new ("my_signal_1",....); */
+/*     signals[MY_SIGNAL_2] = */
+/*             g_signal_new ("my_signal_2",....); */
+/*     etc. */
+}
+
+static void
+modest_account_view_init (ModestAccountView *obj)
+{
+       ModestAccountViewPrivate *priv;
+
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
+       
+       priv->account_mgr = NULL; 
+}
+
+static void
+modest_account_view_finalize (GObject *obj)
+{
+       ModestAccountViewPrivate *priv;
+
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
+       
+       if (priv->account_mgr) {
+               g_object_unref (G_OBJECT(priv->account_mgr));
+               priv->account_mgr = NULL; 
+       }
+}
+
+
+
+static void
+update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view)
+{
+       GSList *account_names, *cursor;
+       GtkListStore *model;
+       GtkTreeIter iter;
+       
+       model = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(view)));  
+       gtk_list_store_clear (model);
+
+       cursor = account_names =
+               modest_account_mgr_account_names (account_mgr, NULL);
+       
+       while (cursor) {
+               gchar    *proto, *store, *account_name;
+               gboolean enabled;
+
+               account_name = (gchar*)cursor->data;
+               
+               store        = modest_account_mgr_get_string (account_mgr,
+                                                             account_name,
+                                                             MODEST_ACCOUNT_STORE_ACCOUNT,
+                                                             FALSE, NULL);
+               if (store) {
+                       proto = modest_account_mgr_get_string (account_mgr,
+                                                              store,
+                                                              MODEST_ACCOUNT_PROTO,
+                                                              TRUE, NULL);
+                       g_free(store);
+               }
+               
+               enabled = modest_account_mgr_account_get_enabled (account_mgr,
+                                                                 account_name,
+                                                                 FALSE);
+               gtk_list_store_insert_with_values (
+                       model, NULL, 0,
+                       ENABLED_COLUMN, enabled,
+                       NAME_COLUMN,  account_name,
+                       PROTO_COLUMN, proto,
+                       -1);
+               
+               g_free (account_name);
+               g_free (proto);
+               
+               cursor = cursor->next;
+       }
+       g_slist_free (account_names);
+}
+
+
+static void
+on_account_changed (ModestAccountMgr *account_mgr,
+                   const gchar* account, const gchar* key,
+                   gboolean server_account, ModestAccountView *self)
+{
+       ModestAccountViewPrivate *priv;
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+       
+       update_account_view (account_mgr, self);
+}
+
+
+static void
+on_account_removed (ModestAccountMgr *account_mgr,
+                   const gchar* account, gboolean server_account,
+                   gpointer user_data)
+{
+       on_account_changed (account_mgr, account, NULL, server_account, user_data);
+}
+
+
+
+
+static void
+on_account_enable_toggled (GtkCellRendererToggle *cell_renderer, gchar *path,
+                          ModestAccountView *self)
+{
+       GtkTreeIter iter;
+       ModestAccountViewPrivate *priv;
+       GtkTreeModel *model;
+       gchar *account_name;
+       gboolean enabled;
+       
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+       model = gtk_tree_view_get_model (GTK_TREE_VIEW(self));
+       
+       if (!gtk_tree_model_get_iter_from_string (model, &iter, path)) {
+               g_printerr ("modest: cannot find iterator\n");
+               return;
+       }
+       
+       gtk_tree_model_get (model, &iter,
+                           ENABLED_COLUMN, &enabled,
+                           NAME_COLUMN, &account_name,
+                           -1);
+       
+       /* toggle enabled / disabled */
+       modest_account_mgr_account_set_enabled (priv->account_mgr, account_name,
+                                               FALSE, !enabled);
+       g_free (account_name);
+}
+
+
+
+
+
+
+static
+init_view (ModestAccountView *self)
+{
+       ModestAccountViewPrivate *priv;
+       GtkTreeSelection *sel;
+       GtkWidget *account_view;
+       GtkCellRenderer *renderer;
+       GtkListStore *model;
+       GtkTreeIter iter;
+
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+               
+       model = gtk_list_store_new (3,
+                                   G_TYPE_BOOLEAN, /* checkbox */
+                                   G_TYPE_STRING,  /* account name */
+                                   G_TYPE_STRING); /* account type (pop, imap,...) */
+
+       gtk_tree_view_set_model (GTK_TREE_VIEW(self), GTK_TREE_MODEL(model));
+
+       renderer = gtk_cell_renderer_toggle_new ();
+       g_object_set (G_OBJECT(renderer), "activatable", TRUE,"radio", FALSE, NULL);
+
+       g_signal_connect (G_OBJECT(renderer), "toggled",
+                         G_CALLBACK(on_account_enable_toggled),
+                         self);
+       
+       gtk_tree_view_append_column (GTK_TREE_VIEW(self),
+                                    gtk_tree_view_column_new_with_attributes (
+                                            _("Enabled"), renderer,
+                                            "active", ENABLED_COLUMN, NULL));
+       gtk_tree_view_append_column (GTK_TREE_VIEW(self),
+                                    gtk_tree_view_column_new_with_attributes (
+                                            _("Account"),
+                                            gtk_cell_renderer_text_new (),
+                                            "text", NAME_COLUMN, NULL));
+       gtk_tree_view_append_column (GTK_TREE_VIEW(self),
+                                    gtk_tree_view_column_new_with_attributes (
+                                            _("Type"),
+                                            gtk_cell_renderer_text_new (),
+                                            "text", PROTO_COLUMN, NULL));
+
+       sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(self));
+       
+       g_signal_connect (G_OBJECT(priv->account_mgr),
+                         "account_removed",
+                         G_CALLBACK(on_account_removed), self);
+       g_signal_connect (G_OBJECT(priv->account_mgr),
+                         "account_changed",
+                         G_CALLBACK(on_account_changed), self);
+}
+
+
+
+GtkWidget*
+modest_account_view_new (ModestAccountMgr *account_mgr)
+{
+       GObject *obj;
+       ModestAccountViewPrivate *priv;
+
+       g_return_val_if_fail (account_mgr, NULL);
+       
+       obj  = g_object_new(MODEST_TYPE_ACCOUNT_VIEW, NULL);
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(obj);
+
+       g_object_ref (G_OBJECT(account_mgr));
+       priv->account_mgr = account_mgr;
+
+       init_view (MODEST_ACCOUNT_VIEW (obj));
+       
+       return GTK_WIDGET(obj);
+}
+
diff --git a/src/modest-account-view.h b/src/modest-account-view.h
new file mode 100644 (file)
index 0000000..2b78bbf
--- /dev/null
@@ -0,0 +1,72 @@
+/* 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.
+ */
+
+#ifndef __MODEST_ACCOUNT_VIEW_H__
+#define __MODEST_ACCOUNT_VIEW_H__
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include "modest-account-mgr.h"
+
+G_BEGIN_DECLS
+
+/* convenience macros */
+#define MODEST_TYPE_ACCOUNT_VIEW             (modest_account_view_get_type())
+#define MODEST_ACCOUNT_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_ACCOUNT_VIEW,ModestAccountView))
+#define MODEST_ACCOUNT_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_ACCOUNT_VIEW,GtkTreeView))
+#define MODEST_IS_ACCOUNT_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_ACCOUNT_VIEW))
+#define MODEST_IS_ACCOUNT_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_ACCOUNT_VIEW))
+#define MODEST_ACCOUNT_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_ACCOUNT_VIEW,ModestAccountViewClass))
+
+typedef struct _ModestAccountView      ModestAccountView;
+typedef struct _ModestAccountViewClass ModestAccountViewClass;
+
+struct _ModestAccountView {
+        GtkTreeView parent;
+       /* insert public members, if any */
+};
+
+struct _ModestAccountViewClass {
+       GtkTreeViewClass parent_class;
+       /* insert signal callback declarations, eg. */
+       /* void (* my_event) (ModestAccountView* obj); */
+};
+
+/* member functions */
+GType        modest_account_view_get_type    (void) G_GNUC_CONST;
+
+
+
+GtkWidget*   modest_account_view_new         (ModestAccountMgr *account_mgr);
+
+G_END_DECLS
+
+#endif /* __MODEST_ACCOUNT_VIEW_H__ */
+