2696abe11a03c50a247ccfd2bc8e16adcd6d830b
[callnotify] / src / usr / lib / hildon-control-panel / libcallnotify.c
1 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
2 #include <hildon/hildon.h>
3 #include <gtk/gtk.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activated)
8 {
9         char a = 'y';
10         char b = 'y';
11         char c = 'y';
12         GtkWidget *dialog;
13         GtkWidget *btnVisual;
14         GtkWidget *btnVibrate;
15         GtkWidget *btnSound;
16         GtkWidget *slider;
17         GtkWidget *lblText;
18         GtkAdjustment * adj;
19         gdouble sldValue = 0.0;
20         gdouble newValue = 0.0;
21         char fileContent[64];
22         char *fileDouble;
23         int i;
24         gint response;
25
26         /* Create dialog with OK and Cancel buttons. Leave the separator out,
27          * as we do not have any content. */
28         dialog = gtk_dialog_new_with_buttons(
29                 "Call Notify Settings",
30                 GTK_WINDOW(data),
31                 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
32                 GTK_STOCK_OK,
33                 GTK_RESPONSE_OK,
34                 GTK_STOCK_CANCEL,
35                 GTK_RESPONSE_CANCEL,
36                 NULL);
37
38         /* ... add something to the dialog ... */
39         //btnVisual = gtk_check_button_new_with_label();
40         btnVisual = (GtkWidget*)hildon_check_button_new(HILDON_SIZE_FULLSCREEN_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
41         gtk_button_set_label (GTK_BUTTON (btnVisual), "Visual Notification");
42
43         btnVibrate = (GtkWidget*)hildon_check_button_new(HILDON_SIZE_FULLSCREEN_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
44         gtk_button_set_label (GTK_BUTTON (btnVibrate), "Vibrate Notification");
45
46         btnSound = (GtkWidget*)hildon_check_button_new(HILDON_SIZE_FULLSCREEN_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
47         gtk_button_set_label (GTK_BUTTON (btnSound), "Sound Notification");
48
49         lblText = (GtkWidget*)gtk_label_new("Please select notification interval:");
50
51
52         slider = gtk_hscale_new_with_range(0.0, 60.0, 0.1);
53         adj = gtk_range_get_adjustment(GTK_RANGE(slider));
54
55
56                 FILE *inputFilePtr = fopen("/home/user/.config/CallNotify/conf.txt", "r");
57
58                 if (inputFilePtr != NULL)
59                 {
60
61
62                     fgets(fileContent, 12,inputFilePtr);
63
64
65                     if (fileContent[0]=='y')
66                         hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnVisual), TRUE);
67                     if (fileContent[2]=='y')
68                         hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnVibrate) , TRUE);
69                     if (fileContent[4]=='y')
70                         hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnSound), TRUE);
71
72                         (char*)strtok(fileContent, ";");
73                         (char*)strtok(NULL, ";");
74                         (char*)strtok(NULL, ";");
75
76                         fileDouble = strtok(NULL, ";");
77
78                         // replace , with .
79                         for (i=0;  i<strlen(fileDouble); i++)
80                                 if (fileDouble[i]==',')
81                                         fileDouble[i] = '.';
82
83                     sldValue = g_strtod(fileDouble, NULL);
84
85                     gtk_adjustment_set_value(adj, sldValue);
86
87                     fclose(inputFilePtr);
88
89                 }
90
91
92         gtk_container_add(GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),     btnVisual);
93         gtk_container_add(GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),     btnVibrate);
94         gtk_container_add(GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),     btnSound);
95         gtk_container_add(GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),     lblText);
96         gtk_container_add(GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),     slider);
97
98         gtk_widget_show_all(dialog);
99
100         /* Wait until user finishes the dialog. */
101         response = gtk_dialog_run(GTK_DIALOG(dialog));
102
103         if (response == GTK_RESPONSE_OK)
104         {
105                 /* ... do something with the dialog stuff ... */
106                 //FILE *f_write =
107                 inputFilePtr = fopen("/home/user/.config/CallNotify/conf.txt", "w");
108
109
110                 a = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnVisual)) ? 'y' : 'n';
111                 b = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnVibrate)) ? 'y' : 'n';
112                 c = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnSound)) ? 'y' : 'n';
113
114                 newValue = gtk_adjustment_get_value(adj);
115
116
117                 fprintf(inputFilePtr, "%c;%c;%c;%.1f\n",a,b,c,newValue);
118
119                 fclose(inputFilePtr);
120
121         }
122
123         /* Free the dialog (and it's children) */
124
125         gtk_widget_destroy(GTK_WIDGET(dialog));
126
127         return OSSO_OK;
128 }
129
130 osso_return_t save_state(osso_context_t *osso, gpointer data)
131 {
132         /* ... save state ... */
133
134         return OSSO_OK;
135 }