From 64368f5551857764187e4c7a5212c76067d2410c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Mon, 30 May 2011 14:50:47 +0300 Subject: [PATCH] Added check for existence of default directory when opening timers 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 | 21 ++++++++++++++++++++- src/kitchenalertmainwindow.h | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/kitchenalertmainwindow.cpp b/src/kitchenalertmainwindow.cpp index 0c3194b..f5fbfa5 100644 --- a/src/kitchenalertmainwindow.cpp +++ b/src/kitchenalertmainwindow.cpp @@ -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()) { diff --git a/src/kitchenalertmainwindow.h b/src/kitchenalertmainwindow.h index a2d7202..392d05b 100644 --- a/src/kitchenalertmainwindow.h +++ b/src/kitchenalertmainwindow.h @@ -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. -- 1.7.9.5