memspyui/ui/hb/src/viewmanager.cpp
changeset 48 da3ec8478e66
parent 47 11fa016241a4
child 54 9347c563e054
equal deleted inserted replaced
47:11fa016241a4 48:da3ec8478e66
     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 <HbMainWindow>
       
    19 #include <HbAction>
       
    20 #include <HbMessageBox>
       
    21 #include <HbLabel>
       
    22 
       
    23 #include "viewmanager.h"
       
    24 
       
    25 #include "enginewrapper.h"
       
    26 #include "memspyview.h"
       
    27 #include "memspymainview.h"
       
    28 #include "memspyprocessview.h"
       
    29 #include "memspythreadview.h"
       
    30 #include "memspythreaddetailindexview.h"
       
    31 #include "memspythreaddetailview.h"
       
    32 #include "memspykernelobjecttypeview.h"
       
    33 #include "memspykernelobjectview.h"
       
    34 #include "memspykernelobjectdetailview.h"
       
    35 #include "memspytrackingview.h"
       
    36 #include "memspyswmtview.h"
       
    37 #include "memspyheapdumpsview.h"
       
    38 
       
    39 template <typename T>
       
    40 static MemSpyView* factory(EngineWrapper &engine, ViewManager &viewManager)
       
    41 {
       
    42 	return new T(engine, viewManager);
       
    43 }
       
    44 // This array needs to be in sync with view enum
       
    45 MemSpyView* (*sFactories[])(EngineWrapper&, ViewManager&) = { 
       
    46 	&factory<MemSpyMainView>,
       
    47 	&factory<MemSpyProcessView>,
       
    48 	&factory<MemSpyThreadView>,
       
    49 	&factory<MemSpyThreadDetailIndexView>,
       
    50 	&factory<MemSpyThreadDetailView>,
       
    51 	&factory<MemSpyKernelObjectTypeView>,
       
    52 	&factory<MemSpyKernelObjectView>,
       
    53 	&factory<MemSpyKernelObjectDetailView>,
       
    54 	&factory<MemSpyTrackingView>,
       
    55 	&factory<MemSpySwmtView>,
       
    56 	&factory<MemSpyHeapDumpsView>
       
    57 };
       
    58 
       
    59 
       
    60 ViewManager::ViewManager(HbMainWindow &window, EngineWrapper &engine, QObject *parent) :
       
    61 	QObject(parent),
       
    62 	mWindow(window),
       
    63 	mEngine(engine)
       
    64 {
       
    65 	connect(&mWindow, SIGNAL(currentViewChanged(HbView *)), this, SLOT(viewChanged(HbView *)));
       
    66 }
       
    67 
       
    68 void ViewManager::showView(ViewIndex viewIndex, const QVariantMap &params)
       
    69 {
       
    70     MemSpyView* view;
       
    71     try {
       
    72         view = sFactories[viewIndex](mEngine, *this);
       
    73         view->initialize(params);
       
    74     }
       
    75     catch (std::exception& ex)
       
    76     {
       
    77         // show message box with exception
       
    78         // TODO: qt_symbian_exception2Error shouldn't probably be here
       
    79         QString error = tr("An error occured during the operation. Error code: %1").arg(
       
    80                 qt_symbian_exception2Error(ex));
       
    81         
       
    82         HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning);
       
    83         messageBox->setText(error);
       
    84         HbLabel *header = new HbLabel(tr("Error"), messageBox);
       
    85         messageBox->setHeadingWidget(header);
       
    86         messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
    87         messageBox->setTimeout(HbPopup::StandardTimeout);
       
    88         messageBox->open();
       
    89         
       
    90         delete view;
       
    91         return;
       
    92     }
       
    93     
       
    94 	if (viewIndex != MainView) {
       
    95 		HbAction* action = new HbAction(Hb::BackNaviAction, this);
       
    96 		connect(action, SIGNAL(triggered()), this, SLOT(goBack()));
       
    97 		view->setNavigationAction(action);
       
    98 	}
       
    99 		
       
   100 	mWindow.addView(view);
       
   101 	mWindow.setCurrentView(view);
       
   102 }
       
   103 
       
   104 void ViewManager::showView(ViewIndex viewIndex)
       
   105 {
       
   106 	showView(viewIndex, QVariantMap());
       
   107 }
       
   108 
       
   109 void ViewManager::goBack()
       
   110 {
       
   111 	const QList<HbView*> views = mWindow.views();
       
   112 	int index = views.indexOf(mWindow.currentView());
       
   113 	mWindow.setCurrentView(views.at(index-1), true, Hb::ViewSwitchUseBackAnim);
       
   114 }
       
   115 
       
   116 void ViewManager::viewChanged(HbView *view)
       
   117 {
       
   118 	const QList<HbView*> views = mWindow.views();
       
   119 	int index = views.indexOf(view);
       
   120 	for (int i=views.count()-1; i>index; i--)
       
   121 		mWindow.removeView(views.at(i));
       
   122 }