--- kdebase-3.5.4/kioslave/media/mediamanager/halbackend.cpp.bz469723-halbackend 2006-07-22 10:15:45.000000000 +0200 +++ kdebase-3.5.4/kioslave/media/mediamanager/halbackend.cpp 2008-12-09 17:44:52.000000000 +0100 @@ -43,8 +43,11 @@ { char* _ppt_string; QString _ppt_QString; - _ppt_string = libhal_device_get_property_string(ctx, udi, key, NULL); - _ppt_QString = QString(_ppt_string ? _ppt_string : ""); + DBusError error; + dbus_error_init(&error); + _ppt_string = libhal_device_get_property_string(ctx, udi, key, &error); + if ( _ppt_string ) + _ppt_QString = _ppt_string; libhal_free_string(_ppt_string); return _ppt_QString; } @@ -214,10 +217,7 @@ /* Query drive udi */ QString driveUdi = libhal_device_get_property_QString(m_halContext, udi, "block.storage_device"); - /* We don't list floppy volumes because we list floppy drives */ - if ((libhal_device_get_property_QString(m_halContext, driveUdi.ascii(), "storage.drive_type") == "floppy") || - (libhal_device_get_property_QString(m_halContext, driveUdi.ascii(), "storage.drive_type") == "zip") || - (libhal_device_get_property_QString(m_halContext, driveUdi.ascii(), "storage.drive_type") == "jaz")) + if ( driveUdi.isNull() ) // no storage - no fun return; // if the device is locked do not act upon it @@ -252,10 +252,16 @@ (libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "zip") || (libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "jaz")) { + if (!libhal_device_get_property_bool(m_halContext, udi, "storage.removable.media_available", NULL) ) { + allowNotification = false; + } /* Create medium */ Medium* medium = new Medium(udi, ""); - setFloppyProperties(medium); - m_mediaList.addMedium(medium, allowNotification); + // if the storage has a volume, we ignore it + if ( setFloppyProperties(medium) ) + m_mediaList.addMedium(medium, allowNotification); + else + delete medium; return; } @@ -282,11 +288,13 @@ void HALBackend::ModifyDevice(const char *udi, const char* key) { - Q_UNUSED(key); const char* mediumUdi = findMediumUdiFromUdi(udi); if (!mediumUdi) return; - ResetProperties(mediumUdi); + bool allowNotification = false; + if (strcmp(key, "storage.removable.media_available") == 0) + allowNotification = libhal_device_get_property_bool(m_halContext, udi, key, NULL); + ResetProperties(mediumUdi, allowNotification); } void HALBackend::DeviceCondition(const char* udi, const char* condition) @@ -366,7 +374,7 @@ return NULL; } -void HALBackend::ResetProperties(const char* mediumUdi) +void HALBackend::ResetProperties(const char* mediumUdi, bool allowNotification) { kdDebug(1219) << "HALBackend::setProperties" << endl; if ( QString::fromLatin1( mediumUdi ).startsWith( "/org/kde/" ) ) @@ -392,7 +400,7 @@ if (libhal_device_query_capability(m_halContext, mediumUdi, "camera", NULL)) setCameraProperties(m); - m_mediaList.changeMediumState(*m, false); + m_mediaList.changeMediumState(*m, allowNotification); delete m; } @@ -411,7 +419,9 @@ if (!halVolume) return; QString driveUdi = libhal_volume_get_storage_device_udi(halVolume); - LibHalDrive* halDrive = libhal_drive_from_udi(m_halContext, driveUdi.ascii()); + LibHalDrive* halDrive = 0; + if ( !driveUdi.isNull() ) + halDrive = libhal_drive_from_udi(m_halContext, driveUdi.ascii()); if (!halDrive) { // at times HAL sends an UnmountForced event before the device is removed libhal_volume_free(halVolume); @@ -586,44 +596,41 @@ } // Handle floppies and zip drives -void HALBackend::setFloppyProperties(Medium* medium) +bool HALBackend::setFloppyProperties(Medium* medium) { kdDebug(1219) << "HALBackend::setFloppyProperties for " << medium->id() << endl; const char* udi = medium->id().ascii(); /* Check if the device still exists */ if (!libhal_device_exists(m_halContext, udi, NULL)) - return; + return false; LibHalDrive* halDrive = libhal_drive_from_udi(m_halContext, udi); if (!halDrive) - return; - int numVolumes; - char** volumes = libhal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes); - LibHalVolume* halVolume = NULL; - kdDebug(1219) << " found " << numVolumes << " volumes" << endl; - if (numVolumes) - halVolume = libhal_volume_from_udi(m_halContext, volumes[0]); + return false; + + QString drive_type = libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type"); + + if (drive_type == "zip") { + int numVolumes; + char** volumes = libhal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes); + libhal_free_string_array(volumes); + kdDebug(1219) << " found " << numVolumes << " volumes" << endl; + if (numVolumes) + { + libhal_drive_free(halDrive); + return false; + } + } medium->setName( generateName(libhal_drive_get_device_file(halDrive)) ); - if (halVolume) - { - medium->mountableState( - libhal_volume_get_device_file(halVolume), /* Device node */ - libhal_volume_get_mount_point(halVolume), /* Mount point */ - libhal_volume_get_fstype(halVolume), /* Filesystem type */ - libhal_volume_is_mounted(halVolume) ); /* Mounted ? */ - } - else - { - // HAL hates floppies - so we have to do it twice ;( - medium->mountableState(libhal_drive_get_device_file(halDrive), QString::null, QString::null, false); - setFstabProperties( medium ); - } + // HAL hates floppies - so we have to do it twice ;( + medium->mountableState(libhal_drive_get_device_file(halDrive), QString::null, QString::null, false); + setFloppyMountState(medium); - if (libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "floppy") + if (drive_type == "floppy") { if (medium->isMounted()) // don't use _SUFFIX here as it accesses the volume medium->setMimeType("media/floppy_mounted" ); @@ -631,7 +638,7 @@ medium->setMimeType("media/floppy_unmounted"); } - if (libhal_device_get_property_QString(m_halContext, udi, "storage.drive_type") == "zip") + else if (drive_type == "zip") { if (medium->isMounted()) medium->setMimeType("media/zip_mounted" ); @@ -643,16 +650,32 @@ medium->setIconName(QString::null); - char *name = libhal_drive_policy_compute_display_name(halDrive, halVolume, m_halStoragePolicy); + libhal_drive_free(halDrive); - if (name) { - medium->setLabel( QString::fromUtf8(name) ); - free(name); - } + return true; +} - free(volumes); - libhal_drive_free(halDrive); - libhal_volume_free(halVolume); +void HALBackend::setFloppyMountState( Medium *medium ) +{ + if ( !medium->id().startsWith( "/org/kde" ) ) + { + KMountPoint::List mtab = KMountPoint::currentMountPoints(); + KMountPoint::List::iterator it = mtab.begin(); + KMountPoint::List::iterator end = mtab.end(); + + QString fstype; + QString mountpoint; + for (; it!=end; ++it) + { + if ((*it)->mountedFrom() == medium->deviceNode() ) + { + fstype = (*it)->mountType().isNull() ? (*it)->mountType() : "auto"; + mountpoint = (*it)->mountPoint(); + medium->mountableState( medium->deviceNode(), mountpoint, fstype, true ); + return; + } + } + } } void HALBackend::setCameraProperties(Medium* medium) @@ -764,10 +787,11 @@ if (fstype.isNull()) fstype = libhal_device_get_property_QString(m_halContext, name.latin1(), "volume.policy.mount_filesystem"); - QString drive_udi = libhal_device_get_property_QString(m_halContext, name.latin1(), "block.storage_device"); - bool removable = libhal_device_get_property_bool(m_halContext, drive_udi.latin1(), "storage.removable", NULL) + bool removable = false; + if ( !drive_udi.isNull() ) + removable = libhal_device_get_property_bool(m_halContext, drive_udi.latin1(), "storage.removable", NULL) || libhal_device_get_property_bool(m_halContext, drive_udi.latin1(), "storage.hotpluggable", NULL); config.setGroup(drive_udi); --- kdebase-3.5.4/kioslave/media/mediamanager/halbackend.h.bz469723-halbackend 2008-12-09 17:43:01.000000000 +0100 +++ kdebase-3.5.4/kioslave/media/mediamanager/halbackend.h 2008-12-09 17:43:01.000000000 +0100 @@ -138,7 +138,7 @@ /** * Reset properties for the given medium */ - void ResetProperties(const char* MediumUdi); + void ResetProperties(const char* MediumUdi, bool allowNotification=false); /** * Find the medium that is concerned with device udi @@ -146,7 +146,8 @@ const char* findMediumUdiFromUdi(const char* udi); void setVolumeProperties(Medium* medium); - void setFloppyProperties(Medium* medium); + bool setFloppyProperties(Medium* medium); + void setFloppyMountState( Medium* medium ); bool setFstabProperties(Medium* medium); void setCameraProperties(Medium* medium); QString generateName(const QString &devNode);