• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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 
00028 /***********************************************************************
00029  *
00030  * Utility classes
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             //kDebug(7015) << "KAutoMount: m_strDevice=" << m_strDevice << " -> mountpoint=" << mountpoint;
00078             if ( m_bShowFilemanagerWindow ) {
00079                 KRun::runUrl( url, "inode/directory", 0 /*TODO - window*/ );
00080             }
00081             // Notify about the new stuff in that dir, in case of opened windows showing it
00082             org::kde::KDirNotify::emitFilesAdded( url.url() );
00083         }
00084 
00085         // Update the desktop file which is used for mount/unmount (icon change)
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         //KDirWatch::self()->setFileDirty( m_desktopFile );
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, _mountpoint, _desktopFile) )
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         // Update the desktop file which is used for mount/unmount (icon change)
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         //KDirWatch::self()->setFileDirty( m_desktopFile );
00131 
00132         // Notify about the new stuff in that dir, in case of opened windows showing it
00133         // You may think we removed files, but this may have also readded some
00134         // (if the mountpoint wasn't empty). The only possible behavior on FilesAdded
00135         // is to relist the directory anyway.
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"

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal