• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Engines

placesengine.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007 Alex Merry <huntedhacker@tiscali.co.uk>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License version 2 as
00006  *   published by the Free Software Foundation
00007  *
00008  *   This program is distributed in the hope that it will be useful,
00009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *   GNU General Public License for more details
00012  *
00013  *   You should have received a copy of the GNU Library General Public
00014  *   License along with this program; if not, write to the
00015  *   Free Software Foundation, Inc.,
00016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017  */
00018 
00019 // Local includes
00020 #include "placesengine.h"
00021 
00022 // Qt includes
00023 #include <QtCore/QString>
00024 #include <QtCore/QVariantList>
00025 
00026 
00027 // KDE includes
00028 #include <KDiskFreeSpace>
00029 
00030 PlacesEngine::PlacesEngine(QObject *parent, const QVariantList &args)
00031     : Plasma::DataEngine(parent, args)
00032 {
00033     // dataChanged(), rowsRemoved() and setupDone() signals from
00034     // KFilePlacesModel are not propagated between applications.
00035     // layoutChanged() is not emitted at all.
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     // suicidal object: don't need to worry about cleanup
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 

Engines

Skip menu "Engines"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal