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 / libemailfunctions / idmapper.h
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.0 KB  |  160 lines

  1. /*
  2.     This file is part of kdepim.
  3.  
  4.     Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
  5.     Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
  6.  
  7.     This library is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU Library General Public
  9.     License as published by the Free Software Foundation; either
  10.     version 2 of the License, or (at your option) any later version.
  11.  
  12.     This library is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     Library General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU Library General Public License
  18.     along with this library; see the file COPYING.LIB.  If not, write to
  19.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20.     Boston, MA 02110-1301, USA.
  21. */
  22. #ifndef KPIM_IDMAPPER_H
  23. #define KPIM_IDMAPPER_H
  24.  
  25. #include <qmap.h>
  26. #include <qvariant.h>
  27.  
  28. #include <kdepimmacros.h>
  29.  
  30. namespace KPIM {
  31.  
  32. /**
  33.     An Id Mapper maps Ids. What to or what for is not entirely
  34.     clear, but maps have categories. This is probably an
  35.     adjoint functor, since adjoint functors are everywhere.
  36. */
  37. class KDE_EXPORT IdMapper
  38. {
  39.   public:
  40.     /**
  41.       Create Id mapper. You have to set path and identifier before you can call
  42.       load() or save().
  43.     */
  44.     IdMapper();
  45.     /**
  46.       Create Id mapper. The path specifies the category of mapping, the
  47.       identifier the concrete object.
  48.       
  49.       If you don't pass an identifier you have to set it before calling load()
  50.       or save().
  51.       
  52.       The current implementation stores the data at
  53.       $(KDEHOME)/share/apps/\<path\>/\<identifier\>.
  54.     */
  55.     IdMapper( const QString &path, const QString &identifier = QString::null );
  56.     /** Destructor. */
  57.     ~IdMapper();
  58.  
  59.     /**
  60.       Set id map path.
  61.     */
  62.     void setPath( const QString &path );
  63.     /**
  64.       Return id map path.
  65.     */
  66.     QString path() const { return mPath; }
  67.  
  68.     /**
  69.       Set id map identifier.
  70.     */
  71.     void setIdentifier( const QString &identifier );
  72.     /**
  73.       Return id map identifier.
  74.     */
  75.     QString identifier() const { return mIdentifier; }
  76.  
  77.     /**
  78.       Loads the map.
  79.      */
  80.     bool load();
  81.  
  82.     /**
  83.       Saves the map.
  84.      */
  85.     bool save();
  86.  
  87.     /**
  88.       Clears the map.
  89.      */
  90.     void clear();
  91.  
  92.     /**
  93.       Stores the remote id for the given local id.
  94.      */
  95.     void setRemoteId( const QString &localId, const QString &remoteId );
  96.  
  97.     /**
  98.       Removes the remote id.
  99.      */
  100.     void removeRemoteId( const QString &remoteId );
  101.  
  102.     /**
  103.       Returns the remote id of the given local id.
  104.      */
  105.     QString remoteId( const QString &localId ) const;
  106.  
  107.     /**
  108.       Returns the local id for the given remote id.
  109.      */
  110.     QString localId( const QString &remoteId ) const;
  111.  
  112.  
  113.     /**
  114.      * Stores a fingerprint for an id which can be used to detect if 
  115.      * the locally held version differs from what is on the server.
  116.      * This can be a sequence number of an md5 hash depending on what
  117.      * the server provides
  118.      */
  119.     void setFingerprint( const QString &localId, const QString &fingerprint );
  120.  
  121.     /**
  122.      * Returns the fingerprint for the map.
  123.      *
  124.      * @todo Figure out if this applies to the last set fingerprint
  125.      *       or if anything else can change it.
  126.      */
  127.     const QString &fingerprint( const QString &localId ) const;
  128.  
  129.  
  130.     /**
  131.      * Returns the entire map for the Id mapper.
  132.      *
  133.      * @todo Document what the map means.
  134.      */
  135.     QMap<QString, QString> remoteIdMap() const;
  136.  
  137.     /**
  138.      * Returns a string representation of the id pairs, that's usefull
  139.      * for debugging.
  140.      */
  141.     QString asString() const;
  142.  
  143.   protected:
  144.     /**
  145.      * Returns the filename this mapper is (or will be) stored in.
  146.      */
  147.     QString filename();
  148.  
  149.   private:
  150.     QMap<QString, QVariant> mIdMap;
  151.     QMap<QString, QString> mFingerprintMap;
  152.  
  153.     QString mPath;
  154.     QString mIdentifier;
  155. };
  156.  
  157. }
  158.  
  159. #endif
  160.