resourcenet.h

00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KABC_RESOURCENET_H
00022 #define KABC_RESOURCENET_H
00023 
00024 #include <kconfig.h>
00025 
00026 #include <sys/types.h>
00027 
00028 #include <kabc/resource.h>
00029 
00030 class QFile;
00031 class QTimer;
00032 class KTempFile;
00033 
00034 namespace KIO {
00035 class Job;
00036 }
00037 
00038 namespace KABC {
00039 
00040 class FormatPlugin;
00041 
00045 class KABC_EXPORT ResourceNet : public Resource
00046 {
00047   Q_OBJECT
00048 
00049   public:
00050     ResourceNet( const KConfig* );
00051     ResourceNet( const KURL &url, const QString &format );
00052     ~ResourceNet();
00053 
00054     virtual void writeConfig( KConfig* );
00055 
00056     virtual bool doOpen();
00057     virtual void doClose();
00058 
00059     virtual Ticket *requestSaveTicket();
00060     virtual void releaseSaveTicket( Ticket* );
00061 
00062     virtual bool load();
00063     virtual bool asyncLoad();
00064     virtual bool save( Ticket* ticket );
00065     virtual bool asyncSave( Ticket* ticket );
00066 
00070     void setUrl( const KURL & );
00071 
00075     KURL url() const;
00076 
00080     void setFormat( const QString &name );
00081 
00085     QString format() const;
00086 
00087   protected:
00088     void init( const KURL &url, const QString &format );
00089 
00090   private slots:
00091     void downloadFinished( KIO::Job* );
00092     void uploadFinished( KIO::Job* );
00093     void signalError();
00094 
00095   private:
00096     bool clearAndLoad( QFile *file );
00097     void saveToFile( QFile *file );
00098     bool hasTempFile() const { return mTempFile != 0; }
00099     void abortAsyncLoading();
00100     void abortAsyncSaving();
00101     bool createLocalTempFile();
00102     void deleteLocalTempFile();
00103     void deleteStaleTempFile();
00104 
00105     FormatPlugin *mFormat;
00106     QString mFormatName;
00107 
00108     KURL mUrl;
00109     KTempFile *mTempFile;
00110 
00111     class ResourceNetPrivate;
00112     ResourceNetPrivate *d;
00113 };
00114 
00115 }
00116 
00117 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys