--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/activityfw/testapplications/activitytestfigure/viewmanager.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,201 @@
+/*
+* 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>
+
+QTM_USE_NAMESPACE
+#define hbApp qobject_cast<HbApplication*>(qApp)
+
+viewmanager::viewmanager(HbApplication *hbapp):
+ HbMainWindow(), mHbApp(hbapp)
+{
+
+ connect(hbApp->activityManager(), SIGNAL(activityRequested(QString)), this, SLOT(loadActivityData(QString)));
+
+
+ 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(updateAct()), this, SLOT(updateAct()));
+ connect(mTw, SIGNAL(updateAct()), this, SLOT(updateAct()));
+ connect(mCw, SIGNAL(updateAct()), this, SLOT(updateAct()));
+ connect(mSw, SIGNAL(del()), this, SLOT(del()));
+ connect(mTw, SIGNAL(del()), this, SLOT(del()));
+ connect(mCw, SIGNAL(del()), this, SLOT(del()));
+
+}
+
+viewmanager::~viewmanager()
+{
+
+}
+
+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;
+
+ HbMainWindow *mainWindow = hbInstance->allMainWindows().first();
+ QPixmap screenshot = QPixmap::grabWidget(mainWindow, mainWindow->rect());
+ QVariantHash metadata;
+ metadata.insert("screenshot", screenshot);
+
+ bool ok = hbApp->activityManager()->addActivity(mStatename, mSaveVariant, metadata);
+ if (!ok) {
+ widget->setFailedFlag();
+ }
+ else {
+ widget->clearFailedFlag();
+ }
+}
+
+void viewmanager::updateAct()
+{
+ QString color;
+ figurewidget* widget = currentWidget();
+ color = widget->color();
+
+ QStringList list;
+ list.append(mStatename);
+ list.append(color);
+ mSaveVariant.clear();
+ mSaveVariant = list;
+
+ HbMainWindow *mainWindow = hbInstance->allMainWindows().first();
+ QPixmap screenshot = QPixmap::grabWidget(mainWindow, mainWindow->rect());
+ QVariantHash metadata;
+ metadata.insert("screenshot", screenshot);
+
+ bool ok = hbApp->activityManager()->updateActivity(mStatename, mSaveVariant, metadata);
+ if (!ok) {
+ widget->setFailedFlag();
+ }
+ else {
+ widget->clearFailedFlag();
+ }
+}
+
+void viewmanager::del()
+{
+ bool ok = hbApp->activityManager()->removeActivity(mStatename);
+ figurewidget* widget = currentWidget();
+ if (!ok) {
+ widget->setFailedFlag();
+ }
+ else {
+ widget->clearFailedFlag();
+ }
+}
+
+void viewmanager::loadActivityData(const QString &name)
+{
+ QVariant data = hbApp->activityManager()->activityData( name );
+ loadActivityData( data );
+}
+
+void viewmanager::loadActivityData(const QVariant &data)
+{
+ 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) {
+ 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