clock/clockui/clockviewmanager/src/clockviewmanager.cpp
changeset 45 b6db4fd4947b
parent 18 c198609911f9
child 55 2c54b51f39c4
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    15 * Definition file for class ClockViewManager.
    15 * Definition file for class ClockViewManager.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 // System includes
    19 // System includes
    20 #include <QDebug>
       
    21 #include <HbMainWindow>
    20 #include <HbMainWindow>
    22 #include <HbInstance>
    21 #include <HbInstance>
       
    22 #include <hbapplication> // hbapplication
       
    23 #include <hbactivitymanager> // hbactivitymanager
    23 
    24 
    24 // User includes
    25 // User includes
    25 #include "clockviewmanager.h"
    26 #include "clockviewmanager.h"
    26 #include "clockdocloader.h"
    27 #include "clockdocloader.h"
    27 #include "clockmainview.h"
    28 #include "clockmainview.h"
    42 	\param controller A reference to the object of ClockAppController.
    43 	\param controller A reference to the object of ClockAppController.
    43  */
    44  */
    44 ClockViewManager::ClockViewManager(
    45 ClockViewManager::ClockViewManager(
    45 		ClockAppControllerIf &controllerIf, QObject *parent)
    46 		ClockAppControllerIf &controllerIf, QObject *parent)
    46 :QObject(parent),
    47 :QObject(parent),
    47  mAppControllerIf(controllerIf)
    48  mAppControllerIf(controllerIf),
       
    49  mWorldClockView(0)
    48 {
    50 {
    49 	qDebug("clock: ClockViewManager::ClockViewManager() -->");
    51     // Activity Reason from Activity Manager
       
    52     int activityReason = qobject_cast<HbApplication*>(qApp)->activateReason();
       
    53     
       
    54     if (Hb::ActivationReasonActivity == activityReason) {
       
    55         // Application is started from an activity
       
    56 		// extract activity data
       
    57         QVariant data = qobject_cast<HbApplication*>(qApp)->activateData();
       
    58         // restore state from activity data
       
    59         QByteArray serializedModel = data.toByteArray();
       
    60         QDataStream stream(&serializedModel, QIODevice::ReadOnly);
       
    61         int activityId;
       
    62         stream >> activityId;
       
    63         
       
    64         if (MainView == activityId) {
       
    65             // Load the main view at the start up.
       
    66             loadMainView();
       
    67 			// Delay loading of other views till main view is loaded.
       
    68         	HbMainWindow *window = hbInstance->allMainWindows().first();
       
    69         	connect(
       
    70                 window, SIGNAL(viewReady()),
       
    71                 this, SLOT(loadOtherViews()));
    50 
    72 
    51 	// Load the document and the views.
    73         }
    52 	loadViews();
    74         else if (WorldClock == activityId) {
       
    75             //no implentation yet, UI specs are not clear
       
    76         }
    53 
    77 
    54 	qDebug("clock: ClockViewManager::ClockViewManager() <--");
    78     }
       
    79     else {
       
    80         // Load the main view at the start up.
       
    81         loadMainView();
       
    82         // Delay loading of other views till main view is loaded.
       
    83         HbMainWindow *window = hbInstance->allMainWindows().first();
       
    84         connect(
       
    85                 window, SIGNAL(viewReady()),
       
    86                 this, SLOT(loadOtherViews()));
       
    87     }
       
    88 
    55 }
    89 }
    56 
    90 
    57 /*!
    91 /*!
    58 	Destructor.
    92 	Destructor.
    59  */
    93  */
    71 {
   105 {
    72 	HbMainWindow *window = hbInstance->allMainWindows().first();
   106 	HbMainWindow *window = hbInstance->allMainWindows().first();
    73 
   107 
    74 	switch (view) {
   108 	switch (view) {
    75 		case MainView:
   109 		case MainView:
       
   110 		    // set captured screenshot as invalid as main view 
       
   111 			// is the current view
       
   112 		    mMainView->captureScreenShot(false);
    76 			window->removeView(window->currentView());
   113 			window->removeView(window->currentView());
    77 			window->addView(mMainView);
   114 			window->addView(mMainView);
    78 			window->setCurrentView(mMainView);
   115 			window->setCurrentView(mMainView);
    79 			break;
   116 			break;
    80 
   117 
    81 		case WorldClock:
   118 		case WorldClock:
       
   119 		    if (mMainView) {
       
   120 				// capture main view as the screenshot for future use 
       
   121 				// to save the main view as an activity, if application is 
       
   122 				// exited/Quit from world view
       
   123                 mMainView->captureScreenShot(true);
       
   124 		    }
    82 			window->removeView(window->currentView());
   125 			window->removeView(window->currentView());
    83 			window->addView(mWorldClockView);
   126 			window->addView(mWorldClockView);
    84 			window->setCurrentView(mWorldClockView);
   127 			window->setCurrentView(mWorldClockView);
    85 			break;
   128 			break;
    86 
   129 
    88 			break;
   131 			break;
    89 	}
   132 	}
    90 }
   133 }
    91 
   134 
    92 /*!
   135 /*!
    93 	Loads the views from the docml file.
       
    94  */
       
    95 void ClockViewManager::loadViews()
       
    96 {
       
    97 	qDebug() << "clock: ClockViewManager::loadViews -->";
       
    98 
       
    99 	// Load the main view.
       
   100 	loadMainView();
       
   101 	// Load the world clock view.
       
   102 	loadWorldClockView();
       
   103 
       
   104 	// Set the main view to the window
       
   105 	hbInstance->allMainWindows().first()->addView(mMainView);
       
   106 
       
   107 	qDebug() << "clock: ClockViewManager::loadViews <--";
       
   108 }
       
   109 
       
   110 /*!
       
   111 	Loads the clock main view.
   136 	Loads the clock main view.
   112  */
   137  */
   113 void ClockViewManager::loadMainView()
   138 void ClockViewManager::loadMainView()
   114 {
   139 {
   115 	qDebug() << "clock: ClockViewManager::loadMainView -->";
       
   116 
       
   117 	bool loadSuccess;
   140 	bool loadSuccess;
   118 
   141 
   119 	// Construct the document loader instance
   142 	// Construct the document loader instance
   120 	ClockDocLoader *docLoader = new ClockDocLoader();
   143 	ClockDocLoader *docLoader = new ClockDocLoader();
   121 
   144 
   122 	// Load the application xml.
   145 	// Load the application xml.
   123 	docLoader->load(CLOCK_MAIN_VIEW_DOCML, &loadSuccess);
   146 	docLoader->load(CLOCK_MAIN_VIEW_DOCML, &loadSuccess);
   124 	Q_ASSERT_X(
       
   125 			loadSuccess,
       
   126 			"viewmanager.cpp",
       
   127 			"Unable to load the main view app xml");
       
   128 
   147 
   129 	// Find the main view.
   148 	// Find the main view.
   130 	mMainView = static_cast<ClockMainView *> (
   149 	mMainView = static_cast<ClockMainView *> (
   131 			docLoader->findWidget(CLOCK_MAIN_VIEW));
   150 			docLoader->findWidget(CLOCK_MAIN_VIEW));
   132 
   151 
   133 	// Setup the view.
   152 	// Setup the view.
   134 	mMainView->setupView(mAppControllerIf, docLoader);
   153 	mMainView->setupView(mAppControllerIf, docLoader);
   135 
   154 
   136 	qDebug() << "clock: ClockViewManager::loadMainView <--";
   155 	// Set the main view to the window
       
   156 	hbInstance->allMainWindows().first()->addView(mMainView);
   137 }
   157 }
   138 
   158 
   139 /*!
   159 /*!
   140 	Loads the world clock view.
   160 	Loads the world clock view.
   141  */
   161  */
   145 	ClockDocLoader *docLoader = new ClockDocLoader();
   165 	ClockDocLoader *docLoader = new ClockDocLoader();
   146 
   166 
   147 	bool loadSuccess;
   167 	bool loadSuccess;
   148 
   168 
   149 	// Construct the world list view from doc loader.
   169 	// Construct the world list view from doc loader.
   150 	docLoader->load(":/xml/worldclockview.docml", &loadSuccess);
   170 	docLoader->load(CLOCK_WORLD_VIEW_DOCML, &loadSuccess);
   151 
   171 
   152 	// Get the world list view.
   172 	// Get the world list view.
   153 	mWorldClockView =
   173 	mWorldClockView = static_cast<ClockWorldView *> (
   154 			static_cast<ClockWorldView *> (docLoader->findWidget("worldClockView"));
   174 			docLoader->findWidget(CLOCK_WORLD_VIEW));
   155 
   175 
   156 	mWorldClockView->setupView(mAppControllerIf, docLoader);
   176 	mWorldClockView->setupView(mAppControllerIf, docLoader);
       
   177 }
   157 
   178 
   158 /*	// Get the world list widget.
   179 /*!
   159 	WorldListWidget *listWidget =
   180 	Load other views
   160 			qobject_cast<WorldListWidget *> (docLoader->findWidget("worldListWidget"));
   181  */
   161 	Q_ASSERT_X(listWidget,
   182 void ClockViewManager::loadOtherViews()
   162 	           "viewmanager.cpp", "Unable to load the world list widget");
   183 {
   163 	listWidget->setupWidget(mWorldListView, docLoader);*/
   184 	mMainView->setupAfterViewReady();
       
   185 	
       
   186 	// Load world clock view
       
   187 	loadWorldClockView();
       
   188 
       
   189 	// Disconnect the signal viewReady as all the views are loaded.
       
   190 	HbMainWindow *window = hbInstance->allMainWindows().first();
       
   191 	disconnect(
       
   192 			window, SIGNAL(viewReady()),
       
   193 			this, SLOT(loadOtherViews()));
   164 }
   194 }
   165 
   195 
   166 // End of file	--Don't remove this.
   196 // End of file	--Don't remove this.