activityfw/testapplications/activitytakeawhile/viewmanager.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     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 #include <qservicemanager.h>
       
    18 #include <HbInstance>
       
    19 #include <QStringList>
       
    20 #include <QCoreApplication>
       
    21 #include <hbapplication.h>
       
    22 #include "viewmanager.h"
       
    23 #include "letterwidget.h"
       
    24 #include <QGraphicsGridLayout>
       
    25 #include <HbPushButton>
       
    26 
       
    27 QTM_USE_NAMESPACE
       
    28 
       
    29 viewmanager::viewmanager():
       
    30     HbMainWindow()
       
    31 {
       
    32     QServiceManager serviceManager;
       
    33     mActivityClient = serviceManager.loadInterface("com.nokia.qt.activities.ActivityClient");
       
    34     if (!mActivityClient) {
       
    35         qFatal("load plugin failed");
       
    36     }
       
    37 
       
    38     mLw = new letterwidget;
       
    39     addView(mLw);
       
    40     
       
    41     connect(mActivityClient, SIGNAL(activityRequested(QString)), this, SLOT(loadActivityData(QString)));
       
    42     
       
    43 
       
    44     
       
    45     bool retok;
       
    46     bool ok = QMetaObject::invokeMethod(mActivityClient, "waitActivity", Q_RETURN_ARG(bool, retok));
       
    47     if (!ok || !retok) {
       
    48 //        qFatal("Subscribe failed");
       
    49     }
       
    50 
       
    51     //startup case    
       
    52     QStringList arglist = qApp->arguments(); 
       
    53     QVariantHash actdata;
       
    54     ok = QMetaObject::invokeMethod(mActivityClient, "parseCommandLine", Q_RETURN_ARG(QVariantHash, actdata), Q_ARG(QStringList, arglist));
       
    55     if (!ok) {
       
    56         qFatal("Startup failed");
       
    57     }
       
    58     QString actid = actdata.value("activityname").toString();
       
    59     if ( !actid.isNull() )
       
    60         {
       
    61         QVariant data;
       
    62         ok = QMetaObject::invokeMethod(mActivityClient, "activityData", Q_RETURN_ARG(QVariant, data), Q_ARG(QString, actid));
       
    63         if (!ok) {
       
    64             qFatal("Get data failed");
       
    65         }
       
    66         loadActivityData(data);
       
    67         }
       
    68     //startup case end
       
    69     
       
    70     connect(mLw, SIGNAL(save()), this, SLOT(save()));
       
    71     connect(mLw, SIGNAL(del()), this, SLOT(del()));
       
    72 }
       
    73 
       
    74 viewmanager::~viewmanager()
       
    75 {
       
    76 }
       
    77 
       
    78 void viewmanager::save()
       
    79 {
       
    80     mSaveVariant = mLw->state();
       
    81 
       
    82     HbMainWindow *mainWindow = hbInstance->allMainWindows().first();
       
    83     QPixmap screenshot = QPixmap::grabWidget(mainWindow, mainWindow->rect());
       
    84     QVariantHash metadata;
       
    85     metadata.insert("screenshot", screenshot);
       
    86 
       
    87     bool retok;
       
    88     bool ok = QMetaObject::invokeMethod(mActivityClient, "removeActivity", Q_RETURN_ARG(bool, retok), Q_ARG(QString, mLw->state()));
       
    89     if (!ok) {
       
    90         qFatal("Remove failed");
       
    91     }
       
    92 
       
    93     ok = QMetaObject::invokeMethod(mActivityClient, "addActivity", Q_RETURN_ARG(bool, retok), Q_ARG(QString, mLw->state()), Q_ARG(QVariant, mSaveVariant), Q_ARG(QVariantHash, metadata));
       
    94     if (!ok || !retok) {
       
    95         qFatal("Add failed");
       
    96     }
       
    97 }
       
    98 void viewmanager::del()
       
    99 {
       
   100     bool retok;
       
   101     bool ok = QMetaObject::invokeMethod(mActivityClient, "removeActivity", Q_RETURN_ARG(bool, retok), Q_ARG(QString, mLw->state()));
       
   102     if (!ok) {
       
   103         qFatal("Remove failed");
       
   104     }
       
   105 }
       
   106     
       
   107 void viewmanager::loadActivityData(const QString &name)
       
   108 {
       
   109     bool retok;
       
   110     bool ok = QMetaObject::invokeMethod(mActivityClient, "waitActivity", Q_RETURN_ARG(bool, retok));
       
   111     if (!ok || !retok) {
       
   112         //qFatal("Resubscribe failed");
       
   113     }
       
   114     QVariant data;
       
   115     ok = QMetaObject::invokeMethod(mActivityClient, "activityData", Q_RETURN_ARG(QVariant, data), Q_ARG(QString, name));
       
   116     if (!ok) {
       
   117         qFatal("Get data failed");
       
   118     }
       
   119     loadActivityData(data);
       
   120 }
       
   121 
       
   122 void viewmanager::loadActivityData(const QVariant &data)
       
   123 {    
       
   124     QString statename = data.toString();
       
   125     mLw->setState(statename);
       
   126 }