NOISSUE split GUI stuff from logic library

This commit is contained in:
Petr Mrázek 2016-04-10 04:29:29 +02:00
parent fcd4a482f7
commit 47e37635f5
286 changed files with 126 additions and 132 deletions

View File

@ -117,6 +117,8 @@ include(Coverity)
############################### Built Artifacts ###############################
add_subdirectory(tests)
add_subdirectory(logic)
add_subdirectory(libraries/logic)
add_subdirectory(libraries/gui)
add_subdirectory(application)
add_subdirectory(wonkoclient)

View File

@ -318,7 +318,7 @@ qt5_add_resources(MULTIMC_RESOURCES ${MULTIMC_QRCS})
# Add executable
add_executable(MultiMC MACOSX_BUNDLE WIN32 ${MULTIMC_SOURCES} ${MULTIMC_UI} ${MULTIMC_RESOURCES} ${MULTIMC_RCS})
target_link_libraries(MultiMC MultiMC_logic xz-embedded unpack200 iconfix ${QUAZIP_LIBRARIES} hoedown rainbow)
target_link_libraries(MultiMC MultiMC_gui ${QUAZIP_LIBRARIES} hoedown rainbow)
if(APPLE)
find_library(OSX_CORE_FOUNDATION CoreFoundation)

View File

@ -58,7 +58,7 @@ ConsoleWindow::ConsoleWindow(std::shared_ptr<LaunchTask> proc, QWidget *parent)
setAttribute(Qt::WA_DeleteOnClose);
auto instance = m_proc->instance();
auto icon = ENV.icons()->getIcon(instance->iconKey());
auto icon = MMC->icons()->getIcon(instance->iconKey());
QString windowTitle = tr("Console window for ") + instance->name();
// Set window properties

View File

@ -1,11 +1,22 @@
#include "InstanceProxyModel.h"
#include "MultiMC.h"
#include <BaseInstance.h>
#include <icons/IconList.h>
InstanceProxyModel::InstanceProxyModel(QObject *parent) : GroupedProxyModel(parent)
{
}
QVariant InstanceProxyModel::data(const QModelIndex & index, int role) const
{
QVariant data = QSortFilterProxyModel::data(index, role);
if(role == Qt::DecorationRole)
{
return QVariant(MMC->icons()->getIcon(data.toString()));
}
return data;
}
bool InstanceProxyModel::subSortLessThan(const QModelIndex &left,
const QModelIndex &right) const
{

View File

@ -9,7 +9,8 @@ class InstanceProxyModel : public GroupedProxyModel
{
public:
explicit InstanceProxyModel(QObject *parent = 0);
QVariant data(const QModelIndex & index, int role) const override;
protected:
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const;
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override;
};

View File

@ -56,7 +56,7 @@
#include <launch/LaunchTask.h>
#include <minecraft/MinecraftVersionList.h>
#include <minecraft/legacy/LwjglVersionList.h>
#include <minecraft/SkinUtils.h>
#include <SkinUtils.h>
#include <net/URLConstants.h>
#include <net/NetJob.h>
#include <net/CacheDownload.h>
@ -468,7 +468,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
connect(view->selectionModel(), &QItemSelectionModel::currentChanged, this, &MainWindow::instanceChanged);
// track icon changes and update the toolbar!
connect(ENV.icons().get(), &IconList::iconUpdated, this, &MainWindow::iconUpdated);
connect(MMC->icons().get(), &IconList::iconUpdated, this, &MainWindow::iconUpdated);
// model reset -> selection is invalid. All the instance pointers are wrong.
connect(MMC->instances().get(), &InstanceList::dataIsInvalid, this, &MainWindow::selectionBad);
@ -1108,7 +1108,7 @@ InstancePtr MainWindow::instanceFromZipPack(QString instName, QString instGroup,
if (QFile::exists(importIconPath))
{
// import icon
auto iconList = ENV.icons();
auto iconList = MMC->icons();
// FIXME: check if the file is OK before removing the existing one...
if (iconList->iconFileExists(instIcon))
{
@ -1311,7 +1311,7 @@ void MainWindow::on_actionChangeInstIcon_triggered()
if (dlg.result() == QDialog::Accepted)
{
m_selectedInstance->setIconKey(dlg.selectedIconKey);
auto ico = ENV.icons()->getBigIcon(dlg.selectedIconKey);
auto ico = MMC->icons()->getBigIcon(dlg.selectedIconKey);
ui->actionChangeInstIcon->setIcon(ico);
}
}
@ -1320,14 +1320,14 @@ void MainWindow::iconUpdated(QString icon)
{
if (icon == m_currentInstIcon)
{
ui->actionChangeInstIcon->setIcon(ENV.icons()->getBigIcon(m_currentInstIcon));
ui->actionChangeInstIcon->setIcon(MMC->icons()->getBigIcon(m_currentInstIcon));
}
}
void MainWindow::updateInstanceToolIcon(QString new_icon)
{
m_currentInstIcon = new_icon;
ui->actionChangeInstIcon->setIcon(ENV.icons()->getBigIcon(m_currentInstIcon));
ui->actionChangeInstIcon->setIcon(MMC->icons()->getBigIcon(m_currentInstIcon));
}
void MainWindow::setSelectedInstanceById(const QString &id)

View File

@ -342,10 +342,10 @@ void MultiMC::initTranslations()
void MultiMC::initIcons()
{
auto setting = MMC->settings()->getSetting("IconsDir");
ENV.m_icons.reset(new IconList(QString(":/icons/instances/"), setting->get().toString()));
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());
m_icons->directoryChanged(value.toString());
});
//FIXME: none of this should be here.

View File

@ -87,6 +87,11 @@ public:
return m_instances;
}
std::shared_ptr<IconList> icons()
{
return m_icons;
}
// APPLICATION ONLY
std::shared_ptr<MojangAccountList> accounts()
{
@ -154,6 +159,7 @@ private:
std::shared_ptr<QTranslator> m_mmc_translator;
std::shared_ptr<SettingsObject> m_settings;
std::shared_ptr<InstanceList> m_instances;
std::shared_ptr<IconList> m_icons;
std::shared_ptr<UpdateChecker> m_updateChecker;
std::shared_ptr<MojangAccountList> m_accounts;
std::shared_ptr<LWJGLVersionList> m_lwjgllist;

View File

@ -36,7 +36,7 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
layout()->setSizeConstraint(QLayout::SetFixedSize);
InstIconKey = original->iconKey();
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
ui->instNameTextBox->setText(original->name());
ui->instNameTextBox->setFocus();
auto groups = MMC->instances()->getGroups().toSet();
@ -88,7 +88,7 @@ void CopyInstanceDialog::on_iconButton_clicked()
if (dlg.result() == QDialog::Accepted)
{
InstIconKey = dlg.selectedIconKey;
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
}
}

View File

@ -27,7 +27,7 @@
#include <QSaveFile>
#include "MMCStrings.h"
#include "SeparatorPrefixTree.h"
#include "Env.h"
#include "MultiMC.h"
#include <icons/IconList.h>
#include <FileSystem.h>
@ -339,7 +339,7 @@ ExportInstanceDialog::~ExportInstanceDialog()
void SaveIcon(InstancePtr m_instance)
{
auto iconKey = m_instance->iconKey();
auto iconList = ENV.icons();
auto iconList = MMC->icons();
auto mmcIcon = iconList->icon(iconKey);
if(mmcIcon)
{

View File

@ -57,7 +57,7 @@ IconPickerDialog::IconPickerDialog(QWidget *parent)
contentsWidget->installEventFilter(this);
contentsWidget->setModel(ENV.icons().get());
contentsWidget->setModel(MMC->icons().get());
auto buttonAdd = ui->buttonBox->addButton(tr("Add Icon"), QDialogButtonBox::ResetRole);
auto buttonRemove =
@ -102,12 +102,12 @@ void IconPickerDialog::addNewIcon()
//: The type of icon files
QStringList fileNames = QFileDialog::getOpenFileNames(this, selectIcons, QString(),
tr("Icons") + "(*.png *.jpg *.jpeg *.ico)");
ENV.icons()->installIcons(fileNames);
MMC->icons()->installIcons(fileNames);
}
void IconPickerDialog::removeSelectedIcon()
{
ENV.icons()->deleteIcon(selectedIconKey);
MMC->icons()->deleteIcon(selectedIconKey);
}
void IconPickerDialog::activated(QModelIndex index)
@ -128,7 +128,7 @@ void IconPickerDialog::selectionChanged(QItemSelection selected, QItemSelection
int IconPickerDialog::execWithSelection(QString selection)
{
auto list = ENV.icons();
auto list = MMC->icons();
auto contentsWidget = ui->iconView;
selectedIconKey = selection;

View File

@ -64,7 +64,7 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, QWidget *pare
setSelectedVersion(MMC->minecraftlist()->getRecommended());
InstIconKey = "default";
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
@ -211,7 +211,7 @@ void NewInstanceDialog::on_iconButton_clicked()
if (dlg.result() == QDialog::Accepted)
{
InstIconKey = dlg.selectedIconKey;
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
}
}

View File

@ -94,7 +94,7 @@ private:
QIcon VersionPage::icon() const
{
return ENV.icons()->getIcon(m_inst->iconKey());
return MMC->icons()->getIcon(m_inst->iconKey());
}
bool VersionPage::shouldDisplay() const
{

View File

@ -0,0 +1,28 @@
project(MultiMC_logic)
set(GUI_SOURCES
DesktopServices.h
DesktopServices.cpp
# Icons
icons/MMCIcon.h
icons/MMCIcon.cpp
icons/IconList.h
icons/IconList.cpp
SkinUtils.cpp
SkinUtils.h
)
################################ COMPILE ################################
add_library(MultiMC_gui SHARED ${GUI_SOURCES})
set_target_properties(MultiMC_gui PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
generate_export_header(MultiMC_gui)
# Link
target_link_libraries(MultiMC_gui iconfix MultiMC_logic)
qt5_use_modules(MultiMC_gui Gui)
# Mark and export headers
target_include_directories(MultiMC_gui PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")

View File

@ -0,0 +1,37 @@
#pragma once
#include <QUrl>
#include <QString>
#include "multimc_gui_export.h"
/**
* This wraps around QDesktopServices and adds workarounds where needed
* Use this instead of QDesktopServices!
*/
namespace DesktopServices
{
/**
* Open a file in whatever application is applicable
*/
MULTIMC_GUI_EXPORT bool openFile(const QString &path);
/**
* Open a file in the specified application
*/
MULTIMC_GUI_EXPORT bool openFile(const QString &application, const QString &path, const QString & workingDirectory = QString(), qint64 *pid = 0);
/**
* Run an application
*/
MULTIMC_GUI_EXPORT bool run(const QString &application,const QStringList &args, const QString & workingDirectory = QString(), qint64 *pid = 0);
/**
* Open a directory
*/
MULTIMC_GUI_EXPORT bool openDirectory(const QString &path, bool ensureExists = false);
/**
* Open the URL, most likely in a browser. Maybe.
*/
MULTIMC_GUI_EXPORT bool openUrl(const QUrl &url);
};

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "minecraft/SkinUtils.h"
#include "SkinUtils.h"
#include "net/HttpMetaCache.h"
#include "Env.h"

View File

@ -17,9 +17,9 @@
#include <QPixmap>
#include "multimc_logic_export.h"
#include "multimc_gui_export.h"
namespace SkinUtils
{
QPixmap MULTIMC_LOGIC_EXPORT getFaceFromCache(QString id, int height = 64, int width = 64);
QPixmap MULTIMC_GUI_EXPORT getFaceFromCache(QString id, int height = 64, int width = 64);
}

View File

@ -18,9 +18,9 @@
#include <QDateTime>
#include <QIcon>
#include "multimc_logic_export.h"
#include "multimc_gui_export.h"
struct MULTIMC_LOGIC_EXPORT MMCImage
struct MULTIMC_GUI_EXPORT MMCImage
{
QIcon icon;
QString filename;
@ -31,7 +31,7 @@ struct MULTIMC_LOGIC_EXPORT MMCImage
}
};
struct MULTIMC_LOGIC_EXPORT MMCIcon
struct MULTIMC_GUI_EXPORT MMCIcon
{
enum Type : unsigned
{

View File

@ -23,7 +23,6 @@
#include "settings/OverrideSetting.h"
#include "minecraft/MinecraftVersionList.h"
#include "icons/IconList.h"
#include "FileSystem.h"
#include "Commandline.h"
@ -35,10 +34,6 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
m_settings->registerSetting("name", "Unnamed Instance");
m_settings->registerSetting("iconKey", "default");
if (ENV.hasIcons())
{
connect(ENV.icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
}
m_settings->registerSetting("notes", "");
m_settings->registerSetting("lastLaunchTime", 0);
m_settings->registerSetting("totalTimePlayed", 0);

View File

@ -35,8 +35,6 @@ set(LOGIC_SOURCES
FileSystem.h
FileSystem.cpp
DesktopServices.h
DesktopServices.cpp
Exception.h
@ -171,8 +169,6 @@ set(LOGIC_SOURCES
minecraft/legacy/LegacyInstance.cpp
minecraft/legacy/LwjglVersionList.h
minecraft/legacy/LwjglVersionList.cpp
minecraft/SkinUtils.h
minecraft/SkinUtils.cpp
minecraft/GradleSpecifier.h
minecraft/MinecraftProfile.cpp
minecraft/MinecraftProfile.h
@ -233,12 +229,6 @@ set(LOGIC_SOURCES
screenshots/ImgurAlbumCreation.h
screenshots/ImgurAlbumCreation.cpp
# Icons
icons/MMCIcon.h
icons/MMCIcon.cpp
icons/IconList.h
icons/IconList.cpp
# Tasks
tasks/Task.h
tasks/Task.cpp
@ -346,8 +336,8 @@ set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISI
generate_export_header(MultiMC_logic)
# Link
target_link_libraries(MultiMC_logic xz-embedded unpack200 iconfix LogicalGui ${QUAZIP_LIBRARIES} nbt++ ${ZLIB_LIBRARIES})
qt5_use_modules(MultiMC_logic Core Xml Widgets Network Concurrent)
target_link_libraries(MultiMC_logic xz-embedded unpack200 ${QUAZIP_LIBRARIES} nbt++ ${ZLIB_LIBRARIES})
qt5_use_modules(MultiMC_logic Core Xml Network Concurrent)
add_dependencies(MultiMC_logic QuaZIP)
# Mark and export headers

View File

@ -1,6 +1,5 @@
#include "Env.h"
#include "net/HttpMetaCache.h"
#include "icons/IconList.h"
#include "BaseVersion.h"
#include "BaseVersionList.h"
#include <QDir>
@ -24,7 +23,6 @@ void Env::destroy()
{
m_metacache.reset();
m_qnam.reset();
m_icons.reset();
m_versionLists.clear();
}
@ -45,16 +43,6 @@ std::shared_ptr< QNetworkAccessManager > Env::qnam()
return m_qnam;
}
std::shared_ptr<IconList> Env::icons()
{
Q_ASSERT(m_icons != nullptr);
return m_icons;
}
bool Env::hasIcons()
{
return m_icons != nullptr;
}
/*
class NullVersion : public BaseVersion
{

View File

@ -6,7 +6,6 @@
#include "multimc_logic_export.h"
class IconList;
class QNetworkAccessManager;
class HttpMetaCache;
class BaseVersionList;
@ -33,10 +32,6 @@ public:
std::shared_ptr<HttpMetaCache> metacache();
std::shared_ptr<IconList> icons();
bool hasIcons();
/// init the cache. FIXME: possible future hook point
void initHttpMetaCache();
@ -59,7 +54,6 @@ public:
protected:
std::shared_ptr<QNetworkAccessManager> m_qnam;
std::shared_ptr<HttpMetaCache> m_metacache;
std::shared_ptr<IconList> m_icons;
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
std::shared_ptr<WonkoIndex> m_wonkoIndex;
QString m_wonkoRootUrl;

View File

@ -27,7 +27,6 @@
#include <QDebug>
#include "InstanceList.h"
#include "icons/IconList.h"
#include "BaseInstance.h"
//FIXME: this really doesn't belong *here*
@ -98,8 +97,7 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const
}
case Qt::DecorationRole:
{
QString key = pdata->iconKey();
return ENV.icons()->getIcon(key);
return pdata->iconKey();
}
// HACK: see GroupView.h in gui!
case GroupRole:

View File

@ -16,7 +16,6 @@
#pragma once
#include <QtNetwork>
#include <QLabel>
#include "JavaChecker.h"
#include "tasks/Task.h"

View File

@ -16,7 +16,6 @@
#pragma once
#include <QStringList>
#include <QWidget>
#include "JavaCheckerJob.h"
#include "JavaChecker.h"

Some files were not shown because too many files have changed in this diff Show More