# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kautomount.cpp

    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., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018
    00019 #include "kautomount.h"
    00020 #include "krun.h"
    00021 #include "kdirwatch.h"
    00022 #include "kio/job.h"
    00023 #include <kdirnotify_stub.h>
    00024 #include <kdebug.h>
    00025
    00026 /***********************************************************************
    00027  *
    00028  * Utility classes
    00029  *
    00030  ***********************************************************************/
    00031
    00032 KAutoMount::KAutoMount( bool _readonly, const QString& _format, const QString& _device,
    00033                         const QString&  _mountpoint, const QString & _desktopFile,
    00034                         bool _show_filemanager_window )
    00035   : m_strDevice( _device ),
    00036     m_desktopFile( _desktopFile )
    00037 {
    00038   //kdDebug(7015) << "KAutoMount device=" << _device << " mountpoint=" << _mountpoint << endl;
    00039   m_bShowFilemanagerWindow = _show_filemanager_window;
    00040
    00041   KIO::Job* job = KIO::mount( _readonly, _format.ascii(), _device, _mountpoint );
    00042   connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) );
    00043 }
    00044
    00045 void KAutoMount::slotResult( KIO::Job * job )
    00046 {
    00047   if ( job->error() ) {
    00048     emit error();
    00049     job->showErrorDialog();
    00050   }
    00051   else
    00052   {
    00053     KURL mountpoint;
    00054     mountpoint.setPath( KIO::findDeviceMountPoint( m_strDevice ) );
    00055     //kdDebug(7015) << "KAutoMount: m_strDevice=" << m_strDevice << " -> mountpoint=" << mountpoint << endl;
    00056     Q_ASSERT( mountpoint.isValid() );
    00057
    00058     if ( mountpoint.path().isEmpty() )
    00059         kdWarning(7015) << m_strDevice << " was correctly mounted, but KIO::findDeviceMountPoint didn't find it. "
    00060                         << "This looks like a bug, please report it on http://bugs.kde.org, together with your /etc/fstab line" << endl;
    00061     else if ( m_bShowFilemanagerWindow )
    00062       KRun::runURL( mountpoint, "inode/directory" );
    00063
    00064     // Notify about the new stuff in that dir, in case of opened windows showing it
    00065     KDirNotify_stub allDirNotify("*", "KDirNotify*");
    00066     allDirNotify.FilesAdded( mountpoint );
    00067
    00068     // Update the desktop file which is used for mount/unmount (icon change)
    00069     kdDebug(7015) << " mount finished : updating " << m_desktopFile << endl;
    00070     KURL dfURL;
    00071     dfURL.setPath( m_desktopFile );
    00072     allDirNotify.FilesChanged( dfURL );
    00073     //KDirWatch::self()->setFileDirty( m_desktopFile );
    00074
    00075     emit finished();
    00076   }
    00077   delete this;
    00078 }
    00079
    00080 KAutoUnmount::KAutoUnmount( const QString & _mountpoint, const QString & _desktopFile )
    00081   : m_desktopFile( _desktopFile ), m_mountpoint( _mountpoint )
    00082 {
    00083   KIO::Job * job = KIO::unmount( m_mountpoint );
    00084   connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) );
    00085 }
    00086
    00087 void KAutoUnmount::slotResult( KIO::Job * job )
    00088 {
    00089   if ( job->error() ) {
    00090     emit error();
    00091     job->showErrorDialog();
    00092   }
    00093   else
    00094   {
    00095     KDirNotify_stub allDirNotify("*", "KDirNotify*");
    00096     // Update the desktop file which is used for mount/unmount (icon change)
    00097     kdDebug(7015) << "unmount finished : updating " << m_desktopFile << endl;
    00098     KURL dfURL;
    00099     dfURL.setPath( m_desktopFile );
    00100     allDirNotify.FilesChanged( dfURL );
    00101     //KDirWatch::self()->setFileDirty( m_desktopFile );
    00102
    00103     // Notify about the new stuff in that dir, in case of opened windows showing it
    00104     // You may think we removed files, but this may have also readded some
    00105     // (if the mountpoint wasn't empty). The only possible behavior on FilesAdded
    00106     // is to relist the directory anyway.
    00107     KURL mp;
    00108     mp.setPath( m_mountpoint );
    00109     allDirNotify.FilesAdded( mp );
    00110
    00111     emit finished();
    00112   }
    00113
    00114   delete this;
    00115 }
    00116
    00117 #include "kautomount.moc"

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:23:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003