diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-10-24 20:54:22 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-10-24 20:54:22 +0200 |
| commit | 8e591143a5fce58597a1597887b1730e24263224 (patch) | |
| tree | 2314392a167e4cc1ca63207468130abfe8062e92 /src | |
| parent | 52cfb8e8a7609c8b763652e1575a769dd5fe1b02 (diff) | |
Add IOrganizer::onProfileXXX callbacks.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 6 | ||||
| -rw-r--r-- | src/organizercore.cpp | 32 | ||||
| -rw-r--r-- | src/organizercore.h | 13 | ||||
| -rw-r--r-- | src/organizerproxy.cpp | 15 | ||||
| -rw-r--r-- | src/organizerproxy.h | 15 | ||||
| -rw-r--r-- | src/profilesdialog.cpp | 27 | ||||
| -rw-r--r-- | src/profilesdialog.h | 21 |
7 files changed, 113 insertions, 16 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3428d72a..18cc85f0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1765,9 +1765,9 @@ void MainWindow::on_profileBox_currentIndexChanged(int index) if (ui->profileBox->currentIndex() == 0) { ui->profileBox->setCurrentIndex(previousIndex); - ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore.managedGame(), this).exec(); + ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore, this).exec(); while (!refreshProfiles()) { - ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore.managedGame(), this).exec(); + ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore, this).exec(); } } else { activateSelectedProfile(); @@ -2432,7 +2432,7 @@ void MainWindow::on_actionAdd_Profile_triggered() { for (;;) { ProfilesDialog profilesDialog(m_OrganizerCore.currentProfile()->name(), - m_OrganizerCore.managedGame(), + m_OrganizerCore, this); // workaround: need to disable monitoring of the saves directory, otherwise the active diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 2aaeb86c..7c975053 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -378,6 +378,22 @@ void OrganizerCore::userInterfaceInitialized() m_UserInterfaceInitialized(m_UserInterface->mainWindow()); } +void OrganizerCore::profileCreated(MOBase::IProfile* profile) +{ + m_ProfileCreated(profile); +} + +void OrganizerCore::profileRenamed(MOBase::IProfile* profile, QString const& oldName, QString const& newName) +{ + m_ProfileRenamed(profile, oldName, newName); +} + +void OrganizerCore::profileRemoved(QString const& profileName) +{ + m_ProfileRemoved(profileName); +} + + void OrganizerCore::externalMessage(const QString &message) { if (MOShortcut moshortcut{ message } ) { @@ -470,6 +486,7 @@ void OrganizerCore::createDefaultProfile() if (QDir(profilesPath).entryList(QDir::AllDirs | QDir::NoDotAndDotDot).size() == 0) { Profile newProf("Default", managedGame(), false); + m_ProfileCreated(&newProf); } } @@ -1144,6 +1161,21 @@ bool OrganizerCore::onUserInterfaceInitialized(std::function<void(QMainWindow*)> return m_UserInterfaceInitialized.connect(func).connected(); } +bool OrganizerCore::onProfileCreated(std::function<void(MOBase::IProfile*)> const& func) +{ + return m_ProfileCreated.connect(func).connected(); +} + +bool OrganizerCore::onProfileRenamed(std::function<void(MOBase::IProfile*, QString const&, QString const&)> const& func) +{ + return m_ProfileRenamed.connect(func).connected(); +} + +bool OrganizerCore::onProfileRemoved(std::function<void(QString const&)> const& func) +{ + return m_ProfileRemoved.connect(func).connected(); +} + bool OrganizerCore::onProfileChanged(std::function<void(IProfile*, IProfile*)> const& func) { return m_ProfileChanged.connect(func).connected(); diff --git a/src/organizercore.h b/src/organizercore.h index 813bf084..b545e4d7 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -82,6 +82,9 @@ private: 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 SignalProfileCreated = boost::signals2::signal<void(MOBase::IProfile*)>;
+ using SignalProfileRenamed = boost::signals2::signal<void(MOBase::IProfile*, QString const&, QString const&)>;
+ using SignalProfileRemoved = boost::signals2::signal<void(QString const&)>;
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&)>;
@@ -326,6 +329,9 @@ public: 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 onProfileCreated(std::function<void(MOBase::IProfile*)> const& func);
+ bool onProfileRenamed(std::function<void(MOBase::IProfile*, QString const&, QString const&)> const& func);
+ bool onProfileRemoved(std::function<void(QString const&)> 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);
@@ -367,6 +373,10 @@ public slots: void userInterfaceInitialized();
+ void profileCreated(MOBase::IProfile* profile);
+ void profileRenamed(MOBase::IProfile* profile, QString const& oldName, QString const& newName);
+ void profileRemoved(QString const& profileName);
+
bool nexusApi(bool retry = false);
signals:
@@ -442,6 +452,9 @@ private: SignalFinishedRunApplication m_FinishedRun;
SignalModInstalled m_ModInstalled;
SignalUserInterfaceInitialized m_UserInterfaceInitialized;
+ SignalProfileCreated m_ProfileCreated;
+ SignalProfileRenamed m_ProfileRenamed;
+ SignalProfileRemoved m_ProfileRemoved;
SignalProfileChanged m_ProfileChanged;
SignalPluginSettingChanged m_PluginSettingChanged;
diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 2932e6bf..df73603a 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -282,6 +282,21 @@ bool OrganizerProxy::onUserInterfaceInitialized(std::function<void(QMainWindow*) return m_Proxied->onUserInterfaceInitialized(func);
}
+bool OrganizerProxy::onProfileCreated(std::function<void(IProfile*)> const& func)
+{
+ return m_Proxied->onProfileCreated(MOShared::callIfPluginActive(this, func));
+}
+
+bool OrganizerProxy::onProfileRenamed(std::function<void(IProfile*, QString const&, QString const&)> const& func)
+{
+ return m_Proxied->onProfileRenamed(MOShared::callIfPluginActive(this, func));
+}
+
+bool OrganizerProxy::onProfileRemoved(std::function<void(QString const&)> const& func)
+{
+ return m_Proxied->onProfileRemoved(MOShared::callIfPluginActive(this, func));
+}
+
bool OrganizerProxy::onProfileChanged(std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func)
{
return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func));
diff --git a/src/organizerproxy.h b/src/organizerproxy.h index cc059aa9..376d1a1a 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -59,12 +59,15 @@ public: virtual bool waitForApplication(HANDLE handle, LPDWORD exitCode = nullptr) const;
virtual void refreshModList(bool saveChanges);
- 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 bool onAboutToRun(const std::function<bool(const QString&)> &func) override;
+ virtual bool onFinishedRun(const std::function<void (const QString&, unsigned int)> &func) override;
+ virtual bool onModInstalled(const std::function<void (const QString&)> &func) override;
+ virtual bool onUserInterfaceInitialized(std::function<void(QMainWindow*)> const& func) override;
+ virtual bool onProfileCreated(std::function<void(MOBase::IProfile*)> const& func) override;
+ virtual bool onProfileRenamed(std::function<void(MOBase::IProfile*, QString const&, QString const&)> const& func) override;
+ virtual bool onProfileRemoved(std::function<void(QString const&)> const& func) override;
+ virtual bool onProfileChanged(std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func) override;
+ virtual bool onPluginSettingChanged(std::function<void(QString const&, const QString& key, const QVariant&, const QVariant&)> const& func) override;
virtual MOBase::IPluginGame const *managedGame() const;
diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index bf6a1d5e..192aaaf3 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -23,6 +23,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "shared/appconfig.h"
#include "bsainvalidation.h"
#include "iplugingame.h"
+#include "organizercore.h"
#include "profile.h"
#include "profileinputdialog.h"
#include "report.h"
@@ -49,11 +50,11 @@ using namespace MOShared; Q_DECLARE_METATYPE(Profile::Ptr)
-ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame const *game, QWidget *parent)
+ProfilesDialog::ProfilesDialog(const QString &profileName, OrganizerCore &organizer, QWidget *parent)
: TutorableDialog("Profiles", parent)
, ui(new Ui::ProfilesDialog)
, m_FailState(false)
- , m_Game(game)
+ , m_Game(organizer.managedGame())
, m_ActiveProfileName("")
{
ui->setupUi(this);
@@ -72,17 +73,21 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame c }
}
- BSAInvalidation *invalidation = game->feature<BSAInvalidation>();
+ BSAInvalidation *invalidation = m_Game->feature<BSAInvalidation>();
if (invalidation == nullptr) {
ui->invalidationBox->setToolTip(tr("Archive invalidation isn't required for this game."));
ui->invalidationBox->setEnabled(false);
}
- if (!game->feature<LocalSavegames>()) {
+ if (!m_Game->feature<LocalSavegames>()) {
ui->localSavesBox->setToolTip(tr("This game does not support profile-specific game saves."));
ui->localSavesBox->setEnabled(false);
}
+
+ connect(this, &ProfilesDialog::profileCreated, &organizer, &OrganizerCore::profileCreated);
+ connect(this, &ProfilesDialog::profileRenamed, &organizer, &OrganizerCore::profileRenamed);
+ connect(this, &ProfilesDialog::profileRemoved, &organizer, &OrganizerCore::profileRemoved);
}
ProfilesDialog::~ProfilesDialog()
@@ -133,9 +138,11 @@ void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) {
try {
QListWidgetItem *newItem = new QListWidgetItem(name, ui->profilesList);
- newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(name, m_Game, useDefaultSettings))));
+ Profile* profile = new Profile(name, m_Game, useDefaultSettings);
+ newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(profile)));
ui->profilesList->addItem(newItem);
m_FailState = false;
+ emit profileCreated(profile);
} catch (const std::exception&) {
m_FailState = true;
throw;
@@ -146,9 +153,11 @@ void ProfilesDialog::createProfile(const QString &name, const Profile &reference {
try {
QListWidgetItem *newItem = new QListWidgetItem(name, ui->profilesList);
- newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(Profile::createPtrFrom(name, reference, m_Game))));
+ Profile* profile = Profile::createPtrFrom(name, reference, m_Game);
+ newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(profile)));
ui->profilesList->addItem(newItem);
m_FailState = false;
+ emit profileCreated(profile);
} catch (const std::exception&) {
m_FailState = true;
throw;
@@ -231,6 +240,8 @@ void ProfilesDialog::on_removeProfileButton_clicked() log::warn("regular delete failed too");
}
}
+
+ emit profileRemoved(profileToDelete->name());
}
}
@@ -254,7 +265,11 @@ void ProfilesDialog::on_renameButton_clicked() }
ui->profilesList->currentItem()->setText(name);
+
+ QString oldName = currentProfile->name();
currentProfile->rename(name);
+
+ emit profileRenamed(currentProfile.get(), oldName, name);
}
diff --git a/src/profilesdialog.h b/src/profilesdialog.h index a47367be..08298d0e 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -22,6 +22,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "tutorabledialog.h"
class Profile;
+class OrganizerCore;
class QListWidget;
class QListWidgetItem;
@@ -46,9 +47,10 @@ public: * @brief constructor
*
* @param profileName currently enabled profile
+ * @param organizer
* @param parent parent widget
**/
- explicit ProfilesDialog(const QString &profileName, MOBase::IPluginGame const *game, QWidget *parent = 0);
+ explicit ProfilesDialog(const QString &profileName, OrganizerCore &organizer, QWidget *parent = 0);
~ProfilesDialog();
// also saves and restores geometry
@@ -61,6 +63,23 @@ public: **/
bool failed() const { return m_FailState; }
+signals:
+
+ /**
+ * @brief Signal emitted when a profile is created.
+ */
+ void profileCreated(Profile* profile);
+
+ /**
+ * @brief Signal emitted when a profile is renamed.
+ */
+ void profileRenamed(Profile* profile, QString const& oldName, QString const& newName);
+
+ /**
+ * @brief Signal emitted when a profile has been removed.
+ */
+ void profileRemoved(QString const& profileName);
+
protected:
virtual void showEvent(QShowEvent *event);
|
