--- kdebase-3.5.4_orig/kioslave/media/libmediacommon/notifieraction.cpp	2005-10-10 17:04:00.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/libmediacommon/notifieraction.cpp	2006-09-11 00:28:39.000000000 +0200
@@ -23,6 +23,9 @@
 #include <kglobal.h>
 #include <kiconloader.h>
 #include <kicontheme.h>
+#include <dcopobject.h>
+#include <dcopref.h>
+#include <dcopclient.h>
 
 NotifierAction::NotifierAction()
 {
@@ -95,3 +98,97 @@
 	return true;
 }
 
+KURL NotifierAction::ensureMediumMounted(const QString &devNodeName, bool &ok)
+{
+	ok = false;
+
+	// We get the mount/media information from the KDE mediamanager, the
+	// same way as what the media:/ ioslave does.
+	DCOPRef mediamanager("kded", "mediamanager");
+	DCOPReply reply = mediamanager.call( "fullList" );
+	if ( !reply.isValid() )
+	{
+		return KURL();
+	}
+
+	Medium::List mediumList = Medium::createList(reply);
+	Medium::List::iterator it = mediumList.begin();
+	Medium::List::iterator end = mediumList.end();
+        
+	Medium thisMedium(QString::null,QString::null);
+
+	for(; it!=end; ++it)
+	{
+		if( (*it).name()==devNodeName)
+		{
+			thisMedium = *it;
+			break;
+		}
+	}
+	if( it==end)
+	{
+		// Couldn't find the medium entry. Sorry.
+		return KURL();
+	}
+
+	// Try mounting this medium.
+	if ( thisMedium.needMounting() )
+	{
+		m_lastErrorCode = 0;
+
+		DCOPRef mediamanager("kded", "mediamanager");
+		DCOPReply reply = mediamanager.call( "mount", thisMedium.id());
+		if (reply.isValid())
+		{
+			reply.get(m_lastErrorMessage);
+		}
+		else
+		{
+			m_lastErrorMessage = i18n("Internal Error");
+		}
+
+		if (!m_lastErrorMessage.isEmpty())
+		{
+			m_lastErrorCode = KIO::ERR_SLAVE_DEFINED;
+		}
+
+		bool ok;
+		thisMedium = findMediumByName(thisMedium.name(), ok);
+		if ( m_lastErrorCode!=0 )
+		{
+			return KURL(); // failed
+		}
+	}
+
+	KURL thisUrl;
+	if(thisMedium.mountPoint()!=QString::null)
+	{
+		thisUrl = KURL(thisMedium.mountPoint());
+	}
+	else
+	{
+		thisUrl = KURL(thisMedium.baseURL());
+	}
+
+	ok = true;
+	return thisUrl;
+}
+
+const Medium NotifierAction::findMediumByName(const QString &name, bool &ok)
+{
+	DCOPRef mediamanager("kded", "mediamanager");
+	DCOPReply reply = mediamanager.call( "properties", name );
+
+	if ( reply.isValid() )
+	{
+		ok = true;
+	}
+	else
+	{
+		m_lastErrorCode = KIO::ERR_SLAVE_DEFINED;
+		m_lastErrorMessage = i18n("The KDE mediamanager is not running.");
+		ok = false;
+	}
+
+	return Medium::create(reply);
+}
--- kdebase-3.5.4_orig/kioslave/media/libmediacommon/notifieraction.h	2005-10-10 17:04:00.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/libmediacommon/notifieraction.h	2006-09-11 00:28:39.000000000 +0200
@@ -23,6 +23,7 @@
 #include <kfileitem.h>
 #include <qstring.h>
 #include <qpixmap.h>
+#include "medium.h"
 
 class NotifierSettings;
 
@@ -46,6 +47,13 @@
 	virtual bool supportsMimetype( const QString &mimetype ) const;
 	virtual void execute( KFileItem &medium ) = 0;
 
+protected:
+	KURL ensureMediumMounted(const QString &devNodeName, bool &ok);
+	const Medium findMediumByName(const QString &name, bool &ok);
+
+	int m_lastErrorCode;
+	QString m_lastErrorMessage;
+
 private:
 	void addAutoMimetype( const QString &mimetype );
 	void removeAutoMimetype( const QString &mimetype );
@@ -54,6 +62,7 @@
 	QString m_iconName;
 	QStringList m_autoMimetypes;
 
+
 	friend class NotifierSettings;
 };
 
--- kdebase-3.5.4_orig/kioslave/media/libmediacommon/notifiernothingaction.cpp	2005-10-10 17:04:00.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/libmediacommon/notifiernothingaction.cpp	2006-09-11 00:28:39.000000000 +0200
@@ -33,7 +33,10 @@
 	return "#NothinAction";
 }
 
-void NotifierNothingAction::execute(KFileItem &/*medium*/)
+void NotifierNothingAction::execute(KFileItem &medium)
 {
+	// Quietly mount this medium.
+	bool ok;
+	ensureMediumMounted(medium.url().fileName(), ok);
 }
 
--- kdebase-3.5.4_orig/kioslave/media/libmediacommon/notifieropenaction.cpp	2005-11-08 23:36:07.000000000 +0100
+++ kdebase-3.5.4/kioslave/media/libmediacommon/notifieropenaction.cpp	2006-09-11 00:28:39.000000000 +0200
@@ -20,6 +20,7 @@
 #include "notifieropenaction.h"
 
 #include <klocale.h>
+#include <krun.h>
 
 NotifierOpenAction::NotifierOpenAction()
 	: NotifierAction()
@@ -35,11 +36,15 @@
 
 void NotifierOpenAction::execute(KFileItem &medium)
 {
-	medium.run();
+	bool ok;
+	KURL thisUrl = ensureMediumMounted(medium.url().fileName(), ok);
+	if ( ok )
+	{
+		new KRun(thisUrl);
+	}
 }
 
 bool NotifierOpenAction::supportsMimetype( const QString &mimetype ) const
 {
 	return !mimetype.contains( "blank" );
 }
-
--- kdebase-3.5.4_orig/kioslave/media/mediamanager/halbackend.cpp	2006-07-22 10:15:45.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/mediamanager/halbackend.cpp	2006-09-11 00:28:39.000000000 +0200
@@ -206,12 +206,12 @@
              !libhal_device_get_property_bool(m_halContext, udi, "volume.disc.has_audio", NULL) &&
              !libhal_device_get_property_bool(m_halContext, udi, "volume.disc.is_blank", NULL) )
             return;
-
+/* Don't hide these. --SBE
         if ( ( libhal_device_get_property_QString(m_halContext, udi, "volume.fsusage") == "filesystem" &&
                !libhal_device_get_property_bool(m_halContext, udi, "volume.is_mounted", NULL ) ) &&
              ( libhal_device_get_property_bool(m_halContext, udi, "volume.ignore", NULL ) ) )
             return;
-
+*/
         /* 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 */
@@ -421,12 +421,30 @@
     medium->setName(
         generateName(libhal_volume_get_device_file(halVolume)) );
 
+    const char *halMp = libhal_volume_get_mount_point(halVolume);
+
     medium->mountableState(
         libhal_volume_get_device_file(halVolume),		/* Device node */
-        libhal_volume_get_mount_point(halVolume),		/* Mount point */
+        halMp,		/* Mount point */
         libhal_volume_get_fstype(halVolume),			/* Filesystem type */
         libhal_volume_is_mounted(halVolume) );			/* Mounted ? */
 
+    // This is kind of workaround for the feature that HAL won't tell you nor
+    // recommend a mountpoint for anything that is not yet mounted. A hint
+    // would be nice. --SBE 
+    if(halMp==0)
+    {
+        QString newMp = getMountPointFromFstab(medium->deviceNode());
+
+        if (!newMp.isNull() )
+        {
+            medium->mountableState(medium->deviceNode(),/* Device node */
+                newMp,					/* Mount point */
+                medium->fsType(),		/* Filesystem type */
+                medium->isMounted());	/* Mounted ? */
+        }
+    }
+
     char* name = libhal_volume_policy_compute_display_name(halDrive, halVolume, m_halStoragePolicy);
     QString volume_name = QString::fromUtf8(name);
     QString media_name = volume_name;
@@ -985,6 +1003,7 @@
     for (; it!=end; ++it)
     {
         kdDebug() << "isInFstab -" << medium->deviceNode() << "- -" << (*it)->realDeviceName() << "- -" << (*it)->mountedFrom() << endl;
+
         if ((*it)->mountedFrom() == medium->deviceNode() || ( !medium->deviceNode().isEmpty() && (*it)->realDeviceName() == medium->deviceNode() ) )
 	{
             QStringList opts = (*it)->mountOptions();
@@ -996,6 +1015,24 @@
     return QString::null;
 }
 
+QString HALBackend::getMountPointFromFstab(const QString &deviceNode)
+{
+    KMountPoint::List fstab = KMountPoint::possibleMountPoints(KMountPoint::NeedRealDeviceName);
+
+    KMountPoint::List::iterator it = fstab.begin();
+    KMountPoint::List::iterator end = fstab.end();
+
+    for (; it!=end; ++it)
+    {
+        if ((*it)->mountedFrom() == deviceNode || ( !deviceNode.isEmpty() && (*it)->realDeviceName() == deviceNode ) )
+	{
+            return (*it)->mountPoint();
+        }
+    }
+
+    return QString::null;
+}
+
 QString HALBackend::mount(const Medium *medium)
 {
     if (medium->isMounted())
--- kdebase-3.5.4_orig/kioslave/media/mediamanager/halbackend.h	2006-07-22 10:15:45.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/mediamanager/halbackend.h	2006-09-11 00:28:39.000000000 +0200
@@ -151,7 +151,7 @@
 	void setCameraProperties(Medium* medium);
 	QString generateName(const QString &devNode);
 	static QString isInFstab(const Medium *medium);
-
+	static QString getMountPointFromFstab(const QString &deviceNode);
 private slots:
 	void slotResult(KIO::Job *job);
 
--- kdebase-3.5.4_orig/kioslave/media/mediamanager/mediamanager.cpp	2006-07-22 10:15:45.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/mediamanager/mediamanager.cpp	2006-09-25 08:23:12.000000000 +0200
@@ -43,6 +43,9 @@
 MediaManager::MediaManager(const QCString &obj)
     : KDEDModule(obj), m_dirNotify(m_mediaList)
 {
+//fprintf(stderr,"MediaManager::MediaManager()\n");
+//fflush(stderr);
+
     connect( &m_mediaList, SIGNAL(mediumAdded(const QString&, const QString&, bool)),
              SLOT(slotMediumAdded(const QString&, const QString&, bool)) );
     connect( &m_mediaList, SIGNAL(mediumRemoved(const QString&, const QString&, bool)),
@@ -52,6 +55,8 @@
              SLOT(slotMediumChanged(const QString&, const QString&, bool, bool)) );
 
     QTimer::singleShot( 10, this, SLOT( loadBackends() ) );
+//fprintf(stderr,"MediaManager::MediaManager() done\n");
+//fflush(stderr);
 }
 
 MediaManager::~MediaManager()
@@ -66,6 +71,8 @@
 
 void MediaManager::loadBackends()
 {
+//fprintf(stderr,"MediaManager::loadBackends()\n");
+//fflush(stderr);
     m_mediaList.blockSignals(true);
 
     while ( !m_backends.isEmpty() )
@@ -110,11 +117,15 @@
 
     m_backends.append( new FstabBackend(m_mediaList) );
     m_mediaList.blockSignals(false);
+//fprintf(stderr,"MediaManager::loadBackends() done\n");
+//fflush(stderr);
 }
 
 
 QStringList MediaManager::fullList()
 {
+//fprintf(stderr,"MediaManager::fullList()\n");
+//fflush(stderr);
     QPtrList<Medium> list = m_mediaList.list();
 
     QStringList result;
@@ -127,6 +138,8 @@
         result+= Medium::SEPARATOR;
     }
 
+//fprintf(stderr,"MediaManager::fullList() done\n");
+//fflush(stderr);
     return result;
 }
 
@@ -283,6 +296,8 @@
                                    bool allowNotification)
 {
     kdDebug(1219) << "MediaManager::slotMediumAdded: " << name << endl;
+//fprintf(stderr,"MediaManager::slotMediumAdded: %s\n",name.latin1());
+//fflush(stderr);
 
     KDirNotify_stub notifier("*", "*");
     notifier.FilesAdded( KURL("media:/") );
@@ -295,6 +310,8 @@
                                      bool allowNotification)
 {
     kdDebug(1219) << "MediaManager::slotMediumRemoved: " << name << endl;
+//fprintf(stderr,"MediaManager::slotMediumRemoved: %s\n",name.latin1());
+//fflush(stderr);
 
     KDirNotify_stub notifier("*", "*");
     notifier.FilesRemoved( KURL("media:/"+name) );
@@ -307,6 +324,8 @@
                                      bool mounted, bool allowNotification)
 {
     kdDebug(1219) << "MediaManager::slotMediumChanged: " << name << endl;
+//fprintf(stderr,"MediaManager::slotMediumChanged: %s\n",name.latin1());
+//fflush(stderr);
 
     KDirNotify_stub notifier("*", "*");
     if (!mounted)
@@ -314,7 +333,24 @@
         notifier.FilesRemoved( KURL("media:/"+name) );
     }
     notifier.FilesChanged( KURL("media:/"+name) );
+/*
+    const Medium *changeMedium = m_mediaList.findByName(name);
+    if ( changeMedium )
+    {
+fprintf(stderr,"MediaManager::slotMediumChanged: checkpoint 1\n");
+fflush(stderr);
+        // Notify that the mountpoint dir properties have changed.
+        if ( changeMedium->mountPoint()!=QString::null && changeMedium->mountPoint()!="")
+        {
+fprintf(stderr,"MediaManager::slotMediumChanged: checkpoint 2 %s\n",changeMedium->mountPoint().latin1());
+fflush(stderr);
 
+            notifier.FilesChanged( KURL(QString("file:/")+changeMedium->mountPoint()) );
+        } 
+    }
+fprintf(stderr,"MediaManager::slotMediumChanged: checkpoint 3\n");
+fflush(stderr);
+*/
     emit mediumChanged(name, allowNotification);
     emit mediumChanged(name);
 }
--- kdebase-3.5.4_orig/kioslave/media/medianotifier/medianotifier.cpp	2006-07-22 10:15:42.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/medianotifier/medianotifier.cpp	2006-09-25 08:22:05.000000000 +0200
@@ -21,6 +21,7 @@
 
 #include <qfile.h>
 #include <qfileinfo.h>
+#include <qeventloop.h>
 
 #include <kapplication.h>
 #include <kglobal.h>
@@ -31,40 +32,94 @@
 #include <kmessagebox.h>
 #include <kstdguiitem.h>
 #include <kstandarddirs.h>
+#include <dcopobject.h>
+#include <dcopref.h>
+#include <dcopclient.h>
 
 #include "notificationdialog.h"
 #include "notifiersettings.h"
 #include "notifieraction.h"
 #include "mediamanagersettings.h"
 
+
 MediaNotifier::MediaNotifier(const QCString &name) : KDEDModule(name)
 {
+//fprintf(stderr,"MediaNotifier::MediaNotifier()\n");
+//fflush(stderr);
 	connectDCOPSignal( "kded", "mediamanager", "mediumAdded(QString, bool)",
 	                   "onMediumChange(QString, bool)", true );
 	
 	connectDCOPSignal( "kded", "mediamanager", "mediumChanged(QString, bool)",
 	                   "onMediumChange(QString, bool)", true );
+//fprintf(stderr,"MediaNotifier::MediaNotifier() done\n");
+//fflush(stderr);
+	automountRemovables();
 }
 
 MediaNotifier::~MediaNotifier()
 {
 }
 
+void MediaNotifier::automountRemovables() {
+
+	// We get the mount/media information from the KDE mediamanager, the
+	// same way as what the media:/ ioslave does.
+	DCOPRef mediamanager("kded", "mediamanager");
+	DCOPReply reply = mediamanager.call( "fullList" );
+	if ( !reply.isValid() )
+	{
+		return;
+	}
+
+	Medium::List mediumList = Medium::createList(reply);
+	Medium::List::iterator it = mediumList.begin();
+	Medium::List::iterator end = mediumList.end();
+        
+	Medium thisMedium(QString::null,QString::null);
+
+	for(; it!=end; ++it)
+	{
+		QString mimeType = (*it).mimeType(); 
+		if( mimeType=="media/cdrom_unmounted" ||
+				mimeType=="media/cdwriter_unmounted" ||
+				mimeType=="media/dvd_unmounted" ||
+				mimeType=="media/zip_unmounted" ||
+				mimeType=="media/removable_unmounted")
+		{
+			// Try mounting this medium.
+			if ( (*it).needMounting() )
+			{
+				DCOPRef mediamanager("kded", "mediamanager");
+				DCOPReply reply = mediamanager.call( "mount", (*it).id());
+			}
+		}
+	}
+}
+
 void MediaNotifier::onMediumChange( const QString &name, bool allowNotification )
 {
 	kdDebug() << "MediaNotifier::onMediumChange( " << name << ", "
 	          << allowNotification << ")" << endl;
 
+//fprintf(stderr,"MediaNotifier::onMediumChange(%s)\n",name.latin1());
+//fflush(stderr);
+
 	if ( !allowNotification )
-	  return;
+		return;
 
 // Update user activity timestamp, otherwise the notification dialog will be shown
 // in the background due to focus stealing prevention. Entering a new media can
 // be seen as a kind of user activity after all. It'd be better to update the timestamp
 // as soon as the media is entered, but it apparently takes some time to get here.
+
 	kapp->updateUserTimestamp();
+//fprintf(stderr,"MediaNotifier::onMediumChange url is now %s\n",thisMedium.mountPoint().latin1());
+//fflush(stderr);
 
-	KURL url(  "system:/media/"+name );
+	KURL url( "media:/"+name );
+
+//fprintf(stderr,"MediaNotifier::onMediumChange checkpoint 2\n");
+//fflush(stderr);
 
 	KIO::SimpleJob *job = KIO::stat( url, false );
 	job->setInteractive( false );
@@ -73,6 +128,9 @@
 	
 	connect( job, SIGNAL( result( KIO::Job * ) ),
 	         this, SLOT( slotStatResult( KIO::Job * ) ) );
+
+//fprintf(stderr,"MediaNotifier::onMediumChange checkpoint 3\n");
+//fflush(stderr);
 }
 
 void MediaNotifier::slotStatResult( KIO::Job *job )
--- kdebase-3.5.4_orig/kioslave/media/medianotifier/medianotifier.h	2005-10-10 17:04:00.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/medianotifier/medianotifier.h	2006-09-20 08:36:57.000000000 +0200
@@ -26,6 +26,7 @@
 
 #include <qstring.h>
 #include <qmap.h>
+#include "medium.h"
 
 class MediaNotifier:  public KDEDModule
 {
@@ -50,7 +51,8 @@
 	                  const QString &autorunFile );
 	bool execAutoopen( const KFileItem &medium, const QString &path,
 	                   const QString &autoopenFile );
-
+	void automountRemovables();
+ 
 	QMap<KIO::Job*,bool> m_allowNotificationMap;
 };
 #endif
--- kdebase-3.5.4_orig/kioslave/media/mounthelper/kio_media_mounthelper.cpp	2006-07-22 10:15:42.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/mounthelper/kio_media_mounthelper.cpp	2006-09-11 00:28:39.000000000 +0200
@@ -35,17 +35,37 @@
 
 #include "kio_media_mounthelper.h"
 
-const Medium MountHelper::findMedium(const QString &name)
+const Medium MountHelper::findMedium(const KURL &url)
 {
+	// Grab all of the mount point data from the mediamanager	
 	DCOPRef mediamanager("kded", "mediamanager");
-	DCOPReply reply = mediamanager.call( "properties", name );
-
-	if ( !reply.isValid() )
-	{
+	DCOPReply reply = mediamanager.call( "fullList" );
+	if ( !reply.isValid() ) {
 		m_errorStr = i18n("The KDE mediamanager is not running.")+"\n";
+		return Medium::Medium("","");
 	}
 
-	return Medium::create(reply);
+	Medium::List mediumList = Medium::createList(reply);
+	Medium::List::iterator it = mediumList.begin();
+	Medium::List::iterator end = mediumList.end();
+        
+	Medium thisMedium(QString::null,QString::null);
+
+	QString key;	
+	if ( url.protocol()=="system" || url.protocol()=="media" ) {
+		key = url.fileName();
+	} else {
+		key = url.path();
+	}
+	
+	for(; it!=end; ++it) {
+		if( ((*it).name()==key) || ((*it).deviceNode()==key) || ((*it).mountPoint()==key) ) {
+			return *it;
+		}
+	}
+
+	// Failure
+	return Medium::Medium("","");
 }
 
 MountHelper::MountHelper() : KApplication()
@@ -55,7 +75,8 @@
 	m_errorStr = "";
 
 	KURL url(args->url(0));
-	const Medium medium = findMedium(url.fileName());
+
+	const Medium medium = findMedium(url);
 
 	if ( medium.id().isEmpty() )
 	{
--- kdebase-3.5.4_orig/kioslave/media/mounthelper/kio_media_mounthelper.h	2005-10-10 17:04:00.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/mounthelper/kio_media_mounthelper.h	2006-09-11 00:28:39.000000000 +0200
@@ -25,6 +25,7 @@
 #include <kapplication.h>
 #include <qstring.h>
 #include <kio/job.h>
+#include <kurl.h>
 
 #include "medium.h"
 
@@ -35,7 +36,7 @@
 	MountHelper();
 
 private:
-	const Medium findMedium(const QString &name);
+	const Medium findMedium(const KURL &name);
 	void invokeEject(const QString &device, bool quiet=false);
 	QString m_errorStr;
 	QString m_device;
--- kdebase-3.5.4_orig/kioslave/media/services/media_unmount.desktop	2006-05-23 13:33:34.000000000 +0200
+++ kdebase-3.5.4/kioslave/media/services/media_unmount.desktop	2006-09-16 11:03:01.000000000 +0200
@@ -1,5 +1,5 @@
 [Desktop Entry]
-ServiceTypes=media/cdrom_mounted,media/cdwriter_mounted,media/dvd_mounted,media/floppy5_mounted,media/floppy_mounted,media/hdd_mounted,media/nfs_mounted,media/smb_mounted,media/zip_mounted,media/vcd,media/svcd,media/dvdvideo
+ServiceTypes=media/floppy5_mounted,media/floppy_mounted,media/hdd_mounted,media/nfs_mounted,media/smb_mounted,media/zip_mounted,media/vcd,media/svcd,media/dvdvideo
 Actions=MediaUnmount;
 X-KDE-Priority=TopLevel
 X-KDE-MediaNotifierHide=true
