|
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 #include "memspyserverview.h" |
|
39 #include "memspyecomcategoryview.h" |
|
40 #include "memspyecominterfaceview.h" |
|
41 #include "memspyecomimplementationview.h" |
|
42 #include "memspyecomimplementationdetailview.h" |
|
43 |
|
44 template <typename T> |
|
45 static MemSpyView* factory(EngineWrapper &engine, ViewManager &viewManager) |
|
46 { |
|
47 return new T(engine, viewManager); |
|
48 } |
|
49 // This array needs to be in sync with view enum |
|
50 MemSpyView* (*sFactories[])(EngineWrapper&, ViewManager&) = { |
|
51 &factory<MemSpyMainView>, |
|
52 &factory<MemSpyProcessView>, |
|
53 &factory<MemSpyThreadView>, |
|
54 &factory<MemSpyThreadDetailIndexView>, |
|
55 &factory<MemSpyThreadDetailView>, |
|
56 &factory<MemSpyKernelObjectTypeView>, |
|
57 &factory<MemSpyKernelObjectView>, |
|
58 &factory<MemSpyKernelObjectDetailView>, |
|
59 &factory<MemSpyTrackingView>, |
|
60 &factory<MemSpySwmtView>, |
|
61 &factory<MemSpyHeapDumpsView>, |
|
62 &factory<MemSpyServerView>, |
|
63 &factory<MemSpyEComCategoryView>, |
|
64 &factory<MemSpyEComInterfaceView>, |
|
65 &factory<MemSpyEComImplementationView>, |
|
66 &factory<MemSpyEComImplementationDetailView>, |
|
67 }; |
|
68 |
|
69 |
|
70 ViewManager::ViewManager(HbMainWindow &window, EngineWrapper &engine, QObject *parent) : |
|
71 QObject(parent), |
|
72 mWindow(window), |
|
73 mEngine(engine) |
|
74 { |
|
75 connect(&mWindow, SIGNAL(currentViewChanged(HbView *)), this, SLOT(viewChanged(HbView *))); |
|
76 } |
|
77 |
|
78 void ViewManager::showView(ViewIndex viewIndex, const QVariantMap ¶ms) |
|
79 { |
|
80 MemSpyView* view; |
|
81 try { |
|
82 view = sFactories[viewIndex](mEngine, *this); |
|
83 view->initialize(params); |
|
84 } |
|
85 catch (std::exception& ex) |
|
86 { |
|
87 // show message box with exception |
|
88 // TODO: qt_symbian_exception2Error shouldn't probably be here |
|
89 QString error = tr("An error occured during the operation. Error code: %1").arg( |
|
90 qt_symbian_exception2Error(ex)); |
|
91 |
|
92 HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning); |
|
93 messageBox->setText(error); |
|
94 HbLabel *header = new HbLabel(tr("Error"), messageBox); |
|
95 messageBox->setHeadingWidget(header); |
|
96 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
97 messageBox->setTimeout(HbPopup::StandardTimeout); |
|
98 messageBox->open(); |
|
99 |
|
100 delete view; |
|
101 return; |
|
102 } |
|
103 |
|
104 if (viewIndex != MainView) { |
|
105 HbAction* action = new HbAction(Hb::BackNaviAction, this); |
|
106 connect(action, SIGNAL(triggered()), this, SLOT(goBack())); |
|
107 view->setNavigationAction(action); |
|
108 } |
|
109 |
|
110 mWindow.addView(view); |
|
111 mWindow.setCurrentView(view); |
|
112 } |
|
113 |
|
114 void ViewManager::showView(ViewIndex viewIndex) |
|
115 { |
|
116 showView(viewIndex, QVariantMap()); |
|
117 } |
|
118 |
|
119 void ViewManager::goBack() |
|
120 { |
|
121 const QList<HbView*> views = mWindow.views(); |
|
122 int index = views.indexOf(mWindow.currentView()); |
|
123 mWindow.setCurrentView(views.at(index-1), true, Hb::ViewSwitchUseBackAnim); |
|
124 } |
|
125 |
|
126 void ViewManager::viewChanged(HbView *view) |
|
127 { |
|
128 const QList<HbView*> views = mWindow.views(); |
|
129 int index = views.indexOf(view); |
|
130 for (int i=views.count()-1; i>index; i--) |
|
131 mWindow.removeView(views.at(i)); |
|
132 } |