00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "placesengine.h"
00020
00021 #include <QtCore/QString>
00022
00023 #include <KDiskFreeSpaceInfo>
00024
00025
00026 PlacesEngine::PlacesEngine(QObject *parent, const QVariantList &args)
00027 : Plasma::DataEngine(parent, args)
00028 {
00029 connect(&m_placesModel, SIGNAL(modelReset()),
00030 this, SLOT(modelReset()));
00031 connect(&m_placesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
00032 this, SLOT(dataChanged(QModelIndex,QModelIndex)));
00033 connect(&m_placesModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
00034 this, SLOT(placesAdded(QModelIndex,int,int)));
00035 connect(&m_placesModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
00036 this, SLOT(placesRemoved(QModelIndex,int,int)));
00037
00038 sendAllData();
00039 }
00040
00041 PlacesEngine::~PlacesEngine()
00042 {
00043 }
00044
00045 void PlacesEngine::modelReset()
00046 {
00047 removeAllSources();
00048 }
00049
00050 void PlacesEngine::placesAdded(const QModelIndex&, int start, int end)
00051 {
00052 sendData(start, end);
00053 }
00054
00055 void PlacesEngine::placesRemoved(const QModelIndex&, int start, int end)
00056 {
00057 kDebug() << "Places" << start << "through" << end << "removed";
00058 for (int index = start; index <= end; index++) {
00059 removeSource(QString::number(index));
00060 }
00061 }
00062
00063 void PlacesEngine::dataChanged(const QModelIndex& topLeft,
00064 const QModelIndex& bottomRight)
00065 {
00066 sendData(topLeft.row(), bottomRight.row());
00067 }
00068
00069 void PlacesEngine::sendAllData()
00070 {
00071 sendData(0, m_placesModel.rowCount() - 1);
00072 }
00073
00074 void PlacesEngine::sendData(int start, int end)
00075 {
00076 for (int row = start; row <= end; ++row) {
00077 QModelIndex index = m_placesModel.index(row, 0);
00078
00079 Data map;
00080
00081 QString source = QString::number(row);
00082
00083 setData(source, "name", m_placesModel.text(index));
00084 setData(source, "url", m_placesModel.url(index).url());
00085 setData(source, "icon", m_placesModel.icon(index));
00086 setData(source, "hidden",
00087 m_placesModel.data(index, KFilePlacesModel::HiddenRole));
00088 setData(source, "setupNeeded",
00089 m_placesModel.data(index, KFilePlacesModel::SetupNeededRole));
00090 setData(source, "isDevice",
00091 m_placesModel.deviceForIndex(index).isValid());
00092
00093 QString path = m_placesModel.url(index).path();
00094 if (!path.isEmpty()) {
00095
00096 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(path);
00097 setData(source, "kBSize", info.size()/1024);
00098 setData(source, "kBUsed", info.used()/1024);
00099 setData(source, "kBAvailable", info.available()/1024);
00100 setData(source, "size (bytes)", info.size());
00101 setData(source, "used (bytes)", info.used());
00102 setData(source, "available (bytes)", info.available());
00103 }
00104 }
00105 }
00106
00107 K_EXPORT_PLASMA_DATAENGINE(places, PlacesEngine)
00108
00109 #include "placesengine.moc"
00110