File hotplug-kde3.diff of Package kdebase4-workspace
Subject: Hotplug support for KDE3 applications
From: Lubos Lunak
Feature: bnc#378338
Patch-upstream: never
Relates: kdebase4-runtime/hotplug-kde3.diff, kdelibs4/hotplug-kde3.diff
--- plasma/applets/devicenotifier/devicenotifier.cpp 2008/05/26 22:47:23 1.9
+++ plasma/applets/devicenotifier/devicenotifier.cpp 2008/05/26 22:50:21
@@ -263,7 +263,7 @@
int nb_actions = 0;
QString last_action_label;
foreach (QString desktop, data["predicateFiles"].toStringList()) {
- QString filePath = KStandardDirs::locate("data", "solid/actions/" + desktop);
+ QString filePath = desktop.startsWith('/')?desktop:KStandardDirs::locate("data", "solid/actions/"+desktop);
QList<KServiceAction> services = KDesktopFileActions::userDefinedServices(filePath, true);
nb_actions += services.size();
if (services.size() > 0) {
--- ./plasma/dataengines/hotplug/hotplugengine.cpp.sav 2008-05-09 09:50:50.000000000 +0200
+++ ./plasma/dataengines/hotplug/hotplugengine.cpp 2008-05-14 15:09:14.000000000 +0200
@@ -24,13 +24,18 @@
#include <KLocale>
#include <KStandardDirs>
#include <KDesktopFile>
+#include <QDir>
#include "plasma/datacontainer.h"
//solid specific includes
+#include <solid/camera.h>
#include <solid/devicenotifier.h>
#include <solid/device.h>
#include <solid/deviceinterface.h>
+#include <solid/opticaldisc.h>
#include <solid/predicate.h>
+#include <solid/storageaccess.h>
+#include <solid/storagedrive.h>
@@ -43,6 +48,7 @@ HotplugEngine::HotplugEngine(QObject* pa
connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(const QString &)),
this, SLOT(onDeviceRemoved(const QString &)));
files = KGlobal::dirs()->findAllResources("data", "solid/actions/");
+ kde3files = findKde3Files();
//kDebug() <<files.size();
new_device=false;
}
@@ -68,6 +74,19 @@ void HotplugEngine::onDeviceAdded(const
interestingDesktopFiles<<KUrl(path).fileName();
}
}
+ // search KDE3 actions too, they are compatible except for finding if they match the device
+ QString kde3Type = kde3DeviceType( device );
+ if( !kde3Type.isEmpty()) {
+ foreach( const QString& path, kde3files ) {
+ KDesktopFile cfg( path );
+ if( cfg.desktopGroup().readEntry( "X-KDE-MediaNotifierHide", false ))
+ continue;
+ if( cfg.desktopGroup().readEntry( "ServiceTypes", QStringList()).contains( kde3Type )) {
+ new_device = true;
+ interestingDesktopFiles<< path; // use full path, devicesnotifier later tries KStandardDirs again
+ }
+ }
+ }
if (new_device) {
//kDebug()<<device.product();
@@ -101,4 +120,81 @@ void HotplugEngine::onDeviceRemoved(cons
checkForUpdates();
}
+QStringList HotplugEngine::findKde3Files()
+{
+ QStringList dirs = QStringList() << "/opt/kde3" << "/etc/opt/kde3" << ( qgetenv( "HOME" ) + "/.kde" );
+ QStringList ret;
+ foreach( const QString& d, dirs ) {
+ QString dir = d + "/share/apps/konqueror/servicemenus/";
+ foreach( const QString& file, QDir( dir ).entryList( QStringList() << "*.desktop", QDir::Files )) {
+ ret.append( dir + file );
+ }
+ }
+ return ret;
+}
+
+QString HotplugEngine::kde3DeviceType( const Solid::Device& device )
+{ // based on HALBackend::setVolumeProperties() from KDE3's mediamanager
+ const Solid::StorageAccess* storage = device.as< const Solid::StorageAccess >();
+ if( storage == NULL )
+ return "";
+#define MOUNT_SUFFIX ( storage->isAccessible() ? QString( "_mounted" ) : QString( "_unmounted" ))
+ QString type;
+ if( const Solid::OpticalDisc* disc = device.as< const Solid::OpticalDisc >()) {
+ type = "media/cdrom" + MOUNT_SUFFIX;
+ if( disc->discType() == Solid::OpticalDisc::CdRom
+ || disc->discType() == Solid::OpticalDisc::CdRecordable
+ || disc->discType() == Solid::OpticalDisc::CdRewritable ) {
+ if( disc->isBlank())
+ type = "media/blankcd";
+ else
+ type = "media/cdwriter" + MOUNT_SUFFIX;
+ }
+ if( disc->discType() == Solid::OpticalDisc::DvdRom
+ || disc->discType() == Solid::OpticalDisc::DvdRam
+ || disc->discType() == Solid::OpticalDisc::DvdRecordable
+ || disc->discType() == Solid::OpticalDisc::DvdRewritable
+ || disc->discType() == Solid::OpticalDisc::DvdPlusRecordable
+ || disc->discType() == Solid::OpticalDisc::DvdPlusRewritable
+ // these two are not in KDE3, but I guess they belong here too
+ || disc->discType() == Solid::OpticalDisc::DvdPlusRewritableDuallayer
+ || disc->discType() == Solid::OpticalDisc::DvdPlusRewritableDuallayer ) {
+ if( disc->isBlank())
+ type = "media/blankdvd";
+ else
+ type = "media/dvd" + MOUNT_SUFFIX;
+ }
+ if(( disc->availableContent() & Solid::OpticalDisc::Audio )
+ && !( disc->availableContent() & Solid::OpticalDisc::Data )) {
+ type = "media/audiocd";
+ }
+ if( disc->availableContent() & Solid::OpticalDisc::VideoCd )
+ type = "media/vcd";
+ if( disc->availableContent() & Solid::OpticalDisc::SuperVideoCd )
+ type = "media/svcd";
+ if( disc->availableContent() & Solid::OpticalDisc::VideoDvd )
+ type = "media/dvdvideo";
+ } else if( const Solid::StorageDrive* drive = device.as< const Solid::StorageDrive >()) {
+ type = "media/hdd" + MOUNT_SUFFIX;
+ if( drive->isHotpluggable())
+ type = "media/removable" + MOUNT_SUFFIX;
+ } else if( device.as< const Solid::StorageVolume >()) {
+ Solid::Device parent = device.parent();
+ if( parent.isValid()) {
+ // duplicated from above
+ if( const Solid::StorageDrive* drive = parent.as< const Solid::StorageDrive >()) {
+ type = "media/hdd" + MOUNT_SUFFIX;
+ if( drive->isHotpluggable())
+ type = "media/removable" + MOUNT_SUFFIX;
+ }
+ }
+ if( device.as< const Solid::Camera >())
+ type = "media/camera" + MOUNT_SUFFIX;
+ if( storage->isAccessible() && QFile::exists( storage->filePath() + "/dcim" ))
+ type = "media/camera" + MOUNT_SUFFIX;
+ }
+#undef MOUNT_SUFFIX
+ return type;
+}
+
#include "hotplugengine.moc"
--- ./plasma/dataengines/hotplug/hotplugengine.h.sav 2008-05-09 09:50:50.000000000 +0200
+++ ./plasma/dataengines/hotplug/hotplugengine.h 2008-05-14 15:08:55.000000000 +0200
@@ -27,6 +27,11 @@
#include "plasma/dataengine.h"
+namespace Solid
+{
+class Device;
+}
+
/**
* This class is connected with solid, filter devices and provide signal with source for applet in Plasma
*/
@@ -41,7 +46,9 @@ class HotplugEngine : public Plasma::Dat
void onDeviceAdded(const QString &udi);
void onDeviceRemoved(const QString &udi);
private :
- QStringList files;
+ static QStringList findKde3Files();
+ static QString kde3DeviceType( const Solid::Device& device );
+ QStringList files, kde3files;
bool new_device;
};