2
* Copyright (C) 2007, 2008, 2009, 2010 Ivan Cukic <ivan.cukic(at)kde.org>
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
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
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.
20
#include "AvailableModels.h"
21
#include <KStandardDirs>
22
#include <KFileDialog>
23
#include <KDirSelectDialog>
27
#include <Lancelot/Models/Serializator>
32
AvailableModels * AvailableModels::instance = NULL;
34
AvailableModels * AvailableModels::self()
37
instance = new AvailableModels();
42
AvailableModels::AvailableModels()
43
: StandardActionTreeModel()
45
StandardActionTreeModel::Item * item = root();
49
new StandardActionTreeModel::Item(
50
i18n("Favorite applications"), QString::null,
52
"FavoriteApplications");
55
new StandardActionTreeModel::Item(
56
i18n("Applications category..."), QString::null,
57
KIcon("plasmaapplet-shelf"),
62
new StandardActionTreeModel::Item(
63
i18n("Places"), QString::null,
68
new StandardActionTreeModel::Item(
69
i18n("Folder..."), QString::null,
75
new StandardActionTreeModel::Item(
76
i18n("Removable devices"), QString::null,
77
KIcon("media-optical"),
81
new StandardActionTreeModel::Item(
82
i18n("Fixed devices"), QString::null,
83
KIcon("drive-harddisk"),
86
// System applications
88
new StandardActionTreeModel::Item(
89
i18n("System tools"), QString::null,
95
new StandardActionTreeModel::Item(
96
i18n("New documents"), QString::null,
97
KIcon("document-new"),
101
new StandardActionTreeModel::Item(
102
i18n("Open documents"), QString::null,
103
KIcon("document-edit"),
107
new StandardActionTreeModel::Item(
108
i18n("Recent documents"), QString::null,
109
KIcon("document-open-recent"),
114
new StandardActionTreeModel::Item(
115
i18n("Online contacts"), QString::null,
120
new StandardActionTreeModel::Item(
121
i18n("Unread messages"), QString::null,
128
AvailableModels::~AvailableModels()
132
StandardActionTreeModel * AvailableModels::createChild(int index)
139
ActionListModel * AvailableModels::modelForSerializedData(const QString & serializedData)
141
QMap < QString, QString > data = Lancelot::Models::Serializator::deserialize(serializedData);
146
QString AvailableModels::serializedDataForItem(int index)
148
QMap < QString, QString > data;
149
data["version"] = "1.0";
150
data["type"] = "list";
151
data["model"] = itemAt(index)->data.toString();
153
if (data["model"] == "Folder") {
154
QString dir = KFileDialog::getExistingDirectory();
155
data["model"] = "Folder " + dir;
156
} else if (data["model"] == "Applications") {
157
data["model"] = "Folder " +
158
KDirSelectDialog::selectDirectory(KUrl("applications:/")).url();
161
if (data["model"] == "Folder ") {
162
return QString::null;
165
return Serializator::serialize(data);
168
ActionListModel * AvailableModels::modelForItem(int index)
170
return modelForSerializedData(
171
serializedDataForItem(index));
174
QString AvailableModels::titleForModel(const QString & modelId)
178
if (modelId.startsWith("Folder ")) {
179
QString result = modelId;
180
result.replace("Folder ", QString());
184
for (int i = 0; i < size(); i++) {
185
if (itemAt(i)->data.toString() == modelId) {
186
return itemAt(i)->title;
193
} // namespace Models
194
} // namespace Lancelot
196
#include "AvailableModels.moc"