Plasma5Support

jobs.h
1/*
2 SPDX-FileCopyrightText: 2008 Alex Merry <alex.merry@kdemail.net>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6#pragma once
7
8#include <QUrl>
9
10#include "modeljob.h"
11
12class AddEditPlaceJob : public ModelJob
13{
14public:
15 AddEditPlaceJob(KFilePlacesModel *model, QModelIndex index, const QVariantMap &parameters, QObject *parent = nullptr)
16 : ModelJob(parent, model, index, (index.isValid() ? "Edit" : "Add"), parameters)
17 , m_text(parameters[QStringLiteral("Name")].toString())
18 , m_url(parameters[QStringLiteral("Url")].toUrl())
19 , m_icon(parameters[QStringLiteral("Icon")].toString())
20 {
21 }
22
23 void start() override
24 {
25 if (m_index.isValid()) {
26 m_model->editPlace(m_index, m_text, m_url, m_icon);
27 } else {
28 m_model->addPlace(m_text, m_url, m_icon);
29 }
30 }
31
32private:
33 QString m_text;
34 QUrl m_url;
35 QString m_icon;
36};
37
38class RemovePlaceJob : public ModelJob
39{
40public:
41 RemovePlaceJob(KFilePlacesModel *model, const QModelIndex &index, QObject *parent)
42 : ModelJob(parent, model, index, QStringLiteral("Remove"))
43 {
44 }
45
46 void start() override
47 {
48 m_model->removePlace(m_index);
49 }
50};
51
52class ShowPlaceJob : public ModelJob
53{
54public:
55 ShowPlaceJob(KFilePlacesModel *model, const QModelIndex &index, bool show = true, QObject *parent = nullptr)
56 : ModelJob(parent, model, index, (show ? "Show" : "Hide"))
57 , m_show(show)
58 {
59 }
60
61 void start() override
62 {
63 m_model->setPlaceHidden(m_index, m_show);
64 }
65
66private:
67 bool m_show;
68};
69
70class TeardownDeviceJob : public ModelJob
71{
72public:
73 TeardownDeviceJob(KFilePlacesModel *model, const QModelIndex &index, QObject *parent = nullptr)
74 : ModelJob(parent, model, index, QStringLiteral("Teardown Device"))
75 {
76 }
77
78 void start() override
79 {
80 m_model->requestTeardown(m_index);
81 }
82};
83
84#include "setupdevicejob.h"
Q_INVOKABLE void removePlace(const QModelIndex &index) const
Q_INVOKABLE void requestTeardown(const QModelIndex &index)
Q_INVOKABLE void addPlace(const QString &text, const QUrl &url, const QString &iconName, const QString &appName, const QModelIndex &after)
Q_INVOKABLE void editPlace(const QModelIndex &index, const QString &text, const QUrl &url, const QString &iconName=QString(), const QString &appName=QString())
Q_INVOKABLE void setPlaceHidden(const QModelIndex &index, bool hidden)
QVariantMap parameters() const
char * toString(const EngineQuery &query)
bool isValid(QStringView ifopt)
bool isValid() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.