kautomount.cpp Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | 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   m_bShowFilemanagerWindow = _show_filemanager_window;
    00039
    00040   KIO::Job* job = KIO::mount( _readonly, _format.ascii(), _device, _mountpoint );
    00041   connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) );
    00042 }
    00043
    00044 void KAutoMount::slotResult( KIO::Job * job )
    00045 {
    00046   if ( job->error() ) {
    00047     emit error();
    00048     job->showErrorDialog();
    00049   }
    00050   else
    00051   {
    00052     KURL mountpoint;
    00053     mountpoint.setPath( KIO::findDeviceMountPoint( m_strDevice ) );
    00054
    00055     if ( m_bShowFilemanagerWindow )
    00056       KRun::runURL( mountpoint, "inode/directory" );
    00057
    00058     // Notify about the new stuff in that dir, in case of opened windows showing it
    00059     KDirNotify_stub allDirNotify("*", "KDirNotify*");
    00060     allDirNotify.FilesAdded( mountpoint );
    00061
    00062     // Update the desktop file which is used for mount/unmount (icon change)
    00063     kdDebug(7015) << " mount finished : updating " << m_desktopFile << endl;
    00064     KURL dfURL;
    00065     dfURL.setPath( m_desktopFile );
    00066     allDirNotify.FilesChanged( dfURL );
    00067     //KDirWatch::self()->setFileDirty( m_desktopFile );
    00068
    00069     emit finished();
    00070   }
    00071   delete this;
    00072 }
    00073
    00074 KAutoUnmount::KAutoUnmount( const QString & _mountpoint, const QString & _desktopFile )
    00075   : m_desktopFile( _desktopFile ), m_mountpoint( _mountpoint )
    00076 {
    00077   KIO::Job * job = KIO::unmount( m_mountpoint );
    00078   connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) );
    00079 }
    00080
    00081 void KAutoUnmount::slotResult( KIO::Job * job )
    00082 {
    00083   if ( job->error() ) {
    00084     emit error();
    00085     job->showErrorDialog();
    00086   }
    00087   else
    00088   {
    00089     KDirNotify_stub allDirNotify("*", "KDirNotify*");
    00090     // Update the desktop file which is used for mount/unmount (icon change)
    00091     kdDebug(7015) << "unmount finished : updating " << m_desktopFile << endl;
    00092     KURL dfURL;
    00093     dfURL.setPath( m_desktopFile );
    00094     allDirNotify.FilesChanged( dfURL );
    00095     //KDirWatch::self()->setFileDirty( m_desktopFile );
    00096
    00097     // Notify about the new stuff in that dir, in case of opened windows showing it
    00098     // You may think we removed files, but this may have also readded some
    00099     // (if the mountpoint wasn't empty). The only possible behaviour on FilesAdded
    00100     // is to relist the directory anyway.
    00101     allDirNotify.FilesAdded( m_mountpoint );
    00102
    00103     emit finished();
    00104   }
    00105
    00106   delete this;
    00107 }
    00108
    00109 #include "kautomount.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:07 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001