plugins/declarative/contacts/qmlcontactdetail.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     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:BSD$
       
    10 ** You may use this file under the terms of the BSD license as follows:
       
    11 **
       
    12 ** "Redistribution and use in source and binary forms, with or without
       
    13 ** modification, are permitted provided that the following conditions are
       
    14 ** met:
       
    15 **   * Redistributions of source code must retain the above copyright
       
    16 **     notice, this list of conditions and the following disclaimer.
       
    17 **   * Redistributions in binary form must reproduce the above copyright
       
    18 **     notice, this list of conditions and the following disclaimer in
       
    19 **     the documentation and/or other materials provided with the
       
    20 **     distribution.
       
    21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
       
    22 **     the names of its contributors may be used to endorse or promote
       
    23 **     products derived from this software without specific prior written
       
    24 **     permission.
       
    25 **
       
    26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
       
    37 ** $QT_END_LICENSE$
       
    38 **
       
    39 ****************************************************************************/
       
    40 
       
    41 #include "qmlcontactdetail.h"
       
    42 #include "qmlcontactdetailfield.h"
       
    43 #include <QDebug>
       
    44 
       
    45 
       
    46 static QString ToContactDetailName(const QString& name)
       
    47 {
       
    48    if (!name.isEmpty())
       
    49      return name.mid(1).prepend(name[0].toUpper());
       
    50    return QString();
       
    51 }
       
    52 
       
    53 
       
    54 QMLContactDetail::QMLContactDetail(QObject* parent)
       
    55     :QObject(parent),
       
    56     m_detailChanged(false)
       
    57 {
       
    58 
       
    59 }
       
    60 
       
    61 QDeclarativePropertyMap* QMLContactDetail::propertyMap() const
       
    62 {
       
    63     return m_map;
       
    64 }
       
    65 void QMLContactDetail::setDetailPropertyMap(QDeclarativePropertyMap* map)
       
    66 {
       
    67     m_map = map;
       
    68     qWarning() << "detail:" << m_detailName << " has " << m_map->count() << " fields.";
       
    69     foreach (const QString& key, m_map->keys()) {
       
    70         QMLContactDetailField* field = new QMLContactDetailField(this);
       
    71         field->setDetailPropertyMap(m_map);
       
    72         field->setKey(key);
       
    73         m_fields.append(field);
       
    74         qWarning() << "    detail field:" << key  << "='" << m_map->value(key) << "'";
       
    75     }
       
    76 }
       
    77 
       
    78 QList<QObject*> QMLContactDetail::fields() const
       
    79 {
       
    80     return m_fields;
       
    81 }
       
    82 
       
    83 QString QMLContactDetail::name() const
       
    84 {
       
    85     return m_detailName;
       
    86 }
       
    87 
       
    88 void QMLContactDetail::setName(const QString& name)
       
    89 {
       
    90     m_detailName = name;
       
    91 }
       
    92 
       
    93 bool QMLContactDetail::detailChanged() const
       
    94 {
       
    95     return m_detailChanged;
       
    96 }
       
    97 
       
    98 QContactDetail QMLContactDetail::detail() const
       
    99 {
       
   100     QContactDetail d(ToContactDetailName(name()));
       
   101     foreach (const QString& key, m_map->keys()) {
       
   102         d.setValue(ToContactDetailName(key), m_map->value(key));
       
   103     }
       
   104     return d;
       
   105 }
       
   106 
       
   107 void QMLContactDetail::detailChanged(const QString &key, const QVariant &value)
       
   108 {
       
   109     qWarning() << "detailChanged field:"  << key << " value:" << value;
       
   110     m_detailChanged = true;
       
   111 }
       
   112 
       
   113 void QMLContactDetail::setDetailChanged(bool changed)
       
   114 {
       
   115     m_detailChanged = changed;
       
   116     emit onDetailChanged();
       
   117 }
       
   118