3905d3553be6a1b144db55c0f284f05831e623e4
[azimuth] / src / controlpanel-applet.c
1 /*
2  * controlpanel-applet.c.c - Source for Azimuth's control panel applet
3  * Copyright (C) 2010 Collabora
4  * @author Alban Crequy <alban.crequy@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include <libintl.h>
22 #include <libosso.h>
23 #include <gconf/gconf-client.h>
24 #include <hildon/hildon.h>
25 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
26
27 #include "azimuth-gconf.h"
28
29 static GtkWidget* button_enabled = NULL;
30 static GConfClient *gconf_client;
31
32 static void
33 enabled_toggled (HildonCheckButton *button, gpointer user_data)
34 {
35   gboolean active;
36
37   active = hildon_check_button_get_active (button);
38   if (active)
39     /* TODO: unblur other widgets */
40     g_debug ("Publishing position is enabled");
41   else
42     /* TODO: blur other widgets */
43     g_debug ("Publishing position is disabled");
44 }
45
46 static GtkWidget*
47 create_main_dialog (gpointer window, osso_context_t *osso)
48 {
49   GtkWidget *dialog;
50   GtkWidget *bSave;
51   gboolean enabled;
52
53   dialog = g_object_new (GTK_TYPE_DIALOG,
54       "transient-for", GTK_WINDOW (window),
55       "destroy-with-parent", TRUE,
56       "resizable", TRUE,
57       "has-separator", FALSE,
58       "modal", TRUE,
59       NULL);
60   gtk_window_set_title (GTK_WINDOW (dialog),
61       "Publish location");
62
63   bSave = gtk_dialog_add_button (GTK_DIALOG (dialog),
64       dgettext ("hildon-libs", "wdgt_bd_save"),
65       GTK_RESPONSE_OK);
66
67   button_enabled = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT |
68       HILDON_SIZE_AUTO_WIDTH);
69   gtk_button_set_label (GTK_BUTTON (button_enabled),
70       "Enable Position Publishing");
71   g_signal_connect (button_enabled, "toggled", G_CALLBACK (enabled_toggled),
72       NULL);
73   enabled = gconf_client_get_bool (gconf_client, AZIMUTH_GCONF_KEY_ENABLED,
74       NULL);
75   hildon_check_button_set_active (HILDON_CHECK_BUTTON (button_enabled),
76       enabled);
77
78   gtk_box_pack_end (GTK_BOX (GTK_DIALOG(dialog)->vbox), button_enabled, FALSE,
79       FALSE, 0);
80
81   gtk_widget_show_all (dialog);
82
83   return dialog;
84 }
85
86 static void
87 save (void)
88 {
89   gboolean enabled;
90
91   enabled = hildon_check_button_get_active (HILDON_CHECK_BUTTON (
92         button_enabled));
93   gconf_client_set_bool (gconf_client, AZIMUTH_GCONF_KEY_ENABLED, enabled,
94       NULL);
95 }
96
97 osso_return_t
98 execute (osso_context_t *osso, gpointer data,
99     gboolean user_activated)
100 {
101   GtkWidget *dialog;
102   gint ret;
103
104   gconf_client = gconf_client_get_default ();
105
106   dialog = create_main_dialog (data, osso);
107
108   ret = gtk_dialog_run (GTK_DIALOG (dialog));
109
110   if (ret == GTK_RESPONSE_OK)
111     save ();
112
113   gtk_widget_destroy (dialog);
114
115   g_object_unref (gconf_client);
116   gconf_client = NULL;
117
118   return OSSO_OK;
119 }