diff --git a/kcontrol/autostart/autostart.cpp b/kcontrol/autostart/autostart.cpp index 7a550e35..b743a6b6 100644 --- a/kcontrol/autostart/autostart.cpp +++ b/kcontrol/autostart/autostart.cpp @@ -88,30 +88,31 @@ Autostart::~Autostart() } -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 ); + AutoStartItem *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& command, bool disabled ) +void Autostart::addItem(AutoStartItem* item, const QString& name, const QString& command, bool disabled) { Q_ASSERT( item ); item->setText(COL_NAME, name); @@ -138,7 +139,7 @@ void Autostart::load() widget->listCMD->clear(); - m_programItem = new QTreeWidgetItem( widget->listCMD); + m_programItem = new QTreeWidgetItem(widget->listCMD); m_programItem->setText(0, i18n( "Desktop File")); m_programItem->setFlags(m_programItem->flags() ^ Qt::ItemIsSelectable); @@ -149,7 +150,7 @@ void Autostart::load() widget->listCMD->expandItem(m_programItem); foreach (const QString& path, m_paths) { - if (! KGlobal::dirs()->exists(path)) { + if (!KGlobal::dirs()->exists(path)) { continue; } @@ -160,8 +161,7 @@ void Autostart::load() QFileInfo fi = list.at(i); QString filename = fi.fileName(); bool desktopFile = filename.endsWith(".desktop"); - if ( desktopFile ) - { + if (desktopFile) { KDesktopFile config(fi.absoluteFilePath()); // kDebug() << fi.absoluteFilePath() << "trying" << config.desktopGroup().readEntry("Exec"); QStringList commandLine = KShell::splitArgs(config.desktopGroup().readEntry("Exec")); @@ -174,7 +174,7 @@ void Autostart::load() continue; } - DesktopStartItem *item = new DesktopStartItem( fi.absoluteFilePath(), m_programItem, this ); + AutoStartItem *item = new AutoStartItem(fi.absoluteFilePath(), m_programItem); const KConfigGroup grp = config.desktopGroup(); const bool hidden = grp.readEntry("Hidden", false); @@ -185,10 +185,11 @@ void Autostart::load() notShowList.contains("KDE") || (!onlyShowList.isEmpty() && !onlyShowList.contains("KDE")); - int indexPath = m_paths.indexOf((item->fileName().directory()+'/' ) ); - if ( indexPath > 0 ) + int indexPath = m_paths.indexOf(item->fileName().directory() + '/'); + if (indexPath > 0) { indexPath = 0; // .config/autostart load destkop at startup - addItem(item, config.readName(), grp.readEntry("Exec"), disabled ); + } + addItem(item, config.readName(), grp.readEntry("Exec"), disabled); } } } @@ -202,8 +203,9 @@ void Autostart::load() void Autostart::slotAddProgram() { KOpenWithDialog owdlg( this ); - if (owdlg.exec() != QDialog::Accepted) + if (owdlg.exec() != QDialog::Accepted) { return; + } KService::Ptr service = owdlg.service(); @@ -244,7 +246,7 @@ void Autostart::slotAddProgram() return; } } - DesktopStartItem * item = new DesktopStartItem(desktopPath, m_programItem, this); + AutoStartItem * item = new AutoStartItem(desktopPath, m_programItem); addItem(item, service->name(), service->exec(), false); } @@ -254,7 +256,7 @@ void Autostart::slotRemoveCMD() if (!item) { return; } - DesktopStartItem *startItem = dynamic_cast(item); + AutoStartItem *startItem = dynamic_cast(item); if (startItem) { m_programItem->takeChild(m_programItem->indexOfChild(startItem)); KIO::DeleteJob* deljob = KIO::del(startItem->fileName().path()); @@ -262,7 +264,7 @@ void Autostart::slotRemoveCMD() if (!deljob->exec()) { KMessageBox::detailedError( this, - i18n("Could not remove the program."), + i18n("Could not remove the autostart file."), deljob->errorString() ); delete deljob; @@ -282,11 +284,9 @@ void Autostart::slotEditCMD(QTreeWidgetItem* ent) if (!slotEditCMD(kfi)) { return; } - DesktopStartItem *desktopEntry = dynamic_cast(entry); - if (desktopEntry) { - KService service(desktopEntry->fileName().path()); - addItem(desktopEntry, service.name(), service.exec(), false); - } + + KService service(entry->fileName().path()); + addItem(entry, service.name(), service.exec(), false); } } @@ -310,7 +310,7 @@ void Autostart::slotAdvanced() return; } - DesktopStartItem *entry = static_cast( widget->listCMD->currentItem() ); + AutoStartItem *entry = static_cast(widget->listCMD->currentItem()); KDesktopFile kc(entry->fileName().path()); KConfigGroup grp = kc.desktopGroup(); bool status = false; @@ -336,10 +336,8 @@ void Autostart::slotAdvanced() void Autostart::slotSelectionChanged() { - const bool hasItems = (dynamic_cast(widget->listCMD->currentItem()) != 0); - widget->btnRemove->setEnabled(hasItems); - - const bool isDesktopItem = (dynamic_cast(widget->listCMD->currentItem()) != 0); + const bool isDesktopItem = (dynamic_cast(widget->listCMD->currentItem()) != 0); + widget->btnRemove->setEnabled(isDesktopItem); widget->btnProperties->setEnabled(isDesktopItem); widget->btnAdvanced->setEnabled(isDesktopItem) ; } diff --git a/kcontrol/autostart/autostart.h b/kcontrol/autostart/autostart.h index e32c1b87..b2a38c4c 100644 --- a/kcontrol/autostart/autostart.h +++ b/kcontrol/autostart/autostart.h @@ -32,12 +32,11 @@ #include "ui_autostartconfig.h" #include "autostartitem.h" -class Autostart: public KCModule +class Autostart : public KCModule { Q_OBJECT - public: - Autostart( QWidget* parent, const QVariantList& ); + Autostart(QWidget* parent, const QVariantList&); ~Autostart(); enum COL_TYPE { COL_NAME = 0, COL_COMMAND=1, COL_STATUS=2 }; void load(); @@ -45,7 +44,7 @@ public: void defaults(); protected: - void addItem(DesktopStartItem *item, const QString& name, const QString& command, bool disabled ); + void addItem(AutoStartItem *item, const QString& name, const QString& command, bool disabled); private slots: void slotAddProgram(); diff --git a/kcontrol/autostart/autostartitem.cpp b/kcontrol/autostart/autostartitem.cpp index d47f8af3..4ef68782 100644 --- a/kcontrol/autostart/autostartitem.cpp +++ b/kcontrol/autostart/autostartitem.cpp @@ -20,24 +20,22 @@ #include "autostartitem.h" #include "autostart.h" -#include -#include +#include #include #include -#include #include #include -AutoStartItem::AutoStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* ) - : QTreeWidgetItem( parent ) +AutoStartItem::AutoStartItem(const QString &service, QTreeWidgetItem *parent) + : QTreeWidgetItem(parent) { m_fileName = KUrl(service); + setCheckState(Autostart::COL_STATUS, Qt::Checked); } AutoStartItem::~AutoStartItem() { - } KUrl AutoStartItem::fileName() const @@ -47,10 +45,11 @@ KUrl AutoStartItem::fileName() const void AutoStartItem::setPath(const QString &path) { - Q_ASSERT( path.endsWith(QDir::separator()) ); + Q_ASSERT(path.endsWith(QDir::separator())); - if (path == m_fileName.directory(KUrl::AppendTrailingSlash)) + if (path == m_fileName.directory(KUrl::AppendTrailingSlash)) { return; + } const QString& newFileName = path + m_fileName.fileName(); KIO::move(m_fileName, KUrl(newFileName)); @@ -58,14 +57,4 @@ void AutoStartItem::setPath(const QString &path) m_fileName = KUrl(newFileName); } -DesktopStartItem::DesktopStartItem( const QString &service, QTreeWidgetItem *parent, Autostart*autostart ) - : AutoStartItem( service, parent,autostart ) -{ - setCheckState ( Autostart::COL_STATUS,Qt::Checked ); -} - -DesktopStartItem::~DesktopStartItem() -{ -} - #include "moc_autostartitem.cpp" diff --git a/kcontrol/autostart/autostartitem.h b/kcontrol/autostart/autostartitem.h index e85b962c..d4d428e7 100644 --- a/kcontrol/autostart/autostartitem.h +++ b/kcontrol/autostart/autostartitem.h @@ -20,18 +20,15 @@ #ifndef AUTOSTARTITEM_H #define AUTOSTARTITEM_H -#include +#include +#include #include #include -#include -#include -class Autostart; - class AutoStartItem : public QTreeWidgetItem, public QObject { public: - AutoStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* ); + AutoStartItem(const QString &service, QTreeWidgetItem *parent); ~AutoStartItem(); KUrl fileName() const; @@ -42,11 +39,4 @@ private: KUrl m_fileName; }; -class DesktopStartItem : public AutoStartItem -{ -public: - DesktopStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* ); - ~DesktopStartItem(); -}; - -#endif +#endif // AUTOSTARTITEM_H