kabc
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 "kabc/resource.h" 00025 #include <sys/types.h> 00026 00027 class QFile; 00028 class KTemporaryFile; 00029 00030 class KJob; 00031 00032 namespace KABC { 00033 00034 class Format; 00035 00039 class KABC_NET_EXPORT ResourceNet : public Resource 00040 { 00041 Q_OBJECT 00042 00043 public: 00044 ResourceNet(); 00045 explicit ResourceNet( const KConfigGroup &group ); 00046 ResourceNet( const KUrl &url, const QString &format ); 00047 ~ResourceNet(); 00048 00049 virtual void writeConfig( KConfigGroup &group ); 00050 00051 virtual bool doOpen(); 00052 virtual void doClose(); 00053 00054 virtual Ticket *requestSaveTicket(); 00055 virtual void releaseSaveTicket( Ticket *ticket ); 00056 00057 virtual bool load(); 00058 virtual bool asyncLoad(); 00059 virtual bool save( Ticket *ticket ); 00060 virtual bool asyncSave( Ticket *ticket ); 00061 00065 void setUrl( const KUrl &url ); 00066 00070 KUrl url() const; 00071 00075 void setFormat( const QString &name ); 00076 00080 QString format() const; 00081 00082 protected: 00083 void init( const KUrl &url, const QString &format ); 00084 00085 private Q_SLOTS: 00086 void downloadFinished( KJob *job ); 00087 void uploadFinished( KJob *job ); 00088 00089 private: 00090 bool clearAndLoad( QFile *file ); 00091 void saveToFile( QFile *file ); 00092 bool hasTempFile() const { return mTempFile != 0; } 00093 void abortAsyncLoading(); 00094 void abortAsyncSaving(); 00095 bool createLocalTempFile(); 00096 void deleteLocalTempFile(); 00097 void deleteStaleTempFile(); 00098 00099 Format *mFormat; 00100 QString mFormatName; 00101 00102 KUrl mUrl; 00103 KTemporaryFile *mTempFile; 00104 00105 class ResourceNetPrivate; 00106 ResourceNetPrivate *d; 00107 }; 00108 00109 } 00110 00111 #endif