messagingapp/msgui/appengine/src/conversationsmodel.cpp
author hgs
Fri, 09 Jul 2010 14:46:10 +0530
changeset 41 25fe1fe642e3
parent 38 4e4b6adb1024
child 46 b1f0785c289d
permissions -rw-r--r--
201027_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
 * All rights reserved.
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
 * Initial Contributors:
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
 * Contributors:
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
 * Description:
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
 */
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "conversationsmodel.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
#include "conversationsenginedefines.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
#include "conversationmsgstorehandler.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
#include "convergedmessage.h"
37
hgs
parents: 25
diff changeset
    22
#include <xqconversions.h>
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
#include "conversationsengineutility.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include "unidatamodelloader.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
#include "unidatamodelplugininterface.h"
37
hgs
parents: 25
diff changeset
    26
#include "ringbc.h"
hgs
parents: 25
diff changeset
    27
#include "msgcontacthandler.h"
hgs
parents: 25
diff changeset
    28
#include "mmsconformancecheck.h"
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include <ccsconversationentry.h>
37
hgs
parents: 25
diff changeset
    30
#include <fileprotectionresolver.h>
hgs
parents: 25
diff changeset
    31
hgs
parents: 25
diff changeset
    32
#include "debugtraces.h"
hgs
parents: 25
diff changeset
    33
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
#include <QFile>
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    35
#include <QFileInfo>
37
hgs
parents: 25
diff changeset
    36
#include <s32mem.h>
hgs
parents: 25
diff changeset
    37
#include <s32strm.h>
hgs
parents: 25
diff changeset
    38
#include <fbs.h>
hgs
parents: 25
diff changeset
    39
#include <ccsdefs.h>
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
37
hgs
parents: 25
diff changeset
    41
//CONSTANTS
hgs
parents: 25
diff changeset
    42
_LIT(KDbFileName, "c:[2002A542]conversations.db");
hgs
parents: 25
diff changeset
    43
hgs
parents: 25
diff changeset
    44
// preview sql query
hgs
parents: 25
diff changeset
    45
_LIT(KSelectConvMsgsStmt, "SELECT message_id, msg_processingstate, subject, body_text, preview_path, msg_property, preview_icon FROM conversation_messages WHERE message_id=:message_id ");
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
37
hgs
parents: 25
diff changeset
    47
//selecet preview-icon query
hgs
parents: 25
diff changeset
    48
_LIT(KSelectPreviewIconStmt,"SELECT  message_id, preview_icon FROM conversation_messages WHERE message_id = :message_id ");
hgs
parents: 25
diff changeset
    49
hgs
parents: 25
diff changeset
    50
// preview-cache max cost (items)
hgs
parents: 25
diff changeset
    51
const int CACHE_COST =  50;
hgs
parents: 25
diff changeset
    52
//Preview thumbnail size
hgs
parents: 25
diff changeset
    53
const int KWidth = 9.5 * 6.7;
hgs
parents: 25
diff changeset
    54
const int KHeight = 9.5 * 6.7;
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
//---------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
// ConversationsModel::ConversationsModel
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
// Constructor
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
//---------------------------------------------------------------
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    59
ConversationsModel::ConversationsModel(ConversationMsgStoreHandler* msgStoreHandler,
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    60
    QObject* parent) :
37
hgs
parents: 25
diff changeset
    61
    QStandardItemModel(parent), mMsgStoreHandler(msgStoreHandler), iSqlDbOpen(EFalse)
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    62
{
37
hgs
parents: 25
diff changeset
    63
    //Open SQL DB
hgs
parents: 25
diff changeset
    64
    if (KErrNone == iSqlDb.Open(KDbFileName))
hgs
parents: 25
diff changeset
    65
    {
hgs
parents: 25
diff changeset
    66
        iSqlDbOpen = ETrue;
hgs
parents: 25
diff changeset
    67
    }
hgs
parents: 25
diff changeset
    68
    previewIconCache.setMaxCost(CACHE_COST);
hgs
parents: 25
diff changeset
    69
hgs
parents: 25
diff changeset
    70
    int err = connect(this, SIGNAL(retrievePreviewIcon(int, QString&)), this,
hgs
parents: 25
diff changeset
    71
        SLOT(updatePreviewIcon(int, QString&)));
hgs
parents: 25
diff changeset
    72
    QCRITICAL_WRITE_FORMAT("Error from connect()", err)
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    73
    iDataModelPluginLoader = new UniDataModelLoader;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    74
    iMmsDataPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    75
    iBioMsgPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    76
}
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
//---------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
// ConversationsModel::~ConversationsModel
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
// Destructor
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
//---------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
ConversationsModel::~ConversationsModel()
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    83
{
37
hgs
parents: 25
diff changeset
    84
    //Close SQL-DB
hgs
parents: 25
diff changeset
    85
    iSqlDb.Close();
hgs
parents: 25
diff changeset
    86
hgs
parents: 25
diff changeset
    87
	//clear preview-cache
hgs
parents: 25
diff changeset
    88
    previewIconCache.clear();
hgs
parents: 25
diff changeset
    89
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    90
    if (iDataModelPluginLoader) {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
        delete iDataModelPluginLoader;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
        iDataModelPluginLoader = NULL;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
    94
}
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    95
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    96
//---------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    97
// ConversationsModel::data
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    98
// @see header
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    99
//---------------------------------------------------------------
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   100
QVariant ConversationsModel::data(const QModelIndex & index, int role) const
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
{
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
    QVariant value;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
    QStandardItem* item = itemFromIndex(index);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   104
    switch (role) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   105
    case ConversationId:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   106
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   107
        value = item->data(ConversationId);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   108
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   109
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   110
    case UnReadStatus:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   111
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   112
        value = item->data(UnReadStatus);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   113
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   114
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   115
    case ContactId:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   116
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   117
        value = item->data(ContactId);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   118
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   119
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   120
    case TimeStamp:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   121
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   122
        value = item->data(TimeStamp);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   123
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   124
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   125
    case ConvergedMsgId:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   126
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   127
        value = item->data(ConvergedMsgId);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   128
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   129
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   130
    case MessageProperty:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   131
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   132
        value = item->data(MessageProperty);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   133
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   134
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   135
    case MessageType:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   136
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   137
        value = item->data(MessageType);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   138
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   139
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   140
    case MessageSubType:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   141
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   142
        value = item->data(MessageSubType);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   143
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   144
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   145
    case Subject:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   146
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   147
        value = item->data(Subject);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   148
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   149
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   150
    case BodyText:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   151
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   152
        value = item->data(BodyText);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   153
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   154
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   155
    case ConversationAddress:
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
    {
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   157
        value = item->data(ConversationAddress);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   158
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   159
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   160
    case Direction:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   161
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   162
        value = item->data(Direction);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   163
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   164
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   165
    case SendingState:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   166
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   167
        value = item->data(SendingState);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   168
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   169
    }
37
hgs
parents: 25
diff changeset
   170
    case PreviewIcon:
hgs
parents: 25
diff changeset
   171
    {
hgs
parents: 25
diff changeset
   172
        QString filepath(item->data(Attachments).toString());
hgs
parents: 25
diff changeset
   173
        int msgId = item->data(ConvergedMsgId).toInt();
hgs
parents: 25
diff changeset
   174
        HbIcon *icon = getPreviewIconItem(msgId, filepath);
hgs
parents: 25
diff changeset
   175
        return *icon;
hgs
parents: 25
diff changeset
   176
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   177
    case MessagePriority:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   178
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   179
        value = item->data(MessagePriority);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   180
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   181
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   182
    case Attachments:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   183
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   184
        value = item->data(Attachments);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   185
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   186
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   187
    case MessageLocation:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   188
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   189
        value = item->data(MessageLocation);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   190
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   191
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   192
    case MessageStore:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   193
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   194
        value = item->data(MessageStore);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   195
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   196
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   197
    case ConversationAlias:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   198
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   199
        value = item->data(ConversationAlias);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   200
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   201
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   202
    case UnreadCount:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   203
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   204
        value = item->data(UnreadCount);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   205
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   206
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   207
    case DisplayName: // Fall through start
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   208
        value = item->data(DisplayName);
37
hgs
parents: 25
diff changeset
   209
        break;
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   210
    case Avatar: // Fall througn end
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   211
        value = item->data(Avatar);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   212
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   213
    case NotificationStatus:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   214
        value = item->data(NotificationStatus);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   215
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   216
    default:
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   217
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   218
        //No matching role found, set invalid variant
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   219
        value = QVariant();
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   220
        break;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   221
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   222
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   223
    return value;
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   224
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
//---------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   227
// ConversationsModel::addRow
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   228
// @see header
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   229
//---------------------------------------------------------------
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   230
void ConversationsModel::addRow(const CCsConversationEntry& entry, bool dynamicUpdate)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   231
{
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   232
    int msgId = entry.EntryId();
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   233
    //match, if found update else add item
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   234
    QModelIndexList indexList = this->match(index(0, 0), ConvergedMsgId, msgId, -1,
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   235
        Qt::MatchExactly);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   236
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   237
    // if not found, add new item
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   238
    if (indexList.count() == 0) {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   239
        QStandardItem* item = new QStandardItem();
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   240
        populateItem(*item, entry);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   241
        if (!dynamicUpdate) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   242
            insertRow(0, item);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   243
        }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   244
        else {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   245
            int i;
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   246
            for (i = rowCount() - 1; i >= 0; --i) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   247
                QStandardItem* modelItem = this->item(i, 0);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   248
                if (modelItem->data(ConvergedMsgId).toInt() < item->data(ConvergedMsgId).toInt()) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   249
                    if (i == rowCount() - 1) {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   250
                        appendRow(item);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   251
                    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   252
                    else {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   253
                        insertRow(i + 1, item);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   254
                    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   255
                    return;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   256
                }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   257
            }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   258
            if (i == 0) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   259
                insertRow(0, item);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   260
            }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   261
        }
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
    else {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   264
        // Update an existing item
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   265
        QModelIndex index = indexList[0];
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   266
        QStandardItem* item = this->item(index.row(), 0);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   267
        populateItem(*item, entry);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   268
    }
23
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
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
// ConversationsModel::deleteRow
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   273
// @see header
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   274
//---------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   275
void ConversationsModel::deleteRow(int msgId)
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   276
{
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   277
    //match, if found remove item
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   278
    QModelIndexList indexList =
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   279
        this->match(index(0, 0), ConvergedMsgId, msgId, 1, Qt::MatchExactly);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   280
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   281
    if (indexList.count() == 1) {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   282
        QModelIndex index = indexList[0];
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   283
        this->removeRow(index.row());
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   284
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   285
}
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   286
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
// ConversationsModel::populateItem
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   289
// @see header
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   290
//---------------------------------------------------------------
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   291
void ConversationsModel::populateItem(QStandardItem& item, const CCsConversationEntry& entry)
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   292
{
37
hgs
parents: 25
diff changeset
   293
    QCRITICAL_WRITE("ConversationsModel::populateItem start.");
hgs
parents: 25
diff changeset
   294
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   295
    int msgId = entry.EntryId();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   296
    // id
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   297
    item.setData(msgId, ConvergedMsgId);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   298
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   299
    // description
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   300
    HBufC* description = entry.Description();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   301
    QString subject("");
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   302
    if (description && description->Length()) {
37
hgs
parents: 25
diff changeset
   303
        subject = (XQConversions::s60DescToQString(*description));     
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   304
    }
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   305
37
hgs
parents: 25
diff changeset
   306
    // time stamp
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   307
    TTime unixEpoch(KUnixEpoch);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   308
    TTimeIntervalSeconds seconds;
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   309
    TTime timeStamp(entry.TimeStamp());
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   310
    timeStamp.SecondsFrom(unixEpoch, seconds);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   311
    item.setData(seconds.Int(), TimeStamp);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   312
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   313
    //contact details
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   314
    HBufC* contact = entry.Contact();
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   315
    if (contact && contact->Length()) {
37
hgs
parents: 25
diff changeset
   316
        item.setData(XQConversions::s60DescToQString(*contact), ConversationAddress);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   317
    }
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   319
    // message type.
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   320
    int msgType = ConversationsEngineUtility::messageType(entry.GetType());
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   321
    item.setData(msgType, MessageType);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   322
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   323
    //message sub-type
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   324
    item.setData(ConversationsEngineUtility::messageSubType(entry.GetType()), MessageSubType);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   325
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   326
    // unread status
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   327
    if (entry.IsAttributeSet(ECsAttributeUnread)) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   328
        item.setData(true, UnReadStatus);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   329
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   330
    else {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   331
        item.setData(false, UnReadStatus);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   332
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   333
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   334
    //sending state
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   335
    item.setData(entry.GetSendState(), SendingState);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   336
    // direction
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   337
    item.setData(entry.ConversationDir(), Direction);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   338
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   339
    //location
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   340
    if (entry.ConversationDir() == ECsDirectionIncoming) {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   341
        item.setData(ConvergedMessage::Inbox, MessageLocation);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   342
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   343
    else if (entry.IsAttributeSet(ECsAttributeDraft)) {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   344
        item.setData(ConvergedMessage::Draft, MessageLocation);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   345
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   346
    else if (entry.IsAttributeSet(ECsAttributeSent)) {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   347
        item.setData(ConvergedMessage::Sent, MessageLocation);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   348
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   349
    else {
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   350
        item.setData(ConvergedMessage::Outbox, MessageLocation);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   351
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   352
37
hgs
parents: 25
diff changeset
   353
    //message specific handling
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   354
    if (msgType == ConvergedMessage::Mms) {
37
hgs
parents: 25
diff changeset
   355
        QCRITICAL_WRITE("ConversationsModel::populateItem  MMS start.")
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   356
        handleMMS(item, entry);
37
hgs
parents: 25
diff changeset
   357
        QCRITICAL_WRITE("ConversationsModel::populateItem MMS end.")
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   358
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   359
    else if(msgType == ConvergedMessage::MmsNotification) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   360
        item.setData(subject, Subject);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   361
        handleMMSNotification(item, entry);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   362
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   363
    else if (msgType == ConvergedMessage::BT) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   364
        handleBlueToothMessages(item, entry);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   365
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   366
    else if (msgType == ConvergedMessage::BioMsg) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   367
        handleBioMessages(item, entry);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   368
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   369
    else {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   370
        // sms bodytext
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   371
        item.setData(subject, BodyText);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   372
    }
37
hgs
parents: 25
diff changeset
   373
hgs
parents: 25
diff changeset
   374
    QCRITICAL_WRITE("ConversationsModel::populateItem end.");
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   375
}
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   376
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   377
//---------------------------------------------------------------
37
hgs
parents: 25
diff changeset
   378
// ConversationsModel::validateMsgForForward
hgs
parents: 25
diff changeset
   379
// @see header file
hgs
parents: 25
diff changeset
   380
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   381
bool ConversationsModel::validateMsgForForward(qint32 messageId)
hgs
parents: 25
diff changeset
   382
{
hgs
parents: 25
diff changeset
   383
    bool retValue = true;
hgs
parents: 25
diff changeset
   384
    //Validate if the mms msg can be forwarded or not
hgs
parents: 25
diff changeset
   385
    MmsConformanceCheck* mmsConformanceCheck = new MmsConformanceCheck;
hgs
parents: 25
diff changeset
   386
    retValue = mmsConformanceCheck->validateMsgForForward(messageId);
hgs
parents: 25
diff changeset
   387
hgs
parents: 25
diff changeset
   388
    delete mmsConformanceCheck;
hgs
parents: 25
diff changeset
   389
    return retValue;
hgs
parents: 25
diff changeset
   390
}
hgs
parents: 25
diff changeset
   391
hgs
parents: 25
diff changeset
   392
hgs
parents: 25
diff changeset
   393
//---------------------------------------------------------------
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   394
// ConversationsModel::handleMMS
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   395
// @see header
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   396
//---------------------------------------------------------------
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   397
void ConversationsModel::handleMMS(QStandardItem& item, const CCsConversationEntry& entry)
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   398
{
37
hgs
parents: 25
diff changeset
   399
    //msg_id
hgs
parents: 25
diff changeset
   400
    int msgId = entry.EntryId();
hgs
parents: 25
diff changeset
   401
hgs
parents: 25
diff changeset
   402
    bool isEntryInDb = false;
hgs
parents: 25
diff changeset
   403
    TInt err = KErrNone;
hgs
parents: 25
diff changeset
   404
hgs
parents: 25
diff changeset
   405
    //check if db is open and query db
hgs
parents: 25
diff changeset
   406
    if (iSqlDbOpen)
hgs
parents: 25
diff changeset
   407
    {
hgs
parents: 25
diff changeset
   408
        RSqlStatement sqlSelectStmt;
hgs
parents: 25
diff changeset
   409
        err = sqlSelectStmt.Prepare(iSqlDb, KSelectConvMsgsStmt);
hgs
parents: 25
diff changeset
   410
hgs
parents: 25
diff changeset
   411
        // move to fallback option
hgs
parents: 25
diff changeset
   412
        if (KErrNone == err)
hgs
parents: 25
diff changeset
   413
            {
hgs
parents: 25
diff changeset
   414
            TInt msgIdIndex = sqlSelectStmt.ParameterIndex(_L(":message_id"));
hgs
parents: 25
diff changeset
   415
            TInt msgProcessingStateIndex = sqlSelectStmt.ColumnIndex(_L("msg_processingstate"));
hgs
parents: 25
diff changeset
   416
            TInt subjectIndex = sqlSelectStmt.ColumnIndex(_L("subject"));
hgs
parents: 25
diff changeset
   417
            TInt bodyIndex = sqlSelectStmt.ColumnIndex(_L("body_text"));
hgs
parents: 25
diff changeset
   418
            TInt previewPathIndex = sqlSelectStmt.ColumnIndex(
hgs
parents: 25
diff changeset
   419
                    _L("preview_path"));
hgs
parents: 25
diff changeset
   420
            TInt msgpropertyIndex = sqlSelectStmt.ColumnIndex(
hgs
parents: 25
diff changeset
   421
                _L("msg_property"));
hgs
parents: 25
diff changeset
   422
            TInt previewIconIndex = sqlSelectStmt.ColumnIndex(
hgs
parents: 25
diff changeset
   423
                _L("preview_icon"));
hgs
parents: 25
diff changeset
   424
hgs
parents: 25
diff changeset
   425
            err = sqlSelectStmt.BindInt(msgIdIndex, msgId);
hgs
parents: 25
diff changeset
   426
hgs
parents: 25
diff changeset
   427
            // populate item
hgs
parents: 25
diff changeset
   428
            if ((KErrNone == err) && (sqlSelectStmt.Next() == KSqlAtRow))
hgs
parents: 25
diff changeset
   429
                {
hgs
parents: 25
diff changeset
   430
                int msgProcessingState = 0;
hgs
parents: 25
diff changeset
   431
                msgProcessingState = sqlSelectStmt.ColumnInt(
hgs
parents: 25
diff changeset
   432
                        msgProcessingStateIndex);
hgs
parents: 25
diff changeset
   433
                if (msgProcessingState == EPreviewMsgProcessed)
hgs
parents: 25
diff changeset
   434
                    {
hgs
parents: 25
diff changeset
   435
                    // use entry to populate model only when,
hgs
parents: 25
diff changeset
   436
                    // entry is present in DB and its processing is over.
hgs
parents: 25
diff changeset
   437
                    RBuf subjectBuffer;
hgs
parents: 25
diff changeset
   438
                    subjectBuffer.Create(sqlSelectStmt.ColumnSize(
hgs
parents: 25
diff changeset
   439
                            subjectIndex));
hgs
parents: 25
diff changeset
   440
                    sqlSelectStmt.ColumnText(subjectIndex, subjectBuffer);
hgs
parents: 25
diff changeset
   441
hgs
parents: 25
diff changeset
   442
                    item.setData(XQConversions::s60DescToQString(
hgs
parents: 25
diff changeset
   443
                            subjectBuffer), Subject);
hgs
parents: 25
diff changeset
   444
                    subjectBuffer.Close();
hgs
parents: 25
diff changeset
   445
hgs
parents: 25
diff changeset
   446
                    RBuf bodyBuffer;
hgs
parents: 25
diff changeset
   447
                    bodyBuffer.Create(sqlSelectStmt.ColumnSize(bodyIndex));
hgs
parents: 25
diff changeset
   448
                    sqlSelectStmt.ColumnText(bodyIndex, bodyBuffer);
hgs
parents: 25
diff changeset
   449
hgs
parents: 25
diff changeset
   450
                    item.setData(
hgs
parents: 25
diff changeset
   451
                            XQConversions::s60DescToQString(bodyBuffer),
hgs
parents: 25
diff changeset
   452
                            BodyText);
hgs
parents: 25
diff changeset
   453
                    bodyBuffer.Close();
hgs
parents: 25
diff changeset
   454
hgs
parents: 25
diff changeset
   455
                    RBuf previewPathBuffer;
hgs
parents: 25
diff changeset
   456
                    previewPathBuffer.Create(sqlSelectStmt.ColumnSize(
hgs
parents: 25
diff changeset
   457
                            previewPathIndex));
hgs
parents: 25
diff changeset
   458
                    sqlSelectStmt.ColumnText(previewPathIndex,
hgs
parents: 25
diff changeset
   459
                            previewPathBuffer);
hgs
parents: 25
diff changeset
   460
hgs
parents: 25
diff changeset
   461
                    //Rightnow set inside attachments
hgs
parents: 25
diff changeset
   462
                    QString attachmentPath(XQConversions::s60DescToQString(
hgs
parents: 25
diff changeset
   463
                            previewPathBuffer));
hgs
parents: 25
diff changeset
   464
hgs
parents: 25
diff changeset
   465
                    item.setData(attachmentPath, Attachments);
hgs
parents: 25
diff changeset
   466
                    previewPathBuffer.Close();
hgs
parents: 25
diff changeset
   467
hgs
parents: 25
diff changeset
   468
                    int msgProperty = 0;
hgs
parents: 25
diff changeset
   469
                    msgProperty = sqlSelectStmt.ColumnInt(msgpropertyIndex);
hgs
parents: 25
diff changeset
   470
                    item.setData(msgProperty, MessageProperty);
hgs
parents: 25
diff changeset
   471
hgs
parents: 25
diff changeset
   472
                    RSqlColumnReadStream stream;
hgs
parents: 25
diff changeset
   473
                    //Get data from binary column BLOB
hgs
parents: 25
diff changeset
   474
                    TInt err = stream.ColumnBinary(sqlSelectStmt,
hgs
parents: 25
diff changeset
   475
                            previewIconIndex);
hgs
parents: 25
diff changeset
   476
hgs
parents: 25
diff changeset
   477
                    QCRITICAL_WRITE_FORMAT("Error from ColumnBinary()", err)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   478
37
hgs
parents: 25
diff changeset
   479
                    if (err == KErrNone)
hgs
parents: 25
diff changeset
   480
                        {
hgs
parents: 25
diff changeset
   481
                        CFbsBitmap *bitmap = new CFbsBitmap;
hgs
parents: 25
diff changeset
   482
                        TRAPD(err,bitmap->InternalizeL(stream));
hgs
parents: 25
diff changeset
   483
                        QCRITICAL_WRITE_FORMAT("Error from bitmap InternalizeL()", err)
hgs
parents: 25
diff changeset
   484
hgs
parents: 25
diff changeset
   485
                        //convert bitmap to pixmap
hgs
parents: 25
diff changeset
   486
                        if (err == KErrNone)
hgs
parents: 25
diff changeset
   487
                            {
hgs
parents: 25
diff changeset
   488
                            TSize size = bitmap->SizeInPixels();
hgs
parents: 25
diff changeset
   489
                            int bytesPerLine = bitmap->ScanLineLength(
hgs
parents: 25
diff changeset
   490
                                    size.iWidth, bitmap->DisplayMode());
hgs
parents: 25
diff changeset
   491
                            const uchar* dataPtr =
hgs
parents: 25
diff changeset
   492
                                    (const uchar*) bitmap->DataAddress();
hgs
parents: 25
diff changeset
   493
hgs
parents: 25
diff changeset
   494
                            QPixmap pixmap = QPixmap::fromImage(QImage(
hgs
parents: 25
diff changeset
   495
                                    dataPtr, size.iWidth, size.iHeight,
hgs
parents: 25
diff changeset
   496
                                    bytesPerLine, QImage::Format_RGB16));
hgs
parents: 25
diff changeset
   497
hgs
parents: 25
diff changeset
   498
                            setPreviewIcon(pixmap, attachmentPath, msgId,
hgs
parents: 25
diff changeset
   499
                                    true);
hgs
parents: 25
diff changeset
   500
hgs
parents: 25
diff changeset
   501
                            }
hgs
parents: 25
diff changeset
   502
                        //remove bitmap
hgs
parents: 25
diff changeset
   503
                        delete bitmap;
hgs
parents: 25
diff changeset
   504
                        }
hgs
parents: 25
diff changeset
   505
hgs
parents: 25
diff changeset
   506
                    //set flag to disable fallback option
hgs
parents: 25
diff changeset
   507
                    isEntryInDb = true;
hgs
parents: 25
diff changeset
   508
                    }
hgs
parents: 25
diff changeset
   509
                }
hgs
parents: 25
diff changeset
   510
            }
hgs
parents: 25
diff changeset
   511
        sqlSelectStmt.Close();
hgs
parents: 25
diff changeset
   512
        }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   513
37
hgs
parents: 25
diff changeset
   514
    //fallback option incase of db operation failure or enry not found in DB
hgs
parents: 25
diff changeset
   515
    //populate from data plugins
hgs
parents: 25
diff changeset
   516
    if (!isEntryInDb || err != KErrNone)
hgs
parents: 25
diff changeset
   517
    {
38
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   518
        int error = iMmsDataPlugin->setMessageId(entry.EntryId());
4e4b6adb1024 201025_01
hgs
parents: 37
diff changeset
   519
        if(error != KErrNone)
37
hgs
parents: 25
diff changeset
   520
        {
hgs
parents: 25
diff changeset
   521
            // skip all
hgs
parents: 25
diff changeset
   522
            return;
hgs
parents: 25
diff changeset
   523
        }
hgs
parents: 25
diff changeset
   524
        int msgProperty = 0;
hgs
parents: 25
diff changeset
   525
hgs
parents: 25
diff changeset
   526
        if (iMmsDataPlugin->attachmentCount() > 0)
hgs
parents: 25
diff changeset
   527
        {
hgs
parents: 25
diff changeset
   528
            msgProperty |= EPreviewAttachment;
hgs
parents: 25
diff changeset
   529
        }
hgs
parents: 25
diff changeset
   530
hgs
parents: 25
diff changeset
   531
        if(validateMsgForForward(entry.EntryId()))
hgs
parents: 25
diff changeset
   532
        {
hgs
parents: 25
diff changeset
   533
            msgProperty |= EPreviewForward;
hgs
parents: 25
diff changeset
   534
        }
hgs
parents: 25
diff changeset
   535
hgs
parents: 25
diff changeset
   536
        //subject
hgs
parents: 25
diff changeset
   537
        item.setData(iMmsDataPlugin->subject(), Subject);
hgs
parents: 25
diff changeset
   538
hgs
parents: 25
diff changeset
   539
        int slideCount = iMmsDataPlugin->slideCount();
hgs
parents: 25
diff changeset
   540
        bool isBodyTextSet = false;
hgs
parents: 25
diff changeset
   541
        bool isAudioSet = false;
hgs
parents: 25
diff changeset
   542
        bool isImageSet = false;
hgs
parents: 25
diff changeset
   543
        bool isVideoSet = false;
hgs
parents: 25
diff changeset
   544
        QString textContent;
hgs
parents: 25
diff changeset
   545
        QString videoPath;
hgs
parents: 25
diff changeset
   546
        QString imagePath;
hgs
parents: 25
diff changeset
   547
hgs
parents: 25
diff changeset
   548
        for (int i = 0; i < slideCount; ++i)
hgs
parents: 25
diff changeset
   549
        {
hgs
parents: 25
diff changeset
   550
            UniMessageInfoList objectList = iMmsDataPlugin->slideContent(i);
hgs
parents: 25
diff changeset
   551
            for (int index = 0; index < objectList.count(); ++index)
hgs
parents: 25
diff changeset
   552
            {
hgs
parents: 25
diff changeset
   553
                if (!isBodyTextSet && objectList[index]->mimetype().contains(
hgs
parents: 25
diff changeset
   554
                    "text"))
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   555
                {
37
hgs
parents: 25
diff changeset
   556
                    QFile file(objectList[index]->path());
hgs
parents: 25
diff changeset
   557
                    file.open(QIODevice::ReadOnly);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   558
                    textContent = file.readAll();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   559
                    item.setData(textContent, BodyText);
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   560
                    isBodyTextSet = true;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   561
                    file.close();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   562
                }
37
hgs
parents: 25
diff changeset
   563
                if (!isVideoSet && !isImageSet && objectList[index]->mimetype().contains(
hgs
parents: 25
diff changeset
   564
                    "image"))
hgs
parents: 25
diff changeset
   565
                {
hgs
parents: 25
diff changeset
   566
                    isImageSet = true;
hgs
parents: 25
diff changeset
   567
                    msgProperty |= EPreviewImage;
hgs
parents: 25
diff changeset
   568
                    if (objectList[index]->isProtected())
hgs
parents: 25
diff changeset
   569
                    {
hgs
parents: 25
diff changeset
   570
                        msgProperty |= EPreviewProtectedImage;
hgs
parents: 25
diff changeset
   571
                    }
hgs
parents: 25
diff changeset
   572
                    if (objectList[index]->isCorrupted())
hgs
parents: 25
diff changeset
   573
                    {
hgs
parents: 25
diff changeset
   574
                        msgProperty |= EPreviewCorruptedImage;
hgs
parents: 25
diff changeset
   575
                    }
hgs
parents: 25
diff changeset
   576
                    imagePath = objectList[index]->path();
hgs
parents: 25
diff changeset
   577
                }
hgs
parents: 25
diff changeset
   578
                if (!isVideoSet && !isAudioSet && objectList[index]->mimetype().contains(
hgs
parents: 25
diff changeset
   579
                    "audio"))
hgs
parents: 25
diff changeset
   580
                {
hgs
parents: 25
diff changeset
   581
                    msgProperty |= EPreviewAudio;
hgs
parents: 25
diff changeset
   582
                    if (objectList[index]->isProtected())
hgs
parents: 25
diff changeset
   583
                    {
hgs
parents: 25
diff changeset
   584
                        msgProperty |= EPreviewProtectedAudio;
hgs
parents: 25
diff changeset
   585
                    }
hgs
parents: 25
diff changeset
   586
                    if (objectList[index]->isCorrupted())
hgs
parents: 25
diff changeset
   587
                    {
hgs
parents: 25
diff changeset
   588
                        msgProperty |= EPreviewCorruptedAudio;
hgs
parents: 25
diff changeset
   589
                    }
hgs
parents: 25
diff changeset
   590
                    isAudioSet = true;
hgs
parents: 25
diff changeset
   591
                }
hgs
parents: 25
diff changeset
   592
                if (!( isImageSet || isAudioSet) && !isVideoSet && objectList[index]->mimetype().contains(
hgs
parents: 25
diff changeset
   593
                    "video"))
hgs
parents: 25
diff changeset
   594
                {
hgs
parents: 25
diff changeset
   595
                    isVideoSet = true;
hgs
parents: 25
diff changeset
   596
                    msgProperty |= EPreviewVideo;
hgs
parents: 25
diff changeset
   597
                    if (objectList[index]->isProtected())
hgs
parents: 25
diff changeset
   598
                    {
hgs
parents: 25
diff changeset
   599
                        msgProperty |= EPreviewProtectedVideo;
hgs
parents: 25
diff changeset
   600
                    }
hgs
parents: 25
diff changeset
   601
                    if (objectList[index]->isCorrupted())
hgs
parents: 25
diff changeset
   602
                    {
hgs
parents: 25
diff changeset
   603
                        msgProperty |= EPreviewCorruptedVideo;
hgs
parents: 25
diff changeset
   604
                    }
hgs
parents: 25
diff changeset
   605
                    videoPath = objectList[index]->path();
hgs
parents: 25
diff changeset
   606
                }
hgs
parents: 25
diff changeset
   607
            }
hgs
parents: 25
diff changeset
   608
            foreach(UniMessageInfo* slide,objectList)
hgs
parents: 25
diff changeset
   609
                {
hgs
parents: 25
diff changeset
   610
                    delete slide;
hgs
parents: 25
diff changeset
   611
                }
hgs
parents: 25
diff changeset
   612
        }
hgs
parents: 25
diff changeset
   613
        QPixmap pixmap;
hgs
parents: 25
diff changeset
   614
        //populate item  with the attachment list
hgs
parents: 25
diff changeset
   615
        //TODO: This code is not required bcoz video icon is show and not preview  
hgs
parents: 25
diff changeset
   616
        if (isVideoSet)
hgs
parents: 25
diff changeset
   617
        {
hgs
parents: 25
diff changeset
   618
            item.setData(videoPath, Attachments);
hgs
parents: 25
diff changeset
   619
            // Store thumbnail only for non protected, non corrupted content.
hgs
parents: 25
diff changeset
   620
            if (!(EPreviewProtectedVideo & msgProperty) &&
hgs
parents: 25
diff changeset
   621
                !(EPreviewCorruptedVideo & msgProperty))
hgs
parents: 25
diff changeset
   622
            {
hgs
parents: 25
diff changeset
   623
                setPreviewIcon(pixmap, videoPath, msgId, false);
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   624
            }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   625
        }
37
hgs
parents: 25
diff changeset
   626
        else if (isImageSet)
hgs
parents: 25
diff changeset
   627
        {
hgs
parents: 25
diff changeset
   628
            item.setData(imagePath, Attachments);
hgs
parents: 25
diff changeset
   629
            // Store thumbnail only for non protected, non corrupted content.
hgs
parents: 25
diff changeset
   630
            if (!(EPreviewProtectedImage & msgProperty) &&
hgs
parents: 25
diff changeset
   631
                !(EPreviewCorruptedImage & msgProperty))
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   632
            {
37
hgs
parents: 25
diff changeset
   633
                setPreviewIcon(pixmap, imagePath, msgId, false);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   634
            }
37
hgs
parents: 25
diff changeset
   635
        }
hgs
parents: 25
diff changeset
   636
        //populate msgProperty
hgs
parents: 25
diff changeset
   637
        item.setData(msgProperty, MessageProperty);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   638
    }
37
hgs
parents: 25
diff changeset
   639
hgs
parents: 25
diff changeset
   640
    // fill other attributes
hgs
parents: 25
diff changeset
   641
    if (entry.IsAttributeSet(ECsAttributeHighPriority))
hgs
parents: 25
diff changeset
   642
    {
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   643
        item.setData(ConvergedMessage::High, MessagePriority);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   644
    }
37
hgs
parents: 25
diff changeset
   645
    else if (entry.IsAttributeSet(ECsAttributeLowPriority))
hgs
parents: 25
diff changeset
   646
    {
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   647
        item.setData(ConvergedMessage::Low, MessagePriority);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   648
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   649
}
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   650
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   651
//---------------------------------------------------------------
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   652
// ConversationsModel::handleMMSNotification
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   653
// @see header
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   654
//---------------------------------------------------------------
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   655
void ConversationsModel::handleMMSNotification(QStandardItem& item,
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   656
    const CCsConversationEntry& entry)
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   657
{
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   658
    // set context to current entry
37
hgs
parents: 25
diff changeset
   659
    TRAPD(err, mMsgStoreHandler->setNotificationMessageIdL(entry.EntryId()));
hgs
parents: 25
diff changeset
   660
    if(err != KErrNone)
hgs
parents: 25
diff changeset
   661
    {
hgs
parents: 25
diff changeset
   662
        return;
hgs
parents: 25
diff changeset
   663
    }
hgs
parents: 25
diff changeset
   664
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   665
    // fetch relevent info to show in CV
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   666
    // notification state e.g. waiting, retrieving etc
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   667
    QString statusStr;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   668
    int status;
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   669
    mMsgStoreHandler->NotificationStatus(status, statusStr);
37
hgs
parents: 25
diff changeset
   670
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   671
    // create data for bodytext role
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   672
    QString dataText;
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   673
    dataText.append(mMsgStoreHandler->NotificationMsgSize());
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   674
    dataText.append(QChar::LineSeparator);
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   675
    dataText.append(mMsgStoreHandler->NotificationClass());
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   676
    dataText.append(QChar::LineSeparator);
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   677
    dataText.append(mMsgStoreHandler->NotificationExpiryDate());
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   678
    if(!statusStr.isEmpty())
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   679
    {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   680
        dataText.append(QChar::LineSeparator);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   681
        dataText.append(statusStr);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   682
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   683
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   684
    // set fetched data to roles
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   685
    item.setData(status, NotificationStatus);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   686
    item.setData(dataText, BodyText);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   687
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   688
    if (entry.IsAttributeSet(ECsAttributeHighPriority)) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   689
        item.setData(ConvergedMessage::High, MessagePriority);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   690
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   691
    else if (entry.IsAttributeSet(ECsAttributeLowPriority)) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   692
        item.setData(ConvergedMessage::Low, MessagePriority);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   693
    }
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   694
}
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   695
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   696
//---------------------------------------------------------------
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   697
// ConversationsModel::handleBlueToothMessages
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   698
// @see header
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   699
//---------------------------------------------------------------
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   700
void ConversationsModel::handleBlueToothMessages(QStandardItem& item,
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   701
    const CCsConversationEntry& entry)
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   702
{
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   703
     int msgSubType = ConversationsEngineUtility::messageSubType(entry.GetType());
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   704
      if (msgSubType == ConvergedMessage::VCard) 
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   705
			{
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   706
           iBioMsgPlugin->setMessageId(entry.EntryId());          
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   707
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   708
           if (iBioMsgPlugin->attachmentCount() > 0) 
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   709
		   			{
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   710
               UniMessageInfoList attList = iBioMsgPlugin->attachmentList();
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   711
               QString attachmentPath = attList[0]->path();
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   712
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   713
               //get display-name and set as bodytext
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   714
               QString displayName = MsgContactHandler::getVCardDisplayName(attachmentPath);
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   715
               item.setData(displayName, BodyText);
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   716
			   	 // clear attachement list : its allocated at data model
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   717
            	while (!attList.isEmpty()) 
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   718
							{
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   719
                delete attList.takeFirst();
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   720
            	}
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   721
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   722
           }
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   723
       }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   724
41
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   725
       else 
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   726
	   	 {
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   727
           QString description = XQConversions::s60DescToQString(*(entry.Description()));
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   728
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   729
           if (msgSubType == ConvergedMessage::VCal) // "vCalendar"
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   730
           {
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   731
               //message sub-type
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   732
               item.setData(ConvergedMessage::VCal, MessageSubType);
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   733
           }
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   734
           else 
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   735
		       {
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   736
               //message sub-type
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   737
               item.setData(ConvergedMessage::None, MessageSubType);
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   738
           }
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   739
           //for BT messages we show filenames for all other (except vcard) messages
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   740
           //get filename and set as body
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   741
           QFileInfo fileinfo(description);
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   742
           QString filename = fileinfo.fileName();
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   743
           item.setData(filename, BodyText);
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   744
       }
25fe1fe642e3 201027_02
hgs
parents: 38
diff changeset
   745
    
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   746
}
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   747
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   748
//---------------------------------------------------------------
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   749
// ConversationsModel::handleBioMessages
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   750
// @see header
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   751
//---------------------------------------------------------------
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   752
void ConversationsModel::handleBioMessages(QStandardItem& item, const CCsConversationEntry& entry)
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   753
{
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   754
    iBioMsgPlugin->setMessageId(entry.EntryId());
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   755
    int msgSubType = ConversationsEngineUtility::messageSubType(entry.GetType());
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   756
    if (ConvergedMessage::VCard == msgSubType) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   757
        if (iBioMsgPlugin->attachmentCount() > 0) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   758
            UniMessageInfoList attList = iBioMsgPlugin->attachmentList();
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   759
            QString attachmentPath = attList[0]->path();
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   760
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   761
            //get display-name and set as bodytext
37
hgs
parents: 25
diff changeset
   762
            QString displayName =
hgs
parents: 25
diff changeset
   763
                    MsgContactHandler::getVCardDisplayName(
hgs
parents: 25
diff changeset
   764
                            attachmentPath);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   765
            item.setData(displayName, BodyText);
37
hgs
parents: 25
diff changeset
   766
            item.setData(attachmentPath, Attachments);
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   767
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   768
            // clear attachement list : its allocated at data model
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   769
            while (!attList.isEmpty()) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   770
                delete attList.takeFirst();
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   771
            }
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   772
        }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   773
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   774
    else if (ConvergedMessage::VCal == msgSubType) {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   775
        //not supported
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   776
    }
37
hgs
parents: 25
diff changeset
   777
    else if (ConvergedMessage::RingingTone == msgSubType) {
hgs
parents: 25
diff changeset
   778
        if (iBioMsgPlugin->attachmentCount() > 0) {
hgs
parents: 25
diff changeset
   779
            UniMessageInfoList attList = iBioMsgPlugin->attachmentList();
hgs
parents: 25
diff changeset
   780
            QString attachmentPath = attList[0]->path();
hgs
parents: 25
diff changeset
   781
hgs
parents: 25
diff changeset
   782
            //get tone title, and set as bodytext
hgs
parents: 25
diff changeset
   783
            RingBc ringBc;
hgs
parents: 25
diff changeset
   784
            item.setData(ringBc.toneTitle(attachmentPath), BodyText);
hgs
parents: 25
diff changeset
   785
            while (!attList.isEmpty()) {
hgs
parents: 25
diff changeset
   786
                delete attList.takeFirst();
hgs
parents: 25
diff changeset
   787
            }
hgs
parents: 25
diff changeset
   788
        }
hgs
parents: 25
diff changeset
   789
hgs
parents: 25
diff changeset
   790
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   791
    else {
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   792
        // description
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   793
        HBufC* description = entry.Description();
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   794
        QString subject("");
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   795
        if (description && description->Length()) {
37
hgs
parents: 25
diff changeset
   796
            subject = (XQConversions::s60DescToQString(*description));
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   797
            item.setData(subject, BodyText);
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   798
        }
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   799
    }
25
84d9eb65b26f Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 23
diff changeset
   800
}
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   801
37
hgs
parents: 25
diff changeset
   802
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   803
// ConversationsModel::getDBHandle()
hgs
parents: 25
diff changeset
   804
// @see header
hgs
parents: 25
diff changeset
   805
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   806
RSqlDatabase& ConversationsModel::getDBHandle(TBool& isOpen)
hgs
parents: 25
diff changeset
   807
{
hgs
parents: 25
diff changeset
   808
    isOpen = iSqlDbOpen;
hgs
parents: 25
diff changeset
   809
    return iSqlDb;
hgs
parents: 25
diff changeset
   810
}
hgs
parents: 25
diff changeset
   811
hgs
parents: 25
diff changeset
   812
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   813
// ConversationsModel::setPreviewIcon()
hgs
parents: 25
diff changeset
   814
// @see header
hgs
parents: 25
diff changeset
   815
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   816
void ConversationsModel::setPreviewIcon(QPixmap& pixmap, QString& filePath,
hgs
parents: 25
diff changeset
   817
    int msgId, bool inDb)
hgs
parents: 25
diff changeset
   818
{
hgs
parents: 25
diff changeset
   819
hgs
parents: 25
diff changeset
   820
    //Since the population happens in reverse this check is needed so that
hgs
parents: 25
diff changeset
   821
    //most recent items have their icons present in cache
hgs
parents: 25
diff changeset
   822
    if (previewIconCache.totalCost() >= previewIconCache.maxCost())
hgs
parents: 25
diff changeset
   823
        return;
hgs
parents: 25
diff changeset
   824
hgs
parents: 25
diff changeset
   825
    // if not found in db, set from file path
hgs
parents: 25
diff changeset
   826
    if (!inDb)
hgs
parents: 25
diff changeset
   827
    {
hgs
parents: 25
diff changeset
   828
        QPixmap pixmap(filePath);
hgs
parents: 25
diff changeset
   829
        QPixmap scaledPixmap = pixmap.scaled(KWidth, KHeight, Qt::IgnoreAspectRatio);
hgs
parents: 25
diff changeset
   830
        HbIcon *previewIcon = new HbIcon(scaledPixmap);
hgs
parents: 25
diff changeset
   831
hgs
parents: 25
diff changeset
   832
        previewIconCache.insert(msgId, previewIcon);
hgs
parents: 25
diff changeset
   833
hgs
parents: 25
diff changeset
   834
    }
hgs
parents: 25
diff changeset
   835
    else
hgs
parents: 25
diff changeset
   836
    {
hgs
parents: 25
diff changeset
   837
        HbIcon *previewIcon = new HbIcon(pixmap);
hgs
parents: 25
diff changeset
   838
        previewIconCache.insert(msgId, previewIcon);
hgs
parents: 25
diff changeset
   839
    }
hgs
parents: 25
diff changeset
   840
}
hgs
parents: 25
diff changeset
   841
hgs
parents: 25
diff changeset
   842
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   843
// ConversationsModel::getPreviewIconItem()
hgs
parents: 25
diff changeset
   844
// @see header
hgs
parents: 25
diff changeset
   845
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   846
HbIcon* ConversationsModel::getPreviewIconItem(int msgId,
hgs
parents: 25
diff changeset
   847
    QString& filepath) const
hgs
parents: 25
diff changeset
   848
{
hgs
parents: 25
diff changeset
   849
    QCRITICAL_WRITE("ConversationsModel::getPreviewIconItem start.")
hgs
parents: 25
diff changeset
   850
hgs
parents: 25
diff changeset
   851
    //Initialize icon from the Cache will be NULL if Item not present
hgs
parents: 25
diff changeset
   852
    HbIcon* previewIcon = previewIconCache[msgId];
hgs
parents: 25
diff changeset
   853
    if (!previewIcon)
hgs
parents: 25
diff changeset
   854
    {
hgs
parents: 25
diff changeset
   855
        //This is done in this way as non-const function call cant be done here
hgs
parents: 25
diff changeset
   856
        emit retrievePreviewIcon(msgId, filepath);
hgs
parents: 25
diff changeset
   857
hgs
parents: 25
diff changeset
   858
        previewIcon = previewIconCache[msgId];
hgs
parents: 25
diff changeset
   859
    }
hgs
parents: 25
diff changeset
   860
hgs
parents: 25
diff changeset
   861
    QCRITICAL_WRITE("ConversationsModel::getPreviewIconItem start.")
hgs
parents: 25
diff changeset
   862
hgs
parents: 25
diff changeset
   863
    return previewIcon;
hgs
parents: 25
diff changeset
   864
}
hgs
parents: 25
diff changeset
   865
hgs
parents: 25
diff changeset
   866
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   867
// ConversationsModel::updatePreviewIcon()
hgs
parents: 25
diff changeset
   868
// @see header
hgs
parents: 25
diff changeset
   869
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   870
void ConversationsModel::updatePreviewIcon(int msgId, QString& filePath)
hgs
parents: 25
diff changeset
   871
{
hgs
parents: 25
diff changeset
   872
    QCRITICAL_WRITE("ConversationsModel::updatePreviewIcon start.")
hgs
parents: 25
diff changeset
   873
hgs
parents: 25
diff changeset
   874
    //sql query to get preview-icon from DB
hgs
parents: 25
diff changeset
   875
    bool imagePreviewed = false;
hgs
parents: 25
diff changeset
   876
    QPixmap pixmap;
hgs
parents: 25
diff changeset
   877
hgs
parents: 25
diff changeset
   878
    if (iSqlDbOpen)
hgs
parents: 25
diff changeset
   879
    {
hgs
parents: 25
diff changeset
   880
        RSqlStatement sqlSelectPreviewIconStmt;
hgs
parents: 25
diff changeset
   881
        TInt err = sqlSelectPreviewIconStmt.Prepare(iSqlDb,
hgs
parents: 25
diff changeset
   882
            KSelectPreviewIconStmt);
hgs
parents: 25
diff changeset
   883
hgs
parents: 25
diff changeset
   884
        QCRITICAL_WRITE_FORMAT("Error from Prepare()", err)
hgs
parents: 25
diff changeset
   885
hgs
parents: 25
diff changeset
   886
        if (err == KErrNone)
hgs
parents: 25
diff changeset
   887
        {
hgs
parents: 25
diff changeset
   888
            //msg_id
hgs
parents: 25
diff changeset
   889
            TInt msgIdIndex = sqlSelectPreviewIconStmt.ParameterIndex(
hgs
parents: 25
diff changeset
   890
                _L(":message_id"));
hgs
parents: 25
diff changeset
   891
            sqlSelectPreviewIconStmt.BindInt(msgIdIndex, msgId);
hgs
parents: 25
diff changeset
   892
hgs
parents: 25
diff changeset
   893
            // get preview-icon from DB
hgs
parents: 25
diff changeset
   894
            err = sqlSelectPreviewIconStmt.Next();
hgs
parents: 25
diff changeset
   895
            QCRITICAL_WRITE_FORMAT("Error from Next()", err)
hgs
parents: 25
diff changeset
   896
hgs
parents: 25
diff changeset
   897
            if (err == KSqlAtRow)
hgs
parents: 25
diff changeset
   898
            {
hgs
parents: 25
diff changeset
   899
                TInt previewIconIndex = sqlSelectPreviewIconStmt.ColumnIndex(
hgs
parents: 25
diff changeset
   900
                    _L("preview_icon"));
hgs
parents: 25
diff changeset
   901
hgs
parents: 25
diff changeset
   902
                RSqlColumnReadStream stream;
hgs
parents: 25
diff changeset
   903
hgs
parents: 25
diff changeset
   904
                //Get data from binary column BLOB
hgs
parents: 25
diff changeset
   905
                err = stream.ColumnBinary(sqlSelectPreviewIconStmt,
hgs
parents: 25
diff changeset
   906
                    previewIconIndex);
hgs
parents: 25
diff changeset
   907
hgs
parents: 25
diff changeset
   908
                QCRITICAL_WRITE_FORMAT("Error from ColumnBinary()", err)
hgs
parents: 25
diff changeset
   909
hgs
parents: 25
diff changeset
   910
                if (err == KErrNone)
hgs
parents: 25
diff changeset
   911
                {
hgs
parents: 25
diff changeset
   912
                    CFbsBitmap *bitmap = new CFbsBitmap;
hgs
parents: 25
diff changeset
   913
                    TRAPD(err,bitmap->InternalizeL(stream));
hgs
parents: 25
diff changeset
   914
                    QCRITICAL_WRITE_FORMAT("Error from bitmap InternalizeL()", err)
hgs
parents: 25
diff changeset
   915
hgs
parents: 25
diff changeset
   916
                    //convert bitmap to pixmap
hgs
parents: 25
diff changeset
   917
                    if (err == KErrNone)
hgs
parents: 25
diff changeset
   918
                    {
hgs
parents: 25
diff changeset
   919
                        TSize size = bitmap->SizeInPixels();
hgs
parents: 25
diff changeset
   920
                        int bytesPerLine = bitmap->ScanLineLength(size.iWidth,
hgs
parents: 25
diff changeset
   921
                            bitmap->DisplayMode());
hgs
parents: 25
diff changeset
   922
                        const uchar* dataPtr =
hgs
parents: 25
diff changeset
   923
                                (const uchar*) bitmap->DataAddress();
hgs
parents: 25
diff changeset
   924
hgs
parents: 25
diff changeset
   925
                        pixmap = QPixmap::fromImage(QImage(dataPtr,
hgs
parents: 25
diff changeset
   926
                            size.iWidth, size.iHeight, bytesPerLine,
hgs
parents: 25
diff changeset
   927
                            QImage::Format_RGB16));
hgs
parents: 25
diff changeset
   928
hgs
parents: 25
diff changeset
   929
                        imagePreviewed = true;
hgs
parents: 25
diff changeset
   930
hgs
parents: 25
diff changeset
   931
                        QCRITICAL_WRITE("Bitmap Conversion completed")
hgs
parents: 25
diff changeset
   932
                    }
hgs
parents: 25
diff changeset
   933
                    //remove bitmap
hgs
parents: 25
diff changeset
   934
                    delete bitmap;
hgs
parents: 25
diff changeset
   935
                }
hgs
parents: 25
diff changeset
   936
                //close stream
hgs
parents: 25
diff changeset
   937
                stream.Close();
hgs
parents: 25
diff changeset
   938
            }
hgs
parents: 25
diff changeset
   939
        }
hgs
parents: 25
diff changeset
   940
        sqlSelectPreviewIconStmt.Close();
hgs
parents: 25
diff changeset
   941
    }
hgs
parents: 25
diff changeset
   942
hgs
parents: 25
diff changeset
   943
    // if not found in db, set from file path
hgs
parents: 25
diff changeset
   944
    if (!imagePreviewed)
hgs
parents: 25
diff changeset
   945
    {
hgs
parents: 25
diff changeset
   946
        QPixmap orgPixmap(filePath);
hgs
parents: 25
diff changeset
   947
        pixmap = orgPixmap.scaled(63.65, 63.65, Qt::IgnoreAspectRatio);
hgs
parents: 25
diff changeset
   948
    }
hgs
parents: 25
diff changeset
   949
    HbIcon * previewIcon = new HbIcon(pixmap);
hgs
parents: 25
diff changeset
   950
hgs
parents: 25
diff changeset
   951
    previewIconCache.insert(msgId, previewIcon);
hgs
parents: 25
diff changeset
   952
hgs
parents: 25
diff changeset
   953
    QCRITICAL_WRITE("ConversationsModel::updatePreviewIcon end.")
hgs
parents: 25
diff changeset
   954
hgs
parents: 25
diff changeset
   955
}
hgs
parents: 25
diff changeset
   956
hgs
parents: 25
diff changeset
   957
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   958
// ConversationsModel::clearModel()
hgs
parents: 25
diff changeset
   959
// @see header
hgs
parents: 25
diff changeset
   960
//---------------------------------------------------------------
hgs
parents: 25
diff changeset
   961
void ConversationsModel::clearModel()
hgs
parents: 25
diff changeset
   962
{
hgs
parents: 25
diff changeset
   963
    clear();
hgs
parents: 25
diff changeset
   964
    previewIconCache.clear();
hgs
parents: 25
diff changeset
   965
}
hgs
parents: 25
diff changeset
   966
hgs
parents: 25
diff changeset
   967
void ConversationsModel:: emitConversationViewEmpty()
hgs
parents: 25
diff changeset
   968
{
hgs
parents: 25
diff changeset
   969
    emit conversationViewEmpty();
hgs
parents: 25
diff changeset
   970
}
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   971
//EOF