SCRATCH move icons over to Env, instance proxy model to gui
This commit is contained in:
parent
154d19bb74
commit
aa70ed2244
@ -283,6 +283,8 @@ SET(MULTIMC_SOURCES
|
||||
gui/GuiUtil.cpp
|
||||
gui/ColumnResizer.h
|
||||
gui/ColumnResizer.cpp
|
||||
gui/InstanceProxyModel.h
|
||||
gui/InstanceProxyModel.cpp
|
||||
|
||||
# GUI - windows
|
||||
gui/MainWindow.h
|
||||
|
29
MultiMC.cpp
29
MultiMC.cpp
@ -194,6 +194,9 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
|
||||
|
||||
m_translationChecker.reset(new TranslationDownloader());
|
||||
|
||||
// load icons
|
||||
initIcons();
|
||||
|
||||
// and instances
|
||||
auto InstDirSetting = m_settings->getSetting("InstanceDir");
|
||||
// instance path: check for problems with '!' in instance path and warn the user in the log
|
||||
@ -307,6 +310,17 @@ void MultiMC::initTranslations()
|
||||
}
|
||||
}
|
||||
|
||||
void MultiMC::initIcons()
|
||||
{
|
||||
auto setting = MMC->settings()->getSetting("IconsDir");
|
||||
ENV.m_icons.reset(new IconList(QString(":/icons/instances/"), setting->get().toString()));
|
||||
connect(setting.get(), &Setting::SettingChanged,[&](const Setting &, QVariant value)
|
||||
{
|
||||
ENV.m_icons->directoryChanged(value.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void moveFile(const QString &oldName, const QString &newName)
|
||||
{
|
||||
QFile::remove(newName);
|
||||
@ -448,21 +462,6 @@ void MultiMC::initGlobalSettings(bool test_mode)
|
||||
m_settings->registerSetting("PagedGeometry", "");
|
||||
}
|
||||
|
||||
std::shared_ptr<IconList> MultiMC::icons()
|
||||
{
|
||||
if (!m_icons)
|
||||
{
|
||||
|
||||
auto setting = MMC->settings()->getSetting("IconsDir");
|
||||
m_icons.reset(new IconList(setting->get().toString()));
|
||||
connect(setting.get(), &Setting::SettingChanged,[&](const Setting &, QVariant value)
|
||||
{
|
||||
m_icons->directoryChanged(value.toString());
|
||||
});
|
||||
}
|
||||
return m_icons;
|
||||
}
|
||||
|
||||
std::shared_ptr<LWJGLVersionList> MultiMC::lwjgllist()
|
||||
{
|
||||
if (!m_lwjgllist)
|
||||
|
@ -64,9 +64,6 @@ public:
|
||||
// InstanceList, OneSixUpdate, MinecraftInstance, OneSixProfileStrategy
|
||||
std::shared_ptr<MinecraftVersionList> minecraftlist();
|
||||
|
||||
// LegacyInstance, BaseInstance, OneSixInstance, InstanceList
|
||||
std::shared_ptr<IconList> icons();
|
||||
|
||||
QIcon getThemedIcon(const QString& name);
|
||||
|
||||
void setIconTheme(const QString& name);
|
||||
@ -152,6 +149,8 @@ private slots:
|
||||
private:
|
||||
void initLogger();
|
||||
|
||||
void initIcons();
|
||||
|
||||
void initGlobalSettings(bool test_mode);
|
||||
|
||||
void initTranslations();
|
||||
@ -166,7 +165,6 @@ private:
|
||||
std::shared_ptr<InstanceList> m_instances;
|
||||
std::shared_ptr<UpdateChecker> m_updateChecker;
|
||||
std::shared_ptr<MojangAccountList> m_accounts;
|
||||
std::shared_ptr<IconList> m_icons;
|
||||
std::shared_ptr<LWJGLVersionList> m_lwjgllist;
|
||||
std::shared_ptr<ForgeVersionList> m_forgelist;
|
||||
std::shared_ptr<LiteLoaderVersionList> m_liteloaderlist;
|
||||
|
@ -59,7 +59,7 @@ ConsoleWindow::ConsoleWindow(BaseProcess *process, QWidget *parent)
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
auto instance = m_proc->instance();
|
||||
auto icon = MMC->icons()->getIcon(instance->iconKey());
|
||||
auto icon = ENV.icons()->getIcon(instance->iconKey());
|
||||
QString windowTitle = tr("Console window for ") + instance->name();
|
||||
|
||||
// Set window properties
|
||||
|
23
gui/InstanceProxyModel.cpp
Normal file
23
gui/InstanceProxyModel.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "InstanceProxyModel.h"
|
||||
#include "MultiMC.h"
|
||||
#include <logic/BaseInstance.h>
|
||||
|
||||
InstanceProxyModel::InstanceProxyModel(QObject *parent) : GroupedProxyModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool InstanceProxyModel::subSortLessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const
|
||||
{
|
||||
BaseInstance *pdataLeft = static_cast<BaseInstance *>(left.internalPointer());
|
||||
BaseInstance *pdataRight = static_cast<BaseInstance *>(right.internalPointer());
|
||||
QString sortMode = MMC->settings()->get("InstSortMode").toString();
|
||||
if (sortMode == "LastLaunch")
|
||||
{
|
||||
return pdataLeft->lastLaunch() > pdataRight->lastLaunch();
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0;
|
||||
}
|
||||
}
|
13
gui/InstanceProxyModel.h
Normal file
13
gui/InstanceProxyModel.h
Normal file
@ -0,0 +1,13 @@
|
||||
#include "groupview/GroupedProxyModel.h"
|
||||
|
||||
/**
|
||||
* A proxy model that is responsible for sorting instances into groups
|
||||
*/
|
||||
class InstanceProxyModel : public GroupedProxyModel
|
||||
{
|
||||
public:
|
||||
explicit InstanceProxyModel(QObject *parent = 0);
|
||||
|
||||
protected:
|
||||
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
};
|
@ -331,6 +331,7 @@ namespace Ui {
|
||||
|
||||
#include "gui/groupview/GroupView.h"
|
||||
#include "gui/groupview/InstanceDelegate.h"
|
||||
#include "gui/InstanceProxyModel.h"
|
||||
|
||||
#include "gui/Platform.h"
|
||||
|
||||
@ -503,7 +504,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
SLOT(instanceChanged(const QModelIndex &, const QModelIndex &)));
|
||||
|
||||
// track icon changes and update the toolbar!
|
||||
connect(MMC->icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
|
||||
connect(ENV.icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
|
||||
|
||||
// model reset -> selection is invalid. All the instance pointers are wrong.
|
||||
// FIXME: stop using POINTERS everywhere
|
||||
@ -1277,7 +1278,7 @@ void MainWindow::on_actionChangeInstIcon_triggered()
|
||||
if (dlg.result() == QDialog::Accepted)
|
||||
{
|
||||
m_selectedInstance->setIconKey(dlg.selectedIconKey);
|
||||
auto ico = MMC->icons()->getBigIcon(dlg.selectedIconKey);
|
||||
auto ico = ENV.icons()->getBigIcon(dlg.selectedIconKey);
|
||||
ui->actionChangeInstIcon->setIcon(ico);
|
||||
}
|
||||
}
|
||||
@ -1286,14 +1287,14 @@ void MainWindow::iconUpdated(QString icon)
|
||||
{
|
||||
if (icon == m_currentInstIcon)
|
||||
{
|
||||
ui->actionChangeInstIcon->setIcon(MMC->icons()->getBigIcon(m_currentInstIcon));
|
||||
ui->actionChangeInstIcon->setIcon(ENV.icons()->getBigIcon(m_currentInstIcon));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateInstanceToolIcon(QString new_icon)
|
||||
{
|
||||
m_currentInstIcon = new_icon;
|
||||
ui->actionChangeInstIcon->setIcon(MMC->icons()->getBigIcon(m_currentInstIcon));
|
||||
ui->actionChangeInstIcon->setIcon(ENV.icons()->getBigIcon(m_currentInstIcon));
|
||||
}
|
||||
|
||||
void MainWindow::setSelectedInstanceById(const QString &id)
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <QProcess>
|
||||
#include <QTimer>
|
||||
|
||||
#include "logic/InstanceList.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "logic/auth/MojangAccount.h"
|
||||
#include "logic/net/NetJob.h"
|
||||
@ -27,6 +26,7 @@
|
||||
class NewsChecker;
|
||||
class NotificationChecker;
|
||||
class QToolButton;
|
||||
class InstanceProxyModel;
|
||||
class LabeledToolButton;
|
||||
class QLabel;
|
||||
class MinecraftProcess;
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "logic/icons/IconList.h"
|
||||
#include "logic/tasks/Task.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
#include <logic/InstanceList.h>
|
||||
#include "logic/InstanceList.h"
|
||||
|
||||
CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
|
||||
:QDialog(parent), ui(new Ui::CopyInstanceDialog), m_original(original)
|
||||
@ -40,7 +40,7 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
|
||||
layout()->setSizeConstraint(QLayout::SetFixedSize);
|
||||
|
||||
InstIconKey = original->iconKey();
|
||||
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
|
||||
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
|
||||
ui->instNameTextBox->setText(original->name());
|
||||
ui->instNameTextBox->setFocus();
|
||||
auto groups = MMC->instances()->getGroups().toSet();
|
||||
@ -91,7 +91,7 @@ void CopyInstanceDialog::on_iconButton_clicked()
|
||||
if (dlg.result() == QDialog::Accepted)
|
||||
{
|
||||
InstIconKey = dlg.selectedIconKey;
|
||||
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
|
||||
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ IconPickerDialog::IconPickerDialog(QWidget *parent)
|
||||
|
||||
contentsWidget->installEventFilter(this);
|
||||
|
||||
contentsWidget->setModel(MMC->icons().get());
|
||||
contentsWidget->setModel(ENV.icons().get());
|
||||
|
||||
auto buttonAdd = ui->buttonBox->addButton(tr("Add Icon"), QDialogButtonBox::ResetRole);
|
||||
auto buttonRemove =
|
||||
@ -104,12 +104,12 @@ void IconPickerDialog::addNewIcon()
|
||||
//: The type of icon files
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(this, selectIcons, QString(),
|
||||
tr("Icons") + "(*.png *.jpg *.jpeg *.ico)");
|
||||
MMC->icons()->installIcons(fileNames);
|
||||
ENV.icons()->installIcons(fileNames);
|
||||
}
|
||||
|
||||
void IconPickerDialog::removeSelectedIcon()
|
||||
{
|
||||
MMC->icons()->deleteIcon(selectedIconKey);
|
||||
ENV.icons()->deleteIcon(selectedIconKey);
|
||||
}
|
||||
|
||||
void IconPickerDialog::activated(QModelIndex index)
|
||||
@ -130,7 +130,7 @@ void IconPickerDialog::selectionChanged(QItemSelection selected, QItemSelection
|
||||
|
||||
int IconPickerDialog::exec(QString selection)
|
||||
{
|
||||
auto list = MMC->icons();
|
||||
auto list = ENV.icons();
|
||||
auto contentsWidget = ui->iconView;
|
||||
selectedIconKey = selection;
|
||||
|
||||
|
@ -66,7 +66,7 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent)
|
||||
|
||||
setSelectedVersion(MMC->minecraftlist()->getLatestStable(), true);
|
||||
InstIconKey = "infinity";
|
||||
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
|
||||
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
|
||||
|
||||
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
|
||||
connect(ui->modpackEdit, &QLineEdit::textChanged, this, &NewInstanceDialog::updateDialogState);
|
||||
@ -181,7 +181,7 @@ void NewInstanceDialog::on_iconButton_clicked()
|
||||
if (dlg.result() == QDialog::Accepted)
|
||||
{
|
||||
InstIconKey = dlg.selectedIconKey;
|
||||
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
|
||||
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
||||
|
||||
QIcon VersionPage::icon() const
|
||||
{
|
||||
return MMC->icons()->getIcon(m_inst->iconKey());
|
||||
return ENV.icons()->getIcon(m_inst->iconKey());
|
||||
}
|
||||
bool VersionPage::shouldDisplay() const
|
||||
{
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include "logic/settings/INISettingsObject.h"
|
||||
#include "logic/settings/Setting.h"
|
||||
@ -37,7 +36,7 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
|
||||
|
||||
m_settings->registerSetting("name", "Unnamed Instance");
|
||||
m_settings->registerSetting("iconKey", "default");
|
||||
connect(MMC->icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
|
||||
connect(ENV.icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
|
||||
m_settings->registerSetting("notes", "");
|
||||
m_settings->registerSetting("lastLaunchTime", 0);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "Env.h"
|
||||
#include "logic/net/HttpMetaCache.h"
|
||||
#include "icons/IconList.h"
|
||||
#include <QDir>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkAccessManager>
|
||||
@ -35,6 +36,11 @@ std::shared_ptr< QNetworkAccessManager > Env::qnam()
|
||||
return m_qnam;
|
||||
}
|
||||
|
||||
std::shared_ptr<IconList> Env::icons()
|
||||
{
|
||||
Q_ASSERT(m_icons != nullptr);
|
||||
return m_icons;
|
||||
}
|
||||
|
||||
void Env::initHttpMetaCache(QString rootPath, QString staticDataPath)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <QString>
|
||||
|
||||
class IconList;
|
||||
class QNetworkAccessManager;
|
||||
class HttpMetaCache;
|
||||
|
||||
@ -26,6 +27,8 @@ public:
|
||||
|
||||
std::shared_ptr<HttpMetaCache> metacache();
|
||||
|
||||
std::shared_ptr<IconList> icons();
|
||||
|
||||
/// init the cache. FIXME: possible future hook point
|
||||
void initHttpMetaCache(QString rootPath, QString staticDataPath);
|
||||
|
||||
@ -35,4 +38,5 @@ public:
|
||||
protected:
|
||||
std::shared_ptr<QNetworkAccessManager> m_qnam;
|
||||
std::shared_ptr<HttpMetaCache> m_metacache;
|
||||
std::shared_ptr<IconList> m_icons;
|
||||
};
|
||||
|
@ -97,7 +97,7 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
QString key = pdata->iconKey();
|
||||
return MMC->icons()->getIcon(key);
|
||||
return ENV.icons()->getIcon(key);
|
||||
}
|
||||
// for now.
|
||||
case GroupViewRoles::GroupRole:
|
||||
@ -547,23 +547,3 @@ void InstanceList::propertiesChanged(BaseInstance *inst)
|
||||
emit dataChanged(index(i), index(i));
|
||||
}
|
||||
}
|
||||
|
||||
InstanceProxyModel::InstanceProxyModel(QObject *parent) : GroupedProxyModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool InstanceProxyModel::subSortLessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const
|
||||
{
|
||||
BaseInstance *pdataLeft = static_cast<BaseInstance *>(left.internalPointer());
|
||||
BaseInstance *pdataRight = static_cast<BaseInstance *>(right.internalPointer());
|
||||
QString sortMode = MMC->settings()->get("InstSortMode").toString();
|
||||
if (sortMode == "LastLaunch")
|
||||
{
|
||||
return pdataLeft->lastLaunch() > pdataRight->lastLaunch();
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0;
|
||||
}
|
||||
}
|
||||
|
@ -181,12 +181,3 @@ protected:
|
||||
QSet<QString> m_groups;
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
};
|
||||
|
||||
class InstanceProxyModel : public GroupedProxyModel
|
||||
{
|
||||
public:
|
||||
explicit InstanceProxyModel(QObject *parent = 0);
|
||||
|
||||
protected:
|
||||
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
};
|
||||
|
@ -127,7 +127,7 @@ std::shared_ptr<Task> LegacyInstance::doUpdate()
|
||||
BaseProcess *LegacyInstance::prepareForLaunch(AuthSessionPtr account)
|
||||
{
|
||||
QString launchScript;
|
||||
QIcon icon = MMC->icons()->getIcon(iconKey());
|
||||
QIcon icon = ENV.icons()->getIcon(iconKey());
|
||||
auto pixmap = icon.pixmap(128, 128);
|
||||
pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG");
|
||||
|
||||
|
@ -158,7 +158,7 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session)
|
||||
BaseProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session)
|
||||
{
|
||||
QString launchScript;
|
||||
QIcon icon = MMC->icons()->getIcon(iconKey());
|
||||
QIcon icon = ENV.icons()->getIcon(iconKey());
|
||||
auto pixmap = icon.pixmap(128, 128);
|
||||
pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG");
|
||||
|
||||
|
@ -212,7 +212,7 @@ void FTBPlugin::loadInstances(QMap<QString, QString> &groupMap, QList<InstancePt
|
||||
qDebug() << "Loading FTB instance from " << record.instanceDir;
|
||||
QString iconKey = record.logo;
|
||||
iconKey.remove(QRegularExpression("\\..*"));
|
||||
MMC->icons()->addIcon(iconKey, iconKey, PathCombine(record.templateDir, record.logo),
|
||||
ENV.icons()->addIcon(iconKey, iconKey, PathCombine(record.templateDir, record.logo),
|
||||
MMCIcon::Transient);
|
||||
|
||||
if (!QFileInfo(PathCombine(record.instanceDir, "instance.cfg")).exists())
|
||||
|
@ -20,14 +20,15 @@
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <MultiMC.h>
|
||||
#include <QSet>
|
||||
#include <logger/QsLog.h>
|
||||
|
||||
#define MAX_SIZE 1024
|
||||
|
||||
IconList::IconList(QString path, QObject *parent) : QAbstractListModel(parent)
|
||||
IconList::IconList(QString builtinPath, QString path, QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
// add builtin icons
|
||||
QDir instance_icons(":/icons/instances/");
|
||||
QDir instance_icons(builtinPath);
|
||||
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
|
||||
for (auto file_info : file_info_list)
|
||||
{
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <memory>
|
||||
#include "MMCIcon.h"
|
||||
#include "logic/settings/Setting.h"
|
||||
#include "logic/Env.h" // there is a global icon list inside Env.
|
||||
|
||||
class QFileSystemWatcher;
|
||||
|
||||
@ -30,7 +31,7 @@ class IconList : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IconList(QString path, QObject *parent = 0);
|
||||
explicit IconList(QString builtinPath, QString path, QObject *parent = 0);
|
||||
virtual ~IconList() {};
|
||||
|
||||
QIcon getIcon(QString key);
|
||||
|
Loading…
Reference in New Issue
Block a user