From 0a19f0433992be5f9791c8869380d09cd06b66b8 Mon Sep 17 00:00:00 2001 From: Tannin Date: Fri, 22 Mar 2013 18:46:40 +0100 Subject: - support for grouping filters for mod list (incomplete) - offering multiple options for mod names during installation - support for renaming profiles - updated installer plugins - minor bugfixes --- src/profilesdialog.cpp | 82 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 24 deletions(-) (limited to 'src/profilesdialog.cpp') diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index cbf50dfc..733412b0 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -37,6 +37,8 @@ along with Mod Organizer. If not, see . using namespace MOBase; using namespace MOShared; +Q_DECLARE_METATYPE(Profile::Ptr) + ProfilesDialog::ProfilesDialog(const QString &gamePath, QWidget *parent) : TutorableDialog("Profiles", parent), ui(new Ui::ProfilesDialog), m_GamePath(gamePath), m_FailState(false) @@ -89,11 +91,11 @@ void ProfilesDialog::on_closeButton_clicked() void ProfilesDialog::addItem(const QString &name) { try { - QVariant temp; +// QVariant temp; QDir profileDir(name); - temp.setValue(Profile(profileDir)); +// temp.setValue(Profile(profileDir)); QListWidgetItem *newItem = new QListWidgetItem(profileDir.dirName(), m_ProfilesList); - newItem->setData(Qt::UserRole, temp); + newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(profileDir)))); m_FailState = false; } catch (const std::exception& e) { reportError(tr("failed to create profile: %1").arg(e.what())); @@ -104,11 +106,11 @@ void ProfilesDialog::addItem(const QString &name) void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) { try { - QVariant temp; - temp.setValue(Profile(name, useDefaultSettings)); +// QVariant temp; +// temp.setValue(Profile(name, useDefaultSettings)); QListWidget *profilesList = findChild("profilesList"); QListWidgetItem *newItem = new QListWidgetItem(name, profilesList); - newItem->setData(Qt::UserRole, temp); + newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(name, useDefaultSettings)))); profilesList->addItem(newItem); m_FailState = false; } catch (const std::exception&) { @@ -121,13 +123,13 @@ void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) void ProfilesDialog::createProfile(const QString &name, const Profile &reference) { try { - Profile newProfile = Profile::createFrom(name, reference); +// Profile newProfile = Profile::createFrom(name, reference); - QVariant temp; - temp.setValue(newProfile); +// QVariant temp; +// temp.setValue(newProfile); QListWidget *profilesList = findChild("profilesList"); QListWidgetItem *newItem = new QListWidgetItem(name, profilesList); - newItem->setData(Qt::UserRole, temp); + newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(Profile::createPtrFrom(name, reference)))); profilesList->addItem(newItem); m_FailState = false; } catch (const std::exception&) { @@ -160,8 +162,8 @@ void ProfilesDialog::on_copyProfileButton_clicked() QListWidget *profilesList = findChild("profilesList"); try { - const Profile ¤tProfile = profilesList->currentItem()->data(Qt::UserRole).value(); - createProfile(name, currentProfile); + const Profile::Ptr currentProfile = profilesList->currentItem()->data(Qt::UserRole).value(); + createProfile(name, *currentProfile); } catch (const std::exception &e) { reportError(tr("failed to copy profile: %1").arg(e.what())); } @@ -176,11 +178,11 @@ void ProfilesDialog::on_removeProfileButton_clicked() if (confirmBox.exec() == QMessageBox::Yes) { QListWidget *profilesList = findChild("profilesList"); - const Profile ¤tProfile = profilesList->currentItem()->data(Qt::UserRole).value(); + Profile::Ptr currentProfile = profilesList->currentItem()->data(Qt::UserRole).value(); // on destruction, the profile object would write the profile.ini file again, so // we have to get rid of the it before deleting the directory - QString profilePath = currentProfile.getPath(); + QString profilePath = currentProfile->getPath(); QListWidgetItem* item = profilesList->takeItem(profilesList->currentRow()); if (item != NULL) { delete item; @@ -190,6 +192,33 @@ void ProfilesDialog::on_removeProfileButton_clicked() } +void ProfilesDialog::on_renameButton_clicked() +{ + Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); + + bool valid = false; + QString name; + + while (!valid) { + bool ok = false; + name = QInputDialog::getText(this, tr("Rename Profile"), tr("New Name"), + QLineEdit::Normal, currentProfile->getName(), + &ok); + valid = fixDirectoryName(name); + if (!ok) { + return; + } + } + + ui->profilesList->currentItem()->setText(name); + currentProfile->rename(name); + +// QVariant temp; +// temp.setValue(currentProfile); +// ui->profilesList->currentItem()->setData(Qt::UserRole, temp); +} + + void ProfilesDialog::on_invalidationBox_stateChanged(int state) { QListWidget *profilesList = findChild("profilesList"); @@ -206,11 +235,11 @@ void ProfilesDialog::on_invalidationBox_stateChanged(int state) if (!currentProfileVariant.isValid() || currentProfileVariant.isNull()) { return; } - const Profile ¤tProfile = currentItem->data(Qt::UserRole).value(); + const Profile::Ptr currentProfile = currentItem->data(Qt::UserRole).value(); if (state == Qt::Unchecked) { - currentProfile.deactivateInvalidation(); + currentProfile->deactivateInvalidation(); } else { - currentProfile.activateInvalidation(m_GamePath + "/data"); + currentProfile->activateInvalidation(m_GamePath + "/data"); } } catch (const std::exception &e) { reportError(tr("failed to change archive invalidation state: %1").arg(e.what())); @@ -225,18 +254,19 @@ void ProfilesDialog::on_profilesList_currentItemChanged(QListWidgetItem *current QPushButton *copyButton = findChild("copyProfileButton"); QPushButton *removeButton = findChild("removeProfileButton"); QPushButton *transferButton = findChild("transferButton"); + QPushButton *renameButton = findChild("renameButton"); if (current != NULL) { - const Profile ¤tProfile = current->data(Qt::UserRole).value(); + const Profile::Ptr currentProfile = current->data(Qt::UserRole).value(); try { bool invalidationSupported = false; invalidationBox->blockSignals(true); - invalidationBox->setChecked(currentProfile.invalidationActive(&invalidationSupported)); + invalidationBox->setChecked(currentProfile->invalidationActive(&invalidationSupported)); invalidationBox->setEnabled(invalidationSupported); invalidationBox->blockSignals(false); - bool localSaves = currentProfile.localSavesEnabled(); + bool localSaves = currentProfile->localSavesEnabled(); transferButton->setEnabled(localSaves); // prevent the stateChanged-event for the saves-box from triggering, otherwise it may think local saves // were disabled and delete the files/rename the dir @@ -246,23 +276,27 @@ void ProfilesDialog::on_profilesList_currentItemChanged(QListWidgetItem *current copyButton->setEnabled(true); removeButton->setEnabled(true); + renameButton->setEnabled(true); } catch (const std::exception& E) { reportError(tr("failed to determine if invalidation is active: %1").arg(E.what())); copyButton->setEnabled(false); removeButton->setEnabled(false); + renameButton->setEnabled(false); invalidationBox->setChecked(false); } } else { invalidationBox->setChecked(false); copyButton->setEnabled(false); removeButton->setEnabled(false); + renameButton->setEnabled(false); } } void ProfilesDialog::on_localSavesBox_stateChanged(int state) { - Profile ¤tProfile = m_ProfilesList->currentItem()->data(Qt::UserRole).value(); - if (currentProfile.enableLocalSaves(state == Qt::Checked)) { + Profile::Ptr currentProfile = m_ProfilesList->currentItem()->data(Qt::UserRole).value(); + + if (currentProfile->enableLocalSaves(state == Qt::Checked)) { ui->transferButton->setEnabled(state == Qt::Checked); } else { // revert checkbox-state @@ -272,7 +306,7 @@ void ProfilesDialog::on_localSavesBox_stateChanged(int state) void ProfilesDialog::on_transferButton_clicked() { - const Profile ¤tProfile = m_ProfilesList->currentItem()->data(Qt::UserRole).value(); - TransferSavesDialog transferDialog(currentProfile, this); + const Profile::Ptr currentProfile = m_ProfilesList->currentItem()->data(Qt::UserRole).value(); + TransferSavesDialog transferDialog(*currentProfile, this); transferDialog.exec(); } -- cgit v1.3.1