messagingapp/msgui/unifiedviewer/src/univieweraddresswidget.cpp
author hgs
Tue, 31 Aug 2010 18:53:38 +0530
changeset 56 f42d9a78f435
parent 48 4f501b74aeb1
child 62 fdbe8253b596
permissions -rw-r--r--
201033_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
 *
37
hgs
parents: 25
diff changeset
    14
 * Description:Custom widget derived from HbTextEdit which provides rich text
hgs
parents: 25
diff changeset
    15
 *              processing
23
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
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
#include "univieweraddresswidget.h"
37
hgs
parents: 25
diff changeset
    20
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
// SYSTEM INCLUDES
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include <QTextCursor>
37
hgs
parents: 25
diff changeset
    23
#include <QTextBlock>
hgs
parents: 25
diff changeset
    24
#include <QApplication>
hgs
parents: 25
diff changeset
    25
#include <QClipboard>
hgs
parents: 25
diff changeset
    26
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include <HbMenu>
37
hgs
parents: 25
diff changeset
    28
#include <HbAction>
hgs
parents: 25
diff changeset
    29
#include <HbTapGesture>
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
37
hgs
parents: 25
diff changeset
    31
#include <xqservicerequest.h>
hgs
parents: 25
diff changeset
    32
#include <xqappmgr.h>
hgs
parents: 25
diff changeset
    33
#include <cntservicescontact.h>
hgs
parents: 25
diff changeset
    34
#include <qtcontacts.h>
hgs
parents: 25
diff changeset
    35
#include <xqservicerequest.h>
hgs
parents: 25
diff changeset
    36
#include <xqaiwrequest.h>
hgs
parents: 25
diff changeset
    37
#include "msgcontacthandler.h"
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
// LOCAL CONSTANTS
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
const QString ADDRESS_SEPARATOR("; ");
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    41
const QString ADDRESS_OPEN(" (");
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    42
const QString ADDRESS_CLOSE(")");
37
hgs
parents: 25
diff changeset
    43
const QString SPACE(" ");
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
37
hgs
parents: 25
diff changeset
    45
//localization
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
    46
#define LOC_CONTACT_INFO      hbTrId("txt_messaging_menu_contact_info")
37
hgs
parents: 25
diff changeset
    47
#define LOC_CALL              hbTrId("txt_common_menu_call_verb")
hgs
parents: 25
diff changeset
    48
#define LOC_SEND_MESSAGE      hbTrId("txt_common_menu_send_message")
hgs
parents: 25
diff changeset
    49
#define LOC_SAVE_TO_CONTACTS  hbTrId("txt_common_menu_save_to_contacts")
hgs
parents: 25
diff changeset
    50
#define LOC_COPY              hbTrId("txt_common_menu_copy")
hgs
parents: 25
diff changeset
    51
hgs
parents: 25
diff changeset
    52
const QString BG_FRAME_GRAPHICS("qtg_fr_lineedit_normal");
hgs
parents: 25
diff changeset
    53
hgs
parents: 25
diff changeset
    54
//---------------------------------------------------------------
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
// UniViewerAddressWidget::UniViewerAddressWidget
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
// @see header file
37
hgs
parents: 25
diff changeset
    57
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
    58
UniViewerAddressWidget::UniViewerAddressWidget(QGraphicsItem * parent) :
hgs
parents: 25
diff changeset
    59
HbTextEdit(parent),
hgs
parents: 25
diff changeset
    60
mCursorPos(-1)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
{
37
hgs
parents: 25
diff changeset
    62
    this->setReadOnly(true);    
hgs
parents: 25
diff changeset
    63
    this->setScrollable(false);
hgs
parents: 25
diff changeset
    64
    this->setFlag(QGraphicsItem::ItemIsFocusable,false);
hgs
parents: 25
diff changeset
    65
    this->setCursorVisibility(Hb::TextCursorHidden);
hgs
parents: 25
diff changeset
    66
    this->setBackgroundItem(0);   
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
37
hgs
parents: 25
diff changeset
    68
    HbFontSpec fontSpec(HbFontSpec::Secondary);
hgs
parents: 25
diff changeset
    69
    QFont font = fontSpec.font();
hgs
parents: 25
diff changeset
    70
    this->setFont(font);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
37
hgs
parents: 25
diff changeset
    72
    mFormatNormal.setForeground(palette().link());
hgs
parents: 25
diff changeset
    73
    mFormatNormal.setBackground(Qt::transparent);
hgs
parents: 25
diff changeset
    74
hgs
parents: 25
diff changeset
    75
    mFormatHighlight.setBackground(palette().highlight());
hgs
parents: 25
diff changeset
    76
    mFormatHighlight.setForeground(palette().highlightedText());
hgs
parents: 25
diff changeset
    77
hgs
parents: 25
diff changeset
    78
    connect(this, SIGNAL(aboutToShowContextMenu(HbMenu*,QPointF)),
hgs
parents: 25
diff changeset
    79
            this, SLOT(aboutToShowContextMenu(HbMenu*,QPointF)));
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
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
// UniViewerAddressWidget::~UniViewerAddressWidget
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    84
// @see header file
37
hgs
parents: 25
diff changeset
    85
//---------------------------------------------------------------
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
UniViewerAddressWidget::~UniViewerAddressWidget()
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    87
{
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    88
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    89
37
hgs
parents: 25
diff changeset
    90
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
    91
//UniViewerAddressWidget :: gestureEvent
hgs
parents: 25
diff changeset
    92
// @see header file
hgs
parents: 25
diff changeset
    93
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
    94
void UniViewerAddressWidget::gestureEvent(QGestureEvent* event)
hgs
parents: 25
diff changeset
    95
{
hgs
parents: 25
diff changeset
    96
    //handle gesture to highlight and dehighlight find item.
hgs
parents: 25
diff changeset
    97
    
hgs
parents: 25
diff changeset
    98
    if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture)))
hgs
parents: 25
diff changeset
    99
    {
hgs
parents: 25
diff changeset
   100
        //capturing gesture position, and map to local co-ordinates.
hgs
parents: 25
diff changeset
   101
        QPointF pos = mapFromScene(tap->scenePosition());
hgs
parents: 25
diff changeset
   102
        
hgs
parents: 25
diff changeset
   103
        switch (tap->state()) 
hgs
parents: 25
diff changeset
   104
        {
hgs
parents: 25
diff changeset
   105
            case Qt::GestureStarted:
hgs
parents: 25
diff changeset
   106
            {
hgs
parents: 25
diff changeset
   107
                //highlight find item.
hgs
parents: 25
diff changeset
   108
                QTextDocument* doc = this->document();
hgs
parents: 25
diff changeset
   109
                mCursorPos = doc->documentLayout()->hitTest(pos, Qt::ExactHit);
hgs
parents: 25
diff changeset
   110
                highlightText(true);
hgs
parents: 25
diff changeset
   111
                break;
hgs
parents: 25
diff changeset
   112
            }  
hgs
parents: 25
diff changeset
   113
            
hgs
parents: 25
diff changeset
   114
            case Qt::GestureFinished:
hgs
parents: 25
diff changeset
   115
            {
hgs
parents: 25
diff changeset
   116
                if (HbTapGesture::Tap == tap->tapStyleHint()) 
hgs
parents: 25
diff changeset
   117
                {
hgs
parents: 25
diff changeset
   118
                    //gesture is finshed dehighlight text.
hgs
parents: 25
diff changeset
   119
                    highlightText(false);
hgs
parents: 25
diff changeset
   120
                    
hgs
parents: 25
diff changeset
   121
                    QString anchor = this->anchorAt(pos);
hgs
parents: 25
diff changeset
   122
                    
hgs
parents: 25
diff changeset
   123
                    //do short tap action.
hgs
parents: 25
diff changeset
   124
                    if (!anchor.isEmpty() && !this->textCursor().hasSelection())
hgs
parents: 25
diff changeset
   125
                    {
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   126
                        shortTapAction(anchor,tap->scenePosition());
37
hgs
parents: 25
diff changeset
   127
                    }
hgs
parents: 25
diff changeset
   128
                }
hgs
parents: 25
diff changeset
   129
                break;
hgs
parents: 25
diff changeset
   130
            }
hgs
parents: 25
diff changeset
   131
            
hgs
parents: 25
diff changeset
   132
            case Qt::GestureCanceled:
hgs
parents: 25
diff changeset
   133
            {
hgs
parents: 25
diff changeset
   134
                //gesture is canceled due to pan or swipe, dehighlight text.
hgs
parents: 25
diff changeset
   135
                if (HbTapGesture::Tap == tap->tapStyleHint()) 
hgs
parents: 25
diff changeset
   136
                {
hgs
parents: 25
diff changeset
   137
                highlightText(false);
hgs
parents: 25
diff changeset
   138
                break;
hgs
parents: 25
diff changeset
   139
                }
hgs
parents: 25
diff changeset
   140
            }
hgs
parents: 25
diff changeset
   141
            default:
hgs
parents: 25
diff changeset
   142
                break;
hgs
parents: 25
diff changeset
   143
        }
hgs
parents: 25
diff changeset
   144
        
hgs
parents: 25
diff changeset
   145
        event->accept();
hgs
parents: 25
diff changeset
   146
    }
hgs
parents: 25
diff changeset
   147
    else
hgs
parents: 25
diff changeset
   148
    {
hgs
parents: 25
diff changeset
   149
        event->ignore();
hgs
parents: 25
diff changeset
   150
    }
hgs
parents: 25
diff changeset
   151
    
hgs
parents: 25
diff changeset
   152
    //passing gesture event to base class.
hgs
parents: 25
diff changeset
   153
    HbTextEdit::gestureEvent(event);
hgs
parents: 25
diff changeset
   154
}
hgs
parents: 25
diff changeset
   155
hgs
parents: 25
diff changeset
   156
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
//----------------------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
// UniViewerAddressWidget::populate
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   159
// @see header file
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
//----------------------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
void UniViewerAddressWidget::populate(const QString &label,
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
                                      const QString &address,
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
                                      const QString &alias)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
{
37
hgs
parents: 25
diff changeset
   165
    QString labelText = label;
hgs
parents: 25
diff changeset
   166
    labelText.trimmed();
hgs
parents: 25
diff changeset
   167
    labelText += SPACE;
hgs
parents: 25
diff changeset
   168
    
hgs
parents: 25
diff changeset
   169
    //Font.
hgs
parents: 25
diff changeset
   170
    HbFontSpec fontSpec(HbFontSpec::Secondary);
hgs
parents: 25
diff changeset
   171
    qreal fontHeight = 0.0;
hgs
parents: 25
diff changeset
   172
    style()->parameter("hb-param-text-height-tiny", fontHeight);
hgs
parents: 25
diff changeset
   173
    fontSpec.setTextHeight(fontHeight);    
hgs
parents: 25
diff changeset
   174
    QFont font = fontSpec.font();
hgs
parents: 25
diff changeset
   175
    
hgs
parents: 25
diff changeset
   176
    QTextCharFormat labelFormat;
hgs
parents: 25
diff changeset
   177
    labelFormat.setFont(font);
hgs
parents: 25
diff changeset
   178
    
hgs
parents: 25
diff changeset
   179
    QTextCharFormat addressFormat;
hgs
parents: 25
diff changeset
   180
    addressFormat.setForeground(palette().link());
hgs
parents: 25
diff changeset
   181
    addressFormat.setFontUnderline(true);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
    // Insert the label then the addresses
37
hgs
parents: 25
diff changeset
   184
    QTextCursor cursor(this->textCursor());
hgs
parents: 25
diff changeset
   185
    cursor.insertText(labelText,labelFormat);
hgs
parents: 25
diff changeset
   186
    
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
    QString address1 = QString();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
    if (!(alias.isEmpty()))
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   189
    {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
        address1.append(alias);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
        QString alias1 = QString();
37
hgs
parents: 25
diff changeset
   192
        
hgs
parents: 25
diff changeset
   193
        int totalNumbers = 0;
hgs
parents: 25
diff changeset
   194
        MsgContactHandler::resolveContactDisplayName(
hgs
parents: 25
diff changeset
   195
                        address,
hgs
parents: 25
diff changeset
   196
                        alias1,
hgs
parents: 25
diff changeset
   197
                        totalNumbers);
hgs
parents: 25
diff changeset
   198
        if (totalNumbers > 1)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
        {
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   200
            address1.append(ADDRESS_OPEN);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   201
            address1.append(address);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   202
            address1.append(ADDRESS_CLOSE);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   203
        }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   205
    else
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   206
    {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   207
        address1.append(address);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   209
    addressFormat.setAnchorHref(address);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
    cursor.insertText(address1, addressFormat);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   211
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   212
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   213
//----------------------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   214
// UniViewerAddressWidget::populate
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   215
// @see header file
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
//----------------------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
void UniViewerAddressWidget::populate(const QString &label,
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
                                      ConvergedMessageAddressList addressList)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
{
37
hgs
parents: 25
diff changeset
   220
    QString labelText = label;
hgs
parents: 25
diff changeset
   221
    labelText.trimmed();
hgs
parents: 25
diff changeset
   222
    labelText += SPACE;
hgs
parents: 25
diff changeset
   223
    
hgs
parents: 25
diff changeset
   224
    //Font.
hgs
parents: 25
diff changeset
   225
    HbFontSpec fontSpec(HbFontSpec::Secondary);
hgs
parents: 25
diff changeset
   226
    qreal fontHeight = 0.0;
hgs
parents: 25
diff changeset
   227
    style()->parameter("hb-param-text-height-tiny", fontHeight);
hgs
parents: 25
diff changeset
   228
    fontSpec.setTextHeight(fontHeight);    
hgs
parents: 25
diff changeset
   229
    QFont font = fontSpec.font();
hgs
parents: 25
diff changeset
   230
    
hgs
parents: 25
diff changeset
   231
    QTextCharFormat labelFormat;
hgs
parents: 25
diff changeset
   232
    labelFormat.setFont(font);
hgs
parents: 25
diff changeset
   233
    
hgs
parents: 25
diff changeset
   234
    QTextCharFormat defaultFormat;
hgs
parents: 25
diff changeset
   235
    defaultFormat.setForeground(palette().link());
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   236
37
hgs
parents: 25
diff changeset
   237
    QTextCharFormat addressFormat;
hgs
parents: 25
diff changeset
   238
    addressFormat.setForeground(palette().link());
hgs
parents: 25
diff changeset
   239
    addressFormat.setFontUnderline(true);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   240
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   241
    // Insert the label then the addresses
37
hgs
parents: 25
diff changeset
   242
    QTextCursor cursor(this->document());
hgs
parents: 25
diff changeset
   243
    cursor.insertText(labelText,labelFormat);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   244
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   245
    int addressCount = addressList.count();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   246
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   247
    for (int i = 0; i < addressCount; ++i)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   248
    {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   249
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   250
        QString address = QString();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   251
        if (! (addressList[i]->alias().isEmpty()))
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   252
        {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   253
            address.append(addressList[i]->alias());
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   254
            QString alias = QString();
37
hgs
parents: 25
diff changeset
   255
            
hgs
parents: 25
diff changeset
   256
            int totalNumbers = 0;
hgs
parents: 25
diff changeset
   257
            MsgContactHandler::resolveContactDisplayName(
hgs
parents: 25
diff changeset
   258
                            addressList[i]->address(),
hgs
parents: 25
diff changeset
   259
                            alias,
hgs
parents: 25
diff changeset
   260
                            totalNumbers);
hgs
parents: 25
diff changeset
   261
            if (totalNumbers > 1)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   262
            {
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   263
                address.append(ADDRESS_OPEN);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   264
                address.append(addressList[i]->address());
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   265
                address.append(ADDRESS_CLOSE);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   266
            }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   267
        }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   268
        else
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   269
        {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   270
            address.append(addressList[i]->address());
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   271
        }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   272
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   273
        addressFormat.setAnchorHref(addressList[i]->address());
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   274
        cursor.insertText(address, addressFormat);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   275
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   276
        if (addressCount - 1 != i)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   277
        {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   278
            cursor.insertText(ADDRESS_SEPARATOR, defaultFormat);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   279
        }
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
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   282
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   283
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   284
//----------------------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   285
// UniViewerAddressWidget::clearContent
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   286
// @see header file
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   287
//----------------------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   288
void UniViewerAddressWidget::clearContent()
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   289
{
37
hgs
parents: 25
diff changeset
   290
    this->document()->clear();
hgs
parents: 25
diff changeset
   291
}
hgs
parents: 25
diff changeset
   292
hgs
parents: 25
diff changeset
   293
//----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   294
// UniViewerAddressWidget::menuClosed
hgs
parents: 25
diff changeset
   295
// @see header file
hgs
parents: 25
diff changeset
   296
//----------------------------------------------------------------------------
hgs
parents: 25
diff changeset
   297
void UniViewerAddressWidget::menuClosed()
hgs
parents: 25
diff changeset
   298
{
hgs
parents: 25
diff changeset
   299
    highlightText(false);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   300
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   301
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   302
//----------------------------------------------------------------------------
37
hgs
parents: 25
diff changeset
   303
// UniViewerAddressWidget::highlightText
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   304
// @see header file
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   305
//----------------------------------------------------------------------------
37
hgs
parents: 25
diff changeset
   306
void UniViewerAddressWidget::highlightText(bool highlight)
hgs
parents: 25
diff changeset
   307
{
hgs
parents: 25
diff changeset
   308
    QTextBlock textBlock = this->document()->findBlock(mCursorPos);
hgs
parents: 25
diff changeset
   309
hgs
parents: 25
diff changeset
   310
    QTextBlock::iterator it;
hgs
parents: 25
diff changeset
   311
hgs
parents: 25
diff changeset
   312
    for (it = textBlock.begin(); !(it.atEnd()); ++it)
hgs
parents: 25
diff changeset
   313
    {
hgs
parents: 25
diff changeset
   314
        QTextFragment currentFragment = it.fragment();
hgs
parents: 25
diff changeset
   315
        
hgs
parents: 25
diff changeset
   316
        if (currentFragment.isValid() && currentFragment.contains(mCursorPos)
hgs
parents: 25
diff changeset
   317
            && currentFragment.charFormat().fontUnderline())
hgs
parents: 25
diff changeset
   318
        {
hgs
parents: 25
diff changeset
   319
            int start = currentFragment.position();
hgs
parents: 25
diff changeset
   320
            int length = currentFragment.length();
hgs
parents: 25
diff changeset
   321
hgs
parents: 25
diff changeset
   322
            QTextCursor cursor = this->textCursor();
hgs
parents: 25
diff changeset
   323
            cursor.clearSelection();
hgs
parents: 25
diff changeset
   324
            cursor.setPosition(start);
hgs
parents: 25
diff changeset
   325
            cursor.setPosition(start + length,QTextCursor::KeepAnchor);
hgs
parents: 25
diff changeset
   326
hgs
parents: 25
diff changeset
   327
            if(highlight)
hgs
parents: 25
diff changeset
   328
            {
hgs
parents: 25
diff changeset
   329
                cursor.mergeCharFormat(mFormatHighlight);
hgs
parents: 25
diff changeset
   330
            }
hgs
parents: 25
diff changeset
   331
            else
hgs
parents: 25
diff changeset
   332
            {
hgs
parents: 25
diff changeset
   333
                cursor.mergeCharFormat(mFormatNormal);
hgs
parents: 25
diff changeset
   334
            }
hgs
parents: 25
diff changeset
   335
hgs
parents: 25
diff changeset
   336
            cursor.clearSelection();
hgs
parents: 25
diff changeset
   337
            break;
hgs
parents: 25
diff changeset
   338
        }
hgs
parents: 25
diff changeset
   339
    }
hgs
parents: 25
diff changeset
   340
}
hgs
parents: 25
diff changeset
   341
hgs
parents: 25
diff changeset
   342
void UniViewerAddressWidget::aboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos)
hgs
parents: 25
diff changeset
   343
{
hgs
parents: 25
diff changeset
   344
    //remove default actions.
hgs
parents: 25
diff changeset
   345
    contextMenu->clearActions();
hgs
parents: 25
diff changeset
   346
    
hgs
parents: 25
diff changeset
   347
    // Check if there is an anchor at this pos
hgs
parents: 25
diff changeset
   348
    QString  anchor = this->anchorAt(pos);
hgs
parents: 25
diff changeset
   349
hgs
parents: 25
diff changeset
   350
    if(!anchor.isEmpty() && !this->textCursor().hasSelection())
hgs
parents: 25
diff changeset
   351
    {
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   352
        populateMenu(contextMenu,anchor);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   353
    }
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   354
}
37
hgs
parents: 25
diff changeset
   355
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   356
void UniViewerAddressWidget::populateMenu(HbMenu* contextMenu,const QString& data)
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   357
{
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   358
    HbAction* action = NULL;
37
hgs
parents: 25
diff changeset
   359
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   360
    int contactId = MsgContactHandler::resolveContactDisplayName(
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   361
                                 data, 
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   362
                                 QContactPhoneNumber::DefinitionName,
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   363
                                 QContactPhoneNumber::FieldNumber); 
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   364
    
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   365
    if(contactId > 0)
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   366
    {
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   367
        action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo()));
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   368
        action->setData(data);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   369
    }
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   370
    else
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   371
    {
37
hgs
parents: 25
diff changeset
   372
        action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   373
        action->setData(data);  
37
hgs
parents: 25
diff changeset
   374
    }
hgs
parents: 25
diff changeset
   375
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   376
    action = contextMenu->addAction(LOC_CALL, this, SLOT(call()));
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   377
    action->setData(data);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   378
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   379
    action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage()));
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   380
    action->setData(data);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   381
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   382
    action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   383
    action->setData(data);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   384
    
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   385
    connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); 
37
hgs
parents: 25
diff changeset
   386
}
hgs
parents: 25
diff changeset
   387
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   388
void UniViewerAddressWidget::shortTapAction(QString anchor,const QPointF& pos)
37
hgs
parents: 25
diff changeset
   389
{
hgs
parents: 25
diff changeset
   390
    HbAction action;
hgs
parents: 25
diff changeset
   391
    action.setData(anchor);
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   392
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   393
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   394
    int contactId = MsgContactHandler::resolveContactDisplayName(
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   395
        anchor, 
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   396
        QContactPhoneNumber::DefinitionName,
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   397
        QContactPhoneNumber::FieldNumber);        
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   398
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   399
    if(contactId > 0 )
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   400
    {
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   401
        //if resolved conatct open contact card 
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   402
        connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo()));
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   403
    }
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   404
    else
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   405
    {
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   406
        //unresolved contact show popup.  
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   407
        highlightText(true);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   408
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   409
        HbMenu* contextMenu = new HbMenu();
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   410
        contextMenu->setDismissPolicy(HbPopup::TapAnywhere);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   411
        contextMenu->setAttribute(Qt::WA_DeleteOnClose, true);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   412
        contextMenu->setPreferredPos(pos); 
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   413
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   414
        populateMenu(contextMenu,anchor);
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   415
        
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   416
        contextMenu->show();
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   417
    }
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   418
37
hgs
parents: 25
diff changeset
   419
    action.trigger();
hgs
parents: 25
diff changeset
   420
}
hgs
parents: 25
diff changeset
   421
hgs
parents: 25
diff changeset
   422
void UniViewerAddressWidget::copyToClipboard()
hgs
parents: 25
diff changeset
   423
{
hgs
parents: 25
diff changeset
   424
    HbAction* action = qobject_cast<HbAction*>(sender());
hgs
parents: 25
diff changeset
   425
hgs
parents: 25
diff changeset
   426
    if(action)
hgs
parents: 25
diff changeset
   427
    {
hgs
parents: 25
diff changeset
   428
        QMimeData* data = new QMimeData();
hgs
parents: 25
diff changeset
   429
        QString str = action->data().toString();
hgs
parents: 25
diff changeset
   430
        data->setText(str);
hgs
parents: 25
diff changeset
   431
        QApplication::clipboard()->setMimeData(data);
hgs
parents: 25
diff changeset
   432
    }
hgs
parents: 25
diff changeset
   433
}
hgs
parents: 25
diff changeset
   434
hgs
parents: 25
diff changeset
   435
void UniViewerAddressWidget::call()
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   436
{
37
hgs
parents: 25
diff changeset
   437
    HbAction* action = qobject_cast<HbAction*>(sender());
hgs
parents: 25
diff changeset
   438
hgs
parents: 25
diff changeset
   439
    if(action)
hgs
parents: 25
diff changeset
   440
    {
hgs
parents: 25
diff changeset
   441
        QString phoneNumber = action->data().toString();
hgs
parents: 25
diff changeset
   442
        
hgs
parents: 25
diff changeset
   443
        //invoke dialer service and pass phoneNumber.        
hgs
parents: 25
diff changeset
   444
        QString serviceName("com.nokia.symbian.ICallDial");
hgs
parents: 25
diff changeset
   445
        QString operation("dial(QString)");
hgs
parents: 25
diff changeset
   446
        
hgs
parents: 25
diff changeset
   447
        XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false);
hgs
parents: 25
diff changeset
   448
        
hgs
parents: 25
diff changeset
   449
        connect(serviceRequest, SIGNAL(requestCompleted(QVariant)),
hgs
parents: 25
diff changeset
   450
                this, SLOT(onServiceRequestCompleted()));
hgs
parents: 25
diff changeset
   451
        
hgs
parents: 25
diff changeset
   452
        connect(serviceRequest, SIGNAL(requestError(int)),
hgs
parents: 25
diff changeset
   453
                this, SLOT(onServiceRequestCompleted()));
hgs
parents: 25
diff changeset
   454
        
hgs
parents: 25
diff changeset
   455
        *serviceRequest << phoneNumber;
hgs
parents: 25
diff changeset
   456
        serviceRequest->send();
hgs
parents: 25
diff changeset
   457
    }
hgs
parents: 25
diff changeset
   458
}
hgs
parents: 25
diff changeset
   459
hgs
parents: 25
diff changeset
   460
void UniViewerAddressWidget::onServiceRequestCompleted()
hgs
parents: 25
diff changeset
   461
    {
hgs
parents: 25
diff changeset
   462
    //service request is now complete. delete it.    
hgs
parents: 25
diff changeset
   463
    XQServiceRequest* request = qobject_cast<XQServiceRequest*>(sender());
hgs
parents: 25
diff changeset
   464
    
hgs
parents: 25
diff changeset
   465
    if(request)
hgs
parents: 25
diff changeset
   466
        {
hgs
parents: 25
diff changeset
   467
        delete request;
hgs
parents: 25
diff changeset
   468
        }
hgs
parents: 25
diff changeset
   469
    }
hgs
parents: 25
diff changeset
   470
hgs
parents: 25
diff changeset
   471
hgs
parents: 25
diff changeset
   472
void UniViewerAddressWidget::openContactInfo()
hgs
parents: 25
diff changeset
   473
{
hgs
parents: 25
diff changeset
   474
    HbAction* action = qobject_cast<HbAction*>(sender());
hgs
parents: 25
diff changeset
   475
    
hgs
parents: 25
diff changeset
   476
    if(action)
hgs
parents: 25
diff changeset
   477
    {
hgs
parents: 25
diff changeset
   478
        QList<QVariant> args;
hgs
parents: 25
diff changeset
   479
        QString operation;
hgs
parents: 25
diff changeset
   480
        
hgs
parents: 25
diff changeset
   481
        QString data = action->data().toString();        
hgs
parents: 25
diff changeset
   482
    
hgs
parents: 25
diff changeset
   483
        int contactId = MsgContactHandler::resolveContactDisplayName(
hgs
parents: 25
diff changeset
   484
                data,
hgs
parents: 25
diff changeset
   485
                QContactPhoneNumber::DefinitionName,
hgs
parents: 25
diff changeset
   486
                QContactPhoneNumber::FieldNumber);
hgs
parents: 25
diff changeset
   487
hgs
parents: 25
diff changeset
   488
        // if contact is unresolved on phone number field
hgs
parents: 25
diff changeset
   489
        // then, try resolving it on email address field
hgs
parents: 25
diff changeset
   490
        if(contactId <= 0)
hgs
parents: 25
diff changeset
   491
        {
hgs
parents: 25
diff changeset
   492
            contactId = MsgContactHandler::resolveContactDisplayName(
hgs
parents: 25
diff changeset
   493
                data,
hgs
parents: 25
diff changeset
   494
                QContactEmailAddress::DefinitionName,
hgs
parents: 25
diff changeset
   495
                QContactEmailAddress::FieldEmailAddress);
hgs
parents: 25
diff changeset
   496
        }
hgs
parents: 25
diff changeset
   497
hgs
parents: 25
diff changeset
   498
        if(contactId > 0)
hgs
parents: 25
diff changeset
   499
        {
hgs
parents: 25
diff changeset
   500
            //open contact card
hgs
parents: 25
diff changeset
   501
            operation = QString("open(int)");
hgs
parents: 25
diff changeset
   502
            args << contactId;
hgs
parents: 25
diff changeset
   503
        }
hgs
parents: 25
diff changeset
   504
        else
hgs
parents: 25
diff changeset
   505
        {
hgs
parents: 25
diff changeset
   506
            //save to contacts with phone number field prefilled.
hgs
parents: 25
diff changeset
   507
hgs
parents: 25
diff changeset
   508
            operation = QString("editCreateNew(QString,QString)");
hgs
parents: 25
diff changeset
   509
            QString type = QContactPhoneNumber::DefinitionName;
hgs
parents: 25
diff changeset
   510
hgs
parents: 25
diff changeset
   511
            args << type;
hgs
parents: 25
diff changeset
   512
            args << data;
hgs
parents: 25
diff changeset
   513
        }
hgs
parents: 25
diff changeset
   514
        
hgs
parents: 25
diff changeset
   515
        //service stuff.
hgs
parents: 25
diff changeset
   516
        QString serviceName("com.nokia.services.phonebookservices");
hgs
parents: 25
diff changeset
   517
     
hgs
parents: 25
diff changeset
   518
        XQAiwRequest* request;
hgs
parents: 25
diff changeset
   519
        XQApplicationManager appManager;
hgs
parents: 25
diff changeset
   520
        request = appManager.create(serviceName, "Fetch", operation, true); // embedded
hgs
parents: 25
diff changeset
   521
        if ( request == NULL )
hgs
parents: 25
diff changeset
   522
            {
hgs
parents: 25
diff changeset
   523
            return;       
hgs
parents: 25
diff changeset
   524
            }
hgs
parents: 25
diff changeset
   525
hgs
parents: 25
diff changeset
   526
        // Result handlers
hgs
parents: 25
diff changeset
   527
        connect (request, SIGNAL(requestOk(const QVariant&)), 
hgs
parents: 25
diff changeset
   528
            this, SLOT(handleOk(const QVariant&)));
hgs
parents: 25
diff changeset
   529
        connect (request, SIGNAL(requestError(const QVariant&)), 
hgs
parents: 25
diff changeset
   530
            this, SLOT(handleError(const QVariant&)));
hgs
parents: 25
diff changeset
   531
        
hgs
parents: 25
diff changeset
   532
        request->setArguments(args);
hgs
parents: 25
diff changeset
   533
        request->send();
hgs
parents: 25
diff changeset
   534
        delete request;
hgs
parents: 25
diff changeset
   535
    }
hgs
parents: 25
diff changeset
   536
}
hgs
parents: 25
diff changeset
   537
hgs
parents: 25
diff changeset
   538
void UniViewerAddressWidget::handleOk(const QVariant& result)
hgs
parents: 25
diff changeset
   539
    {
hgs
parents: 25
diff changeset
   540
    Q_UNUSED(result)
hgs
parents: 25
diff changeset
   541
    }
hgs
parents: 25
diff changeset
   542
hgs
parents: 25
diff changeset
   543
void UniViewerAddressWidget::handleError(int errorCode, const QString& errorMessage)
hgs
parents: 25
diff changeset
   544
    {
hgs
parents: 25
diff changeset
   545
    Q_UNUSED(errorMessage)
hgs
parents: 25
diff changeset
   546
    Q_UNUSED(errorCode)
hgs
parents: 25
diff changeset
   547
    }
hgs
parents: 25
diff changeset
   548
hgs
parents: 25
diff changeset
   549
void UniViewerAddressWidget::saveToContacts()
hgs
parents: 25
diff changeset
   550
{
48
4f501b74aeb1 201029_02
hgs
parents: 37
diff changeset
   551
    openContactInfo();
37
hgs
parents: 25
diff changeset
   552
}
hgs
parents: 25
diff changeset
   553
hgs
parents: 25
diff changeset
   554
void UniViewerAddressWidget::sendMessage()
hgs
parents: 25
diff changeset
   555
{
hgs
parents: 25
diff changeset
   556
    HbAction* action = qobject_cast<HbAction*>(sender());
hgs
parents: 25
diff changeset
   557
hgs
parents: 25
diff changeset
   558
    if(action)
hgs
parents: 25
diff changeset
   559
    {
hgs
parents: 25
diff changeset
   560
        QString phoneNumber = action->data().toString();
hgs
parents: 25
diff changeset
   561
        QString alias;
hgs
parents: 25
diff changeset
   562
hgs
parents: 25
diff changeset
   563
        QTextBlock textBlock = this->document()->findBlock(mCursorPos);
hgs
parents: 25
diff changeset
   564
hgs
parents: 25
diff changeset
   565
        QTextBlock::iterator it;
hgs
parents: 25
diff changeset
   566
hgs
parents: 25
diff changeset
   567
        for (it = textBlock.begin(); !(it.atEnd()); ++it)
hgs
parents: 25
diff changeset
   568
        {
hgs
parents: 25
diff changeset
   569
            QTextFragment currentFragment = it.fragment();
hgs
parents: 25
diff changeset
   570
hgs
parents: 25
diff changeset
   571
            if (currentFragment.isValid() && currentFragment.contains(mCursorPos)
hgs
parents: 25
diff changeset
   572
                && currentFragment.charFormat().fontUnderline())
hgs
parents: 25
diff changeset
   573
            {
hgs
parents: 25
diff changeset
   574
                QString txt = currentFragment.text();
hgs
parents: 25
diff changeset
   575
                if(txt != phoneNumber)
hgs
parents: 25
diff changeset
   576
                {
hgs
parents: 25
diff changeset
   577
                    alias = txt;  
hgs
parents: 25
diff changeset
   578
                }
hgs
parents: 25
diff changeset
   579
                break;
hgs
parents: 25
diff changeset
   580
            }
hgs
parents: 25
diff changeset
   581
        }
hgs
parents: 25
diff changeset
   582
        
hgs
parents: 25
diff changeset
   583
hgs
parents: 25
diff changeset
   584
        //invoke editor & pass phoneNumber.
hgs
parents: 25
diff changeset
   585
        emit sendMessage(phoneNumber,alias);
hgs
parents: 25
diff changeset
   586
    }
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   587
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   588
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   589
// EOF