17 * |
17 * |
18 * Description: |
18 * Description: |
19 * |
19 * |
20 */ |
20 */ |
21 |
21 |
22 #include <QDebug> |
|
23 |
|
24 #include "FileService.h" |
22 #include "FileService.h" |
25 #include <xqserviceutil.h> |
23 #include <xqserviceutil.h> |
26 #include "webpagecontroller.h" |
24 #include "webpagecontroller.h" |
27 #include "Utilities.h" |
25 #include "Utilities.h" |
28 |
26 |
29 |
27 |
30 FileService::FileService(QObject* parent) |
28 FileService::FileService(QObject* parent) |
31 : XQServiceProvider(QLatin1String("NokiaBrowser.com.nokia.symbian.IFileView"), parent) |
29 : XQServiceProvider(QLatin1String("NokiaBrowser.com.nokia.symbian.IFileView"), parent) |
32 { |
30 { |
33 qDebug("FileService::FileService"); |
|
34 publishAll(); |
31 publishAll(); |
35 } |
32 } |
36 |
33 |
37 |
34 |
38 FileService::~FileService() |
35 FileService::~FileService() |
39 { |
36 { |
40 qDebug("FileService::~FileService"); |
|
41 } |
37 } |
42 |
38 |
43 |
39 |
44 // Handles loadFinished signal emitted by WebPageController. This signal |
40 // Handles loadFinished signal emitted by WebPageController. This signal |
45 // indicates the completion of the request. |
41 // indicates the completion of the request. |
46 void FileService::completeAsyncRequest(bool ok) |
42 void FileService::completeAsyncRequest(bool ok) |
47 { |
43 { |
48 qDebug() << "FileService::complete: ok=" << ok; |
44 // completing all requests on current page load not technically correct but |
49 // Complete all |
45 // not required to service more than one request at a time |
50 foreach (quint32 reqId, mAsyncReqIds) { |
46 foreach (int reqId, mAsyncReqIds) { |
51 qDebug("FileService::complete %d", reqId); |
47 if (!completeRequest(reqId, QVariant(ok))) { |
52 completeRequest(reqId, QVariant(ok)); |
48 // failed to complete request |
|
49 RemoveAsyncReqId(); |
|
50 } |
|
51 // else remove async request ID on returnValueDelivered() signal |
53 } |
52 } |
54 |
53 |
55 // disconnect slots connected to WebPageController signals |
54 // disconnect slots connected to WebPageController signals |
56 disconnect(WebPageController::getSingleton(), 0, this, 0); |
55 disconnect(WebPageController::getSingleton(), 0, this, 0); |
57 } |
56 } |
59 |
58 |
60 // View operation / slot for non-data-caged file. |
59 // View operation / slot for non-data-caged file. |
61 bool FileService::view(QString file) |
60 bool FileService::view(QString file) |
62 { |
61 { |
63 XQRequestInfo info = requestInfo(); |
62 XQRequestInfo info = requestInfo(); |
64 qDebug() << "FileService::view(" << file << ")"; |
|
65 |
63 |
66 if (!info.isSynchronous()) { |
64 if (!info.isSynchronous()) { |
67 qDebug() << "FileService::view: Asynchronous Request"; |
65 // not required to service more than one request at a time |
|
66 // but just in case we use a map for request IDs |
|
67 // request ID needed to complete request |
68 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
68 mAsyncReqIds.insertMulti(info.clientSecureId(), setCurrentRequestAsync()); |
69 safe_connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
69 safe_connect(this, SIGNAL(returnValueDelivered()), this, SLOT(handleAnswerDelivered())); |
70 safe_connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
70 safe_connect(this, SIGNAL(clientDisconnected()), this, SLOT(handleClientDisconnect())); |
71 safe_connect(WebPageController::getSingleton(), SIGNAL(loadFinished(bool)), this, SLOT(completeAsyncRequest(bool))); |
71 safe_connect(WebPageController::getSingleton(), SIGNAL(loadFinished(bool)), this, SLOT(completeAsyncRequest(bool))); |
72 } |
72 } |
73 |
73 |
74 // Load specified file. |
74 // Load specified file in current window. |
75 file.prepend("file:///"); // create full URL from file path |
75 file.prepend("file:///"); // create full URL from file path |
76 WebPageController::getSingleton()->loadInitialUrlFromOtherApp(file); |
76 WebPageController::getSingleton()->loadInitialUrlFromOtherApp(file); |
77 |
77 |
78 return true; |
78 return true; |
79 } |
79 } |
80 |
80 |
81 |
81 |
82 // Handles clientDisconnected signal emitted by base class, XQServiceProvider. |
82 // Removes request from asynchronous IDs. This should be done after request |
83 // It's emitted if client accessing a service application terminates. |
83 // handled or on client disconnect. |
84 void FileService::handleClientDisconnect() |
84 void FileService::RemoveAsyncReqId() |
85 { |
85 { |
86 XQRequestInfo info = requestInfo(); |
86 XQRequestInfo info = requestInfo(); |
87 |
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. |
88 // Remove request from asynchronous IDs. |
93 mAsyncReqIds.remove(info.clientSecureId()); |
89 mAsyncReqIds.remove(info.clientSecureId()); |
94 |
90 |
95 // Disconnect signal from this slot if no more asynchronous requests. |
91 // Disconnect signal from this slot if no more asynchronous requests. |
96 if (!asyncAnswer()) { |
92 if (!asyncAnswer()) { |
97 // Disconnect all signals from this object to slots in this object. |
93 // Disconnect all signals from this object to slots in this object. |
98 disconnect(this, 0, this, 0); |
94 disconnect(this, 0, this, 0); |
99 } |
95 } |
100 } |
96 } |
101 |
97 |
|
98 // Handles clientDisconnected signal emitted by base class, XQServiceProvider. |
|
99 // It's emitted if client accessing a service application terminates. |
|
100 void FileService::handleClientDisconnect() |
|
101 { |
|
102 RemoveAsyncReqId(); |
|
103 } |
|
104 |
102 |
105 |
103 // Handles returnValueDelivered signal emitted by base class, XQServiceProvider. |
106 // Handles returnValueDelivered signal emitted by base class, XQServiceProvider. |
104 // It's emitted when asynchronous request has been completed and its return |
107 // It's emitted when asynchronous request has been completed and its return |
105 // value has been delivered to the service client. |
108 // value has been delivered to the service client. |
106 void FileService::handleAnswerDelivered() |
109 void FileService::handleAnswerDelivered() |
107 { |
110 { |
108 XQRequestInfo info = requestInfo(); |
111 RemoveAsyncReqId(); |
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 } |
112 } |
123 |
113 |
124 |
114 |