2
* Copyright (C) 2008 Alex Merry <alex.merry@kdemail.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License version 2 as
6
* published by the Free Software Foundation
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details
13
* You should have received a copy of the GNU Library General Public
14
* License along with this program; if not, write to the
15
* Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "placesengine.h"
21
#include <QtCore/QString>
24
#include <KDiskFreeSpaceInfo>
26
#include "placeservice.h"
28
PlacesEngine::PlacesEngine(QObject *parent, const QVariantList &args)
29
: Plasma::DataEngine(parent, args)
31
connect(&m_placesModel, SIGNAL(modelReset()),
32
this, SLOT(modelReset()));
33
connect(&m_placesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
34
this, SLOT(dataChanged(QModelIndex,QModelIndex)));
35
connect(&m_placesModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
36
this, SLOT(placesAdded(QModelIndex,int,int)));
37
connect(&m_placesModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
38
this, SLOT(placesRemoved(QModelIndex,int,int)));
43
PlacesEngine::~PlacesEngine()
47
void PlacesEngine::modelReset()
52
void PlacesEngine::placesAdded(const QModelIndex&, int start, int end)
57
void PlacesEngine::placesRemoved(const QModelIndex&, int start, int end)
59
kDebug() << "Places" << start << "through" << end << "removed";
60
for (int index = start; index <= end; index++) {
61
removeSource(QString::number(index));
65
void PlacesEngine::dataChanged(const QModelIndex& topLeft,
66
const QModelIndex& bottomRight)
68
sendData(topLeft.row(), bottomRight.row());
71
void PlacesEngine::sendAllData()
73
sendData(0, m_placesModel.rowCount() - 1);
76
Plasma::Service *PlacesEngine::serviceForSource(const QString &source)
78
const int row = source.toInt();
79
const QModelIndex index = m_placesModel.index(row, 0);
80
if (index.isValid()) {
81
return new PlaceService(this, &m_placesModel, index);
84
return DataEngine::serviceForSource(source);
87
void PlacesEngine::sendData(int start, int end)
89
for (int row = start; row <= end; ++row) {
90
const QModelIndex index = m_placesModel.index(row, 0);
94
const QString source = QString::number(row);
96
setData(source, "name", m_placesModel.text(index));
97
setData(source, "url", m_placesModel.url(index).url());
98
setData(source, "icon", m_placesModel.icon(index));
99
setData(source, "hidden",
100
m_placesModel.data(index, KFilePlacesModel::HiddenRole));
101
setData(source, "setupNeeded",
102
m_placesModel.data(index, KFilePlacesModel::SetupNeededRole));
103
setData(source, "isDevice",
104
m_placesModel.deviceForIndex(index).isValid());
106
const QString path = m_placesModel.url(index).path();
107
if (!path.isEmpty()) {
108
// We can't get free space for unmounted volumes :-(
109
KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(path);
110
setData(source, "kBSize", info.size()/1024); // deprecated
111
setData(source, "kBUsed", info.used()/1024); // deprecated
112
setData(source, "kBAvailable", info.available()/1024); // deprecated
113
setData(source, "size (bytes)", info.size());
114
setData(source, "used (bytes)", info.used());
115
setData(source, "available (bytes)", info.available());
120
K_EXPORT_PLASMA_DATAENGINE(places, PlacesEngine)
122
#include "placesengine.moc"