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