summaryrefslogtreecommitdiffabout
path: root/kabc/key.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kabc/key.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kabc/key.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kabc/key.cpp160
1 files changed, 160 insertions, 0 deletions
diff --git a/kabc/key.cpp b/kabc/key.cpp
new file mode 100644
index 0000000..802424b
--- a/dev/null
+++ b/kabc/key.cpp
@@ -0,0 +1,160 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <kapplication.h>
29#include <klocale.h>
30
31#include "key.h"
32
33using namespace KABC;
34
35Key::Key( const QString &text, int type )
36 : mTextData( text ), mIsBinary( false ), mType( type )
37{
38 mId = KApplication::randomString(8);
39}
40
41Key::~Key()
42{
43}
44
45bool Key::operator==( const Key &k ) const
46{
47 if ( mIsBinary != k.mIsBinary ) return false;
48 if ( mIsBinary )
49 if ( mBinaryData != k.mBinaryData ) return false;
50 else
51 if ( mTextData != k.mTextData ) return false;
52 if ( mType != k.mType ) return false;
53 if ( mCustomTypeString != k.mCustomTypeString ) return false;
54
55 return true;
56}
57
58bool Key::operator!=( const Key &k ) const
59{
60 return !( k == *this );
61}
62
63void Key::setId( const QString &id )
64{
65 mId = id;
66}
67
68QString Key::id() const
69{
70 return mId;
71}
72
73void Key::setBinaryData( const QByteArray &binary )
74{
75 mBinaryData = binary;
76 mIsBinary = true;
77}
78
79QByteArray Key::binaryData() const
80{
81 return mBinaryData;
82}
83
84void Key::setTextData( const QString &text )
85{
86 mTextData = text;
87 mIsBinary = false;
88}
89
90QString Key::textData() const
91{
92 return mTextData;
93}
94
95bool Key::isBinary() const
96{
97 return mIsBinary;
98}
99
100void Key::setType( int type )
101{
102 mType = type;
103}
104
105void Key::setCustomTypeString( const QString &custom )
106{
107 mCustomTypeString = custom;
108}
109
110int Key::type() const
111{
112 return mType;
113}
114
115QString Key::customTypeString() const
116{
117 return mCustomTypeString;
118}
119
120Key::TypeList Key::typeList()
121{
122 TypeList list;
123 list << X509;
124 list << PGP;
125 list << Custom;
126
127 return list;
128}
129
130QString Key::typeLabel( int type )
131{
132 switch ( type ) {
133 case X509:
134 return i18n( "X509" );
135 break;
136 case PGP:
137 return i18n( "PGP" );
138 break;
139 case Custom:
140 return i18n( "Custom" );
141 break;
142 default:
143 return i18n( "Unknown type" );
144 break;
145 }
146}
147
148QDataStream &KABC::operator<<( QDataStream &s, const Key &key )
149{
150 return s << key.mId << key.mIsBinary << key.mTextData << key.mBinaryData <<
151 key.mCustomTypeString << key.mType;
152}
153
154QDataStream &KABC::operator>>( QDataStream &s, Key &key )
155{
156 s >> key.mId >> key.mIsBinary >> key.mTextData >> key.mBinaryData >>
157 key.mCustomTypeString >> key.mType;
158
159 return s;
160}