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

okteta

abstractfilesystemexportjob.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of the Kakao Framework, 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 "abstractfilesystemexportjob.h"
00024 
00025 // KDE
00026 #include <KIO/NetAccess>
00027 #include <KTemporaryFile>
00028 #include <KLocale>
00029 // Qt
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"

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