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