9 #include <QGraphicsScene> |
26 #include <QGraphicsScene> |
10 #include <QWebPage> |
27 #include <QWebPage> |
11 #include <QWebFrame> |
28 #include <QWebFrame> |
12 #include <QNetworkAccessManager> |
29 #include <QNetworkAccessManager> |
13 #include <QNetworkDiskCache> |
30 #include <QNetworkDiskCache> |
|
31 #include <QNetworkReply> |
14 #include <QDesktopServices> |
32 #include <QDesktopServices> |
15 #include <QNetworkProxyFactory> |
33 #include <QNetworkProxyFactory> |
|
34 #include <QTimer> |
16 #include <hbmessagebox.h> |
35 #include <hbmessagebox.h> |
17 #include <QFile> |
36 #include <QFile> |
18 #include <QTextStream> |
37 #include <QTextStream> |
19 |
38 #include <qsysteminfo.h> |
|
39 #include <hbmainwindow.h> |
|
40 #include <hbstyleloader.h> |
|
41 #include <hbprogressdialog.h> |
|
42 |
|
43 QTM_USE_NAMESPACE |
20 |
44 |
21 // SHARE_INDEX_FILE defines where the index.html file is loaded from. |
45 // SHARE_INDEX_FILE defines where the index.html file is loaded from. |
22 #define SHARE_INDEX_URL "qrc:///shareview/index.html" |
46 #define SHARE_INDEX_URL "qrc:///shareview/index.html" |
23 |
47 |
24 #ifdef Q_OS_SYMBIAN |
48 #ifdef Q_OS_SYMBIAN |
25 // Symbian target. |
49 // Symbian target. |
26 #ifdef SHARE_PLAYER_RND |
50 #ifdef SHARE_PLAYER_RND |
27 // For R&D testing, index.html may be loaded from E: drive. |
51 // For R&D testing, index.html may be loaded from E: drive. |
28 // User must manually place index.html in the correct location. |
52 // User must manually place index.html in the correct location. |
29 // If the RND file does not exist, then SHARE_INDEX_URL will be used. |
53 // If the RND file does not exist, then SHARE_INDEX_URL will be used. |
30 #define RND_SHARE_INDEX_URL "file:///e:/index.html" |
54 #define RND_SHARE_INDEX_URL "file:///f:/index.html" |
31 #define RND_SHARE_INDEX_FILE "e:\\index.html" |
55 #define RND_SHARE_INDEX_FILE "f:\\index.html" |
32 #define RND_OVI_LOGIN_FILE "e:\\ovicredentials.txt" |
56 #define RND_OVI_LOGIN_FILE "f:\\ovicredentials.txt" |
33 #define RND_DEFAULT_USER "hipsu" |
|
34 #define RND_DEFAULT_PASS "hipsupass" |
|
35 #endif |
57 #endif |
36 #else |
58 #else |
37 // Assume Windows target. |
59 // Assume Windows target. |
38 #define RND_SHARE_INDEX_URL "file:///c:/temp/index.html" |
60 #define RND_SHARE_INDEX_URL "file:///c:/temp/index.html" |
39 #define RND_SHARE_INDEX_FILE "c:\\temp\\index.html" |
61 #define RND_SHARE_INDEX_FILE "c:\\temp\\index.html" |
40 #define RND_OVI_LOGIN_FILE "c:\\temp\\ovicredentials.txt" |
62 #define RND_OVI_LOGIN_FILE "c:\\temp\\ovicredentials.txt" |
41 |
63 |
42 #endif |
64 #endif |
43 |
65 |
44 // For allowing local caching of javascript files loaded by popup |
66 // Default language in case QSystemInfo does not work. |
|
67 #define DEFAULT_LANGUAGE "en-US" |
|
68 |
|
69 // Default error message. |
|
70 #define ERROR_MESSAGE "An error occured. Sharing is not currently available" |
|
71 |
|
72 |
|
73 /*! |
|
74 MpNetworkAccessManager allows local caching of publishing player files |
|
75 in order to minimize network traffic. |
|
76 The files will be cached to the private directory of the application, |
|
77 i.e. in the music player's case, this is C:\Private\10207C62\Cache. |
|
78 */ |
45 class MpNetworkAccessManager : public QNetworkAccessManager |
79 class MpNetworkAccessManager : public QNetworkAccessManager |
46 { |
80 { |
47 public: |
81 public: |
48 MpNetworkAccessManager() { }; |
82 MpNetworkAccessManager( QObject* parent = 0 ) |
|
83 : QNetworkAccessManager( parent ) |
|
84 { |
|
85 proxyFactory()->setUseSystemConfiguration( true ); |
|
86 QNetworkDiskCache* diskCache = new QNetworkDiskCache( this ); |
|
87 QString location = QDesktopServices::storageLocation( QDesktopServices::CacheLocation ); |
|
88 diskCache->setCacheDirectory( location ); |
|
89 setCache( diskCache ); |
|
90 } |
49 |
91 |
50 private: |
92 private: |
51 QNetworkReply *createRequest( Operation op, |
93 QNetworkReply* createRequest( Operation op, |
52 const QNetworkRequest &request, |
94 const QNetworkRequest &request, |
53 QIODevice *outgoingData = 0 ) |
95 QIODevice* outgoingData = 0 ) |
54 { |
96 { |
55 TX_ENTRY |
97 TX_ENTRY |
|
98 TX_LOG_ARGS( "share: createRequest URL=" << request.url().toString() ) |
|
99 |
56 QVariant val = request.attribute( QNetworkRequest::CacheLoadControlAttribute ); |
100 QVariant val = request.attribute( QNetworkRequest::CacheLoadControlAttribute ); |
57 qDebug() << "request cachecontrol - " << val.typeName() << val.toInt(); |
|
58 |
101 |
59 // Change the cache load control attrbute! |
102 // Change the cache load control attrbute! |
60 QNetworkRequest req = request; |
103 QNetworkRequest req = request; |
61 req.setAttribute( QNetworkRequest::CacheLoadControlAttribute, |
104 req.setAttribute( QNetworkRequest::CacheLoadControlAttribute, |
62 QVariant( QNetworkRequest::PreferCache ) ); // was PreferNetwork |
105 QVariant( QNetworkRequest::PreferCache ) ); |
|
106 QNetworkReply* result = QNetworkAccessManager::createRequest( op, req, outgoingData ); |
63 TX_EXIT |
107 TX_EXIT |
64 return QNetworkAccessManager::createRequest( op, req, outgoingData ); |
108 return result; |
|
109 } |
|
110 }; |
|
111 |
|
112 /*! |
|
113 MpShareWebView derives from QGraphicsWebView in order to override it's |
|
114 contextMenuEvent method to prevent the background context menu from |
|
115 being displayed when user makes long click in the web view. |
|
116 */ |
|
117 class MpShareWebView : public QGraphicsWebView |
|
118 { |
|
119 public: |
|
120 MpShareWebView( QGraphicsItem * parent = 0 ) |
|
121 : QGraphicsWebView( parent ) |
|
122 { |
|
123 settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true ); |
|
124 settings()->setAttribute( QWebSettings::LocalStorageDatabaseEnabled, true ); |
|
125 settings()->enablePersistentStorage(); |
|
126 } |
|
127 |
|
128 protected: |
|
129 void contextMenuEvent( QGraphicsSceneContextMenuEvent* /*ev*/ ) // Override QGraphicsWebView::contextMenuEvent |
|
130 { |
|
131 // Fix to prevent "Stop" and "Reload" buttons in page background. |
|
132 // Do not respond to the contextMenuEvent. |
65 } |
133 } |
66 }; |
134 }; |
67 |
135 |
68 |
136 |
69 /*! |
137 /*! |
70 Constructor. |
138 Constructor. |
71 */ |
139 */ |
72 MpDetailsShareDialog::MpDetailsShareDialog() |
140 MpDetailsShareDialog::MpDetailsShareDialog() |
73 : mShareWebView( 0 ), |
141 : mShareWebView( 0 ), |
74 mShareNetAccMan( 0 ) |
142 mShareNetAccMan( 0 ), |
75 { |
143 mProgressbar ( 0 ), |
76 } |
144 mIsInitialized( false ) |
77 |
145 { |
78 void MpDetailsShareDialog::initialize( MpSongData* aSongData ) |
146 // DeleteOnClose attribute prevents crash when user presses Cancel |
|
147 // before publishing player is fully loaded. |
|
148 setAttribute( Qt::WA_DeleteOnClose, true ); |
|
149 } |
|
150 |
|
151 /*! |
|
152 Initialize the share dialog. |
|
153 When fully initialized we set our mIsInitialized flag to true. |
|
154 Our isInitialized() method can be called to determine whether |
|
155 initialization was successful. |
|
156 */ |
|
157 void MpDetailsShareDialog::initialize( MpSongData* aSongData, const QString& aUnknownTr ) |
79 { |
158 { |
80 TX_ENTRY |
159 TX_ENTRY |
81 if ( !initUser() ) |
160 if ( !initUser() ) |
82 { |
161 { |
83 emit closeShareDialog(); |
162 emit closeShareDialog(); |
84 return; |
163 return; |
85 } |
164 } |
86 initShareData( aSongData ); |
165 initShareData( aSongData, aUnknownTr ); |
|
166 initLanguage(); |
87 initNetworkAccessManager(); |
167 initNetworkAccessManager(); |
88 initWebView(); |
168 initWebView(); |
89 initSignalSlots(); |
169 initSignalSlots(); |
90 |
170 |
91 setDismissPolicy( HbDialog::NoDismiss ); |
171 setDismissPolicy( HbDialog::NoDismiss ); |
107 { |
187 { |
108 // Load the production URL from the application resources to the web view. |
188 // Load the production URL from the application resources to the web view. |
109 TX_LOG_ARGS( "share: Use QRC index.html file " << SHARE_INDEX_URL ) |
189 TX_LOG_ARGS( "share: Use QRC index.html file " << SHARE_INDEX_URL ) |
110 mShareWebView->load( QUrl( SHARE_INDEX_URL ) ); |
190 mShareWebView->load( QUrl( SHARE_INDEX_URL ) ); |
111 } |
191 } |
112 TX_EXIT |
192 |
113 } |
193 // Flag that the dialog is now fully initialized. |
114 |
194 mIsInitialized = true; |
|
195 |
|
196 // Show progress dialog in .3 second if loading not finished. |
|
197 QTimer::singleShot(300, this, SLOT(showProgressDialog())); |
|
198 |
|
199 TX_EXIT |
|
200 } |
115 |
201 |
116 /*! |
202 /*! |
117 Destructor. |
203 Destructor. |
118 */ |
204 */ |
119 MpDetailsShareDialog::~MpDetailsShareDialog() |
205 MpDetailsShareDialog::~MpDetailsShareDialog() |
120 { |
206 { |
121 TX_ENTRY |
207 TX_ENTRY |
|
208 if ( mShareData.songData() ) |
|
209 { |
|
210 // Ensure that we remove the temporary album art file when we close the dialog. |
|
211 // TODO this should be removed when base64 issue is solved. |
|
212 TX_LOG_ARGS( "share: remove album art file" ) |
|
213 mShareData.songData()->removeAlbumArtFile(); |
|
214 } |
122 logoutPlayer(); |
215 logoutPlayer(); |
123 delete mShareNetAccMan; |
216 // Probably mShareNetAccMan should not be deleted but qt documentation |
124 TX_EXIT |
217 // does not indicate whether QWebPage takes ownership of the object or not. |
125 } |
218 // See http://doc.qt.nokia.com/4.6/qwebpage.html |
126 |
219 //delete mShareNetAccMan; |
127 void MpDetailsShareDialog::initShareData( MpSongData* aSongData ) |
220 TX_EXIT |
|
221 } |
|
222 |
|
223 /*! |
|
224 Initialize share data. |
|
225 */ |
|
226 void MpDetailsShareDialog::initShareData( MpSongData* aSongData, const QString& aUnknownTr ) |
128 { |
227 { |
129 TX_ENTRY |
228 TX_ENTRY |
130 // Set information for the share data. |
229 // Set information for the share data. |
131 mShareData.setOwner( this ); |
230 mShareData.setOwner( this ); |
132 mShareData.setSongData( aSongData ); |
231 mShareData.setSongData( aSongData ); |
133 // TODO need localized error message. |
232 mShareData.setErrorMessage( tr( ERROR_MESSAGE ) ); |
134 mShareData.setErrorMessage( "An error occured. Sharing is not currently available" ); |
233 mShareData.setUnknownTr( aUnknownTr ); |
135 // TODO need language setting. |
234 TX_EXIT |
136 mShareData.setLanguage( "en" ); |
235 } |
137 TX_EXIT |
236 |
138 } |
237 /*! |
139 |
238 Initialize language. |
|
239 Language string is formatted like "en-US", where "en" is the ISO-639-1 language code, |
|
240 and "US" is the ISO-3166-1 country code. |
|
241 We use the QT Mobility API (systeminfo) to obtain the settings from the device. |
|
242 In the event that we cannot construct the QSystemInfo variable then we will fallback |
|
243 to some DEFAULT_LANGUAGE setting. |
|
244 */ |
|
245 void MpDetailsShareDialog::initLanguage() |
|
246 { |
|
247 TX_ENTRY |
|
248 // Set language string, example "en-US". |
|
249 QString language; |
|
250 QSystemInfo* sysInfo = new QSystemInfo( this ); |
|
251 if ( sysInfo ) |
|
252 { |
|
253 language += sysInfo->currentLanguage(); // ISO-639-1 language code. |
|
254 language += "-"; |
|
255 language += sysInfo->currentCountryCode(); // ISO-3166-1 country code. |
|
256 delete sysInfo; |
|
257 } |
|
258 else |
|
259 { |
|
260 // Fallback to the default language. |
|
261 language = DEFAULT_LANGUAGE; |
|
262 } |
|
263 TX_LOG_ARGS( "share: language '" << language << "'" ) |
|
264 mShareData.setLanguage( language ); |
|
265 TX_EXIT |
|
266 } |
|
267 |
|
268 /*! |
|
269 Initialize network access manager. |
|
270 */ |
140 void MpDetailsShareDialog::initNetworkAccessManager() |
271 void MpDetailsShareDialog::initNetworkAccessManager() |
141 { |
272 { |
142 TX_ENTRY |
273 TX_ENTRY |
143 // Make our own network access manager to allow JS retrieval from local cache, |
274 // Make our own network access manager to allow file retrieval from local cache, |
144 // since configuration for the default network access manager seems to be |
275 // since configuration for the default network access manager seems to be |
145 // to always redownload from network. |
276 // to always redownload from network. |
146 mShareNetAccMan = new MpNetworkAccessManager(); |
277 if ( !mShareNetAccMan ) |
147 mShareNetAccMan->proxyFactory()->setUseSystemConfiguration( true ); |
278 { |
148 QNetworkDiskCache* diskCache = new QNetworkDiskCache( this ); |
279 TX_LOG_ARGS( "share: construct network access manager" ) |
149 QString location = QDesktopServices::storageLocation( QDesktopServices::CacheLocation ); |
280 mShareNetAccMan = new MpNetworkAccessManager( this ); |
150 diskCache->setCacheDirectory( location ); |
281 } |
151 mShareNetAccMan->setCache( diskCache ); |
282 TX_EXIT |
152 TX_EXIT |
283 } |
153 } |
284 |
154 |
285 /*! |
|
286 Initialize the web view. |
|
287 */ |
155 void MpDetailsShareDialog::initWebView() |
288 void MpDetailsShareDialog::initWebView() |
156 { |
289 { |
157 TX_ENTRY |
290 TX_ENTRY |
158 mShareWebView = new QGraphicsWebView(); |
291 if ( !mShareWebView ) |
159 mShareWebView->settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true ); |
292 { |
160 mShareWebView->settings()->setAttribute( QWebSettings::LocalStorageDatabaseEnabled, true ); |
293 TX_LOG_ARGS( "share: construct share web view" ) |
161 mShareWebView->settings()->enablePersistentStorage(); |
294 mShareWebView = new MpShareWebView( this ); |
162 mShareWebView->page()->setNetworkAccessManager( mShareNetAccMan ); |
295 mShareWebView->page()->setNetworkAccessManager( mShareNetAccMan ); |
163 setContentWidget( mShareWebView ); |
296 mShareWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
164 TX_EXIT |
297 mShareWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded); |
165 } |
298 setContentWidget( mShareWebView ); |
166 |
299 addContext(); |
|
300 mProgressbar = new HbProgressDialog(HbProgressDialog::WaitDialog); |
|
301 mProgressbar->setText(tr("Loading")); |
|
302 } |
|
303 TX_EXIT |
|
304 } |
|
305 |
|
306 /*! |
|
307 Initialize signals and slots. |
|
308 */ |
167 void MpDetailsShareDialog::initSignalSlots() |
309 void MpDetailsShareDialog::initSignalSlots() |
168 { |
310 { |
169 TX_ENTRY |
311 TX_ENTRY |
|
312 // Connect various signals to slots for networking. |
|
313 connect( mShareNetAccMan, SIGNAL( sslErrors( QNetworkReply*, const QList< QSslError >& ) ), |
|
314 this, SLOT( handleRequestSSLErrors( QNetworkReply*, const QList< QSslError >& ) ) ); |
|
315 connect( mShareNetAccMan, SIGNAL( finished( QNetworkReply* ) ), this, SLOT( handleRequestFinished( QNetworkReply* ) ) ); |
|
316 |
170 // Connect various signals to slots for interface to webview. |
317 // Connect various signals to slots for interface to webview. |
171 connect( mShareWebView, SIGNAL( loadFinished( bool ) ), SLOT( onIndexLoad( bool ) ) ); |
318 connect( mShareWebView, SIGNAL( loadFinished( bool ) ), SLOT( onIndexLoad( bool ) ) ); |
172 connect( mShareWebView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ), this, SLOT( addContext() ) ); |
319 connect( mShareWebView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ), this, SLOT( addContext() ) ); |
173 connect( mShareWebView->page(), SIGNAL( windowCloseRequested() ), this, SIGNAL( closeShareDialog() ) ); |
320 connect( mShareWebView->page(), SIGNAL( windowCloseRequested() ), this, SIGNAL( closeShareDialog() ) ); |
|
321 connect( mProgressbar, SIGNAL(cancelled()), this, SIGNAL( closeShareDialog() ) ); |
174 TX_EXIT |
322 TX_EXIT |
175 } |
323 } |
176 |
324 |
177 /*! |
325 /*! |
178 initUser is used as temporary solution until Single Sign On is implemented in platform. |
326 initUser is used as temporary solution until Single Sign On is implemented in platform. |
215 TX_EXIT |
362 TX_EXIT |
216 return result; |
363 return result; |
217 } |
364 } |
218 |
365 |
219 /*! |
366 /*! |
|
367 Returns true if the dialog has been fully initialized. |
|
368 */ |
|
369 bool MpDetailsShareDialog::isInitialized() const |
|
370 { |
|
371 return mIsInitialized; |
|
372 } |
|
373 |
|
374 /*! |
|
375 Attempt to cache the publishing player files from internet |
|
376 to improve user experience for first-time use. |
|
377 If the files are already in the cache and have not expired, |
|
378 then this should not do anything. |
|
379 */ |
|
380 void MpDetailsShareDialog::cachePublishingPlayerFiles() |
|
381 { |
|
382 TX_ENTRY |
|
383 // We need the network access manager, so make sure it is initialized. |
|
384 if ( !mShareNetAccMan ) |
|
385 { |
|
386 initNetworkAccessManager(); |
|
387 } |
|
388 // Attempt to get the required publishing player files from the net in advance. |
|
389 // We don't listen to any signal that the download succeeded or failed |
|
390 // since we will let it silently fail at this stage. |
|
391 // These URLs are also included in index.html resource, and the two must |
|
392 // be kept the same. |
|
393 mShareNetAccMan->get( QNetworkRequest( QUrl( |
|
394 "http://hf.ci.wipsl.com/PleiXXPTsup/noheva-be/css/ovi.player.share.ui.css" ) ) ); |
|
395 mShareNetAccMan->get( QNetworkRequest( QUrl( |
|
396 "http://hf.ci.wipsl.com/PleiXXPTsup/noheva-be/js/publishplayer.js" ) ) ); |
|
397 TX_EXIT |
|
398 } |
|
399 |
|
400 /*! |
220 Release resources from share player. |
401 Release resources from share player. |
221 */ |
402 */ |
222 void MpDetailsShareDialog::logoutPlayer() |
403 void MpDetailsShareDialog::logoutPlayer() |
223 { |
404 { |
224 TX_ENTRY |
405 TX_ENTRY |
225 if (mShareWebView) |
406 if ( mShareWebView ) |
226 { |
407 { |
227 mShareWebView->page()->mainFrame()->evaluateJavaScript( "music.teardown();" ); |
408 mShareWebView->page()->mainFrame()->evaluateJavaScript( "music.teardown();" ); |
228 } |
409 } |
229 TX_EXIT |
410 TX_EXIT |
230 } |
411 } |