[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Mountable devices support in KDE
From: David Faure <faure () kde ! org>
Date: 2009-09-14 15:35:34
Message-ID: 200909141735.34987.faure () kde ! org
[Download RAW message or body]
On Monday 14 September 2009, Rafał Miłecki wrote:
> 2009/9/8 Kevin Ottens <ervin@kde.org>:
> >> Is such a url trick acceptable to be commited to KDE (libkonq)?
> >
> > I've no say in that. More something to discuss with David.
>
> Can sb else comment on this, please? David doesn't seem to read this ML.
Hey, how would I have posted 5889 emails to kde-core-devel since 1999 if I
wasn't subscribed to it? :-)
(statistics from kde.markmail.org)
You just have to be a bit patient; business travel and heaps of KDE email
everywhere don't make it easy to answer everything the same week.
Anyway, back to the topic.
IIRC Solid has a way to find the device from the device name like /dev/sdb1,
so instead of a kioslave-specific hack, how about using /dev/sdb1 as the path
for which to show the popupmenu? "All" we need to do is to show mount/unmount
for such paths, and that seems easy to do: just modify
KDesktopFileActions::builtinServices (in kio) so that it calls
KMountPoint::currentMountPoints().findByDevice(_url.path()) when _url is a
device path rather than a .desktop file. Something like the attached patch
(untested).
Ah, but we can only recognize /dev/sdb1 if it's already mounted; otherwise
(if it's not mounted and it's not in fstab), how can we find out it's a
mountable device? Via Solid maybe? Kevin? ;)
--
David Faure, faure@kde.org, sponsored by Nokia to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
["deviceforurl.diff" (text/x-patch)]
Index: kdesktopfileactions.cpp
===================================================================
--- kdesktopfileactions.cpp (revision 1021255)
+++ kdesktopfileactions.cpp (working copy)
@@ -139,6 +139,33 @@
return false;
}
+static QString deviceForUrl(const KUrl& url, QString* error)
+{
+ if (url.isLocalFile()) {
+ const QString path = url.toLocalFile();
+ if (KDesktopFile::isDesktopFile(path)) {
+ KDesktopFile cfg(path);
+ if (cfg.hasDeviceType()) {
+ const QString dev = cfg.readDevice();
+ if (dev.isEmpty()) {
+ *error = i18n("The desktop entry file\n%1\nis of type FSDevice \
but has no Dev=... entry.", path); + } else {
+ return dev;
+ }
+ }
+ } else {
+ // Maybe @p url is a device path like /dev/sda1?
+ // TODO: this ignores unmounted devices (that are not in fstab)
+ // --> use Solid instead?
+ KMountPoint::Ptr mp = \
KMountPoint::currentMountPoints().findByDevice(path); + if (mp) {
+ return path;
+ }
+ }
+ }
+ return QString();
+}
+
QList<KServiceAction> KDesktopFileActions::builtinServices( const KUrl& _url )
{
QList<KServiceAction> result;
@@ -146,38 +173,32 @@
if ( !_url.isLocalFile() )
return result;
- KDesktopFile cfg( _url.toLocalFile() );
- QString type = cfg.readType();
-
- if ( type.isEmpty() )
- return result;
-
- if ( cfg.hasDeviceType() ) {
- const QString dev = cfg.readDevice();
- if ( dev.isEmpty() ) {
- QString tmp = i18n("The desktop entry file\n%1\nis of type FSDevice but \
has no Dev=... entry.", _url.toLocalFile() );
- KMessageBoxWrapper::error(0, tmp);
+ QString error;
+ const QString dev = deviceForUrl(_url, &error);
+ if ( dev.isEmpty() ) {
+ if (!error.isEmpty()) {
+ KMessageBoxWrapper::error(0, error);
+ }
+ } else {
+ KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByDevice( dev );
+ // not mounted ?
+ if (!mp) {
+ KServiceAction mount("mount", i18n("Mount"), QString(), QString(), \
false); + mount.setData(QVariant(ST_MOUNT));
+ result.append(mount);
} else {
- KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByDevice( \
dev );
- // not mounted ?
- if ( !mp ) {
- KServiceAction mount("mount", i18n("Mount"), QString(), QString(), \
false);
- mount.setData(QVariant(ST_MOUNT));
- result.append(mount);
- } else {
- QString text;
+ QString text;
#ifdef HAVE_VOLMGT
- /*
- * Solaris' volume management can only umount+eject
- */
- text = i18n("Eject");
+ /*
+ * Solaris' volume management can only umount+eject
+ */
+ text = i18n("Eject");
#else
- text = i18n("Unmount");
+ text = i18n("Unmount");
#endif
- KServiceAction unmount("unmount", text, QString(), QString(), \
false);
- unmount.setData(QVariant(ST_UNMOUNT));
- result.append(unmount);
- }
+ KServiceAction unmount("unmount", text, QString(), QString(), false);
+ unmount.setData(QVariant(ST_UNMOUNT));
+ result.append(unmount);
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic