00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "entitydisplayattribute.h"
00021
00022 #include "imapparser_p.h"
00023
00024 #include <KIcon>
00025
00026 using namespace Akonadi;
00027
00028 class EntityDisplayAttribute::Private
00029 {
00030 public:
00031 Private() : hidden( false ) {}
00032 QString name;
00033 QString icon;
00034 QString activeIcon;
00035 QColor backgroundColor;
00036 bool hidden;
00037 };
00038
00039 EntityDisplayAttribute::EntityDisplayAttribute() :
00040 d( new Private )
00041 {
00042 }
00043
00044 EntityDisplayAttribute::~ EntityDisplayAttribute()
00045 {
00046 delete d;
00047 }
00048
00049 QString EntityDisplayAttribute::displayName() const
00050 {
00051 return d->name;
00052 }
00053
00054 void EntityDisplayAttribute::setDisplayName(const QString & name)
00055 {
00056 d->name = name;
00057 }
00058
00059 KIcon EntityDisplayAttribute::icon() const
00060 {
00061 return KIcon( d->icon );
00062 }
00063
00064 QString EntityDisplayAttribute::iconName() const
00065 {
00066 return d->icon;
00067 }
00068
00069 void EntityDisplayAttribute::setIconName(const QString & icon)
00070 {
00071 d->icon = icon;
00072 }
00073
00074 QByteArray Akonadi::EntityDisplayAttribute::type() const
00075 {
00076 return "ENTITYDISPLAY";
00077 }
00078
00079 EntityDisplayAttribute * EntityDisplayAttribute::clone() const
00080 {
00081 EntityDisplayAttribute *attr = new EntityDisplayAttribute();
00082 attr->d->name = d->name;
00083 attr->d->icon = d->icon;
00084 attr->d->activeIcon = d->activeIcon;
00085 attr->d->backgroundColor = d->backgroundColor;
00086 return attr;
00087 }
00088
00089 QByteArray EntityDisplayAttribute::serialized() const
00090 {
00091 QList<QByteArray> l;
00092 l << ImapParser::quote( d->name.toUtf8() );
00093 l << ImapParser::quote( d->icon.toUtf8() );
00094 l << ImapParser::quote( d->activeIcon.toUtf8() );
00095 QList<QByteArray> components;
00096 if ( d->backgroundColor.isValid() )
00097 {
00098 components = QList<QByteArray>() << QByteArray::number( d->backgroundColor.red() )
00099 << QByteArray::number( d->backgroundColor.green() )
00100 << QByteArray::number( d->backgroundColor.blue() )
00101 << QByteArray::number( d->backgroundColor.alpha() );
00102 }
00103 l << '(' + ImapParser::join( components, " " ) + ')';
00104 return '(' + ImapParser::join( l, " " ) + ')';
00105 }
00106
00107 void EntityDisplayAttribute::deserialize(const QByteArray &data)
00108 {
00109 QList<QByteArray> l;
00110 ImapParser::parseParenthesizedList( data, l );
00111 int size = l.size();
00112 Q_ASSERT( size >= 2 );
00113 d->name = QString::fromUtf8( l[0] );
00114 d->icon = QString::fromUtf8( l[1] );
00115 if ( size >= 3 ) {
00116 d->activeIcon = QString::fromUtf8( l[2] );
00117 }
00118 if ( size >= 4 )
00119 {
00120 if ( !l[3].isEmpty() )
00121 {
00122 QList<QByteArray> componentData;
00123 ImapParser::parseParenthesizedList( l[3], componentData );
00124 if ( componentData.size() != 4 )
00125 return;
00126 QList<int> components;
00127
00128 bool ok;
00129 for ( int i = 0; i <= 3; ++i )
00130 {
00131 components << componentData.at( i ).toInt( &ok );
00132 if ( !ok )
00133 return;
00134 }
00135 d->backgroundColor = QColor( components.at( 0 ), components.at( 1 ), components.at( 2 ), components.at( 3 ) );
00136 }
00137 }
00138 }
00139
00140 void EntityDisplayAttribute::setActiveIconName( const QString &name )
00141 {
00142 d->activeIcon = name;
00143 }
00144
00145 KIcon EntityDisplayAttribute::activeIcon() const
00146 {
00147 return KIcon( d->activeIcon );
00148 }
00149
00150 QString EntityDisplayAttribute::activeIconName() const
00151 {
00152 return d->activeIcon;
00153 }
00154
00155 QColor EntityDisplayAttribute::backgroundColor() const
00156 {
00157 return d->backgroundColor;
00158 }
00159
00160 void EntityDisplayAttribute::setBackgroundColor( const QColor &color )
00161 {
00162 d->backgroundColor = color;
00163 }
00164