25 #include <QGraphicsScene> |
26 #include <QGraphicsScene> |
26 #include <QWebPage> |
27 #include <QWebPage> |
27 #include <QWebFrame> |
28 #include <QWebFrame> |
28 #include <QNetworkAccessManager> |
29 #include <QNetworkAccessManager> |
29 #include <QNetworkDiskCache> |
30 #include <QNetworkDiskCache> |
|
31 #include <QNetworkReply> |
30 #include <QDesktopServices> |
32 #include <QDesktopServices> |
31 #include <QNetworkProxyFactory> |
33 #include <QNetworkProxyFactory> |
|
34 #include <QTimer> |
32 #include <hbmessagebox.h> |
35 #include <hbmessagebox.h> |
33 #include <QFile> |
36 #include <QFile> |
34 #include <QTextStream> |
37 #include <QTextStream> |
35 |
38 #include <qsysteminfo.h> |
|
39 #include <hbmainwindow.h> |
|
40 #include <hbstyleloader.h> |
|
41 #include <hbprogressdialog.h> |
|
42 |
|
43 QTM_USE_NAMESPACE |
36 |
44 |
37 // 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. |
38 #define SHARE_INDEX_URL "qrc://shareview/index.html" |
46 #define SHARE_INDEX_URL "qrc:///shareview/index.html" |
39 |
47 |
40 #ifdef Q_OS_SYMBIAN |
48 #ifdef Q_OS_SYMBIAN |
41 // Symbian target. |
49 // Symbian target. |
42 #ifdef SHARE_PLAYER_RND |
50 #ifdef SHARE_PLAYER_RND |
43 // 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. |
44 // User must manually place index.html in the correct location. |
52 // User must manually place index.html in the correct location. |
45 // 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. |
46 #define RND_SHARE_INDEX_URL "file://e:/index.html" |
54 #define RND_SHARE_INDEX_URL "file:///f:/index.html" |
47 #define RND_SHARE_INDEX_FILE "e:\\index.html" |
55 #define RND_SHARE_INDEX_FILE "f:\\index.html" |
48 #define RND_OVI_LOGIN_FILE "e:\\ovicredentials.txt" |
56 #define RND_OVI_LOGIN_FILE "f:\\ovicredentials.txt" |
49 #define RND_DEFAULT_USER "hipsu" |
|
50 #define RND_DEFAULT_PASS "hipsupass" |
|
51 #endif |
57 #endif |
52 #else |
58 #else |
53 // Assume Windows target. |
59 // Assume Windows target. |
54 #define RND_SHARE_INDEX_URL "file://c:/temp/index.html" |
60 #define RND_SHARE_INDEX_URL "file:///c:/temp/index.html" |
55 #define RND_SHARE_INDEX_FILE "c:\\temp\\index.html" |
61 #define RND_SHARE_INDEX_FILE "c:\\temp\\index.html" |
56 #define RND_OVI_LOGIN_FILE "c:\\temp\\ovicredentials.txt" |
62 #define RND_OVI_LOGIN_FILE "c:\\temp\\ovicredentials.txt" |
57 |
63 |
58 #endif |
64 #endif |
59 |
65 |
60 // 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 */ |
61 class MpNetworkAccessManager : public QNetworkAccessManager |
79 class MpNetworkAccessManager : public QNetworkAccessManager |
62 { |
80 { |
63 public: |
81 public: |
64 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 } |
65 |
91 |
66 private: |
92 private: |
67 QNetworkReply *createRequest( Operation op, |
93 QNetworkReply* createRequest( Operation op, |
68 const QNetworkRequest &request, |
94 const QNetworkRequest &request, |
69 QIODevice *outgoingData = 0 ) |
95 QIODevice* outgoingData = 0 ) |
70 { |
96 { |
71 TX_ENTRY |
97 TX_ENTRY |
|
98 TX_LOG_ARGS( "share: createRequest URL=" << request.url().toString() ) |
|
99 |
72 QVariant val = request.attribute( QNetworkRequest::CacheLoadControlAttribute ); |
100 QVariant val = request.attribute( QNetworkRequest::CacheLoadControlAttribute ); |
73 qDebug() << "request cachecontrol - " << val.typeName() << val.toInt(); |
|
74 |
101 |
75 // Change the cache load control attrbute! |
102 // Change the cache load control attrbute! |
76 QNetworkRequest req = request; |
103 QNetworkRequest req = request; |
77 req.setAttribute( QNetworkRequest::CacheLoadControlAttribute, |
104 req.setAttribute( QNetworkRequest::CacheLoadControlAttribute, |
78 QVariant( QNetworkRequest::PreferCache ) ); // was PreferNetwork |
105 QVariant( QNetworkRequest::PreferCache ) ); |
|
106 QNetworkReply* result = QNetworkAccessManager::createRequest( op, req, outgoingData ); |
79 TX_EXIT |
107 TX_EXIT |
80 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. |
81 } |
133 } |
82 }; |
134 }; |
83 |
135 |
84 |
136 |
85 /*! |
137 /*! |
86 Constructor. |
138 Constructor. |
87 */ |
139 */ |
88 MpDetailsShareDialog::MpDetailsShareDialog() |
140 MpDetailsShareDialog::MpDetailsShareDialog() |
89 : mShareWebView( 0 ), |
141 : mShareWebView( 0 ), |
90 mShareNetAccMan( 0 ) |
142 mShareNetAccMan( 0 ), |
91 { |
143 mProgressbar ( 0 ), |
92 } |
144 mIsInitialized( false ) |
93 |
145 { |
94 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 ) |
95 { |
158 { |
96 TX_ENTRY |
159 TX_ENTRY |
97 if ( !initUser() ) |
160 if ( !initUser() ) |
98 { |
161 { |
99 emit closeShareDialog(); |
162 emit closeShareDialog(); |
100 return; |
163 return; |
101 } |
164 } |
102 initShareData( aSongData ); |
165 initShareData( aSongData, aUnknownTr ); |
|
166 initLanguage(); |
103 initNetworkAccessManager(); |
167 initNetworkAccessManager(); |
104 initWebView(); |
168 initWebView(); |
105 initSignalSlots(); |
169 initSignalSlots(); |
106 |
170 |
107 setDismissPolicy( HbDialog::NoDismiss ); |
171 setDismissPolicy( HbDialog::NoDismiss ); |
123 { |
187 { |
124 // 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. |
125 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 ) |
126 mShareWebView->load( QUrl( SHARE_INDEX_URL ) ); |
190 mShareWebView->load( QUrl( SHARE_INDEX_URL ) ); |
127 } |
191 } |
128 TX_EXIT |
192 |
129 } |
193 // Flag that the dialog is now fully initialized. |
130 |
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 } |
131 |
201 |
132 /*! |
202 /*! |
133 Destructor. |
203 Destructor. |
134 */ |
204 */ |
135 MpDetailsShareDialog::~MpDetailsShareDialog() |
205 MpDetailsShareDialog::~MpDetailsShareDialog() |
136 { |
206 { |
137 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 } |
138 logoutPlayer(); |
215 logoutPlayer(); |
139 delete mShareNetAccMan; |
216 // Probably mShareNetAccMan should not be deleted but qt documentation |
140 TX_EXIT |
217 // does not indicate whether QWebPage takes ownership of the object or not. |
141 } |
218 // See http://doc.qt.nokia.com/4.6/qwebpage.html |
142 |
219 //delete mShareNetAccMan; |
143 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 ) |
144 { |
227 { |
145 TX_ENTRY |
228 TX_ENTRY |
146 // Set information for the share data. |
229 // Set information for the share data. |
147 mShareData.setOwner( this ); |
230 mShareData.setOwner( this ); |
148 mShareData.setSongData( aSongData ); |
231 mShareData.setSongData( aSongData ); |
149 // TODO need localized error message. |
232 mShareData.setErrorMessage( tr( ERROR_MESSAGE ) ); |
150 mShareData.setErrorMessage( "An error occured. Sharing is not currently available" ); |
233 mShareData.setUnknownTr( aUnknownTr ); |
151 // TODO need language setting. |
234 TX_EXIT |
152 mShareData.setLanguage( "en" ); |
235 } |
153 TX_EXIT |
236 |
154 } |
237 /*! |
155 |
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 */ |
156 void MpDetailsShareDialog::initNetworkAccessManager() |
271 void MpDetailsShareDialog::initNetworkAccessManager() |
157 { |
272 { |
158 TX_ENTRY |
273 TX_ENTRY |
159 // 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, |
160 // since configuration for the default network access manager seems to be |
275 // since configuration for the default network access manager seems to be |
161 // to always redownload from network. |
276 // to always redownload from network. |
162 mShareNetAccMan = new MpNetworkAccessManager(); |
277 if ( !mShareNetAccMan ) |
163 mShareNetAccMan->proxyFactory()->setUseSystemConfiguration( true ); |
278 { |
164 QNetworkDiskCache* diskCache = new QNetworkDiskCache( this ); |
279 TX_LOG_ARGS( "share: construct network access manager" ) |
165 QString location = QDesktopServices::storageLocation( QDesktopServices::CacheLocation ); |
280 mShareNetAccMan = new MpNetworkAccessManager( this ); |
166 diskCache->setCacheDirectory( location ); |
281 } |
167 mShareNetAccMan->setCache( diskCache ); |
282 TX_EXIT |
168 TX_EXIT |
283 } |
169 } |
284 |
170 |
285 /*! |
|
286 Initialize the web view. |
|
287 */ |
171 void MpDetailsShareDialog::initWebView() |
288 void MpDetailsShareDialog::initWebView() |
172 { |
289 { |
173 TX_ENTRY |
290 TX_ENTRY |
174 mShareWebView = new QGraphicsWebView(); |
291 if ( !mShareWebView ) |
175 mShareWebView->settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true ); |
292 { |
176 mShareWebView->settings()->setAttribute( QWebSettings::LocalStorageDatabaseEnabled, true ); |
293 TX_LOG_ARGS( "share: construct share web view" ) |
177 mShareWebView->settings()->enablePersistentStorage(); |
294 mShareWebView = new MpShareWebView( this ); |
178 mShareWebView->page()->setNetworkAccessManager( mShareNetAccMan ); |
295 mShareWebView->page()->setNetworkAccessManager( mShareNetAccMan ); |
179 setContentWidget( mShareWebView ); |
296 mShareWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
180 TX_EXIT |
297 mShareWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded); |
181 } |
298 setContentWidget( mShareWebView ); |
182 |
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 */ |
183 void MpDetailsShareDialog::initSignalSlots() |
309 void MpDetailsShareDialog::initSignalSlots() |
184 { |
310 { |
185 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 |
186 // Connect various signals to slots for interface to webview. |
317 // Connect various signals to slots for interface to webview. |
187 connect( mShareWebView, SIGNAL( loadFinished( bool ) ), SLOT( onIndexLoad( bool ) ) ); |
318 connect( mShareWebView, SIGNAL( loadFinished( bool ) ), SLOT( onIndexLoad( bool ) ) ); |
188 connect( mShareWebView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ), this, SLOT( addContext() ) ); |
319 connect( mShareWebView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ), this, SLOT( addContext() ) ); |
189 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() ) ); |
190 TX_EXIT |
322 TX_EXIT |
191 } |
323 } |
192 |
324 |
193 /*! |
325 /*! |
194 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. |
231 TX_EXIT |
362 TX_EXIT |
232 return result; |
363 return result; |
233 } |
364 } |
234 |
365 |
235 /*! |
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 /*! |
236 Release resources from share player. |
401 Release resources from share player. |
237 */ |
402 */ |
238 void MpDetailsShareDialog::logoutPlayer() |
403 void MpDetailsShareDialog::logoutPlayer() |
239 { |
404 { |
240 TX_ENTRY |
405 TX_ENTRY |
241 if (mShareWebView) |
406 if ( mShareWebView ) |
242 { |
407 { |
243 mShareWebView->page()->mainFrame()->evaluateJavaScript( "music.teardown();" ); |
408 mShareWebView->page()->mainFrame()->evaluateJavaScript( "music.teardown();" ); |
244 } |
409 } |
245 TX_EXIT |
410 TX_EXIT |
246 } |
411 } |