~ubuntu-branches/ubuntu/oneiric/kdeplasma-addons/oneiric

« back to all changes in this revision

Viewing changes to libs/lancelot-datamodels/AvailableModels.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mto: (0.4.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: james.westby@ubuntu.com-20100525095014-e3cebfkdenjrx3xg
Tags: upstream-4.4.80
ImportĀ upstreamĀ versionĀ 4.4.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2007, 2008, 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 "AvailableModels.h"
 
21
#include <KStandardDirs>
 
22
#include <KFileDialog>
 
23
#include <KDirSelectDialog>
 
24
#include <KIcon>
 
25
#include <KDebug>
 
26
 
 
27
#include <Lancelot/Models/Serializator>
 
28
 
 
29
namespace Lancelot {
 
30
namespace Models {
 
31
 
 
32
AvailableModels * AvailableModels::instance = NULL;
 
33
 
 
34
AvailableModels * AvailableModels::self()
 
35
{
 
36
    if (!instance) {
 
37
        instance = new AvailableModels();
 
38
    }
 
39
    return instance;
 
40
}
 
41
 
 
42
AvailableModels::AvailableModels()
 
43
    : StandardActionTreeModel()
 
44
{
 
45
    StandardActionTreeModel::Item * item = root();
 
46
 
 
47
    // Applications model
 
48
    item->children <<
 
49
        new StandardActionTreeModel::Item(
 
50
           i18n("Favorite applications"), QString::null,
 
51
           KIcon("favorites"),
 
52
           "FavoriteApplications");
 
53
 
 
54
    item->children <<
 
55
        new StandardActionTreeModel::Item(
 
56
           i18n("Applications category..."), QString::null,
 
57
           KIcon("plasmaapplet-shelf"),
 
58
           "Applications");
 
59
 
 
60
    // Places
 
61
    item->children <<
 
62
        new StandardActionTreeModel::Item(
 
63
           i18n("Places"), QString::null,
 
64
           KIcon("folder"),
 
65
           "Places");
 
66
 
 
67
    item->children <<
 
68
        new StandardActionTreeModel::Item(
 
69
           i18n("Folder..."), QString::null,
 
70
           KIcon("folder"),
 
71
           "Folder");
 
72
 
 
73
    // Devices
 
74
    item->children <<
 
75
        new StandardActionTreeModel::Item(
 
76
           i18n("Removable devices"), QString::null,
 
77
           KIcon("media-optical"),
 
78
           "Devices/Removable");
 
79
 
 
80
    item->children <<
 
81
        new StandardActionTreeModel::Item(
 
82
           i18n("Fixed devices"), QString::null,
 
83
           KIcon("drive-harddisk"),
 
84
           "Devices/Fixed");
 
85
 
 
86
    // System applications
 
87
    item->children <<
 
88
        new StandardActionTreeModel::Item(
 
89
           i18n("System tools"), QString::null,
 
90
           KIcon("computer"),
 
91
           "System");
 
92
 
 
93
    // Documents
 
94
    item->children <<
 
95
        new StandardActionTreeModel::Item(
 
96
           i18n("New documents"), QString::null,
 
97
           KIcon("document-new"),
 
98
           "NewDocuments");
 
99
 
 
100
    item->children <<
 
101
        new StandardActionTreeModel::Item(
 
102
           i18n("Open documents"), QString::null,
 
103
           KIcon("document-edit"),
 
104
           "OpenDocuments");
 
105
 
 
106
    item->children <<
 
107
        new StandardActionTreeModel::Item(
 
108
           i18n("Recent documents"), QString::null,
 
109
           KIcon("document-open-recent"),
 
110
           "RecentDocuemnts");
 
111
 
 
112
    // Contacts
 
113
    item->children <<
 
114
        new StandardActionTreeModel::Item(
 
115
           i18n("Online contacts"), QString::null,
 
116
           KIcon("kopete"),
 
117
           "Contacts");
 
118
 
 
119
    item->children <<
 
120
        new StandardActionTreeModel::Item(
 
121
           i18n("Unread messages"), QString::null,
 
122
           KIcon("kmail"),
 
123
           "Messages");
 
124
 
 
125
 
 
126
}
 
127
 
 
128
AvailableModels::~AvailableModels()
 
129
{
 
130
}
 
131
 
 
132
StandardActionTreeModel * AvailableModels::createChild(int index)
 
133
{
 
134
    Q_UNUSED(index);
 
135
 
 
136
    return NULL;
 
137
}
 
138
 
 
139
ActionListModel * AvailableModels::modelForSerializedData(const QString & serializedData)
 
140
{
 
141
    QMap < QString, QString > data = Lancelot::Models::Serializator::deserialize(serializedData);
 
142
 
 
143
    return 0;
 
144
}
 
145
 
 
146
QString AvailableModels::serializedDataForItem(int index)
 
147
{
 
148
    QMap < QString, QString > data;
 
149
    data["version"] = "1.0";
 
150
    data["type"] = "list";
 
151
    data["model"] = itemAt(index)->data.toString();
 
152
 
 
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();
 
159
    }
 
160
 
 
161
    if (data["model"] == "Folder ") {
 
162
        return QString::null;
 
163
    }
 
164
 
 
165
    return Serializator::serialize(data);
 
166
}
 
167
 
 
168
ActionListModel * AvailableModels::modelForItem(int index)
 
169
{
 
170
    return modelForSerializedData(
 
171
        serializedDataForItem(index));
 
172
}
 
173
 
 
174
QString AvailableModels::titleForModel(const QString & modelId)
 
175
{
 
176
    kDebug() << modelId;
 
177
 
 
178
    if (modelId.startsWith("Folder ")) {
 
179
        QString result = modelId;
 
180
        result.replace("Folder ", QString());
 
181
        return result;
 
182
    }
 
183
 
 
184
    for (int i = 0; i < size(); i++) {
 
185
        if (itemAt(i)->data.toString() == modelId) {
 
186
            return itemAt(i)->title;
 
187
        }
 
188
    }
 
189
 
 
190
    return QString();
 
191
}
 
192
 
 
193
} // namespace Models
 
194
} // namespace Lancelot
 
195
 
 
196
#include "AvailableModels.moc"