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

Plasma

placesengine.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2008 Alex Merry <alex.merry@kdemail.net>
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 #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             // We can't get free space for unmounted volumes :-(
00096             KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(path);
00097             setData(source, "kBSize", info.size()/1024); // deprecated
00098             setData(source, "kBUsed", info.used()/1024); // deprecated
00099             setData(source, "kBAvailable", info.available()/1024); // deprecated
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 

Plasma

Skip menu "Plasma"
  • 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
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
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