From 1a87bf08498e102a93cf2cdcc8d1b7c58f7d78c8 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 4 Nov 2022 09:21:28 +0200 Subject: [PATCH] kcontrol: drop support for scripts in autostart KCM see the previous commit, also fixes detection of programs that are automatically started by using KStandardDirs to find the autostart directories Signed-off-by: Ivailo Monev --- kcontrol/autostart/CMakeLists.txt | 1 - kcontrol/autostart/addscriptdialog.cpp | 103 ------------------------- kcontrol/autostart/addscriptdialog.h | 57 -------------- kcontrol/autostart/autostart.cpp | 61 +-------------- kcontrol/autostart/autostart.h | 4 +- kcontrol/autostart/autostartconfig.ui | 15 +--- kcontrol/autostart/autostartitem.cpp | 10 --- kcontrol/autostart/autostartitem.h | 10 --- 8 files changed, 6 insertions(+), 255 deletions(-) delete mode 100644 kcontrol/autostart/addscriptdialog.cpp delete mode 100644 kcontrol/autostart/addscriptdialog.h diff --git a/kcontrol/autostart/CMakeLists.txt b/kcontrol/autostart/CMakeLists.txt index 593b1e6d..f17b6861 100644 --- a/kcontrol/autostart/CMakeLists.txt +++ b/kcontrol/autostart/CMakeLists.txt @@ -6,7 +6,6 @@ include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) set(kcm_autostart_PART_SRCS autostartitem.cpp - addscriptdialog.cpp advanceddialog.cpp autostart.cpp ) diff --git a/kcontrol/autostart/addscriptdialog.cpp b/kcontrol/autostart/addscriptdialog.cpp deleted file mode 100644 index 0def019f..00000000 --- a/kcontrol/autostart/addscriptdialog.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Stephen Leaf * - * smileaf@gmail.com * - * Copyright (C) 2008 by Montel Laurent * - * * - * 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 "addscriptdialog.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -AddScriptDialog::AddScriptDialog (QWidget* parent) - : KDialog( parent ) { - QWidget *w = new QWidget( this ); - setButtons( Cancel|Ok ); - QVBoxLayout *lay= new QVBoxLayout; - w->setLayout( lay ); - QLabel *lab = new QLabel( i18n( "Shell script path:" ), w ); - lay->addWidget( lab ); - m_url = new KUrlRequester( w ); - lay->addWidget( m_url ); - m_symlink = new QCheckBox( i18n( "Create as symlink" ), w ); //TODO fix text - m_symlink->setChecked( true ); - lay->addWidget( m_symlink ); - connect( m_url->lineEdit(), SIGNAL(textChanged(QString)), SLOT(textChanged(QString)) ); - m_url->lineEdit()->setFocus(); - enableButtonOk(false); - - setMainWidget( w ); -} - -AddScriptDialog::~AddScriptDialog() -{ -} - -void AddScriptDialog::textChanged(const QString &text) -{ - enableButtonOk(!text.isEmpty()); -} - -void AddScriptDialog::accept() -{ - if ( doBasicSanityCheck() ) - KDialog::accept(); -} - -bool AddScriptDialog::doBasicSanityCheck() -{ - const QString& path = KShell::tildeExpand(m_url->text()); - - QFileInfo file(path); - - if ( ! file.isAbsolute() ) { - KMessageBox::sorry( 0, i18n("\"%1\" is not an absolute path.", path) ); - return false; - } else if ( ! file.exists() ) { - KMessageBox::sorry( 0, i18n("\"%1\" does not exist.", path) ); - return false; - } else if ( !file.isFile() ) { - KMessageBox::sorry( 0, i18n("\"%1\" is not a file.", path) ); - return false; - } else if ( ! file.isReadable() ) { - KMessageBox::sorry( 0, i18n("\"%1\" is not readable.", path) ); - return false; - } - - return true; -} - -KUrl AddScriptDialog::importUrl() const -{ - return m_url->lineEdit()->text(); -} - -bool AddScriptDialog::symLink() const -{ - return m_symlink->isChecked(); -} - -#include "moc_addscriptdialog.cpp" diff --git a/kcontrol/autostart/addscriptdialog.h b/kcontrol/autostart/addscriptdialog.h deleted file mode 100644 index 6cce4256..00000000 --- a/kcontrol/autostart/addscriptdialog.h +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Stephen Leaf * - * smileaf@gmail.com * - * Copyright (C) 2008 by Montel Laurent * - * * - * 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 * - ***************************************************************************/ - -#ifndef ADDSCRIPTDIALOG_H -#define ADDSCRIPTDIALOG_H - -#include -#include - -class KUrlRequester; -#include - -class AddScriptDialog : public KDialog -{ - Q_OBJECT - -public: - explicit AddScriptDialog(QWidget* parent=0); - ~AddScriptDialog(); - // Returns the Url of the script to be imported - KUrl importUrl() const; - bool symLink() const; - -public slots: - // reimplemented - virtual void accept(); - -protected: - virtual bool doBasicSanityCheck(); - -private slots: - void textChanged(const QString &text); - -private: - KUrlRequester *m_url; - QCheckBox* m_symlink; -}; - -#endif diff --git a/kcontrol/autostart/autostart.cpp b/kcontrol/autostart/autostart.cpp index 9937c4b3..cd22748e 100644 --- a/kcontrol/autostart/autostart.cpp +++ b/kcontrol/autostart/autostart.cpp @@ -21,7 +21,6 @@ #include "autostart.h" #include "autostartitem.h" -#include "addscriptdialog.h" #include "advanceddialog.h" #include @@ -63,7 +62,6 @@ K_PLUGIN_FACTORY(AutostartFactory, registerPlugin();) setButtons(Help); - connect( widget->btnAddScript, SIGNAL(clicked()), SLOT(slotAddScript()) ); connect( widget->btnAddProgram, SIGNAL(clicked()), SLOT(slotAddProgram()) ); connect( widget->btnRemove, SIGNAL(clicked()), SLOT(slotRemoveCMD()) ); connect( widget->btnAdvanced, SIGNAL(clicked()), SLOT(slotAdvanced()) ); @@ -121,23 +119,10 @@ void Autostart::addItem( DesktopStartItem* item, const QString& name, const QStr 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 ) -{ - Q_ASSERT( item ); - item->setText( COL_NAME, name ); - item->setText( COL_COMMAND, command ); -} - - void Autostart::load() { // share/autostart may *only* contain .desktop files - // shutdown and env may *only* contain scripts, links or binaries - // autostart on the otherhand may contain all of the above. - // share/autostart is special as it overrides entries found in $KDEDIR/share/autostart - m_paths << KGlobalSettings::autostartPath() // All new entries should go here - << componentData().dirs()->localkdedir() + "share/autostart/" // For Importing purposes - << componentData().dirs()->localxdgconfdir() + "autostart/" ; //xdg-config autostart dir + m_paths << componentData().dirs()->resourceDirs("autostart"); //xdg-config autostart dir widget->listCMD->clear(); @@ -149,13 +134,7 @@ void Autostart::load() 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); - widget->listCMD->expandItem( m_programItem ); - widget->listCMD->expandItem( m_scriptItem ); foreach (const QString& path, m_paths) { if (! KGlobal::dirs()->exists(path)) @@ -198,18 +177,6 @@ void Autostart::load() indexPath = 0; //.kde/share/autostart and .config/autostart load destkop at startup addItem(item, config.readName(), grp.readEntry("Exec"), disabled ); } - else - { - ScriptStartItem *item = new ScriptStartItem( fi.absoluteFilePath(), m_scriptItem,this ); - if ( fi.isSymLink() ) { - QString link = fi.readLink(); - addItem(item, filename, link ); - } - else - { - addItem( item, filename, filename ); - } - } } } //Update button @@ -272,22 +239,6 @@ void Autostart::slotAddProgram() addItem( item, service->name(), service->exec() , false); } -void Autostart::slotAddScript() -{ - AddScriptDialog * addDialog = new AddScriptDialog(this); - int result = addDialog->exec(); - if (result == QDialog::Accepted) { - if (addDialog->symLink()) - KIO::link(addDialog->importUrl(), m_paths[0]); - else - KIO::copy(addDialog->importUrl(), m_paths[0]); - - ScriptStartItem * item = new ScriptStartItem( m_paths[0] + addDialog->importUrl().fileName(), m_scriptItem,this ); - addItem( item, addDialog->importUrl().fileName(), addDialog->importUrl().fileName() ); - } - delete addDialog; -} - void Autostart::slotRemoveCMD() { QTreeWidgetItem* item = widget->listCMD->currentItem(); @@ -300,16 +251,6 @@ void Autostart::slotRemoveCMD() KIO::del(startItem->fileName().path() ); delete item; } - else - { - ScriptStartItem * scriptItem = dynamic_cast( item ); - if ( scriptItem ) - { - m_scriptItem->takeChild( m_scriptItem->indexOfChild( scriptItem ) ); - KIO::del(scriptItem->fileName().path() ); - delete item; - } - } } void Autostart::slotEditCMD(QTreeWidgetItem* ent) diff --git a/kcontrol/autostart/autostart.h b/kcontrol/autostart/autostart.h index 13701f56..e32c1b87 100644 --- a/kcontrol/autostart/autostart.h +++ b/kcontrol/autostart/autostart.h @@ -46,11 +46,9 @@ public: protected: void addItem(DesktopStartItem *item, const QString& name, const QString& command, bool disabled ); - void addItem(ScriptStartItem *item, const QString& name, const QString& command ); private slots: void slotAddProgram(); - void slotAddScript(); void slotRemoveCMD(); void slotEditCMD(QTreeWidgetItem*); bool slotEditCMD(const KFileItem&); @@ -60,7 +58,7 @@ private slots: void slotAdvanced(); private: - QTreeWidgetItem *m_programItem, *m_scriptItem; + QTreeWidgetItem *m_programItem; QStringList m_paths; Ui_AutostartConfig *widget; diff --git a/kcontrol/autostart/autostartconfig.ui b/kcontrol/autostart/autostartconfig.ui index a902c24b..fd4f2961 100644 --- a/kcontrol/autostart/autostartconfig.ui +++ b/kcontrol/autostart/autostartconfig.ui @@ -28,27 +28,20 @@ - - - Add Script... - - - - &Remove - + &Properties... - + Qt::Vertical @@ -61,14 +54,14 @@ - + Qt::Horizontal - + Advanced... diff --git a/kcontrol/autostart/autostartitem.cpp b/kcontrol/autostart/autostartitem.cpp index 2f41a9b0..d47f8af3 100644 --- a/kcontrol/autostart/autostartitem.cpp +++ b/kcontrol/autostart/autostartitem.cpp @@ -68,14 +68,4 @@ DesktopStartItem::~DesktopStartItem() { } -ScriptStartItem::ScriptStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* autostart ) - : AutoStartItem( service, parent,autostart ) -{ -} - -ScriptStartItem::~ScriptStartItem() -{ -} - - #include "moc_autostartitem.cpp" diff --git a/kcontrol/autostart/autostartitem.h b/kcontrol/autostart/autostartitem.h index def95cef..e85b962c 100644 --- a/kcontrol/autostart/autostartitem.h +++ b/kcontrol/autostart/autostartitem.h @@ -49,14 +49,4 @@ public: ~DesktopStartItem(); }; - -class ScriptStartItem : public AutoStartItem -{ - Q_OBJECT - -public: - ScriptStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* ); - ~ScriptStartItem(); -}; - #endif