qtkeychain/keychain.cpp

78 lines
2.1 KiB
C++
Raw Normal View History

2011-10-27 16:15:46 +00:00
/******************************************************************************
* Copyright (C) 2011 Frank Osterfeld <frank.osterfeld@gmail.com> *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. For licensing and distribution *
* details, check the accompanying file 'COPYING'. *
*****************************************************************************/
2011-10-27 16:14:37 +00:00
#include "keychain.h"
#include "keychain_p.h"
2011-10-27 19:17:54 +00:00
using namespace QKeychain;
2011-10-27 16:15:46 +00:00
Keychain::Keychain( const QString& service )
: d( new Private( service ) )
{
}
2011-10-27 16:14:37 +00:00
2011-10-27 16:15:46 +00:00
Keychain::~Keychain() {
delete d;
2011-10-27 16:14:37 +00:00
}
2011-10-27 16:15:46 +00:00
QString Keychain::service() const {
return d->service;
2011-10-27 16:14:37 +00:00
}
2011-10-27 16:15:46 +00:00
Keychain::Error Keychain::error() const {
return d->error;
2011-10-27 16:14:37 +00:00
}
2011-10-27 16:15:46 +00:00
QString Keychain::errorString() const {
return d->errorString;
2011-10-27 16:14:37 +00:00
}
void Keychain::writePassword( const QString &key, const QString &password ) {
writeEntry( key, password.toUtf8() );
}
void Keychain::writeEntry( const QString& key, const QByteArray& ba ) {
2011-10-27 16:15:46 +00:00
QString err;
const Error ret = d->writeEntryImpl( key, ba, &err );
2011-10-27 16:15:46 +00:00
d->error = ret;
d->errorString = err;
2011-10-27 16:14:37 +00:00
}
QString Keychain::readPassword( const QString& key ) {
const QByteArray ba = readEntry( key );
return QString::fromUtf8( ba.constData(), ba.size() );
}
QByteArray Keychain::readEntry( const QString& key ) {
2011-10-27 16:15:46 +00:00
QString err;
QByteArray pw;
const Error ret = d->readEntryImpl( &pw, key, &err );
2011-10-27 16:15:46 +00:00
d->error = ret;
d->errorString = err;
if ( ret != NoError )
return QByteArray();
2011-10-27 16:15:46 +00:00
else
return pw;
}
2011-10-28 07:38:02 +00:00
bool Keychain::entryExists( const QString& key ) {
QString err;
bool exists = false;
const Error ret = d->entryExistsImpl( &exists, key, &err );
d->error = ret;
d->errorString = err;
return exists;
}
void Keychain::deleteEntry( const QString& key ) {
2011-10-27 16:15:46 +00:00
QString err;
const Error ret = d->deleteEntryImpl( key, &err );
2011-10-27 16:15:46 +00:00
d->error = ret;
d->errorString = err;
2011-10-27 16:14:37 +00:00
}