25 #include <kstandarddirs.h> 37 : mPath( path ), mIdentifier( identifier )
57 TQString file = mPath;
58 if ( !file.endsWith(
"/" ) ) file +=
"/";
61 return locateLocal(
"data", file );
67 if ( !file.open( IO_ReadOnly ) ) {
68 kdError(5800) <<
"Can't read uid map file '" <<
filename() <<
"'" << endl;
75 while ( file.readLine( line, 1024 ) != -1 ) {
76 line.truncate( line.length() - 2 );
78 TQStringList parts = TQStringList::split(
"\x02\x02", line,
true );
79 mIdMap.insert( parts[ 0 ], parts[ 1 ] );
80 mFingerprintMap.insert( parts[ 0 ], parts[ 2 ] );
91 if ( !file.open( IO_WriteOnly ) ) {
92 kdError(5800) <<
"Can't write uid map file '" <<
filename() <<
"'" << endl;
98 TQStringVariantMap::Iterator it;
99 for ( it = mIdMap.begin(); it != mIdMap.end(); ++it ) {
101 if ( mFingerprintMap.contains( it.key() ) )
102 fingerprint = mFingerprintMap[ it.key() ];
103 content += it.key() +
"\x02\x02" + it.data().toString() +
"\x02\x02" + fingerprint +
"\r\n";
106 file.writeBlock( content.latin1(), tqstrlen( content.latin1() ) );
115 mFingerprintMap.clear();
120 mIdMap.replace( localId, remoteId );
125 TQStringVariantMap::Iterator it;
126 for ( it = mIdMap.begin(); it != mIdMap.end(); ++it )
127 if ( it.data().toString() ==
remoteId ) {
129 mFingerprintMap.remove( it.key() );
136 TQStringVariantMap::ConstIterator it;
137 it = mIdMap.find( localId );
139 if ( it != mIdMap.end() )
140 return it.data().toString();
147 TQStringVariantMap::ConstIterator it;
148 for ( it = mIdMap.begin(); it != mIdMap.end(); ++it )
149 if ( it.data().toString() ==
remoteId )
159 TQStringVariantMap::ConstIterator it;
160 for ( it = mIdMap.begin(); it != mIdMap.end(); ++it ) {
162 if ( mFingerprintMap.contains( it.key() ) )
163 fp = mFingerprintMap[ it.key() ];
164 content += it.key() +
"\t" + it.data().toString() +
"\t" + fp +
"\r\n";
172 mFingerprintMap.insert( localId, fingerprint );
177 if ( mFingerprintMap.contains( localId ) )
178 return mFingerprintMap[ localId ];
180 return TQString::null;
185 TQMap<TQString, TQString> reverseMap;
186 TQStringVariantMap::ConstIterator it;
187 for ( it = mIdMap.begin(); it != mIdMap.end(); ++it ) {
188 reverseMap.insert( it.data().toString(), it.key() );
TQString localId(const TQString &remoteId) const
Returns the local id for the given remote id.
bool save()
Saves the map.
TQString path() const
Return id map path.
const TQString & fingerprint(const TQString &localId) const
Returns the fingerprint for the map.
void setIdentifier(const TQString &identifier)
Set id map identifier.
IdMapper()
Create Id mapper.
void setFingerprint(const TQString &localId, const TQString &fingerprint)
Stores a fingerprint for an id which can be used to detect if the locally held version differs from w...
void setPath(const TQString &path)
Set id map path.
void clear()
Clears the map.
void removeRemoteId(const TQString &remoteId)
Removes the remote id.
TQString asString() const
Returns a string representation of the id pairs, that's usefull for debugging.
TQMap< TQString, TQString > remoteIdMap() const
Returns the entire map for the Id mapper.
void setRemoteId(const TQString &localId, const TQString &remoteId)
Stores the remote id for the given local id.
TQString remoteId(const TQString &localId) const
Returns the remote id of the given local id.
TQString filename()
Returns the filename this mapper is (or will be) stored in.
KPIM holds all kinds of functions specific to KDE PIM.
bool load()
Loads the map.
TQString identifier() const
Return id map identifier.