|
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 <qdebug.h> |
|
19 #include <qset.h> |
|
20 #include <qstring.h> |
|
21 #include <hblistview.h> |
|
22 #include <hbmenu.h> |
|
23 |
|
24 #include "videocollectioncommon.h" |
|
25 #include "videocollectionuiloader.h" |
|
26 #include "videocollectionuiloaderdef.h" |
|
27 #include "videolistview.h" |
|
28 #include "videolistwidget.h" |
|
29 #include "videohintwidget.h" |
|
30 #include "videolistselectiondialog.h" |
|
31 #include "videocollectionwrapper.h" |
|
32 |
|
33 #include "videocollectionuiloaderdata.h" |
|
34 |
|
35 bool VideoCollectionUiLoaderData::mFindFailure = false; |
|
36 bool VideoCollectionUiLoaderData::mFailDialogLoad = false; |
|
37 QStringList VideoCollectionUiLoaderData::mFindFailureNameList; |
|
38 QMap<VideoCollectionUiLoader::ActionIds, HbAction*> VideoCollectionUiLoaderData::mMenuActions; |
|
39 int VideoCollectionUiLoaderData::mLastLoadPhasedData = -1; |
|
40 |
|
41 VideoCollectionUiLoader::VideoCollectionUiLoader(): |
|
42 HbDocumentLoader(), |
|
43 mTimerId(0), |
|
44 mIsService(0) |
|
45 { |
|
46 // not stubbed |
|
47 } |
|
48 |
|
49 VideoCollectionUiLoader::~VideoCollectionUiLoader() |
|
50 { |
|
51 VideoCollectionUiLoaderData::reset(); |
|
52 } |
|
53 |
|
54 void VideoCollectionUiLoader::loadPhase(int loadPhase) |
|
55 { |
|
56 VideoCollectionUiLoaderData::mLastLoadPhasedData = loadPhase; |
|
57 } |
|
58 |
|
59 void VideoCollectionUiLoader::addData(QList<VideoCollectionUiLoaderParam> params, |
|
60 QObject *receiver, |
|
61 const char *slot) |
|
62 { |
|
63 Q_UNUSED(params); |
|
64 Q_UNUSED(receiver); |
|
65 Q_UNUSED(slot); |
|
66 } |
|
67 |
|
68 void VideoCollectionUiLoader::removeOrphanFromList(QObject *object) |
|
69 { |
|
70 if (mOrphans.contains(object)) |
|
71 { |
|
72 mOrphans.removeOne(object); |
|
73 } |
|
74 |
|
75 const QString &name = mObjects.key(object); |
|
76 if (!name.isEmpty()) |
|
77 { |
|
78 // found from list, remove |
|
79 mObjects.remove(name); |
|
80 } |
|
81 } |
|
82 |
|
83 void VideoCollectionUiLoader::setIsService(bool isService) |
|
84 { |
|
85 mIsService = isService; |
|
86 } |
|
87 |
|
88 void VideoCollectionUiLoader::load(const QString &fileName, bool *ok) |
|
89 { |
|
90 QObjectList list = HbDocumentLoader::load(fileName, ok); |
|
91 storeOrphans(list); |
|
92 } |
|
93 |
|
94 void VideoCollectionUiLoader::load(const QString &fileName, const QString §ion , bool *ok) |
|
95 { |
|
96 QObjectList list = HbDocumentLoader::load(fileName, section, ok); |
|
97 storeOrphans(list); |
|
98 } |
|
99 |
|
100 QGraphicsWidget* VideoCollectionUiLoader::doFindWidget(const QString &name, bool loadIfNotFound) |
|
101 { |
|
102 Q_UNUSED(loadIfNotFound); |
|
103 QGraphicsWidget *widget = 0; |
|
104 if(VideoCollectionUiLoaderData::mFindFailure) |
|
105 { |
|
106 return 0; |
|
107 } |
|
108 if(!VideoCollectionUiLoaderData::mFindFailureNameList.contains(name)) |
|
109 { |
|
110 widget = HbDocumentLoader::findWidget(name); |
|
111 } |
|
112 return widget; |
|
113 } |
|
114 |
|
115 QObject* VideoCollectionUiLoader::doFindObject(const QString &name, bool loadIfNotFound) |
|
116 { |
|
117 Q_UNUSED(loadIfNotFound); |
|
118 QObject *object = 0; |
|
119 if(VideoCollectionUiLoaderData::mFindFailure) |
|
120 { |
|
121 return 0; |
|
122 } |
|
123 if(!VideoCollectionUiLoaderData::mFindFailureNameList.contains(name)) |
|
124 { |
|
125 object = HbDocumentLoader::findObject(name); |
|
126 } |
|
127 return object; |
|
128 } |
|
129 |
|
130 void VideoCollectionUiLoader::initObject(QObject *object, |
|
131 const QString &name) |
|
132 { |
|
133 VideoCollectionWrapper &wrapper = VideoCollectionWrapper::instance(); |
|
134 |
|
135 if (name == DOCML_NAME_VC_VIDEOLISTWIDGET || |
|
136 name == DOCML_NAME_VC_COLLECTIONWIDGET || |
|
137 name == DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) |
|
138 { |
|
139 VideoCollectionCommon::TModelType type = VideoCollectionCommon::EModelTypeAllVideos; |
|
140 if(name == DOCML_NAME_VC_COLLECTIONWIDGET) { |
|
141 type = VideoCollectionCommon::EModelTypeCollections; |
|
142 } else if (name == DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) { |
|
143 type = VideoCollectionCommon::EModelTypeCollectionContent; |
|
144 } |
|
145 VideoListWidget *videoList = qobject_cast<VideoListWidget*>(object); |
|
146 VideoSortFilterProxyModel *model = wrapper.getModel(type); |
|
147 |
|
148 VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelInvalid; |
|
149 if(name == DOCML_NAME_VC_VIDEOLISTWIDGET ) |
|
150 { |
|
151 level = VideoCollectionCommon::ELevelVideos; |
|
152 } |
|
153 else if(name == DOCML_NAME_VC_COLLECTIONWIDGET) |
|
154 { |
|
155 level = VideoCollectionCommon::ELevelCategory; |
|
156 } |
|
157 videoList->initialize(*model, 0, level); |
|
158 } |
|
159 else if (name == DOCML_NAME_DIALOG) |
|
160 { |
|
161 |
|
162 } |
|
163 else if (name == DOCML_NAME_VC_VIDEOHINTWIDGET) |
|
164 { |
|
165 |
|
166 } |
|
167 else if (name == DOCML_NAME_OPTIONS_MENU) |
|
168 { |
|
169 |
|
170 } |
|
171 else if (name == DOCML_NAME_SORT_MENU) |
|
172 { |
|
173 VideoCollectionUiLoaderData::mMenuActions[EActionSortBy] = qobject_cast<HbAction*>(object); |
|
174 } |
|
175 else if(name == DOCML_NAME_ADD_TO_COLLECTION) |
|
176 { |
|
177 VideoCollectionUiLoaderData::mMenuActions[EActionAddToCollection] = qobject_cast<HbAction*>(object); |
|
178 } |
|
179 else if(name == DOCML_NAME_CREATE_COLLECTION) |
|
180 { |
|
181 VideoCollectionUiLoaderData::mMenuActions[EActionNewCollection] = qobject_cast<HbAction*>(object); |
|
182 } |
|
183 else if(name == DOCML_NAME_DELETE_MULTIPLE) |
|
184 { |
|
185 VideoCollectionUiLoaderData::mMenuActions[EActionDelete] = qobject_cast<HbAction*>(object); |
|
186 } |
|
187 else if(name == DOCML_NAME_SORT_BY_DATE) |
|
188 { |
|
189 VideoCollectionUiLoaderData::mMenuActions[EActionSortByDate] = qobject_cast<HbAction*>(object); |
|
190 } |
|
191 else if(name == DOCML_NAME_SORT_BY_NAME) |
|
192 { |
|
193 VideoCollectionUiLoaderData::mMenuActions[EActionSortByName] = qobject_cast<HbAction*>(object); |
|
194 } |
|
195 else if(name == DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS) |
|
196 { |
|
197 VideoCollectionUiLoaderData::mMenuActions[EACtionSortByItemCount] = qobject_cast<HbAction*>(object); |
|
198 } |
|
199 else if(name == DOCML_NAME_SORT_BY_SIZE) |
|
200 { |
|
201 VideoCollectionUiLoaderData::mMenuActions[EActionSortBySize] = qobject_cast<HbAction*>(object); |
|
202 } |
|
203 } |
|
204 |
|
205 void VideoCollectionUiLoader::timerEvent(QTimerEvent *event) |
|
206 { |
|
207 Q_UNUSED(event); |
|
208 // not stubbed |
|
209 } |
|
210 |
|
211 QObject* VideoCollectionUiLoader::createObject(const QString& type, |
|
212 const QString &name) |
|
213 { |
|
214 QObject* object = doFindObject(name, true); |
|
215 if (!object) |
|
216 { |
|
217 if (name == DOCML_NAME_VIEW) |
|
218 { |
|
219 object = new VideoListView(this); |
|
220 } |
|
221 else if (name == DOCML_NAME_VC_COLLECTIONWIDGET || |
|
222 name == DOCML_NAME_VC_COLLECTIONCONTENTWIDGET || |
|
223 name == DOCML_NAME_VC_VIDEOLISTWIDGET) |
|
224 { |
|
225 object = new VideoListWidget(this); |
|
226 initObject(qobject_cast<QGraphicsWidget*>(object), name); |
|
227 } |
|
228 else if (name == DOCML_NAME_DIALOG) |
|
229 { |
|
230 if(!VideoCollectionUiLoaderData::mFailDialogLoad) |
|
231 { |
|
232 object = new VideoListSelectionDialog(this); |
|
233 } |
|
234 else |
|
235 { |
|
236 return 0; |
|
237 } |
|
238 } |
|
239 else if (name == DOCML_NAME_VC_VIDEOHINTWIDGET) |
|
240 { |
|
241 object = new VideoHintWidget(this); |
|
242 } |
|
243 if (object) |
|
244 { |
|
245 object->setObjectName(name); |
|
246 return object; |
|
247 } |
|
248 object = HbDocumentLoader::createObject(type, name); |
|
249 initObject(object, name); |
|
250 } |
|
251 |
|
252 return object; |
|
253 } |
|
254 |
|
255 void VideoCollectionUiLoader::runNext() |
|
256 { |
|
257 // not stubbed |
|
258 } |
|
259 |
|
260 bool VideoCollectionUiLoader::isValid(const VideoCollectionUiLoaderParam ¶m) |
|
261 { |
|
262 Q_UNUSED(param); |
|
263 // not stubbed |
|
264 return true; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // storeOrphans |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void VideoCollectionUiLoader::storeOrphans(const QObjectList &list) |
|
272 { |
|
273 foreach (QObject *object, list) |
|
274 { |
|
275 if (!mOrphans.contains(object)) |
|
276 { |
|
277 // add to list |
|
278 mOrphans.append(object); |
|
279 |
|
280 // connect to "destroyed" signal |
|
281 connect( |
|
282 object, SIGNAL(destroyed(QObject*)), |
|
283 this, SLOT(removeOrphanFromList(QObject*))); |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 // end of file |