aboutsummaryrefslogtreecommitdiff
path: root/application/pages/modplatform/twitch/TwitchPage.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2020-03-31 03:13:19 +0200
committerPetr Mrázek <peterix@gmail.com>2020-04-01 00:44:24 +0200
commit3ff93a42161a5fe9301db1054dcb62c7d79ac77d (patch)
treed863a68a825fb7aebc63c5a80ec764da3cfe2cc6 /application/pages/modplatform/twitch/TwitchPage.cpp
parent21ac860e2771d2710e13c5694f18c3a244f20523 (diff)
downloadPrismLauncher-3ff93a42161a5fe9301db1054dcb62c7d79ac77d.tar.gz
PrismLauncher-3ff93a42161a5fe9301db1054dcb62c7d79ac77d.tar.bz2
PrismLauncher-3ff93a42161a5fe9301db1054dcb62c7d79ac77d.zip
NOISSUE Bare-bones twitch pack browser
Diffstat (limited to 'application/pages/modplatform/twitch/TwitchPage.cpp')
-rw-r--r--application/pages/modplatform/twitch/TwitchPage.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/application/pages/modplatform/twitch/TwitchPage.cpp b/application/pages/modplatform/twitch/TwitchPage.cpp
new file mode 100644
index 00000000..80d83133
--- /dev/null
+++ b/application/pages/modplatform/twitch/TwitchPage.cpp
@@ -0,0 +1,86 @@
+#include "TwitchPage.h"
+#include "ui_TwitchPage.h"
+
+#include "MultiMC.h"
+#include "dialogs/NewInstanceDialog.h"
+#include <InstanceImportTask.h>
+#include "TwitchModel.h"
+#include <QKeyEvent>
+
+TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent)
+ : QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
+{
+ ui->setupUi(this);
+ connect(ui->searchButton, &QPushButton::clicked, this, &TwitchPage::triggerSearch);
+ ui->searchEdit->installEventFilter(this);
+ model = new Twitch::ListModel(this);
+ ui->packView->setModel(model);
+ connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &TwitchPage::onSelectionChanged);
+}
+
+TwitchPage::~TwitchPage()
+{
+ delete ui;
+}
+
+bool TwitchPage::eventFilter(QObject* watched, QEvent* event)
+{
+ if (watched == ui->searchEdit && event->type() == QEvent::KeyPress) {
+ QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
+ if (keyEvent->key() == Qt::Key_Return) {
+ triggerSearch();
+ keyEvent->accept();
+ return true;
+ }
+ }
+ return QWidget::eventFilter(watched, event);
+}
+
+bool TwitchPage::shouldDisplay() const
+{
+ return true;
+}
+
+void TwitchPage::openedImpl()
+{
+ suggestCurrent();
+}
+
+void TwitchPage::triggerSearch()
+{
+ model->searchWithTerm(ui->searchEdit->text());
+}
+
+void TwitchPage::onSelectionChanged(QModelIndex first, QModelIndex second)
+{
+ if(!first.isValid())
+ {
+ if(isOpened)
+ {
+ dialog->setSuggestedPack();
+ }
+ return;
+ }
+ current = model->data(first, Qt::UserRole).value<Twitch::Modpack>();
+ suggestCurrent();
+}
+
+void TwitchPage::suggestCurrent()
+{
+ if(!isOpened)
+ {
+ return;
+ }
+ if(current.broken)
+ {
+ dialog->setSuggestedPack();
+ }
+
+ dialog->setSuggestedPack(current.name, new InstanceImportTask(current.latestFile.downloadUrl));
+ QString editedLogoName;
+ editedLogoName = "twitch_" + current.logoName.section(".", 0, 0);
+ model->getLogo(current.logoName, current.logoUrl, [this, editedLogoName](QString logo)
+ {
+ dialog->setSuggestedIconFromFile(logo, editedLogoName);
+ });
+}