From: Pali Rohár Date: Mon, 9 Jul 2012 07:41:22 +0000 (+0200) Subject: Fix crashing of control panel aplet, create config directory if missing X-Git-Url: http://git.maemo.org/git/?p=callnotify;a=commitdiff_plain;h=cd0ba53e811853e524a7f86acdf153d5fa9f8407 Fix crashing of control panel aplet, create config directory if missing --- diff --git a/debian/changelog b/debian/changelog index 931f21d..79687ea 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,8 +5,9 @@ callnotify (0.3.0-1) stable; urgency=low * Use playbin2 for playing sound files * Use python dbus module for dbus method calls * Respect profile settings (silent profile, disabled vibrations) + * Fix crashing of control panel aplet, create config directory if missing - -- Pali Rohár Fri, 22 Jun 2012 16:06:29 +0200 + -- Pali Rohár Mon, 09 Jul 2012 09:42:11 +0200 callnotify (0.2.0-2) stable; urgency=low diff --git a/src/usr/lib/hildon-control-panel/libcallnotify.c b/src/usr/lib/hildon-control-panel/libcallnotify.c index 2696abe..5e60b96 100644 --- a/src/usr/lib/hildon-control-panel/libcallnotify.c +++ b/src/usr/lib/hildon-control-panel/libcallnotify.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activated) { @@ -22,6 +24,7 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat char *fileDouble; int i; gint response; + FILE *inputFilePtr; /* Create dialog with OK and Cancel buttons. Leave the separator out, * as we do not have any content. */ @@ -36,7 +39,6 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat NULL); /* ... add something to the dialog ... */ - //btnVisual = gtk_check_button_new_with_label(); btnVisual = (GtkWidget*)hildon_check_button_new(HILDON_SIZE_FULLSCREEN_WIDTH | HILDON_SIZE_FINGER_HEIGHT); gtk_button_set_label (GTK_BUTTON (btnVisual), "Visual Notification"); @@ -53,41 +55,44 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat adj = gtk_range_get_adjustment(GTK_RANGE(slider)); - FILE *inputFilePtr = fopen("/home/user/.config/CallNotify/conf.txt", "r"); + inputFilePtr = fopen("/home/user/.config/CallNotify/conf.txt", "r"); - if (inputFilePtr != NULL) - { + if (inputFilePtr != NULL) + { + fgets(fileContent, 12,inputFilePtr); - fgets(fileContent, 12,inputFilePtr); + if (fileContent[0]=='y') + hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnVisual), TRUE); + if (fileContent[2]=='y') + hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnVibrate) , TRUE); + if (fileContent[4]=='y') + hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnSound), TRUE); - if (fileContent[0]=='y') - hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnVisual), TRUE); - if (fileContent[2]=='y') - hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnVibrate) , TRUE); - if (fileContent[4]=='y') - hildon_check_button_set_active (HILDON_CHECK_BUTTON(btnSound), TRUE); + (char*)strtok(fileContent, ";"); + (char*)strtok(NULL, ";"); + (char*)strtok(NULL, ";"); - (char*)strtok(fileContent, ";"); - (char*)strtok(NULL, ";"); - (char*)strtok(NULL, ";"); + fileDouble = strtok(NULL, ";"); - fileDouble = strtok(NULL, ";"); + if (fileDouble) + { // replace , with . for (i=0; ivbox), btnVisual); gtk_container_add(GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), btnVibrate); @@ -103,20 +108,25 @@ osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activat if (response == GTK_RESPONSE_OK) { /* ... do something with the dialog stuff ... */ - //FILE *f_write = inputFilePtr = fopen("/home/user/.config/CallNotify/conf.txt", "w"); + if (inputFilePtr == NULL) + { + mkdir("/home/user/.config/CallNotify", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + inputFilePtr = fopen("/home/user/.config/CallNotify/conf.txt", "w"); + } - a = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnVisual)) ? 'y' : 'n'; - b = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnVibrate)) ? 'y' : 'n'; - c = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnSound)) ? 'y' : 'n'; - - newValue = gtk_adjustment_get_value(adj); - + if (inputFilePtr != NULL) + { + a = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnVisual)) ? 'y' : 'n'; + b = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnVibrate)) ? 'y' : 'n'; + c = hildon_check_button_get_active(HILDON_CHECK_BUTTON(btnSound)) ? 'y' : 'n'; - fprintf(inputFilePtr, "%c;%c;%c;%.1f\n",a,b,c,newValue); + newValue = gtk_adjustment_get_value(adj); - fclose(inputFilePtr); + fprintf(inputFilePtr, "%c;%c;%c;%.1f\n",a,b,c,newValue); + fclose(inputFilePtr); + } }