kabc
secrecy.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "secrecy.h"
00022
00023 #include <klocale.h>
00024
00025 #include <QtCore/QDataStream>
00026 #include <QtCore/QSharedData>
00027
00028 using namespace KABC;
00029
00030 class Secrecy::PrivateData : public QSharedData
00031 {
00032 public:
00033 PrivateData()
00034 : mType( Secrecy::Invalid )
00035 {
00036 }
00037
00038 PrivateData( const PrivateData &other )
00039 : QSharedData( other )
00040 {
00041 mType = other.mType;
00042 }
00043
00044 Type mType;
00045 };
00046
00047 Secrecy::Secrecy( Type type )
00048 : d( new PrivateData )
00049 {
00050 d->mType = type;
00051 }
00052
00053 Secrecy::Secrecy( const Secrecy &other )
00054 : d( other.d )
00055 {
00056 }
00057
00058 Secrecy::~Secrecy()
00059 {
00060 }
00061
00062 Secrecy &Secrecy::operator=( const Secrecy &other )
00063 {
00064 if ( this != &other ) {
00065 d = other.d;
00066 }
00067
00068 return *this;
00069 }
00070
00071 bool Secrecy::operator==( const Secrecy &other ) const
00072 {
00073 return d->mType == other.d->mType;
00074 }
00075
00076 bool Secrecy::operator!=( const Secrecy &other ) const
00077 {
00078 return !( *this == other );
00079 }
00080
00081 bool Secrecy::isValid() const
00082 {
00083 return d->mType != Invalid;
00084 }
00085
00086 void Secrecy::setType( Type type )
00087 {
00088 d->mType = type;
00089 }
00090
00091 Secrecy::Type Secrecy::type() const
00092 {
00093 return d->mType;
00094 }
00095
00096 Secrecy::TypeList Secrecy::typeList()
00097 {
00098 static TypeList list;
00099
00100 if ( list.isEmpty() ) {
00101 list << Public << Private << Confidential;
00102 }
00103
00104 return list;
00105 }
00106
00107 QString Secrecy::typeLabel( Type type )
00108 {
00109 switch ( type ) {
00110 case Public:
00111 return i18nc( "access is for everyone", "Public" );
00112 break;
00113 case Private:
00114 return i18nc( "access is by owner only", "Private" );
00115 break;
00116 case Confidential:
00117 return i18nc( "access is by owner and a controlled group", "Confidential" );
00118 break;
00119 default:
00120 return i18nc( "unknown secrecy type", "Unknown type" );
00121 break;
00122 }
00123 }
00124
00125 QString Secrecy::toString() const
00126 {
00127 QString str;
00128
00129 str += QString( "Secrecy {\n" );
00130 str += QString( " Type: %1\n" ).arg( typeLabel( d->mType ) );
00131 str += QString( "}\n" );
00132
00133 return str;
00134 }
00135
00136 QDataStream &KABC::operator<<( QDataStream &s, const Secrecy &secrecy )
00137 {
00138 return s << (uint)secrecy.d->mType;
00139 }
00140
00141 QDataStream &KABC::operator>>( QDataStream &s, Secrecy &secrecy )
00142 {
00143 uint type;
00144 s >> type;
00145
00146 switch ( type ) {
00147 case 0:
00148 secrecy.d->mType = Secrecy::Public;
00149 break;
00150 case 1:
00151 secrecy.d->mType = Secrecy::Private;
00152 break;
00153 case 2:
00154 secrecy.d->mType = Secrecy::Confidential;
00155 break;
00156 default:
00157 secrecy.d->mType = Secrecy::Invalid;
00158 break;
00159 }
00160
00161 return s;
00162 }