add more spacing
[personal-kdebase.git] / workspace / plasma / dataengines / places / placesengine.cpp
blob4b8edab104a30749b044d38a4ce84659292541b9
1 /*
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>
23 #include <KDiskFreeSpaceInfo>
26 PlacesEngine::PlacesEngine(QObject *parent, const QVariantList &args)
27 : Plasma::DataEngine(parent, args)
29 connect(&m_placesModel, SIGNAL(modelReset()),
30 this, SLOT(modelReset()));
31 connect(&m_placesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
32 this, SLOT(dataChanged(QModelIndex,QModelIndex)));
33 connect(&m_placesModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
34 this, SLOT(placesAdded(QModelIndex,int,int)));
35 connect(&m_placesModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
36 this, SLOT(placesRemoved(QModelIndex,int,int)));
38 sendAllData();
41 PlacesEngine::~PlacesEngine()
45 void PlacesEngine::modelReset()
47 removeAllSources();
50 void PlacesEngine::placesAdded(const QModelIndex&, int start, int end)
52 sendData(start, end);
55 void PlacesEngine::placesRemoved(const QModelIndex&, int start, int end)
57 kDebug() << "Places" << start << "through" << end << "removed";
58 for (int index = start; index <= end; index++) {
59 removeSource(QString::number(index));
63 void PlacesEngine::dataChanged(const QModelIndex& topLeft,
64 const QModelIndex& bottomRight)
66 sendData(topLeft.row(), bottomRight.row());
69 void PlacesEngine::sendAllData()
71 sendData(0, m_placesModel.rowCount() - 1);
74 void PlacesEngine::sendData(int start, int end)
76 for (int row = start; row <= end; ++row) {
77 QModelIndex index = m_placesModel.index(row, 0);
79 Data map;
81 QString source = QString::number(row);
83 setData(source, "name", m_placesModel.text(index));
84 setData(source, "url", m_placesModel.url(index).url());
85 setData(source, "icon", m_placesModel.icon(index));
86 setData(source, "hidden",
87 m_placesModel.data(index, KFilePlacesModel::HiddenRole));
88 setData(source, "setupNeeded",
89 m_placesModel.data(index, KFilePlacesModel::SetupNeededRole));
90 setData(source, "isDevice",
91 m_placesModel.deviceForIndex(index).isValid());
93 QString path = m_placesModel.url(index).path();
94 if (!path.isEmpty()) {
95 // We can't get free space for unmounted volumes :-(
96 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(path);
97 setData(source, "kBSize", info.size()/1024); // deprecated
98 setData(source, "kBUsed", info.used()/1024); // deprecated
99 setData(source, "kBAvailable", info.available()/1024); // deprecated
100 setData(source, "size (bytes)", info.size());
101 setData(source, "used (bytes)", info.used());
102 setData(source, "available (bytes)", info.available());
107 K_EXPORT_PLASMA_DATAENGINE(places, PlacesEngine)
109 #include "placesengine.moc"