23 #include <klocalizedstring.h>
26 #include <QtCore/QDataStream>
27 #include <QtCore/QSharedData>
31 class Key::Private :
public QSharedData
35 : mId( KRandom::randomString( 8 ) )
39 Private(
const Private &other )
40 : QSharedData( other )
43 mBinaryData = other.mBinaryData;
44 mTextData = other.mTextData;
45 mCustomTypeString = other.mCustomTypeString;
46 mIsBinary = other.mIsBinary;
51 QByteArray mBinaryData;
53 QString mCustomTypeString;
78 if ( d->mId != other.d->mId ) {
82 if ( d->mType != other.d->mType ) {
86 if ( d->mIsBinary != other.d->mIsBinary ) {
91 if ( d->mBinaryData != other.d->mBinaryData ) {
95 if ( d->mTextData != other.d->mTextData ) {
100 if ( d->mCustomTypeString != other.d->mCustomTypeString ) {
109 return !( *
this == other );
114 if (
this != &other ) {
133 d->mBinaryData = binary;
139 return d->mBinaryData;
145 d->mIsBinary =
false;
165 d->mCustomTypeString = custom;
175 return d->mCustomTypeString;
182 str += QLatin1String(
"Key {\n" );
183 str += QString::fromLatin1(
" Id: %1\n" ).arg( d->mId );
184 str += QString::fromLatin1(
" Type: %1\n" ).arg(
typeLabel( d->mType ) );
185 if ( d->mType ==
Custom ) {
186 str += QString::fromLatin1(
" CustomType: %1\n" ).arg( d->mCustomTypeString );
188 str += QString::fromLatin1(
" IsBinary: %1\n" ).
189 arg( d->mIsBinary ? QLatin1String(
"true" ) : QLatin1String(
"false" ) );
190 if ( d->mIsBinary ) {
191 str += QString::fromLatin1(
" Binary: %1\n" ).
192 arg( QString::fromLatin1( d->mBinaryData.toBase64() ) );
194 str += QString::fromLatin1(
" Text: %1\n" ).arg( d->mTextData );
196 str += QLatin1String(
"}\n" );
205 if ( list.isEmpty() ) {
216 return i18nc(
"X.509 public key",
"X509" );
219 return i18nc(
"Pretty Good Privacy key",
"PGP" );
222 return i18nc(
"A custom key",
"Custom" );
225 return i18nc(
"another type of encryption key",
"Unknown type" );
230 QDataStream &KABC::operator<<( QDataStream &s,
const Key &key )
232 return s << key.d->mId << key.d->mType << key.d->mIsBinary << key.d->mBinaryData
233 << key.d->mTextData << key.d->mCustomTypeString;
236 QDataStream &KABC::operator>>( QDataStream &s,
Key &key )
239 s >> key.d->mId >> type >> key.d->mIsBinary >> key.d->mBinaryData >> key.d->mTextData
240 >> key.d->mCustomTypeString;
void setId(const QString &identifier)
Sets the unique identifier.
Key(const QString &text=QString(), Type type=PGP)
Creates a new key.
QString textData() const
Returns the text data.
void setBinaryData(const QByteArray &data)
Sets binary data.
void setTextData(const QString &data)
Sets text data.
static TypeList typeList()
Returns a list of all available key types.
QList< Type > TypeList
List of key types.
QByteArray binaryData() const
Returns the binary data.
A class to store an encryption key.
bool isBinary() const
Returns whether the key contains binary or text data.
Custom or IANA conform key.
static QString typeLabel(Type type)
Returns a translated label for a given key type.
QString toString() const
Returns a string representation of the key.
void setCustomTypeString(const QString &type)
Sets custom type string.
void setType(Type type)
Sets the type.
QString id() const
Returns the unique identifier.
Key & operator=(const Key &other)
Assignment operator.
QString customTypeString() const
Returns the custom type string.
Type type() const
Returns the type, see Type.
bool operator!=(const Key &) const
Not-equal operator.
bool operator==(const Key &) const
Equality operator.