messagingapp/msgui/unifiedviewer/src/univiewertextitem.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 11 Jun 2010 13:35:48 +0300
changeset 34 84197e66a4bd
parent 31 ebfee66fde93
child 43 35b64624a9e7
permissions -rw-r--r--
Revision: 201021 Kit: 2010123
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
 * All rights reserved.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
 *
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
 * Initial Contributors:
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
 *
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
 * Contributors:
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
 *
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
 * Description:
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
 * Message body preview class.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
 * has in built logic for finding phone number, email, url.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
 *
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
 */
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
#include "univiewertextitem.h"
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
#include "msgcontacthandler.h"
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
#include <QRegExp>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
#include <QApplication>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
#include <QClipboard>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
#include <QTextBlock>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    28
#include <HbTapGesture>
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
#include <HbMenu>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
#include <HbAction>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
#include <cntservicescontact.h>
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    32
#include <xqservicerequest.h>
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
#include <xqaiwrequest.h>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
#include <xqappmgr.h>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
//consts
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
//regexp
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
const QString NUMBER_PATTERN("(\\(|\\+|\\d)((?:\\d{2,})((?:[\\s-/.\\)\\()])*(?:(\\d+|\\))))*)|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
const QString EMAIL_PATTERN("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
const QString URL_PATTERN("(((ht|f|rt)(tp|sp)(s?)\\:\\/\\/)|(www|wap)(?:\\.))(([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&amp;%\\$#_=~]*)(\\.)([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&amp;%\\$#_=~]*))+");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
//rules
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
const QString NUMBER_RULE("NUMBER_RULE");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
const QString EMAIL_RULE("EMAIL_RULE");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
const QString URL_RULE("URL_RULE");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
//localization
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
#define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
#define LOC_CALL              hbTrId("txt_common_menu_call_verb")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
#define LOC_SEND_MESSAGE      hbTrId("txt_common_menu_send_message")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
#define LOC_SAVE_TO_CONTACTS  hbTrId("txt_common_menu_save_to_contacts")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
#define LOC_COPY              hbTrId("txt_common_menu_copy")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
#define LOC_CREATE_EMAIL      hbTrId("txt_messaging_menu_create_mail")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
#define LOC_OPEN_LINK         hbTrId("txt_messaging_menu_open_link")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
#define LOC_ADD_TO_BOOKMARKS  hbTrId("txt_messaging_menu_add_to_bookmarks")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
#define LOC_COPY_LINK         hbTrId("txt_messaging_menu_copy_link")
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
UniViewerTextItem::UniViewerTextItem(QGraphicsItem* parent):
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    63
HbTextEdit(parent),
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
mFindOn(true),
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
mCursorPos(-1)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
    this->setReadOnly(true);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
    this->setScrollable(false);
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    69
    this->setSmileysEnabled(true);
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    70
    this->setCursorVisibility(Hb::TextCursorHidden);
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    71
    this->setFlag(QGraphicsItem::ItemIsFocusable,false);
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    73
    this->setBackgroundItem(0);   
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    75
    //inserting rules and patterns to map.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    76
    mRules.insert(NUMBER_RULE,NUMBER_PATTERN);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
    mRules.insert(EMAIL_RULE,EMAIL_PATTERN);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
    mRules.insert(URL_RULE,URL_PATTERN);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
    mFormatNormal.setForeground(palette().link());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
    mFormatNormal.setBackground(Qt::transparent);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
    mFormatHighlight.setBackground(palette().highlight());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
    mFormatHighlight.setForeground(palette().highlightedText());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
    connect(this, SIGNAL(aboutToShowContextMenu(HbMenu*,QPointF)),
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
            this, SLOT(aboutToShowContextMenu(HbMenu*,QPointF)));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    89
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
UniViewerTextItem::~UniViewerTextItem()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
void UniViewerTextItem::setFindOn(bool on)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
    mFindOn = on;   
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
void UniViewerTextItem::setText(const QString& text)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
    this->setPlainText(text);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
    applyRule();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
void UniViewerTextItem::applyRule()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
    if(mFindOn == false)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   111
        return;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   113
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   114
    QMap<QString, QString>::const_iterator i;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   115
    for (i = mRules.constBegin(); i != mRules.constEnd(); ++i)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   116
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   117
        QString ruleName = i.key();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   118
        QString rule = i.value();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   119
        QRegExp ruleExp(rule);
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   120
        ruleExp.setCaseSensitivity(Qt::CaseInsensitive);
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   121
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   122
        QTextCursor cursor = this->document()->find(ruleExp);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   123
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   124
        while(cursor.hasSelection())
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   125
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   126
            // Insert anchor in the document
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   127
            QTextCharFormat f;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   128
            f.setFontUnderline(true);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   129
            f.setForeground(palette().link());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   130
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   131
            //prepending rule name to identiy different fragment to which
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   132
            //catagory it belongs to.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   133
            QString txt = cursor.selectedText().prepend(ruleName);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   134
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   135
            if(ruleName == NUMBER_RULE)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   136
            {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   137
                //removing special char(s) from phone numbers.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   138
                QRegExp numberCharExp("[\\s-/.\\(\\)]");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   139
                txt = txt.remove(numberCharExp);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   140
            }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   141
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   142
            f.setAnchorHref(txt);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   143
            f.setAnchor(true);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   144
            cursor.mergeCharFormat(f);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   145
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   146
            // Find next
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   147
            cursor = this->document()->find(ruleExp, cursor);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   148
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   149
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   150
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   151
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   152
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   153
void UniViewerTextItem::aboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   154
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   155
    // Check if there is an anchor at this pos
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   156
    QString  anchor = this->anchorAt(pos);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   157
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   158
    if(!anchor.isEmpty() && !this->textCursor().hasSelection())
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   159
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   160
        //remove default actions.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   161
        contextMenu->clearActions();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   162
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   163
        if(anchor.contains(QRegExp("^"+NUMBER_RULE)))
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   164
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   165
            addNumberMenu(contextMenu,anchor);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   166
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   167
        else if(anchor.contains(QRegExp("^"+EMAIL_RULE)))
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   168
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   169
            addEmailMenu(contextMenu,anchor);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   170
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   171
        else if(anchor.contains(QRegExp("^"+URL_RULE)))
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   172
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   173
            addUrlMenu(contextMenu,anchor);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   174
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   175
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   176
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   177
    connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   178
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   179
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   180
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   181
void UniViewerTextItem::gestureEvent(QGestureEvent* event)
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   182
{
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   183
    //handle gesture to highlight and dehighlight find item.
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   184
    
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   185
    if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture)))
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   186
    {
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   187
        //capturing gesture position, and map to local co-ordinates.
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   188
        QPointF pos = mapFromScene(tap->scenePosition());
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   189
        
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   190
        switch (tap->state()) 
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   191
        {
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   192
            case Qt::GestureStarted:
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   193
            {
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   194
                //highlight find item.
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   195
                QTextDocument* doc = this->document();
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   196
                mCursorPos = doc->documentLayout()->hitTest(pos, Qt::ExactHit);
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   197
                highlightText(true);
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   198
                break;
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   199
            }  
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   200
            
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   201
            case Qt::GestureFinished:
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   202
            {
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   203
                if (HbTapGesture::Tap == tap->tapStyleHint()) 
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   204
                {
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   205
                    //gesture is finshed dehighlight text.
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   206
                    highlightText(false);
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   207
                    
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   208
                    QString anchor = this->anchorAt(pos);
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   209
                    
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   210
                    //do short tap action.
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   211
                    if (!anchor.isEmpty() && !this->textCursor().hasSelection())
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   212
                    {
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   213
                        shortTapAction(anchor);
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   214
                    }
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   215
                }
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   216
                break;
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   217
            }
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   218
            
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   219
            case Qt::GestureCanceled:
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   220
            {
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   221
                //gesture is canceled due to pan or swipe, dehighlight text.
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   222
                if (HbTapGesture::Tap == tap->tapStyleHint()) 
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   223
                {
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   224
                highlightText(false);
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   225
                break;
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   226
                }
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   227
            }
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   228
            default:
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   229
                break;
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   230
        }
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   231
        event->accept();
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   232
    }
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   233
    else
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   234
    {
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   235
        event->ignore();
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   236
    }
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   237
    
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   238
    //passing gesture event to base class.
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   239
    HbTextEdit::gestureEvent(event);
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   240
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   241
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   242
void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   243
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   244
    HbAction* action = NULL;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   245
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   246
    action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   247
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   248
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   249
    action = contextMenu->addAction(LOC_CALL, this, SLOT(call()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   250
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   251
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   252
    action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   253
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   254
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   255
    action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   256
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   257
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   258
    action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   259
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   260
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   261
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   262
void UniViewerTextItem::addEmailMenu(HbMenu* contextMenu,const QString& data)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   263
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   264
    HbAction* action = NULL;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   265
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   266
    action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   267
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   268
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   269
    action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   270
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   271
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   272
    action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   273
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   274
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   275
    action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   276
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   277
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   278
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   279
void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   280
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   281
    HbAction* action = NULL;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   282
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   283
    action = contextMenu->addAction(LOC_OPEN_LINK, this, SLOT(openLink()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   284
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   285
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   286
    action = contextMenu->addAction(LOC_ADD_TO_BOOKMARKS, this, SLOT(addToBookmarks()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   287
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   288
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   289
    action = contextMenu->addAction(LOC_COPY_LINK, this, SLOT(copyToClipboard()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   290
    action->setData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   291
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   292
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   293
void UniViewerTextItem::shortTapAction(QString anchor)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   294
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   295
    HbAction action;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   296
    action.setData(anchor);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   297
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   298
    if(anchor.contains(NUMBER_RULE))
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   299
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   300
        //open vcard template.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   301
        connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   302
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   303
    else if(anchor.contains(EMAIL_RULE))
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   304
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   305
        //Create email
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   306
        connect(&action,SIGNAL(triggered()),this,SLOT(createEmail()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   307
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   308
    else if(anchor.contains(URL_RULE))
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   309
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   310
        //Open link in the browser
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   311
        connect(&action,SIGNAL(triggered()),this,SLOT(openLink()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   312
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   313
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   314
    action.trigger();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   315
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   316
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   317
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   318
void UniViewerTextItem::copyToClipboard()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   319
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   320
    HbAction* action = qobject_cast<HbAction*>(sender());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   321
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   322
    if(action)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   323
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   324
        QMimeData* data = new QMimeData();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   325
        QString str = action->data().toString();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   326
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   327
        //removing rule name before setting it to clipboard.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   328
        str.remove(QRegExp("^"+NUMBER_RULE));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   329
        str.remove(QRegExp("^"+EMAIL_RULE));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   330
        str.remove(QRegExp("^"+URL_RULE));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   331
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   332
        data->setText(str);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   333
        QApplication::clipboard()->setMimeData(data);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   334
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   335
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   336
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   337
void UniViewerTextItem::call()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   338
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   339
    HbAction* action = qobject_cast<HbAction*>(sender());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   340
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   341
    if(action)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   342
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   343
        QString phoneNumber = action->data().toString();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   344
        phoneNumber.remove(NUMBER_RULE);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   345
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   346
        //invoke dialer service and pass phoneNumber.        
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   347
        QString serviceName("com.nokia.symbian.ICallDial");
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   348
        QString operation("dial(QString)");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   349
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   350
        XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   351
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   352
        connect(serviceRequest, SIGNAL(requestCompleted(QVariant)),
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   353
                this, SLOT(onServiceRequestCompleted()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   354
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   355
        connect(serviceRequest, SIGNAL(requestError(int)),
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   356
                this, SLOT(onServiceRequestCompleted()));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   357
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   358
        *serviceRequest << phoneNumber;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   359
        serviceRequest->send();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   360
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   361
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   362
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   363
void UniViewerTextItem::sendMessage()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   364
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   365
    HbAction* action = qobject_cast<HbAction*>(sender());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   366
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   367
    if(action)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   368
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   369
        QString phoneNumber = action->data().toString();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   370
        phoneNumber.remove(NUMBER_RULE);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   371
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   372
        //invoke editor & pass phoneNumber.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   373
        emit sendMessage(phoneNumber);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   374
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   375
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   376
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   377
void UniViewerTextItem::createEmail()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   378
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   379
    HbAction* action = qobject_cast<HbAction*>(sender());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   380
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   381
    if ( action )
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   382
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   383
        QString emailId = action->data().toString();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   384
        emailId.remove(EMAIL_RULE);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   385
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   386
        // Launch email editor
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   387
        QString interfaceName("com.nokia.symbian.IEmailMessageSend");
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   388
        QString operation("send(QVariant)");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   389
        XQApplicationManager appManager;
34
84197e66a4bd Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   390
        XQAiwRequest* request = appManager.create(interfaceName, 
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   391
			operation, true); 
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   392
        if ( request == NULL )
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   393
            {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   394
            return;       
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   395
            }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   396
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   397
        // Fill args
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   398
        QStringList recipients;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   399
        recipients.append(emailId);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   400
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   401
        QMap<QString,QVariant> map;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   402
        map.insert(QString("to"),recipients);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   403
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   404
        QList<QVariant> args;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   405
        args.append(map);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   406
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   407
        // Result handlers
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   408
        connect (request, SIGNAL(requestOk(const QVariant&)), 
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   409
         this, SLOT(handleOk(const QVariant&)));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   410
        connect (request, SIGNAL(requestError(const QVariant&)), 
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   411
             this, SLOT(handleError(const QVariant&)));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   412
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   413
        request->setArguments(args);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   414
        request->send();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   415
        delete request;       
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   416
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   417
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   418
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   419
void UniViewerTextItem::openLink()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   420
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   421
    HbAction* action = qobject_cast<HbAction*>(sender());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   422
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   423
    if(action)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   424
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   425
        QString url = action->data().toString();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   426
        url.remove(URL_RULE);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   427
        //invoke browser service  & pass url.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   428
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   429
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   430
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   431
void UniViewerTextItem::addToBookmarks()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   432
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   433
    HbAction* action = qobject_cast<HbAction*>(sender());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   434
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   435
    if(action)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   436
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   437
        QString url = action->data().toString();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   438
        url.remove(URL_RULE);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   439
        //invoke browser service to save url.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   440
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   441
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   442
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   443
void UniViewerTextItem::openContactInfo()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   444
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   445
    HbAction* action = qobject_cast<HbAction*>(sender());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   446
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   447
    if(action)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   448
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   449
        QList<QVariant> args;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   450
        QString operation;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   451
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   452
        QString data = action->data().toString();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   453
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   454
        if(data.contains(QRegExp("^"+NUMBER_RULE)))
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   455
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   456
            data.remove(NUMBER_RULE);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   457
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   458
            int contactId = MsgContactHandler::resolveContactDisplayName(
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   459
                                         data, 
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   460
                                         QContactPhoneNumber::DefinitionName,
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   461
                                         QContactPhoneNumber::FieldNumber);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   462
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   463
            if(contactId > 0)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   464
                {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   465
                //open contact card
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   466
                operation = QString("open(int)");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   467
                args << contactId;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   468
                }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   469
            else
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   470
                {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   471
                //save to contacts with phone number field prefilled.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   472
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   473
                operation = QString("editCreateNew(QString,QString)");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   474
                QString type = QContactPhoneNumber::DefinitionName;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   475
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   476
                args << type;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   477
                args << data;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   478
                }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   479
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   480
        else if(data.contains(QRegExp("^"+EMAIL_RULE)))
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   481
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   482
            data.remove(EMAIL_RULE);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   483
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   484
            int contactId = MsgContactHandler::resolveContactDisplayName(
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   485
                    data,
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   486
                    QContactEmailAddress::DefinitionName,
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   487
                    QContactEmailAddress::FieldEmailAddress);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   488
            
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   489
            if(contactId > 0)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   490
                {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   491
                //open contact card
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   492
                operation = QString("open(int)");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   493
                args << contactId;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   494
                }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   495
            else
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   496
                {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   497
                //save to contacts with e-mail field prefilled.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   498
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   499
                operation = QString("editCreateNew(QString,QString)");                
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   500
                
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   501
                QString type = QContactEmailAddress::DefinitionName;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   502
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   503
                args << type;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   504
                args << data;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   505
                }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   506
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   507
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   508
        //service stuff.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   509
        QString serviceName("com.nokia.services.phonebookservices");
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   510
     
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   511
        XQAiwRequest* request;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   512
        XQApplicationManager appManager;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   513
        request = appManager.create(serviceName, "Fetch", operation, true); // embedded
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   514
        if ( request == NULL )
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   515
            {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   516
            return;       
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   517
            }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   518
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   519
        // Result handlers
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   520
        connect (request, SIGNAL(requestOk(const QVariant&)), 
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   521
			this, SLOT(handleOk(const QVariant&)));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   522
        connect (request, SIGNAL(requestError(const QVariant&)), 
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   523
			this, SLOT(handleError(const QVariant&)));
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   524
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   525
        request->setArguments(args);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   526
        request->send();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   527
        delete request;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   528
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   529
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   530
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   531
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   532
void UniViewerTextItem::saveToContacts()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   533
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   534
    //handler for save to contacts.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   535
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   536
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   537
void UniViewerTextItem::onServiceRequestCompleted()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   538
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   539
    //service request is now complete. delete it.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   540
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   541
    XQServiceRequest* request = qobject_cast<XQServiceRequest*>(sender());
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   542
    
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   543
    if(request)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   544
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   545
        delete request;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   546
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   547
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   548
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   549
void UniViewerTextItem::menuClosed()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   550
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   551
    highlightText(false);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   552
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   553
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   554
void UniViewerTextItem::highlightText(bool highlight)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   555
{
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   556
    QTextBlock textBlock = this->document()->findBlock(mCursorPos);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   557
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   558
    QTextBlock::iterator it;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   559
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   560
    for (it = textBlock.begin(); !(it.atEnd()); ++it)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   561
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   562
        QTextFragment currentFragment = it.fragment();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   563
        
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   564
        if (currentFragment.isValid() && currentFragment.contains(mCursorPos)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   565
            && currentFragment.charFormat().fontUnderline())
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   566
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   567
            int start = currentFragment.position();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   568
            int length = currentFragment.length();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   569
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   570
            QTextCursor cursor = this->textCursor();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   571
            cursor.clearSelection();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   572
            cursor.setPosition(start);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   573
            cursor.setPosition(start + length,QTextCursor::KeepAnchor);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   574
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   575
            if(highlight)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   576
            {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   577
                cursor.mergeCharFormat(mFormatHighlight);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   578
            }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   579
            else
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   580
            {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   581
                cursor.mergeCharFormat(mFormatNormal);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   582
            }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   583
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   584
            cursor.clearSelection();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   585
            break;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   586
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   587
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   588
}
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   589
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   590
//---------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   591
// UniViewerTextItem::handleOk
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   592
//
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   593
//---------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   594
void UniViewerTextItem::handleOk(const QVariant& result)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   595
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   596
    Q_UNUSED(result)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   597
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   598
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   599
//---------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   600
// UniViewerTextItem::handleError
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   601
// 
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   602
//---------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   603
void UniViewerTextItem::handleError(int errorCode, const QString& errorMessage)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   604
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   605
    Q_UNUSED(errorMessage)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   606
    Q_UNUSED(errorCode)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   607
    }