emailuis/nmailui/src/nmrecipientfield.cpp
changeset 43 99bcbff212ad
parent 40 2c62ef3caffd
child 44 c2d07d913565
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    20 static const double Un = 6.66;
    20 static const QString ContactsServiceName = "com.nokia.services.phonebookservices";
    21 static const double Margin = 2 * Un;
    21 static const QString ContactsInterfaceName = "Fetch";
       
    22 static const QString ContactsOperationName = "fetch(QString,QString,QString)";
       
    23 
    22 static const int MaxRows = 10000;
    24 static const int MaxRows = 10000;
    23 static const double LabelFieldWidth = 12.5 * Un;
       
    24 static const double ButtonWidth = 9.5 * Un;
       
    25 static const double FieldHeight = 5 * Un;
       
    26 static const char *ContactsServiceName = "com.nokia.services.phonebookservices";
       
    27 static const char *ContactsInterfaceName = "Fetch";
       
    28 static const char *ContactsOperationName = "fetch(QString,QString,QString)";
       
    29 
    25 
    30 /*!
    26 /*!
    31    widget is created using AD/docml
    27    widget is created using AD/docml
    32 */
    28 */
    33 NmRecipientField::NmRecipientField(const QString &labelString, QGraphicsItem *parent):
    29 NmRecipientField::NmRecipientField(
    34     HbWidget(parent),
    30         QObject *parent, HbDocumentLoader &docLoader, const QString &objPrefix):
       
    31     QObject(parent),
       
    32     mDocumentLoader(docLoader),
       
    33     mObjectPrefix(objPrefix),
    35     mLabel(NULL),
    34     mLabel(NULL),
    36     mRecipientsEditor(NULL),
    35     mRecipientsEditor(NULL),
    37     mLaunchContactsPickerButton(NULL),
    36     mLaunchContactsPickerButton(NULL)
    38     mOwned(true)
       
    39 {
    37 {
    40     //construct default ui.    
    38     NM_FUNCTION;
    41     mLayoutHorizontal = new QGraphicsLinearLayout(Qt::Horizontal);
    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"));
    42 
    43 
    43     mLabel = new HbLabel(labelString);
    44     mLabel = qobject_cast<HbLabel *>
    44     if (mLabel) {
    45         (mDocumentLoader.findWidget(mObjectPrefix + "Label"));
    45         mLayoutHorizontal->addItem(mLabel);
       
    46         mLabel->setPreferredWidth(LabelFieldWidth);
       
    47         mLabel->setFontSpec(HbFontSpec(HbFontSpec::Secondary));
       
    48     }
       
    49 
    46 
    50     mRecipientsEditor = new NmRecipientLineEdit();
    47     mRecipientsEditor = qobject_cast<NmRecipientLineEdit *>
    51     if (mRecipientsEditor) {
    48         (mDocumentLoader.findWidget(mObjectPrefix + "Edit"));
    52     	mLayoutHorizontal->addItem(mRecipientsEditor);
    49     mRecipientsEditor->setMaxRows(MaxRows);
    53         mRecipientsEditor->setMaxRows(MaxRows);
       
    54         mRecipientsEditor->setFontSpec(HbFontSpec(HbFontSpec::Secondary));
       
    55         mRecipientsEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    56         mRecipientsEditor->setMinimumHeight(FieldHeight);
       
    57         mRecipientsEditor->setPreferredHeight(FieldHeight);
       
    58         mRecipientsEditor->setMaximumHeight(FieldHeight);
       
    59     }
       
    60 
    50 
    61     mLaunchContactsPickerButton = new HbPushButton();
    51     mLaunchContactsPickerButton = qobject_cast<HbPushButton *>
    62     if (mLaunchContactsPickerButton) {
    52         (mDocumentLoader.findWidget(mObjectPrefix + "Button"));
    63     	mLayoutHorizontal->addItem(mLaunchContactsPickerButton);
       
    64     	mLayoutHorizontal->setAlignment(mLaunchContactsPickerButton, Qt::AlignTop);
       
    65         mLaunchContactsPickerButton->setPreferredHeight(FieldHeight);
       
    66         mLaunchContactsPickerButton->setPreferredWidth(ButtonWidth);
       
    67         mLaunchContactsPickerButton->setMaximumHeight(FieldHeight);
       
    68 
    53 
    69         mLaunchContactsPickerButton->setIcon(NmIcons::getIcon(NmIcons::NmIconContacts));
    54     mLaunchContactsPickerButton->setIcon(NmIcons::getIcon(NmIcons::NmIconContacts));
    70     }
       
    71 
       
    72     mLayoutHorizontal->setContentsMargins(0, 0, 0, 0);
       
    73     // Set the spacing between the line edit  and the Add button to
       
    74     mLayoutHorizontal->setItemSpacing(1, Un);
       
    75     // Set the spacing between the label and the line edit to 0.0
       
    76     mLayoutHorizontal->setItemSpacing(0, 0.0);
       
    77     
       
    78     this->setLayout(mLayoutHorizontal);
       
    79 
    55 
    80     createConnections();
    56     createConnections();
    81 }
    57 }
    82 
    58 
    83 /*!
    59 /*!
    84    Creates connections for this class items
    60    Creates connections for this class items
    85 */
    61 */
    86 void NmRecipientField::createConnections()
    62 void NmRecipientField::createConnections()
    87 {
    63 {
       
    64     NM_FUNCTION;
       
    65     
    88     connect(mRecipientsEditor, SIGNAL(textChanged(const QString &)),
    66     connect(mRecipientsEditor, SIGNAL(textChanged(const QString &)),
    89         this, SIGNAL(textChanged(const QString &)));
    67         this, SIGNAL(textChanged(const QString &)));
    90     connect(mRecipientsEditor, SIGNAL(cursorPositionChanged(int, int)),
    68     connect(mRecipientsEditor, SIGNAL(cursorPositionChanged(int, int)),
    91         this, SIGNAL(cursorPositionChanged(int, int)));
    69         this, SIGNAL(cursorPositionChanged(int, int)));
    92     connect(mRecipientsEditor, SIGNAL(editingFinished()),
    70     connect(mRecipientsEditor, SIGNAL(editingFinished()),
   105 /*!
    83 /*!
   106    Destructor
    84    Destructor
   107 */
    85 */
   108 NmRecipientField::~NmRecipientField()
    86 NmRecipientField::~NmRecipientField()
   109 {
    87 {
   110     if (mOwned)
    88     NM_FUNCTION;
   111     {
       
   112         if (mLaunchContactsPickerButton) {
       
   113             delete mLaunchContactsPickerButton;
       
   114             mLaunchContactsPickerButton = 0;
       
   115         }
       
   116         if (mRecipientsEditor) {
       
   117             delete mRecipientsEditor;
       
   118             mRecipientsEditor = 0;
       
   119         }
       
   120         if (mLabel) {
       
   121             delete mLabel;
       
   122             mLabel = 0;
       
   123         }
       
   124     }
       
   125 }
    89 }
   126 
    90 
   127 /*!
    91 /*!
   128    Widget height
    92    Widget height
   129 */
    93 */
   130 qreal NmRecipientField::height()
    94 qreal NmRecipientField::height()
   131 {
    95 {
   132     return mRecipientsEditor->geometry().height() + Margin;
    96     NM_FUNCTION;
       
    97     
       
    98     return mWidget->geometry().height();
   133 }
    99 }
   134 
   100 
   135 /*!
   101 /*!
   136    editor
   102    editor
   137 */
   103 */
   138 NmRecipientLineEdit *NmRecipientField::editor() const
   104 NmRecipientLineEdit *NmRecipientField::editor() const
   139 {
   105 {
       
   106     NM_FUNCTION;
       
   107     
   140     return mRecipientsEditor;
   108     return mRecipientsEditor;
   141 }
   109 }
   142 
   110 
   143 
   111 
   144 /*!
   112 /*!
   145    LineEdit contents
   113    LineEdit contents
   146 */
   114 */
   147 const QString NmRecipientField::text() const
   115 const QString NmRecipientField::text() const
   148 {
   116 {
       
   117     NM_FUNCTION;
       
   118     
   149     return mRecipientsEditor->text();
   119     return mRecipientsEditor->text();
   150 }
   120 }
   151 
   121 
   152 
   122 
   153 /*!
   123 /*!
   154    Slot setText
   124    Slot setText
   155 */
   125 */
   156 void NmRecipientField::setText(const QString &newText)
   126 void NmRecipientField::setText(const QString &newText)
   157 {
   127 {
       
   128     NM_FUNCTION;
       
   129     
   158     if (newText != mRecipientsEditor->text()) {
   130     if (newText != mRecipientsEditor->text()) {
   159         mRecipientsEditor->setText(newText);
   131         mRecipientsEditor->setText(newText);
   160         emit textChanged(newText);
   132         emit textChanged(newText);
   161     }
   133     }
   162 }
   134 }
   166 /*!
   138 /*!
   167    This Slot launches the contacts-picker
   139    This Slot launches the contacts-picker
   168 */
   140 */
   169 void NmRecipientField::launchContactsPicker()
   141 void NmRecipientField::launchContactsPicker()
   170 {
   142 {
       
   143     NM_FUNCTION;
       
   144     
   171     XQApplicationManager mAppmgr;
   145     XQApplicationManager mAppmgr;
   172     XQAiwRequest *launchContactsPickerRequest;
   146     XQAiwRequest *launchContactsPickerRequest;
   173     
   147     
   174     bool isEmbeded = true;
   148     bool isEmbeded = true;
   175     launchContactsPickerRequest = mAppmgr.create(ContactsServiceName, ContactsInterfaceName, 
   149     launchContactsPickerRequest = mAppmgr.create(ContactsServiceName, ContactsInterfaceName, 
   179         connect(launchContactsPickerRequest, SIGNAL(requestOk(QVariant)),
   153         connect(launchContactsPickerRequest, SIGNAL(requestOk(QVariant)),
   180                 mRecipientsEditor, SLOT(insertSelectedContacts(QVariant)));
   154                 mRecipientsEditor, SLOT(insertSelectedContacts(QVariant)));
   181     }
   155     }
   182     else {
   156     else {
   183         // Failed creating request 
   157         // Failed creating request 
   184         NMLOG("XQApplicationManager: failed creating fecth contactspicker request.");
   158         NM_ERROR(1,"XQApplicationManager: failed creating fecth contactspicker request");
   185 	    return;
   159 	    return;
   186     }
   160     }
   187 
   161 
       
   162     QVariantList args; 
       
   163     args << "Non-filtered multi-fetch";
       
   164     args << KCntActionAll; 
       
   165     args << KCntFilterDisplayAll; 
       
   166     launchContactsPickerRequest->setArguments(args); 
       
   167     
   188     // Send request
   168     // Send request
   189     if (!launchContactsPickerRequest->send()) {
   169     if (!launchContactsPickerRequest->send()) {
   190        //Failed sending request 
   170        //Failed sending request 
   191        NMLOG("XQApplicationManager: failed sending request.");
   171        NM_ERROR(1,"XQApplicationManager: failed sending request");
   192     }
   172     }
   193         
   173         
   194     delete launchContactsPickerRequest;
   174     delete launchContactsPickerRequest;
   195     launchContactsPickerRequest = 0;
   175     launchContactsPickerRequest = 0;
   196 }
   176 }