• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

okteta

abstractfilesystemloadjob.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of the Okteta Kakao module, part of the KDE project.
00003 
00004     Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) version 3, or any
00010     later version accepted by the membership of KDE e.V. (or its
00011     successor approved by the membership of KDE e.V.), which shall
00012     act as a proxy defined in Section 6 of version 3 of the license.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public
00020     License along with this library. If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 
00023 #include "abstractfilesystemloadjob.h"
00024 
00025 // library
00026 #include "abstractmodelfilesystemsynchronizer.h"
00027 #include <kabstractdocument.h>
00028 // KDE
00029 #include <KIO/NetAccess>
00030 #include <KTemporaryFile>
00031 #include <KLocale>
00032 #include <KDirWatch>
00033 // Qt
00034 #include <QtCore/QTimer>
00035 
00036 
00037 class AbstractFileSystemLoadJob::Private
00038 {
00039   public:
00040     Private( AbstractModelFileSystemSynchronizer* synchronizer, const KUrl& url );
00041 
00042   public:
00043     void setWorkFilePath( const QString &workFilePath );
00044 
00045   public:
00046     const KUrl &url() const;
00047     QString workFilePath() const;
00048     QWidget *widget() const;
00049     AbstractModelFileSystemSynchronizer* synchronizer() const;
00050 
00051   protected:
00052     AbstractModelFileSystemSynchronizer* mSynchronizer;
00053     const KUrl mUrl;
00054     QString mWorkFilePath;
00055 };
00056 
00057 AbstractFileSystemLoadJob::Private::Private( AbstractModelFileSystemSynchronizer* synchronizer, const KUrl &url )
00058  : mSynchronizer( synchronizer ), mUrl( url )
00059 {}
00060 
00061 inline AbstractModelFileSystemSynchronizer* AbstractFileSystemLoadJob::Private::synchronizer() const
00062 {
00063     return mSynchronizer;
00064 }
00065 inline const KUrl &AbstractFileSystemLoadJob::Private::url()      const { return mUrl; }
00066 inline QString AbstractFileSystemLoadJob::Private::workFilePath() const { return mWorkFilePath; }
00067 // TODO: setup a notification system
00068 inline QWidget *AbstractFileSystemLoadJob::Private::widget()      const { return 0; }
00069 
00070 inline void AbstractFileSystemLoadJob::Private::setWorkFilePath( const QString &workFilePath )
00071 {
00072     mWorkFilePath = workFilePath;
00073 }
00074 
00075 
00076 
00077 AbstractFileSystemLoadJob::AbstractFileSystemLoadJob( AbstractModelFileSystemSynchronizer* synchronizer,
00078                                                       const KUrl &url )
00079  : d( new Private(synchronizer,url) )
00080 {}
00081 
00082 AbstractModelFileSystemSynchronizer* AbstractFileSystemLoadJob::synchronizer() const
00083 {
00084     return d->synchronizer();
00085 }
00086 QString AbstractFileSystemLoadJob::workFilePath() const { return d->workFilePath(); }
00087 QWidget *AbstractFileSystemLoadJob::widget() const { return d->widget(); }
00088 
00089 void AbstractFileSystemLoadJob::start()
00090 {
00091     QTimer::singleShot( 0, this, SLOT(load()) );
00092 }
00093 
00094 void AbstractFileSystemLoadJob::load()
00095 {
00096     QString workFilePath;
00097     // TODO: see if this could be used asynchronously instead
00098     if( KIO::NetAccess::download(d->url().url(),workFilePath,d->widget()) )
00099     {
00100         d->setWorkFilePath( workFilePath );
00101         startLoadFromFile();
00102     }
00103     else
00104     {
00105         setError( KilledJobError );
00106         setErrorText( KIO::NetAccess::lastErrorString() );
00107         // TODO: should we rather skip setDocument in the API?
00108         AbstractLoadJob::setDocument( 0 );
00109     }
00110 }
00111 
00112 
00113 void AbstractFileSystemLoadJob::setDocument( KAbstractDocument *document )
00114 {
00115     AbstractModelFileSystemSynchronizer* synchronizer = d->synchronizer();
00116 
00117     if( document )
00118     {
00119         synchronizer->setUrl( d->url() );
00120         if( d->url().isLocalFile() )
00121         {
00122             KDirWatch *dirWatch = KDirWatch::self();
00123             connect( dirWatch, SIGNAL(dirty( const QString & )),
00124                      synchronizer, SLOT(onFileDirty( const QString & )) );
00125 
00126             connect( dirWatch, SIGNAL(created( const QString & )),
00127                      synchronizer, SLOT(onFileCreated( const QString & )) );
00128 
00129             connect( dirWatch, SIGNAL(deleted( const QString & )),
00130                      synchronizer, SLOT(onFileDeleted( const QString & )) );
00131             dirWatch->addFile( d->url().path() );
00132         }
00133         document->setSynchronizer( synchronizer );
00134     }
00135     else
00136     {
00137         delete synchronizer;
00138         // TODO: these reports should go to a notification system, for log or popup
00139         setError( KilledJobError );
00140         setErrorText( i18nc("@info","Problem when loading from local filesystem.") );
00141     }
00142 
00143     KIO::NetAccess::removeTempFile( d->workFilePath() );
00144 
00145     AbstractLoadJob::setDocument( document );
00146 }
00147 
00148 
00149 AbstractFileSystemLoadJob::~AbstractFileSystemLoadJob()
00150 {
00151     delete d;
00152 }
00153 
00154 #include "abstractfilesystemloadjob.moc"

okteta

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

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.4
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