TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

160 lines
4.0 KiB

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