00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "placesengine.h"
00021
00022
00023 #include <QtCore/QString>
00024 #include <QtCore/QVariantList>
00025
00026
00027
00028 #include <KDiskFreeSpace>
00029
00030 PlacesEngine::PlacesEngine(QObject *parent, const QVariantList &args)
00031 : Plasma::DataEngine(parent, args)
00032 {
00033
00034
00035
00036 connect(&m_placesModel, SIGNAL(modelReset()),
00037 this, SLOT(modelReset()));
00038 connect(&m_placesModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
00039 this, SLOT(placesAdded(QModelIndex,int,int)));
00040
00041 sendData();
00042 }
00043
00044 PlacesEngine::~PlacesEngine()
00045 {
00046 }
00047
00048 void PlacesEngine::modelReset()
00049 {
00050 kDebug() << "Model reset";
00051
00052 removeAllSources();
00053 }
00054
00055 void PlacesEngine::placesAdded(const QModelIndex &parent, int start, int end)
00056 {
00057 kDebug() << "Places added:" << parent << "from" << start << "to" << end;
00058 sendData();
00059 }
00060
00061 void PlacesEngine::diskFreeSpaceFound(const QString &mountPoint,
00062 quint64 kBSize,
00063 quint64 kBUsed,
00064 quint64 kBAvailable)
00065 {
00066 kDebug() << "Sir! We got one!" << mountPoint + ": "
00067 << "size =" << kBSize
00068 << "used =" << kBUsed
00069 << "avail =" << kBAvailable;
00070 QString source;
00071
00072 foreach (const QString &testsource, sources()) {
00073 kDebug() << "Testing" << query(testsource)["url"];
00074 KUrl url(query(testsource)["url"].toString());
00075 if (url.isLocalFile() && url.path() == mountPoint) {
00076 source = testsource;
00077 break;
00078 }
00079 }
00080
00081 kDebug() << "Source:" << source;
00082 if (!source.isEmpty()) {
00083 setData(source, "kBSize", kBSize);
00084 setData(source, "kBUsed", kBUsed);
00085 setData(source, "kBAvailable", kBAvailable);
00086 }
00087 }
00088
00089 void PlacesEngine::tryGetFreeSpace(const KUrl &url)
00090 {
00091 if (!url.isLocalFile()) {
00092 return;
00093 }
00094
00095 kDebug() << "Requesting free space on" << url;
00096
00097
00098 KDiskFreeSpace *diskFreeSpace = new KDiskFreeSpace(this);
00099 connect(diskFreeSpace,
00100 SIGNAL(foundMountPoint(QString,quint64,quint64,quint64)),
00101 this,
00102 SLOT(diskFreeSpaceFound(QString,quint64,quint64,quint64)));
00103 diskFreeSpace->readDF(url.path());
00104 }
00105
00106 void PlacesEngine::sendData()
00107 {
00108 int rowCount = m_placesModel.rowCount();
00109 for (int i = 0; i < rowCount; ++i) {
00110 QModelIndex index = m_placesModel.index(i,0);
00111
00112 Data map;
00113
00114 QString source = QString::number(i);
00115
00116 setData(source, "name", m_placesModel.text(index));
00117 setData(source, "url", m_placesModel.url(index).url());
00118 setData(source, "icon", m_placesModel.icon(index));
00119 setData(source, "hidden",
00120 m_placesModel.data(index, KFilePlacesModel::HiddenRole));
00121 setData(source, "setupNeeded",
00122 m_placesModel.data(index, KFilePlacesModel::SetupNeededRole));
00123
00124 if (m_placesModel.deviceForIndex(index).isValid()) {
00125 setData(source, "isDevice", true);
00126 tryGetFreeSpace(m_placesModel.url(index));
00127 } else {
00128 setData(source, "isDevice", false);
00129 }
00130 }
00131 }
00132
00133 K_EXPORT_PLASMA_DATAENGINE(places, PlacesEngine)
00134
00135