summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-06-16 15:39:59 -0400
committerGitHub <noreply@github.com>2020-06-16 15:39:59 -0400
commit4ae95e21ad77256cb9fe2942a302bbcdda04ef30 (patch)
treed6a017fe88ae98c5f478e9497c5b36db5584bb69 /src
parent7d553557a64e9a3eb6656a09cbe70103f576b3b9 (diff)
parent8c410aff33395daf607ae8a1c62b8be70943ba4d (diff)
Merge pull request #1135 from Holt59/new-iorganizer-callbacks
Update for new organizer callbacks.
Diffstat (limited to 'src')
-rw-r--r--src/iuserinterface.h3
-rw-r--r--src/mainwindow.cpp6
-rw-r--r--src/mainwindow.h7
-rw-r--r--src/organizercore.cpp54
-rw-r--r--src/organizercore.h29
-rw-r--r--src/organizerproxy.cpp24
-rw-r--r--src/organizerproxy.h3
-rw-r--r--src/processrunner.cpp4
8 files changed, 97 insertions, 33 deletions
diff --git a/src/iuserinterface.h b/src/iuserinterface.h
index aa48194f..cce89070 100644
--- a/src/iuserinterface.h
+++ b/src/iuserinterface.h
@@ -7,6 +7,7 @@
#include <ipluginmodpage.h>
#include <delayedfilewriter.h>
#include <QMenu>
+#include <QMainWindow>
class IUserInterface
@@ -30,7 +31,7 @@ public:
virtual MOBase::DelayedFileWriterBase &archivesWriter() = 0;
- virtual QWidget* qtWidget() = 0;
+ virtual QMainWindow* mainWindow() = 0;
};
#endif // IUSERINTERFACE_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index fef69010..91c906a1 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -502,6 +502,7 @@ MainWindow::MainWindow(Settings &settings
m_Tutorial.expose("espList", m_OrganizerCore.pluginList());
m_OrganizerCore.setUserInterface(this);
+ connect(this, &MainWindow::userInterfaceInitialized, &m_OrganizerCore, &OrganizerCore::userInterfaceInitialized);
for (const QString &fileName : m_PluginContainer.pluginFileNames()) {
installTranslator(QFileInfo(fileName).baseName());
}
@@ -1382,6 +1383,9 @@ void MainWindow::showEvent(QShowEvent *event)
m_OrganizerCore.settings().nexus().registerAsNXMHandler(false);
m_WasVisible = true;
updateProblemsButton();
+
+ // Notify plugin that the UI is initialized:
+ emit userInterfaceInitialized();
}
}
@@ -2264,7 +2268,7 @@ void MainWindow::storeSettings()
s.interface().setFilterOptions(FilterWidget::options());
}
-QWidget* MainWindow::qtWidget()
+QMainWindow* MainWindow::mainWindow()
{
return this;
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 94626ff3..60f22770 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -118,7 +118,7 @@ public:
void processUpdates();
- QWidget* qtWidget() override;
+ QMainWindow* mainWindow() override;
bool addProfile();
void updateBSAList(const QStringList &defaultArchives, const QStringList &activeArchives);
@@ -175,6 +175,11 @@ signals:
*/
void styleChanged(const QString &styleFile);
+ /**
+ * @brief emitted when the user interface has been completely initialized
+ */
+ void userInterfaceInitialized();
+
void modListDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index b167b8e3..062369d6 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);
@@ -230,7 +233,7 @@ void OrganizerCore::setUserInterface(IUserInterface* ui)
QWidget* w = nullptr;
if (m_UserInterface) {
- w = m_UserInterface->qtWidget();
+ w = m_UserInterface->mainWindow();
}
if (w) {
@@ -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()
+{
+ m_UserInterfaceInitialized(m_UserInterface->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<Profile>(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<uint>)), this, SLOT(modStatusChanged(QList<uint>)));
+ connect(m_CurrentProfile.get(), SIGNAL(modStatusChanged(uint)), this, SLOT(modStatusChanged(uint)));
+ connect(m_CurrentProfile.get(), SIGNAL(modStatusChanged(QList<uint>)), this, SLOT(modStatusChanged(QList<uint>)));
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<void(QMainWindow*)> const& func)
+{
+ return m_UserInterfaceInitialized.connect(func).connected();
+}
+
+bool OrganizerCore::onProfileChanged(std::function<void(IProfile*, IProfile*)> const& func)
+{
+ return m_ProfileChanged.connect(func).connected();
+}
+
+bool OrganizerCore::onPluginSettingChanged(std::function<void(QString const&, const QString& key, const QVariant&, const QVariant&)> 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;
}
@@ -1804,7 +1834,7 @@ bool OrganizerCore::beforeRun(
{
QWidget* w = nullptr;
if (m_UserInterface) {
- w = m_UserInterface->qtWidget();
+ w = m_UserInterface->mainWindow();
}
QMessageBox::warning(w, tr("Error"), e.what());
return false;
diff --git a/src/organizercore.h b/src/organizercore.h
index 81119866..2588d332 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -78,9 +78,12 @@ private:
private:
- typedef boost::signals2::signal<bool (const QString&), SignalCombinerAnd> SignalAboutToRunApplication;
- typedef boost::signals2::signal<void (const QString&, unsigned int)> SignalFinishedRunApplication;
- typedef boost::signals2::signal<void (const QString&)> SignalModInstalled;
+ using SignalAboutToRunApplication = boost::signals2::signal<bool (const QString&), SignalCombinerAnd>;
+ using SignalFinishedRunApplication = boost::signals2::signal<void (const QString&, unsigned int)>;
+ using SignalModInstalled = boost::signals2::signal<void (const QString&)>;
+ using SignalUserInterfaceInitialized = boost::signals2::signal<void (QMainWindow*)>;
+ using SignalProfileChanged = boost::signals2::signal<void (MOBase::IProfile *, MOBase::IProfile *)>;
+ using SignalPluginSettingChanged = boost::signals2::signal<void (QString const&, const QString& key, const QVariant&, const QVariant&)>;
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<QString> enabledArchives();
@@ -315,12 +318,17 @@ public:
DownloadManager *downloadManager();
PluginList *pluginList();
ModList *modList();
- bool onModInstalled(const std::function<void (const QString &)> &func);
- bool onAboutToRun(const std::function<bool (const QString &)> &func);
- bool onFinishedRun(const std::function<void (const QString &, unsigned int)> &func);
void refreshModList(bool saveChanges = true);
QStringList modsSortedByProfilePriority() const;
+
+ bool onModInstalled(const std::function<void(const QString&)>& func);
+ bool onAboutToRun(const std::function<bool(const QString&)>& func);
+ bool onFinishedRun(const std::function<void(const QString&, unsigned int)>& func);
+ bool onUserInterfaceInitialized(std::function<void(QMainWindow*)> const& func);
+ bool onProfileChanged(std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func);
+ bool onPluginSettingChanged(std::function<void(QString const&, const QString& key, const QVariant&, const QVariant&)> 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();
+
bool nexusApi(bool retry = false);
signals:
@@ -422,7 +432,7 @@ private:
MOBase::IPluginGame *m_GamePlugin;
ModDataContentHolder m_Contents;
- Profile *m_CurrentProfile;
+ std::unique_ptr<Profile> 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..9ccc3c17 100644
--- a/src/organizerproxy.cpp
+++ b/src/organizerproxy.cpp
@@ -14,17 +14,10 @@ using namespace MOShared;
OrganizerProxy::OrganizerProxy(OrganizerCore *organizer, PluginContainer *pluginContainer, const QString &pluginName)
- : IOrganizer(organizer)
- , m_Proxied(organizer)
+ : 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 +186,21 @@ bool OrganizerProxy::onModInstalled(const std::function<void (const QString &)>
return m_Proxied->onModInstalled(func);
}
+bool OrganizerProxy::onUserInterfaceInitialized(std::function<void(QMainWindow*)> const& func)
+{
+ return m_Proxied->onUserInterfaceInitialized(func);
+}
+
+bool OrganizerProxy::onProfileChanged(std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func)
+{
+ return m_Proxied->onProfileChanged(func);
+}
+
+bool OrganizerProxy::onPluginSettingChanged(std::function<void(QString const&, const QString& key, const QVariant&, const QVariant&)> 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<bool(const QString&)> &func);
virtual bool onFinishedRun(const std::function<void (const QString&, unsigned int)> &func);
virtual bool onModInstalled(const std::function<void (const QString&)> &func);
+ virtual bool onUserInterfaceInitialized(std::function<void(QMainWindow*)> const& func);
+ virtual bool onProfileChanged(std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func);
+ virtual bool onPluginSettingChanged(std::function<void(QString const&, const QString& key, const QVariant&, const QVariant&)> const& func);
virtual MOBase::IPluginGame const *managedGame() const;
diff --git a/src/processrunner.cpp b/src/processrunner.cpp
index 91443750..3ea40da2 100644
--- a/src/processrunner.cpp
+++ b/src/processrunner.cpp
@@ -520,7 +520,7 @@ ProcessRunner& ProcessRunner::setFromFile(
QWidget* parent, const QFileInfo& targetInfo)
{
if (!parent && m_ui) {
- parent = m_ui->qtWidget();
+ parent = m_ui->mainWindow();
}
// if the file is a .exe, start it directly; if it's anything else, ask the
@@ -767,7 +767,7 @@ std::optional<ProcessRunner::Results> ProcessRunner::runBinary()
}
// parent widget used for any dialog popped up while checking for things
- QWidget* parent = (m_ui ? m_ui->qtWidget() : nullptr);
+ QWidget* parent = (m_ui ? m_ui->mainWindow() : nullptr);
const auto* game = m_core.managedGame();
auto& settings = m_core.settings();