okteta
abstractfilesystemexportjob.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "abstractfilesystemexportjob.h"
00024
00025
00026 #include <KIO/NetAccess>
00027 #include <KTemporaryFile>
00028 #include <KLocale>
00029
00030 #include <QtCore/QTimer>
00031
00032
00033 class AbstractFileSystemExportJob::Private
00034 {
00035 public:
00036 Private( AbstractModel *model, const AbstractModelSelection *selection, const KUrl &url );
00037 public:
00038 void prepareWorkFile();
00039 void removeWorkFile();
00040 public:
00041 AbstractModel *model() const;
00042 const AbstractModelSelection *selection() const;
00043 const KUrl &url() const;
00044 QString workFilePath() const;
00045 QWidget *widget() const;
00046 protected:
00047 AbstractModel *mModel;
00048 const AbstractModelSelection *mSelection;
00049 const KUrl mUrl;
00050 KTemporaryFile *mTemporaryFile;
00051 QString mWorkFilePath;
00052 QWidget *mWidget;
00053 };
00054
00055 inline AbstractFileSystemExportJob::Private::Private( AbstractModel *model, const AbstractModelSelection *selection,
00056 const KUrl &url)
00057 : mModel( model ), mSelection( selection ), mUrl( url ), mTemporaryFile( 0 ), mWidget( 0 )
00058 {}
00059 inline AbstractModel *AbstractFileSystemExportJob::Private::model() const { return mModel; }
00060 inline const AbstractModelSelection *AbstractFileSystemExportJob::Private::selection() const { return mSelection; }
00061 inline const KUrl &AbstractFileSystemExportJob::Private::url() const { return mUrl; }
00062 inline QString AbstractFileSystemExportJob::Private::workFilePath() const { return mWorkFilePath; }
00063 inline QWidget *AbstractFileSystemExportJob::Private::widget() const { return mWidget; }
00064
00065 inline void AbstractFileSystemExportJob::Private::prepareWorkFile()
00066 {
00067 if( mUrl.isLocalFile() )
00068 mWorkFilePath = mUrl.path();
00069 else
00070 {
00071 mTemporaryFile = new KTemporaryFile;
00072 mTemporaryFile->open();
00073 mWorkFilePath = mTemporaryFile->fileName();
00074 }
00075 }
00076 inline void AbstractFileSystemExportJob::Private::removeWorkFile()
00077 {
00078 delete mTemporaryFile;
00079 }
00080
00081
00082 AbstractFileSystemExportJob::AbstractFileSystemExportJob( AbstractModel *model, const AbstractModelSelection *selection,
00083 const KUrl &url )
00084 : d( new Private(model,selection,url) )
00085 {
00086 }
00087
00088 AbstractModel *AbstractFileSystemExportJob::model() const { return d->model(); }
00089 const AbstractModelSelection *AbstractFileSystemExportJob::selection() const { return d->selection(); }
00090 QString AbstractFileSystemExportJob::workFilePath() const { return d->workFilePath(); }
00091 QWidget *AbstractFileSystemExportJob::widget() const { return d->widget(); }
00092
00093
00094 void AbstractFileSystemExportJob::start()
00095 {
00096 QTimer::singleShot( 0, this, SLOT(exportToFile()) );
00097 }
00098
00099 void AbstractFileSystemExportJob::exportToFile()
00100 {
00101 d->prepareWorkFile();
00102
00103 startExportToFile();
00104 }
00105
00106 void AbstractFileSystemExportJob::completeExport( bool success )
00107 {
00108 if( success )
00109 {
00110 if( !d->url().isLocalFile() )
00111 {
00112 success = KIO::NetAccess::upload( d->workFilePath(), d->url(), d->widget() );
00113 if( !success )
00114 {
00115 setError( KilledJobError );
00116 setErrorText( KIO::NetAccess::lastErrorString() );
00117 }
00118 }
00119 }
00120 else
00121 {
00122 setError( KilledJobError );
00123 setErrorText( i18nc("@info","Problem when saving to local filesystem.") );
00124 }
00125
00126 d->removeWorkFile();
00127
00128 emitResult();
00129 }
00130
00131
00132 AbstractFileSystemExportJob::~AbstractFileSystemExportJob()
00133 {
00134 delete d;
00135 }
00136
00137 #include "abstractfilesystemexportjob.moc"