messagingapp/msgui/msgapp/src/msgmainwindow.cpp
author hgs
Tue, 19 Oct 2010 11:30:16 +0530
changeset 76 60a8a215b0ec
parent 73 ecf6a73a9186
permissions -rw-r--r--
201041
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
 * Main window of the messaging application. Activates the default view.
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
 *
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
 */
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
#include "msgmainwindow.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
#include "msgviewmanager.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include "msgserviceinterface.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
#include "msgsendserviceinterface.h"
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include "conversationsengine.h"
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    25
#include "msgactivityhandler.h"
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    27
#include <hbapplication.h>
62
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
    28
#include <QKeyEvent>
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    29
#include <afactivation.h>
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    30
#include <afactivitystorage.h>
62
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
    31
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    32
const int INVALID_MSGID = -1;
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    33
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    34
//---------------------------------------------------------------
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    35
// MsgMainWindow::MsgMainWindow
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    36
// Constructor
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    37
//---------------------------------------------------------------
76
hgs
parents: 73
diff changeset
    38
MsgMainWindow::MsgMainWindow(bool serviceRequest,
hgs
parents: 73
diff changeset
    39
    MsgActivityHandler *handler,
hgs
parents: 73
diff changeset
    40
    QWidget *parent) :
hgs
parents: 73
diff changeset
    41
HbMainWindow(parent), mMsgSI(0), mMsgSendSI(0),mActivityHandler(handler)
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    42
{
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    43
    initialize(serviceRequest);    
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    44
}
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
//---------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
// MsgMainWindow::MsgMainWindow
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
// Constructor
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
//---------------------------------------------------------------
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    50
void MsgMainWindow::initialize(bool serviceRequest)
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
{
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    52
    int activityMsgId = INVALID_MSGID;
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    53
    
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    54
        
76
hgs
parents: 73
diff changeset
    55
    AfActivation *activation = mActivityHandler->activation();
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    56
    
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    57
    Af::ActivationReason reason = activation->reason();      
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    58
    
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    59
    if (reason == Af::ActivationReasonActivity) 
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    60
        {
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    61
        // set service request to false , since its a activity launch
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    62
        serviceRequest = false;
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    63
        
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    64
        QString actName = activation->name();
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    65
                
76
hgs
parents: 73
diff changeset
    66
        QVariant data = mActivityHandler->activitiyStorage()->
hgs
parents: 73
diff changeset
    67
                                                         activityData(actName);        
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    68
        
76
hgs
parents: 73
diff changeset
    69
        activityMsgId = mActivityHandler->parseActivityData(data);
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    70
        }
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    71
    
37
hgs
parents: 23
diff changeset
    72
    mViewManager = new MsgViewManager(serviceRequest,this,this,activityMsgId);
76
hgs
parents: 73
diff changeset
    73
    mViewManager->setActivityHandler(mActivityHandler);
hgs
parents: 73
diff changeset
    74
    
37
hgs
parents: 23
diff changeset
    75
    mMsgSI = new MsgServiceInterface(NULL,mViewManager);
hgs
parents: 23
diff changeset
    76
    mMsgSendSI = new MsgSendServiceInterface(NULL,mViewManager);
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    77
            
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
    //Model creation
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
    ConversationsEngine::instance();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
    
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    81
    // clear the old activities
76
hgs
parents: 73
diff changeset
    82
    mActivityHandler->clearActivities();
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    83
    
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    84
    // Set the main window pointer to activity handler.
76
hgs
parents: 73
diff changeset
    85
    mActivityHandler->setMainWindow(this); 
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    86
    
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    87
    // connect to aboutToQuit signal to save drafts content
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
    88
    QObject::connect(qApp, SIGNAL(aboutToQuit()), 
76
hgs
parents: 73
diff changeset
    89
        mActivityHandler, SLOT(saveActivity()));
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    90
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
//---------------------------------------------------------------
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
// MsgMainWindow::~MsgMainWindow
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
// Constructor
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
MsgMainWindow::~MsgMainWindow()
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    97
{   
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    98
    if (mMsgSI)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    99
    {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   100
        delete mMsgSI;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
        mMsgSI = NULL;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
    if (mMsgSendSI)
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   104
    {
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   105
        delete mMsgSendSI;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   106
        mMsgSendSI = NULL;
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   107
    }
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   108
    
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
    delete ConversationsEngine::instance();
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   110
}
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
37
hgs
parents: 23
diff changeset
   112
//---------------------------------------------------------------
hgs
parents: 23
diff changeset
   113
// MsgMainWindow::viewManager
hgs
parents: 23
diff changeset
   114
// Constructor
hgs
parents: 23
diff changeset
   115
//---------------------------------------------------------------
hgs
parents: 23
diff changeset
   116
MsgViewManager* MsgMainWindow::viewManager()
hgs
parents: 23
diff changeset
   117
{   
hgs
parents: 23
diff changeset
   118
     return mViewManager; 
hgs
parents: 23
diff changeset
   119
}
62
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   120
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   121
//---------------------------------------------------------------
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   122
// MsgMainWindow::keyPressEvent
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   123
// @see header
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   124
//---------------------------------------------------------------
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   125
void MsgMainWindow::keyPressEvent(QKeyEvent *event)
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   126
{
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   127
    bool eventHandled = false;
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   128
    if (Qt::Key_Yes == event->key()) {
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   129
        eventHandled = mViewManager->handleKeyEvent(event->key());
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   130
    }
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   131
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   132
    if (eventHandled) {
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   133
        event->accept();
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   134
    }
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   135
    else {
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   136
        HbMainWindow::keyPressEvent(event);
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   137
    }
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   138
fdbe8253b596 201035_03
hgs
parents: 37
diff changeset
   139
}
73
ecf6a73a9186 201039_03
hgs
parents: 62
diff changeset
   140
76
hgs
parents: 73
diff changeset
   141
//---------------------------------------------------------------
hgs
parents: 73
diff changeset
   142
// MsgMainWindow::eventFilter
hgs
parents: 73
diff changeset
   143
// @see header
hgs
parents: 73
diff changeset
   144
//---------------------------------------------------------------
hgs
parents: 73
diff changeset
   145
bool MsgMainWindow::eventFilter(QObject *obj, QEvent *event)
hgs
parents: 73
diff changeset
   146
{
hgs
parents: 73
diff changeset
   147
    if (event->type() == QEvent::ApplicationActivate) {
hgs
parents: 73
diff changeset
   148
        mViewManager->handleApplicationActive();
hgs
parents: 73
diff changeset
   149
    }
hgs
parents: 73
diff changeset
   150
    return QObject::eventFilter(obj, event);
hgs
parents: 73
diff changeset
   151
}
hgs
parents: 73
diff changeset
   152
23
238255e8b033 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
// End of file