|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include <QDebug> |
|
23 |
|
24 #include "FileService.h" |
|
25 #include <xqserviceutil.h> |
|
26 #include "webpagecontroller.h" |
|
27 #include "Utilities.h" |
|
28 |
|
29 |
|
30 FileService::FileService(QObject* parent) |
|
31 : XQServiceProvider(QLatin1String("NokiaBrowser.com.nokia.symbian.IFileView"), parent) |
|
32 { |
|
33 qDebug("FileService::FileService"); |
|
34 publishAll(); |
|
35 } |
|
36 |
|
37 |
|
38 FileService::~FileService() |
|
39 { |
|
40 qDebug("FileService::~FileService"); |
|
41 } |
|
42 |
|
43 |
|
44 // Handles loadFinished signal emitted by WebPageController. This signal |
|
45 // indicates the completion of the request. |
|
46 void FileService::completeAsyncRequest(bool ok) |
|
47 { |
|
48 qDebug() << "FileService::complete: ok=" << ok; |
|
49 // Complete all |
|
50 foreach (quint32 reqId, mAsyncReqIds) { |
|
51 qDebug("FileService::complete %d", reqId); |
|
52 completeRequest(reqId, QVariant(ok)); |
|
53 } |
|
54 |
|
55 // disconnect slots connected to WebPageController signals |
|
56 disconnect(WebPageController::getSingleton(), 0, this, 0); |
|
57 } |
|
58 |
|
59 |
|
60 // View operation / slot for non-data-caged file. |
|
61 bool FileService::view(QString file) |
|
62 { |
|
63 XQRequestInfo info = requestInfo(); |
|
64 qDebug() << "FileService::view(" << file << ")"; |
|
65 |
|
66 if (!info.isSynchronous()) { |
|
67 qDebug() << "FileService::view: Asynchronous Request"; |
|
68 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
|
69 safe_connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
|
70 safe_connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
|
71 safe_connect(WebPageController::getSingleton(), SIGNAL(loadFinished(bool)), this, SLOT(completeAsyncRequest(bool))); |
|
72 } |
|
73 |
|
74 // Load specified file. |
|
75 file.prepend("file:///"); // create full URL from file path |
|
76 WebPageController::getSingleton()->loadInitialUrlFromOtherApp(file); |
|
77 |
|
78 return true; |
|
79 } |
|
80 |
|
81 |
|
82 // Handles clientDisconnected signal emitted by base class, XQServiceProvider. |
|
83 // It's emitted if client accessing a service application terminates. |
|
84 void FileService::handleClientDisconnect() |
|
85 { |
|
86 XQRequestInfo info = requestInfo(); |
|
87 |
|
88 // Output some debug info. |
|
89 qDebug("FileService::handleClientDisconnect"); |
|
90 qDebug("\tRequest info: id=%d,sid=%X,vid=%X", info.id(),info.clientSecureId(), info.clientVendorId()); |
|
91 |
|
92 // Remove request from asynchronous IDs. |
|
93 mAsyncReqIds.remove(info.clientSecureId()); |
|
94 |
|
95 // Disconnect signal from this slot if no more asynchronous requests. |
|
96 if (!asyncAnswer()) { |
|
97 // Disconnect all signals from this object to slots in this object. |
|
98 disconnect(this, 0, this, 0); |
|
99 } |
|
100 } |
|
101 |
|
102 |
|
103 // Handles returnValueDelivered signal emitted by base class, XQServiceProvider. |
|
104 // It's emitted when asynchronous request has been completed and its return |
|
105 // value has been delivered to the service client. |
|
106 void FileService::handleAnswerDelivered() |
|
107 { |
|
108 XQRequestInfo info = requestInfo(); |
|
109 |
|
110 // Output some debug info. |
|
111 qDebug("FileService::handleAnswerDelivered"); |
|
112 qDebug("\tRequest info: sid=%X,vid=%X", info.clientSecureId(), info.clientVendorId()); |
|
113 |
|
114 // Done servicing request, remove it from asynchronous IDs. |
|
115 mAsyncReqIds.remove(info.clientSecureId()); |
|
116 |
|
117 // Disconnect signal from this slot if no more asynchronous requests. |
|
118 if (!asyncAnswer()) { |
|
119 // Disconnect all signals from this object to slots in this object. |
|
120 disconnect(this, 0, this, 0); |
|
121 } |
|
122 } |
|
123 |
|
124 |