messagingapp/msgui/msgapp/src/msgactivityhandler.cpp
author hgs
Fri, 06 Aug 2010 23:19:50 +0530
changeset 51 3507212d340e
parent 37 518b245aa84c
child 62 fdbe8253b596
permissions -rw-r--r--
201031_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description:
hgs
parents:
diff changeset
    15
 * Handles saving and opening activites.
hgs
parents:
diff changeset
    16
 *
hgs
parents:
diff changeset
    17
 */
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
#include "msgactivityhandler.h"
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include "msgviewmanager.h"
hgs
parents:
diff changeset
    22
#include "msgbaseview.h"
hgs
parents:
diff changeset
    23
#include "msgmainwindow.h"
hgs
parents:
diff changeset
    24
#include <hbapplication.h>
hgs
parents:
diff changeset
    25
#include <hbactivitymanager.h>
hgs
parents:
diff changeset
    26
#include <QVariantHash>
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
const int INVALID_MSGID = -1;
hgs
parents:
diff changeset
    29
// Activity Names 
hgs
parents:
diff changeset
    30
const QString ListViewActivityName("MsgConversationsList");
hgs
parents:
diff changeset
    31
const QString EditorActivityName("MsgCreate");
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    34
// MsgActivityHandler::MsgActivityHandler
hgs
parents:
diff changeset
    35
// Constructor
hgs
parents:
diff changeset
    36
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    37
MsgActivityHandler::MsgActivityHandler(QObject* parent):
hgs
parents:
diff changeset
    38
    QObject(parent)
hgs
parents:
diff changeset
    39
{
hgs
parents:
diff changeset
    40
  
hgs
parents:
diff changeset
    41
}
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    44
// MsgActivityHandler::MsgActivityHandler
hgs
parents:
diff changeset
    45
// Destructor
hgs
parents:
diff changeset
    46
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    47
MsgActivityHandler::~MsgActivityHandler()
hgs
parents:
diff changeset
    48
{
hgs
parents:
diff changeset
    49
   
hgs
parents:
diff changeset
    50
}
hgs
parents:
diff changeset
    51
hgs
parents:
diff changeset
    52
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    53
// MsgActivityHandler::saveActivity
hgs
parents:
diff changeset
    54
// @see header
hgs
parents:
diff changeset
    55
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    56
void MsgActivityHandler::saveActivity()
hgs
parents:
diff changeset
    57
{
hgs
parents:
diff changeset
    58
    HbActivityManager* activityManager = 
hgs
parents:
diff changeset
    59
                        qobject_cast<HbApplication*>(qApp)->activityManager();
hgs
parents:
diff changeset
    60
                        
hgs
parents:
diff changeset
    61
     int currentView = mMainWindow->viewManager()->currentView();
hgs
parents:
diff changeset
    62
     int msgId = INVALID_MSGID;
hgs
parents:
diff changeset
    63
     if((currentView == MsgBaseView::CV) || (currentView== MsgBaseView::UNIEDITOR))
hgs
parents:
diff changeset
    64
         {
hgs
parents:
diff changeset
    65
         msgId = mMainWindow->viewManager()->saveContentToDraft();
hgs
parents:
diff changeset
    66
         }
hgs
parents:
diff changeset
    67
     
hgs
parents:
diff changeset
    68
     // get a screenshot for saving to the activity manager
hgs
parents:
diff changeset
    69
     QVariantHash metadata;
hgs
parents:
diff changeset
    70
     metadata.insert("screenshot", 
hgs
parents:
diff changeset
    71
             QPixmap::grabWidget(mMainWindow, mMainWindow->rect()));
hgs
parents:
diff changeset
    72
hgs
parents:
diff changeset
    73
     // save any data necessary to save the state
hgs
parents:
diff changeset
    74
     QByteArray serializedActivity;
hgs
parents:
diff changeset
    75
     QDataStream stream(&serializedActivity, 
hgs
parents:
diff changeset
    76
             QIODevice::WriteOnly | QIODevice::Append);
hgs
parents:
diff changeset
    77
  
hgs
parents:
diff changeset
    78
    if( msgId != INVALID_MSGID)
hgs
parents:
diff changeset
    79
        {
hgs
parents:
diff changeset
    80
        stream << EditorActivityName;
hgs
parents:
diff changeset
    81
        stream << msgId;
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
        // add the activity to the activity manager
hgs
parents:
diff changeset
    84
        bool ok = activityManager->addActivity(EditorActivityName, 
hgs
parents:
diff changeset
    85
                serializedActivity, metadata);
hgs
parents:
diff changeset
    86
        }
hgs
parents:
diff changeset
    87
    else
hgs
parents:
diff changeset
    88
        {    
hgs
parents:
diff changeset
    89
        stream << ListViewActivityName;
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
        // add the activity to the activity manager
hgs
parents:
diff changeset
    92
        bool ok = activityManager->addActivity(ListViewActivityName, 
hgs
parents:
diff changeset
    93
                serializedActivity, metadata);
hgs
parents:
diff changeset
    94
        }
hgs
parents:
diff changeset
    95
}
hgs
parents:
diff changeset
    96
hgs
parents:
diff changeset
    97
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    98
// MsgActivityHandler::parseActivityData
hgs
parents:
diff changeset
    99
// @see header
hgs
parents:
diff changeset
   100
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   101
int MsgActivityHandler::parseActivityData(const QVariant &activityData)
hgs
parents:
diff changeset
   102
{
hgs
parents:
diff changeset
   103
    QByteArray serializedModel = activityData.toByteArray();
hgs
parents:
diff changeset
   104
    QDataStream stream(&serializedModel, QIODevice::ReadOnly);
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
    QString activityName;
hgs
parents:
diff changeset
   107
    int msgId = INVALID_MSGID;
hgs
parents:
diff changeset
   108
    stream >> activityName;
hgs
parents:
diff changeset
   109
    if( activityName == EditorActivityName)
hgs
parents:
diff changeset
   110
        {
hgs
parents:
diff changeset
   111
        stream >> msgId;
hgs
parents:
diff changeset
   112
        }
hgs
parents:
diff changeset
   113
    return msgId;
hgs
parents:
diff changeset
   114
}
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   117
// MsgActivityHandler::clearActivities
hgs
parents:
diff changeset
   118
// @see header
hgs
parents:
diff changeset
   119
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   120
void MsgActivityHandler::clearActivities()
hgs
parents:
diff changeset
   121
{
hgs
parents:
diff changeset
   122
    HbActivityManager* activityManager = 
hgs
parents:
diff changeset
   123
                        qobject_cast<HbApplication*>(qApp)->activityManager();
hgs
parents:
diff changeset
   124
    activityManager->removeActivity(ListViewActivityName);   
hgs
parents:
diff changeset
   125
    activityManager->removeActivity(EditorActivityName);   
hgs
parents:
diff changeset
   126
}
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   129
// MsgActivityHandler::setMainWindow
hgs
parents:
diff changeset
   130
// @see header
hgs
parents:
diff changeset
   131
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
   132
void  MsgActivityHandler::setMainWindow(MsgMainWindow* mainWindow)
hgs
parents:
diff changeset
   133
{
hgs
parents:
diff changeset
   134
    mMainWindow = mainWindow;
hgs
parents:
diff changeset
   135
}