Skip to content

Commit 2f47b82

Browse files
committed
Storing last path implemented according to received feedback
1 parent c6520ff commit 2f47b82

4 files changed

Lines changed: 15 additions & 25 deletions

File tree

gui/applicationdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void ApplicationDialog::Browse()
6464
filter);
6565

6666
if (!selectedFile.isEmpty()) {
67-
SetPath(SETTINGS_LAST_APP_PATH, selectedFile, false);
67+
SetPath(SETTINGS_LAST_APP_PATH, selectedFile);
6868
QString path(QDir::toNativeSeparators(selectedFile));
6969
mUI.mPath->setText(path);
7070
}

gui/common.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,19 @@
2626
QString GetPath(const QString &type)
2727
{
2828
QSettings settings;
29-
const QString path = settings.value(type, "").toString();
30-
if (path.isEmpty())
31-
return settings.value(SETTINGS_LAST_USED_PATH, "").toString();
29+
QString path = settings.value(type, "").toString();
30+
if (path.isEmpty()) {
31+
// if not set, fallback to last check path hoping that it will be close enough
32+
path = settings.value(SETTINGS_LAST_CHECK_PATH, "").toString();
33+
if (path.isEmpty())
34+
// if not set, return user's home directory as the best we can do for now
35+
return QDir::homePath();
36+
}
3237
return path;
3338
}
3439

35-
void SetPath(const QString &type, const QString &value, bool storeAsLastUsed /* = true */)
40+
void SetPath(const QString &type, const QString &value)
3641
{
3742
QSettings settings;
3843
settings.setValue(type, value);
39-
if (storeAsLastUsed) {
40-
// file name and especially its extension is not portable between types so strip it
41-
const QFileInfo fi(value);
42-
if (fi.isFile()) {
43-
settings.setValue(SETTINGS_LAST_USED_PATH, fi.dir().path());
44-
}
45-
else {
46-
settings.setValue(SETTINGS_LAST_USED_PATH, value);
47-
}
48-
}
4944
}

gui/common.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484

8585
#define SETTINGS_CHECKED_PLATFORM "Checked platform"
8686

87-
#define SETTINGS_LAST_USED_PATH "Last used path"
8887
#define SETTINGS_LAST_CHECK_PATH "Last check path"
8988
#define SETTINGS_LAST_PROJECT_PATH "Last project path"
9089
#define SETTINGS_LAST_RESULT_PATH "Last result path"
@@ -95,24 +94,20 @@
9594

9695
/**
9796
* @brief Obtains the path of specified type
98-
* Returns the path of specifed type if not empty. Otherwise returns
99-
* common last used path set previously by any other file dialog window.
97+
* Returns the path of specified type if not empty. Otherwise returns last check
98+
* path if valid or user's home directory.
10099
* @param type Type of path to obtain
101100
* @return Best path fo provided type
102101
*/
103102
QString GetPath(const QString &type);
104103

105104
/**
106105
* @brief Stores last used path of specified type
107-
* Stores provided path as last used path for specified type and if
108-
* @p storeAsLastUsed is enabled its directory is also set as common last used
109-
* path that will later be used to initialize the value of paths of other types.
106+
* Stores provided path as last used path for specified type.
110107
* @param type Type of the path to store
111108
* @param value Path to store
112-
* @param storeAsLastUsed Specifies if directory of that path should also be
113-
* stored as common last used path.
114109
*/
115-
void SetPath(const QString &type, const QString &value, bool storeAsLastUsed = true);
110+
void SetPath(const QString &type, const QString &value);
116111

117112
/// @}
118113
#endif

gui/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void MainWindow::DoCheckFiles(const QStringList &files)
332332
mThread->SetFiles(fileNames);
333333
QDir inf(mCurrentDirectory);
334334
const QString checkPath = inf.canonicalPath();
335-
mSettings->setValue(SETTINGS_CHECK_PATH, checkPath);
335+
SetPath(SETTINGS_LAST_CHECK_PATH, checkPath);
336336

337337
CheckLockDownUI(); // lock UI while checking
338338

0 commit comments

Comments
 (0)