kautomount.cpp
/* This file is part of the KDE libraries
Copyright (C) 2000 David Faure <faure@kde.org>
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 <kdirnotify_stub.h>
#include <kdebug.h>
/***********************************************************************
*
* 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"
KRun::runURL
static pid_t runURL(const KURL &_url, const QString &_mimetype, bool tempFile, bool runExecutables)
Open the given URL.
Definition: krun.cpp:92
KAutoUnmount::KAutoUnmount
KAutoUnmount(const QString &mountpoint, const QString &desktopFile)
Unmounts a device.
Definition: kautomount.cpp:80
KIO::unmount
KIO_EXPORT SimpleJob * unmount(const QString &point, bool showProgressInfo=true)
Unmount filesystem.
Definition: job.cpp:802
KIO::findDeviceMountPoint
KIO_EXPORT QString findDeviceMountPoint(const QString &device)
Returns the mount point where device is mounted right now.
Definition: global.cpp:1368
KAutoMount::error
void error()
Emitted in case the directory could not been mounted.
KIO::Job::showErrorDialog
void showErrorDialog(QWidget *parent=0L)
Display a dialog box to inform the user of the error given by this job.
Definition: job.cpp:294
KAutoUnmount::error
void error()
Emitted in case the directory could not been unmounted.
KAutoUnmount::finished
void finished()
Emitted when the directory has been unmounted.
KIO::mount
KIO_EXPORT SimpleJob * mount(bool ro, const char *fstype, const QString &dev, const QString &point, bool showProgressInfo=true)
Mount filesystem.
Definition: job.cpp:792
KIO::Job::error
int error() const
Returns the error code, if there has been an error.
Definition: jobclasses.h:95
KIO::Job
The base class for all jobs.
Definition: jobclasses.h:68
KAutoMount::KAutoMount
KAutoMount(bool readonly, const QString &format, const QString &device, const QString &mountpoint, const QString &desktopFile, bool show_filemanager_window=true)
Mounts a device.
Definition: kautomount.cpp:32
KAutoMount::finished
void finished()
Emitted when the directory has been mounted.

KDE Home | KDE Accessibility Home | Description of Access Keys