From 4dbdc1cb26809a569883b1685819ee9d632fdef1 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 3 May 2011 01:13:40 +0200 Subject: [PATCH] Implemented copy and delete profile functions --- apps/launcher/datafilespage.cpp | 70 +++++++++++++++++++++++++++++++-- apps/launcher/datafilespage.hpp | 1 + 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 1fa93962ac..06e9ff3f8a 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -83,12 +83,14 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) mNewProfileButton = new QPushButton(this); mNewProfileButton->setIcon(QIcon::fromTheme("document-new")); + mNewProfileButton->setShortcut(QKeySequence(tr("Ctrl+N"))); mCopyProfileButton = new QPushButton(this); mCopyProfileButton->setIcon(QIcon::fromTheme("edit-copy")); mDeleteProfileButton = new QPushButton(this); mDeleteProfileButton->setIcon(QIcon::fromTheme("document-close")); + mDeleteProfileButton->setShortcut(QKeySequence(tr("Delete"))); QHBoxLayout *bottomLayout = new QHBoxLayout(); @@ -122,6 +124,8 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) connect(mNewProfileButton, SIGNAL(pressed()), this, SLOT(newProfile())); + connect(mCopyProfileButton, SIGNAL(pressed()), this, SLOT(copyProfile())); + connect(mDeleteProfileButton, SIGNAL(pressed()), this, SLOT(deleteProfile())); setupConfig(); } @@ -149,15 +153,73 @@ void DataFilesPage::newProfile() } +void DataFilesPage::copyProfile() +{ + QString profile = mProfilesComboBox->currentText(); + bool ok; + + QString text = QInputDialog::getText(this, tr("Copy Profile"), + tr("Profile Name:"), QLineEdit::Normal, + tr("%0 Copy").arg(profile), &ok); + if (ok && !text.isEmpty()) { + if (mProfilesComboBox->findText(text) != -1) + { + QMessageBox::warning(this, tr("Profile already exists"), + tr("the profile %0 already exists.").arg(text), + QMessageBox::Ok); + } else { + // Add the new profile to the combobox + mProfilesComboBox->addItem(text); + + // First write the current profile as the new profile + writeConfig(text); + mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(text)); + + } + + } + +} + void DataFilesPage::deleteProfile() { QString profile = mProfilesComboBox->currentText(); - if (!profile.isEmpty()) { - QMessageBox::warning(this, tr("Delete profile"), - tr("Are you sure you want to remove %0.").arg(profile), - QMessageBox::Ok); + if (profile.isEmpty()) { + return; + } + + QMessageBox deleteMessageBox(this); + deleteMessageBox.setWindowTitle(tr("Delete Profile")); + deleteMessageBox.setText(tr("Are you sure you want to delete %0?").arg(profile)); + deleteMessageBox.setIcon(QMessageBox::Warning); + QAbstractButton *deleteButton = + deleteMessageBox.addButton(tr("Delete"), QMessageBox::ActionRole); + + deleteMessageBox.addButton(QMessageBox::Cancel); + + deleteMessageBox.exec(); + + if (deleteMessageBox.clickedButton() == deleteButton) { + + qDebug() << "Delete profile " << profile; + + // Make sure we have no groups open + while (!mLauncherConfig->group().isEmpty()) { + mLauncherConfig->endGroup(); + } + + mLauncherConfig->beginGroup("Profiles"); + + // Open the profile-name subgroup + mLauncherConfig->beginGroup(profile); + mLauncherConfig->remove(""); // Clear the subgroup + mLauncherConfig->endGroup(); + mLauncherConfig->endGroup(); + + // Remove the profile from the combobox + mProfilesComboBox->removeItem(mProfilesComboBox->findText(profile)); } } diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 2d91cf3293..2aebc01605 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -39,6 +39,7 @@ public slots: void resizeRows(); void profileChanged(const QString &previous, const QString ¤t); void newProfile(); + void copyProfile(); void deleteProfile(); private: