Adding a dialog to the settings plugin that lists all connections.
[strongswan.git] / src / frontends / maemo / src / strongswan-settings.c
1 /*
2 * Copyright (C) 2010 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
17 #include <gtk/gtk.h>
18 #include <hildon/hildon.h>
19
20 #include <string.h>
21
22 #include "strongswan-connections.h"
23
24 enum {
25 RESPONSE_NEW = 1,
26 RESPONSE_EDIT,
27 RESPONSE_DELETE
28 };
29
30 struct {
31 GtkWidget *dialog;
32 GtkWidget *list;
33 StrongswanConnections *conns;
34 } ListDialog = { 0, };
35
36 /**
37 * Creates a dialog showing a list of all connections
38 */
39 static void
40 create_list_dialog (gpointer *parent)
41 {
42 GtkWidget *dialog = gtk_dialog_new_with_buttons (
43 "strongSwan Connections",
44 GTK_WINDOW (parent),
45 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
46 GTK_STOCK_NEW,
47 RESPONSE_NEW,
48 GTK_STOCK_EDIT,
49 RESPONSE_EDIT,
50 GTK_STOCK_DELETE,
51 RESPONSE_DELETE,
52 GTK_STOCK_CLOSE,
53 GTK_RESPONSE_OK,
54 NULL);
55 ListDialog.dialog = dialog;
56 GtkWidget *vbox = GTK_DIALOG (dialog)->vbox;
57
58 ListDialog.conns = strongswan_connections_new ();
59
60 GtkTreeModel *model = strongswan_connections_get_model (ListDialog.conns);
61 ListDialog.list = gtk_tree_view_new_with_model (model);
62 g_object_unref (model);
63
64 GtkTreeSelection *selection;
65 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ListDialog.list));
66 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
67
68 GtkTreeViewColumn *column = gtk_tree_view_column_new ();
69 strongswan_connections_setup_column_renderers (ListDialog.conns,
70 GTK_CELL_LAYOUT (column));
71 gtk_tree_view_append_column (GTK_TREE_VIEW (ListDialog.list), column);
72
73 gtk_box_pack_start (GTK_BOX (vbox),
74 ListDialog.list,
75 TRUE,
76 TRUE,
77 HILDON_MARGIN_DEFAULT);
78 gtk_widget_show_all (dialog);
79 gtk_widget_hide (dialog);
80 }
81
82
83 /**
84 * main callback for control panel plugins
85 */
86 osso_return_t execute(osso_context_t *osso, gpointer data,
87 gboolean user_activated)
88 {
89 gint response;
90
91 create_list_dialog (data);
92
93 if (!user_activated)
94 {
95 /* load state */
96 }
97
98 do
99 {
100 gchar *selected;
101 response = gtk_dialog_run (GTK_DIALOG (ListDialog.dialog));
102 switch (response)
103 {
104 case RESPONSE_NEW:
105 {
106 break;
107 }
108 case RESPONSE_EDIT:
109 {
110 break;
111 }
112 case RESPONSE_DELETE:
113 {
114 break;
115 }
116 default:
117 break;
118 }
119 }
120 while (response > 0);
121
122 gtk_widget_destroy (ListDialog.dialog);
123 g_object_unref (ListDialog.conns);
124 return OSSO_OK;
125 }
126
127 /**
128 * callback called in case state has to be saved
129 */
130 osso_return_t save_state(osso_context_t *osso, gpointer data)
131 {
132 /* save state */
133 return OSSO_OK;
134 }
135