diff --git a/kcms/autostart/AUTHORS b/kcms/autostart/AUTHORS --- a/kcms/autostart/AUTHORS +++ b/kcms/autostart/AUTHORS @@ -1,2 +1,3 @@ Stephen Leaf Montel Laurent +Alexander Lohnau diff --git a/kcms/autostart/addscriptdialog.h b/kcms/autostart/addscriptdialog.h --- a/kcms/autostart/addscriptdialog.h +++ b/kcms/autostart/addscriptdialog.h @@ -29,12 +29,12 @@ class KUrlRequester; class QCheckBox; -class AddScriptDialog : public QDialog +class AddScriptDialog: public QDialog { - Q_OBJECT +Q_OBJECT public: - explicit AddScriptDialog(QWidget* parent=nullptr); + explicit AddScriptDialog(QWidget *parent = nullptr); ~AddScriptDialog() override; // Returns the Url of the script to be imported QUrl importUrl() const; @@ -52,9 +52,9 @@ private: KUrlRequester *m_url; - QCheckBox* m_symlink; + QCheckBox *m_symlink; - QDialogButtonBox* m_buttons; + QDialogButtonBox *m_buttons; }; #endif diff --git a/kcms/autostart/addscriptdialog.cpp b/kcms/autostart/addscriptdialog.cpp --- a/kcms/autostart/addscriptdialog.cpp +++ b/kcms/autostart/addscriptdialog.cpp @@ -32,22 +32,21 @@ #include #include -AddScriptDialog::AddScriptDialog (QWidget* parent) - : QDialog( parent ) +AddScriptDialog::AddScriptDialog(QWidget *parent) + : QDialog(parent) { - QVBoxLayout *lay= new QVBoxLayout; - setLayout( lay ); - QLabel *lab = new QLabel( i18n( "Shell script path:" ), this ); - lay->addWidget( lab ); - m_url = new KUrlRequester( this ); - lay->addWidget( m_url ); - m_symlink = new QCheckBox( i18n( "Create as symlink" ), this ); //TODO fix text - m_symlink->setChecked( true ); - lay->addWidget( m_symlink ); - connect( m_url->lineEdit(), &QLineEdit::textChanged, this, &AddScriptDialog::textChanged ); + QVBoxLayout *lay = new QVBoxLayout(this); + QLabel *lab = new QLabel(i18n("Shell script path:"), this); + lay->addWidget(lab); + m_url = new KUrlRequester(this); + lay->addWidget(m_url); + m_symlink = new QCheckBox(i18n("Create as symlink"), this); //TODO fix text + m_symlink->setChecked(true); + lay->addWidget(m_symlink); + connect(m_url->lineEdit(), &QLineEdit::textChanged, this, &AddScriptDialog::textChanged); m_url->lineEdit()->setFocus(); - m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this); + m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); m_buttons->button(QDialogButtonBox::Ok)->setEnabled(false); lay->addWidget(m_buttons); connect(m_buttons, &QDialogButtonBox::accepted, this, &AddScriptDialog::accept); @@ -65,27 +64,27 @@ void AddScriptDialog::accept() { - if ( doBasicSanityCheck() ) + if (doBasicSanityCheck()) { QDialog::accept(); + } } bool AddScriptDialog::doBasicSanityCheck() { - const QString& path = KShell::tildeExpand(m_url->text()); - - QFileInfo file(path); + const QString &path = KShell::tildeExpand(m_url->text()); + const QFileInfo file(path); - if ( ! file.isAbsolute() ) { - KMessageBox::sorry( nullptr, i18n("\"%1\" is not an absolute path.", path) ); + if (!file.isAbsolute()) { + KMessageBox::sorry(nullptr, i18n("\"%1\" is not an absolute path.", path)); return false; - } else if ( ! file.exists() ) { - KMessageBox::sorry( nullptr, i18n("\"%1\" does not exist.", path) ); + } else if (!file.exists()) { + KMessageBox::sorry(nullptr, i18n("\"%1\" does not exist.", path)); return false; - } else if ( !file.isFile() ) { - KMessageBox::sorry( nullptr, i18n("\"%1\" is not a file.", path) ); + } else if (!file.isFile()) { + KMessageBox::sorry(nullptr, i18n("\"%1\" is not a file.", path)); return false; - } else if ( ! file.isReadable() ) { - KMessageBox::sorry( nullptr, i18n("\"%1\" is not readable.", path) ); + } else if (!file.isReadable()) { + KMessageBox::sorry(nullptr, i18n("\"%1\" is not readable.", path)); return false; } diff --git a/kcms/autostart/advanceddialog.h b/kcms/autostart/advanceddialog.h --- a/kcms/autostart/advanceddialog.h +++ b/kcms/autostart/advanceddialog.h @@ -23,12 +23,12 @@ #include class QCheckBox; -class AdvancedDialog : public QDialog +class AdvancedDialog: public QDialog { Q_OBJECT public: - explicit AdvancedDialog(QWidget* parent, bool status); + explicit AdvancedDialog(QWidget *parent, bool status); ~AdvancedDialog() override; bool onlyInKde() const; diff --git a/kcms/autostart/advanceddialog.cpp b/kcms/autostart/advanceddialog.cpp --- a/kcms/autostart/advanceddialog.cpp +++ b/kcms/autostart/advanceddialog.cpp @@ -25,18 +25,17 @@ #include -AdvancedDialog::AdvancedDialog( QWidget *parent, bool status ) - : QDialog( parent ) +AdvancedDialog::AdvancedDialog(QWidget *parent, bool status) + : QDialog(parent) { - QVBoxLayout *lay= new QVBoxLayout(this); - m_onlyInKde = new QCheckBox( i18n( "Autostart only in Plasma" ), this ); - m_onlyInKde->setChecked( status ); - lay->addWidget( m_onlyInKde ); + QVBoxLayout *lay = new QVBoxLayout(this); + m_onlyInKde = new QCheckBox(i18n("Autostart only in Plasma"), this); + m_onlyInKde->setChecked(status); + lay->addWidget(m_onlyInKde); - QDialogButtonBox* buttons = new QDialogButtonBox(this); - buttons->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + QDialogButtonBox *buttons = new QDialogButtonBox(this); + buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); lay->addWidget(buttons); - setLayout( lay ); connect(buttons, &QDialogButtonBox::accepted, this, &AdvancedDialog::accept); connect(buttons, &QDialogButtonBox::rejected, this, &AdvancedDialog::reject); diff --git a/kcms/autostart/autostart.h b/kcms/autostart/autostart.h --- a/kcms/autostart/autostart.h +++ b/kcms/autostart/autostart.h @@ -37,31 +37,32 @@ Q_OBJECT public: - explicit Autostart( QWidget* parent, const QVariantList& ); + explicit Autostart(QWidget *parent, const QVariantList &); ~Autostart() override; enum COL_TYPE { COL_NAME = 0, COL_COMMAND=1, COL_STATUS=2,COL_RUN=3 }; void load() override; void save() override; void defaults() override; - QStringList listPathName() const { return m_pathName;} + QStringList listPathName() const { return m_pathName; } public Q_SLOTS: - void slotChangeStartup( ScriptStartItem* item, int index ); + void slotChangeStartup(ScriptStartItem *item, int index); protected: - void addItem(DesktopStartItem *item, const QString& name, const QString& run, const QString& command, bool disabled ); - void addItem(ScriptStartItem *item, const QString& name, const QString& command, ScriptStartItem::ENV type ); + void + addItem(DesktopStartItem *item, const QString &name, const QString &run, const QString &command, bool disabled); + void addItem(ScriptStartItem *item, const QString &name, const QString &command, ScriptStartItem::ENV type); private Q_SLOTS: void slotAddProgram(); void slotAddScript(); void slotRemoveCMD(); - void slotEditCMD(QTreeWidgetItem*); - bool slotEditCMD(const KFileItem&); + void slotEditCMD(QTreeWidgetItem *); + bool slotEditCMD(const KFileItem &); void slotEditCMD(); void slotSelectionChanged(); - void slotItemClicked( QTreeWidgetItem *, int); + void slotItemClicked(QTreeWidgetItem *, int); void slotAdvanced(); private: diff --git a/kcms/autostart/autostart.cpp b/kcms/autostart/autostart.cpp --- a/kcms/autostart/autostart.cpp +++ b/kcms/autostart/autostart.cpp @@ -43,24 +43,27 @@ K_PLUGIN_FACTORY(AutostartFactory, registerPlugin();) -Autostart::Autostart( QWidget* parent, const QVariantList& ) - : KCModule(parent ) +Autostart::Autostart(QWidget *parent, const QVariantList &) + : KCModule(parent) { widget = new Ui_AutostartConfig(); widget->setupUi(this); QStringList lstHeader; - lstHeader << i18n( "Name" ) - << i18n( "Command" ) - << i18n( "Status" ) - << i18nc("@title:column The name of the column that decides if the program is run on session startup, on session shutdown, etc", "Run On" ); + lstHeader << i18n("Name") + << i18n("Command") + << i18n("Status") + << i18nc( + "@title:column The name of the column that decides if the program is run on session startup, on session shutdown, etc", + "Run On"); widget->listCMD->setHeaderLabels(lstHeader); widget->listCMD->setFocus(); setButtons(Help); - - connect( widget->btnProperties, SIGNAL(clicked()), SLOT(slotEditCMD()) ); - connect( widget->listCMD, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(slotEditCMD(QTreeWidgetItem*)) ); + connect(widget->btnProperties, &QPushButton::clicked, + this, static_cast(&Autostart::slotEditCMD)); + connect(widget->listCMD, &QTreeWidget::itemDoubleClicked, + this, static_cast(&Autostart::slotEditCMD)); connect(widget->btnAddScript, &QPushButton::clicked, this, &Autostart::slotAddScript); @@ -71,66 +74,71 @@ connect(widget->listCMD, &QTreeWidget::itemSelectionChanged, this, &Autostart::slotSelectionChanged); - KAboutData* about = new KAboutData(QStringLiteral("Autostart"), + KAboutData *about = new KAboutData(QStringLiteral("Autostart"), i18n("Session Autostart Manager"), QStringLiteral("1.0"), i18n("Session Autostart Manager Control Panel Module"), KAboutLicense::GPL, i18n("Copyright © 2006–2010 Autostart Manager team")); about->addAuthor(i18n("Stephen Leaf"), QString(), QStringLiteral("smileaf@gmail.com")); - about->addAuthor(i18n("Montel Laurent"), i18n( "Maintainer" ), QStringLiteral("montel@kde.org")); - setAboutData( about ); + about->addAuthor(i18n("Montel Laurent"), i18n("Maintainer"), QStringLiteral("montel@kde.org")); + about->addAuthor(i18n("Alexander Lohnau"), QString(), QStringLiteral("alexander.lohnau@gmx.de")); + setAboutData(about); } Autostart::~Autostart() { - delete widget; + delete widget; } - -void Autostart::slotItemClicked( QTreeWidgetItem *item, int col) +void Autostart::slotItemClicked(QTreeWidgetItem *item, int col) { - if ( item && col == COL_STATUS ) { - DesktopStartItem *entry = dynamic_cast( item ); - if ( entry ) { - bool disable = ( item->checkState( col ) == Qt::Unchecked ); + if (item && col == COL_STATUS) { + DesktopStartItem *entry = dynamic_cast(item); + if (entry) { + bool disable = (item->checkState(col) == Qt::Unchecked); KDesktopFile kc(entry->fileName().path()); KConfigGroup grp = kc.desktopGroup(); - if ( grp.hasKey( "Hidden" ) && !disable) { - grp.deleteEntry( "Hidden" ); - } - else + if (grp.hasKey("Hidden") && !disable) { + grp.deleteEntry("Hidden"); + } else { grp.writeEntry("Hidden", disable); + } kc.sync(); - if ( disable ) - item->setText( COL_STATUS, i18nc( "The program won't be run", "Disabled" ) ); - else - item->setText( COL_STATUS, i18nc( "The program will be run", "Enabled" ) ); + if (disable) { + item->setText(COL_STATUS, i18nc("The program won't be run", "Disabled")); + } else { + item->setText(COL_STATUS, i18nc("The program will be run", "Enabled")); + } } } } -void Autostart::addItem( DesktopStartItem* item, const QString& name, const QString& run, const QString& command, bool disabled ) +void Autostart::addItem(DesktopStartItem *item, + const QString &name, + const QString &run, + const QString &command, + bool disabled) { - Q_ASSERT( item ); - item->setText( COL_NAME, name ); - item->setText( COL_RUN, run ); - item->setText( COL_COMMAND, command ); - item->setCheckState( COL_STATUS, disabled ? Qt::Unchecked : Qt::Checked ); - item->setText( COL_STATUS, disabled ? i18nc( "The program won't be run", "Disabled" ) : i18nc( "The program will be run", "Enabled" )); + Q_ASSERT(item); + item->setText(COL_NAME, name); + item->setText(COL_RUN, run); + item->setText(COL_COMMAND, command); + item->setCheckState(COL_STATUS, disabled ? Qt::Unchecked : Qt::Checked); + item->setText(COL_STATUS, disabled ? i18nc("The program won't be run", "Disabled") : + i18nc("The program will be run", "Enabled")); } -void Autostart::addItem(ScriptStartItem* item, const QString& name, const QString& command, ScriptStartItem::ENV type ) +void Autostart::addItem(ScriptStartItem *item, const QString &name, const QString &command, ScriptStartItem::ENV type) { - Q_ASSERT( item ); - item->setText( COL_NAME, name ); - item->setText( COL_COMMAND, command ); - item->changeStartup( type ); + Q_ASSERT(item); + item->setText(COL_NAME, name); + item->setText(COL_COMMAND, command); + item->changeStartup(type); } - void Autostart::load() { // FDO user autostart directories are @@ -146,119 +154,118 @@ //the comment above describes how autostart *currently* works, it is not definitive documentation on how autostart *should* work - m_desktopPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/autostart/"); + m_desktopPath = + QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/autostart/"); - m_paths << QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/autostart-scripts/") - << QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/plasma-workspace/shutdown/") - << QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/plasma-workspace/env/"); + m_paths << QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + + QStringLiteral("/autostart-scripts/") + << QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + + QStringLiteral("/plasma-workspace/shutdown/") + << QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + + QStringLiteral("/plasma-workspace/env/"); // share/autostart shouldn't be an option as this should be reserved for global autostart entries m_pathName << i18n("Startup") - << i18n("Logout") - << i18n("Before session startup") - ; + << i18n("Logout") + << i18n("Before session startup"); widget->listCMD->clear(); - m_programItem = new QTreeWidgetItem( widget->listCMD ); - m_programItem->setText( 0, i18n( "Desktop File" )); - m_programItem->setFlags(m_programItem->flags()^Qt::ItemIsSelectable ); + m_programItem = new QTreeWidgetItem(widget->listCMD); + m_programItem->setText(0, i18n("Desktop File")); + m_programItem->setFlags(m_programItem->flags() ^ Qt::ItemIsSelectable); - QFont boldFont = m_programItem->font(0); - boldFont.setBold( true ); - m_programItem->setData ( 0, Qt::FontRole, boldFont ); + QFont boldFont = m_programItem->font(0); + boldFont.setBold(true); + m_programItem->setData(0, Qt::FontRole, boldFont); - m_scriptItem = new QTreeWidgetItem( widget->listCMD ); - m_scriptItem->setText( 0, i18n( "Script File" )); - m_scriptItem->setFlags(m_scriptItem->flags()^Qt::ItemIsSelectable); - m_scriptItem->setData ( 0, Qt::FontRole, boldFont); + m_scriptItem = new QTreeWidgetItem(widget->listCMD); + m_scriptItem->setText(0, i18n("Script File")); + m_scriptItem->setFlags(m_scriptItem->flags() ^ Qt::ItemIsSelectable); + m_scriptItem->setData(0, Qt::FontRole, boldFont); - widget->listCMD->expandItem( m_programItem ); - widget->listCMD->expandItem( m_scriptItem ); + widget->listCMD->expandItem(m_programItem); + widget->listCMD->expandItem(m_scriptItem); //add programs { QDir d(m_desktopPath); - if (!d.exists()) + if (!d.exists()) { d.mkpath(m_desktopPath); - QDir autostartdir( m_desktopPath ); - autostartdir.setFilter( QDir::Files ); - const QFileInfoList list = autostartdir.entryInfoList(); - - for (int i = 0; i < list.size(); ++i) { - QFileInfo fi = list.at(i); - QString filename = fi.fileName(); - bool desktopFile = filename.endsWith(QLatin1String(".desktop")); - if ( desktopFile ) { + } + QDir autostartdir(m_desktopPath); + autostartdir.setFilter(QDir::Files); + const QFileInfoList entries = autostartdir.entryInfoList(); + + for (const QFileInfo &fi : entries) { + const QString filename = fi.fileName(); + const bool desktopFile = filename.endsWith(QLatin1String(".desktop")); + if (desktopFile) { KDesktopFile config(fi.absoluteFilePath()); //kDebug() << fi.absoluteFilePath() << "trying" << config.desktopGroup().readEntry("Exec"); - QStringList commandLine = KShell::splitArgs(config.desktopGroup().readEntry("Exec")); + const QStringList commandLine = KShell::splitArgs(config.desktopGroup().readEntry("Exec")); if (commandLine.isEmpty()) { continue; } - const QString exe = commandLine.first(); + const QString &exe = commandLine.first(); if (exe.isEmpty() || QStandardPaths::findExecutable(exe).isEmpty()) { continue; } - DesktopStartItem *item = new DesktopStartItem( fi.absoluteFilePath(), m_programItem, this ); + DesktopStartItem *item = new DesktopStartItem(fi.absoluteFilePath(), m_programItem, this); const KConfigGroup grp = config.desktopGroup(); const bool hidden = grp.readEntry("Hidden", false); const QStringList notShowList = grp.readXdgListEntry("NotShowIn"); const QStringList onlyShowList = grp.readXdgListEntry("OnlyShowIn"); - const bool disabled = hidden || - notShowList.contains(QLatin1String("KDE")) || - (!onlyShowList.isEmpty() && !onlyShowList.contains(QLatin1String("KDE"))); + const bool disabled = hidden + || notShowList.contains(QLatin1String("KDE")) + || (!onlyShowList.isEmpty() && !onlyShowList.contains(QLatin1String("KDE"))); - int indexPath = m_paths.indexOf((item->fileName().adjusted(QUrl::RemoveFilename).toString() ) ); - if ( indexPath > 2 ) + int indexPath = m_paths.indexOf((item->fileName().adjusted(QUrl::RemoveFilename).toString())); + if (indexPath > 2) { indexPath = 0; //.kde/share/autostart and .config/autostart load desktop at startup - addItem(item, config.readName(), m_pathName.value(indexPath), grp.readEntry("Exec"), disabled ); + } + addItem(item, config.readName(), m_pathName.value(indexPath), grp.readEntry("Exec"), disabled); } } } //add scripts - - for (const QString& path : qAsConst(m_paths)) { + for (const QString &path : qAsConst(m_paths)) { QDir d(path); - if (!d.exists()) + if (!d.exists()) { d.mkpath(path); + } - QDir autostartdir( path ); - autostartdir.setFilter( QDir::Files ); - const QFileInfoList list = autostartdir.entryInfoList(); - - for (int i = 0; i < list.size(); ++i) { - QFileInfo fi = list.at(i); + QDir autostartdir(path); + autostartdir.setFilter(QDir::Files); + const QFileInfoList entries = autostartdir.entryInfoList(); - ScriptStartItem *item = new ScriptStartItem( fi.absoluteFilePath(), m_scriptItem,this ); - int typeOfStartup = m_paths.indexOf((item->fileName().adjusted(QUrl::RemoveScheme | QUrl::RemoveFilename).toString()) ); + for (const QFileInfo &fi : entries) { + ScriptStartItem *item = new ScriptStartItem(fi.absoluteFilePath(), m_scriptItem, this); + int typeOfStartup = + m_paths.indexOf((item->fileName().adjusted(QUrl::RemoveScheme | QUrl::RemoveFilename).toString())); ScriptStartItem::ENV type = ScriptStartItem::START; - switch( typeOfStartup ) - { + switch (typeOfStartup) { case 0: - type =ScriptStartItem::START; + type = ScriptStartItem::START; break; case 1: type = ScriptStartItem::SHUTDOWN; break; case 2: type = ScriptStartItem::PRE_START; break; default: - qDebug()<<" type is not defined :"<desktopEntryName().isEmpty() || service->entryPath().isEmpty()) { + if (service->desktopEntryName().isEmpty() || service->entryPath().isEmpty()) { // Build custom desktop file (e.g. when the user entered an executable // name in the OpenWithDialog). desktopPath = m_desktopPath + service->name() + QStringLiteral(".desktop"); - desktopTemplate = QUrl::fromLocalFile( desktopPath ); + desktopTemplate = QUrl::fromLocalFile(desktopPath); KConfig kc(desktopTemplate.path(), KConfig::SimpleConfig); KConfigGroup kcg = kc.group("Desktop Entry"); - kcg.writeEntry("Exec",service->exec()); - kcg.writeEntry("Icon","system-run"); - kcg.writeEntry("Path",""); - kcg.writeEntry("Terminal",false); - kcg.writeEntry("Type","Application"); + kcg.writeEntry("Exec", service->exec()); + kcg.writeEntry("Icon", "system-run"); + kcg.writeEntry("Path", ""); + kcg.writeEntry("Terminal", false); + kcg.writeEntry("Type", "Application"); kc.sync(); - KPropertiesDialog dlg( desktopTemplate, this ); - if ( dlg.exec() != QDialog::Accepted ) - { + KPropertiesDialog dlg(desktopTemplate, this); + if (dlg.exec() != QDialog::Accepted) { return; } - } - else - { + } else { // Use existing desktop file and use same file name to enable overrides. desktopPath = m_desktopPath + service->desktopEntryName() + QStringLiteral(".desktop"); - desktopTemplate = QUrl::fromLocalFile( QStandardPaths::locate(QStandardPaths::ApplicationsLocation, service->entryPath()) ); - - KPropertiesDialog dlg( QUrl::fromLocalFile(service->entryPath()), QUrl::fromLocalFile(m_desktopPath), service->desktopEntryName() + QStringLiteral(".desktop"), this ); - if ( dlg.exec() != QDialog::Accepted ) + desktopTemplate = + QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::ApplicationsLocation, service->entryPath())); + + KPropertiesDialog dlg(QUrl::fromLocalFile(service->entryPath()), + QUrl::fromLocalFile(m_desktopPath), + service->desktopEntryName() + QStringLiteral(".desktop"), + this); + if (dlg.exec() != QDialog::Accepted) { return; + } } KDesktopFile newConf(desktopTemplate.path()); - DesktopStartItem * item = new DesktopStartItem( desktopPath, m_programItem,this ); - addItem( item, service->name(), m_pathName[0], newConf.desktopGroup().readEntry("Exec") , false); + DesktopStartItem *item = new DesktopStartItem(desktopPath, m_programItem, this); + addItem(item, service->name(), m_pathName[0], newConf.desktopGroup().readEntry("Exec"), false); } void Autostart::slotAddScript() { - AddScriptDialog * addDialog = new AddScriptDialog(this); + AddScriptDialog *addDialog = new AddScriptDialog(this); int result = addDialog->exec(); if (result == QDialog::Accepted) { - if (addDialog->symLink()) + if (addDialog->symLink()) { KIO::link(addDialog->importUrl(), QUrl::fromLocalFile(m_paths[0])); - else + } else { KIO::copy(addDialog->importUrl(), QUrl::fromLocalFile(m_paths[0])); + } - ScriptStartItem * item = new ScriptStartItem( m_paths[0] + addDialog->importUrl().fileName(), m_scriptItem,this ); - addItem( item, addDialog->importUrl().fileName(), addDialog->importUrl().fileName(),ScriptStartItem::START ); + ScriptStartItem *item = new ScriptStartItem(m_paths[0] + addDialog->importUrl().fileName(), m_scriptItem, this); + addItem(item, addDialog->importUrl().fileName(), addDialog->importUrl().fileName(), ScriptStartItem::START); } delete addDialog; } void Autostart::slotRemoveCMD() { - QTreeWidgetItem* item = widget->listCMD->currentItem(); - if (!item) + QTreeWidgetItem *item = widget->listCMD->currentItem(); + if (!item) { return; - DesktopStartItem *startItem = dynamic_cast( item ); - if ( startItem ) - { + } + DesktopStartItem *startItem = dynamic_cast(item); + if (startItem) { QUrl path(startItem->fileName()); path.setScheme(QStringLiteral("file")); - m_programItem->takeChild( m_programItem->indexOfChild( startItem ) ); + m_programItem->takeChild(m_programItem->indexOfChild(startItem)); KIO::del(path); delete item; - } - else - { - ScriptStartItem * scriptItem = dynamic_cast( item ); - if ( scriptItem ) - { + } else { + ScriptStartItem *scriptItem = dynamic_cast(item); + if (scriptItem) { QUrl path(scriptItem->fileName()); path.setScheme(QStringLiteral("file")); - m_scriptItem->takeChild( m_scriptItem->indexOfChild( scriptItem ) ); + m_scriptItem->takeChild(m_scriptItem->indexOfChild(scriptItem)); KIO::del(path); delete item; } } } -void Autostart::slotEditCMD(QTreeWidgetItem* ent) +void Autostart::slotEditCMD(QTreeWidgetItem *ent) { - - if (!ent) return; - DesktopStartItem *desktopEntry = dynamic_cast( ent ); - if ( desktopEntry ) - { + if (!ent) { + return; + } + DesktopStartItem *desktopEntry = dynamic_cast(ent); + if (desktopEntry) { KFileItem kfi = KFileItem(QUrl(desktopEntry->fileName())); kfi.setDelayedMimeTypes(true); - if (! slotEditCMD( kfi )) + if (!slotEditCMD(kfi)) { return; + } if (desktopEntry) { KService service(desktopEntry->fileName().path()); - addItem( desktopEntry, service.name(), m_pathName.value(m_paths.indexOf(desktopEntry->fileName().adjusted(QUrl::RemoveFilename).toString())), service.exec(),false ); + addItem(desktopEntry, service.name(), + m_pathName + .value(m_paths.indexOf(desktopEntry->fileName().adjusted(QUrl::RemoveFilename).toString())), + service.exec(), false); } } } -bool Autostart::slotEditCMD( const KFileItem &item) +bool Autostart::slotEditCMD(const KFileItem &item) { - KPropertiesDialog dlg( item, this ); - bool c = ( dlg.exec() == QDialog::Accepted ); - return c; + KPropertiesDialog dlg(item, this); + return dlg.exec() == QDialog::Accepted; } void Autostart::slotEditCMD() { - if ( widget->listCMD->currentItem() == nullptr ) + if (!widget->listCMD->currentItem()) { return; - slotEditCMD( (AutoStartItem*)widget->listCMD->currentItem() ); + } + slotEditCMD((AutoStartItem *) widget->listCMD->currentItem()); } void Autostart::slotAdvanced() { - if ( widget->listCMD->currentItem() == nullptr ) + if (widget->listCMD->currentItem() == nullptr) { return; + } - DesktopStartItem *entry = static_cast( widget->listCMD->currentItem() ); + DesktopStartItem *entry = static_cast( widget->listCMD->currentItem()); KDesktopFile kc(entry->fileName().path()); KConfigGroup grp = kc.desktopGroup(); bool status = false; QStringList lstEntry; - if (grp.hasKey("OnlyShowIn")) - { + if (grp.hasKey("OnlyShowIn")) { lstEntry = grp.readXdgListEntry("OnlyShowIn"); status = lstEntry.contains(QLatin1String("KDE")); } - AdvancedDialog *dlg = new AdvancedDialog( this,status ); - if ( dlg->exec() ) - { + AdvancedDialog *dlg = new AdvancedDialog(this, status); + if (dlg->exec()) { status = dlg->onlyInKde(); - if ( lstEntry.contains(QLatin1String("KDE") ) && !status ) - { - lstEntry.removeAll( QStringLiteral("KDE") ); - grp.writeXdgListEntry( "OnlyShowIn", lstEntry ); - } - else if ( !lstEntry.contains(QLatin1String("KDE") ) && status ) - { - lstEntry.append( QStringLiteral("KDE") ); - grp.writeXdgListEntry( "OnlyShowIn", lstEntry ); + if (lstEntry.contains(QLatin1String("KDE")) && !status) { + lstEntry.removeAll(QStringLiteral("KDE")); + grp.writeXdgListEntry("OnlyShowIn", lstEntry); + } else if (!lstEntry.contains(QLatin1String("KDE")) && status) { + lstEntry.append(QStringLiteral("KDE")); + grp.writeXdgListEntry("OnlyShowIn", lstEntry); } } delete dlg; } -void Autostart::slotChangeStartup( ScriptStartItem* item, int index ) +void Autostart::slotChangeStartup(ScriptStartItem *item, int index) { Q_ASSERT(item); - if ( item ) - { + if (item) { item->setPath(m_paths.value(index)); - widget->listCMD->setCurrentItem( item ); - if ( ( index == 2 ) && !item->fileName().path().endsWith( QLatin1String(".sh") )) - KMessageBox::information( this, i18n( "Only files with “.sh” extensions are allowed for setting up the environment." ) ); + widget->listCMD->setCurrentItem(item); + if ((index == 2) && !item->fileName().path().endsWith(QLatin1String(".sh"))) { + KMessageBox::information(this, + i18n("Only files with “.sh” extensions are allowed for setting up the environment.")); + } } } void Autostart::slotSelectionChanged() { - const bool hasItems = ( dynamic_cast( widget->listCMD->currentItem() )!=nullptr ) ; + const bool hasItems = (dynamic_cast(widget->listCMD->currentItem()) != nullptr); widget->btnRemove->setEnabled(hasItems); - const bool isDesktopItem = (dynamic_cast(widget->listCMD->currentItem() ) != nullptr) ; + const bool isDesktopItem = (dynamic_cast(widget->listCMD->currentItem()) != nullptr); widget->btnProperties->setEnabled(isDesktopItem); - widget->btnAdvanced->setEnabled(isDesktopItem) ; + widget->btnAdvanced->setEnabled(isDesktopItem); } void Autostart::defaults() diff --git a/kcms/autostart/autostartitem.h b/kcms/autostart/autostartitem.h --- a/kcms/autostart/autostartitem.h +++ b/kcms/autostart/autostartitem.h @@ -28,10 +28,10 @@ class QTreeWidget; class Autostart; -class AutoStartItem : public QTreeWidgetItem, public QObject +class AutoStartItem: public QTreeWidgetItem, public QObject { public: - AutoStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* ); + AutoStartItem(const QString &service, QTreeWidgetItem *parent, Autostart *); ~AutoStartItem() override; QUrl fileName() const; @@ -42,27 +42,26 @@ QUrl m_fileName; }; -class DesktopStartItem : public AutoStartItem +class DesktopStartItem: public AutoStartItem { public: - DesktopStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* ); + DesktopStartItem(const QString &service, QTreeWidgetItem *parent, Autostart *); ~DesktopStartItem() override; }; - -class ScriptStartItem : public AutoStartItem +class ScriptStartItem: public AutoStartItem { Q_OBJECT public: - enum ENV { START=0, SHUTDOWN=1, PRE_START=2}; //rename - ScriptStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* ); + enum ENV { START=0, SHUTDOWN=1, PRE_START=2 }; //rename + ScriptStartItem(const QString &service, QTreeWidgetItem *parent, Autostart *); ~ScriptStartItem() override; - void changeStartup( ScriptStartItem::ENV type ); + void changeStartup(ScriptStartItem::ENV type); Q_SIGNALS: - void askChangeStartup(ScriptStartItem* item, int index); + void askChangeStartup(ScriptStartItem *item, int index); private Q_SLOTS: diff --git a/kcms/autostart/autostartitem.cpp b/kcms/autostart/autostartitem.cpp --- a/kcms/autostart/autostartitem.cpp +++ b/kcms/autostart/autostartitem.cpp @@ -29,9 +29,8 @@ #include #include -AutoStartItem::AutoStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* ) - : QTreeWidgetItem( parent ) - , m_fileName(QUrl::fromLocalFile(service)) +AutoStartItem::AutoStartItem(const QString &service, QTreeWidgetItem *parent, Autostart *) + : QTreeWidgetItem(parent), m_fileName(QUrl::fromLocalFile(service)) { } @@ -47,37 +46,39 @@ void AutoStartItem::setPath(const QString &path) { - Q_ASSERT( path.endsWith(QDir::separator()) ); + Q_ASSERT(path.endsWith(QDir::separator())); - if (QUrl(path) == m_fileName.adjusted(QUrl::RemoveFilename)) + if (QUrl(path) == m_fileName.adjusted(QUrl::RemoveFilename)) { return; + } - const QString& newFileName = path + m_fileName.fileName(); + const QString &newFileName = path + m_fileName.fileName(); KIO::move(m_fileName, QUrl::fromLocalFile(newFileName)); m_fileName = QUrl::fromLocalFile(newFileName); } -DesktopStartItem::DesktopStartItem( const QString &service, QTreeWidgetItem *parent, Autostart*autostart ) - : AutoStartItem( service, parent,autostart ) +DesktopStartItem::DesktopStartItem(const QString &service, QTreeWidgetItem *parent, Autostart *autostart) + : AutoStartItem(service, parent, autostart) { - setCheckState ( Autostart::COL_STATUS,Qt::Checked ); + setCheckState(Autostart::COL_STATUS, Qt::Checked); } DesktopStartItem::~DesktopStartItem() { } -ScriptStartItem::ScriptStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* autostart ) - : AutoStartItem( service, parent,autostart ) +ScriptStartItem::ScriptStartItem(const QString &service, QTreeWidgetItem *parent, Autostart *autostart) + : AutoStartItem(service, parent, autostart) { m_comboBoxStartup = new QComboBox; - m_comboBoxStartup->addItems( autostart->listPathName() ); + m_comboBoxStartup->addItems(autostart->listPathName()); - setText( 2, i18nc( "The program will be run", "Enabled" ) ); - QObject::connect(m_comboBoxStartup, static_cast(&QComboBox::activated), this, &ScriptStartItem::slotStartupChanged); - QObject::connect( this,&ScriptStartItem::askChangeStartup,autostart,&Autostart::slotChangeStartup ); - treeWidget()->setItemWidget ( this, Autostart::COL_RUN, m_comboBoxStartup ); + setText(2, i18nc("The program will be run", "Enabled")); + QObject::connect(m_comboBoxStartup, static_cast(&QComboBox::activated), + this, &ScriptStartItem::slotStartupChanged); + QObject::connect(this, &ScriptStartItem::askChangeStartup, autostart, &Autostart::slotChangeStartup); + treeWidget()->setItemWidget(this, Autostart::COL_RUN, m_comboBoxStartup); } ScriptStartItem::~ScriptStartItem() @@ -89,18 +90,17 @@ emit askChangeStartup(this, index); } -void ScriptStartItem::changeStartup(ScriptStartItem::ENV type ) +void ScriptStartItem::changeStartup(ScriptStartItem::ENV type) { - switch( type ) - { + switch (type) { case ScriptStartItem::START: - m_comboBoxStartup->setCurrentIndex( 0 ); + m_comboBoxStartup->setCurrentIndex(0); break; case ScriptStartItem::SHUTDOWN: - m_comboBoxStartup->setCurrentIndex( 1 ); + m_comboBoxStartup->setCurrentIndex(1); break; case ScriptStartItem::PRE_START: - m_comboBoxStartup->setCurrentIndex( 2 ); + m_comboBoxStartup->setCurrentIndex(2); break; default: qWarning() << " startup type is not defined :" << type;