qtmobility/plugins/contacts/symbian/src/transform/cnttransformorganisation.cpp
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include "cnttransformorganisation.h"
       
    42 
       
    43 QList<CContactItemField *> CntTransformOrganisation::transformDetailL(const QContactDetail &detail)
       
    44 {
       
    45     if(detail.definitionName() != QContactOrganization::DefinitionName)
       
    46        User::Leave(KErrArgument);
       
    47 
       
    48     QList<CContactItemField *> fieldList;
       
    49 
       
    50 	//cast to orgenisation
       
    51     const QContactOrganization &orgDetails(static_cast<const QContactOrganization&>(detail));
       
    52 
       
    53     //create new fields without contexts
       
    54     transformToTextFieldL(orgDetails, fieldList, orgDetails.name(), KUidContactFieldCompanyName, KUidContactFieldVCardMapORG, false);
       
    55 	QStringList departments = orgDetails.department();
       
    56 	if(departments.count()) // Take only the first department
       
    57 	    transformToTextFieldL(orgDetails, fieldList, departments[0], KUidContactFieldDepartmentName, KUidContactFieldVCardMapDepartment, false);
       
    58 	transformToTextFieldL(orgDetails, fieldList, orgDetails.title(), KUidContactFieldJobTitle, KUidContactFieldVCardMapTITLE, false);
       
    59     transformToTextFieldL(orgDetails, fieldList, orgDetails.assistantName(), KUidContactFieldAssistant, KUidContactFieldVCardMapAssistant, false);
       
    60 
       
    61 	return fieldList;
       
    62 }
       
    63 
       
    64 
       
    65 QContactDetail *CntTransformOrganisation::transformItemField(const CContactItemField& field, const QContact &contact)
       
    66 {
       
    67     QContactOrganization *organisation = new QContactOrganization(contact.detail<QContactOrganization>());
       
    68 
       
    69 	CContactTextField* storage = field.TextStorage();
       
    70 	QString orgDetail = QString::fromUtf16(storage->Text().Ptr(), storage->Text().Length());
       
    71 
       
    72 	for (int i = 0; i < field.ContentType().FieldTypeCount(); i++) {
       
    73 		//Company
       
    74 		if (field.ContentType().FieldType(i) == KUidContactFieldCompanyName) {
       
    75             organisation->setName(orgDetail);
       
    76 		}
       
    77 		//Department
       
    78 		else if (field.ContentType().FieldType(i) == KUidContactFieldDepartmentName) {
       
    79 		    // Assume only a single department
       
    80 		    QStringList departments = QStringList(orgDetail);
       
    81             organisation->setDepartment(departments);
       
    82 		}
       
    83 		//Job title
       
    84 		else if (field.ContentType().FieldType(i) == KUidContactFieldJobTitle) {
       
    85             organisation->setTitle(orgDetail);
       
    86 		}
       
    87 	    //Assistant name
       
    88 	    else if (field.ContentType().FieldType(i) == KUidContactFieldAssistant) {
       
    89             organisation->setAssistantName(orgDetail);
       
    90 	    }
       
    91 	}
       
    92 
       
    93 	return organisation;
       
    94 }
       
    95 
       
    96 bool CntTransformOrganisation::supportsField(TUint32 fieldType) const
       
    97 {
       
    98     bool ret = false;
       
    99     if (fieldType == KUidContactFieldCompanyName.iUid ||
       
   100         fieldType == KUidContactFieldDepartmentName.iUid ||
       
   101         fieldType == KUidContactFieldJobTitle.iUid ||
       
   102         fieldType == KUidContactFieldAssistant.iUid) {
       
   103         ret = true;
       
   104     }
       
   105     return ret;
       
   106 }
       
   107 
       
   108 bool CntTransformOrganisation::supportsDetail(QString detailName) const
       
   109 {
       
   110     bool ret = false;
       
   111     if (detailName == QContactOrganization::DefinitionName) {
       
   112         ret = true;
       
   113     }
       
   114     return ret;
       
   115 }
       
   116 
       
   117 QList<TUid> CntTransformOrganisation::supportedSortingFieldTypes(QString detailFieldName) const
       
   118 {
       
   119     QList<TUid> uids;
       
   120 
       
   121     if (detailFieldName == QContactOrganization::FieldName)
       
   122         return uids << KUidContactFieldCompanyName;
       
   123 
       
   124     if (detailFieldName == QContactOrganization::FieldDepartment)
       
   125         return uids << KUidContactFieldDepartmentName;
       
   126 
       
   127     if (detailFieldName == QContactOrganization::FieldTitle)
       
   128         return uids << KUidContactFieldJobTitle;
       
   129 
       
   130     if (detailFieldName == QContactOrganization::FieldAssistantName)
       
   131         return uids << KUidContactFieldAssistant;
       
   132 
       
   133     return uids;
       
   134 }
       
   135 
       
   136 
       
   137 /*!
       
   138  * Checks whether the subtype is supported
       
   139  *
       
   140  * \a subType The subtype to be checked
       
   141  * \return True if this subtype is supported
       
   142  */
       
   143 bool CntTransformOrganisation::supportsSubType(const QString& subType) const
       
   144 {
       
   145     Q_UNUSED(subType);
       
   146     return false;
       
   147 }
       
   148 
       
   149 /*!
       
   150  * Returns the filed id corresponding to a field
       
   151  *
       
   152  * \a fieldName The name of the supported field
       
   153  * \return fieldId for the fieldName, 0  if not supported
       
   154  */
       
   155 quint32 CntTransformOrganisation::getIdForField(const QString& fieldName) const
       
   156 {
       
   157 
       
   158     if (QContactOrganization::FieldName  == fieldName)
       
   159         return KUidContactFieldCompanyName.iUid;
       
   160     else if (QContactOrganization::FieldLogo == fieldName)
       
   161         return 0;
       
   162     else if (QContactOrganization::FieldDepartment == fieldName)
       
   163         return KUidContactFieldDepartmentName.iUid;
       
   164     else if (QContactOrganization::FieldLocation == fieldName)
       
   165         return 0;
       
   166     else if (QContactOrganization::FieldTitle == fieldName)
       
   167         return KUidContactFieldJobTitle.iUid;
       
   168     else if (QContactOrganization::FieldAssistantName == fieldName)
       
   169         return KUidContactFieldAssistant.iUid;
       
   170     else
       
   171         return 0;
       
   172 
       
   173 }
       
   174 
       
   175 /*!
       
   176  * Modifies the detail definitions. The default detail definitions are
       
   177  * queried from QContactManagerEngine::schemaDefinitions and then modified
       
   178  * with this function in the transform leaf classes.
       
   179  *
       
   180  * \a definitions The detail definitions to modify.
       
   181  * \a contactType The contact type the definitions apply for.
       
   182  */
       
   183 void CntTransformOrganisation::detailDefinitions(QMap<QString, QContactDetailDefinition> &definitions, const QString& contactType) const
       
   184 {
       
   185     Q_UNUSED(contactType);
       
   186 
       
   187     if(definitions.contains(QContactOrganization::DefinitionName)) {
       
   188         QContactDetailDefinition d = definitions.value(QContactOrganization::DefinitionName);
       
   189         QMap<QString, QContactDetailFieldDefinition> fields = d.fields();
       
   190         QContactDetailFieldDefinition f;
       
   191 
       
   192         // Not all fields are supported, replace:
       
   193         fields.clear();
       
   194         f.setDataType(QVariant::String);
       
   195         f.setAllowableValues(QVariantList());
       
   196         fields.insert(QContactOrganization::FieldName, f);
       
   197         fields.insert(QContactOrganization::FieldTitle, f);
       
   198         fields.insert(QContactOrganization::FieldAssistantName, f);
       
   199         f.setDataType(QVariant::StringList);
       
   200         fields.insert(QContactOrganization::FieldDepartment, f);
       
   201 
       
   202         d.setFields(fields);
       
   203 
       
   204         // Replace original definitions
       
   205         definitions.insert(d.name(), d);
       
   206     }
       
   207 }