|
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 * |
|
16 */ |
|
17 |
|
18 #include "cntactivities.h" |
|
19 #include "cntglobal.h" |
|
20 #include <cntdebug.h> |
|
21 #include <afactivation.h> |
|
22 #include <afactivitystorage.h> |
|
23 #include <QPixmap> |
|
24 |
|
25 |
|
26 /*! |
|
27 Constructor, initialize member variables. |
|
28 */ |
|
29 CntActivities::CntActivities() |
|
30 { |
|
31 mActivation = new AfActivation(); |
|
32 mActivityStorage = new AfActivityStorage(); |
|
33 } |
|
34 |
|
35 /*! |
|
36 Destructor |
|
37 */ |
|
38 CntActivities::~CntActivities() |
|
39 { |
|
40 delete mActivation; |
|
41 delete mActivityStorage; |
|
42 } |
|
43 |
|
44 bool CntActivities::loadActivity(QByteArray &serializedModel) |
|
45 { |
|
46 bool isActityStartup = false; |
|
47 if (mActivation->reason() == Af::ActivationReasonActivity) |
|
48 { |
|
49 QVariant data = mActivityStorage->activityData(mActivation->name()); |
|
50 // restore state from activity data |
|
51 serializedModel = data.toByteArray(); |
|
52 isActityStartup = true; |
|
53 } |
|
54 |
|
55 // clean up all activities from the activity manager. |
|
56 removeActivities(); |
|
57 |
|
58 return isActityStartup; |
|
59 } |
|
60 |
|
61 void CntActivities::saveActivity(const QString &name, const QByteArray &serializedActivity, const QPixmap &screenshot) |
|
62 { |
|
63 // clean up all activities from the activity manager. |
|
64 removeActivities(); |
|
65 |
|
66 // do not save empty activity |
|
67 if (name.isEmpty()) |
|
68 return; |
|
69 |
|
70 // screen shot |
|
71 QVariantHash metadata; |
|
72 metadata.insert("screenshot", screenshot); |
|
73 |
|
74 // add the activity to the activity manager |
|
75 bool ok = mActivityStorage->saveActivity(name, serializedActivity, metadata); |
|
76 if ( !ok ) |
|
77 { |
|
78 qFatal("Add failed"); |
|
79 } |
|
80 } |
|
81 |
|
82 void CntActivities::removeActivities() |
|
83 { |
|
84 QStringList activityList = mActivityStorage->allActivities(); |
|
85 foreach (QString activity, activityList) |
|
86 { |
|
87 mActivityStorage->removeActivity(activity); |
|
88 } |
|
89 } |
|
90 |