2 * Copyright (C) 2010 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
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>.
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
16 #include <hildon/hildon.h>
18 #include "strongswan-status.h"
19 #include "strongswan-connections.h"
21 #define STRONGSWAN_STATUS_GET_PRIVATE(object) \
22 (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
23 STRONGSWAN_TYPE_STATUS, \
24 StrongswanStatusPrivate))
26 #define ICON_SIZE_STATUS 18
27 #define ICON_SIZE_BUTTON 48
29 struct _StrongswanStatusPrivate
32 GdkPixbuf
*status_open
;
33 GdkPixbuf
*status_close
;
34 GdkPixbuf
*button_open
;
35 GdkPixbuf
*button_close
;
44 StrongswanConnections
*conns
;
49 HD_DEFINE_PLUGIN_MODULE_EXTENDED (StrongswanStatus
, strongswan_status
, \
50 HD_TYPE_STATUS_MENU_ITEM
, {}, { \
51 strongswan_connection_register (G_TYPE_MODULE (plugin
)); \
52 strongswan_connections_register (G_TYPE_MODULE (plugin
)); }, {});
55 dialog_response (GtkDialog
*dialog
, gint response_id
, StrongswanStatus
*plugin
)
57 StrongswanStatusPrivate
*priv
= plugin
->priv
;
58 g_object_unref (priv
->dialog
);
63 connect_clicked (HildonButton
*button
, StrongswanStatus
*plugin
)
65 StrongswanStatusPrivate
*priv
= plugin
->priv
;
66 gtk_dialog_response (GTK_DIALOG (priv
->dialog
), GTK_RESPONSE_OK
);
70 disconnect_clicked (HildonButton
*button
, StrongswanStatus
*plugin
)
72 StrongswanStatusPrivate
*priv
= plugin
->priv
;
73 gtk_dialog_response (GTK_DIALOG (priv
->dialog
), GTK_RESPONSE_OK
);
77 button_clicked (HildonButton
*button
, StrongswanStatus
*plugin
)
79 StrongswanStatusPrivate
*priv
= plugin
->priv
;
81 priv
->dialog
= gtk_dialog_new ();
82 gtk_window_set_title (GTK_WINDOW (priv
->dialog
), "strongSwan VPN");
83 g_signal_connect (priv
->dialog
, "response",
84 G_CALLBACK (dialog_response
), plugin
);
86 GtkWidget
*vbox
= GTK_DIALOG (priv
->dialog
)->vbox
;
91 GtkWidget
*hbox
= gtk_hbox_new (FALSE
, 0);
93 GtkWidget
*button
= hildon_button_new_with_text (
94 HILDON_SIZE_FINGER_HEIGHT
|
95 HILDON_SIZE_AUTO_WIDTH
,
96 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL
,
97 "Disconnect", priv
->current
);
98 hildon_button_set_style (HILDON_BUTTON (button
),
99 HILDON_BUTTON_STYLE_PICKER
);
100 g_signal_connect (button
, "clicked", G_CALLBACK (disconnect_clicked
),
102 gtk_box_pack_start (GTK_BOX (hbox
), button
, TRUE
, TRUE
, 0);
103 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
107 /* unconnected case */
108 GtkWidget
*hbox
= gtk_hbox_new (FALSE
, 0);
110 GtkWidget
*button
= hildon_picker_button_new (
111 HILDON_SIZE_FINGER_HEIGHT
|
112 HILDON_SIZE_AUTO_WIDTH
,
113 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL
);
114 hildon_button_set_title (HILDON_BUTTON (button
), "Connection:");
115 gtk_box_pack_start (GTK_BOX (hbox
), button
, TRUE
, TRUE
, 0);
117 GtkWidget
*selector
= hildon_touch_selector_new ();
118 priv
->selector
= selector
;
119 GtkTreeModel
*model
= strongswan_connections_get_model (priv
->conns
);
120 hildon_touch_selector_append_text_column (
121 HILDON_TOUCH_SELECTOR (selector
),
124 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button
),
125 HILDON_TOUCH_SELECTOR (selector
));
126 g_object_unref (model
);
128 button
= hildon_button_new_with_text (
129 HILDON_SIZE_FINGER_HEIGHT
|
130 HILDON_SIZE_AUTO_WIDTH
,
131 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL
,
133 gtk_box_pack_start (GTK_BOX (hbox
), button
, FALSE
, FALSE
, 0);
134 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
135 g_signal_connect (button
, "clicked", G_CALLBACK (connect_clicked
),
139 gtk_widget_show_all (priv
->dialog
);
143 load_icons (StrongswanStatusPrivate
*priv
)
145 GtkIconTheme
*theme
= gtk_icon_theme_get_default ();
146 priv
->icons
.status_open
= gtk_icon_theme_load_icon (theme
,
147 "strongswan_lock_open",
148 ICON_SIZE_STATUS
, GTK_ICON_LOOKUP_NO_SVG
, NULL
);
149 priv
->icons
.status_close
= gtk_icon_theme_load_icon (theme
,
150 "strongswan_lock_close",
151 ICON_SIZE_STATUS
, GTK_ICON_LOOKUP_NO_SVG
, NULL
);
152 priv
->icons
.button_open
= gtk_icon_theme_load_icon (theme
,
153 "strongswan_lock_open",
154 ICON_SIZE_BUTTON
, GTK_ICON_LOOKUP_NO_SVG
, NULL
);
155 priv
->icons
.button_close
= gtk_icon_theme_load_icon (theme
,
156 "strongswan_lock_close",
157 ICON_SIZE_BUTTON
, GTK_ICON_LOOKUP_NO_SVG
, NULL
);
161 strongswan_status_init (StrongswanStatus
*plugin
)
163 StrongswanStatusPrivate
*priv
= STRONGSWAN_STATUS_GET_PRIVATE (plugin
);
166 priv
->conns
= strongswan_connections_new ();
170 hd_status_plugin_item_set_status_area_icon (HD_STATUS_PLUGIN_ITEM (plugin
),
171 priv
->icons
.status_open
);
173 GtkWidget
*button
= hildon_button_new_with_text (
174 HILDON_SIZE_FINGER_HEIGHT
| HILDON_SIZE_AUTO_WIDTH
,
175 HILDON_BUTTON_ARRANGEMENT_VERTICAL
,
176 "strongSwan VPN", "Not connected");
177 hildon_button_set_style (HILDON_BUTTON (button
),
178 HILDON_BUTTON_STYLE_PICKER
);
179 priv
->button
= button
;
180 gtk_container_add (GTK_CONTAINER (plugin
), button
);
182 GtkWidget
*image
= gtk_image_new_from_pixbuf (priv
->icons
.button_open
);
184 hildon_button_set_image (HILDON_BUTTON (button
), image
);
186 gtk_button_set_alignment (GTK_BUTTON (button
), 0.0, 0.5);
188 g_signal_connect (button
, "clicked", G_CALLBACK (button_clicked
), plugin
);
190 gtk_widget_show_all (GTK_WIDGET (plugin
));
194 strongswan_status_dispose (GObject
*object
)
196 StrongswanStatusPrivate
*priv
= STRONGSWAN_STATUS (object
)->priv
;
199 priv
->conns
= (g_object_unref (priv
->conns
), NULL
);
203 priv
->dialog
= (g_object_unref (priv
->dialog
), NULL
);
205 if (priv
->icons
.status_open
)
207 g_object_unref (priv
->icons
.status_open
);
208 priv
->icons
.status_open
= NULL
;
210 if (priv
->icons
.status_close
)
212 g_object_unref (priv
->icons
.status_close
);
213 priv
->icons
.status_close
= NULL
;
215 if (priv
->icons
.button_open
)
217 g_object_unref (priv
->icons
.button_open
);
218 priv
->icons
.button_open
= NULL
;
220 if (priv
->icons
.button_close
)
222 g_object_unref (priv
->icons
.button_close
);
223 priv
->icons
.button_close
= NULL
;
225 G_OBJECT_CLASS (strongswan_status_parent_class
)->dispose (object
);
229 strongswan_status_finalize (GObject
*object
)
231 StrongswanStatusPrivate
*priv
= STRONGSWAN_STATUS (object
)->priv
;
232 priv
->current
= (g_free (priv
->current
), NULL
);
233 G_OBJECT_CLASS (strongswan_status_parent_class
)->finalize (object
);
237 strongswan_status_class_finalize (StrongswanStatusClass
*klass
)
242 strongswan_status_class_init (StrongswanStatusClass
*klass
)
244 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
246 object_class
->dispose
= strongswan_status_dispose
;
247 object_class
->finalize
= strongswan_status_finalize
;
249 g_type_class_add_private (klass
, sizeof (StrongswanStatusPrivate
));