From kde-core-devel Mon Sep 14 15:35:34 2009 From: David Faure Date: Mon, 14 Sep 2009 15:35:34 +0000 To: kde-core-devel Subject: Re: Mountable devices support in KDE Message-Id: <200909141735.34987.faure () kde ! org> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=125294259805956 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_GLmrKY4NUKrn4cL" --Boundary-00=_GLmrKY4NUKrn4cL Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Monday 14 September 2009, Rafa=C5=82 Mi=C5=82ecki wrote: > 2009/9/8 Kevin Ottens : > >> Is such a url trick acceptable to be commited to KDE (libkonq)? > > > > I've no say in that. More something to discuss with David. >=20 > Can sb else comment on this, please? David doesn't seem to read this ML. =20 Hey, how would I have posted 5889 emails to kde-core-devel since 1999 if I= =20 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=20 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 pa= th for which to show the popupmenu? "All" we need to do is to show mount/unmou= nt=20 for such paths, and that seems easy to do: just modify=20 KDesktopFileActions::builtinServices (in kio) so that it calls=20 KMountPoint::currentMountPoints().findByDevice(_url.path()) when _url is a= =20 device path rather than a .desktop file. Something like the attached patch= =20 (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=20 mountable device? Via Solid maybe? Kevin? ;) =2D-=20 David Faure, faure@kde.org, sponsored by Nokia to work on KDE, Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org). --Boundary-00=_GLmrKY4NUKrn4cL Content-Type: text/x-patch; charset="UTF-8"; name="deviceforurl.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="deviceforurl.diff" 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 KDesktopFileActions::builtinServices( const KUrl& _url ) { QList 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); } } --Boundary-00=_GLmrKY4NUKrn4cL--