forked from higan-emu/higan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser-window.cpp
52 lines (44 loc) · 1.69 KB
/
browser-window.cpp
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
#if defined(Hiro_BrowserWindow)
namespace hiro {
auto pBrowserWindow::directory(BrowserWindow::State& state) -> string {
QString directory = QFileDialog::getExistingDirectory(
state.parent ? state.parent->self()->qtWindow : nullptr,
state.title ? QString::fromUtf8(state.title) : "Select Directory",
QString::fromUtf8(state.path), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
string name = directory.toUtf8().constData();
if(name && name.endsWith("/") == false) name.append("/");
return name;
}
auto pBrowserWindow::open(BrowserWindow::State& state) -> string {
string filters;
for(auto& filter : state.filters) {
auto part = filter.split("|", 1L);
if(part.size() != 2) continue;
filters.append(part[0], " (", part[1].transform(":", " "), ");;");
}
filters.trimRight(";;", 1L);
QString filename = QFileDialog::getOpenFileName(
state.parent ? state.parent->self()->qtWindow : nullptr,
state.title ? QString::fromUtf8(state.title) : "Open File",
QString::fromUtf8(state.path), QString::fromUtf8(filters)
);
return filename.toUtf8().constData();
}
auto pBrowserWindow::save(BrowserWindow::State& state) -> string {
string filters;
for(auto& filter : state.filters) {
auto part = filter.split("|", 1L);
if(part.size() != 2) continue;
filters.append(part[0], " (", part[1].transform(":", " "), ");;");
}
filters.trimRight(";;", 1L);
QString filename = QFileDialog::getSaveFileName(
state.parent ? state.parent->self()->qtWindow : nullptr,
state.title ? QString::fromUtf8(state.title) : "Save File",
QString::fromUtf8(state.path), QString::fromUtf8(filters)
);
return filename.toUtf8().constData();
}
}
#endif