22 #include <hbview.h> |
22 #include <hbview.h> |
23 #include <hbmainwindow.h> |
23 #include <hbmainwindow.h> |
24 #include <qtcontacts.h> |
24 #include <qtcontacts.h> |
25 #include "cntviewnavigator.h" |
25 #include "cntviewnavigator.h" |
26 #include "cntsimutility.h" |
26 #include "cntsimutility.h" |
|
27 #include "cntdebug.h" |
|
28 #include <QApplication> |
27 |
29 |
28 CntDefaultViewManager::CntDefaultViewManager( HbMainWindow* aWindow ) : QObject(), |
30 CntDefaultViewManager::CntDefaultViewManager( HbMainWindow* aWindow ) : QObject(), |
29 mFactory(NULL), |
31 mFactory(NULL), |
30 mCurrent(NULL), |
32 mCurrent(NULL), |
31 mOldView(NULL), |
33 mOldView(NULL), |
32 mNavigator(NULL), |
34 mNavigator(NULL), |
33 mMainWindow( aWindow ), |
35 mMainWindow( aWindow ), |
34 mSimUtility(NULL) |
36 mSimUtility(NULL) |
35 |
37 { |
36 { |
38 CNT_ENTRY |
|
39 |
37 setViewFactory(new CntDefaultViewFactory()); |
40 setViewFactory(new CntDefaultViewFactory()); |
38 setViewNavigator(new CntViewNavigator(this)); |
41 setViewNavigator(new CntViewNavigator(this)); |
39 |
42 |
40 int error = -1; |
43 int error = -1; |
41 mSimUtility = new CntSimUtility(CntSimUtility::AdnStore, error); |
44 mSimUtility = new CntSimUtility(CntSimUtility::AdnStore, error); |
42 if (error != 0) |
45 if (error != 0) |
43 { |
46 { |
44 delete mSimUtility; |
47 delete mSimUtility; |
45 mSimUtility = 0; |
48 mSimUtility = 0; |
46 } |
49 } |
|
50 |
|
51 CNT_EXIT |
47 } |
52 } |
48 |
53 |
49 CntDefaultViewManager::~CntDefaultViewManager() |
54 CntDefaultViewManager::~CntDefaultViewManager() |
50 { |
55 { |
|
56 CNT_ENTRY |
|
57 |
|
58 cleanup(); |
|
59 |
|
60 CNT_EXIT |
|
61 } |
|
62 |
|
63 void CntDefaultViewManager::cleanup() |
|
64 { |
|
65 CNT_ENTRY |
|
66 |
|
67 mOldView = mCurrent; |
|
68 mCurrent = NULL; |
|
69 deleteOldView(); |
|
70 |
|
71 qDeleteAll(mBackends); |
|
72 mBackends.clear(); |
|
73 |
51 qDeleteAll(mDefaults.values()); |
74 qDeleteAll(mDefaults.values()); |
|
75 mDefaults.clear(); |
|
76 |
52 delete mFactory; |
77 delete mFactory; |
|
78 mFactory = NULL; |
|
79 |
53 delete mSimUtility; |
80 delete mSimUtility; |
|
81 mSimUtility = NULL; |
|
82 |
|
83 CNT_EXIT |
54 } |
84 } |
55 |
85 |
56 void CntDefaultViewManager::setViewFactory( CntAbstractViewFactory* aFactory ) |
86 void CntDefaultViewManager::setViewFactory( CntAbstractViewFactory* aFactory ) |
57 { |
87 { |
|
88 CNT_ENTRY |
|
89 |
58 if ( aFactory ) |
90 if ( aFactory ) |
59 { |
91 { |
|
92 if (mFactory) { |
|
93 delete mFactory; |
|
94 } |
60 mFactory = aFactory; |
95 mFactory = aFactory; |
61 } |
96 } |
|
97 |
|
98 CNT_EXIT |
62 } |
99 } |
63 |
100 |
64 void CntDefaultViewManager::setViewNavigator( CntViewNavigator* aNavigator ) |
101 void CntDefaultViewManager::setViewNavigator( CntViewNavigator* aNavigator ) |
65 { |
102 { |
|
103 CNT_ENTRY |
|
104 |
66 if ( aNavigator ) |
105 if ( aNavigator ) |
67 { |
106 { |
|
107 if (mNavigator) { |
|
108 delete mNavigator; |
|
109 } |
68 mNavigator = aNavigator; |
110 mNavigator = aNavigator; |
69 } |
111 } |
|
112 |
|
113 CNT_EXIT |
70 } |
114 } |
71 |
115 |
72 void CntDefaultViewManager::back(const CntViewParameters aArgs) |
116 void CntDefaultViewManager::back(const CntViewParameters aArgs) |
73 { |
117 { |
|
118 CNT_ENTRY |
|
119 |
74 mArgs.clear(); |
120 mArgs.clear(); |
75 |
121 |
76 QFlags<Hb::ViewSwitchFlag> flags; |
122 QFlags<Hb::ViewSwitchFlag> flags; |
77 int back = mNavigator->back( flags ); |
123 int back = mNavigator->back( flags ); |
78 |
124 |
88 |
134 |
89 if (mArgs.value(EViewId).toInt() != noView) |
135 if (mArgs.value(EViewId).toInt() != noView) |
90 { |
136 { |
91 switchView( mArgs, flags ); |
137 switchView( mArgs, flags ); |
92 } |
138 } |
|
139 else { |
|
140 // exiting application |
|
141 cleanup(); |
|
142 closeApp(); |
|
143 } |
|
144 |
|
145 CNT_EXIT |
|
146 } |
|
147 |
|
148 void CntDefaultViewManager::closeApp() |
|
149 { |
|
150 CNT_ENTRY |
|
151 |
|
152 qApp->quit(); |
|
153 |
|
154 CNT_EXIT |
93 } |
155 } |
94 |
156 |
95 void CntDefaultViewManager::changeView(const CntViewParameters aArgs) |
157 void CntDefaultViewManager::changeView(const CntViewParameters aArgs) |
96 { |
158 { |
|
159 CNT_ENTRY |
|
160 |
97 QFlags<Hb::ViewSwitchFlag> flags; |
161 QFlags<Hb::ViewSwitchFlag> flags; |
98 mNavigator->next(aArgs.value(EViewId).toInt(), flags); |
162 mNavigator->next(aArgs.value(EViewId).toInt(), flags); |
99 switchView(aArgs, flags); |
163 switchView(aArgs, flags); |
|
164 |
|
165 CNT_EXIT |
100 } |
166 } |
101 |
167 |
102 QContactManager* CntDefaultViewManager::contactManager( const QString& aType ) |
168 QContactManager* CntDefaultViewManager::contactManager( const QString& aType ) |
103 { |
169 { |
|
170 CNT_ENTRY |
|
171 |
104 foreach ( QContactManager* mgr, mBackends ) |
172 foreach ( QContactManager* mgr, mBackends ) |
105 { |
173 { |
106 QString uri = mgr->managerUri(); |
174 QString uri = mgr->managerUri(); |
107 if ( aType.compare(uri, Qt::CaseInsensitive) == 0 ) |
175 if ( aType.compare(uri, Qt::CaseInsensitive) == 0 ) |
108 { |
176 { |
114 if ( manager ) |
182 if ( manager ) |
115 { |
183 { |
116 mBackends.append( manager ); |
184 mBackends.append( manager ); |
117 } |
185 } |
118 |
186 |
|
187 CNT_EXIT |
119 return manager; |
188 return manager; |
120 } |
189 } |
121 |
190 |
122 void CntDefaultViewManager::removeCurrentView() |
191 void CntDefaultViewManager::removeCurrentView() |
123 { |
192 { |
|
193 CNT_ENTRY |
|
194 |
124 if (mOldView) |
195 if (mOldView) |
125 { |
196 { |
126 connect(mMainWindow, SIGNAL(viewReady()), this, SLOT(deleteOldView())); |
197 connect(mMainWindow, SIGNAL(viewReady()), this, SLOT(deleteOldView())); |
127 } |
198 } |
128 else |
199 else |
129 { |
200 { |
130 mMainWindow->setInteractive( true ); |
201 mMainWindow->setInteractive( true ); |
131 } |
202 } |
|
203 |
|
204 CNT_EXIT |
132 } |
205 } |
133 |
206 |
134 void CntDefaultViewManager::deleteOldView() |
207 void CntDefaultViewManager::deleteOldView() |
135 { |
208 { |
|
209 CNT_ENTRY |
|
210 |
136 disconnect(mMainWindow, SIGNAL(viewReady()), this, SLOT(deleteOldView())); |
211 disconnect(mMainWindow, SIGNAL(viewReady()), this, SLOT(deleteOldView())); |
137 |
212 |
138 if (mOldView) |
213 if (mOldView) |
139 { |
214 { |
140 mOldView->deactivate(); |
215 mOldView->deactivate(); |
141 |
216 |
142 // Due to something strange in wk16, this check will fail occationally and cause |
217 // Due to something strange in wk16, this check will fail occationally and cause |
143 // a memory leak... most likely when opening edit view for the first time |
218 // a memory leak... most likely when opening edit view for the first time |
144 if (!mOldView->view()->isVisible()) |
219 if (mCurrent == NULL || !mOldView->view()->isVisible()) |
145 { |
220 { |
146 mMainWindow->removeView(mOldView->view()); |
221 mMainWindow->removeView(mOldView->view()); |
147 |
222 |
148 if (!mOldView->isDefault()) |
223 if (!mOldView->isDefault()) |
149 { |
224 { |
158 } |
233 } |
159 } |
234 } |
160 } |
235 } |
161 |
236 |
162 mMainWindow->setInteractive(true); |
237 mMainWindow->setInteractive(true); |
|
238 |
|
239 CNT_EXIT |
163 } |
240 } |
164 |
241 |
165 void CntDefaultViewManager::switchView(const CntViewParameters aArgs, QFlags<Hb::ViewSwitchFlag> flags) |
242 void CntDefaultViewManager::switchView(const CntViewParameters aArgs, QFlags<Hb::ViewSwitchFlag> flags) |
166 { |
243 { |
|
244 CNT_ENTRY |
|
245 |
167 mMainWindow->setInteractive(false); |
246 mMainWindow->setInteractive(false); |
168 int id = aArgs.value(EViewId).toInt(); |
247 int id = aArgs.value(EViewId).toInt(); |
169 if ( id != noView ) |
248 if ( id != noView ) |
170 { |
249 { |
171 CntAbstractView* nextView(NULL); |
250 CntAbstractView* nextView(NULL); |