summaryrefslogtreecommitdiffstats
path: root/application/GuiUtil.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-05-05 00:42:04 +0200
committerPetr Mrázek <peterix@gmail.com>2015-05-05 00:42:04 +0200
commit49d3705d16dcbfb69995eb731a11944eb9db33fd (patch)
tree29b40be625dcf7e19b273b94e4be9be2e7035a2f /application/GuiUtil.cpp
parentc09dc85090a286305ce4f6faf86a71498a792018 (diff)
downloadMultiMC-49d3705d16dcbfb69995eb731a11944eb9db33fd.tar
MultiMC-49d3705d16dcbfb69995eb731a11944eb9db33fd.tar.gz
MultiMC-49d3705d16dcbfb69995eb731a11944eb9db33fd.tar.lz
MultiMC-49d3705d16dcbfb69995eb731a11944eb9db33fd.tar.xz
MultiMC-49d3705d16dcbfb69995eb731a11944eb9db33fd.zip
GH-899 clean up mod browse buttons and dead legacy forge
Diffstat (limited to 'application/GuiUtil.cpp')
-rw-r--r--application/GuiUtil.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/application/GuiUtil.cpp b/application/GuiUtil.cpp
index fb42b9bc..7ce00115 100644
--- a/application/GuiUtil.cpp
+++ b/application/GuiUtil.cpp
@@ -3,11 +3,15 @@
#include <QClipboard>
#include <QDesktopServices>
#include <QApplication>
+#include <QFileDialog>
#include "dialogs/ProgressDialog.h"
#include "net/PasteUpload.h"
#include "dialogs/CustomMessageBox.h"
+#include "MultiMC.h"
+#include <settings/SettingsObject.h>
+
void GuiUtil::uploadPaste(const QString &text, QWidget *parentWidget)
{
ProgressDialog dialog(parentWidget);
@@ -46,3 +50,52 @@ void GuiUtil::setClipboardText(const QString &text)
{
QApplication::clipboard()->setText(text);
}
+
+QStringList GuiUtil::BrowseForMods(QString context, QString caption, QString filter,
+ QWidget *parentWidget)
+{
+ static QMap<QString, QString> savedPaths;
+
+ QFileDialog w(parentWidget, caption);
+ QSet<QString> locations;
+ QString modsFolder = MMC->settings()->get("CentralModsDir").toString();
+ auto f = [&](QStandardPaths::StandardLocation l)
+ {
+ QString location = QStandardPaths::writableLocation(l);
+ QFileInfo finfo(location);
+ if (!finfo.exists())
+ return;
+ locations.insert(location);
+ };
+ f(QStandardPaths::DesktopLocation);
+ f(QStandardPaths::DocumentsLocation);
+ f(QStandardPaths::DownloadLocation);
+ f(QStandardPaths::HomeLocation);
+ QList<QUrl> urls;
+ for (auto location : locations)
+ {
+ urls.append(QUrl::fromLocalFile(location));
+ }
+ urls.append(QUrl::fromLocalFile(modsFolder));
+
+ w.setFileMode(QFileDialog::ExistingFiles);
+ w.setAcceptMode(QFileDialog::AcceptOpen);
+ w.setNameFilter(filter);
+ if(savedPaths.contains(context))
+ {
+ w.setDirectory(savedPaths[context]);
+ }
+ else
+ {
+ w.setDirectory(modsFolder);
+ }
+ w.setSidebarUrls(urls);
+
+ if (w.exec())
+ {
+ savedPaths[context] = w.directory().absolutePath();
+ return w.getOpenFileNames();
+ }
+ savedPaths[context] = w.directory().absolutePath();
+ return {};
+}