messagingapp/msgui/unifiededitor/src/msgunieditoraddress.cpp
author hgs
Fri, 09 Jul 2010 14:46:10 +0530
changeset 41 25fe1fe642e3
parent 38 4e4b6adb1024
child 48 4f501b74aeb1
permissions -rw-r--r--
201027_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
 * All rights reserved.
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
 * Initial Contributors:
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
 * Contributors:
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
 * Description:
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
 */
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
// INCLUDES
37
hgs
parents: 25
diff changeset
    19
#include <QTimer>
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
#include <HbTextItem>
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
#include <HbPushButton>
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include <HbAction>
37
hgs
parents: 25
diff changeset
    23
#include <hbmessagebox.h>
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include <cntservicescontact.h>
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    25
#include <xqaiwrequest.h>
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    26
#include <xqappmgr.h>
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    27
#include <telconfigcrkeys.h>        // KCRUidTelephonyConfiguration
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    28
#include <centralrepository.h>
37
hgs
parents: 25
diff changeset
    29
#include <HbNotificationDialog>
hgs
parents: 25
diff changeset
    30
#include <commonphoneparser.h>      // Common phone number validity checker
hgs
parents: 25
diff changeset
    31
#include <xqconversions.h>
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
// USER INCLUDES
37
hgs
parents: 25
diff changeset
    34
#include "debugtraces.h"
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
#include "msgunieditoraddress.h"
37
hgs
parents: 25
diff changeset
    36
#include "msgunieditorlineedit.h"
hgs
parents: 25
diff changeset
    37
#include "msgunieditormonitor.h"
hgs
parents: 25
diff changeset
    38
#include "UniEditorGenUtils.h"
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    40
const QString PBK_ICON("qtg_mono_contacts");
37
hgs
parents: 25
diff changeset
    41
const QString REPLACEMENT_STR("; ");
hgs
parents: 25
diff changeset
    42
const QString COMMA_SEPERATOR(",");
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
// Constants
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    45
const int KDefaultGsmNumberMatchLength = 7;  //matching unique ph numbers
37
hgs
parents: 25
diff changeset
    46
#define LOC_SMS_RECIPIENT_LIMIT_REACHED hbTrId("txt_messaging_dialog_number_of_recipients_exceeded")
hgs
parents: 25
diff changeset
    47
#define LOC_MMS_RECIPIENT_LIMIT_REACHED hbTrId("txt_messaging_dpopinfo_unable_to_add_more_recipien")
hgs
parents: 25
diff changeset
    48
#define LOC_DIALOG_OK hbTrId("txt_common_button_ok")
hgs
parents: 25
diff changeset
    49
#define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
hgs
parents: 25
diff changeset
    50
#define LOC_INVALID_RECIPIENT hbTrId("txt_messaging_dialog_invalid_recipient_found")
hgs
parents: 25
diff changeset
    51
#define LOC_INVALID_RECIPIENT_NOT_ADDED hbTrId("txt_messaging_dialog_invalid_recipient_not_added")
hgs
parents: 25
diff changeset
    52
#define LOC_INVALID_RECIPIENTS_NOT_ADDED hbTrId("txt_messaging_dialog_invalid_recipients_not_added")
hgs
parents: 25
diff changeset
    53
hgs
parents: 25
diff changeset
    54
hgs
parents: 25
diff changeset
    55
hgs
parents: 25
diff changeset
    56
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
MsgUnifiedEditorAddress::MsgUnifiedEditorAddress( const QString& label,
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
                                                  QGraphicsItem *parent ) :
37
hgs
parents: 25
diff changeset
    60
MsgUnifiedEditorBaseWidget(parent),
hgs
parents: 25
diff changeset
    61
mSkipMaxRecipientQuery(false),
hgs
parents: 25
diff changeset
    62
mAboutToExceedMaxSmsRecipients(false),
hgs
parents: 25
diff changeset
    63
mAboutToExceedMaxMmsRecipients(false),
hgs
parents: 25
diff changeset
    64
mExceedsMaxMmsRecipientsBy(0)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
{
37
hgs
parents: 25
diff changeset
    66
    this->setContentsMargins(0,0,0,0);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
    mLaunchBtn = new HbPushButton(this);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
    HbStyle::setItemName(mLaunchBtn,"launchBtn");
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    70
    connect(mLaunchBtn,SIGNAL(clicked()),this,SLOT(fetchContacts()));
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
    mLaunchBtn->setIcon(HbIcon(PBK_ICON));
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
    mAddressEdit = new MsgUnifiedEditorLineEdit(label,this);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
    HbStyle::setItemName(mAddressEdit,"addressField");
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
    mAddressEdit->setMaxRows(40);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    78
    connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
37
hgs
parents: 25
diff changeset
    79
            this, SLOT(onContentsChanged(const QString&)));
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    81
    mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers);
37
hgs
parents: 25
diff changeset
    82
}
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    84
MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress()
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
{
37
hgs
parents: 25
diff changeset
    86
	//TODO: Should remove this code depending on orbit's reply whether it is needed
hgs
parents: 25
diff changeset
    87
	//to unregister the same plugin registered on two different widgets twice.
hgs
parents: 25
diff changeset
    88
    //style()->unregisterPlugin(mPluginPath);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    89
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    90
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    91
void MsgUnifiedEditorAddress::fetchContacts()
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    92
{
37
hgs
parents: 25
diff changeset
    93
    mLaunchBtn->blockSignals(true);
hgs
parents: 25
diff changeset
    94
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    95
    QList<QVariant> args;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    96
    QString serviceName("com.nokia.services.phonebookservices");
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    97
    QString operation("fetch(QString,QString,QString)");
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    98
    XQAiwRequest* request;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    99
    XQApplicationManager appManager;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   100
    request = appManager.create(serviceName, "Fetch", operation, true); // embedded
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   101
    if ( request == NULL )
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   102
        {
37
hgs
parents: 25
diff changeset
   103
        return;
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   104
        }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   105
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   106
    // Result handlers
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   107
    connect (request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   108
    connect (request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
37
hgs
parents: 25
diff changeset
   109
hgs
parents: 25
diff changeset
   110
    args << QString(tr("Phonebook"));
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   111
    args << KCntActionAll;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   112
    args << KCntFilterDisplayAll;
37
hgs
parents: 25
diff changeset
   113
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   114
    request->setArguments(args);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   115
    request->send();
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   116
    delete request;
37
hgs
parents: 25
diff changeset
   117
hgs
parents: 25
diff changeset
   118
    //unblock click signal after some delay.
hgs
parents: 25
diff changeset
   119
    QTimer::singleShot(250,this,SLOT(unblockSignals()));
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   120
}
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   121
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   122
void MsgUnifiedEditorAddress::handleOk(const QVariant& value)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
{
37
hgs
parents: 25
diff changeset
   124
   CntServicesContactList contactList =
hgs
parents: 25
diff changeset
   125
           qVariantValue<CntServicesContactList>(value);
hgs
parents: 25
diff changeset
   126
    int count = contactList.count();
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   127
37
hgs
parents: 25
diff changeset
   128
    ConvergedMessageAddressList addrlist;
hgs
parents: 25
diff changeset
   129
    for(int i = 0; i < count; i++ )
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   130
    {
37
hgs
parents: 25
diff changeset
   131
        ConvergedMessageAddress* address =
hgs
parents: 25
diff changeset
   132
                new ConvergedMessageAddress();
hgs
parents: 25
diff changeset
   133
        if(!contactList[i].mPhoneNumber.isEmpty())
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   134
        {
37
hgs
parents: 25
diff changeset
   135
            address->setAddress(contactList[i].mPhoneNumber);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   136
        }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
        else
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   138
        {
37
hgs
parents: 25
diff changeset
   139
            address->setAddress(contactList[i].mEmailAddress);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   140
        }
37
hgs
parents: 25
diff changeset
   141
        address->setAlias(contactList[i].mDisplayName);
hgs
parents: 25
diff changeset
   142
        addrlist << address;
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
    }
37
hgs
parents: 25
diff changeset
   144
    setAddresses(addrlist);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   146
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   147
void MsgUnifiedEditorAddress::handleError(int errorCode, const QString& errorMessage)
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   148
{
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   149
    Q_UNUSED(errorMessage)
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   150
    Q_UNUSED(errorCode)
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   151
}
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   152
37
hgs
parents: 25
diff changeset
   153
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   154
// MsgUnifiedEditorAddress::addresses
hgs
parents: 25
diff changeset
   155
// @see header
hgs
parents: 25
diff changeset
   156
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   157
ConvergedMessageAddressList MsgUnifiedEditorAddress::addresses(
hgs
parents: 25
diff changeset
   158
        bool removeDuplicates)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   159
{
37
hgs
parents: 25
diff changeset
   160
#ifdef _DEBUG_TRACES_
hgs
parents: 25
diff changeset
   161
    qCritical() << "MsgUnifiedEditorAddress::addresses start";
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
#endif
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
    // sync-up map to account for user-actions on edit-field
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
    syncDeletionsToMap();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
    syncAdditionsToMap();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
    ConvergedMessageAddressList addresses;
37
hgs
parents: 25
diff changeset
   168
    if(removeDuplicates)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
    {
37
hgs
parents: 25
diff changeset
   170
        QStringList uniqueAddr;
hgs
parents: 25
diff changeset
   171
        uniqueAddr = uniqueAddressList();
hgs
parents: 25
diff changeset
   172
        foreach(QString addr, uniqueAddr)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   173
        {
37
hgs
parents: 25
diff changeset
   174
            ConvergedMessageAddress* address = new ConvergedMessageAddress;
hgs
parents: 25
diff changeset
   175
            address->setAddress(addr);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   176
            address->setAlias(mAddressMap.value(addr));
37
hgs
parents: 25
diff changeset
   177
            addresses.append(address);
hgs
parents: 25
diff changeset
   178
        }
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   179
    }
37
hgs
parents: 25
diff changeset
   180
    else
hgs
parents: 25
diff changeset
   181
    {
hgs
parents: 25
diff changeset
   182
        QMap<QString, QString>::iterator i = mAddressMap.begin();
hgs
parents: 25
diff changeset
   183
        while (i != mAddressMap.end())
hgs
parents: 25
diff changeset
   184
        {
hgs
parents: 25
diff changeset
   185
            ConvergedMessageAddress* address = new ConvergedMessageAddress;
hgs
parents: 25
diff changeset
   186
            address->setAddress(i.key());
hgs
parents: 25
diff changeset
   187
            address->setAlias(i.value());
hgs
parents: 25
diff changeset
   188
            addresses.append(address);
hgs
parents: 25
diff changeset
   189
            i++;
hgs
parents: 25
diff changeset
   190
        }
hgs
parents: 25
diff changeset
   191
    }
hgs
parents: 25
diff changeset
   192
#ifdef _DEBUG_TRACES_
hgs
parents: 25
diff changeset
   193
    qCritical() << "MsgUnifiedEditorAddress::addresses end";
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
#endif
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
    return addresses;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   198
int MsgUnifiedEditorAddress::addressCount()
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
{
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   200
    return mAddressEdit->addresses().count();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   201
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   202
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   203
void MsgUnifiedEditorAddress::setAddresses(ConvergedMessageAddressList addrlist)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
{
37
hgs
parents: 25
diff changeset
   205
    // avoid processing if no info available
hgs
parents: 25
diff changeset
   206
    if(addrlist.count() == 0)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   207
    {
37
hgs
parents: 25
diff changeset
   208
        return;
hgs
parents: 25
diff changeset
   209
    }
hgs
parents: 25
diff changeset
   210
hgs
parents: 25
diff changeset
   211
    // ensure flags are reset before starting the addr addition
hgs
parents: 25
diff changeset
   212
    mAboutToExceedMaxSmsRecipients = false;
hgs
parents: 25
diff changeset
   213
    mAboutToExceedMaxMmsRecipients = false;
hgs
parents: 25
diff changeset
   214
    mExceedsMaxMmsRecipientsBy = 0;
hgs
parents: 25
diff changeset
   215
hgs
parents: 25
diff changeset
   216
    // first, we check if MMS max-recipient count will exceed
hgs
parents: 25
diff changeset
   217
    int count = addrlist.count();
hgs
parents: 25
diff changeset
   218
	int futureCount = count + MsgUnifiedEditorMonitor::msgAddressCount();
hgs
parents: 25
diff changeset
   219
	if(futureCount > MsgUnifiedEditorMonitor::maxMmsRecipients())
hgs
parents: 25
diff changeset
   220
	{
hgs
parents: 25
diff changeset
   221
	    mAboutToExceedMaxMmsRecipients = true;
hgs
parents: 25
diff changeset
   222
	    mExceedsMaxMmsRecipientsBy =
hgs
parents: 25
diff changeset
   223
	            futureCount - MsgUnifiedEditorMonitor::maxMmsRecipients();
hgs
parents: 25
diff changeset
   224
	}
hgs
parents: 25
diff changeset
   225
	// else, check if SMS max-recipient count will exceed
hgs
parents: 25
diff changeset
   226
	else if(!mSkipMaxRecipientQuery)
hgs
parents: 25
diff changeset
   227
	{
hgs
parents: 25
diff changeset
   228
	    futureCount = count + addressCount();
hgs
parents: 25
diff changeset
   229
	    if( (addressCount() <= MsgUnifiedEditorMonitor::maxSmsRecipients()) &&
hgs
parents: 25
diff changeset
   230
	        (futureCount > MsgUnifiedEditorMonitor::maxSmsRecipients()) )
hgs
parents: 25
diff changeset
   231
	    {
hgs
parents: 25
diff changeset
   232
	        mAboutToExceedMaxSmsRecipients = true;
hgs
parents: 25
diff changeset
   233
	    }
hgs
parents: 25
diff changeset
   234
	}
hgs
parents: 25
diff changeset
   235
hgs
parents: 25
diff changeset
   236
	int  invalidCount= 0;
hgs
parents: 25
diff changeset
   237
    QString invalidContacts;
hgs
parents: 25
diff changeset
   238
    for(int i = 0; i < count; i++ )
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   239
        {
37
hgs
parents: 25
diff changeset
   240
        bool isValid = false;
hgs
parents: 25
diff changeset
   241
        isValid = checkValidAddress(addrlist.at(i)->address());
hgs
parents: 25
diff changeset
   242
        if(!isValid)
hgs
parents: 25
diff changeset
   243
           {
hgs
parents: 25
diff changeset
   244
            invalidCount ++;
hgs
parents: 25
diff changeset
   245
            // append the comma till last but one contact.
hgs
parents: 25
diff changeset
   246
            // add the invalid ocntacts to the " , " seperated string.
hgs
parents: 25
diff changeset
   247
            if(invalidCount > 1)
hgs
parents: 25
diff changeset
   248
                {
hgs
parents: 25
diff changeset
   249
                invalidContacts.append(COMMA_SEPERATOR);
hgs
parents: 25
diff changeset
   250
                }
hgs
parents: 25
diff changeset
   251
            invalidContacts.append(addrlist.at(i)->alias());
hgs
parents: 25
diff changeset
   252
           }
hgs
parents: 25
diff changeset
   253
       else
hgs
parents: 25
diff changeset
   254
           {
hgs
parents: 25
diff changeset
   255
           mAddressMap.insertMulti(addrlist[i]->address(), addrlist[i]->alias());
hgs
parents: 25
diff changeset
   256
           if(!addrlist[i]->alias().isEmpty())
hgs
parents: 25
diff changeset
   257
              {
hgs
parents: 25
diff changeset
   258
              mAddressEdit->setText(addrlist[i]->alias());
hgs
parents: 25
diff changeset
   259
              }
hgs
parents: 25
diff changeset
   260
           else
hgs
parents: 25
diff changeset
   261
              {
hgs
parents: 25
diff changeset
   262
              mAddressEdit->setText(addrlist[i]->address(), false);
hgs
parents: 25
diff changeset
   263
              }
hgs
parents: 25
diff changeset
   264
           }
hgs
parents: 25
diff changeset
   265
       }
hgs
parents: 25
diff changeset
   266
    if(invalidCount)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   267
        {
37
hgs
parents: 25
diff changeset
   268
        QString invalidStr;
hgs
parents: 25
diff changeset
   269
        (invalidCount == 1)?(invalidStr = QString(LOC_INVALID_RECIPIENT_NOT_ADDED)) :(invalidStr = QString(LOC_INVALID_RECIPIENTS_NOT_ADDED));
hgs
parents: 25
diff changeset
   270
        // append line seperator
hgs
parents: 25
diff changeset
   271
         invalidStr.append("<br>");
hgs
parents: 25
diff changeset
   272
         invalidStr.append(invalidContacts);
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   273
         HbMessageBox::information(invalidStr, 0, 0, HbMessageBox::Ok);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   274
        }
37
hgs
parents: 25
diff changeset
   275
hgs
parents: 25
diff changeset
   276
    // addition operation complete, reset flags
hgs
parents: 25
diff changeset
   277
    mAboutToExceedMaxSmsRecipients = false;
hgs
parents: 25
diff changeset
   278
    mAboutToExceedMaxMmsRecipients = false;
hgs
parents: 25
diff changeset
   279
    mExceedsMaxMmsRecipientsBy = 0;
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   280
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   281
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   282
int MsgUnifiedEditorAddress::contactMatchDigits()
37
hgs
parents: 25
diff changeset
   283
{
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   284
    // Read the amount of digits to be used in contact matching
37
hgs
parents: 25
diff changeset
   285
    // The key is owned by PhoneApp
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   286
    int matchDigitCount = 0;
37
hgs
parents: 25
diff changeset
   287
    TRAP_IGNORE(
hgs
parents: 25
diff changeset
   288
        CRepository* repository = CRepository::NewLC(KCRUidTelConfiguration);
hgs
parents: 25
diff changeset
   289
        if ( repository->Get(KTelMatchDigits, matchDigitCount) == KErrNone )
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   290
        {
37
hgs
parents: 25
diff changeset
   291
            // Min is 7
hgs
parents: 25
diff changeset
   292
            matchDigitCount = Max(matchDigitCount, KDefaultGsmNumberMatchLength);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   293
        }
37
hgs
parents: 25
diff changeset
   294
        CleanupStack::PopAndDestroy(); // repository
hgs
parents: 25
diff changeset
   295
    );
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   296
    return matchDigitCount;
37
hgs
parents: 25
diff changeset
   297
}
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   298
37
hgs
parents: 25
diff changeset
   299
void MsgUnifiedEditorAddress::onContentsChanged(const QString& text)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   300
{
37
hgs
parents: 25
diff changeset
   301
    // Max MMS recipient count check
hgs
parents: 25
diff changeset
   302
    if( mAboutToExceedMaxMmsRecipients ||
hgs
parents: 25
diff changeset
   303
        (MsgUnifiedEditorMonitor::msgAddressCount() >= MsgUnifiedEditorMonitor::maxMmsRecipients()) )
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   304
    {
37
hgs
parents: 25
diff changeset
   305
        if(mAboutToExceedMaxMmsRecipients)
hgs
parents: 25
diff changeset
   306
        {// show discreet note only once
hgs
parents: 25
diff changeset
   307
            --mExceedsMaxMmsRecipientsBy;
hgs
parents: 25
diff changeset
   308
            if(!mExceedsMaxMmsRecipientsBy)
hgs
parents: 25
diff changeset
   309
            {
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   310
                HbMessageBox::information(LOC_MMS_RECIPIENT_LIMIT_REACHED, 0, 0, HbMessageBox::Ok);
37
hgs
parents: 25
diff changeset
   311
            }
hgs
parents: 25
diff changeset
   312
            resetToPrevious();
hgs
parents: 25
diff changeset
   313
        }
hgs
parents: 25
diff changeset
   314
        else
hgs
parents: 25
diff changeset
   315
        {
hgs
parents: 25
diff changeset
   316
            // update monitor data
hgs
parents: 25
diff changeset
   317
            emit contentChanged();
hgs
parents: 25
diff changeset
   318
            if(MsgUnifiedEditorMonitor::msgAddressCount() > MsgUnifiedEditorMonitor::maxMmsRecipients())
hgs
parents: 25
diff changeset
   319
            {
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   320
                HbMessageBox::information(LOC_MMS_RECIPIENT_LIMIT_REACHED, 0, 0, HbMessageBox::Ok);
37
hgs
parents: 25
diff changeset
   321
                resetToPrevious();
hgs
parents: 25
diff changeset
   322
                // reset monitor data
hgs
parents: 25
diff changeset
   323
                emit contentChanged();
hgs
parents: 25
diff changeset
   324
            }
hgs
parents: 25
diff changeset
   325
            else
hgs
parents: 25
diff changeset
   326
            {
hgs
parents: 25
diff changeset
   327
                mPrevBuffer = text;
hgs
parents: 25
diff changeset
   328
            }
hgs
parents: 25
diff changeset
   329
        }
hgs
parents: 25
diff changeset
   330
        return;
hgs
parents: 25
diff changeset
   331
    }
hgs
parents: 25
diff changeset
   332
hgs
parents: 25
diff changeset
   333
    // Max SMS recipient count check
hgs
parents: 25
diff changeset
   334
    if( !mSkipMaxRecipientQuery &&
hgs
parents: 25
diff changeset
   335
        (MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Sms) &&
hgs
parents: 25
diff changeset
   336
        (mAddressEdit->addresses().count() > MsgUnifiedEditorMonitor::maxSmsRecipients()) )
hgs
parents: 25
diff changeset
   337
    {
hgs
parents: 25
diff changeset
   338
        // when we show this dialog, we don't want the intermediate states
hgs
parents: 25
diff changeset
   339
        // to be signalled to us
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   340
        disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
37
hgs
parents: 25
diff changeset
   341
                this, SLOT(onContentsChanged(const QString&)));
hgs
parents: 25
diff changeset
   342
        QTimer::singleShot(50, this, SLOT(handleRecipientLimitReached()));
hgs
parents: 25
diff changeset
   343
    }
hgs
parents: 25
diff changeset
   344
    else
hgs
parents: 25
diff changeset
   345
    {
hgs
parents: 25
diff changeset
   346
        if(!mAboutToExceedMaxSmsRecipients)
hgs
parents: 25
diff changeset
   347
        {// remember addresses before the block insertion started
hgs
parents: 25
diff changeset
   348
            mPrevBuffer = text;
hgs
parents: 25
diff changeset
   349
        }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   350
        emit contentChanged();
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   351
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   352
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   353
37
hgs
parents: 25
diff changeset
   354
void MsgUnifiedEditorAddress::handleRecipientLimitReached()
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   355
{
37
hgs
parents: 25
diff changeset
   356
    HbMessageBox* dlg = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
hgs
parents: 25
diff changeset
   357
    dlg->setAttribute(Qt::WA_DeleteOnClose);
hgs
parents: 25
diff changeset
   358
    dlg->setFocusPolicy(Qt::NoFocus);
hgs
parents: 25
diff changeset
   359
    dlg->setTimeout(HbPopup::NoTimeout);
hgs
parents: 25
diff changeset
   360
hgs
parents: 25
diff changeset
   361
    dlg->setText(LOC_SMS_RECIPIENT_LIMIT_REACHED);
hgs
parents: 25
diff changeset
   362
    
hgs
parents: 25
diff changeset
   363
    dlg->clearActions();
hgs
parents: 25
diff changeset
   364
    HbAction* okAction = new HbAction(LOC_DIALOG_OK,dlg);
hgs
parents: 25
diff changeset
   365
    dlg->addAction(okAction);
hgs
parents: 25
diff changeset
   366
hgs
parents: 25
diff changeset
   367
    HbAction* cancelAction = new HbAction(LOC_BUTTON_CANCEL,dlg);
hgs
parents: 25
diff changeset
   368
    dlg->addAction(cancelAction);
hgs
parents: 25
diff changeset
   369
hgs
parents: 25
diff changeset
   370
    dlg->open(this,SLOT(onMaxRecipientsReached(HbAction*)));
hgs
parents: 25
diff changeset
   371
    // reconnect to get back updates
hgs
parents: 25
diff changeset
   372
    connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
hgs
parents: 25
diff changeset
   373
            this, SLOT(onContentsChanged(const QString&)));
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   374
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   375
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   376
void MsgUnifiedEditorAddress::syncDeletionsToMap()
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   377
{
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   378
    // get address list from edit-field
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   379
    QStringList addrList = mAddressEdit->addresses();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   380
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   381
    QMap<QString, QString>::iterator i = mAddressMap.begin();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   382
    while (i != mAddressMap.end())
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   383
    {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   384
        // check if either key or value is present in the list
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   385
        if( !(addrList.contains(i.value(), Qt::CaseSensitive) ||
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   386
              addrList.contains(i.key(), Qt::CaseSensitive)) )
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   387
        {// if none are present, then delete entry from map
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   388
            i = mAddressMap.erase(i);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   389
        }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   390
        else
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   391
        {
37
hgs
parents: 25
diff changeset
   392
            // ensure that the matched contact is removed from the
hgs
parents: 25
diff changeset
   393
            // address's list
hgs
parents: 25
diff changeset
   394
            int matchedIndex = addrList.indexOf(i.value());
hgs
parents: 25
diff changeset
   395
            if(matchedIndex == -1)
hgs
parents: 25
diff changeset
   396
            {
hgs
parents: 25
diff changeset
   397
                matchedIndex = addrList.indexOf(i.key());
hgs
parents: 25
diff changeset
   398
            }
hgs
parents: 25
diff changeset
   399
            if(matchedIndex != -1)
hgs
parents: 25
diff changeset
   400
            {
hgs
parents: 25
diff changeset
   401
                addrList.removeAt(matchedIndex);
hgs
parents: 25
diff changeset
   402
            }
hgs
parents: 25
diff changeset
   403
            // now go to next index in map
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   404
            ++i;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   405
        }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   406
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   407
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   408
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   409
void MsgUnifiedEditorAddress::syncAdditionsToMap()
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   410
{
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   411
    // remove already mapped addresses from edit-field
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   412
    QStringList userInputAddrList(mAddressEdit->addresses());
37
hgs
parents: 25
diff changeset
   413
    QStringList mapAddrList = mAddressMap.values();
hgs
parents: 25
diff changeset
   414
    mapAddrList << mAddressMap.keys();
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   415
    foreach(QString addr, mapAddrList)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   416
    {
37
hgs
parents: 25
diff changeset
   417
        userInputAddrList.removeOne(addr);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   418
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   419
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   420
    // add the unmapped addresses to address-map
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   421
    foreach(QString addr, userInputAddrList)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   422
    {
37
hgs
parents: 25
diff changeset
   423
        mAddressMap.insertMulti(addr, QString());
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   424
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   425
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   426
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   427
QStringList MsgUnifiedEditorAddress::uniqueAddressList()
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   428
{
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   429
    int matchDigitCount = MsgUnifiedEditorAddress::contactMatchDigits();
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   430
    QStringList mapAddrList = mAddressMap.keys();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   431
    for(int j = 0;j<mapAddrList.count()-1;j++)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   432
    {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   433
        for(int i =j+1;i<mapAddrList.count();i++)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   434
        {
37
hgs
parents: 25
diff changeset
   435
            if(0 == mapAddrList[j].right(matchDigitCount).compare(mapAddrList[i].right(matchDigitCount)))
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   436
            {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   437
               mapAddrList.removeAt(i);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   438
               i--;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   439
            }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   440
        }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   441
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   442
    return mapAddrList;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   443
}
37
hgs
parents: 25
diff changeset
   444
hgs
parents: 25
diff changeset
   445
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   446
// MsgUnifiedEditorAddress::skipMaxRecipientQuery
hgs
parents: 25
diff changeset
   447
// @see header
hgs
parents: 25
diff changeset
   448
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   449
void MsgUnifiedEditorAddress::skipMaxRecipientQuery(bool skip)
hgs
parents: 25
diff changeset
   450
{
hgs
parents: 25
diff changeset
   451
    mSkipMaxRecipientQuery = skip;
hgs
parents: 25
diff changeset
   452
}
hgs
parents: 25
diff changeset
   453
hgs
parents: 25
diff changeset
   454
void MsgUnifiedEditorAddress::setFocus()
hgs
parents: 25
diff changeset
   455
{
hgs
parents: 25
diff changeset
   456
    mAddressEdit->setFocus(Qt::MouseFocusReason);
hgs
parents: 25
diff changeset
   457
}
hgs
parents: 25
diff changeset
   458
hgs
parents: 25
diff changeset
   459
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   460
// MsgUnifiedEditorAddress::resetToPrevious
hgs
parents: 25
diff changeset
   461
// @see header
hgs
parents: 25
diff changeset
   462
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   463
void MsgUnifiedEditorAddress::resetToPrevious()
hgs
parents: 25
diff changeset
   464
{
hgs
parents: 25
diff changeset
   465
    // when we do this reset operation, we don't want the intermediate states
hgs
parents: 25
diff changeset
   466
    // to be signalled to us
hgs
parents: 25
diff changeset
   467
    disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
hgs
parents: 25
diff changeset
   468
            this, SLOT(onContentsChanged(const QString&)));
hgs
parents: 25
diff changeset
   469
hgs
parents: 25
diff changeset
   470
    mAddressEdit->clearContent();
hgs
parents: 25
diff changeset
   471
    QStringList list = mPrevBuffer.split(REPLACEMENT_STR,
hgs
parents: 25
diff changeset
   472
            QString::SkipEmptyParts);
hgs
parents: 25
diff changeset
   473
    int count = list.count();
hgs
parents: 25
diff changeset
   474
    QStringList valList = mAddressMap.values();
hgs
parents: 25
diff changeset
   475
    for(int i=0; i<count; i++)
hgs
parents: 25
diff changeset
   476
    {
hgs
parents: 25
diff changeset
   477
        QString addr = list.at(i);
hgs
parents: 25
diff changeset
   478
        if(valList.contains(addr))
hgs
parents: 25
diff changeset
   479
        {
hgs
parents: 25
diff changeset
   480
            mAddressEdit->setText(addr);
hgs
parents: 25
diff changeset
   481
        }
hgs
parents: 25
diff changeset
   482
        else
hgs
parents: 25
diff changeset
   483
        {
hgs
parents: 25
diff changeset
   484
            mAddressEdit->setText(addr, false);
hgs
parents: 25
diff changeset
   485
        }
hgs
parents: 25
diff changeset
   486
    }
hgs
parents: 25
diff changeset
   487
    syncDeletionsToMap();
hgs
parents: 25
diff changeset
   488
    connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
hgs
parents: 25
diff changeset
   489
            this, SLOT(onContentsChanged(const QString&)));
hgs
parents: 25
diff changeset
   490
}
hgs
parents: 25
diff changeset
   491
hgs
parents: 25
diff changeset
   492
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   493
// MsgUnifiedEditorAddress::onMaxRecipientsReached
hgs
parents: 25
diff changeset
   494
// @see header
hgs
parents: 25
diff changeset
   495
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   496
void MsgUnifiedEditorAddress::onMaxRecipientsReached(HbAction* action)
hgs
parents: 25
diff changeset
   497
{
hgs
parents: 25
diff changeset
   498
    HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
hgs
parents: 25
diff changeset
   499
    if (action == dlg->actions().at(0)) {
hgs
parents: 25
diff changeset
   500
        // accept new content, update prev-buffer
hgs
parents: 25
diff changeset
   501
        emit contentChanged();
hgs
parents: 25
diff changeset
   502
        mPrevBuffer = mAddressEdit->content();
hgs
parents: 25
diff changeset
   503
    }
hgs
parents: 25
diff changeset
   504
    else {
hgs
parents: 25
diff changeset
   505
        // reject the new content, keep the old
hgs
parents: 25
diff changeset
   506
        resetToPrevious();
hgs
parents: 25
diff changeset
   507
    }
hgs
parents: 25
diff changeset
   508
}
hgs
parents: 25
diff changeset
   509
hgs
parents: 25
diff changeset
   510
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   511
// MsgUnifiedEditorAddress::validateContacts
hgs
parents: 25
diff changeset
   512
// @see header
hgs
parents: 25
diff changeset
   513
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   514
bool MsgUnifiedEditorAddress::validateContacts()
hgs
parents: 25
diff changeset
   515
{
hgs
parents: 25
diff changeset
   516
    UniEditorGenUtils* genUtils = new UniEditorGenUtils;
hgs
parents: 25
diff changeset
   517
hgs
parents: 25
diff changeset
   518
    // sync-up map to account for user-actions on address-field
hgs
parents: 25
diff changeset
   519
    syncDeletionsToMap();
hgs
parents: 25
diff changeset
   520
    syncAdditionsToMap();
hgs
parents: 25
diff changeset
   521
hgs
parents: 25
diff changeset
   522
    // get the list of contacts in address-field
hgs
parents: 25
diff changeset
   523
    QStringList fieldAddresses(mAddressEdit->addresses());
hgs
parents: 25
diff changeset
   524
hgs
parents: 25
diff changeset
   525
    bool isValid = true;
hgs
parents: 25
diff changeset
   526
    foreach(QString addr, fieldAddresses)
hgs
parents: 25
diff changeset
   527
    {
hgs
parents: 25
diff changeset
   528
        // run address validation only if address is unmapped
hgs
parents: 25
diff changeset
   529
        // (i.e. user-inserted)
hgs
parents: 25
diff changeset
   530
        if(mAddressMap.contains(addr))
hgs
parents: 25
diff changeset
   531
        {
hgs
parents: 25
diff changeset
   532
        isValid = checkValidAddress(addr);
hgs
parents: 25
diff changeset
   533
            if(!isValid)
hgs
parents: 25
diff changeset
   534
            {
hgs
parents: 25
diff changeset
   535
                mAddressEdit->highlightInvalidString(addr);
hgs
parents: 25
diff changeset
   536
                QString invalidAddrStr =
hgs
parents: 25
diff changeset
   537
                        QString(LOC_INVALID_RECIPIENT).arg(addr);
hgs
parents: 25
diff changeset
   538
                HbMessageBox* dlg = new HbMessageBox(invalidAddrStr,
hgs
parents: 25
diff changeset
   539
                        HbMessageBox::MessageTypeInformation);
hgs
parents: 25
diff changeset
   540
                dlg->setDismissPolicy(HbPopup::TapInside);
hgs
parents: 25
diff changeset
   541
                dlg->setTimeout(HbPopup::NoTimeout);
hgs
parents: 25
diff changeset
   542
                dlg->setAttribute(Qt::WA_DeleteOnClose, true);
hgs
parents: 25
diff changeset
   543
                dlg->open(this, SLOT(handleInvalidContactDialog(HbAction*)));
hgs
parents: 25
diff changeset
   544
                break;
hgs
parents: 25
diff changeset
   545
            }
hgs
parents: 25
diff changeset
   546
        }
hgs
parents: 25
diff changeset
   547
    }
hgs
parents: 25
diff changeset
   548
hgs
parents: 25
diff changeset
   549
    return isValid;
hgs
parents: 25
diff changeset
   550
}
hgs
parents: 25
diff changeset
   551
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   552
// MsgUnifiedEditorAddress::checkValidAddress
hgs
parents: 25
diff changeset
   553
// @see header
hgs
parents: 25
diff changeset
   554
// ----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   555
bool MsgUnifiedEditorAddress::checkValidAddress(const QString& addr)
hgs
parents: 25
diff changeset
   556
    {
hgs
parents: 25
diff changeset
   557
    bool isValid = false;
38
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   558
    
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   559
    HBufC *tempAddr = XQConversions::qStringToS60Desc(addr);
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   560
    	
37
hgs
parents: 25
diff changeset
   561
    // 1. perform number validation
hgs
parents: 25
diff changeset
   562
    isValid = CommonPhoneParser::IsValidPhoneNumber(
38
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   563
            *tempAddr,
37
hgs
parents: 25
diff changeset
   564
            CommonPhoneParser::ESMSNumber );
hgs
parents: 25
diff changeset
   565
hgs
parents: 25
diff changeset
   566
    // 2. if number validity fails, then perform email addr validation
hgs
parents: 25
diff changeset
   567
    UniEditorGenUtils* genUtils = new UniEditorGenUtils;
hgs
parents: 25
diff changeset
   568
    if(!isValid)
hgs
parents: 25
diff changeset
   569
        { // additional check for MMS only
hgs
parents: 25
diff changeset
   570
        isValid = genUtils->IsValidEmailAddress(
38
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   571
                    *tempAddr );
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   572
        } 
37
hgs
parents: 25
diff changeset
   573
    delete genUtils;
38
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   574
    delete tempAddr;
37
hgs
parents: 25
diff changeset
   575
    return isValid;
hgs
parents: 25
diff changeset
   576
    }
hgs
parents: 25
diff changeset
   577
hgs
parents: 25
diff changeset
   578
void MsgUnifiedEditorAddress::handleInvalidContactDialog(
hgs
parents: 25
diff changeset
   579
        HbAction* act)
hgs
parents: 25
diff changeset
   580
{
hgs
parents: 25
diff changeset
   581
    Q_UNUSED(act);
hgs
parents: 25
diff changeset
   582
    QTimer::singleShot(250, this, SLOT(setFocus()));
hgs
parents: 25
diff changeset
   583
}
hgs
parents: 25
diff changeset
   584
hgs
parents: 25
diff changeset
   585
void MsgUnifiedEditorAddress::unblockSignals()
hgs
parents: 25
diff changeset
   586
{
hgs
parents: 25
diff changeset
   587
    mLaunchBtn->blockSignals(false);
hgs
parents: 25
diff changeset
   588
}
hgs
parents: 25
diff changeset
   589
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   590
Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   591
Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   592
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   593
//EOF