From f66cf4ad99219716e221f2a6717b910e531bc7d3 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Mon, 15 Jun 2020 22:47:21 +0200 Subject: Update for new organizer callbacks. --- src/mainwindow.cpp | 2 ++ src/organizercore.cpp | 50 ++++++++++++++++++++++++++++++++++++++++---------- src/organizercore.h | 29 +++++++++++++++++++++-------- src/organizerproxy.cpp | 23 ++++++++++++++++------- src/organizerproxy.h | 3 +++ 5 files changed, 82 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fef69010..6a18f76c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -539,6 +539,8 @@ MainWindow::MainWindow(Settings &settings processUpdates(); ui->statusBar->updateNormalMessage(m_OrganizerCore); + + m_OrganizerCore.userInterfaceInitialized(this); } void MainWindow::setupModList() diff --git a/src/organizercore.cpp b/src/organizercore.cpp index b167b8e3..45207910 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -151,6 +151,10 @@ OrganizerCore::OrganizerCore(Settings &settings) // make directory refresher run in a separate thread m_RefresherThread.start(); m_DirectoryRefresher->moveToThread(&m_RefresherThread); + + connect(&settings.plugins(), &PluginSettings::pluginSettingChanged, [this](auto const& ...args) { + m_PluginSettingChanged(args...); + }); } OrganizerCore::~OrganizerCore() @@ -165,8 +169,7 @@ OrganizerCore::~OrganizerCore() saveCurrentProfile(); // profile has to be cleaned up before the modinfo-buffer is cleared - delete m_CurrentProfile; - m_CurrentProfile = nullptr; + m_CurrentProfile.reset(); ModInfo::clear(); m_ModList.setProfile(nullptr); @@ -297,6 +300,10 @@ void OrganizerCore::disconnectPlugins() m_AboutToRun.disconnect_all_slots(); m_FinishedRun.disconnect_all_slots(); m_ModInstalled.disconnect_all_slots(); + m_UserInterfaceInitialized.disconnect_all_slots(); + m_ProfileChanged.disconnect_all_slots(); + m_PluginSettingChanged.disconnect_all_slots(); + m_ModList.disconnectSlots(); m_PluginList.disconnectSlots(); m_Updater.setPluginContainer(nullptr); @@ -364,6 +371,11 @@ void OrganizerCore::downloadRequestedNXM(const QString &url) } } +void OrganizerCore::userInterfaceInitialized(QMainWindow* mainWindow) +{ + m_UserInterfaceInitialized(mainWindow); +} + void OrganizerCore::externalMessage(const QString &message) { if (MOShortcut moshortcut{ message } ) { @@ -533,11 +545,12 @@ void OrganizerCore::setCurrentProfile(const QString &profileName) profileBaseDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot).at(0)); } - Profile *newProfile = new Profile(QDir(profileDir), managedGame()); + // Keep the old profile to emit signal-changed: + auto oldProfile = std::move(m_CurrentProfile); + + m_CurrentProfile = std::make_unique(QDir(profileDir), managedGame()); - delete m_CurrentProfile; - m_CurrentProfile = newProfile; - m_ModList.setProfile(newProfile); + m_ModList.setProfile(m_CurrentProfile.get()); if (m_CurrentProfile->invalidationActive(nullptr)) { m_CurrentProfile->activateInvalidation(); @@ -547,11 +560,13 @@ void OrganizerCore::setCurrentProfile(const QString &profileName) m_Settings.game().setSelectedProfileName(m_CurrentProfile->name()); - connect(m_CurrentProfile, SIGNAL(modStatusChanged(uint)), this, SLOT(modStatusChanged(uint))); - connect(m_CurrentProfile, SIGNAL(modStatusChanged(QList)), this, SLOT(modStatusChanged(QList))); + connect(m_CurrentProfile.get(), SIGNAL(modStatusChanged(uint)), this, SLOT(modStatusChanged(uint))); + connect(m_CurrentProfile.get(), SIGNAL(modStatusChanged(QList)), this, SLOT(modStatusChanged(QList))); refreshDirectoryStructure(); m_CurrentProfile->debugDump(); + + m_ProfileChanged(oldProfile.get(), m_CurrentProfile.get()); } MOBase::IModRepositoryBridge *OrganizerCore::createNexusBridge() const @@ -1100,6 +1115,21 @@ bool OrganizerCore::onModInstalled( return conn.connected(); } +bool OrganizerCore::onUserInterfaceInitialized(std::function const& func) +{ + return m_UserInterfaceInitialized.connect(func).connected(); +} + +bool OrganizerCore::onProfileChanged(std::function const& func) +{ + return m_ProfileChanged.connect(func).connected(); +} + +bool OrganizerCore::onPluginSettingChanged(std::function const& func) +{ + return m_PluginSettingChanged.connect(func).connected(); +} + void OrganizerCore::refreshModList(bool saveChanges) { // don't lose changes! @@ -1153,7 +1183,7 @@ void OrganizerCore::refreshBSAList() // found (which might // happen if ini files are missing) use hard-coded defaults (preferrably the // same the game would use) - m_DefaultArchives = archives->archives(m_CurrentProfile); + m_DefaultArchives = archives->archives(m_CurrentProfile.get()); if (m_DefaultArchives.length() == 0) { m_DefaultArchives = archives->vanillaArchives(); } @@ -1370,7 +1400,7 @@ void OrganizerCore::requestDownload(const QUrl &url, QNetworkReply *reply) ModListSortProxy *OrganizerCore::createModListProxyModel() { - ModListSortProxy *result = new ModListSortProxy(m_CurrentProfile, this); + ModListSortProxy *result = new ModListSortProxy(m_CurrentProfile.get(), this); result->setSourceModel(&m_ModList); return result; } diff --git a/src/organizercore.h b/src/organizercore.h index 81119866..ae4a34c4 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -78,9 +78,12 @@ private: private: - typedef boost::signals2::signal SignalAboutToRunApplication; - typedef boost::signals2::signal SignalFinishedRunApplication; - typedef boost::signals2::signal SignalModInstalled; + using SignalAboutToRunApplication = boost::signals2::signal; + using SignalFinishedRunApplication = boost::signals2::signal; + using SignalModInstalled = boost::signals2::signal; + using SignalUserInterfaceInitialized = boost::signals2::signal; + using SignalProfileChanged = boost::signals2::signal; + using SignalPluginSettingChanged = boost::signals2::signal; public: @@ -215,7 +218,7 @@ public: m_ExecutablesList = executablesList; } - Profile *currentProfile() const { return m_CurrentProfile; } + Profile *currentProfile() const { return m_CurrentProfile.get(); } void setCurrentProfile(const QString &profileName); std::vector enabledArchives(); @@ -315,12 +318,17 @@ public: DownloadManager *downloadManager(); PluginList *pluginList(); ModList *modList(); - bool onModInstalled(const std::function &func); - bool onAboutToRun(const std::function &func); - bool onFinishedRun(const std::function &func); void refreshModList(bool saveChanges = true); QStringList modsSortedByProfilePriority() const; + + bool onModInstalled(const std::function& func); + bool onAboutToRun(const std::function& func); + bool onFinishedRun(const std::function& func); + bool onUserInterfaceInitialized(std::function const& func); + bool onProfileChanged(std::function const& func); + bool onPluginSettingChanged(std::function const& func); + bool getArchiveParsing() const { return m_ArchiveParsing; @@ -357,6 +365,8 @@ public slots: void requestDownload(const QUrl &url, QNetworkReply *reply); void downloadRequestedNXM(const QString &url); + void userInterfaceInitialized(QMainWindow *); + bool nexusApi(bool retry = false); signals: @@ -422,7 +432,7 @@ private: MOBase::IPluginGame *m_GamePlugin; ModDataContentHolder m_Contents; - Profile *m_CurrentProfile; + std::unique_ptr m_CurrentProfile; Settings& m_Settings; @@ -431,6 +441,9 @@ private: SignalAboutToRunApplication m_AboutToRun; SignalFinishedRunApplication m_FinishedRun; SignalModInstalled m_ModInstalled; + SignalUserInterfaceInitialized m_UserInterfaceInitialized; + SignalProfileChanged m_ProfileChanged; + SignalPluginSettingChanged m_PluginSettingChanged; ModList m_ModList; PluginList m_PluginList; diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index d728ecad..d8c64eca 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -14,17 +14,11 @@ using namespace MOShared; OrganizerProxy::OrganizerProxy(OrganizerCore *organizer, PluginContainer *pluginContainer, const QString &pluginName) - : IOrganizer(organizer) + : IOrganizer() , m_Proxied(organizer) , m_PluginContainer(pluginContainer) , m_PluginName(pluginName) { - - PluginSettings& pluginSettings = m_Proxied->settings().plugins(); - - connect(&pluginSettings, &PluginSettings::pluginSettingChanged, [this](auto const& ...args) { - emit pluginSettingChanged(args...); - }); } IModRepositoryBridge *OrganizerProxy::createNexusBridge() const @@ -193,6 +187,21 @@ bool OrganizerProxy::onModInstalled(const std::function return m_Proxied->onModInstalled(func); } +bool OrganizerProxy::onUserInterfaceInitialized(std::function const& func) +{ + return m_Proxied->onUserInterfaceInitialized(func); +} + +bool OrganizerProxy::onProfileChanged(std::function const& func) +{ + return m_Proxied->onProfileChanged(func); +} + +bool OrganizerProxy::onPluginSettingChanged(std::function const& func) +{ + return m_Proxied->onPluginSettingChanged(func); +} + void OrganizerProxy::refreshModList(bool saveChanges) { m_Proxied->refreshModList(saveChanges); diff --git a/src/organizerproxy.h b/src/organizerproxy.h index 8a0177c8..e64e8838 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -52,6 +52,9 @@ public: virtual bool onAboutToRun(const std::function &func); virtual bool onFinishedRun(const std::function &func); virtual bool onModInstalled(const std::function &func); + virtual bool onUserInterfaceInitialized(std::function const& func); + virtual bool onProfileChanged(std::function const& func); + virtual bool onPluginSettingChanged(std::function const& func); virtual MOBase::IPluginGame const *managedGame() const; -- cgit v1.3.1