Added check for existence of default directory when opening timers
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 30 May 2011 11:50:47 +0000 (14:50 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 30 May 2011 11:50:47 +0000 (14:50 +0300)
to prevent the directory save offers not being accessible by open
(open now gives /home/user too if no default directory found)

src/kitchenalertmainwindow.cpp
src/kitchenalertmainwindow.h

index 0c3194b..f5fbfa5 100644 (file)
@@ -458,7 +458,26 @@ void KitchenAlertMainWindow::saveTimer()
 
 void KitchenAlertMainWindow::loadTimer()
 {
-    QString filename = QFileDialog::getOpenFileName(this,"",defaultSaveDirectory_,tr("KitchenAlert timer files (*.kitchenalert)"));
+
+// If the default save directory does not exist use /home/user instead (as that's what the save dialog will use)
+// This avoids a situation where save directs to a folder that cannot be accessed with open...
+
+    QString startDirectory;
+
+    if (QFile(defaultSaveDirectory_).exists())
+    {
+        startDirectory = defaultSaveDirectory_;
+    }
+    else
+    {
+        startDirectory = "/home/user/";
+        qDebug () << "default save directory not found";
+    }
+
+
+ //Get the filename to open with a dialog
+
+    QString filename = QFileDialog::getOpenFileName(this,"",startDirectory,tr("KitchenAlert timer files (*.kitchenalert)"));
     if (!filename.isEmpty())
     {
 
index a2d7202..392d05b 100644 (file)
@@ -150,7 +150,7 @@ private:
 
     CurrentAlertsTableModel model_; /*! The model that stores the alerts */
 
-    const QString defaultSaveDirectory_;
+    QString defaultSaveDirectory_;
 
     /*!
     Returns a QMoldelIndex pointing to the cell in the column 0 of the row that is currently selected.