• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • workspace API Reference
  • KDE Home
  • Contact Us
 

liblancelot

  • sources
  • kde-4.14
  • workspace
  • kdeplasma-addons
  • libs
  • lancelot
  • models
PlasmaServiceListModel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Ivan Cukic <ivan.cukic(at)kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser/Library General Public License version 2,
6  * or (at your option) any later version, as published by the Free
7  * Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser/Library General Public License for more details
13  *
14  * You should have received a copy of the GNU Lesser/Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "PlasmaServiceListModel.h"
21 
22 #include <KDebug>
23 #include <KIcon>
24 #include <KConfigGroup>
25 
26 #include <Plasma/Service>
27 #include <Plasma/DataEngineManager>
28 
29 namespace Lancelot {
30 
31 class PlasmaServiceListModel::Private {
32 public:
33  Private()
34  : engine(NULL)
35  {}
36 
37  Plasma::DataEngine * engine;
38  Plasma::DataEngine::Data data;
39 
40  QString title;
41  QIcon icon;
42 };
43 
44 PlasmaServiceListModel::PlasmaServiceListModel(QString dataEngine)
45  : d(new Private())
46 {
47  d->engine = Plasma::DataEngineManager::self()->loadEngine(dataEngine);
48 
49  if (!d->engine->sources().contains(".metadata")) {
50  kDebug() << dataEngine << "is not a lancelot model - it doesn't have the .metadata structure";
51  d->engine = NULL;
52  return;
53  }
54 
55  Plasma::DataEngine::Data data =
56  d->engine->query(".metadata");
57  if (!data.contains("lancelot") ||
58  data["lancelot"].toMap()["version"] != "1.0"
59  ) {
60  kDebug() << dataEngine << "is not a lancelot model - the version is not valid";
61  d->engine = NULL;
62  return;
63  }
64  kDebug() << data
65  << data["lancelot"].toMap()["modelTitle"].toString()
66  << data["lancelot"].toMap()["modelIcon"].toString();
67 
68  d->icon = KIcon(data["lancelot"].toMap()["modelIcon"].toString());
69 
70  d->title = data["lancelot"].toMap()["modelTitle"].toString();
71  d->icon = KIcon(data["lancelot"].toMap()["modelIcon"].toString());
72 
73  d->engine->connectSource("data", this);
74 }
75 
76 PlasmaServiceListModel::~PlasmaServiceListModel()
77 {
78  delete d;
79 }
80 
81 QString PlasmaServiceListModel::title(int index) const
82 {
83  if (index < 0 || index >= size()) {
84  return QString();
85  }
86 
87  QStringList list = d->data["title"].toStringList();
88  return list.at(index);
89 }
90 
91 QString PlasmaServiceListModel::description(int index) const
92 {
93  if (index < 0 || index >= size()) {
94  return QString();
95  }
96 
97  QStringList list = d->data["description"].toStringList();
98  return list.at(index);
99 }
100 
101 QIcon PlasmaServiceListModel::icon(int index) const
102 {
103  if (index < 0 || index >= size()) {
104  return QIcon();
105  }
106 
107  QStringList list = d->data["icon"].toStringList();
108  return KIcon(list.at(index));
109 }
110 
111 bool PlasmaServiceListModel::isCategory(int index) const
112 {
113  Q_UNUSED(index);
114  return false;
115 }
116 
117 int PlasmaServiceListModel::size() const
118 {
119  return d->data["title"].toStringList().size();
120 }
121 
122 void PlasmaServiceListModel::dataUpdated(const QString & name,
123  const Plasma::DataEngine::Data & data)
124 {
125  if (name == "data") {
126  d->data = data;
127  emit updated();
128  }
129 }
130 
131 QString PlasmaServiceListModel::selfTitle() const
132 {
133  return d->title;
134 }
135 
136 QIcon PlasmaServiceListModel::selfIcon() const
137 {
138  return d->icon;
139 }
140 
141 void PlasmaServiceListModel::activate(int index)
142 {
143  Plasma::Service * service =
144  d->engine->serviceForSource("data");
145  KConfigGroup cg = service->operationDescription("activate");
146 
147  QStringList list = d->data["data"].toStringList();
148  cg.writeEntry("data", list.at(index));
149 
150  service->startOperationCall(cg);
151 }
152 
153 } // namespace Lancelot
154 
Lancelot::PlasmaServiceListModel::description
L_Override QString description(int index) const
Definition: PlasmaServiceListModel.cpp:91
QList::at
const T & at(int i) const
Lancelot::ActionListModel::updated
void updated()
This signal is emitted when the model is updated and the update is too complex to explain using itemI...
Lancelot::PlasmaServiceListModel::PlasmaServiceListModel
PlasmaServiceListModel(QString dataEngine)
Creates a new instance of PlasmaServiceListModel.
Definition: PlasmaServiceListModel.cpp:44
Lancelot::PlasmaServiceListModel::isCategory
L_Override bool isCategory(int index) const
Definition: PlasmaServiceListModel.cpp:111
Lancelot::PlasmaServiceListModel::title
L_Override QString title(int index) const
Definition: PlasmaServiceListModel.cpp:81
Lancelot::PlasmaServiceListModel::size
L_Override int size() const
Definition: PlasmaServiceListModel.cpp:117
Lancelot::PlasmaServiceListModel::icon
L_Override QIcon icon(int index) const
Definition: PlasmaServiceListModel.cpp:101
QString
QStringList
Lancelot::PlasmaServiceListModel::selfTitle
L_Override QString selfTitle() const
Definition: PlasmaServiceListModel.cpp:131
Lancelot::PlasmaServiceListModel::activate
L_Override void activate(int index)
Models should reimplement this function.
Definition: PlasmaServiceListModel.cpp:141
Lancelot::PlasmaServiceListModel::dataUpdated
void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data)
Definition: PlasmaServiceListModel.cpp:122
PlasmaServiceListModel.h
Lancelot::PlasmaServiceListModel::~PlasmaServiceListModel
virtual ~PlasmaServiceListModel()
Destroys this PlasmaServiceListModel.
Definition: PlasmaServiceListModel.cpp:76
Lancelot::PlasmaServiceListModel::selfIcon
L_Override QIcon selfIcon() const
Definition: PlasmaServiceListModel.cpp:136
QIcon
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:43:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

liblancelot

Skip menu "liblancelot"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

workspace API Reference

Skip menu "workspace API Reference"
  • kdeplasma-addons
  •       GroupingDesktop
  •     liblancelot

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal