okteta
abstractfilesystemsyncfromremotejob.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 "abstractfilesystemsyncfromremotejob.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 <KMessageBox> 00033 #include <KDirWatch> 00034 // Qt 00035 #include <QtCore/QTimer> 00036 00037 00038 class AbstractFileSystemSyncFromRemoteJob::Private 00039 { 00040 public: 00041 Private( AbstractModelFileSystemSynchronizer* synchronizer ); 00042 00043 public: 00044 void setWorkFilePath( const QString &workFilePath ); 00045 00046 public: 00047 KUrl url() const; 00048 QString workFilePath() const; 00049 QWidget *widget() const; 00050 AbstractModelFileSystemSynchronizer* synchronizer() const; 00051 00052 protected: 00053 AbstractModelFileSystemSynchronizer* mSynchronizer; 00054 QString mWorkFilePath; 00055 }; 00056 00057 AbstractFileSystemSyncFromRemoteJob::Private::Private( AbstractModelFileSystemSynchronizer* synchronizer ) 00058 : mSynchronizer( synchronizer ) 00059 {} 00060 00061 inline KUrl AbstractFileSystemSyncFromRemoteJob::Private::url() const { return mSynchronizer->url(); } 00062 inline QString AbstractFileSystemSyncFromRemoteJob::Private::workFilePath() const { return mWorkFilePath; } 00063 // TODO: setup a notification system 00064 inline QWidget *AbstractFileSystemSyncFromRemoteJob::Private::widget() const { return 0; } 00065 inline AbstractModelFileSystemSynchronizer* AbstractFileSystemSyncFromRemoteJob::Private::synchronizer() const 00066 { 00067 return mSynchronizer; 00068 } 00069 00070 inline void AbstractFileSystemSyncFromRemoteJob::Private::setWorkFilePath( const QString &workFilePath ) 00071 { 00072 mWorkFilePath = workFilePath; 00073 } 00074 00075 00076 00077 AbstractFileSystemSyncFromRemoteJob::AbstractFileSystemSyncFromRemoteJob( AbstractModelFileSystemSynchronizer* synchronizer ) 00078 : d( new Private(synchronizer) ) 00079 {} 00080 00081 AbstractModelFileSystemSynchronizer* AbstractFileSystemSyncFromRemoteJob::synchronizer() const 00082 { 00083 return d->synchronizer(); 00084 } 00085 QString AbstractFileSystemSyncFromRemoteJob::workFilePath() const { return d->workFilePath(); } 00086 QWidget *AbstractFileSystemSyncFromRemoteJob::widget() const { return d->widget(); } 00087 00088 void AbstractFileSystemSyncFromRemoteJob::start() 00089 { 00090 QTimer::singleShot( 0, this, SLOT(syncFromRemote()) ); 00091 } 00092 00093 void AbstractFileSystemSyncFromRemoteJob::syncFromRemote() 00094 { 00095 QString workFilePath; 00096 // TODO: see if this could be used asynchronously instead 00097 if( KIO::NetAccess::download(d->url().url(),workFilePath,d->widget()) ) 00098 { 00099 d->setWorkFilePath( workFilePath ); 00100 startReadFromFile(); 00101 } 00102 else 00103 { 00104 setError( KilledJobError ); 00105 setErrorText( KIO::NetAccess::lastErrorString() ); 00106 emitResult(); 00107 } 00108 } 00109 00110 00111 void AbstractFileSystemSyncFromRemoteJob::completeRead( bool success ) 00112 { 00113 if( !success ) 00114 { 00115 setError( KilledJobError ); 00116 setErrorText( i18nc("@info","Problem when loading from local filesystem.") ); 00117 } 00118 00119 KIO::NetAccess::removeTempFile( d->workFilePath() ); 00120 00121 emitResult(); 00122 } 00123 00124 00125 AbstractFileSystemSyncFromRemoteJob::~AbstractFileSystemSyncFromRemoteJob() 00126 { 00127 delete d; 00128 } 00129 00130 #include "abstractfilesystemsyncfromremotejob.moc"
KDE 4.2 API Reference