|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbapplication.h> |
|
19 #include <hbview.h> |
|
20 #include <hbmenu.h> |
|
21 #include <hbaction.h> |
|
22 #include <hbtoolbar.h> |
|
23 #include <hbstyleloader.h> |
|
24 |
|
25 #include <QtDebug> |
|
26 #include <Qt> |
|
27 #include <qstringlist.h> |
|
28 #include <qmessagebox.h> |
|
29 |
|
30 #include <glxmediamodel.h> |
|
31 #include <glxviewsfactory.h> |
|
32 #include <glxviewids.h> |
|
33 #include <glxview.h> |
|
34 #include <glxgridview.h> |
|
35 #include <glxmodelparm.h> |
|
36 #include <glxaiwservicehandler.h> |
|
37 #include <glxcollectionpluginall.hrh> |
|
38 #include <glxcollectionpluginimageviewer.hrh> |
|
39 #include <xqserviceutil.h> |
|
40 #include <glxstatemanager.h> |
|
41 #include <glximageviewermanager.h> |
|
42 #include <glxexternalutility.h> |
|
43 #include "glxlocalisationstrings.h" |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // GlxAiwServiceHandler() |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 GlxAiwServiceHandler::GlxAiwServiceHandler() : |
|
50 HbMainWindow(), mModel(NULL), mView(NULL), mService(NULL), |
|
51 mStateMgr(NULL),mFSView(NULL),mFetcherContextMenu(NULL) |
|
52 { |
|
53 mService = new GlxGetImageService(this); |
|
54 mImageViewerService = new GlxImageViewerService(this); |
|
55 |
|
56 #ifdef _DEBUG |
|
57 QString t; |
|
58 QStringList args = QApplication::arguments(); |
|
59 foreach (QString arg, args) |
|
60 { |
|
61 t += "GlxAiwServiceHandler::cmdline arg=" + arg + "\n"; |
|
62 } |
|
63 qDebug()<< t; |
|
64 #endif |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // ~GlxAiwServiceHandler() |
|
69 // ---------------------------------------------------------------------------- |
|
70 // |
|
71 GlxAiwServiceHandler::~GlxAiwServiceHandler() |
|
72 { |
|
73 HbStyleLoader::unregisterFilePath(":/data/photos.css"); |
|
74 if (mView) |
|
75 { |
|
76 removeView(mView); |
|
77 } |
|
78 delete mView; |
|
79 delete mFSView; |
|
80 delete mModel; |
|
81 delete mService; |
|
82 } |
|
83 |
|
84 void GlxAiwServiceHandler::handleClientDisconnect() |
|
85 { |
|
86 // Just quit application |
|
87 qApp->quit(); |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // itemSelected() |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 void GlxAiwServiceHandler::itemSelected(const QModelIndex & index) |
|
95 { |
|
96 qDebug() << "GlxFetcher::itemSelected"; |
|
97 if (mService->isActive()) |
|
98 { |
|
99 qDebug() << "GlxFetcher::itemSelected :: SERVICE ACTIVE"; |
|
100 QVariant variant = mModel->data(index, GlxUriRole); |
|
101 if (variant.isValid()) |
|
102 { |
|
103 QString itemPath = variant.value<QString> (); |
|
104 qDebug() << "GlxFetcher::itemSelected :: VALID URI -->" << itemPath; |
|
105 QStringList list = (QStringList() << itemPath); |
|
106 mService->complete(list); |
|
107 } |
|
108 } |
|
109 } |
|
110 |
|
111 |
|
112 |
|
113 void GlxAiwServiceHandler::launchFetcher() |
|
114 { |
|
115 HbStyleLoader::registerFilePath(":/data/photos.css"); |
|
116 GlxModelParm modelParm(KGlxCollectionPluginAllImplementationUid, 0); |
|
117 mModel = new GlxMediaModel(modelParm); |
|
118 |
|
119 if ( this->orientation() == Qt::Horizontal ) { |
|
120 mModel->setData(QModelIndex(), (int)GlxContextLsFs, GlxContextRole ); |
|
121 } |
|
122 else { |
|
123 mModel->setData(QModelIndex(), (int)GlxContextPtFs, GlxContextRole ); |
|
124 } |
|
125 |
|
126 mView = GlxViewsFactory::createView(GLX_GRIDVIEW_ID, this); |
|
127 mView->activate(); |
|
128 mView->setModel(mModel); |
|
129 addView(mView); |
|
130 connect(mView, SIGNAL(gridItemSelected(const QModelIndex &)), this, |
|
131 SLOT( itemSelected(const QModelIndex &))); |
|
132 |
|
133 connect ( mView, SIGNAL(itemSpecificMenuTriggered(qint32,QPointF ) ), |
|
134 this, SLOT( itemSpecificMenuTriggered(qint32,QPointF ) ), |
|
135 Qt::QueuedConnection ); |
|
136 } |
|
137 |
|
138 void GlxAiwServiceHandler::itemSpecificMenuTriggered(qint32 viewId,QPointF pos) |
|
139 { |
|
140 mFetcherContextMenu = new HbMenu(); |
|
141 HbAction *action = mFetcherContextMenu->addAction(GLX_MENU_OPEN); |
|
142 connect(action, SIGNAL(triggered()), this, SLOT(openFSView())); |
|
143 connect(this, SIGNAL(aboutToChangeOrientation ()), mFetcherContextMenu, SLOT(close())); |
|
144 connect( mFetcherContextMenu, SIGNAL( aboutToClose () ), this, SLOT( closeContextMenu() ) ); |
|
145 mFetcherContextMenu->setPreferredPos( pos ); |
|
146 mFetcherContextMenu->show(); |
|
147 } |
|
148 |
|
149 void GlxAiwServiceHandler::closeContextMenu() |
|
150 { |
|
151 disconnect( this, SIGNAL( aboutToChangeOrientation () ), mFetcherContextMenu, SLOT( close() ) ); |
|
152 disconnect( mFetcherContextMenu, SIGNAL( aboutToClose () ), this, SLOT( closeContextMenu() ) ); |
|
153 mFetcherContextMenu->deleteLater(); |
|
154 mFetcherContextMenu = NULL; |
|
155 } |
|
156 |
|
157 void GlxAiwServiceHandler::openFSView() |
|
158 { |
|
159 HbAction* selectAction = new HbAction(GLX_BUTTON_SELECT); |
|
160 connect(selectAction, SIGNAL(triggered()), this, SLOT(handleFSSelect())); |
|
161 HbToolBar* toolBar = new HbToolBar(); |
|
162 toolBar->setOrientation( Qt::Horizontal ); |
|
163 toolBar->setVisible(true); |
|
164 toolBar->addAction(selectAction); |
|
165 |
|
166 mModel->setData( QModelIndex(), FETCHER_S, GlxSubStateRole ); |
|
167 mFSView = GlxViewsFactory::createView(GLX_FULLSCREENVIEW_ID, this); |
|
168 //ownership transfered to view |
|
169 mFSView->setToolBar(toolBar); |
|
170 mFSView->activate(); |
|
171 mFSView->setModel(mModel); |
|
172 addView(mFSView); |
|
173 setCurrentView(mFSView,false); |
|
174 } |
|
175 |
|
176 |
|
177 void GlxAiwServiceHandler::handleFSSelect() |
|
178 { |
|
179 QModelIndex selectedIndex = mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0); |
|
180 itemSelected(selectedIndex); |
|
181 } |
|
182 |
|
183 void GlxAiwServiceHandler::launchImageViewer() |
|
184 { |
|
185 qApp->setApplicationName("Image Viewer"); |
|
186 GlxExternalUtility* util = GlxExternalUtility::instance(); |
|
187 util->setMainWindow(this); |
|
188 delete mStateMgr; |
|
189 mStateMgr = NULL; |
|
190 mStateMgr = new GlxStateManager(); |
|
191 mStateMgr->launchFromExternal(); |
|
192 if (mImageViewerService && mImageViewerService->asyncRequest()) |
|
193 { |
|
194 connect(mImageViewerService, SIGNAL(returnValueDelivered()), this, |
|
195 SLOT(handleAnswerDelivered())); |
|
196 mImageViewerService->complete(true); |
|
197 } |
|
198 return; |
|
199 } |
|
200 // ---------------------------------------------------------------------------- |
|
201 // GlxGetImageService() |
|
202 // ---------------------------------------------------------------------------- |
|
203 // |
|
204 GlxGetImageService::GlxGetImageService(GlxAiwServiceHandler* parent) : |
|
205 XQServiceProvider( |
|
206 QLatin1String("com.nokia.services.media.Image"), parent), |
|
207 mServiceApp(parent) |
|
208 { |
|
209 mImageRequestIndex = -1; |
|
210 publishAll(); |
|
211 connect(this, SIGNAL(clientDisconnected()), mServiceApp, |
|
212 SLOT(handleClientDisconnect())); |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------------------------------- |
|
216 // ~GlxGetImageService() |
|
217 // ---------------------------------------------------------------------------- |
|
218 // |
|
219 GlxGetImageService::~GlxGetImageService() |
|
220 { |
|
221 } |
|
222 |
|
223 // ---------------------------------------------------------------------------- |
|
224 // fetchFailed() |
|
225 // ---------------------------------------------------------------------------- |
|
226 // |
|
227 void GlxGetImageService::fetchFailed(int errorCode) |
|
228 { |
|
229 QStringList filesList; |
|
230 filesList.insert(0, QString::number(errorCode));//result |
|
231 doComplete(filesList); |
|
232 } |
|
233 |
|
234 // ---------------------------------------------------------------------------- |
|
235 // complete() |
|
236 // ---------------------------------------------------------------------------- |
|
237 // |
|
238 void GlxGetImageService::complete(QStringList filesList) |
|
239 { |
|
240 doComplete(filesList); |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // doComplete() |
|
245 // ---------------------------------------------------------------------------- |
|
246 // |
|
247 void GlxGetImageService::doComplete(QStringList filesList) |
|
248 { |
|
249 if (isActive()) |
|
250 { |
|
251 completeRequest(mImageRequestIndex, filesList); |
|
252 mImageRequestIndex = -1; |
|
253 connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit())); |
|
254 } |
|
255 } |
|
256 |
|
257 // ---------------------------------------------------------------------------- |
|
258 // isActive() |
|
259 // ---------------------------------------------------------------------------- |
|
260 // |
|
261 bool GlxGetImageService::isActive() |
|
262 { |
|
263 return mImageRequestIndex > -1; |
|
264 } |
|
265 |
|
266 // ---------------------------------------------------------------------------- |
|
267 // fetch() |
|
268 // ---------------------------------------------------------------------------- |
|
269 // |
|
270 void GlxGetImageService::fetch(QVariantMap filter, QVariant flag) |
|
271 { |
|
272 Q_UNUSED(filter) |
|
273 Q_UNUSED(flag) |
|
274 mImageRequestIndex = setCurrentRequestAsync(); |
|
275 mServiceApp->launchFetcher(); |
|
276 } |
|
277 |
|
278 // ----------GlxImageViewerService--------------- |
|
279 |
|
280 GlxImageViewerService::GlxImageViewerService(GlxAiwServiceHandler* parent) : |
|
281 XQServiceProvider(QLatin1String( |
|
282 "com.nokia.services.media.com.nokia.symbian.IFileView"), parent), |
|
283 mServiceApp(parent), mAsyncReqId(-1), mAsyncRequest(false), |
|
284 mImageViewerInstance(NULL) |
|
285 |
|
286 { |
|
287 publishAll(); |
|
288 connect(this, SIGNAL(clientDisconnected()), mServiceApp, |
|
289 SLOT(handleClientDisconnect())); |
|
290 } |
|
291 |
|
292 GlxImageViewerService::~GlxImageViewerService() |
|
293 { |
|
294 if (mImageViewerInstance) |
|
295 { |
|
296 mImageViewerInstance->Close(); |
|
297 } |
|
298 } |
|
299 |
|
300 void GlxImageViewerService::complete(bool ok) |
|
301 { |
|
302 if (mAsyncReqId == -1) |
|
303 return; |
|
304 completeRequest(mAsyncReqId, QVariant(ok)); |
|
305 } |
|
306 |
|
307 bool GlxImageViewerService::view(QString file) |
|
308 { |
|
309 XQRequestInfo info = requestInfo(); |
|
310 mAsyncRequest = !info.isSynchronous(); |
|
311 if (!mImageViewerInstance) |
|
312 { |
|
313 mImageViewerInstance = CGlxImageViewerManager::InstanceL(); |
|
314 } |
|
315 file.replace(QString("/"), QString("\\")); |
|
316 TPtrC16 str(reinterpret_cast<const TUint16*> (file.utf16())); |
|
317 HBufC* uri = str.Alloc(); |
|
318 |
|
319 mImageViewerInstance->SetImageUriL(*uri); |
|
320 if (mAsyncRequest) |
|
321 { |
|
322 mAsyncReqId = setCurrentRequestAsync(); |
|
323 } |
|
324 mServiceApp->launchImageViewer(); |
|
325 return true; |
|
326 } |
|
327 |
|
328 bool GlxImageViewerService::view(XQSharableFile sf) |
|
329 { |
|
330 if (!mImageViewerInstance) |
|
331 { |
|
332 mImageViewerInstance = CGlxImageViewerManager::InstanceL(); |
|
333 } |
|
334 RFile file; |
|
335 bool ok = sf.getHandle(file); |
|
336 if (ok) |
|
337 { |
|
338 mImageViewerInstance->SetImageFileHandleL(file); |
|
339 sf.close(); |
|
340 } |
|
341 mServiceApp->launchImageViewer(); |
|
342 mAsyncRequest = !XQServiceUtil::isEmbedded(); |
|
343 |
|
344 if (mAsyncRequest) |
|
345 { |
|
346 mAsyncReqId = setCurrentRequestAsync(); |
|
347 connect(this, SIGNAL(clientDisconnected()), this, |
|
348 SLOT(handleClientDisconnect())); |
|
349 } |
|
350 return true; |
|
351 } |
|
352 |
|
353 |
|
354 |