--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/activityfw/testapplications/newtestappset/acttestfigure/viewmanager.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,225 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+#include "viewmanager.h"
+#include <qservicemanager.h>
+#include <HbInstance>
+#include <QStringList>
+#include <QCoreApplication>
+#include <hbinstance.h>
+#include <hbapplication.h>
+#include <hbactivitymanager.h>
+#include <hbmainwindow.h>
+#include "squrewidget.h"
+#include "trianglewidget.h"
+#include "circlewidget.h"
+#include "figurewidget.h"
+#include <QEventLoop>
+
+#include <afactivitystorage.h>
+#include <afactivation.h>
+#include "afstorageglobals.h"
+
+QTM_USE_NAMESPACE
+
+
+viewmanager::viewmanager(HbApplication *hbapp):
+ HbMainWindow(), mHbApp(hbapp)
+{
+
+ mActivityStorage = new AfActivityStorage;
+ mActivation = new AfActivation;
+
+ qRegisterMetaType<Af::ActivationReason>("Af::ActivationReason");
+ connect(mActivation, SIGNAL(activated(Af::ActivationReason, QString, QVariantHash)), this, SLOT(loadActivityData(Af::ActivationReason, QString, QVariantHash)));
+
+
+
+ mSw = new squrewidget();
+ mTw = new trianglewidget();
+ mCw = new circlewidget();
+ mSView = addView(mSw);
+ mSView->setTitle("Squre");
+ mTView = addView(mTw);
+ mTView->setTitle("Triangle");
+ mCView = addView(mCw);
+ mCView->setTitle("Circle");
+ totriangle();
+ connect(mSw, SIGNAL(totriangle()), this, SLOT(totriangle()));
+ connect(mSw, SIGNAL(tocircle()), this, SLOT(tocircle()));
+
+ connect(mTw, SIGNAL(tocircle()), this, SLOT(tocircle()));
+ connect(mTw, SIGNAL(tosqure()), this, SLOT(tosqure()));
+
+ connect(mCw, SIGNAL(tosqure()), this, SLOT(tosqure()));
+ connect(mCw, SIGNAL(totriangle()), this, SLOT(totriangle()));
+
+ connect(mSw, SIGNAL(save()), this, SLOT(save()));
+ connect(mTw, SIGNAL(save()), this, SLOT(save()));
+ connect(mCw, SIGNAL(save()), this, SLOT(save()));
+ connect(mSw, SIGNAL(del()), this, SLOT(del()));
+ connect(mTw, SIGNAL(del()), this, SLOT(del()));
+ connect(mCw, SIGNAL(del()), this, SLOT(del()));
+
+ //startup case
+ Af::ActivationReason reason = mActivation->reason();
+ QString actName;
+ QVariantHash parameters;
+ if (reason == Af::ActivationReasonActivity) {
+ actName = mActivation->name();
+ parameters = mActivation->parameters();
+ QVariant data = mActivityStorage->activityData(actName);
+ loadActivityData(data, true);
+ }
+ //startup case end
+
+}
+
+viewmanager::~viewmanager()
+{
+
+ delete mActivityStorage;
+ delete mActivation;
+}
+
+void viewmanager::totriangle()
+{
+ setCurrentView(mTView);
+ mStatename = "triangle";
+}
+
+void viewmanager::tosqure()
+{
+ setCurrentView(mSView);
+ mStatename = "squre";
+}
+
+void viewmanager::tocircle()
+{
+ setCurrentView(mCView);
+ mStatename = "circle";
+}
+
+
+void viewmanager::save()
+{
+ QString color;
+ figurewidget* widget = currentWidget();
+ color = widget->color();
+
+ QStringList list;
+ list.append(mStatename);
+ list.append(color);
+ mSaveVariant.clear();
+ mSaveVariant = list;
+ QString visible = widget->visibility();
+ QString persistent = widget->persistent();
+ QString name = widget->name();
+ bool delBefore = widget->delBeforeSave();
+
+ HbMainWindow *mainWindow = hbInstance->allMainWindows().first();
+ QPixmap screenshot = QPixmap::grabWidget(mainWindow, mainWindow->rect());
+ QVariantHash metadata;
+ metadata.insert("screenshot", screenshot);
+ if ( visible == "true" )
+ {
+ metadata.insert(ActivityVisibility, true);
+ }
+ else if ( visible == "false" )
+ {
+ metadata.insert(ActivityVisibility, false);
+ }
+
+ if ( persistent == "true" )
+ {
+ metadata.insert(ActivityPersistence, true);
+ }
+ else if ( persistent == "false" )
+ {
+ metadata.insert(ActivityPersistence, false);
+ }
+
+ if ( name != "none" )
+ {
+ metadata.insert(ActivityApplicationName, name);
+ }
+
+ if (delBefore) {
+ bool ok = mActivityStorage->removeActivity(mStatename);
+ }
+ bool ok = mActivityStorage->saveActivity(mStatename, mSaveVariant, metadata);
+ if (!ok) {
+ widget->setFailedFlag();
+ }
+ else {
+ widget->clearFailedFlag();
+ }
+}
+
+
+void viewmanager::del()
+{
+ bool ok = mActivityStorage->removeActivity(mStatename);
+ figurewidget* widget = currentWidget();
+ if (!ok) {
+ widget->setFailedFlag();
+ }
+ else {
+ widget->clearFailedFlag();
+ }
+}
+
+void viewmanager::loadActivityData(Af::ActivationReason reason, const QString &name, QVariantHash parameter)
+{
+ QVariant data = mActivityStorage->activityData( name );
+ loadActivityData( data, false );
+}
+
+void viewmanager::loadActivityData(const QVariant &data, bool startup)
+{
+ HbView *oldView = currentView();
+ QStringList list = data.toStringList();
+ QString statename = list.at(0);
+ QString color = list.at(1);
+ if (statename == "squre") {
+ mSw->setcolor(color);
+ tosqure();
+ mSw->update();
+ } else if (statename == "triangle") {
+ mTw->setcolor(color);
+ totriangle();
+ mTw->update();
+ } else if (statename == "circle") {
+ mCw->setcolor(color);
+ tocircle();
+ mCw->update();
+ } else {
+ Q_ASSERT(false);
+ }
+
+ if (currentView() != oldView && !startup) {
+ QEventLoop loop;
+ loop.connect(this, SIGNAL(viewReady()), SLOT(quit()));
+ loop.exec();
+ }
+}
+
+figurewidget* viewmanager::currentWidget()
+ {
+ HbView* view = currentView();
+ QGraphicsWidget* gwidget = view->widget();
+ figurewidget* lwidget = qobject_cast<figurewidget*>(gwidget);
+ }
\ No newline at end of file