diff --git a/kcms/solid_actions/ActionItem.cpp b/kcms/solid_actions/ActionItem.cpp index d0964962c..f5e39a3e6 100644 --- a/kcms/solid_actions/ActionItem.cpp +++ b/kcms/solid_actions/ActionItem.cpp @@ -1,157 +1,157 @@ /*************************************************************************** * Copyright (C) 2009 by Ben Cooksley * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * ***************************************************************************/ #include "ActionItem.h" #include "SolidActionData.h" #include #include #include #include #include ActionItem::ActionItem(const QString& pathToDesktop, const QString& action, QObject *parent) { Q_UNUSED(parent); desktopMasterPath = pathToDesktop; actionName = action; // Create the desktop file desktopFileMaster = new KDesktopFile(desktopMasterPath); desktopWritePath = desktopFileMaster->locateLocal(desktopMasterPath); desktopFileWrite = new KDesktopFile(desktopWritePath); // Now we can fill the action groups list configGroups.append(desktopFileMaster->desktopGroup()); actionGroups.insertMulti(ActionItem::GroupDesktop, &configGroups.last()); configGroups.append(desktopFileMaster->actionGroup(actionName)); actionGroups.insertMulti(ActionItem::GroupAction, &configGroups.last()); configGroups.append(desktopFileWrite->desktopGroup()); actionGroups.insertMulti(ActionItem::GroupDesktop, &configGroups.last()); configGroups.append(desktopFileWrite->actionGroup(actionName)); actionGroups.insertMulti(ActionItem::GroupAction, &configGroups.last()); const QString predicateString = readKey(ActionItem::GroupDesktop, QStringLiteral("X-KDE-Solid-Predicate"), QLatin1String("")); predicateItem = Solid::Predicate::fromString( predicateString ); } ActionItem::~ActionItem() { delete desktopFileWrite; delete desktopFileMaster; } /// Public functions below bool ActionItem::isUserSupplied() const { return hasKey(ActionItem::GroupDesktop, QStringLiteral("X-KDE-Action-Custom")); } QString ActionItem::icon() const { return readKey(ActionItem::GroupAction, QStringLiteral("Icon"), QLatin1String("")); } QString ActionItem::exec() const { return readKey(ActionItem::GroupAction, QStringLiteral("Exec"), QLatin1String("")); } QString ActionItem::name() const { return readKey(ActionItem::GroupAction, QStringLiteral("Name"), QLatin1String("")); } Solid::Predicate ActionItem::predicate() const { return predicateItem; } QString ActionItem::involvedTypes() const { SolidActionData * actData = SolidActionData::instance(); - QSet devTypeList = predicateItem.usedTypes(); + const QSet devTypeList = predicateItem.usedTypes(); QStringList deviceTypes; - foreach( Solid::DeviceInterface::Type devType, devTypeList ) { + for (Solid::DeviceInterface::Type devType : devTypeList) { deviceTypes << actData->nameFromInterface( devType ); } return deviceTypes.join(QLatin1String(", ")); } void ActionItem::setIcon(const QString& nameOfIcon) { setKey(ActionItem::GroupAction, QStringLiteral("Icon"), nameOfIcon); } void ActionItem::setName(const QString& nameOfAction) { setKey(ActionItem::GroupAction, QStringLiteral("Name"), nameOfAction); } void ActionItem::setExec(const QString& execUrl) { setKey(ActionItem::GroupAction, QStringLiteral("Exec"), execUrl); } void ActionItem::setPredicate( const QString& newPredicate ) { setKey(ActionItem::GroupDesktop, QStringLiteral("X-KDE-Solid-Predicate"), newPredicate); predicateItem = Solid::Predicate::fromString( newPredicate ); } /// Private functions below QString ActionItem::readKey(GroupType keyGroup, const QString& keyName, const QString& defaultValue) const { return configItem(ActionItem::DesktopRead, keyGroup, keyName)->readEntry(keyName, defaultValue); } void ActionItem::setKey(GroupType keyGroup, const QString& keyName, const QString& keyContents) { configItem(ActionItem::DesktopWrite, keyGroup)->writeEntry(keyName, keyContents); } bool ActionItem::hasKey(GroupType keyGroup, const QString& keyName) const { return configItem(ActionItem::DesktopRead, keyGroup, keyName)->hasKey(keyName); } KConfigGroup * ActionItem::configItem(DesktopAction actionType, GroupType keyGroup, const QString& keyName) const { int countAccess = 0; if (actionType == ActionItem::DesktopRead) { - foreach(KConfigGroup * possibleGroup, actionGroups.values(keyGroup)) { + const auto values = actionGroups.values(keyGroup); + for (KConfigGroup *possibleGroup : values) { if (possibleGroup->hasKey(keyName)) { return possibleGroup; - break; } } } else if (actionType == ActionItem::DesktopWrite) { if (isUserSupplied()) { countAccess = 1; } return actionGroups.values(keyGroup)[countAccess]; } return actionGroups.values(keyGroup)[0]; // Implement a backstop so a valid value is always returned } diff --git a/kcms/solid_actions/ActionModel.cpp b/kcms/solid_actions/ActionModel.cpp index a4a114467..8dd8b9282 100644 --- a/kcms/solid_actions/ActionModel.cpp +++ b/kcms/solid_actions/ActionModel.cpp @@ -1,129 +1,129 @@ /************************************************************************** * Copyright (C) 2009 Ben Cooksley * * Copyright (C) 2007 Will Stephenson * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * * 02110-1301, USA. * ***************************************************************************/ #include "ActionModel.h" #include "ActionItem.h" #include #include #include #include class ActionModel::Private { public: Private() {} QList actions; }; static bool sortAction( ActionItem * left, ActionItem * right ) { return left->name().localeAwareCompare(right->name()) < 0; } ActionModel::ActionModel( QObject *parent ) : QAbstractTableModel( parent ) , d( new Private() ) { } ActionModel::~ActionModel() { qDeleteAll( d->actions ); d->actions.clear(); delete d; } int ActionModel::columnCount( const QModelIndex &parent ) const { Q_UNUSED( parent ); return 2; } int ActionModel::rowCount( const QModelIndex &parent ) const { if( !parent.isValid() ) { return d->actions.count(); } return 0; } QVariant ActionModel::data( const QModelIndex &index, int role ) const { QVariant theData; if ( !index.isValid() ) { return QVariant(); } ActionItem * mi = d->actions.at( index.row() ); switch ( role ) { case Qt::DisplayRole: if( index.column() == 0 ) { theData.setValue( mi->name() ); } else if( index.column() == 1 ) { theData.setValue( mi->involvedTypes() ); } break; case Qt::DecorationRole: if( index.column() == 0 ) { theData = QIcon::fromTheme(mi->icon()); } break; case Qt::UserRole: theData.setValue( mi ); break; default: break; } return theData; } void ActionModel::buildActionList() { beginResetModel(); qDeleteAll( d->actions ); d->actions.clear(); // Prepare to search for possible actions -> we only want solid types const QStringList actionDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("solid/actions"), QStandardPaths::LocateDirectory); // Get service objects for those actions and add them to the display - foreach (const QString & actionDir, actionDirs) { + for (const QString &actionDir : actionDirs) { QDirIterator it(actionDir, QStringList() << QStringLiteral("*.desktop")); while (it.hasNext()) { it.next(); const QString desktop = it.filePath(); // Get contained services list - QList services = KDesktopFileActions::userDefinedServices(desktop, true); - foreach( const KServiceAction &deviceAction, services ) { + const QList services = KDesktopFileActions::userDefinedServices(desktop, true); + for (const KServiceAction &deviceAction : services) { ActionItem * actionItem = new ActionItem( desktop, deviceAction.name(), this ); // Create an action d->actions.append( actionItem ); } } } std::sort(d->actions.begin(), d->actions.end(), sortAction); endResetModel(); } QList ActionModel::actionList() const { return d->actions; } diff --git a/kcms/solid_actions/DesktopFileGenerator.cpp b/kcms/solid_actions/DesktopFileGenerator.cpp index 7e3cb8b19..8ef284131 100644 --- a/kcms/solid_actions/DesktopFileGenerator.cpp +++ b/kcms/solid_actions/DesktopFileGenerator.cpp @@ -1,81 +1,79 @@ /*************************************************************************** * Copyright (C) 2009 by Ben Cooksley * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * ***************************************************************************/ -#include #include #include #include #include #include #include #include "SolidActionData.h" int main( int argc, char *argv[] ) { QCoreApplication application(argc, argv); KLocalizedString::setApplicationDomain("kcm_solid_actions"); // About data KAboutData aboutData(QStringLiteral("solid-action-desktop-gen"), i18n("Solid Action Desktop File Generator"), QStringLiteral("0.4"), i18n("Tool to automatically generate Desktop Files from Solid DeviceInterface classes for translation"), KAboutLicense::GPL, i18n("(c) 2009, Ben Cooksley")); aboutData.addAuthor(i18n("Ben Cooksley"), i18n("Maintainer"), QStringLiteral("ben@eclipse.endoftheinternet.org")); KAboutData::setApplicationData(aboutData); QCommandLineParser parser; aboutData.setupCommandLine(&parser); parser.process(application); aboutData.processCommandLine(&parser); - SolidActionData * availActions = SolidActionData::instance(); - foreach( Solid::DeviceInterface::Type internalType, availActions->interfaceTypeList() ) { + SolidActionData *availActions = SolidActionData::instance(); + const auto interfaceTypes = availActions->interfaceTypeList(); + for (Solid::DeviceInterface::Type internalType : interfaceTypes) { const QString typeName = Solid::DeviceInterface::typeToString( internalType ); KDesktopFile typeFile(QStandardPaths::GenericDataLocation, "solid/devices/solid-device-" + typeName + ".desktop" ); KConfigGroup tConfig = typeFile.desktopGroup(); tConfig.writeEntry( "Name", "Solid Device" ); tConfig.writeEntry( "X-KDE-ServiceTypes", "SolidDevice" ); tConfig.writeEntry( "Type", "Service" ); if( !tConfig.hasKey("X-KDE-Solid-Actions-Type") ) { tConfig.writeEntry( "X-KDE-Solid-Actions-Type", typeName ); } const QStringList typeValues = availActions->propertyInternalList( internalType ); const QString actionText = typeValues.join(QLatin1Char(';')).append(";"); tConfig.writeEntry( "Actions", actionText ); - qWarning() << "Desktop file created: " + typeFile.fileName(); - foreach( const QString &tValue, typeValues ) { + for (const QString &tValue : typeValues) { KConfigGroup vConfig = typeFile.actionGroup( tValue ); if( !vConfig.hasKey("Name") ) { vConfig.writeEntry( "Name", availActions->propertyName( internalType, tValue ) ); } vConfig.sync(); } tConfig.sync(); typeFile.sync(); } - qWarning() << "Generation now completed"; return 0; } diff --git a/kcms/solid_actions/SolidActionData.cpp b/kcms/solid_actions/SolidActionData.cpp index d28b7e3e5..b50787fc2 100644 --- a/kcms/solid_actions/SolidActionData.cpp +++ b/kcms/solid_actions/SolidActionData.cpp @@ -1,176 +1,177 @@ /*************************************************************************** * Copyright (C) 2009 by Ben Cooksley * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * ***************************************************************************/ #include "SolidActionData.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static SolidActionData * actData = nullptr; SolidActionData::SolidActionData(bool includeFiles) { const int propertyOffset = Solid::DeviceInterface::staticMetaObject.propertyOffset(); - QList interfaceList = fillInterfaceList(); - foreach( const QMetaObject &interface, interfaceList ) { + const QList interfaceList = fillInterfaceList(); + for (const QMetaObject &interface : interfaceList) { QString ifaceName = interface.className(); ifaceName.remove(0, ifaceName.lastIndexOf(':') + 1); Solid::DeviceInterface::Type ifaceDev = Solid::DeviceInterface::stringToType( ifaceName ); const QString cleanName = Solid::DeviceInterface::typeDescription( ifaceDev ); types.insert( ifaceDev, cleanName ); QMap deviceValues; for( int doneProps = propertyOffset; interface.propertyCount() > doneProps; doneProps = doneProps + 1 ) { QMetaProperty ifaceProp = interface.property(doneProps); deviceValues.insert( ifaceProp.name(), generateUserString(ifaceProp.name()) ); } values.insert( ifaceDev, deviceValues ); } if( includeFiles ) { // Fill the lists of possible device types / device values const QString deviceDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("/solid/devices/"), QStandardPaths::LocateDirectory); // List all the known device actions, then add their name and all values to the appropriate lists QDirIterator it(deviceDir, QStringList() << QStringLiteral("*.desktop")); while (it.hasNext()) { it.next(); const QString desktop = it.filePath(); KDesktopFile deviceFile(desktop); KConfigGroup deviceType = deviceFile.desktopGroup(); // Retrieve the configuration group where the user friendly name is const QString ifaceName = deviceType.readEntry("X-KDE-Solid-Actions-Type"); Solid::DeviceInterface::Type ifaceDev = Solid::DeviceInterface::stringToType( ifaceName ); const QString cleanName = Solid::DeviceInterface::typeDescription( ifaceDev ); types.insert( ifaceDev, cleanName ); // Read the user friendly name QMap deviceValues = values.value( ifaceDev ); - foreach( const QString &text, deviceFile.readActions() ) { // We want every single action + const auto actions = deviceFile.readActions(); + for (const QString &text : actions) { // We want every single action KConfigGroup actionType = deviceFile.actionGroup( text ); deviceValues.insert( text, actionType.readEntry("Name") ); // Add to the type - actions map } values.insert( ifaceDev, deviceValues ); } } } QList SolidActionData::propertyList( Solid::DeviceInterface::Type devInterface ) { return values.value( devInterface ).values(); } QList SolidActionData::propertyInternalList( Solid::DeviceInterface::Type devInterface ) { return values.value( devInterface ).keys(); } QString SolidActionData::propertyInternal( Solid::DeviceInterface::Type devInterface, QString property ) { return values.value( devInterface ).key( property ); } QString SolidActionData::propertyName( Solid::DeviceInterface::Type devInterface, QString property ) { return values.value( devInterface ).value( property ); } int SolidActionData::propertyPosition( Solid::DeviceInterface::Type devInterface, QString property ) { return values.value( devInterface ).keys().indexOf( property ); } QList SolidActionData::interfaceList() { return types.values(); } QList SolidActionData::interfaceTypeList() { return types.keys(); } Solid::DeviceInterface::Type SolidActionData::interfaceFromName( const QString& name ) { return types.key( name ); } QString SolidActionData::nameFromInterface( Solid::DeviceInterface::Type devInterface ) { return types.value( devInterface ); } int SolidActionData::interfacePosition( Solid::DeviceInterface::Type devInterface ) { return types.keys().indexOf( devInterface ); } QString SolidActionData::generateUserString( QString className ) { QString finalString; QRegExp camelCase(QStringLiteral("([A-Z])")); // Create the split regexp finalString = className.remove(0, className.lastIndexOf(':') + 1); // Remove any Class information finalString.replace( camelCase, QStringLiteral(" \\1") ); // Use Camel Casing to add spaces finalString = KStringHandler::capwords( finalString ); // Capitalize everything return finalString.trimmed(); } SolidActionData * SolidActionData::instance() { if( actData == nullptr ) { actData = new SolidActionData( true ); } return actData; } QList SolidActionData::fillInterfaceList() { QList interfaces; interfaces.append( Solid::Battery::staticMetaObject ); interfaces.append( Solid::Block::staticMetaObject ); interfaces.append( Solid::Camera::staticMetaObject ); interfaces.append( Solid::PortableMediaPlayer::staticMetaObject ); interfaces.append( Solid::Processor::staticMetaObject ); interfaces.append( Solid::StorageAccess::staticMetaObject ); interfaces.append( Solid::StorageDrive::staticMetaObject ); interfaces.append( Solid::OpticalDrive::staticMetaObject ); interfaces.append( Solid::StorageVolume::staticMetaObject ); interfaces.append( Solid::OpticalDisc::staticMetaObject ); return interfaces; } diff --git a/kcms/solid_actions/SolidActions.cpp b/kcms/solid_actions/SolidActions.cpp index e9bbf34d5..cb2e6aa46 100644 --- a/kcms/solid_actions/SolidActions.cpp +++ b/kcms/solid_actions/SolidActions.cpp @@ -1,238 +1,238 @@ /*************************************************************************** * Copyright (C) 2009 by Ben Cooksley * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * ***************************************************************************/ #include "SolidActions.h" #include "ActionItem.h" #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY( SolidActionsFactory, registerPlugin(); ) SolidActions::SolidActions(QWidget* parent, const QVariantList&) : KCModule(parent) { KAboutData * about = new KAboutData(QStringLiteral("Device Actions"), i18n("Solid Device Actions Editor"), QStringLiteral("1.2"), i18n("Solid Device Actions Control Panel Module"), KAboutLicense::GPL, i18n("(c) 2009, 2014 Solid Device Actions team")); about->addAuthor(i18n("Ben Cooksley"), i18n("Maintainer"), QStringLiteral("ben@eclipse.endoftheinternet.org")); about->addCredit(QStringLiteral("Lukáš Tinkl"), i18n("Port to Plasma 5"), QStringLiteral("ltinkl@redhat.com")); setAboutData(about); setButtons(KCModule::Help); // Prepare main display dialog actionModel = new ActionModel( this ); mainUi.setupUi( this ); mainUi.TvActions->setModel( actionModel ); mainUi.TvActions->setHeaderHidden( true ); mainUi.TvActions->setRootIsDecorated( false ); mainUi.TvActions->setSelectionMode( QAbstractItemView::SingleSelection ); KStandardGuiItem::assign(mainUi.PbAddAction, KStandardGuiItem::Add); mainUi.PbEditAction->setIcon( QIcon::fromTheme(QStringLiteral("document-edit")) ); connect(mainUi.PbAddAction, &QPushButton::clicked, this, &SolidActions::slotShowAddDialog); connect(mainUi.PbEditAction, &QPushButton::clicked, this, &SolidActions::editAction); connect(mainUi.PbDeleteAction, &QPushButton::clicked, this, &SolidActions::deleteAction); connect( mainUi.TvActions->selectionModel(), &QItemSelectionModel::currentChanged, this, &SolidActions::toggleEditDelete ); connect(mainUi.TvActions, &QTreeView::doubleClicked, this, &SolidActions::editAction); // Prepare + connect up with Edit dialog editUi = new ActionEditor(this); connect(editUi, &ActionEditor::accepted, this, &SolidActions::acceptActionChanges); // Prepare + connect up add action dialog addDialog = new QDialog(this); addUi.setupUi( addDialog ); addDialog->resize(QSize(300, 100)); // Set a sensible default size slotTextChanged( addUi.LeActionName->text() ); connect(addUi.LeActionName, &QLineEdit::textChanged, this, &SolidActions::slotTextChanged); connect(addUi.buttonBox, &QDialogButtonBox::accepted, this, &SolidActions::addAction); connect(addUi.buttonBox, &QDialogButtonBox::rejected, addDialog, &QDialog::reject); } SolidActions::~SolidActions() { delete editUi; delete actionModel; } void SolidActions::slotShowAddDialog() { addDialog->show(); addUi.LeActionName->setFocus(); addUi.LeActionName->clear(); } void SolidActions::slotTextChanged( const QString & text ) { addUi.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); } void SolidActions::load() { fillActionsList(); } void SolidActions::defaults() { } void SolidActions::save() { } void SolidActions::addAction() { const QString enteredName = addUi.LeActionName->text(); KDesktopFile templateDesktop(QStandardPaths::GenericDataLocation, QStringLiteral("kcmsolidactions/solid-action-template.desktop")); // Lets get the template // Lets get a desktop file QString internalName = enteredName; // copy the name the user entered -> we will be making mods internalName.replace(QChar(' '), QChar('-'), Qt::CaseSensitive); // replace spaces with dashes internalName = KIO::encodeFileName(internalName); QString filePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/solid/actions/"; // Get the location on disk for "data" if (!QDir().exists(filePath)) { QDir().mkpath(filePath); } filePath += internalName + ".desktop"; // Fill in an initial template KDesktopFile * newDesktop = templateDesktop.copyTo(filePath); newDesktop->actionGroup(QStringLiteral("open")).writeEntry("Name", enteredName); // ditto delete newDesktop; // Force file to be written // Prepare to open the editDialog fillActionsList(); - QList actionList = actionModel->actionList(); + const QList actionList = actionModel->actionList(); QModelIndex newAction; - foreach( ActionItem * newItem, actionList ) { // Lets find our new action + for (ActionItem *newItem : actionList) { // Lets find our new action if( newItem->desktopMasterPath == filePath ) { const int position = actionList.indexOf( newItem ); newAction = actionModel->index( position, 0 ); // Grab it break; } } mainUi.TvActions->setCurrentIndex( newAction ); // Set it as currently active addDialog->hide(); editAction(); // Open the edit dialog } void SolidActions::editAction() { ActionItem * selectedItem = selectedAction(); if( !selectedItem ) { return; } // We should error out here if we have to if( !selectedItem->predicate().isValid() ) { KMessageBox::error(this, i18n("It appears that the predicate for this action is not valid."), i18n("Error Parsing Device Conditions")); return; } // Display us! editUi->setActionToEdit( selectedItem ); editUi->setWindowIcon( windowIcon() ); editUi->show(); } void SolidActions::deleteAction() { ActionItem * action = selectedAction(); if( action->isUserSupplied() ) { // Is the action user supplied? QFile::remove(action->desktopMasterPath); // Remove the main desktop file then } QFile::remove(action->desktopWritePath); // Remove the modified desktop file now fillActionsList(); // Update the list of actions } ActionItem * SolidActions::selectedAction() const { QModelIndex action = mainUi.TvActions->currentIndex(); ActionItem * actionItem = actionModel->data( action, Qt::UserRole ).value(); return actionItem; } void SolidActions::fillActionsList() { mainUi.TvActions->clearSelection(); actionModel->buildActionList(); mainUi.TvActions->header()->setSectionResizeMode( 0, QHeaderView::Stretch ); mainUi.TvActions->header()->setSectionResizeMode( 1, QHeaderView::ResizeToContents ); toggleEditDelete(); } void SolidActions::acceptActionChanges() { // Re-read the actions list to ensure changes are reflected KBuildSycocaProgressDialog::rebuildKSycoca(this); fillActionsList(); } void SolidActions::toggleEditDelete() { bool toggle = true; if( !mainUi.TvActions->currentIndex().isValid() ) { // Is an action selected? mainUi.PbDeleteAction->setText( i18n("No Action Selected") ); // Set a friendly disabled text mainUi.PbDeleteAction->setIcon( QIcon() ); toggle = false; } mainUi.PbEditAction->setEnabled(toggle); // Change them to the new state mainUi.PbDeleteAction->setEnabled(toggle); // Ditto if( !toggle ) { return; } // What functionality do we need to change? if( selectedAction()->isUserSupplied() ) { // We are able to directly delete it, enable full delete functionality KStandardGuiItem::assign(mainUi.PbDeleteAction, KStandardGuiItem::Remove); } else if( QFile::exists(selectedAction()->desktopWritePath) ) { // Does the write file exist? // We are able to revert, lets show it KStandardGuiItem::assign(mainUi.PbDeleteAction, KStandardGuiItem::Discard); } else { // We cannot do anything then, disable delete functionality mainUi.PbDeleteAction->setText( i18n("Cannot be deleted") ); mainUi.PbDeleteAction->setIcon( QIcon() ); mainUi.PbDeleteAction->setEnabled( false ); } } #include "SolidActions.moc"