emailuis/nmailui/src/nmrecipientfield.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     1 /*
       
     2 * Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "nmuiheaders.h"
       
    19 
       
    20 static const QString NmContactsServiceName = "phonebookservices";
       
    21 static const QString NmContactsInterfaceName = "com.nokia.symbian.IContactsFetch";
       
    22 static const QString NmContactsOperationName = "multiFetch(QString,QString)";
       
    23 
       
    24 static const int NmMaxRows = 10000;
       
    25 
       
    26 /*!
       
    27    widget is created using AD/docml
       
    28 */
       
    29 NmRecipientField::NmRecipientField(
       
    30         QObject *parent, HbDocumentLoader &docLoader, const QString &objPrefix):
       
    31     QObject(parent),
       
    32     mDocumentLoader(docLoader),
       
    33     mObjectPrefix(objPrefix),
       
    34     mLabel(NULL),
       
    35     mRecipientsEditor(NULL),
       
    36     mLaunchContactsPickerButton(NULL)
       
    37 {
       
    38     NM_FUNCTION;
       
    39 
       
    40     // Load the widgets from nmeditorview.docml. The names match to the definitions in that docml.
       
    41     mWidget = qobject_cast<HbWidget *>
       
    42         (mDocumentLoader.findWidget(mObjectPrefix + "Field"));
       
    43 
       
    44     mLabel = qobject_cast<HbLabel *>
       
    45         (mDocumentLoader.findWidget(mObjectPrefix + "Label"));
       
    46 
       
    47     mRecipientsEditor = qobject_cast<NmRecipientLineEdit *>
       
    48         (mDocumentLoader.findWidget(mObjectPrefix + "Edit"));
       
    49     if (mRecipientsEditor) {
       
    50         mRecipientsEditor->setMaxRows(NmMaxRows);
       
    51     }
       
    52 
       
    53     mLaunchContactsPickerButton = qobject_cast<HbPushButton *>
       
    54         (mDocumentLoader.findWidget(mObjectPrefix + "Button"));
       
    55     if (mLaunchContactsPickerButton) {
       
    56         mLaunchContactsPickerButton->setIcon(NmIcons::getIcon(NmIcons::NmIconContacts));
       
    57     }
       
    58 
       
    59     createConnections();
       
    60 }
       
    61 
       
    62 /*!
       
    63    Creates connections for this class items
       
    64 */
       
    65 void NmRecipientField::createConnections()
       
    66 {
       
    67     NM_FUNCTION;
       
    68 
       
    69     connect(mRecipientsEditor, SIGNAL(textChanged(const QString &)),
       
    70         this, SIGNAL(textChanged(const QString &)));
       
    71     connect(mRecipientsEditor, SIGNAL(cursorPositionChanged(int, int)),
       
    72         this, SIGNAL(cursorPositionChanged(int, int)));
       
    73     connect(mRecipientsEditor, SIGNAL(editingFinished()),
       
    74         this, SIGNAL(editingFinished()));
       
    75     connect(mRecipientsEditor, SIGNAL(selectionChanged()),
       
    76         this, SIGNAL(selectionChanged()));
       
    77     connect(mLaunchContactsPickerButton, SIGNAL(pressed()),
       
    78             this, SIGNAL(launchContactsPickerButtonClicked()));
       
    79     connect(mLaunchContactsPickerButton, SIGNAL(pressed()),
       
    80             this, SLOT(launchContactsPicker()));
       
    81 }
       
    82 
       
    83 
       
    84 /*!
       
    85    Destructor
       
    86 */
       
    87 NmRecipientField::~NmRecipientField()
       
    88 {
       
    89     NM_FUNCTION;
       
    90 }
       
    91 
       
    92 /*!
       
    93    Widget height
       
    94 */
       
    95 qreal NmRecipientField::height()
       
    96 {
       
    97     NM_FUNCTION;
       
    98 
       
    99     return mWidget->geometry().height();
       
   100 }
       
   101 
       
   102 /*!
       
   103    editor
       
   104 */
       
   105 NmRecipientLineEdit *NmRecipientField::editor() const
       
   106 {
       
   107     NM_FUNCTION;
       
   108 
       
   109     return mRecipientsEditor;
       
   110 }
       
   111 
       
   112 
       
   113 /*!
       
   114    LineEdit contents
       
   115 */
       
   116 const QString NmRecipientField::text() const
       
   117 {
       
   118     NM_FUNCTION;
       
   119 
       
   120     return mRecipientsEditor->text();
       
   121 }
       
   122 
       
   123 
       
   124 /*!
       
   125    Slot setText
       
   126 */
       
   127 void NmRecipientField::setText(const QString &newText)
       
   128 {
       
   129     NM_FUNCTION;
       
   130 
       
   131     if (newText != mRecipientsEditor->text()) {
       
   132         mRecipientsEditor->setText(newText);
       
   133         emit textChanged(newText);
       
   134     }
       
   135 }
       
   136 
       
   137 
       
   138 /*!
       
   139    This Slot launches the contacts-picker
       
   140 */
       
   141 void NmRecipientField::launchContactsPicker()
       
   142 {
       
   143     NM_FUNCTION;
       
   144 
       
   145     XQApplicationManager mAppmgr;
       
   146     XQAiwRequest *launchContactsPickerRequest;
       
   147 
       
   148     bool isEmbeded = true;
       
   149     launchContactsPickerRequest = mAppmgr.create(NmContactsServiceName, NmContactsInterfaceName,
       
   150                                                  NmContactsOperationName, isEmbeded);
       
   151 
       
   152     if (launchContactsPickerRequest) {
       
   153         connect(launchContactsPickerRequest, SIGNAL(requestOk(QVariant)),
       
   154                 mRecipientsEditor, SLOT(addSelectedContacts(QVariant)));
       
   155     }
       
   156     else {
       
   157         // Failed creating request
       
   158         NM_ERROR(1,"XQApplicationManager: failed creating fecth contactspicker request");
       
   159 	    return;
       
   160     }
       
   161 
       
   162     QVariantList args;
       
   163     args << hbTrId("txt_mail_select_contacts");
       
   164     args << KCntActionEmail;
       
   165     launchContactsPickerRequest->setArguments(args);
       
   166 
       
   167     // Send request
       
   168     if (!launchContactsPickerRequest->send()) {
       
   169        //Failed sending request
       
   170        NM_ERROR(1,"XQApplicationManager: failed sending request");
       
   171     }
       
   172 
       
   173     delete launchContactsPickerRequest;
       
   174     launchContactsPickerRequest = NULL;
       
   175 }