Helper methods added to StrongSwanConnections to easily show connections in a list...
authorTobias Brunner <tobias@strongswan.org>
Fri, 4 Jun 2010 12:11:24 +0000 (14:11 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 14 Oct 2010 15:36:17 +0000 (17:36 +0200)
src/frontends/maemo/src/strongswan-connections.c
src/frontends/maemo/src/strongswan-connections.h

index 9378101..3f152c2 100644 (file)
@@ -31,6 +31,7 @@ struct _StrongswanConnectionsPrivate
        gchar *path;
        GnomeVFSMonitorHandle *monitor;
        GHashTable *connections;
+       GtkTreeModel *model;
 };
 
 G_DEFINE_TYPE (StrongswanConnections, strongswan_connections, G_TYPE_OBJECT);
@@ -39,6 +40,8 @@ static void
 strongswan_connections_load_connections (StrongswanConnections *connections)
 {
        StrongswanConnectionsPrivate *priv = connections->priv;
+       GHashTableIter iter;
+       gpointer key, value;
        gchar **groups;
        guint i;
 
@@ -57,6 +60,17 @@ strongswan_connections_load_connections (StrongswanConnections *connections)
                }
        }
        g_strfreev (groups);
+
+       gtk_list_store_clear (GTK_LIST_STORE (priv->model));
+       g_hash_table_iter_init (&iter, priv->connections);
+       while (g_hash_table_iter_next (&iter, &key, &value))
+       {
+               gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->model),
+                                                                                  NULL,
+                                                                                  -1,
+                                                                                  0, key,
+                                                                                  -1);
+       }
 }
 
 static void
@@ -123,6 +137,12 @@ strongswan_connections_init (StrongswanConnections *connections)
                                                                                           g_free,
                                                                                           g_object_unref);
 
+       priv->model = GTK_TREE_MODEL (gtk_list_store_new (2,
+                                                                                                         G_TYPE_STRING,
+                                                                                                         G_TYPE_STRING));
+       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->model),
+                                                                                 0,
+                                                                                 GTK_SORT_ASCENDING);
 }
 
 static void
@@ -162,6 +182,11 @@ strongswan_connections_dispose (GObject *object)
        g_return_if_fail (STRONGSWAN_IS_CONNECTIONS (object));
        priv = STRONGSWAN_CONNECTIONS (object)->priv;
 
+       if (priv->model)
+       {
+               priv->model = (g_object_unref (priv->model), NULL);
+       }
+
        G_OBJECT_CLASS (strongswan_connections_parent_class)->dispose (object);
 }
 
@@ -193,6 +218,27 @@ strongswan_connections_class_init (StrongswanConnectionsClass *klass)
        g_type_class_add_private (klass, sizeof (StrongswanConnectionsPrivate));
 }
 
+GtkTreeModel *
+strongswan_connections_get_model (StrongswanConnections *self)
+{
+       StrongswanConnectionsPrivate *priv = self->priv;
+       return g_object_ref (priv->model);
+}
+
+void
+strongswan_connections_setup_column_renderers (StrongswanConnections *self,
+                                                                                          GtkCellLayout *layout)
+{
+       GtkCellRenderer *renderer;
+       renderer = gtk_cell_renderer_text_new ();
+       gtk_cell_layout_pack_start (layout,
+                                                               renderer,
+                                                               TRUE);
+       gtk_cell_layout_add_attribute (layout,
+                                                                  renderer,
+                                                                  "text", 0);
+}
+
 StrongswanConnections *
 strongswan_connections_new (void)
 {
index 6a9f557..ff75341 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef __STRONGSWAN_CONNECTIONS_H__
 #define __STRONGSWAN_CONNECTIONS_H__
 
+#include <gtk/gtk.h>
+
 #include "strongswan-connection.h"
 
 G_BEGIN_DECLS
@@ -47,6 +49,9 @@ GType strongswan_connections_get_type (void);
 
 StrongswanConnections *strongswan_connections_new (void);
 
+GtkTreeModel *strongswan_connections_get_model (StrongswanConnections *connections);
+void strongswan_connections_setup_column_renderers (StrongswanConnections *connections, GtkCellLayout *layout);
+
 StrongswanConnection *strongswan_connections_get_connection (StrongswanConnections *self, const gchar *name);
 void strongswan_connections_save_connection (StrongswanConnections *self, StrongswanConnection *conn);
 void strongswan_connections_remove_connection (StrongswanConnections *self, const gchar *name);