A Dimecres, 23 de setembre de 2009, Rafał Miłecki va escriure:
> Hi again,
> 
> I can not understand why kio_sysinfo gets outdated data from
> Solid::Device::listFromQuery.
> 
> How to reproduce:
> 1) Plug in some pendrive
> 2) Run "konqeuror sysinfo:/"
> 3) Mount pendrive using for ex. DeviceNotifier
> 4) Refresh sysinfo:/ page in Konqueror
> 
> The problem is that
> bool kio_sysinfoProtocol::fillMediaDevices()
> still gets info that pendrive is not mounted.
> 
> The same problem happens in second order:
> 1) Plug in pendrive
> 2) Mount it using for ex. DeviceNotifier
> 3) Run "konqeuror sysinfo:/"
> 4) Unmount pendirve using for ex. DeviceNotifier
> 5) Refresh sysinfo:/ page in Konqueror
> 
> Again bool kio_sysinfoProtocol::fillMediaDevices() gets info that
> pendrive is mounted and it even gets it's old mount point.
> 
> Could someone explain this to me, please?
> 
> Source:
> http://websvn.kde.org/trunk/playground/base/kio_sysinfo/src/
> 
> You may want to put:
> kDebug() << "[DBG]" << di.deviceNode << ": isAccesible:" <<
> access->isAccessible() << " ; filePath:" << access->filePath();
> in bool kio_sysinfoProtocol::fillMediaDevices()
> 

Yes, the solid hal backend has a cache of hal returned information via dbus, 
this cache is invalidated when hal sends a specific signal via dbus, the 
problem is that qdbus does not work in kio slaves because it needs an event 
loop and kio slaves don't have one.

Talking with dfaure it seems there are three solutions:
 * Add a thread with an event loop to the sysinfo slave and do the solid calls 
there and somehow pass the info 
 * Tell solid not to cache the information

I've tried to prepare a cude hack based on the first and seems to work for me, 
can you try the following patch?

Albert
Index: src/sysinfo.h
===================================================================
--- src/sysinfo.h	(revision 1027318)
+++ src/sysinfo.h	(working copy)
@@ -143,7 +143,6 @@
     QMap<int, QString> m_info;
 
     QList<DiskInfo> m_devices;
-    Solid::Predicate m_predicate;
 };
 
 #endif
Index: src/sysinfo.cpp
===================================================================
--- src/sysinfo.cpp	(revision 1027318)
+++ src/sysinfo.cpp	(working copy)
@@ -149,7 +149,6 @@
 kio_sysinfoProtocol::kio_sysinfoProtocol( const QByteArray & pool_socket, const QByteArray & app_socket )
     : SlaveBase( "kio_sysinfo", pool_socket, app_socket )
 {
-    m_predicate = Solid::Predicate::fromString(SOLID_MEDIALIST_PREDICATE);
 }
 
 kio_sysinfoProtocol::~kio_sysinfoProtocol()
@@ -673,6 +672,7 @@
 {
     KComponentData componentData( "kio_sysinfo" );
     ( void ) KGlobal::locale();
+    QCoreApplication app(argc, argv);
 
     kDebug(1242) << "*** Starting kio_sysinfo ";
 
@@ -688,64 +688,85 @@
     return 0;
 }
 
-bool kio_sysinfoProtocol::fillMediaDevices()
+#include <QThread>
+class FooThread : public QThread
 {
-    QStringList devices;
+    public:
+        FooThread()
+        {
+        }
+        
+        void run()
+        {
+            QEventLoop e;
+            while (e.processEvents()) {}
+            
+            const QList<Solid::Device> &deviceList = Solid::Device::listFromQuery(Solid::Predicate::fromString(SOLID_MEDIALIST_PREDICATE));
+            
+            if (deviceList.isEmpty())
+            {
+                kDebug(1242) << "DEVICE LIST IS EMPTY!";
+                return;
+            }
+            
+            Q_FOREACH (const Solid::Device &device, deviceList)
+            {
+                if (!device.isValid())
+                    continue;
 
-    const QList<Solid::Device> &deviceList = Solid::Device::listFromQuery(m_predicate);
+                const Solid::StorageAccess *access = device.as<Solid::StorageAccess>();
+                const Solid::StorageVolume *volume = device.as<Solid::StorageVolume>();
+                const Solid::Block *block = device.as<Solid::Block>();
+                const Solid::StorageDrive *drive = device.parent().as<Solid::StorageDrive>();
 
-    if (deviceList.isEmpty())
-    {
-        kDebug(1242) << "DEVICE LIST IS EMPTY!";
-        return false;
-    }
+                DiskInfo di;
 
-    m_devices.clear();
+                di.id = device.udi();
+                if (block)
+                    di.deviceNode = block->device();
+                if (volume)
+                    di.fsType = volume->fsType();
+                di.mounted = access && access->isAccessible();
+                di.removable = (di.mounted || device.is<Solid::OpticalDisc>()) && drive && drive->isRemovable();
+                if ( di.mounted )
+                    di.mountPoint = access->filePath();
+                if (volume)
+                    di.label = volume->label();
+                if (di.label.isEmpty())
+                    di.label = di.mountPoint;
+                //FIXME: pick up some label for unmounted and not labeled devices
+                di.iconName = device.icon();
 
-    Q_FOREACH (const Solid::Device &device, deviceList)
-    {
-        if (!device.isValid())
-            continue;
+                di.total = di.avail = 0;
 
-        const Solid::StorageAccess *access = device.as<Solid::StorageAccess>();
-        const Solid::StorageVolume *volume = device.as<Solid::StorageVolume>();
-        const Solid::Block *block = device.as<Solid::Block>();
-        const Solid::StorageDrive *drive = device.parent().as<Solid::StorageDrive>();
+                if (volume)
+                    di.total = volume->size();
 
-        DiskInfo di;
+                // calc the free/total space
+                struct statfs sfs;
+                if ( di.mounted && statfs( QFile::encodeName( di.mountPoint ), &sfs ) == 0 )
+                {
+                    di.total = ( unsigned long long )sfs.f_blocks * sfs.f_bsize;
+                    di.avail = ( unsigned long long )( getuid() ? sfs.f_bavail : sfs.f_bfree ) * sfs.f_bsize;
+                }
 
-        di.id = device.udi();
-        if (block)
-            di.deviceNode = block->device();
-        if (volume)
-            di.fsType = volume->fsType();
-        di.mounted = access && access->isAccessible();
-        di.removable = (di.mounted || device.is<Solid::OpticalDisc>()) && drive && drive->isRemovable();
-        if ( di.mounted )
-            di.mountPoint = access->filePath();
-        if (volume)
-            di.label = volume->label();
-        if (di.label.isEmpty())
-            di.label = di.mountPoint;
-        //FIXME: pick up some label for unmounted and not labeled devices
-        di.iconName = device.icon();
+                m_devices.append( di );
+            }
+            exit();
+        }
+        
+        QList<DiskInfo> m_devices;
+};
 
-        di.total = di.avail = 0;
+bool kio_sysinfoProtocol::fillMediaDevices()
+{
+    FooThread *tf = new FooThread();
+    tf->run();
+    tf->wait();
+    m_devices = tf->m_devices;
+    delete tf;
 
-        if (volume)
-            di.total = volume->size();
 
-        // calc the free/total space
-        struct statfs sfs;
-        if ( di.mounted && statfs( QFile::encodeName( di.mountPoint ), &sfs ) == 0 )
-        {
-            di.total = ( unsigned long long )sfs.f_blocks * sfs.f_bsize;
-            di.avail = ( unsigned long long )( getuid() ? sfs.f_bavail : sfs.f_bfree ) * sfs.f_bsize;
-        }
-
-        m_devices.append( di );
-    }
-
     // this is ugly workaround, should be in HAL but there is no LVM support
     QRegExp rxlvm("^/dev/mapper/\\S*-\\S*");
 
_______________________________________________
Kde-hardware-devel mailing list
Kde-hardware-devel@kde.org
https://mail.kde.org/mailman/listinfo/kde-hardware-devel

Reply via email to