forked from sqlitebrowser/sqlitebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileDialog.cpp
More file actions
72 lines (64 loc) · 2.53 KB
/
FileDialog.cpp
File metadata and controls
72 lines (64 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "FileDialog.h"
#include "Settings.h"
QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, const QString &filter, QString *selectedFilter, Options options)
{
QString result = QFileDialog::getOpenFileName(parent, caption, getFileDialogPath(), filter, selectedFilter, options);
if(!result.isEmpty())
setFileDialogPath(result);
return result;
}
QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
{
QStringList result = QFileDialog::getOpenFileNames(parent, caption, getFileDialogPath(), filter, selectedFilter, options);
if(!result.isEmpty())
{
QFileInfo path = QFileInfo(result.first());
setFileDialogPath(path.absolutePath());
}
return result;
}
QString FileDialog::getSaveFileName(QWidget* parent, const QString& caption, const QString& filter, const QString& defaultFileName, QString* selectedFilter, Options options)
{
QString dir = getFileDialogPath();
if(!defaultFileName.isEmpty())
dir += "/" + defaultFileName;
QString result = QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options);
if(!result.isEmpty())
setFileDialogPath(result);
return result;
}
QString FileDialog::getExistingDirectory(QWidget* parent, const QString& caption, Options options)
{
QString result = QFileDialog::getExistingDirectory(parent, caption, getFileDialogPath(), options);
if(!result.isEmpty())
setFileDialogPath(result);
return result;
}
QString FileDialog::getFileDialogPath()
{
switch(Settings::getValue("db", "savedefaultlocation").toInt())
{
case 0: // Remember last location
case 2: // Remember last location for current session only
return Settings::getValue("db", "lastlocation").toString();
case 1: // Always use this locations
return Settings::getValue("db", "defaultlocation").toString();
default:
return "";
}
}
void FileDialog::setFileDialogPath(const QString& new_path)
{
QString dir = QFileInfo(new_path).absolutePath();
switch(Settings::getValue("db", "savedefaultlocation").toInt())
{
case 0: // Remember last location
Settings::setValue("db", "lastlocation", dir);
break;
case 2: // Remember last location for current session only
Settings::setValue("db", "lastlocation", dir, true);
break;
case 1: // Always use this locations
break; // Do nothing
}
}