Commit 01776488 authored by Méven Car's avatar Méven Car

KCM/Autostart Add a model to separate logic from UI

Summary:
Adds the complete fileName of the autostart entries as tooltips.
Collapse home to ~ in command column.

Test Plan:
 * Add a desktop entry
 * Edit a desktop entry
 * Disable a desktop entry
 * Remove a desktop entry
 * Make a destktop entry run only in KDE
 * Add a script Item with symlink
 * Add a script Item without symlink
 * Change the startup choice for a script Item
   * Add twice the same script to the same startup choice
 * Remove a script item

Before:
{F8133419}
After:
{F8133420}

Reviewers: mlaurent, ervin, #plasma, broulik, bport, crossi

Reviewed By: ervin

Subscribers: alex, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26934
parent baa168ed
......@@ -5,6 +5,7 @@ set(kcm_autostart_PART_SRCS
autostartitem.cpp
addscriptdialog.cpp
advanceddialog.cpp
autostartmodel.cpp
autostart.cpp )
ki18n_wrap_ui(kcm_autostart_PART_SRCS autostartconfig.ui )
......
This diff is collapsed.
......@@ -39,36 +39,36 @@ class Autostart: public KCModule
public:
explicit Autostart( QWidget* parent, const QVariantList& );
~Autostart() override;
enum COL_TYPE { COL_NAME = 0, COL_COMMAND=1, COL_STATUS=2,COL_RUN=3 };
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;}
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 updateDesktopStartItem(DesktopStartItem *item, const QString &name, const QString &command, bool disabled, const QString &fileName);
void updateScriptStartItem(ScriptStartItem *item, const QString &name, const QString &command, AutostartEntrySource type, const QString &fileName);
private Q_SLOTS:
void slotAddProgram();
void slotAddScript();
void slotRemoveCMD();
void slotEditCMD(QTreeWidgetItem*);
bool slotEditCMD(const KFileItem&);
void slotEditCMD();
void slotSelectionChanged();
void slotItemClicked( QTreeWidgetItem *, int);
void slotAdvanced();
void slotRowInserted(const QModelIndex &parent, int first, int last);
void slotDatachanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
private:
QTreeWidgetItem *m_programItem, *m_scriptItem;
QString m_desktopPath;
QStringList m_paths;
QStringList m_pathName;
QModelIndex indexFromWidget(QTreeWidgetItem *widget) const;
AutostartModel *m_model;
QTreeWidgetItem *m_programItem;
QTreeWidgetItem *m_scriptItem;
Ui_AutostartConfig *widget;
};
......
......@@ -29,9 +29,8 @@
#include <KLocalizedString>
#include <KIO/CopyJob>
AutoStartItem::AutoStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* )
AutoStartItem::AutoStartItem(QTreeWidgetItem *parent)
: QTreeWidgetItem( parent )
, m_fileName(QUrl::fromLocalFile(service))
{
}
......@@ -40,44 +39,30 @@ AutoStartItem::~AutoStartItem()
}
QUrl AutoStartItem::fileName() const
DesktopStartItem::DesktopStartItem(QTreeWidgetItem *parent )
: AutoStartItem(parent )
{
return m_fileName;
}
void AutoStartItem::setPath(const QString &path)
{
Q_ASSERT( path.endsWith(QDir::separator()) );
if (QUrl(path) == m_fileName.adjusted(QUrl::RemoveFilename))
return;
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 )
{
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( QTreeWidgetItem *parent, Autostart* autostart )
: AutoStartItem( parent )
{
m_comboBoxStartup = new QComboBox;
m_comboBoxStartup->addItems( autostart->listPathName() );
setText( 2, i18nc( "The program will be run", "Enabled" ) );
QObject::connect(m_comboBoxStartup, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &ScriptStartItem::slotStartupChanged);
QObject::connect( this,&ScriptStartItem::askChangeStartup,autostart,&Autostart::slotChangeStartup );
treeWidget()->setItemWidget ( this, Autostart::COL_RUN, m_comboBoxStartup );
// make the folder PathName match the AutoStartPaths that match AutostartEntrySource
// skipping XdgAutoStart that is not available for script items
m_comboBoxStartup->addItem(AutostartModel::listPathName()[0], AutostartEntrySource::XdgScripts);
m_comboBoxStartup->addItem(AutostartModel::listPathName()[1], AutostartEntrySource::PlasmaShutdown);
m_comboBoxStartup->addItem(AutostartModel::listPathName()[2], AutostartEntrySource::PlasmaStart);
setText(Autostart::COL_STATUS, i18nc( "The program will be run", "Enabled" ) );
connect(m_comboBoxStartup, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &ScriptStartItem::slotStartupChanged);
connect( this, &ScriptStartItem::askChangeStartup, autostart, &Autostart::slotChangeStartup );
treeWidget()->setItemWidget( this, Autostart::COL_RUN, m_comboBoxStartup );
}
ScriptStartItem::~ScriptStartItem()
......@@ -86,20 +71,21 @@ ScriptStartItem::~ScriptStartItem()
void ScriptStartItem::slotStartupChanged(int index)
{
emit askChangeStartup(this, index);
Q_UNUSED(index)
emit askChangeStartup(this, m_comboBoxStartup->currentData().toInt());
}
void ScriptStartItem::changeStartup(ScriptStartItem::ENV type )
void ScriptStartItem::changeStartup(AutostartEntrySource type )
{
switch( type )
{
case ScriptStartItem::START:
case AutostartEntrySource::XdgScripts:
m_comboBoxStartup->setCurrentIndex( 0 );
break;
case ScriptStartItem::SHUTDOWN:
case AutostartEntrySource::PlasmaShutdown:
m_comboBoxStartup->setCurrentIndex( 1 );
break;
case ScriptStartItem::PRE_START:
case AutostartEntrySource::PlasmaStart:
m_comboBoxStartup->setCurrentIndex( 2 );
break;
default:
......
......@@ -20,8 +20,9 @@
#ifndef AUTOSTARTITEM_H
#define AUTOSTARTITEM_H
#include "autostartmodel.h"
#include <QTreeWidgetItem>
#include <QObject>
#include <QUrl>
class QComboBox;
......@@ -31,21 +32,15 @@ class Autostart;
class AutoStartItem : public QTreeWidgetItem, public QObject
{
public:
AutoStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* );
AutoStartItem(QTreeWidgetItem *parent);
~AutoStartItem() override;
QUrl fileName() const;
void setPath(const QString &path);
private:
QUrl m_fileName;
};
class DesktopStartItem : public AutoStartItem
{
public:
DesktopStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* );
DesktopStartItem(QTreeWidgetItem *parent );
~DesktopStartItem() override;
};
......@@ -55,17 +50,15 @@ class ScriptStartItem : public AutoStartItem
Q_OBJECT
public:
enum ENV { START=0, SHUTDOWN=1, PRE_START=2}; //rename
ScriptStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* );
ScriptStartItem(QTreeWidgetItem *parent, Autostart* autostart );
~ScriptStartItem() override;
void changeStartup( ScriptStartItem::ENV type );
void changeStartup( AutostartEntrySource type );
Q_SIGNALS:
void askChangeStartup(ScriptStartItem* item, int index);
private Q_SLOTS:
void slotStartupChanged(int index);
private:
......
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2020 by Méven Car <meven.car@enioka.com> *
* *
* 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 AUTOSTARTMODEL_H
#define AUTOSTARTMODEL_H
#include <QAbstractListModel>
#include <KService>
enum AutostartEntrySource {
XdgAutoStart = 0,
XdgScripts = 1,
PlasmaShutdown = 2,
PlasmaStart = 3,
};
struct AutostartEntry
{
QString name; // Human readable name or local script name
QString command; // exec or original .sh file
AutostartEntrySource source;
bool enabled;
QString fileName; // the file backing the entry
bool onlyInPlasma;
};
Q_DECLARE_TYPEINFO(AutostartEntry, Q_MOVABLE_TYPE);
class AutostartModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit AutostartModel(QWidget *parent = nullptr);
enum Roles {
Command = Qt::UserRole + 1,
Enabled,
Source,
FileName,
OnlyInPlasma
};
static AutostartEntrySource sourceFromInt(int index);
static QString XdgAutoStartPath();
static QStringList listPath();
static QStringList listPathName();
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
QHash<int, QByteArray> roleNames() const override;
bool addEntry(const KService::Ptr &service);
bool addEntry(const QUrl &path, const bool symlink);
bool reloadEntry(const QModelIndex &index, const QString &fileName);
bool removeEntry(const QModelIndex &index);
void load();
private:
QVector<AutostartEntry> m_entries;
QWidget *m_window;
};
#endif // AUTOSTARTMODEL_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment