From 91ba4cf75ee30c64779edb5b7644e5a830de5026 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 14 Aug 2023 18:16:53 +0200 Subject: chore: reformat Signed-off-by: Sefa Eyeoglu --- launcher/ui/pages/instance/ExternalResourcesPage.h | 4 +- launcher/ui/pages/instance/GameOptionsPage.cpp | 11 +- launcher/ui/pages/instance/GameOptionsPage.h | 38 +- .../ui/pages/instance/InstanceSettingsPage.cpp | 127 ++----- launcher/ui/pages/instance/InstanceSettingsPage.h | 36 +- launcher/ui/pages/instance/LogPage.cpp | 146 +++----- launcher/ui/pages/instance/LogPage.h | 44 +-- launcher/ui/pages/instance/NotesPage.cpp | 5 +- launcher/ui/pages/instance/NotesPage.h | 35 +- launcher/ui/pages/instance/OtherLogsPage.cpp | 140 +++----- launcher/ui/pages/instance/OtherLogsPage.h | 42 +-- launcher/ui/pages/instance/ResourcePackPage.h | 11 +- launcher/ui/pages/instance/ScreenshotsPage.cpp | 244 ++++++------- launcher/ui/pages/instance/ScreenshotsPage.h | 58 +--- launcher/ui/pages/instance/ServersPage.cpp | 382 ++++++++------------- launcher/ui/pages/instance/ServersPage.h | 59 ++-- launcher/ui/pages/instance/ShaderPackPage.h | 7 +- launcher/ui/pages/instance/TexturePackPage.h | 12 +- launcher/ui/pages/instance/VersionPage.cpp | 1 - launcher/ui/pages/instance/WorldListPage.cpp | 177 ++++------ launcher/ui/pages/instance/WorldListPage.h | 64 ++-- 21 files changed, 598 insertions(+), 1045 deletions(-) (limited to 'launcher/ui/pages/instance') diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.h b/launcher/ui/pages/instance/ExternalResourcesPage.h index 97d922d8..d29be0fc 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.h +++ b/launcher/ui/pages/instance/ExternalResourcesPage.h @@ -4,8 +4,8 @@ #include #include "Application.h" -#include "settings/Setting.h" #include "minecraft/MinecraftInstance.h" +#include "settings/Setting.h" #include "ui/pages/BasePage.h" class ResourceFolderModel; @@ -52,7 +52,7 @@ class ExternalResourcesPage : public QMainWindow, public BasePage { virtual void addItem(); void removeItem(); - virtual void removeItems(const QItemSelection &selection); + virtual void removeItems(const QItemSelection& selection); virtual void enableItem(); virtual void disableItem(); diff --git a/launcher/ui/pages/instance/GameOptionsPage.cpp b/launcher/ui/pages/instance/GameOptionsPage.cpp index 63443166..e9004170 100644 --- a/launcher/ui/pages/instance/GameOptionsPage.cpp +++ b/launcher/ui/pages/instance/GameOptionsPage.cpp @@ -34,23 +34,20 @@ */ #include "GameOptionsPage.h" -#include "ui_GameOptionsPage.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/gameoptions/GameOptions.h" +#include "ui_GameOptionsPage.h" -GameOptionsPage::GameOptionsPage(MinecraftInstance * inst, QWidget* parent) - : QWidget(parent), ui(new Ui::GameOptionsPage) +GameOptionsPage::GameOptionsPage(MinecraftInstance* inst, QWidget* parent) : QWidget(parent), ui(new Ui::GameOptionsPage) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); m_model = inst->gameOptionsModel(); ui->optionsView->setModel(m_model.get()); auto head = ui->optionsView->header(); - if(head->count()) - { + if (head->count()) { head->setSectionResizeMode(0, QHeaderView::ResizeToContents); - for(int i = 1; i < head->count(); i++) - { + for (int i = 1; i < head->count(); i++) { head->setSectionResizeMode(i, QHeaderView::Stretch); } } diff --git a/launcher/ui/pages/instance/GameOptionsPage.h b/launcher/ui/pages/instance/GameOptionsPage.h index de8c421e..563bd10a 100644 --- a/launcher/ui/pages/instance/GameOptionsPage.h +++ b/launcher/ui/pages/instance/GameOptionsPage.h @@ -35,50 +35,36 @@ #pragma once -#include #include +#include -#include "ui/pages/BasePage.h" #include +#include "ui/pages/BasePage.h" -namespace Ui -{ +namespace Ui { class GameOptionsPage; } class GameOptions; class MinecraftInstance; -class GameOptionsPage : public QWidget, public BasePage -{ +class GameOptionsPage : public QWidget, public BasePage { Q_OBJECT -public: - explicit GameOptionsPage(MinecraftInstance *inst, QWidget *parent = 0); + public: + explicit GameOptionsPage(MinecraftInstance* inst, QWidget* parent = 0); virtual ~GameOptionsPage(); void openedImpl() override; void closedImpl() override; - virtual QString displayName() const override - { - return tr("Game Options"); - } - virtual QIcon icon() const override - { - return APPLICATION->getThemedIcon("settings"); - } - virtual QString id() const override - { - return "gameoptions"; - } - virtual QString helpPage() const override - { - return "Game-Options-management"; - } + virtual QString displayName() const override { return tr("Game Options"); } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("settings"); } + virtual QString id() const override { return "gameoptions"; } + virtual QString helpPage() const override { return "Game-Options-management"; } void retranslate() override; -private: // data - Ui::GameOptionsPage *ui = nullptr; + private: // data + Ui::GameOptionsPage* ui = nullptr; std::shared_ptr m_model; }; diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index 718c628c..8ea24b78 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -38,8 +38,8 @@ #include "InstanceSettingsPage.h" #include "ui_InstanceSettingsPage.h" -#include #include +#include #include #include @@ -47,15 +47,15 @@ #include "ui/dialogs/VersionSelectDialog.h" #include "ui/widgets/CustomCommands.h" -#include "JavaCommon.h" #include "Application.h" +#include "JavaCommon.h" #include "minecraft/auth/AccountList.h" #include "FileSystem.h" #include "java/JavaInstallList.h" #include "java/JavaUtils.h" -InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent) +InstanceSettingsPage::InstanceSettingsPage(BaseInstance* inst, QWidget* parent) : QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst) { m_settings = inst->settings(); @@ -78,7 +78,7 @@ InstanceSettingsPage::~InstanceSettingsPage() void InstanceSettingsPage::globalSettingsButtonClicked(bool) { - switch(ui->settingsTabs->currentIndex()) { + switch (ui->settingsTabs->currentIndex()) { case 0: APPLICATION->ShowGlobalSettings(this, "java-settings"); return; @@ -104,13 +104,10 @@ void InstanceSettingsPage::applySettings() // Miscellaneous bool miscellaneous = ui->miscellaneousSettingsBox->isChecked(); m_settings->set("OverrideMiscellaneous", miscellaneous); - if (miscellaneous) - { + if (miscellaneous) { m_settings->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked()); m_settings->set("QuitAfterGameStop", ui->quitAfterGameStopCheck->isChecked()); - } - else - { + } else { m_settings->reset("CloseAfterLaunch"); m_settings->reset("QuitAfterGameStop"); } @@ -118,14 +115,11 @@ void InstanceSettingsPage::applySettings() // Console bool console = ui->consoleSettingsBox->isChecked(); m_settings->set("OverrideConsole", console); - if (console) - { + if (console) { m_settings->set("ShowConsole", ui->showConsoleCheck->isChecked()); m_settings->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); m_settings->set("ShowConsoleOnError", ui->showConsoleErrorCheck->isChecked()); - } - else - { + } else { m_settings->reset("ShowConsole"); m_settings->reset("AutoCloseConsole"); m_settings->reset("ShowConsoleOnError"); @@ -134,14 +128,11 @@ void InstanceSettingsPage::applySettings() // Window Size bool window = ui->windowSizeGroupBox->isChecked(); m_settings->set("OverrideWindow", window); - if (window) - { + if (window) { m_settings->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); m_settings->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); m_settings->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); - } - else - { + } else { m_settings->reset("LaunchMaximized"); m_settings->reset("MinecraftWinWidth"); m_settings->reset("MinecraftWinHeight"); @@ -150,24 +141,18 @@ void InstanceSettingsPage::applySettings() // Memory bool memory = ui->memoryGroupBox->isChecked(); m_settings->set("OverrideMemory", memory); - if (memory) - { + if (memory) { int min = ui->minMemSpinBox->value(); int max = ui->maxMemSpinBox->value(); - if(min < max) - { + if (min < max) { m_settings->set("MinMemAlloc", min); m_settings->set("MaxMemAlloc", max); - } - else - { + } else { m_settings->set("MinMemAlloc", max); m_settings->set("MaxMemAlloc", min); } m_settings->set("PermGen", ui->permGenSpinBox->value()); - } - else - { + } else { m_settings->reset("MinMemAlloc"); m_settings->reset("MaxMemAlloc"); m_settings->reset("PermGen"); @@ -176,13 +161,10 @@ void InstanceSettingsPage::applySettings() // Java Install Settings bool javaInstall = ui->javaSettingsGroupBox->isChecked(); m_settings->set("OverrideJavaLocation", javaInstall); - if (javaInstall) - { + if (javaInstall) { m_settings->set("JavaPath", ui->javaPathTextBox->text()); m_settings->set("IgnoreJavaCompatibility", ui->skipCompatibilityCheckbox->isChecked()); - } - else - { + } else { m_settings->reset("JavaPath"); m_settings->reset("IgnoreJavaCompatibility"); } @@ -190,12 +172,9 @@ void InstanceSettingsPage::applySettings() // Java arguments bool javaArgs = ui->javaArgumentsGroupBox->isChecked(); m_settings->set("OverrideJavaArgs", javaArgs); - if(javaArgs) - { + if (javaArgs) { m_settings->set("JvmArgs", ui->jvmArgsTextBox->toPlainText().replace("\n", " ")); - } - else - { + } else { m_settings->reset("JvmArgs"); } @@ -205,14 +184,11 @@ void InstanceSettingsPage::applySettings() // Custom Commands bool custcmd = ui->customCommands->checked(); m_settings->set("OverrideCommands", custcmd); - if (custcmd) - { + if (custcmd) { m_settings->set("PreLaunchCommand", ui->customCommands->prelaunchCommand()); m_settings->set("WrapperCommand", ui->customCommands->wrapperCommand()); m_settings->set("PostExitCommand", ui->customCommands->postexitCommand()); - } - else - { + } else { m_settings->reset("PreLaunchCommand"); m_settings->reset("WrapperCommand"); m_settings->reset("PostExitCommand"); @@ -221,13 +197,10 @@ void InstanceSettingsPage::applySettings() // Workarounds bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked(); m_settings->set("OverrideNativeWorkarounds", workarounds); - if(workarounds) - { + if (workarounds) { m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); m_settings->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked()); - } - else - { + } else { m_settings->reset("UseNativeOpenAL"); m_settings->reset("UseNativeGLFW"); } @@ -235,14 +208,11 @@ void InstanceSettingsPage::applySettings() // Performance bool performance = ui->perfomanceGroupBox->isChecked(); m_settings->set("OverridePerformance", performance); - if(performance) - { + if (performance) { m_settings->set("EnableFeralGamemode", ui->enableFeralGamemodeCheck->isChecked()); m_settings->set("EnableMangoHud", ui->enableMangoHud->isChecked()); m_settings->set("UseDiscreteGpu", ui->useDiscreteGpuCheck->isChecked()); - } - else - { + } else { m_settings->reset("EnableFeralGamemode"); m_settings->reset("EnableMangoHud"); m_settings->reset("UseDiscreteGpu"); @@ -251,13 +221,10 @@ void InstanceSettingsPage::applySettings() // Game time bool gameTime = ui->gameTimeGroupBox->isChecked(); m_settings->set("OverrideGameTime", gameTime); - if (gameTime) - { + if (gameTime) { m_settings->set("ShowGameTime", ui->showGameTime->isChecked()); m_settings->set("RecordGameTime", ui->recordGameTime->isChecked()); - } - else - { + } else { m_settings->reset("ShowGameTime"); m_settings->reset("RecordGameTime"); } @@ -265,12 +232,9 @@ void InstanceSettingsPage::applySettings() // Join server on launch bool joinServerOnLaunch = ui->serverJoinGroupBox->isChecked(); m_settings->set("JoinServerOnLaunch", joinServerOnLaunch); - if (joinServerOnLaunch) - { + if (joinServerOnLaunch) { m_settings->set("JoinServerOnLaunchAddress", ui->serverJoinAddress->text()); - } - else - { + } else { m_settings->reset("JoinServerOnLaunchAddress"); } @@ -316,13 +280,10 @@ void InstanceSettingsPage::loadSettings() ui->memoryGroupBox->setChecked(m_settings->get("OverrideMemory").toBool()); int min = m_settings->get("MinMemAlloc").toInt(); int max = m_settings->get("MaxMemAlloc").toInt(); - if(min < max) - { + if (min < max) { ui->minMemSpinBox->setValue(min); ui->maxMemSpinBox->setValue(max); - } - else - { + } else { ui->minMemSpinBox->setValue(max); ui->maxMemSpinBox->setValue(min); } @@ -332,7 +293,6 @@ void InstanceSettingsPage::loadSettings() ui->labelPermGen->setVisible(permGenVisible); ui->labelPermgenNote->setVisible(permGenVisible); - // Java Settings bool overrideJava = m_settings->get("OverrideJava").toBool(); bool overrideLocation = m_settings->get("OverrideJavaLocation").toBool() || overrideJava; @@ -346,13 +306,8 @@ void InstanceSettingsPage::loadSettings() ui->jvmArgsTextBox->setPlainText(m_settings->get("JvmArgs").toString()); // Custom commands - ui->customCommands->initialize( - true, - m_settings->get("OverrideCommands").toBool(), - m_settings->get("PreLaunchCommand").toString(), - m_settings->get("WrapperCommand").toString(), - m_settings->get("PostExitCommand").toString() - ); + ui->customCommands->initialize(true, m_settings->get("OverrideCommands").toBool(), m_settings->get("PreLaunchCommand").toString(), + m_settings->get("WrapperCommand").toString(), m_settings->get("PostExitCommand").toString()); // Workarounds ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool()); @@ -408,8 +363,7 @@ void InstanceSettingsPage::on_javaDetectBtn_clicked() vselect.setResizeOn(2); vselect.exec(); - if (vselect.result() == QDialog::Accepted && vselect.selectedVersion()) - { + if (vselect.result() == QDialog::Accepted && vselect.selectedVersion()) { java = std::dynamic_pointer_cast(vselect.selectedVersion()); ui->javaPathTextBox->setText(java->path); bool visible = java->id.requiresPermGen() && m_settings->get("OverrideMemory").toBool(); @@ -425,15 +379,13 @@ void InstanceSettingsPage::on_javaBrowseBtn_clicked() QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if(raw_path.isEmpty()) - { + if (raw_path.isEmpty()) { return; } QString cooked_path = FS::NormalizePath(raw_path); QFileInfo javaInfo(cooked_path); - if(!javaInfo.exists() || !javaInfo.isExecutable()) - { + if (!javaInfo.exists() || !javaInfo.isExecutable()) { return; } ui->javaPathTextBox->setText(cooked_path); @@ -447,13 +399,11 @@ void InstanceSettingsPage::on_javaBrowseBtn_clicked() void InstanceSettingsPage::on_javaTestBtn_clicked() { - if(checker) - { + if (checker) { return; } - checker.reset(new JavaCommon::TestCheck( - this, ui->javaPathTextBox->text(), ui->jvmArgsTextBox->toPlainText().replace("\n", " "), - ui->minMemSpinBox->value(), ui->maxMemSpinBox->value(), ui->permGenSpinBox->value())); + checker.reset(new JavaCommon::TestCheck(this, ui->javaPathTextBox->text(), ui->jvmArgsTextBox->toPlainText().replace("\n", " "), + ui->minMemSpinBox->value(), ui->maxMemSpinBox->value(), ui->permGenSpinBox->value())); connect(checker.get(), SIGNAL(finished()), SLOT(checkerFinished())); checker->run(); } @@ -470,7 +420,6 @@ void InstanceSettingsPage::updateAccountsMenu() if (i == accountIndex) ui->instanceAccountSelector->setCurrentIndex(i); } - } QIcon InstanceSettingsPage::getFaceForAccount(MinecraftAccountPtr account) diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.h b/launcher/ui/pages/instance/InstanceSettingsPage.h index 036b4181..9f135593 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.h +++ b/launcher/ui/pages/instance/InstanceSettingsPage.h @@ -46,35 +46,21 @@ #include "ui/pages/BasePage.h" class JavaChecker; -namespace Ui -{ +namespace Ui { class InstanceSettingsPage; } -class InstanceSettingsPage : public QWidget, public BasePage -{ +class InstanceSettingsPage : public QWidget, public BasePage { Q_OBJECT -public: - explicit InstanceSettingsPage(BaseInstance *inst, QWidget *parent = 0); + public: + explicit InstanceSettingsPage(BaseInstance* inst, QWidget* parent = 0); virtual ~InstanceSettingsPage(); - virtual QString displayName() const override - { - return tr("Settings"); - } - virtual QIcon icon() const override - { - return APPLICATION->getThemedIcon("instance-settings"); - } - virtual QString id() const override - { - return "settings"; - } + virtual QString displayName() const override { return tr("Settings"); } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("instance-settings"); } + virtual QString id() const override { return "settings"; } virtual bool apply() override; - virtual QString helpPage() const override - { - return "Instance-settings"; - } + virtual QString helpPage() const override { return "Instance-settings"; } void retranslate() override; void updateThresholds(); @@ -96,9 +82,9 @@ public: QIcon getFaceForAccount(MinecraftAccountPtr account); void changeInstanceAccount(int index); -private: - Ui::InstanceSettingsPage *ui; - BaseInstance *m_instance; + private: + Ui::InstanceSettingsPage* ui; + BaseInstance* m_instance; SettingsObjectPtr m_settings; unique_qobject_ptr checker; }; diff --git a/launcher/ui/pages/instance/LogPage.cpp b/launcher/ui/pages/instance/LogPage.cpp index 639cd711..8e1e5376 100644 --- a/launcher/ui/pages/instance/LogPage.cpp +++ b/launcher/ui/pages/instance/LogPage.cpp @@ -47,56 +47,42 @@ #include "launch/LaunchTask.h" #include "settings/Setting.h" -#include "ui/GuiUtil.h" #include "ui/ColorCache.h" +#include "ui/GuiUtil.h" #include -class LogFormatProxyModel : public QIdentityProxyModel -{ -public: - LogFormatProxyModel(QObject* parent = nullptr) : QIdentityProxyModel(parent) - { - } - QVariant data(const QModelIndex &index, int role) const override +class LogFormatProxyModel : public QIdentityProxyModel { + public: + LogFormatProxyModel(QObject* parent = nullptr) : QIdentityProxyModel(parent) {} + QVariant data(const QModelIndex& index, int role) const override { - switch(role) - { + switch (role) { case Qt::FontRole: return m_font; - case Qt::ForegroundRole: - { - MessageLevel::Enum level = (MessageLevel::Enum) QIdentityProxyModel::data(index, LogModel::LevelRole).toInt(); + case Qt::ForegroundRole: { + MessageLevel::Enum level = (MessageLevel::Enum)QIdentityProxyModel::data(index, LogModel::LevelRole).toInt(); return m_colors->getFront(level); } - case Qt::BackgroundRole: - { - MessageLevel::Enum level = (MessageLevel::Enum) QIdentityProxyModel::data(index, LogModel::LevelRole).toInt(); + case Qt::BackgroundRole: { + MessageLevel::Enum level = (MessageLevel::Enum)QIdentityProxyModel::data(index, LogModel::LevelRole).toInt(); return m_colors->getBack(level); } default: return QIdentityProxyModel::data(index, role); - } + } } - void setFont(QFont font) - { - m_font = font; - } + void setFont(QFont font) { m_font = font; } - void setColors(LogColorCache* colors) - { - m_colors.reset(colors); - } + void setColors(LogColorCache* colors) { m_colors.reset(colors); } - QModelIndex find(const QModelIndex &start, const QString &value, bool reverse) const + QModelIndex find(const QModelIndex& start, const QString& value, bool reverse) const { QModelIndex parentIndex = parent(start); - auto compare = [&](int r) -> QModelIndex - { + auto compare = [&](int r) -> QModelIndex { QModelIndex idx = index(r, start.column(), parentIndex); - if (!idx.isValid() || idx == start) - { + if (!idx.isValid() || idx == start) { return QModelIndex(); } QVariant v = data(idx, Qt::DisplayRole); @@ -105,35 +91,28 @@ public: return idx; return QModelIndex(); }; - if(reverse) - { + if (reverse) { int from = start.row(); int to = 0; - for (int i = 0; i < 2; ++i) - { - for (int r = from; (r >= to); --r) - { + for (int i = 0; i < 2; ++i) { + for (int r = from; (r >= to); --r) { auto idx = compare(r); - if(idx.isValid()) + if (idx.isValid()) return idx; } // prepare for the next iteration from = rowCount() - 1; to = start.row(); } - } - else - { + } else { int from = start.row(); int to = rowCount(parentIndex); - for (int i = 0; i < 2; ++i) - { - for (int r = from; (r < to); ++r) - { + for (int i = 0; i < 2; ++i) { + for (int r = from; (r < to); ++r) { auto idx = compare(r); - if(idx.isValid()) + if (idx.isValid()) return idx; } // prepare for the next iteration @@ -143,13 +122,13 @@ public: } return QModelIndex(); } -private: + + private: QFont m_font; std::unique_ptr m_colors; }; -LogPage::LogPage(InstancePtr instance, QWidget *parent) - : QWidget(parent), ui(new Ui::LogPage), m_instance(instance) +LogPage::LogPage(InstancePtr instance, QWidget* parent) : QWidget(parent), ui(new Ui::LogPage), m_instance(instance) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); @@ -167,8 +146,7 @@ LogPage::LogPage(InstancePtr instance, QWidget *parent) QString fontFamily = APPLICATION->settings()->get("ConsoleFont").toString(); bool conversionOk = false; int fontSize = APPLICATION->settings()->get("ConsoleFontSize").toInt(&conversionOk); - if(!conversionOk) - { + if (!conversionOk) { fontSize = 11; } m_proxy->setFont(QFont(fontFamily, fontSize)); @@ -179,8 +157,7 @@ LogPage::LogPage(InstancePtr instance, QWidget *parent) // set up instance and launch process recognition { auto launchTask = m_instance->getLaunchTask(); - if(launchTask) - { + if (launchTask) { setInstanceLaunchTaskChanged(launchTask, true); } connect(m_instance.get(), &BaseInstance::launchTaskChanged, this, &LogPage::onInstanceLaunchTaskChanged); @@ -202,30 +179,23 @@ LogPage::~LogPage() void LogPage::modelStateToUI() { - if(m_model->wrapLines()) - { + if (m_model->wrapLines()) { ui->text->setWordWrap(true); ui->wrapCheckbox->setCheckState(Qt::Checked); - } - else - { + } else { ui->text->setWordWrap(false); ui->wrapCheckbox->setCheckState(Qt::Unchecked); } - if(m_model->suspended()) - { + if (m_model->suspended()) { ui->trackLogCheckbox->setCheckState(Qt::Unchecked); - } - else - { + } else { ui->trackLogCheckbox->setCheckState(Qt::Checked); } } void LogPage::UIToModelState() { - if(!m_model) - { + if (!m_model) { return; } m_model->setLineWrap(ui->wrapCheckbox->checkState() == Qt::Checked); @@ -235,21 +205,15 @@ void LogPage::UIToModelState() void LogPage::setInstanceLaunchTaskChanged(shared_qobject_ptr proc, bool initial) { m_process = proc; - if(m_process) - { + if (m_process) { m_model = proc->getLogModel(); m_proxy->setSourceModel(m_model.get()); - if(initial) - { + if (initial) { modelStateToUI(); - } - else - { + } else { UIToModelState(); } - } - else - { + } else { m_proxy->setSourceModel(nullptr); m_model.reset(); } @@ -272,34 +236,25 @@ bool LogPage::shouldDisplay() const void LogPage::on_btnPaste_clicked() { - if(!m_model) + if (!m_model) return; - //FIXME: turn this into a proper task and move the upload logic out of GuiUtil! - m_model->append( - MessageLevel::Launcher, - QString("Log upload triggered at: %1").arg( - QDateTime::currentDateTime().toString(Qt::RFC2822Date) - ) - ); + // FIXME: turn this into a proper task and move the upload logic out of GuiUtil! + m_model->append(MessageLevel::Launcher, + QString("Log upload triggered at: %1").arg(QDateTime::currentDateTime().toString(Qt::RFC2822Date))); auto url = GuiUtil::uploadPaste(tr("Minecraft Log"), m_model->toPlainText(), this); - if(!url.has_value()) - { + if (!url.has_value()) { m_model->append(MessageLevel::Error, QString("Log upload canceled")); - } - else if (url->isNull()) - { + } else if (url->isNull()) { m_model->append(MessageLevel::Error, QString("Log upload failed!")); - } - else - { + } else { m_model->append(MessageLevel::Launcher, QString("Log uploaded to: %1").arg(url.value())); } } void LogPage::on_btnCopy_clicked() { - if(!m_model) + if (!m_model) return; m_model->append(MessageLevel::Launcher, QString("Clipboard copy at: %1").arg(QDateTime::currentDateTime().toString(Qt::RFC2822Date))); GuiUtil::setClipboardText(m_model->toPlainText()); @@ -307,7 +262,7 @@ void LogPage::on_btnCopy_clicked() void LogPage::on_btnClear_clicked() { - if(!m_model) + if (!m_model) return; m_model->clear(); m_container->refreshContainer(); @@ -320,7 +275,7 @@ void LogPage::on_btnBottom_clicked() void LogPage::on_trackLogCheckbox_clicked(bool checked) { - if(!m_model) + if (!m_model) return; m_model->suspend(!checked); } @@ -328,7 +283,7 @@ void LogPage::on_trackLogCheckbox_clicked(bool checked) void LogPage::on_wrapCheckbox_clicked(bool checked) { ui->text->setWordWrap(checked); - if(!m_model) + if (!m_model) return; m_model->setLineWrap(checked); } @@ -353,8 +308,7 @@ void LogPage::findPreviousActivated() void LogPage::findActivated() { // focus the search bar if it doesn't have focus - if (!ui->searchBar->hasFocus()) - { + if (!ui->searchBar->hasFocus()) { ui->searchBar->setFocus(); ui->searchBar->selectAll(); } diff --git a/launcher/ui/pages/instance/LogPage.h b/launcher/ui/pages/instance/LogPage.h index f6fe87c4..33b6cc39 100644 --- a/launcher/ui/pages/instance/LogPage.h +++ b/launcher/ui/pages/instance/LogPage.h @@ -37,46 +37,32 @@ #include +#include #include "BaseInstance.h" #include "launch/LaunchTask.h" #include "ui/pages/BasePage.h" -#include -namespace Ui -{ +namespace Ui { class LogPage; } class QTextCharFormat; class LogFormatProxyModel; -class LogPage : public QWidget, public BasePage -{ +class LogPage : public QWidget, public BasePage { Q_OBJECT -public: - explicit LogPage(InstancePtr instance, QWidget *parent = 0); + public: + explicit LogPage(InstancePtr instance, QWidget* parent = 0); virtual ~LogPage(); - virtual QString displayName() const override - { - return tr("Minecraft Log"); - } - virtual QIcon icon() const override - { - return APPLICATION->getThemedIcon("log"); - } - virtual QString id() const override - { - return "console"; - } + virtual QString displayName() const override { return tr("Minecraft Log"); } + virtual QIcon icon() const override { return APPLICATION->getThemedIcon("log"); } + virtual QString id() const override { return "console"; } virtual bool apply() override; - virtual QString helpPage() const override - { - return "Minecraft-Logs"; - } + virtual QString helpPage() const override { return "Minecraft-Logs"; } virtual bool shouldDisplay() const override; void retranslate() override; -private slots: + private slots: void on_btnPaste_clicked(); void on_btnCopy_clicked(); void on_btnClear_clicked(); @@ -92,16 +78,16 @@ private slots: void onInstanceLaunchTaskChanged(shared_qobject_ptr proc); -private: + private: void modelStateToUI(); void UIToModelState(); void setInstanceLaunchTaskChanged(shared_qobject_ptr proc, bool initial); -private: - Ui::LogPage *ui; + private: + Ui::LogPage* ui; InstancePtr m_instance; shared_qobject_ptr m_process; - LogFormatProxyModel * m_proxy; - shared_qobject_ptr m_model; + LogFormatProxyModel* m_proxy; + shared_qobject_ptr m_model; }; diff --git a/launcher/ui/pages/instance/NotesPage.cpp b/launcher/ui/pages/instance/NotesPage.cpp index 95a9fad2..887bad85 100644 --- a/launcher/ui/pages/instance/NotesPage.cpp +++ b/launcher/ui/pages/instance/NotesPage.cpp @@ -34,11 +34,10 @@ */ #include "NotesPage.h" -#include "ui_NotesPage.h" #include +#include "ui_NotesPage.h" -NotesPage::NotesPage(BaseInstance *inst, QWidget *parent) - : QWidget(parent), ui(new Ui::NotesPage), m_inst(inst) +NotesPage::NotesPage(BaseInstance* inst, QWidget* parent) : QWidget(parent), ui(new Ui::NotesPage), m_inst(inst) { ui->setupUi(this); ui->noteEditor->setText(m_inst->notes()); diff --git a/launcher/ui/pages/instance/NotesPage.h b/launcher/ui/pages/instance/NotesPage.h index 80a7279b..aa608306 100644 --- a/launcher/ui/pages/instance/NotesPage.h +++ b/launcher/ui/pages/instance/NotesPage.h @@ -37,45 +37,34 @@ #include +#include #include "BaseInstance.h" #include "ui/pages/BasePage.h" -#include -namespace Ui -{ +namespace Ui { class NotesPage; } -class NotesPage : public QWidget, public BasePage -{ +class NotesPage : public QWidget, public BasePage { Q_OBJECT -public: - explicit NotesPage(BaseInstance *inst, QWidget *parent = 0); + public: + explicit NotesPage(BaseInstance* inst, QWidget* parent = 0); virtual ~NotesPage(); - virtual QString displayName() const override - { - return tr("Notes"); - } + virtual QString displayName() const override { return tr("Notes"); } virtual QIcon icon() const override { auto icon = APPLICATION->getThemedIcon("notes"); - if(icon.isNull()) + if (icon.isNull()) icon = APPLICATION->getThemedIcon("news"); return icon; } - virtual QString id() const override - { - return "notes"; - } + virtual QString id() const override { return "notes"; } virtual bool apply() override; - virtual QString helpPage() const override - { - return "Notes"; - } + virtual QString helpPage() const override { return "Notes"; } void retranslate() override; -private: - Ui::NotesPage *ui; - BaseInstance *m_inst; + private: + Ui::NotesPage* ui; + BaseInstance* m_inst; }; diff --git a/launcher/ui/pages/instance/OtherLogsPage.cpp b/launcher/ui/pages/instance/OtherLogsPage.cpp index f2b13f32..ab5d9828 100644 --- a/launcher/ui/pages/instance/OtherLogsPage.cpp +++ b/launcher/ui/pages/instance/OtherLogsPage.cpp @@ -41,14 +41,13 @@ #include "ui/GuiUtil.h" -#include "RecursiveFileSystemWatcher.h" -#include #include +#include #include +#include "RecursiveFileSystemWatcher.h" -OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent) - : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter), - m_watcher(new RecursiveFileSystemWatcher(this)) +OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget* parent) + : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter), m_watcher(new RecursiveFileSystemWatcher(this)) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); @@ -94,21 +93,15 @@ void OtherLogsPage::populateSelectLogBox() { ui->selectLogBox->clear(); ui->selectLogBox->addItems(m_watcher->files()); - if (m_currentFile.isEmpty()) - { + if (m_currentFile.isEmpty()) { setControlsEnabled(false); ui->selectLogBox->setCurrentIndex(-1); - } - else - { + } else { const int index = ui->selectLogBox->findText(m_currentFile); - if (index != -1) - { + if (index != -1) { ui->selectLogBox->setCurrentIndex(index); setControlsEnabled(true); - } - else - { + } else { setControlsEnabled(false); } } @@ -117,19 +110,15 @@ void OtherLogsPage::populateSelectLogBox() void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index) { QString file; - if (index != -1) - { + if (index != -1) { file = ui->selectLogBox->itemText(index); } - if (file.isEmpty() || !QFile::exists(FS::PathCombine(m_path, file))) - { + if (file.isEmpty() || !QFile::exists(FS::PathCombine(m_path, file))) { m_currentFile = QString(); ui->text->clear(); setControlsEnabled(false); - } - else - { + } else { m_currentFile = file; on_btnReload_clicked(); setControlsEnabled(true); @@ -138,64 +127,49 @@ void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index) void OtherLogsPage::on_btnReload_clicked() { - if(m_currentFile.isEmpty()) - { + if (m_currentFile.isEmpty()) { setControlsEnabled(false); return; } QFile file(FS::PathCombine(m_path, m_currentFile)); - if (!file.open(QFile::ReadOnly)) - { + if (!file.open(QFile::ReadOnly)) { setControlsEnabled(false); - ui->btnReload->setEnabled(true); // allow reload + ui->btnReload->setEnabled(true); // allow reload m_currentFile = QString(); - QMessageBox::critical(this, tr("Error"), tr("Unable to open %1 for reading: %2") - .arg(m_currentFile, file.errorString())); - } - else - { - auto setPlainText = [&](const QString & text) - { + QMessageBox::critical(this, tr("Error"), tr("Unable to open %1 for reading: %2").arg(m_currentFile, file.errorString())); + } else { + auto setPlainText = [&](const QString& text) { QString fontFamily = APPLICATION->settings()->get("ConsoleFont").toString(); bool conversionOk = false; int fontSize = APPLICATION->settings()->get("ConsoleFontSize").toInt(&conversionOk); - if(!conversionOk) - { + if (!conversionOk) { fontSize = 11; } - QTextDocument *doc = ui->text->document(); + QTextDocument* doc = ui->text->document(); doc->setDefaultFont(QFont(fontFamily, fontSize)); ui->text->setPlainText(text); }; - auto showTooBig = [&]() - { - setPlainText( - tr("The file (%1) is too big. You may want to open it in a viewer optimized " - "for large files.").arg(file.fileName())); + auto showTooBig = [&]() { + setPlainText(tr("The file (%1) is too big. You may want to open it in a viewer optimized " + "for large files.") + .arg(file.fileName())); }; - if(file.size() > (1024ll * 1024ll * 12ll)) - { + if (file.size() > (1024ll * 1024ll * 12ll)) { showTooBig(); return; } QString content; - if(file.fileName().endsWith(".gz")) - { + if (file.fileName().endsWith(".gz")) { QByteArray temp; - if(!GZip::unzip(file.readAll(), temp)) - { - setPlainText( - tr("The file (%1) is not readable.").arg(file.fileName())); + if (!GZip::unzip(file.readAll(), temp)) { + setPlainText(tr("The file (%1) is not readable.").arg(file.fileName())); return; } content = QString::fromUtf8(temp); - } - else - { + } else { content = QString::fromUtf8(file.readAll()); } - if (content.size() >= 50000000ll) - { + if (content.size() >= 50000000ll) { showTooBig(); return; } @@ -215,8 +189,7 @@ void OtherLogsPage::on_btnCopy_clicked() void OtherLogsPage::on_btnDelete_clicked() { - if(m_currentFile.isEmpty()) - { + if (m_currentFile.isEmpty()) { setControlsEnabled(false); return; } @@ -230,36 +203,27 @@ void OtherLogsPage::on_btnDelete_clicked() } QFile file(FS::PathCombine(m_path, m_currentFile)); - if (FS::trash(file.fileName())) - { + if (FS::trash(file.fileName())) { return; } - if (!file.remove()) - { - QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2") - .arg(m_currentFile, file.errorString())); + if (!file.remove()) { + QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2").arg(m_currentFile, file.errorString())); } } - - void OtherLogsPage::on_btnClean_clicked() { auto toDelete = m_watcher->files(); - if(toDelete.isEmpty()) - { + if (toDelete.isEmpty()) { return; } - QMessageBox *messageBox = new QMessageBox(this); + QMessageBox* messageBox = new QMessageBox(this); messageBox->setWindowTitle(tr("Confirm Cleanup")); - if(toDelete.size() > 5) - { + if (toDelete.size() > 5) { messageBox->setText(tr("Are you sure you want to delete all log files?")); messageBox->setDetailedText(toDelete.join('\n')); - } - else - { + } else { messageBox->setText(tr("Are you sure you want to delete all these files?\n%1").arg(toDelete.join('\n'))); } messageBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); @@ -268,34 +232,26 @@ void OtherLogsPage::on_btnClean_clicked() messageBox->setIcon(QMessageBox::Question); messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction); - if (messageBox->exec() != QMessageBox::Ok) - { + if (messageBox->exec() != QMessageBox::Ok) { return; } QStringList failed; - for(auto item: toDelete) - { + for (auto item : toDelete) { QFile file(FS::PathCombine(m_path, item)); - if (FS::trash(file.fileName())) - { + if (FS::trash(file.fileName())) { continue; } - if (!file.remove()) - { + if (!file.remove()) { failed.push_back(item); } } - if(!failed.empty()) - { - QMessageBox *messageBoxFailure = new QMessageBox(this); + if (!failed.empty()) { + QMessageBox* messageBoxFailure = new QMessageBox(this); messageBoxFailure->setWindowTitle(tr("Error")); - if(failed.size() > 5) - { + if (failed.size() > 5) { messageBoxFailure->setText(tr("Couldn't delete some files!")); messageBoxFailure->setDetailedText(failed.join('\n')); - } - else - { + } else { messageBoxFailure->setText(tr("Couldn't delete some files:\n%1").arg(failed.join('\n'))); } messageBoxFailure->setStandardButtons(QMessageBox::Ok); @@ -307,7 +263,6 @@ void OtherLogsPage::on_btnClean_clicked() } } - void OtherLogsPage::setControlsEnabled(const bool enabled) { ui->btnReload->setEnabled(enabled); @@ -319,7 +274,7 @@ void OtherLogsPage::setControlsEnabled(const bool enabled) } // FIXME: HACK, use LogView instead? -static void findNext(QPlainTextEdit * _this, const QString& what, bool reverse) +static void findNext(QPlainTextEdit* _this, const QString& what, bool reverse) { _this->find(what, reverse ? QTextDocument::FindFlag::FindBackward : QTextDocument::FindFlag(0)); } @@ -344,8 +299,7 @@ void OtherLogsPage::findPreviousActivated() void OtherLogsPage::findActivated() { // focus the search bar if it doesn't have focus - if (!ui->searchBar->hasFocus()) - { + if (!ui->searchBar->hasFocus()) { ui->searchBar->setFocus(); ui->searchBar->selectAll(); } diff --git a/launcher/ui/pages/instance/OtherLogsPage.h b/launcher/ui/pages/instance/OtherLogsPage.h index 95591638..ecb896fc 100644 --- a/launcher/ui/pages/instance/OtherLogsPage.h +++ b/launcher/ui/pages/instance/OtherLogsPage.h @@ -37,47 +37,33 @@ #include -#include "ui/pages/BasePage.h" #include #include +#include "ui/pages/BasePage.h" -namespace Ui -{ +namespace Ui { class OtherLogsPage; } class RecursiveFileSystemWatcher; -class OtherLogsPage : public QWidget, public BasePage -{ +class OtherLogsPage : public QWidget, public BasePage { Q_OBJECT -public: - explicit OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent = 0); + public: + explicit OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget* parent = 0); ~OtherLogsPage(); - QString id() const override - { - return "logs"; - } - QString displayName() const override - { - return tr("Other logs"); - } - QIcon icon() const override - { - return APPLICATION->getThemedIcon("log"); - } - QString helpPage() const override - { - return "Minecraft-Logs"; - } + QString id() const override { return "logs"; } + QString displayName() const override { return tr("Other logs"); } + QIcon icon() const override { return APPLICATION->getThemedIcon("log"); } + QString helpPage() const override { return "Minecraft-Logs"; } void retranslate() override; void openedImpl() override; void closedImpl() override; -private slots: + private slots: void populateSelectLogBox(); void on_selectLogBox_currentIndexChanged(const int index); void on_btnReload_clicked(); @@ -91,13 +77,13 @@ private slots: void findNextActivated(); void findPreviousActivated(); -private: + private: void setControlsEnabled(const bool enabled); -private: - Ui::OtherLogsPage *ui; + private: + Ui::OtherLogsPage* ui; QString m_path; QString m_currentFile; IPathMatcher::Ptr m_fileFilter; - RecursiveFileSystemWatcher *m_watcher; + RecursiveFileSystemWatcher* m_watcher; }; diff --git a/launcher/ui/pages/instance/ResourcePackPage.h b/launcher/ui/pages/instance/ResourcePackPage.h index b04aa2e9..cb84ca96 100644 --- a/launcher/ui/pages/instance/ResourcePackPage.h +++ b/launcher/ui/pages/instance/ResourcePackPage.h @@ -42,11 +42,10 @@ #include "minecraft/mod/ResourcePackFolderModel.h" -class ResourcePackPage : public ExternalResourcesPage -{ +class ResourcePackPage : public ExternalResourcesPage { Q_OBJECT -public: - explicit ResourcePackPage(MinecraftInstance *instance, std::shared_ptr model, QWidget *parent = 0); + public: + explicit ResourcePackPage(MinecraftInstance* instance, std::shared_ptr model, QWidget* parent = 0); QString displayName() const override { return tr("Resource packs"); } QIcon icon() const override { return APPLICATION->getThemedIcon("resourcepacks"); } @@ -55,12 +54,10 @@ public: virtual bool shouldDisplay() const override { - return !m_instance->traits().contains("no-texturepacks") && - !m_instance->traits().contains("texturepacks"); + return !m_instance->traits().contains("no-texturepacks") && !m_instance->traits().contains("texturepacks"); } public slots: bool onSelectionChanged(const QModelIndex& current, const QModelIndex& previous) override; void downloadRPs(); }; - diff --git a/launcher/ui/pages/instance/ScreenshotsPage.cpp b/launcher/ui/pages/instance/ScreenshotsPage.cpp index bcce5f57..29c835fc 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.cpp +++ b/launcher/ui/pages/instance/ScreenshotsPage.cpp @@ -39,52 +39,50 @@ #include "BuildConfig.h" #include "ui_ScreenshotsPage.h" -#include -#include -#include -#include +#include +#include #include #include -#include -#include -#include -#include -#include #include +#include +#include #include +#include +#include +#include #include +#include +#include #include -#include "ui/dialogs/ProgressDialog.h" #include "ui/dialogs/CustomMessageBox.h" +#include "ui/dialogs/ProgressDialog.h" #include "net/NetJob.h" -#include "screenshots/ImgurUpload.h" #include "screenshots/ImgurAlbumCreation.h" +#include "screenshots/ImgurUpload.h" #include "tasks/SequentialTask.h" -#include "RWStorage.h" -#include #include +#include +#include "RWStorage.h" typedef RWStorage SharedIconCache; typedef std::shared_ptr SharedIconCachePtr; -class ThumbnailingResult : public QObject -{ +class ThumbnailingResult : public QObject { Q_OBJECT -public slots: - inline void emitResultsReady(const QString &path) { emit resultsReady(path); } - inline void emitResultsFailed(const QString &path) { emit resultsFailed(path); } -signals: - void resultsReady(const QString &path); - void resultsFailed(const QString &path); + public slots: + inline void emitResultsReady(const QString& path) { emit resultsReady(path); } + inline void emitResultsFailed(const QString& path) { emit resultsFailed(path); } + signals: + void resultsReady(const QString& path); + void resultsFailed(const QString& path); }; -class ThumbnailRunnable : public QRunnable -{ -public: +class ThumbnailRunnable : public QRunnable { + public: ThumbnailRunnable(QString path, SharedIconCachePtr cache) { m_path = path; @@ -129,57 +127,50 @@ public: // this is about as elegant and well written as a bag of bricks with scribbles done by insane // asylum patients. -class FilterModel : public QIdentityProxyModel -{ +class FilterModel : public QIdentityProxyModel { Q_OBJECT -public: - explicit FilterModel(QObject *parent = 0) : QIdentityProxyModel(parent) + public: + explicit FilterModel(QObject* parent = 0) : QIdentityProxyModel(parent) { m_thumbnailingPool.setMaxThreadCount(4); m_thumbnailCache = std::make_shared(); m_thumbnailCache->add("placeholder", APPLICATION->getThemedIcon("screenshot-placeholder")); connect(&watcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString))); } - virtual ~FilterModel() { + virtual ~FilterModel() + { m_thumbnailingPool.clear(); if (!m_thumbnailingPool.waitForDone(500)) qDebug() << "Thumbnail pool took longer than 500ms to finish"; } - virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const + virtual QVariant data(const QModelIndex& proxyIndex, int role = Qt::DisplayRole) const { auto model = sourceModel(); if (!model) return QVariant(); - if (role == Qt::DisplayRole || role == Qt::EditRole) - { + if (role == Qt::DisplayRole || role == Qt::EditRole) { QVariant result = sourceModel()->data(mapToSource(proxyIndex), role); return result.toString().remove(QRegularExpression("\\.png$")); } - if (role == Qt::DecorationRole) - { - QVariant result = - sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole); + if (role == Qt::DecorationRole) { + QVariant result = sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole); QString filePath = result.toString(); QIcon temp; - if (!watched.contains(filePath)) - { - ((QFileSystemWatcher &)watcher).addPath(filePath); - ((QSet &)watched).insert(filePath); + if (!watched.contains(filePath)) { + ((QFileSystemWatcher&)watcher).addPath(filePath); + ((QSet&)watched).insert(filePath); } - if (m_thumbnailCache->get(filePath, temp)) - { + if (m_thumbnailCache->get(filePath, temp)) { return temp; } - if (!m_failed.contains(filePath)) - { - ((FilterModel *)this)->thumbnailImage(filePath); + if (!m_failed.contains(filePath)) { + ((FilterModel*)this)->thumbnailImage(filePath); } return (m_thumbnailCache->get("placeholder")); } return sourceModel()->data(mapToSource(proxyIndex), role); } - virtual bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole) + virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) { auto model = sourceModel(); if (!model) @@ -189,23 +180,21 @@ public: // FIXME: this is a workaround for a bug in QFileSystemModel, where it doesn't // sort after renames { - ((QFileSystemModel *)model)->setNameFilterDisables(true); - ((QFileSystemModel *)model)->setNameFilterDisables(false); + ((QFileSystemModel*)model)->setNameFilterDisables(true); + ((QFileSystemModel*)model)->setNameFilterDisables(false); } return model->setData(mapToSource(index), value.toString() + ".png", role); } -private: + private: void thumbnailImage(QString path) { auto runnable = new ThumbnailRunnable(path, m_thumbnailCache); - connect(&(runnable->m_resultEmitter), SIGNAL(resultsReady(QString)), - SLOT(thumbnailReady(QString))); - connect(&(runnable->m_resultEmitter), SIGNAL(resultsFailed(QString)), - SLOT(thumbnailFailed(QString))); - ((QThreadPool &)m_thumbnailingPool).start(runnable); + connect(&(runnable->m_resultEmitter), SIGNAL(resultsReady(QString)), SLOT(thumbnailReady(QString))); + connect(&(runnable->m_resultEmitter), SIGNAL(resultsFailed(QString)), SLOT(thumbnailFailed(QString))); + ((QThreadPool&)m_thumbnailingPool).start(runnable); } -private slots: + private slots: void thumbnailReady(QString path) { emit layoutChanged(); } void thumbnailFailed(QString path) { m_failed.insert(path); } void fileChanged(QString filepath) @@ -219,7 +208,7 @@ private slots: } } -private: + private: SharedIconCachePtr m_thumbnailCache; QThreadPool m_thumbnailingPool; QSet m_failed; @@ -227,18 +216,15 @@ private: QFileSystemWatcher watcher; }; -class CenteredEditingDelegate : public QStyledItemDelegate -{ -public: - explicit CenteredEditingDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {} +class CenteredEditingDelegate : public QStyledItemDelegate { + public: + explicit CenteredEditingDelegate(QObject* parent = 0) : QStyledItemDelegate(parent) {} virtual ~CenteredEditingDelegate() {} - virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { auto widget = QStyledItemDelegate::createEditor(parent, option, index); - auto foo = dynamic_cast(widget); - if (foo) - { + auto foo = dynamic_cast(widget); + if (foo) { foo->setAlignment(Qt::AlignHCenter); foo->setFrame(true); foo->setMaximumWidth(192); @@ -247,15 +233,14 @@ public: } }; -ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent) - : QMainWindow(parent), ui(new Ui::ScreenshotsPage) +ScreenshotsPage::ScreenshotsPage(QString path, QWidget* parent) : QMainWindow(parent), ui(new Ui::ScreenshotsPage) { m_model.reset(new QFileSystemModel()); m_filterModel.reset(new FilterModel()); m_filterModel->setSourceModel(m_model.get()); m_model->setFilter(QDir::Files); m_model->setReadOnly(false); - m_model->setNameFilters({"*.png"}); + m_model->setNameFilters({ "*.png" }); m_model->setNameFilterDisables(false); m_folder = path; m_valid = FS::ensureFolderPathExists(m_folder); @@ -278,31 +263,29 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent) connect(ui->listView, SIGNAL(activated(QModelIndex)), SLOT(onItemActivated(QModelIndex))); } -bool ScreenshotsPage::eventFilter(QObject *obj, QEvent *evt) +bool ScreenshotsPage::eventFilter(QObject* obj, QEvent* evt) { if (obj != ui->listView) return QWidget::eventFilter(obj, evt); - if (evt->type() != QEvent::KeyPress) - { + if (evt->type() != QEvent::KeyPress) { return QWidget::eventFilter(obj, evt); } - QKeyEvent *keyEvent = static_cast(evt); + QKeyEvent* keyEvent = static_cast(evt); if (keyEvent->matches(QKeySequence::Copy)) { on_actionCopy_File_s_triggered(); return true; } - switch (keyEvent->key()) - { - case Qt::Key_Delete: - on_actionDelete_triggered(); - return true; - case Qt::Key_F2: - on_actionRename_triggered(); - return true; - default: - break; + switch (keyEvent->key()) { + case Qt::Key_Delete: + on_actionDelete_triggered(); + return true; + case Qt::Key_F2: + on_actionRename_triggered(); + return true; + default: + break; } return QWidget::eventFilter(obj, evt); } @@ -322,17 +305,17 @@ void ScreenshotsPage::ShowContextMenu(const QPoint& pos) auto menu = ui->toolBar->createContextMenu(this, tr("Context menu")); if (ui->listView->selectionModel()->selectedRows().size() > 1) { - menu->removeAction( ui->actionCopy_Image ); + menu->removeAction(ui->actionCopy_Image); } menu->exec(ui->listView->mapToGlobal(pos)); delete menu; } -QMenu * ScreenshotsPage::createPopupMenu() +QMenu* ScreenshotsPage::createPopupMenu() { QMenu* filteredMenu = QMainWindow::createPopupMenu(); - filteredMenu->removeAction( ui->toolBar->toggleViewAction() ); + filteredMenu->removeAction(ui->toolBar->toggleViewAction()); return filteredMenu; } @@ -345,13 +328,12 @@ void ScreenshotsPage::onItemActivated(QModelIndex index) DesktopServices::openFile(info.absoluteFilePath()); } -void ScreenshotsPage::onCurrentSelectionChanged(const QItemSelection &selected) +void ScreenshotsPage::onCurrentSelectionChanged(const QItemSelection& selected) { bool allReadable = !selected.isEmpty(); bool allWritable = !selected.isEmpty(); - for (auto index : selected.indexes()) - { + for (auto index : selected.indexes()) { if (!index.isValid()) break; auto info = m_model->fileInfo(index); @@ -401,8 +383,7 @@ void ScreenshotsPage::on_actionUpload_triggered() QList uploaded; auto job = NetJob::Ptr(new NetJob("Screenshot Upload", APPLICATION->network())); - if(selection.size() < 2) - { + if (selection.size() < 2) { auto item = selection.at(0); auto info = m_model->fileInfo(item); auto screenshot = std::make_shared(info); @@ -411,31 +392,24 @@ void ScreenshotsPage::on_actionUpload_triggered() m_uploadActive = true; ProgressDialog dialog(this); - if(dialog.execWithTask(job.get()) != QDialog::Accepted) - { - CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), - tr("Unknown error"), QMessageBox::Warning)->exec(); - } - else - { + if (dialog.execWithTask(job.get()) != QDialog::Accepted) { + CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), tr("Unknown error"), QMessageBox::Warning)->exec(); + } else { auto link = screenshot->m_url; - QClipboard *clipboard = QApplication::clipboard(); + QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(link); CustomMessageBox::selectable( - this, - tr("Upload finished"), - tr("The link to the uploaded screenshot has been placed in your clipboard.") - .arg(link), - QMessageBox::Information - )->exec(); + this, tr("Upload finished"), + tr("The link to the uploaded screenshot has been placed in your clipboard.").arg(link), + QMessageBox::Information) + ->exec(); } m_uploadActive = false; return; } - for (auto item : selection) - { + for (auto item : selection) { auto info = m_model->fileInfo(item); auto screenshot = std::make_shared(info); uploaded.push_back(screenshot); @@ -449,26 +423,16 @@ void ScreenshotsPage::on_actionUpload_triggered() task.addTask(albumTask); m_uploadActive = true; ProgressDialog prog(this); - if (prog.execWithTask(&task) != QDialog::Accepted) - { - CustomMessageBox::selectable( - this, - tr("Failed to upload screenshots!"), - tr("Unknown error"), - QMessageBox::Warning - )->exec(); - } - else - { + if (prog.execWithTask(&task) != QDialog::Accepted) { + CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), tr("Unknown error"), QMessageBox::Warning)->exec(); + } else { auto link = QString("https://imgur.com/a/%1").arg(imgurAlbum->id()); - QClipboard *clipboard = QApplication::clipboard(); + QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(link); - CustomMessageBox::selectable( - this, - tr("Upload finished"), - tr("The link to the uploaded album has been placed in your clipboard.") .arg(link), - QMessageBox::Information - )->exec(); + CustomMessageBox::selectable(this, tr("Upload finished"), + tr("The link to the uploaded album has been placed in your clipboard.").arg(link), + QMessageBox::Information) + ->exec(); } m_uploadActive = false; } @@ -476,8 +440,7 @@ void ScreenshotsPage::on_actionUpload_triggered() void ScreenshotsPage::on_actionCopy_Image_triggered() { auto selection = ui->listView->selectionModel()->selectedRows(); - if(selection.size() < 1) - { + if (selection.size() < 1) { return; } @@ -492,15 +455,13 @@ void ScreenshotsPage::on_actionCopy_Image_triggered() void ScreenshotsPage::on_actionCopy_File_s_triggered() { auto selection = ui->listView->selectionModel()->selectedRows(); - if(selection.size() < 1) - { + if (selection.size() < 1) { // Don't do anything so we don't empty the users clipboard return; } QString buf = ""; - for (auto item : selection) - { + for (auto item : selection) { auto info = m_model->fileInfo(item); buf += "file:///" + info.absoluteFilePath() + "\r\n"; } @@ -532,8 +493,7 @@ void ScreenshotsPage::on_actionDelete_triggered() if (response != QMessageBox::Yes) return; - for (auto item : selected) - { + for (auto item : selected) { if (FS::trash(m_model->filePath(item))) continue; @@ -552,23 +512,19 @@ void ScreenshotsPage::on_actionRename_triggered() void ScreenshotsPage::openedImpl() { - if(!m_valid) - { + if (!m_valid) { m_valid = FS::ensureFolderPathExists(m_folder); } - if (m_valid) - { + if (m_valid) { QString path = QDir(m_folder).absolutePath(); auto idx = m_model->setRootPath(path); - if(idx.isValid()) - { + if (idx.isValid()) { ui->listView->setModel(m_filterModel.get()); - connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ScreenshotsPage::onCurrentSelectionChanged); - onCurrentSelectionChanged(ui->listView->selectionModel()->selection()); // set initial button enable states + connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged, this, + &ScreenshotsPage::onCurrentSelectionChanged); + onCurrentSelectionChanged(ui->listView->selectionModel()->selection()); // set initial button enable states ui->listView->setRootIndex(m_filterModel->mapFromSource(idx)); - } - else - { + } else { ui->listView->setModel(nullptr); } } diff --git a/launcher/ui/pages/instance/ScreenshotsPage.h b/launcher/ui/pages/instance/ScreenshotsPage.h index 89611b6d..0f824a05 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.h +++ b/launcher/ui/pages/instance/ScreenshotsPage.h @@ -37,16 +37,15 @@ #include -#include "ui/pages/BasePage.h" #include +#include "ui/pages/BasePage.h" #include "settings/Setting.h" class QFileSystemModel; class QIdentityProxyModel; class QItemSelection; -namespace Ui -{ +namespace Ui { class ScreenshotsPage; } @@ -54,49 +53,30 @@ struct