KIO
kautomount.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 David Faure <faure@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 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 #include <sys/mount.h> 00028 00029 /*********************************************************************** 00030 * 00031 * Utility classes 00032 * 00033 ***********************************************************************/ 00034 00035 class KAutoMountPrivate 00036 { 00037 public: 00038 KAutoMountPrivate(KAutoMount *qq, const QString &device, const QString& mountPoint, 00039 const QString &desktopFile, bool showFileManagerWindow) 00040 : q(qq), m_strDevice(device), m_desktopFile(desktopFile), m_mountPoint(mountPoint), 00041 m_bShowFilemanagerWindow(showFileManagerWindow) 00042 { } 00043 00044 KAutoMount *q; 00045 QString m_strDevice; 00046 QString m_desktopFile; 00047 QString m_mountPoint; 00048 bool m_bShowFilemanagerWindow; 00049 00050 void slotResult( KJob * ); 00051 }; 00052 00053 KAutoMount::KAutoMount( bool _readonly, const QByteArray& _format, const QString& _device, 00054 const QString& _mountpoint, const QString & _desktopFile, 00055 bool _show_filemanager_window ) 00056 : d(new KAutoMountPrivate(this, _device, _mountpoint, _desktopFile, _show_filemanager_window)) 00057 { 00058 KIO::Job* job = KIO::mount( _readonly, _format, _device, _mountpoint ); 00059 connect( job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)) ); 00060 } 00061 00062 KAutoMount::~KAutoMount() 00063 { 00064 delete d; 00065 } 00066 00067 void KAutoMountPrivate::slotResult( KJob * job ) 00068 { 00069 if ( job->error() ) { 00070 emit q->error(); 00071 job->uiDelegate()->showErrorMessage(); 00072 } else { 00073 const KMountPoint::List mountPoints (KMountPoint::currentMountPoints()); 00074 KMountPoint::Ptr mp = mountPoints.findByDevice(m_strDevice); 00075 // Mounting devices using "LABEL=" or "UUID=" will fail if we look for 00076 // the device using only its real name since /etc/mtab will never contain 00077 // the LABEL or UUID entries. Hence, we check using the mount point below 00078 // when device name lookup fails. #247235 00079 if (!mp) { 00080 mp = mountPoints.findByPath(m_mountPoint); 00081 } 00082 00083 if (!mp) { 00084 kWarning(7015) << m_strDevice << "was correctly mounted, but findByDevice() didn't find it." 00085 << "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"; 00086 } else { 00087 KUrl url(mp->mountPoint()); 00088 //kDebug(7015) << "KAutoMount: m_strDevice=" << m_strDevice << " -> mountpoint=" << mountpoint; 00089 if ( m_bShowFilemanagerWindow ) { 00090 KRun::runUrl( url, "inode/directory", 0 /*TODO - window*/ ); 00091 } 00092 // Notify about the new stuff in that dir, in case of opened windows showing it 00093 org::kde::KDirNotify::emitFilesAdded( url.url() ); 00094 } 00095 00096 // Update the desktop file which is used for mount/unmount (icon change) 00097 kDebug(7015) << " mount finished : updating " << m_desktopFile; 00098 KUrl dfURL; 00099 dfURL.setPath( m_desktopFile ); 00100 org::kde::KDirNotify::emitFilesChanged( QStringList() << dfURL.url() ); 00101 //KDirWatch::self()->setFileDirty( m_desktopFile ); 00102 00103 emit q->finished(); 00104 } 00105 q->deleteLater(); 00106 } 00107 00108 class KAutoUnmountPrivate 00109 { 00110 public: 00111 KAutoUnmountPrivate( KAutoUnmount *qq, const QString & _mountpoint, const QString & _desktopFile ) 00112 : q(qq), m_desktopFile( _desktopFile ), m_mountpoint( _mountpoint ) 00113 {} 00114 KAutoUnmount *q; 00115 QString m_desktopFile; 00116 QString m_mountpoint; 00117 00118 void slotResult( KJob * job ); 00119 }; 00120 00121 KAutoUnmount::KAutoUnmount( const QString & _mountpoint, const QString & _desktopFile ) 00122 : d( new KAutoUnmountPrivate(this, _mountpoint, _desktopFile) ) 00123 { 00124 KIO::Job * job = KIO::unmount( d->m_mountpoint ); 00125 connect( job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)) ); 00126 } 00127 00128 void KAutoUnmountPrivate::slotResult( KJob * job ) 00129 { 00130 if ( job->error() ) { 00131 emit q->error(); 00132 job->uiDelegate()->showErrorMessage(); 00133 } 00134 else 00135 { 00136 // Update the desktop file which is used for mount/unmount (icon change) 00137 kDebug(7015) << "unmount finished : updating " << m_desktopFile; 00138 KUrl dfURL; 00139 dfURL.setPath( m_desktopFile ); 00140 org::kde::KDirNotify::emitFilesChanged( QStringList() << dfURL.url() ); 00141 //KDirWatch::self()->setFileDirty( m_desktopFile ); 00142 00143 // Notify about the new stuff in that dir, in case of opened windows showing it 00144 // You may think we removed files, but this may have also readded some 00145 // (if the mountpoint wasn't empty). The only possible behavior on FilesAdded 00146 // is to relist the directory anyway. 00147 KUrl mp( m_mountpoint ); 00148 org::kde::KDirNotify::emitFilesAdded( mp.url() ); 00149 00150 emit q->finished(); 00151 } 00152 00153 q->deleteLater(); 00154 } 00155 00156 KAutoUnmount::~KAutoUnmount() 00157 { 00158 delete d; 00159 } 00160 00161 #include "kautomount.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:34:58 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:34:58 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.