|
1 | 1 | #include "FileDialog.h" |
2 | 2 | #include "Settings.h" |
3 | 3 |
|
4 | | -QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, const QString &filter, QString *selectedFilter, Options options) |
| 4 | +QString FileDialog::getOpenFileName(const FileDialogTypes dialogType, QWidget* parent, const QString& caption, const QString &filter, QString *selectedFilter, Options options) |
5 | 5 | { |
6 | | - QString result = QFileDialog::getOpenFileName(parent, caption, getFileDialogPath(), filter, selectedFilter, options); |
| 6 | + QString result = QFileDialog::getOpenFileName(parent, caption, getFileDialogPath(dialogType), filter, selectedFilter, options); |
7 | 7 | if(!result.isEmpty()) |
8 | | - setFileDialogPath(result); |
| 8 | + setFileDialogPath(dialogType, result); |
9 | 9 | return result; |
10 | 10 | } |
11 | 11 |
|
12 | | -QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption, const QString &filter, QString *selectedFilter, QFileDialog::Options options) |
| 12 | +QStringList FileDialog::getOpenFileNames(const FileDialogTypes dialogType, QWidget *parent, const QString &caption, const QString &filter, QString *selectedFilter, QFileDialog::Options options) |
13 | 13 | { |
14 | | - QStringList result = QFileDialog::getOpenFileNames(parent, caption, getFileDialogPath(), filter, selectedFilter, options); |
| 14 | + QStringList result = QFileDialog::getOpenFileNames(parent, caption, getFileDialogPath(dialogType), filter, selectedFilter, options); |
15 | 15 | if(!result.isEmpty()) |
16 | 16 | { |
17 | 17 | QFileInfo path = QFileInfo(result.first()); |
18 | | - setFileDialogPath(path.absolutePath()); |
| 18 | + setFileDialogPath(dialogType, path.absolutePath()); |
19 | 19 | } |
20 | 20 | return result; |
21 | 21 | } |
22 | 22 |
|
23 | | -QString FileDialog::getSaveFileName(QWidget* parent, const QString& caption, const QString& filter, const QString& defaultFileName, QString* selectedFilter, Options options) |
| 23 | +QString FileDialog::getSaveFileName(const FileDialogTypes dialogType, QWidget* parent, const QString& caption, const QString& filter, const QString& defaultFileName, QString* selectedFilter, Options options) |
24 | 24 | { |
25 | | - QString dir = getFileDialogPath(); |
| 25 | + QString dir = getFileDialogPath(dialogType); |
26 | 26 | if(!defaultFileName.isEmpty()) |
27 | 27 | dir += "/" + defaultFileName; |
28 | 28 |
|
29 | 29 | QString result = QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options); |
30 | 30 | if(!result.isEmpty()) |
31 | | - setFileDialogPath(result); |
| 31 | + setFileDialogPath(dialogType, result); |
32 | 32 | return result; |
33 | 33 | } |
34 | 34 |
|
35 | | -QString FileDialog::getExistingDirectory(QWidget* parent, const QString& caption, Options options) |
| 35 | +QString FileDialog::getExistingDirectory(const FileDialogTypes dialogType, QWidget* parent, const QString& caption, Options options) |
36 | 36 | { |
37 | | - QString result = QFileDialog::getExistingDirectory(parent, caption, getFileDialogPath(), options); |
| 37 | + QString result = QFileDialog::getExistingDirectory(parent, caption, getFileDialogPath(dialogType), options); |
38 | 38 | if(!result.isEmpty()) |
39 | | - setFileDialogPath(result); |
| 39 | + setFileDialogPath(dialogType, result); |
40 | 40 | return result; |
41 | 41 | } |
42 | 42 |
|
43 | | -QString FileDialog::getFileDialogPath() |
| 43 | +QString FileDialog::getFileDialogPath(const FileDialogTypes dialogType) |
44 | 44 | { |
45 | 45 | switch(Settings::getValue("db", "savedefaultlocation").toInt()) |
46 | 46 | { |
47 | 47 | case 0: // Remember last location |
48 | | - case 2: // Remember last location for current session only |
49 | | - return Settings::getValue("db", "lastlocation").toString(); |
| 48 | + case 2: { // Remember last location for current session only |
| 49 | + QHash<QString, QVariant> lastLocations = Settings::getValue("db", "lastlocations").toHash(); |
| 50 | + |
| 51 | + return lastLocations[QString(dialogType)].toString(); |
| 52 | + } |
50 | 53 | case 1: // Always use this locations |
51 | 54 | return Settings::getValue("db", "defaultlocation").toString(); |
52 | 55 | default: |
53 | 56 | return ""; |
54 | 57 | } |
55 | 58 | } |
56 | 59 |
|
57 | | -void FileDialog::setFileDialogPath(const QString& new_path) |
| 60 | +void FileDialog::setFileDialogPath(const FileDialogTypes dialogType, const QString& new_path) |
58 | 61 | { |
59 | 62 | QString dir = QFileInfo(new_path).absolutePath(); |
| 63 | + QHash<QString, QVariant> lastLocations = Settings::getValue("db", "lastlocations").toHash(); |
| 64 | + |
| 65 | + lastLocations[QString(dialogType)] = dir; |
60 | 66 |
|
61 | 67 | switch(Settings::getValue("db", "savedefaultlocation").toInt()) |
62 | 68 | { |
63 | 69 | case 0: // Remember last location |
64 | | - Settings::setValue("db", "lastlocation", dir); |
| 70 | + Settings::setValue("db", "lastlocations", lastLocations); |
65 | 71 | break; |
66 | 72 | case 2: // Remember last location for current session only |
67 | | - Settings::setValue("db", "lastlocation", dir, true); |
| 73 | + Settings::setValue("db", "lastlocations", lastLocations, true); |
68 | 74 | break; |
69 | 75 | case 1: // Always use this locations |
70 | 76 | break; // Do nothing |
|
0 commit comments