|
1 /* |
|
2 * Copyright (c) 2010 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.h> |
|
19 #include <hbdocumentloader.h> |
|
20 #include <hbaction.h> |
|
21 #include <hbmenu.h> |
|
22 |
|
23 #include "cbsuiviewmanager.h" |
|
24 #include "cbsuitopiclistview.h" |
|
25 #include "cbsuitopicview.h" |
|
26 #include "mcbs.h" |
|
27 #include "cbslog.h" |
|
28 |
|
29 const char *CBS_APP_XML = ":/xml/cbs_app.docml"; |
|
30 const char *CBS_TOPIC_VIEW_XML = ":/xml/cbs_topic_view.docml"; |
|
31 const char *CBS_MAIN_VIEW = "t:view"; |
|
32 const char *CBS_TOPIC_VIEW ="t:view2"; |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ================================================== |
|
35 // ---------------------------------------------------------------------------- |
|
36 // CbsUiViewManager::CbsUiViewManager |
|
37 // ---------------------------------------------------------------------------- |
|
38 // |
|
39 CbsUiViewManager::CbsUiViewManager(HbMainWindow *window, MCbs &server) |
|
40 :mMainWindow(window), |
|
41 mServer(server), |
|
42 mTopicListView(NULL), |
|
43 mTopicView(NULL), |
|
44 mLoader(NULL), |
|
45 mSoftKeyBackAction(NULL), |
|
46 mSoftKeyExitAction(NULL) |
|
47 { |
|
48 LOG(NORMAL,"CBSUI: CbsUiViewManager::CbsUiViewManager IN"); |
|
49 |
|
50 // SYMBIAN CODE: |
|
51 //mTopicMonitor = CCbsUiTopicListMonitor::NewL(mServer); not in use at the moment |
|
52 |
|
53 bool ok = false; |
|
54 mLoader = new CbsUiDocumentLoader(); |
|
55 // ownership of the objects are transferred to caller |
|
56 mObjects = mLoader->load(CBS_APP_XML, &ok); |
|
57 if (ok) { |
|
58 activateMainView(); |
|
59 } else { |
|
60 LOG(NORMAL,"CBSUI: CbsUiViewManager::CbsUiViewManager DocML failure!"); |
|
61 } |
|
62 |
|
63 LOG(NORMAL,"CBSUI: CbsUiViewManager::CbsUiViewManager OUT"); |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CbsUiViewManager::~CbsUiViewManager |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 CbsUiViewManager::~CbsUiViewManager() |
|
71 { |
|
72 LOG(NORMAL,"CBSUI: CbsUiViewManager::~CbsUiViewManager IN"); |
|
73 //delete mTopicMonitor; not in use at the moment |
|
74 delete mLoader; |
|
75 // delete all objects created from DocML. |
|
76 while (!mObjects.isEmpty()) { |
|
77 LOG(NORMAL,"CBSUI: CbsUiViewManager::~CbsUiViewManager deleting..."); |
|
78 delete mObjects.takeFirst(); |
|
79 } |
|
80 LOG(NORMAL,"CBSUI: CbsUiViewManager::~CbsUiViewManager OUT"); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // CbsUiViewManager::activateTopicView |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 void CbsUiViewManager::activateTopicView(TCbsTopicNumber topicNumber) |
|
88 { |
|
89 LOG(NORMAL,"CBSUI: CbsUiViewManager::activateTopicView IN"); |
|
90 if (!mTopicView) { |
|
91 bool ok = false; |
|
92 // ownership of the objects are transferred to caller |
|
93 mObjects += mLoader->load(CBS_TOPIC_VIEW_XML, &ok); |
|
94 if (ok) { |
|
95 mTopicView = |
|
96 qobject_cast<CbsUiTopicView *>(mLoader->findWidget(CBS_TOPIC_VIEW)); |
|
97 mTopicView->init(mServer, *this); |
|
98 } else { |
|
99 LOG(NORMAL,"CBSUI: CbsUiViewManager::activateTopicView DocML failure!"); |
|
100 } |
|
101 } |
|
102 |
|
103 if (mTopicView != mMainWindow->currentView()) { |
|
104 if (!mSoftKeyBackAction) { |
|
105 mSoftKeyBackAction = new HbAction(Hb::BackAction,mTopicView); |
|
106 LOG2(NORMAL,"CBSUI: CbsUiViewManager::activateTopicView \ |
|
107 mSoftKeyBackAction==%d", mSoftKeyBackAction); |
|
108 } |
|
109 |
|
110 mTopicView->reloadMessages(topicNumber); |
|
111 mMainWindow->addSoftKeyAction(Hb::SecondarySoftKey,mSoftKeyBackAction); |
|
112 bool ret = connect(mSoftKeyBackAction, SIGNAL(triggered()), |
|
113 this, SLOT(activateMainView())); |
|
114 HbView* view = mMainWindow->currentView(); |
|
115 mMainWindow->removeView(view); |
|
116 // just temp implement |
|
117 mTopicListView = 0; |
|
118 mMainWindow->addView(mTopicView); |
|
119 LOG2(NORMAL,"CBSUI: CbsUiViewManager::activateTopicView\ |
|
120 mTopicView=%d", mTopicView); |
|
121 } |
|
122 LOG(NORMAL,"CBSUI: CbsUiViewManager::activateTopicView OUT"); |
|
123 } |
|
124 |
|
125 // ---------------------------------------------------------------------------- |
|
126 // CbsUiViewManager::activateMainView |
|
127 // ---------------------------------------------------------------------------- |
|
128 // |
|
129 void CbsUiViewManager::activateMainView() |
|
130 { |
|
131 LOG(NORMAL,"CBSUI: CbsUiViewManager::activateMainView IN"); |
|
132 if (!mTopicListView) { |
|
133 // First time called |
|
134 mTopicListView = qobject_cast<CbsUiTopicListView *> |
|
135 (mLoader->findWidget(CBS_MAIN_VIEW)); |
|
136 mTopicListView->init(mServer, *this); |
|
137 // Connect signal to change view |
|
138 bool ret = connect(mTopicListView, |
|
139 SIGNAL(topicSelected(TCbsTopicNumber)), this, |
|
140 SLOT(activateTopicView(TCbsTopicNumber))); |
|
141 LOG2(NORMAL,"CBSUI: CbsUiViewManager::activateMainView ret=%d", ret); |
|
142 } else { |
|
143 HbView *view = mMainWindow->currentView(); |
|
144 mMainWindow->removeView(view); |
|
145 // just temp implement |
|
146 mTopicView = 0; |
|
147 } |
|
148 |
|
149 if (!mSoftKeyExitAction) { |
|
150 mSoftKeyExitAction = new HbAction(Hb::QuitAction, mTopicListView); |
|
151 LOG(NORMAL,"CBSUI: CbsUiViewManager::activateMainView add quit action"); |
|
152 } |
|
153 if ( mSoftKeyBackAction ) { |
|
154 mMainWindow->removeSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBackAction); |
|
155 mSoftKeyBackAction = 0; |
|
156 LOG(NORMAL,"CBSUI: CbsUiViewManager::activateMainView remove back action"); |
|
157 } |
|
158 |
|
159 mMainWindow->addSoftKeyAction(Hb::SecondarySoftKey,mSoftKeyExitAction); |
|
160 bool ret = connect(mSoftKeyExitAction, SIGNAL(triggered()), |
|
161 mMainWindow, SLOT(close())); |
|
162 LOG2(NORMAL,"CBSUI: CbsUiViewManager::activateMainView connect exit=%d", ret); |
|
163 mMainWindow->addView(mTopicListView); |
|
164 mMainWindow->setCurrentView(mTopicListView); |
|
165 LOG(NORMAL,"CBSUI: CbsUiViewManager::activateMainView OUT"); |
|
166 } |
|
167 |
|
168 // ---------------------------------------------------------------------------- |
|
169 // CbsUiDocumentLoader::createObject |
|
170 // For DocML usage: |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 QObject *CbsUiDocumentLoader::createObject( |
|
174 const QString& type, const QString &name) |
|
175 { |
|
176 LOG(NORMAL,"CBSUI: CbsUiViewManager::createObject IN"); |
|
177 if (type == CbsUiTopicListView::staticMetaObject.className()) { |
|
178 QObject *object = new CbsUiTopicListView; |
|
179 object->setObjectName(name); |
|
180 LOG(NORMAL,"CBSUI: CbsUiViewManager::createObject:CbsUiTopicListView OUT"); |
|
181 return object; |
|
182 } else if (type == CbsUiTopicView::staticMetaObject.className()) { |
|
183 QObject *object = new CbsUiTopicView; |
|
184 object->setObjectName(name); |
|
185 LOG(NORMAL,"CBSUI: CbsUiViewManager::createObject:CbsUiTopicView OUT"); |
|
186 return object; |
|
187 } |
|
188 LOG2(NORMAL,"CBSUI: CbsUiViewManager::createObject: \ |
|
189 object name = %s",name.utf16()); |
|
190 return HbDocumentLoader::createObject(type, name); |
|
191 } |
|
192 |
|
193 // End of file |