ginebra2/ViewController.cpp
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
--- a/ginebra2/ViewController.cpp	Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/ViewController.cpp	Wed Jun 23 17:59:43 2010 +0300
@@ -1,26 +1,29 @@
 /*
 * Copyright (c) 2010 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".
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
 *
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Lesser General Public License for more details.
 *
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program.  If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
 *
-* Description: 
+* Description:
 *
 */
 
-
 #include "ViewController.h"
 #include <QDebug>
 
 namespace GVA {
-    
+
   ViewController::ViewController()
     : m_viewMap() {
     m_current = m_viewMap.begin();
@@ -38,7 +41,7 @@
              << " jsObject=" << controllableView->jsObject();
     QString key;
     // Set up parent/child link for javascript access to the view.
-    if(controllableView->jsObject()) {
+    if (controllableView->jsObject()) {
       // Use the view's javascript object.
       controllableView->jsObject()->setParent(this);
       key = controllableView->jsObject()->objectName();
@@ -48,10 +51,13 @@
       controllableView->setParent(this);
       key = controllableView->objectName();
     }
-    if(key.isNull()) {
+    if (key.isNull()) {
       qWarning("ViewController::addView: missing objectName.");
     }
     m_viewMap.insert(key, controllableView);
+    // Set the only view to current view
+    if (m_viewMap.size() == 1)
+        m_current = m_viewMap.begin();
   }
 
   QObjectList ViewController::getViews() {
@@ -61,13 +67,13 @@
     }
     return *result;
   }
-  
+
   void ViewController::showCurrent() {
       qDebug() << "ViewController::showCurrent: " << m_current.value();
       ControllableViewBase *currentView = m_current.value();
-      if(!currentView) return;
+      if (!currentView) return;
 
-      if(!currentView->isActive()) {
+      if (!currentView->isActive()) {
           emit currentViewChanging();
           // Activate the current view.
           currentView->activate();
@@ -75,7 +81,7 @@
 
           // Deactivate all others.
           foreach(ControllableViewBase *view, m_viewMap) {
-              if(view && view->isActive() && view != currentView) {
+              if (view && view->isActive() && view != currentView) {
                   view->hide();
                   view->deactivate();
               }
@@ -83,23 +89,23 @@
           emit currentViewChanged();
       }
   }
-  
+
   void ViewController::showView(const QString &name) {
       ViewMap::iterator it = m_viewMap.find(name);
-      if(it != m_viewMap.end()) {
+      if (it != m_viewMap.end()) {
           m_current = it;
           showCurrent();
       }
   }
-  
+
   void ViewController::freezeView() {
-      if(!m_viewMap.isEmpty() ) {
+      if (!m_viewMap.isEmpty() ) {
           m_current.value()->freeze();
       }
   }
-  
+
   void ViewController::unfreezeView() {
-      if(!m_viewMap.isEmpty() ) {
+      if (!m_viewMap.isEmpty() ) {
           m_current.value()->unfreeze();
       }
   }
@@ -116,9 +122,9 @@
   void ViewController::viewChanged() {
       emit currentViewChanged();
   }
-  
+
   ControllableViewBase* ViewController::currentView() {
-      if(!m_viewMap.isEmpty())
+      if (!m_viewMap.isEmpty())
           return m_current.value();
       else
           return NULL;