homescreenapp/stateplugins/hshomescreenstateplugin/tsrc/t_hshomescreenstateplugin/src/hswidgethost_mock.cpp
changeset 90 3ac3aaebaee5
equal deleted inserted replaced
86:e4f038c420f7 90:3ac3aaebaee5
       
     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 <QApplication>
       
    19 #include <QStateMachine>
       
    20 #include <QState>
       
    21 #include <QFinalState>
       
    22 #include <QGraphicsLinearLayout>
       
    23 #include <QParallelAnimationGroup>
       
    24 #include <QPropertyAnimation>
       
    25 #include <QGraphicsDropShadowEffect>
       
    26 #include <QGraphicsSceneResizeEvent>
       
    27 #include <QGesture>
       
    28 #include <QGraphicsScene>
       
    29 
       
    30 #include <qservicemanager.h>
       
    31 #include <qservicefilter.h>
       
    32 #include <qserviceinterfacedescriptor.h>
       
    33 
       
    34 #include <HbInstantFeedback>
       
    35 #include <HbTouchArea>
       
    36 
       
    37 #include "hsdatabase.h"
       
    38 #include "hsdomainmodeldatastructures.h"
       
    39 #include "hsscene.h"
       
    40 #include "hspage.h"
       
    41 #include "hswidgethost.h"
       
    42 #include "hswidgethostvisual.h"
       
    43 #include "hswidgettoucharea.h"
       
    44 #include "hswidgetcomponentregistry.h"
       
    45 #include "hswidgetcomponent.h"
       
    46 #include "hsconfiguration.h"
       
    47 #include "hscontentservice.h"
       
    48 #include "testwidget.h"
       
    49 
       
    50 // Helper macros for connecting state entry and exit actions.
       
    51 #define ENTRY_ACTION(state, action) \
       
    52     connect(state, SIGNAL(entered()), SLOT(action()));
       
    53 #define EXIT_ACTION(state, action) \
       
    54     connect(state, SIGNAL(exited()), SLOT(action()));
       
    55 
       
    56 QTM_USE_NAMESPACE
       
    57 
       
    58 HsWidgetHost::HsWidgetHost(int databaseId, QObject *parent)
       
    59   : QObject(parent),
       
    60     mDatabaseId(databaseId),
       
    61     mVisual(new HsWidgetHostVisual),    
       
    62     mStateMachine(0),
       
    63     mWidget(0),
       
    64     mPage(0),
       
    65     mComponent(0),
       
    66     mIsFinishing(false)
       
    67 {
       
    68     setupStates();
       
    69 }
       
    70 
       
    71 HsWidgetHost::~HsWidgetHost()
       
    72 {
       
    73     delete mVisual;
       
    74 }
       
    75 
       
    76 HsWidgetHost *HsWidgetHost::createInstance(HsWidgetData &widgetData, 
       
    77                                            const QVariantHash &preferences)
       
    78 {
       
    79     Q_UNUSED(widgetData);
       
    80     Q_UNUSED(preferences);
       
    81     HsWidgetHost *host = NULL;
       
    82     host = new HsWidgetHost(-1);
       
    83     return host;
       
    84 }
       
    85 
       
    86 int HsWidgetHost::databaseId() const
       
    87 {
       
    88     return mDatabaseId;
       
    89 }
       
    90 
       
    91 bool HsWidgetHost::setPage(HsPage *page)
       
    92 {
       
    93     mPage = page;
       
    94     return true;
       
    95 }
       
    96  
       
    97 HsPage *HsWidgetHost::page() const
       
    98 {
       
    99     return mPage;
       
   100 }
       
   101 
       
   102 bool HsWidgetHost::loadPresentation()
       
   103 {
       
   104     return true;
       
   105 }
       
   106 
       
   107 bool HsWidgetHost::loadPresentation(Qt::Orientation orientation)
       
   108 {
       
   109     Q_UNUSED(orientation)
       
   110     return true;
       
   111 }
       
   112 
       
   113 bool HsWidgetHost::savePresentation()
       
   114 {
       
   115     return true;
       
   116 }
       
   117 
       
   118 bool HsWidgetHost::savePresentation(Qt::Orientation orientation)
       
   119 {
       
   120     Q_UNUSED(orientation)
       
   121     return true;
       
   122 }
       
   123 
       
   124 bool HsWidgetHost::savePresentation(HsWidgetPresentationData &presentation)
       
   125 {
       
   126     Q_UNUSED(presentation)
       
   127     return true;
       
   128 }
       
   129 
       
   130 bool HsWidgetHost::getPresentation(HsWidgetPresentationData &presentation)
       
   131 {
       
   132     Q_UNUSED(presentation)
       
   133     return true;
       
   134 }
       
   135 
       
   136 bool HsWidgetHost::removePresentation(Qt::Orientation orientation)
       
   137 {
       
   138     Q_UNUSED(orientation)
       
   139     return true;
       
   140 }
       
   141 
       
   142 
       
   143 void HsWidgetHost::startWidget(bool show)
       
   144 {
       
   145     if (show) {
       
   146         emit event_startAndShow();
       
   147     } else {
       
   148         emit event_startAndHide();
       
   149     }
       
   150 }
       
   151  
       
   152 void HsWidgetHost::showWidget()
       
   153 {
       
   154     emit event_show();
       
   155 }
       
   156     
       
   157 void HsWidgetHost::hideWidget()
       
   158 {
       
   159     emit event_hide();
       
   160 }
       
   161 
       
   162 void HsWidgetHost::setOnline(bool online)
       
   163 {
       
   164     mIsOnlineProperty.write(mWidget, online);
       
   165 }
       
   166 
       
   167 void HsWidgetHost::remove()
       
   168 {
       
   169     emit event_remove();
       
   170 }
       
   171  
       
   172 void HsWidgetHost::close()
       
   173 {
       
   174     emit event_close();
       
   175 }
       
   176 
       
   177 
       
   178 
       
   179 void HsWidgetHost::setupStates()
       
   180 {
       
   181     // State machine
       
   182 
       
   183     mStateMachine = new QStateMachine(this);
       
   184     mStateMachine->setAnimated(false);
       
   185     
       
   186     // States
       
   187 
       
   188     QState *state_component = new QState;
       
   189     QState *state_unloaded = new QState(state_component);
       
   190     QState *state_running = new QState(state_component);
       
   191     QState *state_show = new QState(state_running);
       
   192     QState *state_hide = new QState(state_running);
       
   193     QState *state_finished = new QState;
       
   194     QState *state_faulted = new QState;
       
   195     QState *state_remove = new QState;
       
   196     QFinalState *state_final = new QFinalState;
       
   197 
       
   198     mStateMachine->addState(state_component);
       
   199     mStateMachine->addState(state_finished);
       
   200     mStateMachine->addState(state_faulted);
       
   201     mStateMachine->addState(state_remove);
       
   202     mStateMachine->addState(state_final);
       
   203 
       
   204     mStateMachine->setInitialState(state_component);
       
   205     state_component->setInitialState(state_unloaded);
       
   206     state_running->setInitialState(state_hide);
       
   207 
       
   208     // Transitions
       
   209 
       
   210     state_component->addTransition(
       
   211         this, SIGNAL(event_close()), state_final);
       
   212     state_component->addTransition(
       
   213         this, SIGNAL(event_remove()), state_remove);
       
   214     state_component->addTransition(
       
   215         this, SIGNAL(event_finished()), state_finished);
       
   216     state_component->addTransition(
       
   217         this, SIGNAL(event_faulted()), state_faulted);
       
   218 
       
   219     state_unloaded->addTransition(
       
   220         this, SIGNAL(event_startAndShow()), state_show);
       
   221     state_unloaded->addTransition(
       
   222         this, SIGNAL(event_startAndHide()), state_hide);
       
   223 
       
   224     state_running->addTransition(
       
   225         this, SIGNAL(event_unload()), state_unloaded);
       
   226     
       
   227     state_show->addTransition(
       
   228         this, SIGNAL(event_hide()), state_hide);
       
   229 
       
   230     state_hide->addTransition(
       
   231         this, SIGNAL(event_show()), state_show);
       
   232 
       
   233     state_finished->addTransition(
       
   234         this, SIGNAL(event_remove()), state_remove);
       
   235     state_finished->addTransition(
       
   236         this, SIGNAL(event_close()), state_final);
       
   237 
       
   238     state_faulted->addTransition(
       
   239         this, SIGNAL(event_remove()), state_remove);
       
   240     state_faulted->addTransition(
       
   241         this, SIGNAL(event_close()), state_final);
       
   242 
       
   243     state_remove->addTransition(state_final);
       
   244 
       
   245     // Actions
       
   246 
       
   247     ENTRY_ACTION(state_component, action_connectComponent)
       
   248     EXIT_ACTION(state_component, action_disconnectComponent)
       
   249 
       
   250     ENTRY_ACTION(state_running, action_load)
       
   251     ENTRY_ACTION(state_running, action_initialize)
       
   252     EXIT_ACTION(state_running, action_uninitialize)
       
   253     EXIT_ACTION(state_running, action_unload)
       
   254 
       
   255     ENTRY_ACTION(state_show, action_show)
       
   256 
       
   257     ENTRY_ACTION(state_hide, action_hide)
       
   258 
       
   259     ENTRY_ACTION(state_finished, action_finished)
       
   260 
       
   261     ENTRY_ACTION(state_faulted, action_faulted)
       
   262 
       
   263     ENTRY_ACTION(state_remove, action_notifyRemove)
       
   264     ENTRY_ACTION(state_remove, action_remove)
       
   265 
       
   266     // Delete on finish.
       
   267 
       
   268     connect(mStateMachine, SIGNAL(finished()), SLOT(deleteLater()), 
       
   269             Qt::QueuedConnection);
       
   270 }
       
   271 
       
   272 bool HsWidgetHost::setProperty(const char *name, QMetaProperty &property)
       
   273 {
       
   274     const QMetaObject *object = mWidget->metaObject();
       
   275     int index = object->indexOfProperty(name);
       
   276     property = object->property(index);
       
   277     return index >= 0;
       
   278 }
       
   279 
       
   280 bool HsWidgetHost::setMethod(const char *signature, QMetaMethod &method)
       
   281 {
       
   282     const QMetaObject *object = mWidget->metaObject();
       
   283     int index = object->indexOfMethod(
       
   284         QMetaObject::normalizedSignature(signature));
       
   285     method = object->method(index);
       
   286     return index >= 0;
       
   287 }
       
   288 
       
   289 bool HsWidgetHost::hasSignal(const char *signature)
       
   290 {
       
   291     const QMetaObject *object = mWidget->metaObject();
       
   292     int index = object->indexOfSignal(
       
   293         QMetaObject::normalizedSignature(signature));
       
   294     return index >= 0;
       
   295 }
       
   296 
       
   297 
       
   298 bool HsWidgetHost::setPreferencesToWidget()
       
   299 {
       
   300     return true;
       
   301 }
       
   302 
       
   303 void HsWidgetHost::action_connectComponent()
       
   304 {    
       
   305 }
       
   306 
       
   307 void HsWidgetHost::action_disconnectComponent()
       
   308 {
       
   309 }
       
   310 
       
   311 void HsWidgetHost::action_load()
       
   312 {   
       
   313 
       
   314 }
       
   315 
       
   316 void HsWidgetHost::action_unload()
       
   317 {
       
   318     delete mWidget;
       
   319     mWidget = 0;
       
   320 
       
   321     mOnInitializeMethod = QMetaMethod();
       
   322     mOnShowMethod = QMetaMethod();
       
   323     mOnHideMethod = QMetaMethod();
       
   324     mOnUninitializeMethod = QMetaMethod();    
       
   325     mIsOnlineProperty = QMetaProperty();
       
   326 	mRootPathProperty = QMetaProperty();    
       
   327 }
       
   328 
       
   329 void HsWidgetHost::action_initialize()
       
   330 {    
       
   331     setPreferencesToWidget();
       
   332     setOnline(HsScene::instance()->isOnline());
       
   333     mOnInitializeMethod.invoke(mWidget);
       
   334 }
       
   335 
       
   336 void HsWidgetHost::action_uninitialize()
       
   337 {
       
   338     mOnUninitializeMethod.invoke(mWidget);
       
   339 }
       
   340 
       
   341 void HsWidgetHost::action_show()
       
   342 {
       
   343     if (!mIsFinishing) {
       
   344         mOnShowMethod.invoke(mWidget);
       
   345     }
       
   346 }
       
   347 
       
   348 void HsWidgetHost::action_hide()
       
   349 {
       
   350     if (!mIsFinishing) {
       
   351         mOnHideMethod.invoke(mWidget);
       
   352     }
       
   353 }
       
   354 
       
   355 void HsWidgetHost::action_finished()
       
   356 {
       
   357     emit finished();
       
   358 }
       
   359 
       
   360 void HsWidgetHost::action_faulted()
       
   361 {
       
   362     emit faulted();
       
   363 }
       
   364 
       
   365 void HsWidgetHost::action_remove()
       
   366 {   
       
   367     mDatabaseId = -1;
       
   368 }
       
   369 
       
   370 void HsWidgetHost::action_notifyRemove()
       
   371 {
       
   372     //Empty at mock
       
   373 }
       
   374 
       
   375 void HsWidgetHost::onFinished()
       
   376 {
       
   377     mIsFinishing = true;
       
   378     emit event_finished();
       
   379 }
       
   380  
       
   381 void HsWidgetHost::onError()
       
   382 {
       
   383     mIsFinishing = true;
       
   384     emit event_faulted();
       
   385 }
       
   386 
       
   387 void HsWidgetHost::onSetPreferences(const QStringList &names)
       
   388 {
       
   389     Q_UNUSED(names)
       
   390 }
       
   391 /*!
       
   392     Starts the drag effect.
       
   393 */
       
   394 void HsWidgetHost::startDragEffect()
       
   395 {   
       
   396 }
       
   397 
       
   398 /*!
       
   399     Starts the drop effect.
       
   400 */
       
   401 void HsWidgetHost::startDropEffect()
       
   402 {    
       
   403 }
       
   404 HsWidgetHostVisual *HsWidgetHost::visual() const
       
   405 {
       
   406     return mVisual;
       
   407 }
       
   408