KIO
kautomount.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kautomount.h"
00020 #include "krun.h"
00021 #include "kdirwatch.h"
00022 #include "kio/job.h"
00023 #include "kio/jobuidelegate.h"
00024 #include <kdirnotify.h>
00025 #include <kdebug.h>
00026 #include <kmountpoint.h>
00027
00028
00029
00030
00031
00032
00033
00034 class KAutoMountPrivate
00035 {
00036 public:
00037 KAutoMountPrivate(KAutoMount *qq, const QString &device, const QString &desktopFile,
00038 bool showFileManagerWindow)
00039 : q(qq), m_strDevice(device), m_desktopFile(desktopFile),
00040 m_bShowFilemanagerWindow(showFileManagerWindow)
00041 { }
00042
00043 KAutoMount *q;
00044 QString m_strDevice;
00045 QString m_desktopFile;
00046 bool m_bShowFilemanagerWindow;
00047
00048 void slotResult( KJob * );
00049 };
00050
00051 KAutoMount::KAutoMount( bool _readonly, const QByteArray& _format, const QString& _device,
00052 const QString& _mountpoint, const QString & _desktopFile,
00053 bool _show_filemanager_window )
00054 : d(new KAutoMountPrivate(this, _device, _desktopFile, _show_filemanager_window))
00055 {
00056 KIO::Job* job = KIO::mount( _readonly, _format, _device, _mountpoint );
00057 connect( job, SIGNAL( result( KJob * ) ), this, SLOT( slotResult( KJob * ) ) );
00058 }
00059
00060 KAutoMount::~KAutoMount()
00061 {
00062 delete d;
00063 }
00064
00065 void KAutoMountPrivate::slotResult( KJob * job )
00066 {
00067 if ( job->error() ) {
00068 emit q->error();
00069 job->uiDelegate()->showErrorMessage();
00070 } else {
00071 KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByDevice( m_strDevice );
00072 if (!mp) {
00073 kWarning(7015) << m_strDevice << "was correctly mounted, but findByDevice() didn't find it."
00074 << "This looks like a bug, please report it on http://bugs.kde.org, together with your /etc/fstab and /etc/mtab lines for this device";
00075 } else {
00076 KUrl url(mp->mountPoint());
00077
00078 if ( m_bShowFilemanagerWindow ) {
00079 KRun::runUrl( url, "inode/directory", 0 );
00080 }
00081
00082 org::kde::KDirNotify::emitFilesAdded( url.url() );
00083 }
00084
00085
00086 kDebug(7015) << " mount finished : updating " << m_desktopFile;
00087 KUrl dfURL;
00088 dfURL.setPath( m_desktopFile );
00089 org::kde::KDirNotify::emitFilesChanged( QStringList() << dfURL.url() );
00090
00091
00092 emit q->finished();
00093 }
00094 q->deleteLater();
00095 }
00096
00097 class KAutoUnmountPrivate
00098 {
00099 public:
00100 KAutoUnmountPrivate( KAutoUnmount *qq, const QString & _mountpoint, const QString & _desktopFile )
00101 : q(qq), m_desktopFile( _desktopFile ), m_mountpoint( _mountpoint )
00102 {}
00103 KAutoUnmount *q;
00104 QString m_desktopFile;
00105 QString m_mountpoint;
00106
00107 void slotResult( KJob * job );
00108 };
00109
00110 KAutoUnmount::KAutoUnmount( const QString & _mountpoint, const QString & _desktopFile )
00111 : d( new KAutoUnmountPrivate(this, _desktopFile, _mountpoint) )
00112 {
00113 KIO::Job * job = KIO::unmount( d->m_mountpoint );
00114 connect( job, SIGNAL( result( KJob * ) ), this, SLOT( slotResult( KJob * ) ) );
00115 }
00116
00117 void KAutoUnmountPrivate::slotResult( KJob * job )
00118 {
00119 if ( job->error() ) {
00120 emit q->error();
00121 job->uiDelegate()->showErrorMessage();
00122 }
00123 else
00124 {
00125
00126 kDebug(7015) << "unmount finished : updating " << m_desktopFile;
00127 KUrl dfURL;
00128 dfURL.setPath( m_desktopFile );
00129 org::kde::KDirNotify::emitFilesChanged( QStringList() << dfURL.url() );
00130
00131
00132
00133
00134
00135
00136 KUrl mp( m_mountpoint );
00137 org::kde::KDirNotify::emitFilesAdded( mp.url() );
00138
00139 emit q->finished();
00140 }
00141
00142 q->deleteLater();
00143 }
00144
00145 KAutoUnmount::~KAutoUnmount()
00146 {
00147 delete d;
00148 }
00149
00150 #include "kautomount.moc"