homescreenapp/hsapplication/tsrc/t_hsapplication/t_hsapplicationexe/src/hsscene_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 <HbInstance>
       
    19 #include "hsdomainmodeldatastructures.h"
       
    20 #include "hsscene.h"
       
    21 #include "hspage.h"
       
    22 #include "hswidgethost.h"
       
    23 #include "hswallpaper.h"
       
    24 #include "hsconfiguration.h"
       
    25 
       
    26 HsScene::~HsScene()
       
    27 {
       
    28     delete mWallpaper;
       
    29     qDeleteAll(mPages);
       
    30 }
       
    31 
       
    32 int HsScene::databaseId() const
       
    33 {
       
    34     return mDatabaseId;
       
    35 }
       
    36 
       
    37 bool HsScene::load()
       
    38 {
       
    39     return true;
       
    40 }
       
    41 
       
    42 HsWallpaper *HsScene::wallpaper() const
       
    43 {
       
    44     return mWallpaper;
       
    45 }
       
    46 
       
    47 QList<HsPage *> HsScene::pages() const
       
    48 {
       
    49     return mPages;
       
    50 }
       
    51 
       
    52 bool HsScene::addPage(HsPage *page)
       
    53 {
       
    54     if (!page) {
       
    55         return false;
       
    56     }
       
    57 
       
    58     if (mPages.contains(page)) {
       
    59         return true;
       
    60     }
       
    61 
       
    62     mPages << page;
       
    63     return true;
       
    64 }
       
    65 
       
    66 bool HsScene::removePage(HsPage *page)
       
    67 {
       
    68     if (!page) {
       
    69         return false;
       
    70     }
       
    71     return mPages.removeOne(page);
       
    72 }
       
    73 
       
    74 bool HsScene::setActivePage(HsPage *page)
       
    75 {
       
    76     if (!page) {
       
    77         return false;
       
    78     }
       
    79 
       
    80     if (!mPages.contains(page)) {
       
    81         return false;
       
    82     }
       
    83 
       
    84     mActivePage = page;
       
    85     return true;
       
    86 }
       
    87 
       
    88 bool HsScene::setActivePageIndex(int index)
       
    89 {
       
    90     if (index < 0 || mPages.count() <= index) {
       
    91         return false;
       
    92     }
       
    93     return setActivePage(mPages[index]);
       
    94 }
       
    95 
       
    96 HsPage *HsScene::activePage() const
       
    97 {
       
    98     return mActivePage;
       
    99 }
       
   100 
       
   101 int HsScene::activePageIndex() const
       
   102 {
       
   103     return mPages.indexOf(mActivePage);
       
   104 }
       
   105 
       
   106 void HsScene::setActiveWidget(HsWidgetHost *widget)
       
   107 {
       
   108     mActiveWidget = widget;
       
   109 }
       
   110 
       
   111 HsWidgetHost *HsScene::activeWidget() const
       
   112 {
       
   113     return mActiveWidget;
       
   114 }
       
   115 
       
   116 void HsScene::setOnline(bool online)
       
   117 {
       
   118     mIsOnline = online;
       
   119     foreach (HsPage *page, mPages) {
       
   120         page->setOnline(online);
       
   121     }
       
   122 }
       
   123 
       
   124 bool HsScene::isOnline()const
       
   125 {
       
   126     return mIsOnline;
       
   127 }
       
   128 
       
   129 /*!
       
   130     Singleton.
       
   131 */
       
   132 HsScene *HsScene::instance()
       
   133 {
       
   134     return mInstance;
       
   135 }
       
   136 
       
   137 HsScene *HsScene::takeInstance()
       
   138 {
       
   139     HsScene *instance = mInstance;
       
   140     mInstance = 0;
       
   141     return instance;
       
   142 }
       
   143  
       
   144 void HsScene::setInstance(HsScene *instance)
       
   145 {
       
   146     if (mInstance != instance) {
       
   147         delete mInstance;
       
   148         mInstance = instance; 
       
   149     }    
       
   150 }
       
   151 
       
   152 /*!
       
   153     Listens for application background/foreground changes.
       
   154 */
       
   155 bool HsScene::eventFilter(QObject *watched, QEvent *event)
       
   156 {
       
   157     switch (event->type()) {
       
   158         case QEvent::ApplicationActivate:
       
   159             mActivePage->showWidgets();
       
   160             break;
       
   161 		case QEvent::ApplicationDeactivate:
       
   162             mActivePage->hideWidgets();
       
   163             break;
       
   164         default:
       
   165             break;
       
   166 	}
       
   167     return QObject::eventFilter(watched, event);
       
   168 }
       
   169 
       
   170 HsScene::HsScene(QObject *parent)
       
   171   : QObject(parent),
       
   172     mDatabaseId(-1),
       
   173     mWallpaper(0),
       
   174     mActivePage(0),
       
   175     mActiveWidget(0),
       
   176     mIsOnline(true)
       
   177 {
       
   178 }
       
   179 
       
   180 /*!
       
   181     Points to the scene instance.
       
   182 */
       
   183 HsScene *HsScene::mInstance = 0;