Revert back source file libcallnotify.c
[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 - Show quoted text -
18 GtkAdjustment * adj;
19 gdouble sldValue = 0.0;
20 gdouble newValue = 0.0;
21 char *fileContent;
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
54
55 FILE *inputFilePtr = fopen("/home/user/.config/CallNotify/conf.txt", "r");
56
57 if (inputFilePtr != NULL)
58 {
59
60
61    fgets(fileContent, 12,inputFilePtr);
62
63
64    if (fileContent[0]=='y')
65     hildon_check_button_set_active (GTK_BUTTON(btnVisual), TRUE);
66    if (fileContent[2]=='y')
67     hildon_check_button_set_active (GTK_BUTTON(btnVibrate) , TRUE);
68    if (fileContent[4]=='y')
69     hildon_check_button_set_active (GTK_BUTTON(btnSound), TRUE);
70
71 (char*)strtok(fileContent, ";");
72 (char*)strtok(NULL, ";");
73 (char*)strtok(NULL, ";");
74
75 fileDouble = strtok(NULL, ";");
76
77 // replace , with .
78 for (i=0;  i<strlen(fileDouble); i++)
79 if (fileDouble[i]==',')
80 fileDouble[i] = '.';
81
82    sldValue = g_strtod(fileDouble, NULL);
83
84    adj = gtk_range_get_adjustment(GTK_RANGE(slider));
85    gtk_adjustment_set_value(adj, sldValue);
86
87 }
88
89 fclose(inputFilePtr);
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(GTK_BUTTON(btnVisual)) ? 'y' : 'n';
111 b = hildon_check_button_get_active(GTK_BUTTON(btnVibrate)) ? 'y' : 'n';
112 c = hildon_check_button_get_active(GTK_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 }
136
137