00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include <kapplication.h>
00022
#include <klocale.h>
00023
00024
#include "key.h"
00025
00026
using namespace KABC;
00027
00028 Key::Key(
const QString &text,
int type )
00029 : mTextData( text ), mIsBinary( false ), mType( type )
00030 {
00031 mId =
KApplication::randomString(8);
00032 }
00033
00034 Key::~Key()
00035 {
00036 }
00037
00038
bool Key::operator==(
const Key &k )
const
00039
{
00040
if ( mIsBinary != k.
mIsBinary )
return false;
00041
if ( mIsBinary )
00042
if ( mBinaryData != k.
mBinaryData )
return false;
00043
else
00044
if ( mTextData != k.
mTextData )
return false;
00045
if ( mType != k.
mType )
return false;
00046
if ( mCustomTypeString != k.
mCustomTypeString )
return false;
00047
00048
return true;
00049 }
00050
00051
bool Key::operator!=(
const Key &k )
const
00052
{
00053
return !( k == *
this );
00054 }
00055
00056 void Key::setId(
const QString &
id )
00057 {
00058 mId =
id;
00059 }
00060
00061 QString Key::id()
const
00062
{
00063
return mId;
00064 }
00065
00066 void Key::setBinaryData(
const QByteArray &binary )
00067 {
00068 mBinaryData = binary;
00069 mIsBinary =
true;
00070 }
00071
00072 QByteArray Key::binaryData()
const
00073
{
00074
return mBinaryData;
00075 }
00076
00077 void Key::setTextData(
const QString &text )
00078 {
00079 mTextData = text;
00080 mIsBinary =
false;
00081 }
00082
00083 QString Key::textData()
const
00084
{
00085
return mTextData;
00086 }
00087
00088 bool Key::isBinary()
const
00089
{
00090
return mIsBinary;
00091 }
00092
00093 void Key::setType(
int type )
00094 {
00095 mType = type;
00096 }
00097
00098 void Key::setCustomTypeString(
const QString &custom )
00099 {
00100 mCustomTypeString = custom;
00101 }
00102
00103 int Key::type()
const
00104
{
00105
return mType;
00106 }
00107
00108 QString Key::customTypeString()
const
00109
{
00110
return mCustomTypeString;
00111 }
00112
00113 Key::TypeList Key::typeList()
00114 {
00115
TypeList list;
00116 list << X509;
00117 list << PGP;
00118 list << Custom;
00119
00120
return list;
00121 }
00122
00123 QString Key::typeLabel(
int type )
00124 {
00125
switch ( type ) {
00126
case X509:
00127
return i18n(
"X509" );
00128
break;
00129
case PGP:
00130
return i18n(
"PGP" );
00131
break;
00132
case Custom:
00133
return i18n(
"Custom" );
00134
break;
00135
default:
00136
return i18n(
"Unknown type" );
00137
break;
00138 }
00139 }
00140
00141
QDataStream &KABC::operator<<(
QDataStream &s,
const Key &key )
00142 {
00143
return s << key.mId << key.mIsBinary << key.mTextData << key.mBinaryData <<
00144 key.mCustomTypeString << key.mType;
00145 }
00146
00147
QDataStream &KABC::operator>>(
QDataStream &s,
Key &key )
00148 {
00149 s >> key.mId >> key.mIsBinary >> key.mTextData >> key.mBinaryData >>
00150 key.mCustomTypeString >> key.mType;
00151
00152
return s;
00153 }