36 #include <kstandarddirs.h>
39 #include <QtCore/QFile>
40 #include <QtCore/QTextStream>
41 #include <QtCore/QVariant>
48 QMap<QString, QVariant> idMap;
49 QMap<QString, QString> fingerprintMap;
56 : d( new IdMapperPrivate )
61 : d( new IdMapperPrivate )
94 QString file = d->path;
95 if ( !file.endsWith(
'/' ) ) {
98 file += d->identifier;
100 return KStandardDirs::locateLocal(
"data", file );
106 if ( !file.open( QIODevice::ReadOnly ) ) {
107 kError( 5800 ) <<
"Cannot read uid map file '" <<
filename() <<
"'";
113 QTextStream ts( &file );
115 while ( !ts.atEnd() ) {
116 line = ts.readLine( 1024 );
117 QStringList parts = line.split(
"\x02\x02", QString::KeepEmptyParts );
120 if ( parts.count() == 3 ) {
121 d->idMap.insert( parts[ 0 ], parts[ 1 ] );
122 d->fingerprintMap.insert( parts[ 0 ], parts[ 2 ] );
134 if ( !file.open( QIODevice::WriteOnly ) ) {
135 kError( 5800 ) <<
"Can't write uid map file '" <<
filename() <<
"'";
141 QMap<QString, QVariant>::Iterator it;
142 for ( it = d->idMap.begin(); it != d->idMap.end(); ++it ) {
144 if ( d->fingerprintMap.contains( it.key() ) ) {
145 fingerprint = d->fingerprintMap[ it.key() ];
147 content += it.key() +
"\x02\x02" + it.value().toString() +
"\x02\x02" + fingerprint +
"\r\n";
149 QTextStream ts( &file );
159 d->fingerprintMap.clear();
164 if ( !( localId.isEmpty() || remoteId.isEmpty() ) ) {
165 d->idMap.insert( localId, remoteId );
171 if ( !remoteId.isEmpty( ) ) {
172 QMap<QString, QVariant>::Iterator it;
173 for ( it = d->idMap.begin(); it != d->idMap.end(); ++it ) {
174 if ( it.value().toString() ==
remoteId ) {
176 QString key = it.key();
178 d->idMap.remove( key );
179 d->fingerprintMap.remove( key );
188 QMap<QString, QVariant>::ConstIterator it;
189 it = d->idMap.constFind( localId );
191 if ( it != d->idMap.constEnd() ) {
192 return it.value().toString();
200 QMap<QString, QVariant>::ConstIterator it;
201 for ( it = d->idMap.constBegin(); it != d->idMap.constEnd(); ++it ) {
202 if ( it.value().toString() ==
remoteId ) {
214 QMap<QString, QVariant>::ConstIterator it;
215 for ( it = d->idMap.constBegin(); it != d->idMap.constEnd(); ++it ) {
217 if ( d->fingerprintMap.contains( it.key() ) ) {
218 fp = d->fingerprintMap[ it.key() ];
220 content += it.key() +
'\t' + it.value().toString() +
'\t' + fp +
"\r\n";
228 if ( !( localId.isEmpty() || fingerprint.isEmpty() ) ) {
229 d->fingerprintMap.insert( localId, fingerprint );
235 if ( d->fingerprintMap.contains( localId ) ) {
236 return d->fingerprintMap[
localId ];
244 QMap<QString, QString> reverseMap;
245 QMap<QString, QVariant>::ConstIterator it;
246 for ( it = d->idMap.constBegin(); it != d->idMap.constEnd(); ++it ) {
247 reverseMap.insert( it.value().toString(), it.key() );