Finish of the OtherLogs page, and (re)format page related files

This commit is contained in:
Jan Dalheimer 2014-07-12 23:02:52 +02:00 committed by Petr Mrázek
parent 5c43842359
commit 4c0dc51110
35 changed files with 423 additions and 356 deletions

View File

@ -9,6 +9,7 @@ NamespaceIndentation: None
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
ColumnLimit: 96
MaxEmptyLinesToKeep: 1

View File

@ -14,18 +14,20 @@
*/
#include "PageDialog.h"
#include "gui/Platform.h"
#include "MultiMC.h"
#include "logic/settings/SettingsObject.h"
#include <gui/widgets/IconLabel.h>
#include <gui/widgets/PageContainer.h>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QtGui/QKeyEvent>
#include <QKeyEvent>
PageDialog::PageDialog(BasePageProviderPtr pageProvider, QString defaultId, QWidget *parent) : QDialog(parent)
#include "MultiMC.h"
#include "logic/settings/SettingsObject.h"
#include "gui/Platform.h"
#include "gui/widgets/IconLabel.h"
#include "gui/widgets/PageContainer.h"
PageDialog::PageDialog(BasePageProviderPtr pageProvider, QString defaultId, QWidget *parent)
: QDialog(parent)
{
MultiMCPlatform::fixWM_CLASS(this);
setWindowTitle(pageProvider->dialogTitle());
@ -34,23 +36,25 @@ PageDialog::PageDialog(BasePageProviderPtr pageProvider, QString defaultId, QWid
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(m_container);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0,0,0,0);
mainLayout->setContentsMargins(0, 0, 0, 0);
setLayout(mainLayout);
QDialogButtonBox *buttons =
new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Close);
buttons->button(QDialogButtonBox::Close)->setDefault(true);
m_container->addButtons(buttons);
connect(buttons->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(close()));
connect(buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), m_container, SLOT(help()));
connect(buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), m_container,
SLOT(help()));
restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("PagedGeometry").toByteArray()));
restoreGeometry(
QByteArray::fromBase64(MMC->settings()->get("PagedGeometry").toByteArray()));
}
void PageDialog::closeEvent(QCloseEvent * event)
void PageDialog::closeEvent(QCloseEvent *event)
{
if(m_container->requestClose(event))
if (m_container->requestClose(event))
{
MMC->settings()->set("PagedGeometry", saveGeometry().toBase64());
QDialog::closeEvent(event);

View File

@ -14,8 +14,9 @@
*/
#pragma once
#include <QDialog>
#include <gui/pages/BasePageProvider.h>
#include "gui/pages/BasePageProvider.h"
class PageContainer;
class PageDialog : public QDialog
@ -24,7 +25,7 @@ class PageDialog : public QDialog
public:
explicit PageDialog(BasePageProviderPtr pageProvider, QString defaultId = QString(),
QWidget *parent = 0);
virtual ~PageDialog() {};
virtual ~PageDialog() {}
private
slots:

View File

@ -14,6 +14,7 @@
*/
#pragma once
#include <QString>
#include <QIcon>
#include <memory>
@ -21,28 +22,15 @@
class BasePage
{
public:
virtual ~BasePage(){}
virtual ~BasePage() {}
virtual QString id() const = 0;
virtual QString displayName() const = 0;
virtual QIcon icon() const = 0;
virtual bool apply()
{
return true;
}
virtual bool shouldDisplay() const
{
return true;
}
virtual QString helpPage() const
{
return QString();
}
virtual void opened()
{
}
virtual void closed()
{
}
virtual bool apply() { return true; }
virtual bool shouldDisplay() const { return true; }
virtual QString helpPage() const { return QString(); }
virtual void opened() {}
virtual void closed() {}
int stackIndex = -1;
int listIndex = -1;
};

View File

@ -1,27 +1,14 @@
#include "InstanceSettingsPage.h"
#include <gui/dialogs/VersionSelectDialog.h>
#include "logic/NagUtils.h"
#include <logic/java/JavaVersionList.h>
#include "MultiMC.h"
#include <QDialog>
#include <QFileDialog>
#include <QMessageBox>
#include "ui_InstanceSettingsPage.h"
QString InstanceSettingsPage::displayName() const
{
return tr("Settings");
}
#include <QFileDialog>
#include <QDialog>
#include <QMessageBox>
QIcon InstanceSettingsPage::icon() const
{
return QIcon::fromTheme("settings");
}
QString InstanceSettingsPage::id() const
{
return "settings";
}
#include "gui/dialogs/VersionSelectDialog.h"
#include "logic/NagUtils.h"
#include "logic/java/JavaVersionList.h"
#include "MultiMC.h"
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)

View File

@ -14,11 +14,12 @@
*/
#pragma once
#include <QWidget>
#include <logic/OneSixInstance.h>
#include <logic/net/NetJob.h>
#include <logic/java/JavaChecker.h>
#include "logic/OneSixInstance.h"
#include "logic/net/NetJob.h"
#include "logic/java/JavaChecker.h"
#include "BasePage.h"
class JavaChecker;
@ -34,11 +35,23 @@ class InstanceSettingsPage : public QWidget, public BasePage
public:
explicit InstanceSettingsPage(BaseInstance *inst, QWidget *parent = 0);
virtual ~InstanceSettingsPage();
virtual QString displayName() const override;
virtual QIcon icon() const override;
virtual QString id() const override;
virtual QString displayName() const override
{
return tr("Settings");
}
virtual QIcon icon() const override
{
return QIcon::fromTheme("settings");
}
virtual QString id() const override
{
return "settings";
}
virtual bool apply();
virtual QString helpPage() const override { return "Instance-settings"; }
virtual QString helpPage() const override
{
return "Instance-settings";
}
virtual bool shouldDisplay() const;
private slots:
void on_javaDetectBtn_clicked();
@ -51,6 +64,7 @@ private slots:
void applySettings();
void loadSettings();
private:
Ui::InstanceSettingsPage *ui;
BaseInstance *m_instance;

View File

@ -15,6 +15,13 @@
#include "LegacyJarModPage.h"
#include "ui_LegacyJarModPage.h"
#include <QKeyEvent>
#include <QFileDialog>
#include <QKeyEvent>
#include <pathutils.h>
#include "gui/dialogs/VersionSelectDialog.h"
#include "gui/dialogs/ProgressDialog.h"
#include "gui/dialogs/ModEditDialogCommon.h"
@ -23,10 +30,6 @@
#include "logic/forge/ForgeVersion.h"
#include "logic/forge/ForgeVersionList.h"
#include "MultiMC.h"
#include <pathutils.h>
#include <QtGui/QKeyEvent>
#include <QFileDialog>
#include <QKeyEvent>
LegacyJarModPage::LegacyJarModPage(LegacyInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::LegacyJarModPage), m_inst(inst)
@ -49,26 +52,11 @@ LegacyJarModPage::~LegacyJarModPage()
delete ui;
}
QString LegacyJarModPage::displayName() const
{
return tr("Jar Mods");
}
bool LegacyJarModPage::shouldDisplay() const
{
return !m_inst->isRunning();
}
QIcon LegacyJarModPage::icon() const
{
return QIcon::fromTheme("plugin-red");
}
QString LegacyJarModPage::id() const
{
return "jarmods";
}
bool LegacyJarModPage::eventFilter(QObject *obj, QEvent *ev)
{
if (ev->type() != QEvent::KeyPress || obj != ui->jarModsTreeView)

View File

@ -15,8 +15,9 @@
#pragma once
#include <QDialog>
#include <logic/net/NetJob.h>
#include <QWidget>
#include "logic/net/NetJob.h"
#include "BasePage.h"
class ModList;
@ -34,10 +35,22 @@ public:
explicit LegacyJarModPage(LegacyInstance *inst, QWidget *parent = 0);
virtual ~LegacyJarModPage();
virtual QString displayName() const;
virtual QIcon icon() const;
virtual QString id() const;
virtual QString helpPage() const override { return "Legacy-jar-mods"; }
virtual QString displayName() const
{
return tr("Jar Mods");
}
virtual QIcon icon() const
{
return QIcon::fromTheme("plugin-red");
}
virtual QString id() const
{
return "jarmods";
}
virtual QString helpPage() const override
{
return "Legacy-jar-mods";
}
virtual bool shouldDisplay() const;
private

View File

@ -1,21 +1,7 @@
#include "LegacyUpgradePage.h"
#include <logic/LegacyInstance.h>
#include "ui_LegacyUpgradePage.h"
QString LegacyUpgradePage::displayName() const
{
return tr("Upgrade");
}
QIcon LegacyUpgradePage::icon() const
{
return QIcon::fromTheme("checkupdate");
}
QString LegacyUpgradePage::id() const
{
return "upgrade";
}
#include "logic/LegacyInstance.h"
LegacyUpgradePage::LegacyUpgradePage(LegacyInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::LegacyUpgradePage), m_inst(inst)

View File

@ -14,10 +14,11 @@
*/
#pragma once
#include <QWidget>
#include <logic/OneSixInstance.h>
#include <logic/net/NetJob.h>
#include "logic/OneSixInstance.h"
#include "logic/net/NetJob.h"
#include "BasePage.h"
class EnabledItemFilter;
@ -33,10 +34,22 @@ class LegacyUpgradePage : public QWidget, public BasePage
public:
explicit LegacyUpgradePage(LegacyInstance *inst, QWidget *parent = 0);
virtual ~LegacyUpgradePage();
virtual QString displayName() const override;
virtual QIcon icon() const override;
virtual QString id() const override;
virtual QString helpPage() const override { return "Legacy-upgrade"; }
virtual QString displayName() const override
{
return tr("Upgrade");
}
virtual QIcon icon() const override
{
return QIcon::fromTheme("checkupdate");
}
virtual QString id() const override
{
return "upgrade";
}
virtual QString helpPage() const override
{
return "Legacy-upgrade";
}
virtual bool shouldDisplay() const;
private
slots:

View File

@ -7,21 +7,6 @@
#include "logic/MinecraftProcess.h"
#include "gui/GuiUtil.h"
QString LogPage::displayName() const
{
return tr("Minecraft Log");
}
QIcon LogPage::icon() const
{
return QIcon::fromTheme("refresh");
}
QString LogPage::id() const
{
return "console";
}
LogPage::LogPage(MinecraftProcess *proc, QWidget *parent)
: QWidget(parent), ui(new Ui::LogPage), m_process(proc)
{

View File

@ -13,13 +13,13 @@
* limitations under the License.
*/
#pragma once
#include <QWidget>
#include <logic/BaseInstance.h>
#include <logic/net/NetJob.h>
#include <logic/MinecraftProcess.h>
#include "logic/BaseInstance.h"
#include "logic/net/NetJob.h"
#include "logic/MinecraftProcess.h"
#include "BasePage.h"
class EnabledItemFilter;
@ -36,11 +36,23 @@ class LogPage : public QWidget, public BasePage
public:
explicit LogPage(MinecraftProcess *proc, QWidget *parent = 0);
virtual ~LogPage();
virtual QString displayName() const override;
virtual QIcon icon() const override;
virtual QString id() const override;
virtual QString displayName() const override
{
return tr("Minecraft Log");
}
virtual QIcon icon() const override
{
return QIcon::fromTheme("log");
}
virtual QString id() const override
{
return "console";
}
virtual bool apply();
virtual QString helpPage() const override { return "Minecraft-Log"; }
virtual QString helpPage() const override
{
return "Minecraft-Log";
}
virtual bool shouldDisplay() const;
private:
@ -64,7 +76,7 @@ private slots:
void on_btnPaste_clicked();
void on_btnCopy_clicked();
void on_btnClear_clicked();
private:
Ui::LogPage *ui;
MinecraftProcess *m_process;

View File

@ -13,9 +13,9 @@
* limitations under the License.
*/
#include "MultiMC.h"
#include "ModFolderPage.h"
#include "ui_ModFolderPage.h"
#include <pathutils.h>
#include <QFileDialog>
#include <QMessageBox>
#include <QEvent>
@ -23,33 +23,18 @@
#include <QDesktopServices>
#include <QAbstractItemModel>
#include "ModFolderPage.h"
#include "ui_ModFolderPage.h"
#include <pathutils.h>
#include "MultiMC.h"
#include "gui/dialogs/CustomMessageBox.h"
#include "gui/dialogs/ModEditDialogCommon.h"
#include "logic/ModList.h"
#include "logic/Mod.h"
#include <logic/VersionFilterData.h>
#include "logic/VersionFilterData.h"
QString ModFolderPage::displayName() const
{
return m_displayName;
}
QIcon ModFolderPage::icon() const
{
return QIcon::fromTheme(m_iconName);
}
QString ModFolderPage::id() const
{
return m_id;
}
ModFolderPage::ModFolderPage(BaseInstance * inst, std::shared_ptr<ModList> mods, QString id, QString iconName,
QString displayName, QString helpPage, QWidget *parent)
ModFolderPage::ModFolderPage(BaseInstance *inst, std::shared_ptr<ModList> mods, QString id,
QString iconName, QString displayName, QString helpPage,
QWidget *parent)
: QWidget(parent), ui(new Ui::ModFolderPage)
{
ui->setupUi(this);
@ -82,7 +67,7 @@ ModFolderPage::~ModFolderPage()
bool ModFolderPage::shouldDisplay() const
{
if(m_inst)
if (m_inst)
return !m_inst->isRunning();
return true;
}
@ -91,13 +76,13 @@ bool CoreModFolderPage::shouldDisplay() const
{
if (ModFolderPage::shouldDisplay())
{
auto inst = dynamic_cast<OneSixInstance*>(m_inst);
if(!inst)
auto inst = dynamic_cast<OneSixInstance *>(m_inst);
if (!inst)
return true;
auto version = inst->getFullVersion();
if(!version)
if (!version)
return true;
if(version->m_releaseTime < g_VersionFilterData.legacyCutoffDate)
if (version->m_releaseTime < g_VersionFilterData.legacyCutoffDate)
{
return true;
}

View File

@ -14,10 +14,11 @@
*/
#pragma once
#include <QWidget>
#include <logic/OneSixInstance.h>
#include <logic/net/NetJob.h>
#include "logic/OneSixInstance.h"
#include "logic/net/NetJob.h"
#include "BasePage.h"
class EnabledItemFilter;
@ -36,9 +37,18 @@ public:
QString iconName, QString displayName, QString helpPage = "",
QWidget *parent = 0);
virtual ~ModFolderPage();
virtual QString displayName() const override;
virtual QIcon icon() const override;
virtual QString id() const override;
virtual QString displayName() const override
{
return m_displayName;
}
virtual QIcon icon() const override
{
return QIcon::fromTheme(m_iconName);
}
virtual QString id() const override
{
return m_id;
}
virtual QString helpPage() const override
{
return m_helpName;

View File

@ -1,21 +1,6 @@
#include "NotesPage.h"
#include "ui_NotesPage.h"
QString NotesPage::displayName() const
{
return tr("Notes");
}
QIcon NotesPage::icon() const
{
return QIcon::fromTheme("news");
}
QString NotesPage::id() const
{
return "notes";
}
NotesPage::NotesPage(BaseInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::NotesPage), m_inst(inst)
{

View File

@ -14,10 +14,11 @@
*/
#pragma once
#include <QWidget>
#include <logic/BaseInstance.h>
#include <logic/net/NetJob.h>
#include "logic/BaseInstance.h"
#include "logic/net/NetJob.h"
#include "BasePage.h"
class EnabledItemFilter;
@ -33,11 +34,23 @@ class NotesPage : public QWidget, public BasePage
public:
explicit NotesPage(BaseInstance *inst, QWidget *parent = 0);
virtual ~NotesPage();
virtual QString displayName() const override;
virtual QIcon icon() const override;
virtual QString id() const override;
virtual QString displayName() const override
{
return tr("Notes");
}
virtual QIcon icon() const override
{
return QIcon::fromTheme("news");
}
virtual QString id() const override
{
return "notes";
}
virtual bool apply();
virtual QString helpPage() const override { return "Notes"; }
virtual QString helpPage() const override
{
return "Notes";
}
private:
Ui::NotesPage *ui;

View File

@ -1,3 +1,18 @@
/* Copyright 2014 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "OtherLogsPage.h"
#include "ui_OtherLogsPage.h"
@ -8,28 +23,18 @@
#include "logic/RecursiveFileSystemWatcher.h"
#include "logic/BaseInstance.h"
OtherLogsPage::OtherLogsPage(BaseInstance *instance, QWidget *parent) :
QWidget(parent),
ui(new Ui::OtherLogsPage),
m_instance(instance),
m_watcher(new RecursiveFileSystemWatcher(this))
OtherLogsPage::OtherLogsPage(BaseInstance *instance, QWidget *parent)
: QWidget(parent), ui(new Ui::OtherLogsPage), m_instance(instance),
m_watcher(new RecursiveFileSystemWatcher(this))
{
ui->setupUi(this);
connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, [this]()
{
ui->selectLogBox->clear();
ui->selectLogBox->addItems(m_watcher->files());
ui->selectLogBox->addItem(tr("&Other"), true);
if (m_currentFile.isNull())
{
ui->selectLogBox->setCurrentIndex(-1);
}
else
{
const int index = ui->selectLogBox->findText(m_currentFile);
ui->selectLogBox->setCurrentIndex(-1);
}
});
m_watcher->setFileExpression(".*\\.log$");
m_watcher->setRootDir(QDir::current().absoluteFilePath(m_instance->minecraftRoot()));
connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, this,
&OtherLogsPage::populateSelectLogBox);
populateSelectLogBox();
}
OtherLogsPage::~OtherLogsPage()
@ -46,6 +51,22 @@ void OtherLogsPage::closed()
m_watcher->disable();
}
void OtherLogsPage::populateSelectLogBox()
{
ui->selectLogBox->clear();
ui->selectLogBox->addItems(m_watcher->files());
ui->selectLogBox->addItem(tr("Other"), true);
if (m_currentFile.isNull())
{
ui->selectLogBox->setCurrentIndex(-1);
}
else
{
const int index = ui->selectLogBox->findText(m_currentFile);
ui->selectLogBox->setCurrentIndex(index);
}
}
void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index)
{
QString file;
@ -53,7 +74,8 @@ void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index)
{
if (ui->selectLogBox->itemData(index).isValid())
{
file = QFileDialog::getOpenFileName(this, tr("Open log file"), m_instance->minecraftRoot(), tr("*.log;;*.txt;;*"));
file = QFileDialog::getOpenFileName(
this, tr("Open log file"), m_instance->minecraftRoot(), tr("*.log;;*.txt;;*"));
}
else
{
@ -61,9 +83,10 @@ void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index)
}
}
if (file.isEmpty() || !QFile::exists(file))
if (file.isEmpty() || !QFile::exists(m_instance->minecraftRoot() + "/" + file))
{
m_currentFile = QString();
ui->text->clear();
setControlsEnabled(false);
}
else
@ -76,13 +99,14 @@ void OtherLogsPage::on_selectLogBox_currentIndexChanged(const int index)
void OtherLogsPage::on_btnReload_clicked()
{
QFile file(m_currentFile);
QFile file(m_instance->minecraftRoot() + "/" + m_currentFile);
if (!file.open(QFile::ReadOnly))
{
setControlsEnabled(false);
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()));
QMessageBox::critical(this, tr("Error"), tr("Unable to open %1 for reading: %2")
.arg(m_currentFile, file.errorString()));
}
else
{
@ -100,15 +124,17 @@ void OtherLogsPage::on_btnCopy_clicked()
}
void OtherLogsPage::on_btnDelete_clicked()
{
if (QMessageBox::question(this, tr("Delete"), tr("Do you really want to delete %1?").arg(m_currentFile), QMessageBox::Yes, QMessageBox::No)
== QMessageBox::No)
if (QMessageBox::question(this, tr("Delete"),
tr("Do you really want to delete %1?").arg(m_currentFile),
QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
{
return;
}
QFile file(m_currentFile);
QFile file(m_instance->minecraftRoot() + "/" + m_currentFile);
if (!file.remove())
{
QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2").arg(m_currentFile, file.errorString()));
QMessageBox::critical(this, tr("Error"), tr("Unable to delete %1: %2")
.arg(m_currentFile, file.errorString()));
}
}

View File

@ -1,10 +1,26 @@
/* Copyright 2014 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QWidget>
#include "BasePage.h"
namespace Ui {
namespace Ui
{
class OtherLogsPage;
}
@ -20,15 +36,27 @@ public:
explicit OtherLogsPage(BaseInstance *instance, QWidget *parent = 0);
~OtherLogsPage();
QString id() const override { return "logs"; }
QString displayName() const override { return tr("Other logs"); }
QIcon icon() const override { return QIcon(); } // TODO
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 QIcon::fromTheme("log");
}
QString helpPage() const override
{
return "Minecraft-Logs";
}
void opened() override;
void closed() override;
private
slots:
private slots:
void populateSelectLogBox();
void on_selectLogBox_currentIndexChanged(const int index);
void on_btnReload_clicked();
void on_btnPaste_clicked();

View File

@ -39,7 +39,14 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="selectLogBox"/>
<widget class="QComboBox" name="selectLogBox">
<property name="maximumSize">
<size>
<width>96</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnReload">

View File

@ -5,8 +5,8 @@ class ResourcePackPage : public ModFolderPage
{
public:
explicit ResourcePackPage(BaseInstance *instance, QWidget *parent = 0)
: ModFolderPage(instance, instance->resourcePackList(), "resourcepacks", "resourcepacks",
tr("Resource packs"), "Resource-packs", parent)
: ModFolderPage(instance, instance->resourcePackList(), "resourcepacks",
"resourcepacks", tr("Resource packs"), "Resource-packs", parent)
{
}

View File

@ -9,10 +9,11 @@
#include <QFileSystemModel>
#include <QStyledItemDelegate>
#include <QLineEdit>
#include <QtGui/qevent.h>
#include <QtGui/QPainter>
#include <QtGui/QClipboard>
#include <QtGui/QDesktopServices>
#include <QEvent>
#include <QPainter>
#include <QClipboard>
#include <QDesktopServices>
#include <QKeyEvent>
#include <pathutils.h>
@ -24,30 +25,25 @@
#include "logic/tasks/SequentialTask.h"
#include "logic/RWStorage.h"
typedef RWStorage<QString, QIcon> SharedIconCache;
typedef std::shared_ptr<SharedIconCache> SharedIconCachePtr;
class ThumbnailingResult : public QObject
{
Q_OBJECT
public Q_SLOTS:
inline void emitResultsReady(const QString &path)
{
emit resultsReady(path);
}
inline void emitResultsFailed(const QString &path)
{
emit resultsFailed(path);
}
Q_SIGNALS:
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
class ThumbnailRunnable : public QRunnable
{
public:
ThumbnailRunnable (QString path, SharedIconCachePtr cache)
ThumbnailRunnable(QString path, SharedIconCachePtr cache)
{
m_path = path;
m_cache = cache;
@ -55,14 +51,14 @@ public:
void run()
{
QFileInfo info(m_path);
if(info.isDir())
if (info.isDir())
return;
if((info.suffix().compare("png", Qt::CaseInsensitive) != 0))
if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0))
return;
int tries = 5;
while(tries)
while (tries)
{
if(!m_cache->stale(m_path))
if (!m_cache->stale(m_path))
return;
QImage image(m_path);
if (image.isNull())
@ -72,19 +68,19 @@ public:
continue;
}
QImage small;
if(image.width() > image.height())
if (image.width() > image.height())
small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation);
else
small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation);
auto smallSize = small.size();
QPoint offset((256-small.width())/2, (256-small.height())/2);
QImage square(QSize(256,256), QImage::Format_ARGB32);
QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2);
QImage square(QSize(256, 256), QImage::Format_ARGB32);
square.fill(Qt::transparent);
QPainter painter(&square);
painter.drawImage(offset, small);
painter.end();
QIcon icon(QPixmap::fromImage(square));
m_cache->add(m_path, icon);
m_resultEmitter.emitResultsReady(m_path);
@ -97,12 +93,13 @@ public:
ThumbnailingResult m_resultEmitter;
};
// this is about as elegant and well written as a bag of bricks with scribbles done by insane asylum patients.
// this is about as elegant and well written as a bag of bricks with scribbles done by insane
// asylum patients.
class FilterModel : public QIdentityProxyModel
{
Q_OBJECT
public:
explicit FilterModel(QObject *parent = 0):QIdentityProxyModel(parent)
explicit FilterModel(QObject *parent = 0) : QIdentityProxyModel(parent)
{
m_thumbnailingPool.setMaxThreadCount(4);
m_thumbnailCache = std::make_shared<SharedIconCache>();
@ -110,10 +107,7 @@ public:
connect(&watcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
// FIXME: the watched file set is not updated when files are removed
}
virtual ~FilterModel()
{
m_thumbnailingPool.waitForDone(500);
}
virtual ~FilterModel() { m_thumbnailingPool.waitForDone(500); }
virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const
{
auto model = sourceModel();
@ -126,23 +120,24 @@ public:
}
if (role == Qt::DecorationRole)
{
QVariant result = sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole);
QVariant result =
sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole);
QString filePath = result.toString();
QIcon temp;
if(!watched.contains(filePath))
if (!watched.contains(filePath))
{
((QFileSystemWatcher &)watcher).addPath(filePath);
((QSet<QString> &)watched).insert(filePath);
}
if(m_thumbnailCache->get(filePath, temp))
if (m_thumbnailCache->get(filePath, temp))
{
return temp;
}
if(!m_failed.contains(filePath))
if (!m_failed.contains(filePath))
{
((FilterModel *)this)->thumbnailImage(filePath);
}
return(m_thumbnailCache->get("placeholder"));
return (m_thumbnailCache->get("placeholder"));
}
return sourceModel()->data(mapToSource(proxyIndex), role);
}
@ -162,24 +157,20 @@ public:
}
return model->setData(mapToSource(index), value.toString() + ".png", role);
}
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)));
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:
void thumbnailReady(QString path)
{
emit layoutChanged();
}
void thumbnailFailed(QString path)
{
m_failed.insert(path);
}
private slots:
void thumbnailReady(QString path) { emit layoutChanged(); }
void thumbnailFailed(QString path) { m_failed.insert(path); }
void fileChanged(QString filepath)
{
m_thumbnailCache->setStale(filepath);
@ -200,12 +191,8 @@ private:
class CenteredEditingDelegate : public QStyledItemDelegate
{
public:
explicit CenteredEditingDelegate(QObject *parent = 0) : QStyledItemDelegate(parent)
{
}
virtual ~CenteredEditingDelegate()
{
}
explicit CenteredEditingDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {}
virtual ~CenteredEditingDelegate() {}
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
@ -221,21 +208,6 @@ public:
}
};
QString ScreenshotsPage::displayName() const
{
return tr("Screenshots");
}
QIcon ScreenshotsPage::icon() const
{
return QIcon::fromTheme("screenshots");
}
QString ScreenshotsPage::id() const
{
return "screenshots";
}
ScreenshotsPage::ScreenshotsPage(BaseInstance *instance, QWidget *parent)
: QWidget(parent), ui(new Ui::ScreenshotsPage)
{
@ -341,7 +313,8 @@ void ScreenshotsPage::on_uploadBtn_clicked()
QDesktopServices::openUrl(link);
CustomMessageBox::selectable(
this, tr("Upload finished"),
tr("The <a href=\"%1\">link to the uploaded album</a> has been opened in the default browser and placed in your clipboard.<br/>Delete hash: %2 (save "
tr("The <a href=\"%1\">link to the uploaded album</a> has been opened in the "
"default browser and placed in your clipboard.<br/>Delete hash: %2 (save "
"this if you want to be able to edit/delete the album)")
.arg(link, imgurAlbum->deleteHash()),
QMessageBox::Information)->exec();

View File

@ -14,11 +14,11 @@
*/
#pragma once
#include <QWidget>
#include <logic/OneSixInstance.h>
#include "logic/OneSixInstance.h"
#include "BasePage.h"
#include <QIcon>
#include <QEvent>
class QFileSystemModel;
class QIdentityProxyModel;
@ -38,21 +38,32 @@ class ScreenshotsPage : public QWidget, public BasePage
public:
explicit ScreenshotsPage(BaseInstance *instance, QWidget *parent = 0);
virtual ~ScreenshotsPage();
virtual void opened() override;
enum
{
NothingDone = 0x42
};
virtual bool eventFilter(QObject *, QEvent *);
virtual QString displayName() const override;
virtual QIcon icon() const override;
virtual QString id() const override;
virtual QString helpPage() const override { return "Screenshots-management"; }
private
slots:
virtual QString displayName() const override
{
return tr("Screenshots");
}
virtual QIcon icon() const override
{
return QIcon::fromTheme("screenshots");
}
virtual QString id() const override
{
return "screenshots";
}
virtual QString helpPage() const override
{
return "Screenshots-management";
}
private slots:
void on_uploadBtn_clicked();
void on_deleteBtn_clicked();
void on_renameBtn_clicked();

View File

@ -31,6 +31,12 @@
#include "gui/dialogs/ProgressDialog.h"
#include <QAbstractItemModel>
#include <QMessageBox>
#include <QListView>
#include <QString>
#include <QUrl>
#include "logic/ModList.h"
#include "logic/minecraft/InstanceVersion.h"
#include "logic/EnabledItemFilter.h"
@ -40,31 +46,14 @@
#include "logic/liteloader/LiteLoaderInstaller.h"
#include "logic/minecraft/VersionBuilder.h"
#include "logic/auth/MojangAccountList.h"
#include "logic/Mod.h"
#include "logic/icons/IconList.h"
#include <QAbstractItemModel>
#include <logic/Mod.h>
#include <logic/icons/IconList.h>
#include <QMessageBox>
#include <QListView>
#include <QString>
#include <QUrl>
QString VersionPage::displayName() const
{
return tr("Version");
}
QIcon VersionPage::icon() const
{
return MMC->icons()->getIcon(m_inst->iconKey());
}
QString VersionPage::id() const
{
return "version";
}
bool VersionPage::shouldDisplay() const
{
return !m_inst->isRunning();

View File

@ -14,10 +14,11 @@
*/
#pragma once
#include <QWidget>
#include <logic/OneSixInstance.h>
#include <logic/net/NetJob.h>
#include "logic/OneSixInstance.h"
#include "logic/net/NetJob.h"
#include "BasePage.h"
class EnabledItemFilter;
@ -33,10 +34,19 @@ class VersionPage : public QWidget, public BasePage
public:
explicit VersionPage(OneSixInstance *inst, QWidget *parent = 0);
virtual ~VersionPage();
virtual QString displayName() const override;
virtual QString displayName() const override
{
return tr("Version");
}
virtual QIcon icon() const override;
virtual QString id() const override;
virtual QString helpPage() const override { return "Instance-version"; }
virtual QString id() const override
{
return "version";
}
virtual QString helpPage() const override
{
return "Instance-version";
}
virtual bool shouldDisplay() const;
private
slots:

View File

@ -14,12 +14,11 @@
*/
#include "PageContainer.h"
#include "gui/Platform.h"
#include <QStackedLayout>
#include <QPushButton>
#include <QSortFilterProxyModel>
#include <QUrl>
#include "MultiMC.h"
#include <QStyledItemDelegate>
#include <QListView>
#include <QLineEdit>
@ -27,10 +26,12 @@
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QDesktopServices>
#include "logic/settings/SettingsObject.h"
#include "MultiMC.h"
#include "logic/settings/SettingsObject.h"
#include "gui/widgets/IconLabel.h"
#include "gui/Platform.h"
#include "PageContainer_p.h"
#include <gui/widgets/IconLabel.h>
class PageEntryFilterModel : public QSortFilterProxyModel
{
@ -197,5 +198,9 @@ bool PageContainer::requestClose(QCloseEvent *event)
if (!page->apply())
return false;
}
if (m_currentPage)
{
m_currentPage->closed();
}
return true;
}

View File

@ -14,9 +14,11 @@
*/
#pragma once
#include <QWidget>
#include <QModelIndex>
#include <gui/pages/BasePageProvider.h>
#include "gui/pages/BasePageProvider.h"
class QLayout;
class IconLabel;
@ -34,7 +36,7 @@ class PageContainer : public QWidget
public:
explicit PageContainer(BasePageProviderPtr pageProvider, QString defaultId = QString(),
QWidget *parent = 0);
virtual ~PageContainer() {};
virtual ~PageContainer() {}
void addButtons(QWidget * buttons);
void addButtons(QLayout * buttons);
@ -49,7 +51,7 @@ slots:
void help();
private:
BasePage * m_currentPage;
BasePage * m_currentPage = 0;
QSortFilterProxyModel *m_proxyModel;
PageModel *m_model;
QStackedLayout *m_pageStack;

View File

@ -1,4 +1,20 @@
/* Copyright 2014 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QListView>
#include <QStyledItemDelegate>
#include <QEvent>
@ -30,7 +46,7 @@ public:
empty.fill(Qt::transparent);
m_emptyIcon = QIcon(empty);
}
virtual ~PageModel() {};
virtual ~PageModel() {}
int rowCount(const QModelIndex &parent = QModelIndex()) const
{

View File

@ -1,13 +1,15 @@
#include "RecursiveFileSystemWatcher.h"
#include <QRegularExpression>
#include <QDebug>
RecursiveFileSystemWatcher::RecursiveFileSystemWatcher(QObject *parent)
: QObject(parent),
m_watcher(new QFileSystemWatcher(this))
: QObject(parent), m_exp(".*"), m_watcher(new QFileSystemWatcher(this))
{
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &RecursiveFileSystemWatcher::fileChange);
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &RecursiveFileSystemWatcher::directoryChange);
connect(m_watcher, &QFileSystemWatcher::fileChanged, this,
&RecursiveFileSystemWatcher::fileChange);
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this,
&RecursiveFileSystemWatcher::directoryChange);
}
void RecursiveFileSystemWatcher::setRootDir(const QDir &root)
@ -34,12 +36,20 @@ void RecursiveFileSystemWatcher::setWatchFiles(const bool watchFiles)
void RecursiveFileSystemWatcher::enable()
{
if (m_isEnabled)
{
return;
}
Q_ASSERT(m_root != QDir::root());
addFilesToWatcherRecursive(m_root);
m_isEnabled = true;
}
void RecursiveFileSystemWatcher::disable()
{
if (!m_isEnabled)
{
return;
}
m_isEnabled = false;
m_watcher->removePaths(m_watcher->files());
m_watcher->removePaths(m_watcher->directories());
@ -57,9 +67,9 @@ void RecursiveFileSystemWatcher::setFiles(const QStringList &files)
void RecursiveFileSystemWatcher::addFilesToWatcherRecursive(const QDir &dir)
{
m_watcher->addPath(dir.absolutePath());
for (const QFileInfo &info : dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot))
for (const QString &directory : dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
addFilesToWatcherRecursive(info.absoluteDir());
addFilesToWatcherRecursive(dir.absoluteFilePath(directory));
}
if (m_watchFiles)
{
@ -69,19 +79,19 @@ void RecursiveFileSystemWatcher::addFilesToWatcherRecursive(const QDir &dir)
}
}
}
QStringList RecursiveFileSystemWatcher::scanRecursive(const QDir &dir)
QStringList RecursiveFileSystemWatcher::scanRecursive(const QDir &directory)
{
QStringList ret;
QRegularExpression exp(m_exp);
for (const QFileInfo &info : dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files))
for (const QString &dir : directory.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
if (info.isFile() && exp.match(info.absoluteFilePath()).hasMatch())
ret.append(scanRecursive(directory.absoluteFilePath(dir)));
}
for (const QString &file : directory.entryList(QDir::Files))
{
if (exp.match(file).hasMatch())
{
ret.append(info.absoluteFilePath());
}
else if (info.isDir())
{
ret.append(scanRecursive(info.absoluteDir()));
ret.append(m_root.relativeFilePath(directory.absoluteFilePath(file)));
}
}
return ret;

View File

@ -25,8 +25,7 @@ signals:
void filesChanged();
void fileChanged(const QString &path);
public
slots:
public slots:
void enable();
void disable();
@ -39,13 +38,12 @@ private:
QFileSystemWatcher *m_watcher;
QStringList m_files;
void setFiles(const QStringList &scanRecursive);
void setFiles(const QStringList &files);
void addFilesToWatcherRecursive(const QDir &dir);
QStringList scanRecursive(const QDir &dir);
private
slots:
private slots:
void fileChange(const QString &path);
void directoryChange(const QString &path);
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -164,6 +164,13 @@
<file>24x24/noaccount.png</file>
<file>32x32/noaccount.png</file>
<file>48x48/noaccount.png</file>
<!-- Log file, LGPL, http://www.iconarchive.com/show/crystal-clear-icons-by-everaldo/Mimetype-text-icon.html -->
<file>16x16/log.png</file>
<file>24x24/log.png</file>
<file>32x32/log.png</file>
<file>48x48/log.png</file>
<file>64x64/log.png</file>
<!-- placeholder when loading screenshot images -->
<file>scalable/screenshot-placeholder.svg</file>