Storing last path implemented according to received feedback

This commit is contained in:
Mateusz Pusz 2013-02-17 19:59:16 +01:00
parent c6520ffafe
commit 2f47b82090
4 changed files with 15 additions and 25 deletions

View File

@ -64,7 +64,7 @@ void ApplicationDialog::Browse()
filter); filter);
if (!selectedFile.isEmpty()) { if (!selectedFile.isEmpty()) {
SetPath(SETTINGS_LAST_APP_PATH, selectedFile, false); SetPath(SETTINGS_LAST_APP_PATH, selectedFile);
QString path(QDir::toNativeSeparators(selectedFile)); QString path(QDir::toNativeSeparators(selectedFile));
mUI.mPath->setText(path); mUI.mPath->setText(path);
} }

View File

@ -26,24 +26,19 @@
QString GetPath(const QString &type) QString GetPath(const QString &type)
{ {
QSettings settings; QSettings settings;
const QString path = settings.value(type, "").toString(); QString path = settings.value(type, "").toString();
if (path.isEmpty()) if (path.isEmpty()) {
return settings.value(SETTINGS_LAST_USED_PATH, "").toString(); // if not set, fallback to last check path hoping that it will be close enough
path = settings.value(SETTINGS_LAST_CHECK_PATH, "").toString();
if (path.isEmpty())
// if not set, return user's home directory as the best we can do for now
return QDir::homePath();
}
return path; return path;
} }
void SetPath(const QString &type, const QString &value, bool storeAsLastUsed /* = true */) void SetPath(const QString &type, const QString &value)
{ {
QSettings settings; QSettings settings;
settings.setValue(type, value); settings.setValue(type, value);
if (storeAsLastUsed) {
// file name and especially its extension is not portable between types so strip it
const QFileInfo fi(value);
if (fi.isFile()) {
settings.setValue(SETTINGS_LAST_USED_PATH, fi.dir().path());
}
else {
settings.setValue(SETTINGS_LAST_USED_PATH, value);
}
}
} }

View File

@ -84,7 +84,6 @@
#define SETTINGS_CHECKED_PLATFORM "Checked platform" #define SETTINGS_CHECKED_PLATFORM "Checked platform"
#define SETTINGS_LAST_USED_PATH "Last used path"
#define SETTINGS_LAST_CHECK_PATH "Last check path" #define SETTINGS_LAST_CHECK_PATH "Last check path"
#define SETTINGS_LAST_PROJECT_PATH "Last project path" #define SETTINGS_LAST_PROJECT_PATH "Last project path"
#define SETTINGS_LAST_RESULT_PATH "Last result path" #define SETTINGS_LAST_RESULT_PATH "Last result path"
@ -95,8 +94,8 @@
/** /**
* @brief Obtains the path of specified type * @brief Obtains the path of specified type
* Returns the path of specifed type if not empty. Otherwise returns * Returns the path of specified type if not empty. Otherwise returns last check
* common last used path set previously by any other file dialog window. * path if valid or user's home directory.
* @param type Type of path to obtain * @param type Type of path to obtain
* @return Best path fo provided type * @return Best path fo provided type
*/ */
@ -104,15 +103,11 @@ QString GetPath(const QString &type);
/** /**
* @brief Stores last used path of specified type * @brief Stores last used path of specified type
* Stores provided path as last used path for specified type and if * Stores provided path as last used path for specified type.
* @p storeAsLastUsed is enabled its directory is also set as common last used
* path that will later be used to initialize the value of paths of other types.
* @param type Type of the path to store * @param type Type of the path to store
* @param value Path to store * @param value Path to store
* @param storeAsLastUsed Specifies if directory of that path should also be
* stored as common last used path.
*/ */
void SetPath(const QString &type, const QString &value, bool storeAsLastUsed = true); void SetPath(const QString &type, const QString &value);
/// @} /// @}
#endif #endif

View File

@ -332,7 +332,7 @@ void MainWindow::DoCheckFiles(const QStringList &files)
mThread->SetFiles(fileNames); mThread->SetFiles(fileNames);
QDir inf(mCurrentDirectory); QDir inf(mCurrentDirectory);
const QString checkPath = inf.canonicalPath(); const QString checkPath = inf.canonicalPath();
mSettings->setValue(SETTINGS_CHECK_PATH, checkPath); SetPath(SETTINGS_LAST_CHECK_PATH, checkPath);
CheckLockDownUI(); // lock UI while checking CheckLockDownUI(); // lock UI while checking