Fix crashing of control panel aplet, create config directory if missing
authorPali Rohár <pali.rohar@gmail.com>
Mon, 9 Jul 2012 07:41:22 +0000 (09:41 +0200)
committerPali Rohár <pali.rohar@gmail.com>
Mon, 9 Jul 2012 07:42:37 +0000 (09:42 +0200)
debian/changelog
src/usr/lib/hildon-control-panel/libcallnotify.c

index 931f21d..79687ea 100644 (file)
@@ -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 <pali.rohar@gmail.com>  Fri, 22 Jun 2012 16:06:29 +0200
+ -- Pali Rohár <pali.rohar@gmail.com>  Mon, 09 Jul 2012 09:42:11 +0200
 
 callnotify (0.2.0-2) stable; urgency=low
 
index 2696abe..5e60b96 100644 (file)
@@ -3,6 +3,8 @@
 #include <gtk/gtk.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 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;  i<strlen(fileDouble); i++)
                                if (fileDouble[i]==',')
                                        fileDouble[i] = '.';
 
-                   sldValue = g_strtod(fileDouble, NULL);
+                       sldValue = g_strtod(fileDouble, NULL);
 
-                   gtk_adjustment_set_value(adj, sldValue);
+               }
 
-                   fclose(inputFilePtr);
+               fclose(inputFilePtr);
 
-               }
+       }
 
+       gtk_adjustment_set_value(adj, sldValue);
 
        gtk_container_add(GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),     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);
+               }
 
        }