948660b9da32f49a5dcfa1dbe6e2d5375fee3c64
[strongswan.git] / src / frontends / maemo / src / strongswan-status.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/hildon.h>
17
18 #define STRONGSWAN_STATUS_GET_PRIVATE(object) \
19 (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
20 STRONGSWAN_TYPE_STATUS, \
21 StrongswanStatusPrivate))
22
23 #define ICON_SIZE_STATUS 18
24 #define ICON_SIZE_BUTTON 48
25
26 struct _StrongswanStatusPrivate
27 {
28 struct {
29 GdkPixbuf *status_open;
30 GdkPixbuf *status_close;
31 GdkPixbuf *button_open;
32 GdkPixbuf *button_close;
33 } icons;
34
35 GtkWidget *button;
36 GtkWidget *image;
37 };
38
39 HD_DEFINE_PLUGIN_MODULE_EXTENDED (StrongswanStatus, strongswan_status, \
40 HD_TYPE_STATUS_MENU_ITEM, {}, { \
41 strongswan_connection_register (G_TYPE_MODULE (plugin)); \
42 strongswan_connections_register (G_TYPE_MODULE (plugin)); }, {});
43
44 static void
45 button_clicked (HildonButton *button, StrongswanStatus *plugin)
46 {
47 StrongswanStatusPrivate *priv = plugin->priv;
48 }
49
50 static void
51 load_icons (StrongswanStatusPrivate *priv)
52 {
53 GtkIconTheme *theme = gtk_icon_theme_get_default ();
54 priv->icons.status_open = gtk_icon_theme_load_icon (theme,
55 "strongswan_lock_open",
56 ICON_SIZE_STATUS, GTK_ICON_LOOKUP_NO_SVG, NULL);
57 priv->icons.status_close = gtk_icon_theme_load_icon (theme,
58 "strongswan_lock_close",
59 ICON_SIZE_STATUS, GTK_ICON_LOOKUP_NO_SVG, NULL);
60 priv->icons.button_open = gtk_icon_theme_load_icon (theme,
61 "strongswan_lock_open",
62 ICON_SIZE_BUTTON, GTK_ICON_LOOKUP_NO_SVG, NULL);
63 priv->icons.button_close = gtk_icon_theme_load_icon (theme,
64 "strongswan_lock_close",
65 ICON_SIZE_BUTTON, GTK_ICON_LOOKUP_NO_SVG, NULL);
66 }
67
68 static void
69 strongswan_status_init (StrongswanStatus *plugin)
70 {
71 StrongswanStatusPrivate *priv = STRONGSWAN_STATUS_GET_PRIVATE (plugin);
72 plugin->priv = priv;
73
74 load_icons(priv);
75
76 hd_status_plugin_item_set_status_area_icon (HD_STATUS_PLUGIN_ITEM (plugin),
77 priv->icons.status_open);
78
79 GtkWidget *button = hildon_button_new_with_text (
80 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,
81 HILDON_BUTTON_ARRANGEMENT_VERTICAL,
82 "strongSwan VPN", "Not connected");
83 hildon_button_set_style (HILDON_BUTTON (button),
84 HILDON_BUTTON_STYLE_PICKER);
85 priv->button = button;
86 gtk_container_add (GTK_CONTAINER (plugin), button);
87
88 GtkWidget *image = gtk_image_new_from_pixbuf (priv->icons.button_open);
89 priv->image = image;
90 hildon_button_set_image (HILDON_BUTTON (button), image);
91
92 gtk_button_set_alignment (GTK_BUTTON (button), 0.0, 0.5);
93
94 g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), plugin);
95
96 gtk_widget_show_all (GTK_WIDGET (plugin));
97 }
98
99 static void
100 strongswan_status_dispose (GObject *object)
101 {
102 StrongswanStatusPrivate *priv = STRONGSWAN_STATUS (object)->priv;
103 if (priv->icons.status_open)
104 {
105 g_object_unref (priv->icons.status_open);
106 priv->icons.status_open = NULL;
107 }
108 if (priv->icons.status_close)
109 {
110 g_object_unref (priv->icons.status_close);
111 priv->icons.status_close = NULL;
112 }
113 if (priv->icons.button_open)
114 {
115 g_object_unref (priv->icons.button_open);
116 priv->icons.button_open = NULL;
117 }
118 if (priv->icons.button_close)
119 {
120 g_object_unref (priv->icons.button_close);
121 priv->icons.button_close = NULL;
122 }
123 G_OBJECT_CLASS (strongswan_status_parent_class)->dispose (object);
124 }
125
126 static void
127 strongswan_status_finalize (GObject *object)
128 {
129 StrongswanStatusPrivate *priv = STRONGSWAN_STATUS (object)->priv;
130 G_OBJECT_CLASS (strongswan_status_parent_class)->finalize (object);
131 }
132
133 static void
134 strongswan_status_class_finalize (StrongswanStatusClass *klass)
135 {
136 }
137
138 static void
139 strongswan_status_class_init (StrongswanStatusClass *klass)
140 {
141 GObjectClass *object_class = G_OBJECT_CLASS (klass);
142
143 object_class->dispose = strongswan_status_dispose;
144 object_class->finalize = strongswan_status_finalize;
145
146 g_type_class_add_private (klass, sizeof (StrongswanStatusPrivate));
147 }