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