From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kio/kio/kautomount.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 kio/kio/kautomount.cpp (limited to 'kio/kio/kautomount.cpp') diff --git a/kio/kio/kautomount.cpp b/kio/kio/kautomount.cpp new file mode 100644 index 000000000..23d3c970c --- /dev/null +++ b/kio/kio/kautomount.cpp @@ -0,0 +1,117 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kautomount.h" +#include "krun.h" +#include "kdirwatch.h" +#include "kio/job.h" +#include +#include + +/*********************************************************************** + * + * Utility classes + * + ***********************************************************************/ + +KAutoMount::KAutoMount( bool _readonly, const QString& _format, const QString& _device, + const QString& _mountpoint, const QString & _desktopFile, + bool _show_filemanager_window ) + : m_strDevice( _device ), + m_desktopFile( _desktopFile ) +{ + //kdDebug(7015) << "KAutoMount device=" << _device << " mountpoint=" << _mountpoint << endl; + m_bShowFilemanagerWindow = _show_filemanager_window; + + KIO::Job* job = KIO::mount( _readonly, _format.ascii(), _device, _mountpoint ); + connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) ); +} + +void KAutoMount::slotResult( KIO::Job * job ) +{ + if ( job->error() ) { + emit error(); + job->showErrorDialog(); + } + else + { + KURL mountpoint; + mountpoint.setPath( KIO::findDeviceMountPoint( m_strDevice ) ); + //kdDebug(7015) << "KAutoMount: m_strDevice=" << m_strDevice << " -> mountpoint=" << mountpoint << endl; + Q_ASSERT( mountpoint.isValid() ); + + if ( mountpoint.path().isEmpty() ) + kdWarning(7015) << m_strDevice << " was correctly mounted, but KIO::findDeviceMountPoint didn't find it. " + << "This looks like a bug, please report it on http://bugs.kde.org, together with your /etc/fstab line" << endl; + else if ( m_bShowFilemanagerWindow ) + KRun::runURL( mountpoint, "inode/directory" ); + + // Notify about the new stuff in that dir, in case of opened windows showing it + KDirNotify_stub allDirNotify("*", "KDirNotify*"); + allDirNotify.FilesAdded( mountpoint ); + + // Update the desktop file which is used for mount/unmount (icon change) + kdDebug(7015) << " mount finished : updating " << m_desktopFile << endl; + KURL dfURL; + dfURL.setPath( m_desktopFile ); + allDirNotify.FilesChanged( dfURL ); + //KDirWatch::self()->setFileDirty( m_desktopFile ); + + emit finished(); + } + delete this; +} + +KAutoUnmount::KAutoUnmount( const QString & _mountpoint, const QString & _desktopFile ) + : m_desktopFile( _desktopFile ), m_mountpoint( _mountpoint ) +{ + KIO::Job * job = KIO::unmount( m_mountpoint ); + connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) ); +} + +void KAutoUnmount::slotResult( KIO::Job * job ) +{ + if ( job->error() ) { + emit error(); + job->showErrorDialog(); + } + else + { + KDirNotify_stub allDirNotify("*", "KDirNotify*"); + // Update the desktop file which is used for mount/unmount (icon change) + kdDebug(7015) << "unmount finished : updating " << m_desktopFile << endl; + KURL dfURL; + dfURL.setPath( m_desktopFile ); + allDirNotify.FilesChanged( dfURL ); + //KDirWatch::self()->setFileDirty( m_desktopFile ); + + // Notify about the new stuff in that dir, in case of opened windows showing it + // You may think we removed files, but this may have also readded some + // (if the mountpoint wasn't empty). The only possible behavior on FilesAdded + // is to relist the directory anyway. + KURL mp; + mp.setPath( m_mountpoint ); + allDirNotify.FilesAdded( mp ); + + emit finished(); + } + + delete this; +} + +#include "kautomount.moc" -- cgit v1.2.1