home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kabc / resourcefile.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-22  |  3.7 KB  |  163 lines

  1. /*
  2.     This file is part of libkabc.
  3.     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KABC_RESOURCEFILE_H
  22. #define KABC_RESOURCEFILE_H
  23.  
  24. #include <kconfig.h>
  25. #include <kdirwatch.h>
  26.  
  27. #include <sys/types.h>
  28.  
  29. #include <kabc/resource.h>
  30.  
  31. namespace KABC {
  32.  
  33. class FormatPlugin;
  34. class ResourceConfigWidget;
  35. class Lock;
  36.  
  37. /**
  38.   This resource allows access to a local file.
  39. */
  40. class KABC_EXPORT ResourceFile : public Resource
  41. {
  42.   Q_OBJECT
  43.  
  44.   public:
  45.     /**
  46.       Constructor.
  47.  
  48.       @param cfg The config object where custom resource settings are stored.
  49.      */
  50.     ResourceFile( const KConfig *cfg );
  51.  
  52.     /**
  53.       Construct file resource on file @arg fileName using format @arg formatName.
  54.      */
  55.     ResourceFile( const QString &fileName, const QString &formatName = "vcard" );
  56.  
  57.     /**
  58.       Destructor.
  59.      */
  60.     ~ResourceFile();
  61.  
  62.     /**
  63.       Writes the config back.
  64.      */
  65.     virtual void writeConfig( KConfig *cfg );
  66.  
  67.     /**
  68.       Tries to open the file and checks for the proper format.
  69.       This method should be called before load().
  70.      */
  71.     virtual bool doOpen();
  72.  
  73.     /**
  74.       Closes the file again.
  75.      */
  76.     virtual void doClose();
  77.  
  78.     /**
  79.       Requests a save ticket, that is used by save()
  80.      */
  81.     virtual Ticket *requestSaveTicket();
  82.  
  83.     virtual void releaseSaveTicket( Ticket* );
  84.  
  85.     /**
  86.       Loads all addressees from file to the address book.
  87.       Returns true if all addressees could be loaded otherwise false.
  88.      */
  89.     virtual bool load();
  90.  
  91.     virtual bool asyncLoad();
  92.  
  93.     /**
  94.       Saves all addresses from address book to file.
  95.       Returns true if all addressees could be saved otherwise false.
  96.  
  97.       @param ticket  The ticket returned by requestSaveTicket()
  98.      */
  99.     virtual bool save( Ticket *ticket );
  100.  
  101.     virtual bool asyncSave( Ticket *ticket );
  102.  
  103.     /**
  104.       Set name of file to be used for saving.
  105.      */
  106.     void setFileName( const QString & );
  107.  
  108.     /**
  109.       Return name of file used for loading and saving the address book.
  110.      */
  111.     QString fileName() const;
  112.  
  113.     /**
  114.       Sets a new format by name.
  115.      */
  116.     void setFormat( const QString &name );
  117.  
  118.     /**
  119.       Returns the format name.
  120.      */
  121.     QString format() const;
  122.  
  123.     /**
  124.       Remove a addressee from its source.
  125.       This method is mainly called by KABC::AddressBook.
  126.      */
  127.     virtual void removeAddressee( const Addressee& addr );
  128.  
  129.   private slots:
  130.     void emitLoadingFinished();
  131.     void emitLoadingError();
  132.     void emitSavingFinished();
  133.     void emitSavingError();
  134.  
  135.   protected slots:
  136.     void fileChanged();
  137.  
  138.   protected:
  139.     void init( const QString &fileName, const QString &format );
  140.  
  141.     bool lock( const QString &fileName );
  142.     void unlock( const QString &fileName );
  143.  
  144.   private:
  145.     QString mFileName;
  146.     QString mFormatName;
  147.  
  148.     FormatPlugin *mFormat;
  149.  
  150.     Lock *mLock;
  151.  
  152.     KDirWatch mDirWatch;
  153.  
  154.     bool mAsynchronous;
  155.  
  156.     class ResourceFilePrivate;
  157.     ResourceFilePrivate *d;
  158. };
  159.  
  160. }
  161.  
  162. #endif
  163.