MCPcopy Create free account
hub / github.com/MultiMC/Launcher / BrowseForFileInternal

Function BrowseForFileInternal

launcher/ui/GuiUtil.cpp:63–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63static QStringList BrowseForFileInternal(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget, bool single)
64{
65 static QMap<QString, QString> savedPaths;
66
67 QFileDialog w(parentWidget, caption);
68 QSet<QString> locations;
69 auto f = [&](QStandardPaths::StandardLocation l)
70 {
71 QString location = QStandardPaths::writableLocation(l);
72 QFileInfo finfo(location);
73 if (!finfo.exists()) {
74 return;
75 }
76 locations.insert(location);
77 };
78 f(QStandardPaths::DesktopLocation);
79 f(QStandardPaths::DocumentsLocation);
80 f(QStandardPaths::DownloadLocation);
81 f(QStandardPaths::HomeLocation);
82 QList<QUrl> urls;
83 for (auto location : locations)
84 {
85 urls.append(QUrl::fromLocalFile(location));
86 }
87 urls.append(QUrl::fromLocalFile(defaultPath));
88
89 w.setFileMode(single ? QFileDialog::ExistingFile : QFileDialog::ExistingFiles);
90 w.setAcceptMode(QFileDialog::AcceptOpen);
91 w.setNameFilter(filter);
92
93 QString pathToOpen;
94 if(savedPaths.contains(context))
95 {
96 pathToOpen = savedPaths[context];
97 }
98 else
99 {
100 pathToOpen = defaultPath;
101 }
102 if(!pathToOpen.isEmpty())
103 {
104 QFileInfo finfo(pathToOpen);
105 if(finfo.exists() && finfo.isDir())
106 {
107 w.setDirectory(finfo.absoluteFilePath());
108 }
109 }
110
111 w.setSidebarUrls(urls);
112
113 if (w.exec())
114 {
115 savedPaths[context] = w.directory().absolutePath();
116 return w.selectedFiles();
117 }
118 savedPaths[context] = w.directory().absolutePath();
119 return {};
120}

Callers 2

BrowseForFileMethod · 0.85
BrowseForFilesMethod · 0.85

Calls 6

existsMethod · 0.80
insertMethod · 0.80
appendMethod · 0.80
isEmptyMethod · 0.80
containsMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected