[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kfile
From: Kevin Ottens <ervin () kde ! org>
Date: 2007-04-03 17:18:43
Message-ID: 1175620723.894018.23059.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 650039 by ervin:
Nice it all fits together now. Mount devices on demand using Solid.
M +25 -1 kfileplacesmodel.cpp
M +4 -0 kfileplacesmodel.h
M +22 -4 kfileplacesview.cpp
--- trunk/KDE/kdelibs/kfile/kfileplacesmodel.cpp #650038:650039
@@ -62,7 +62,7 @@
d->bookmarkManager = KBookmarkManager::managerForFile(file, "dolphin", false);
- d->deviceModel = new KDeviceListModel("IS Volume", this);
+ d->deviceModel = new KDeviceListModel("[ Volume.ignored == false AND \
Volume.usage == 'FileSystem' ]", this);
connect(d->deviceModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
this, SLOT(_k_devicesInserted(const QModelIndex&, int, int)));
@@ -99,6 +99,30 @@
return data(index, Qt::DisplayRole).toString();
}
+bool KFilePlacesModel::isDevice(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return false;
+
+ KFilePlacesItem *item = static_cast<KFilePlacesItem*>(index.internalPointer());
+
+ return item->isDevice();
+}
+
+Solid::Device KFilePlacesModel::deviceForIndex(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return Solid::Device();
+
+ KFilePlacesItem *item = static_cast<KFilePlacesItem*>(index.internalPointer());
+
+ if (item->isDevice()) {
+ return d->deviceModel->deviceForIndex(item->deviceIndex());
+ } else {
+ return Solid::Device();
+ }
+}
+
QVariant KFilePlacesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
--- trunk/KDE/kdelibs/kfile/kfileplacesmodel.h #650038:650039
@@ -26,6 +26,8 @@
#include <kurl.h>
#include <kicon.h>
+#include <solid/device.h>
+
/**
* This class is a list view model. Each entry represents a "place"
* where user can access files. Only revelant when
@@ -48,6 +50,8 @@
bool mountNeeded(const QModelIndex &index) const;
KIcon icon(const QModelIndex &index) const;
QString text(const QModelIndex &index) const;
+ bool isDevice(const QModelIndex &index) const;
+ Solid::Device deviceForIndex(const QModelIndex &index) const;
/**
* @brief Get a visible data based on Qt role for the given index.
--- trunk/KDE/kdelibs/kfile/kfileplacesview.cpp #650038:650039
@@ -19,7 +19,8 @@
#include "kfileplacesview.h"
-#include <kdebug.h>
+#include <kjob.h>
+#include <solid/volume.h>
#include "kfileplacesmodel.h"
@@ -30,6 +31,8 @@
KFilePlacesView * const q;
+ KUrl currentUrl;
+
void _k_placeClicked(const QModelIndex &index);
};
@@ -47,7 +50,6 @@
void KFilePlacesView::setUrl(const KUrl &url)
{
- kDebug() << k_funcinfo << endl;
KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel*>(model());
if (placesModel==0) return;
@@ -55,20 +57,36 @@
QModelIndex index = placesModel->closestItem(url);
if (index.isValid()) {
+ d->currentUrl = url;
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
} else {
+ d->currentUrl = KUrl();
selectionModel()->clear();
}
}
void KFilePlacesView::Private::_k_placeClicked(const QModelIndex &index)
{
- kDebug() << k_funcinfo << endl;
KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel*>(q->model());
if (placesModel==0) return;
- emit q->urlChanged(placesModel->url(index));
+ if (placesModel->isDevice(index)) {
+ Solid::Device device = placesModel->deviceForIndex(index);
+ if (device.is<Solid::Volume>() && !device.as<Solid::Volume>()->isMounted()) \
{ + KJob *job = device.as<Solid::Volume>()->mount();
+ job->exec(); // FIXME: Do this asynchronously
+ }
+ }
+
+ KUrl url = placesModel->url(index);
+
+ if (url.isValid()) {
+ currentUrl = url;
+ emit q->urlChanged(url);
+ } else {
+ q->setUrl(currentUrl);
+ }
}
#include "kfileplacesview.moc"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic