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( QLatin1Char(
'/') ) ) {
96 file += QLatin1Char(
'/');
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( QLatin1String(
"\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() ) ) {
147 content += it.key() + QLatin1String(
"\x02\x02") + it.value().toString() + QLatin1String(
"\x02\x02") +
fingerprint + QLatin1String(
"\r\n");
149 QTextStream ts( &file );
159 d->fingerprintMap.clear();
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() + QLatin1Char(
'\t') + it.value().toString() + QLatin1Char(
'\t') + fp + QLatin1String(
"\r\n");
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() );
bool save()
Saves the map.
QString remoteId(const QString &localId) const
Returns the remote id of the given local id.
IdMapper()
Create Id mapper.
QString fingerprint(const QString &localId) const
Returns the fingerprint for the map.
void setPath(const QString &path)
Set id map path.
void clear()
Clears the map.
bool load()
Loads the map.
QString filename()
Filename of the map when stored on disk.
void setIdentifier(const QString &identifier)
Set id map identifier.
void setRemoteId(const QString &localId, const QString &remoteId)
Stores the remote id for the given local id.
QString path() const
Return id map path.
QString identifier() const
Return id map identifier.
This file is part of the KDE resource framework and defines the IdMapper class.
void setFingerprint(const QString &localId, const QString &fingerprint)
Stores a fingerprint for an id which can be used to detect if the locally held version differs from w...
QString asString() const
Returns a string representation of the id pairs, that's useful for debugging.
QString localId(const QString &remoteId) const
Returns the local id for the given remote id.
void removeRemoteId(const QString &remoteId)
Removes the remote id.
QMap< QString, QString > remoteIdMap() const
Returns the entire map of local-to-remote Ids.