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 #define STRONGSWAN_STATUS_GET_PRIVATE(object) \
19 (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
20 STRONGSWAN_TYPE_STATUS, \
21 StrongswanStatusPrivate))
23 #define ICON_SIZE_STATUS 18
24 #define ICON_SIZE_BUTTON 48
26 struct _StrongswanStatusPrivate
29 GdkPixbuf
*status_open
;
30 GdkPixbuf
*status_close
;
31 GdkPixbuf
*button_open
;
32 GdkPixbuf
*button_close
;
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
)); }, {});
45 button_clicked (HildonButton
*button
, StrongswanStatus
*plugin
)
47 StrongswanStatusPrivate
*priv
= plugin
->priv
;
51 load_icons (StrongswanStatusPrivate
*priv
)
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
);
69 strongswan_status_init (StrongswanStatus
*plugin
)
71 StrongswanStatusPrivate
*priv
= STRONGSWAN_STATUS_GET_PRIVATE (plugin
);
76 hd_status_plugin_item_set_status_area_icon (HD_STATUS_PLUGIN_ITEM (plugin
),
77 priv
->icons
.status_open
);
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
);
88 GtkWidget
*image
= gtk_image_new_from_pixbuf (priv
->icons
.button_open
);
90 hildon_button_set_image (HILDON_BUTTON (button
), image
);
92 gtk_button_set_alignment (GTK_BUTTON (button
), 0.0, 0.5);
94 g_signal_connect (button
, "clicked", G_CALLBACK (button_clicked
), plugin
);
96 gtk_widget_show_all (GTK_WIDGET (plugin
));
100 strongswan_status_dispose (GObject
*object
)
102 StrongswanStatusPrivate
*priv
= STRONGSWAN_STATUS (object
)->priv
;
103 if (priv
->icons
.status_open
)
105 g_object_unref (priv
->icons
.status_open
);
106 priv
->icons
.status_open
= NULL
;
108 if (priv
->icons
.status_close
)
110 g_object_unref (priv
->icons
.status_close
);
111 priv
->icons
.status_close
= NULL
;
113 if (priv
->icons
.button_open
)
115 g_object_unref (priv
->icons
.button_open
);
116 priv
->icons
.button_open
= NULL
;
118 if (priv
->icons
.button_close
)
120 g_object_unref (priv
->icons
.button_close
);
121 priv
->icons
.button_close
= NULL
;
123 G_OBJECT_CLASS (strongswan_status_parent_class
)->dispose (object
);
127 strongswan_status_finalize (GObject
*object
)
129 StrongswanStatusPrivate
*priv
= STRONGSWAN_STATUS (object
)->priv
;
130 G_OBJECT_CLASS (strongswan_status_parent_class
)->finalize (object
);
134 strongswan_status_class_finalize (StrongswanStatusClass
*klass
)
139 strongswan_status_class_init (StrongswanStatusClass
*klass
)
141 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
143 object_class
->dispose
= strongswan_status_dispose
;
144 object_class
->finalize
= strongswan_status_finalize
;
146 g_type_class_add_private (klass
, sizeof (StrongswanStatusPrivate
));