akonadi
contactmetadata.cpp
00001 /* 00002 This file is part of Akonadi Contact. 00003 00004 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org> 00005 00006 This library is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU Library General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to the 00018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 02110-1301, USA. 00020 */ 00021 00022 #include "contactmetadata_p.h" 00023 00024 #include "contactmetadataattribute_p.h" 00025 00026 #include <akonadi/item.h> 00027 00028 using namespace Akonadi; 00029 00030 class ContactMetaData::Private 00031 { 00032 public: 00033 Private() 00034 : mDisplayNameMode( -1 ) 00035 { 00036 } 00037 00038 int mDisplayNameMode; 00039 QVariantList mCustomFieldDescriptions; 00040 }; 00041 00042 ContactMetaData::ContactMetaData() 00043 : d( new Private ) 00044 { 00045 } 00046 00047 ContactMetaData::~ContactMetaData() 00048 { 00049 delete d; 00050 } 00051 00052 void ContactMetaData::load( const Akonadi::Item &contact ) 00053 { 00054 if ( !contact.hasAttribute( "contactmetadata" ) ) 00055 return; 00056 00057 ContactMetaDataAttribute *attribute = contact.attribute<ContactMetaDataAttribute>(); 00058 const QVariantMap metaData = attribute->metaData(); 00059 00060 if ( metaData.contains( QLatin1String( "DisplayNameMode" ) ) ) 00061 d->mDisplayNameMode = metaData.value( QLatin1String( "DisplayNameMode" ) ).toInt(); 00062 else 00063 d->mDisplayNameMode = -1; 00064 00065 d->mCustomFieldDescriptions = metaData.value( QLatin1String( "CustomFieldDescriptions" ) ).toList(); 00066 } 00067 00068 void ContactMetaData::store( Akonadi::Item &contact ) 00069 { 00070 ContactMetaDataAttribute *attribute = contact.attribute<ContactMetaDataAttribute>( Item::AddIfMissing ); 00071 00072 QVariantMap metaData; 00073 if ( d->mDisplayNameMode != -1 ) 00074 metaData.insert( QLatin1String( "DisplayNameMode" ), QVariant( d->mDisplayNameMode ) ); 00075 00076 if ( !d->mCustomFieldDescriptions.isEmpty() ) 00077 metaData.insert( QLatin1String( "CustomFieldDescriptions" ), d->mCustomFieldDescriptions ); 00078 00079 attribute->setMetaData( metaData ); 00080 } 00081 00082 void ContactMetaData::setDisplayNameMode( int mode ) 00083 { 00084 d->mDisplayNameMode = mode; 00085 } 00086 00087 int ContactMetaData::displayNameMode() const 00088 { 00089 return d->mDisplayNameMode; 00090 } 00091 00092 void ContactMetaData::setCustomFieldDescriptions( const QVariantList &descriptions ) 00093 { 00094 d->mCustomFieldDescriptions = descriptions; 00095 } 00096 00097 QVariantList ContactMetaData::customFieldDescriptions() const 00098 { 00099 return d->mCustomFieldDescriptions; 00100 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:31 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:31 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.