mpviewplugins/mpdetailsviewplugin/src/mpdetailssharedialog.cpp
author hgs
Fri, 11 Jun 2010 19:36:32 -0500
changeset 37 eb79a7c355bf
parent 36 a0afa279b8fe
child 45 612c4815aebe
permissions -rw-r--r--
201023
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36
hgs
parents: 35
diff changeset
     1
/*
hgs
parents: 35
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 35
diff changeset
     3
* All rights reserved.
hgs
parents: 35
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents: 35
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents: 35
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents: 35
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 35
diff changeset
     8
*
hgs
parents: 35
diff changeset
     9
* Initial Contributors:
hgs
parents: 35
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents: 35
diff changeset
    11
*
hgs
parents: 35
diff changeset
    12
* Contributors:
hgs
parents: 35
diff changeset
    13
*
hgs
parents: 35
diff changeset
    14
* Description: Implementation for share player.
hgs
parents: 35
diff changeset
    15
*
hgs
parents: 35
diff changeset
    16
*/
hgs
parents: 35
diff changeset
    17
35
hgs
parents:
diff changeset
    18
#ifdef SHARE_FUNC_ENABLED
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include "mpdetailssharedialog.h"
hgs
parents:
diff changeset
    21
#include "mpsharedata.h"
hgs
parents:
diff changeset
    22
#include "mpsongdata.h"
hgs
parents:
diff changeset
    23
#include "mptrace.h"
hgs
parents:
diff changeset
    24
#include <QObject>
hgs
parents:
diff changeset
    25
#include <QGraphicsWebView>
hgs
parents:
diff changeset
    26
#include <QGraphicsScene>
hgs
parents:
diff changeset
    27
#include <QWebPage>
hgs
parents:
diff changeset
    28
#include <QWebFrame>
hgs
parents:
diff changeset
    29
#include <QNetworkAccessManager>
hgs
parents:
diff changeset
    30
#include <QNetworkDiskCache>
36
hgs
parents: 35
diff changeset
    31
#include <QNetworkReply>
35
hgs
parents:
diff changeset
    32
#include <QDesktopServices>
hgs
parents:
diff changeset
    33
#include <QNetworkProxyFactory>
36
hgs
parents: 35
diff changeset
    34
#include <QTimer>
35
hgs
parents:
diff changeset
    35
#include <hbmessagebox.h>
hgs
parents:
diff changeset
    36
#include <QFile>
hgs
parents:
diff changeset
    37
#include <QTextStream>
36
hgs
parents: 35
diff changeset
    38
#include <qsysteminfo.h>
hgs
parents: 35
diff changeset
    39
#include <hbmainwindow.h>
hgs
parents: 35
diff changeset
    40
#include <hbstyleloader.h>
hgs
parents: 35
diff changeset
    41
#include <hbprogressdialog.h>
35
hgs
parents:
diff changeset
    42
36
hgs
parents: 35
diff changeset
    43
QTM_USE_NAMESPACE
35
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
// SHARE_INDEX_FILE defines where the index.html file is loaded from.
hgs
parents:
diff changeset
    46
#define SHARE_INDEX_URL "qrc:///shareview/index.html"
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
#ifdef Q_OS_SYMBIAN
hgs
parents:
diff changeset
    49
// Symbian target.
hgs
parents:
diff changeset
    50
#ifdef SHARE_PLAYER_RND
hgs
parents:
diff changeset
    51
// For R&D testing, index.html may be loaded from E: drive.
hgs
parents:
diff changeset
    52
// User must manually place index.html in the correct location.
hgs
parents:
diff changeset
    53
// If the RND file does not exist, then SHARE_INDEX_URL will be used.
36
hgs
parents: 35
diff changeset
    54
#define RND_SHARE_INDEX_URL "file:///f:/index.html"
hgs
parents: 35
diff changeset
    55
#define RND_SHARE_INDEX_FILE "f:\\index.html"
hgs
parents: 35
diff changeset
    56
#define RND_OVI_LOGIN_FILE "f:\\ovicredentials.txt"
35
hgs
parents:
diff changeset
    57
#endif
hgs
parents:
diff changeset
    58
#else
hgs
parents:
diff changeset
    59
// Assume Windows target.
hgs
parents:
diff changeset
    60
#define RND_SHARE_INDEX_URL "file:///c:/temp/index.html"
hgs
parents:
diff changeset
    61
#define RND_SHARE_INDEX_FILE "c:\\temp\\index.html"
hgs
parents:
diff changeset
    62
#define RND_OVI_LOGIN_FILE "c:\\temp\\ovicredentials.txt"
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
#endif
hgs
parents:
diff changeset
    65
36
hgs
parents: 35
diff changeset
    66
// Default language in case QSystemInfo does not work.
hgs
parents: 35
diff changeset
    67
#define DEFAULT_LANGUAGE "en-US"
hgs
parents: 35
diff changeset
    68
hgs
parents: 35
diff changeset
    69
// Default error message.
hgs
parents: 35
diff changeset
    70
#define ERROR_MESSAGE "An error occured. Sharing is not currently available"
hgs
parents: 35
diff changeset
    71
hgs
parents: 35
diff changeset
    72
hgs
parents: 35
diff changeset
    73
/*!
hgs
parents: 35
diff changeset
    74
 MpNetworkAccessManager allows local caching of publishing player files
hgs
parents: 35
diff changeset
    75
 in order to minimize network traffic.
hgs
parents: 35
diff changeset
    76
 The files will be cached to the private directory of the application,
hgs
parents: 35
diff changeset
    77
 i.e. in the music player's case, this is C:\Private\10207C62\Cache.
hgs
parents: 35
diff changeset
    78
 */
35
hgs
parents:
diff changeset
    79
class MpNetworkAccessManager : public QNetworkAccessManager
hgs
parents:
diff changeset
    80
{
hgs
parents:
diff changeset
    81
public:
36
hgs
parents: 35
diff changeset
    82
    MpNetworkAccessManager( QObject* parent = 0 )
hgs
parents: 35
diff changeset
    83
        : QNetworkAccessManager( parent )
hgs
parents: 35
diff changeset
    84
    {
hgs
parents: 35
diff changeset
    85
        proxyFactory()->setUseSystemConfiguration( true );
hgs
parents: 35
diff changeset
    86
        QNetworkDiskCache* diskCache = new QNetworkDiskCache( this );
hgs
parents: 35
diff changeset
    87
        QString location = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
hgs
parents: 35
diff changeset
    88
        diskCache->setCacheDirectory( location );
hgs
parents: 35
diff changeset
    89
        setCache( diskCache );
hgs
parents: 35
diff changeset
    90
    }
35
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
private:
36
hgs
parents: 35
diff changeset
    93
    QNetworkReply* createRequest( Operation op,
hgs
parents: 35
diff changeset
    94
                                  const QNetworkRequest &request,
hgs
parents: 35
diff changeset
    95
                                  QIODevice* outgoingData = 0 )
35
hgs
parents:
diff changeset
    96
    {
hgs
parents:
diff changeset
    97
        TX_ENTRY
36
hgs
parents: 35
diff changeset
    98
        TX_LOG_ARGS( "share: createRequest URL=" << request.url().toString() )
hgs
parents: 35
diff changeset
    99
35
hgs
parents:
diff changeset
   100
        QVariant val = request.attribute( QNetworkRequest::CacheLoadControlAttribute );
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
         // Change the cache load control attrbute!
hgs
parents:
diff changeset
   103
        QNetworkRequest req = request;
hgs
parents:
diff changeset
   104
        req.setAttribute( QNetworkRequest::CacheLoadControlAttribute,
36
hgs
parents: 35
diff changeset
   105
                          QVariant( QNetworkRequest::PreferCache ) );
hgs
parents: 35
diff changeset
   106
        QNetworkReply* result = QNetworkAccessManager::createRequest( op, req, outgoingData );
35
hgs
parents:
diff changeset
   107
        TX_EXIT
36
hgs
parents: 35
diff changeset
   108
        return result;
hgs
parents: 35
diff changeset
   109
    }
hgs
parents: 35
diff changeset
   110
};
hgs
parents: 35
diff changeset
   111
hgs
parents: 35
diff changeset
   112
/*!
hgs
parents: 35
diff changeset
   113
 MpShareWebView derives from QGraphicsWebView in order to override it's
hgs
parents: 35
diff changeset
   114
 contextMenuEvent method to prevent the background context menu from
hgs
parents: 35
diff changeset
   115
 being displayed when user makes long click in the web view.
hgs
parents: 35
diff changeset
   116
 */
hgs
parents: 35
diff changeset
   117
class MpShareWebView : public QGraphicsWebView
hgs
parents: 35
diff changeset
   118
{
hgs
parents: 35
diff changeset
   119
public:
hgs
parents: 35
diff changeset
   120
    MpShareWebView( QGraphicsItem * parent = 0 )
hgs
parents: 35
diff changeset
   121
        : QGraphicsWebView( parent )
hgs
parents: 35
diff changeset
   122
    {
hgs
parents: 35
diff changeset
   123
        settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
hgs
parents: 35
diff changeset
   124
        settings()->setAttribute( QWebSettings::LocalStorageDatabaseEnabled, true );
hgs
parents: 35
diff changeset
   125
        settings()->enablePersistentStorage();
hgs
parents: 35
diff changeset
   126
    }
hgs
parents: 35
diff changeset
   127
hgs
parents: 35
diff changeset
   128
protected:
hgs
parents: 35
diff changeset
   129
    void contextMenuEvent( QGraphicsSceneContextMenuEvent* /*ev*/ ) // Override QGraphicsWebView::contextMenuEvent
hgs
parents: 35
diff changeset
   130
    {
hgs
parents: 35
diff changeset
   131
        // Fix to prevent "Stop" and "Reload" buttons in page background.
hgs
parents: 35
diff changeset
   132
        // Do not respond to the contextMenuEvent.
35
hgs
parents:
diff changeset
   133
    }
hgs
parents:
diff changeset
   134
};
hgs
parents:
diff changeset
   135
hgs
parents:
diff changeset
   136
hgs
parents:
diff changeset
   137
/*!
hgs
parents:
diff changeset
   138
 Constructor.
hgs
parents:
diff changeset
   139
 */
hgs
parents:
diff changeset
   140
MpDetailsShareDialog::MpDetailsShareDialog()
hgs
parents:
diff changeset
   141
    : mShareWebView( 0 ),
36
hgs
parents: 35
diff changeset
   142
      mShareNetAccMan( 0 ),
hgs
parents: 35
diff changeset
   143
      mProgressbar ( 0 ),
hgs
parents: 35
diff changeset
   144
      mIsInitialized( false )
35
hgs
parents:
diff changeset
   145
{
36
hgs
parents: 35
diff changeset
   146
    // DeleteOnClose attribute prevents crash when user presses Cancel
hgs
parents: 35
diff changeset
   147
    // before publishing player is fully loaded.
hgs
parents: 35
diff changeset
   148
    setAttribute( Qt::WA_DeleteOnClose, true );
35
hgs
parents:
diff changeset
   149
}
hgs
parents:
diff changeset
   150
36
hgs
parents: 35
diff changeset
   151
/*!
hgs
parents: 35
diff changeset
   152
 Initialize the share dialog.
hgs
parents: 35
diff changeset
   153
 When fully initialized we set our mIsInitialized flag to true.
hgs
parents: 35
diff changeset
   154
 Our isInitialized() method can be called to determine whether
hgs
parents: 35
diff changeset
   155
 initialization was successful.
hgs
parents: 35
diff changeset
   156
 */
hgs
parents: 35
diff changeset
   157
void MpDetailsShareDialog::initialize( MpSongData* aSongData, const QString& aUnknownTr )
35
hgs
parents:
diff changeset
   158
{
hgs
parents:
diff changeset
   159
    TX_ENTRY
hgs
parents:
diff changeset
   160
    if ( !initUser() )
hgs
parents:
diff changeset
   161
    {
hgs
parents:
diff changeset
   162
        emit closeShareDialog();
hgs
parents:
diff changeset
   163
        return;
hgs
parents:
diff changeset
   164
    }
36
hgs
parents: 35
diff changeset
   165
    initShareData( aSongData, aUnknownTr );
hgs
parents: 35
diff changeset
   166
    initLanguage();
35
hgs
parents:
diff changeset
   167
    initNetworkAccessManager();
hgs
parents:
diff changeset
   168
    initWebView();
hgs
parents:
diff changeset
   169
    initSignalSlots();
hgs
parents:
diff changeset
   170
hgs
parents:
diff changeset
   171
    setDismissPolicy( HbDialog::NoDismiss );
hgs
parents:
diff changeset
   172
hgs
parents:
diff changeset
   173
    // No timeout needed for the dialog.
hgs
parents:
diff changeset
   174
    setTimeout( HbPopup::NoTimeout );
hgs
parents:
diff changeset
   175
hgs
parents:
diff changeset
   176
#ifdef SHARE_PLAYER_RND
hgs
parents:
diff changeset
   177
    // Test whether the RND file exists.
hgs
parents:
diff changeset
   178
    QFile file( RND_SHARE_INDEX_FILE );
hgs
parents:
diff changeset
   179
    if ( file.exists() )
hgs
parents:
diff changeset
   180
    {
hgs
parents:
diff changeset
   181
        // Load the RND URL from the specified location to the web view.
hgs
parents:
diff changeset
   182
        TX_LOG_ARGS( "share: Use RND index.html file " << RND_SHARE_INDEX_FILE )
hgs
parents:
diff changeset
   183
        mShareWebView->load( QUrl( RND_SHARE_INDEX_URL ) );
hgs
parents:
diff changeset
   184
    }
hgs
parents:
diff changeset
   185
    else
hgs
parents:
diff changeset
   186
#endif
hgs
parents:
diff changeset
   187
    {
hgs
parents:
diff changeset
   188
        // Load the production URL from the application resources to the web view.
hgs
parents:
diff changeset
   189
        TX_LOG_ARGS( "share: Use QRC index.html file " << SHARE_INDEX_URL )
hgs
parents:
diff changeset
   190
        mShareWebView->load( QUrl( SHARE_INDEX_URL ) );
hgs
parents:
diff changeset
   191
    }
36
hgs
parents: 35
diff changeset
   192
hgs
parents: 35
diff changeset
   193
    // Flag that the dialog is now fully initialized.
hgs
parents: 35
diff changeset
   194
    mIsInitialized = true;
hgs
parents: 35
diff changeset
   195
hgs
parents: 35
diff changeset
   196
    // Show progress dialog in .3 second if loading not finished.
hgs
parents: 35
diff changeset
   197
    QTimer::singleShot(300, this, SLOT(showProgressDialog()));
hgs
parents: 35
diff changeset
   198
35
hgs
parents:
diff changeset
   199
    TX_EXIT
hgs
parents:
diff changeset
   200
}
hgs
parents:
diff changeset
   201
hgs
parents:
diff changeset
   202
/*!
hgs
parents:
diff changeset
   203
 Destructor.
hgs
parents:
diff changeset
   204
 */
hgs
parents:
diff changeset
   205
MpDetailsShareDialog::~MpDetailsShareDialog()
hgs
parents:
diff changeset
   206
{
hgs
parents:
diff changeset
   207
    TX_ENTRY
36
hgs
parents: 35
diff changeset
   208
    if ( mShareData.songData() )
hgs
parents: 35
diff changeset
   209
    {
hgs
parents: 35
diff changeset
   210
        // Ensure that we remove the temporary album art file when we close the dialog.
hgs
parents: 35
diff changeset
   211
        // TODO this should be removed when base64 issue is solved.
hgs
parents: 35
diff changeset
   212
        TX_LOG_ARGS( "share: remove album art file" )
hgs
parents: 35
diff changeset
   213
        mShareData.songData()->removeAlbumArtFile();
hgs
parents: 35
diff changeset
   214
    }
35
hgs
parents:
diff changeset
   215
    logoutPlayer();
36
hgs
parents: 35
diff changeset
   216
    // Probably mShareNetAccMan should not be deleted but qt documentation
hgs
parents: 35
diff changeset
   217
    // does not indicate whether QWebPage takes ownership of the object or not.
hgs
parents: 35
diff changeset
   218
    // See http://doc.qt.nokia.com/4.6/qwebpage.html
hgs
parents: 35
diff changeset
   219
    //delete mShareNetAccMan;
35
hgs
parents:
diff changeset
   220
    TX_EXIT
hgs
parents:
diff changeset
   221
}
hgs
parents:
diff changeset
   222
36
hgs
parents: 35
diff changeset
   223
/*!
hgs
parents: 35
diff changeset
   224
 Initialize share data.
hgs
parents: 35
diff changeset
   225
 */
hgs
parents: 35
diff changeset
   226
void MpDetailsShareDialog::initShareData( MpSongData* aSongData, const QString& aUnknownTr )
35
hgs
parents:
diff changeset
   227
{
hgs
parents:
diff changeset
   228
    TX_ENTRY
hgs
parents:
diff changeset
   229
    // Set information for the share data.
hgs
parents:
diff changeset
   230
    mShareData.setOwner( this );
hgs
parents:
diff changeset
   231
    mShareData.setSongData( aSongData );
36
hgs
parents: 35
diff changeset
   232
    mShareData.setErrorMessage( tr( ERROR_MESSAGE ) );
hgs
parents: 35
diff changeset
   233
    mShareData.setUnknownTr( aUnknownTr );
35
hgs
parents:
diff changeset
   234
    TX_EXIT
hgs
parents:
diff changeset
   235
}
hgs
parents:
diff changeset
   236
36
hgs
parents: 35
diff changeset
   237
/*!
hgs
parents: 35
diff changeset
   238
 Initialize language.
hgs
parents: 35
diff changeset
   239
 Language string is formatted like "en-US", where "en" is the ISO-639-1 language code,
hgs
parents: 35
diff changeset
   240
 and "US" is the ISO-3166-1 country code.
hgs
parents: 35
diff changeset
   241
 We use the QT Mobility API (systeminfo) to obtain the settings from the device.
hgs
parents: 35
diff changeset
   242
 In the event that we cannot construct the QSystemInfo variable then we will fallback
hgs
parents: 35
diff changeset
   243
 to some DEFAULT_LANGUAGE setting.
hgs
parents: 35
diff changeset
   244
 */
hgs
parents: 35
diff changeset
   245
void MpDetailsShareDialog::initLanguage()
hgs
parents: 35
diff changeset
   246
{
hgs
parents: 35
diff changeset
   247
    TX_ENTRY
hgs
parents: 35
diff changeset
   248
    // Set language string, example "en-US".
hgs
parents: 35
diff changeset
   249
    QString language;
hgs
parents: 35
diff changeset
   250
    QSystemInfo* sysInfo = new QSystemInfo( this );
hgs
parents: 35
diff changeset
   251
    if ( sysInfo )
hgs
parents: 35
diff changeset
   252
    {
hgs
parents: 35
diff changeset
   253
        language += sysInfo->currentLanguage(); // ISO-639-1 language code.
hgs
parents: 35
diff changeset
   254
        language += "-";
hgs
parents: 35
diff changeset
   255
        language += sysInfo->currentCountryCode(); // ISO-3166-1 country code.
hgs
parents: 35
diff changeset
   256
        delete sysInfo;
hgs
parents: 35
diff changeset
   257
    }
hgs
parents: 35
diff changeset
   258
    else
hgs
parents: 35
diff changeset
   259
    {
hgs
parents: 35
diff changeset
   260
        // Fallback to the default language.
hgs
parents: 35
diff changeset
   261
        language = DEFAULT_LANGUAGE;
hgs
parents: 35
diff changeset
   262
    }
hgs
parents: 35
diff changeset
   263
    TX_LOG_ARGS( "share: language '" << language << "'" )
hgs
parents: 35
diff changeset
   264
    mShareData.setLanguage( language );
hgs
parents: 35
diff changeset
   265
    TX_EXIT
hgs
parents: 35
diff changeset
   266
}
hgs
parents: 35
diff changeset
   267
hgs
parents: 35
diff changeset
   268
/*!
hgs
parents: 35
diff changeset
   269
 Initialize network access manager.
hgs
parents: 35
diff changeset
   270
 */
35
hgs
parents:
diff changeset
   271
void MpDetailsShareDialog::initNetworkAccessManager()
hgs
parents:
diff changeset
   272
{
hgs
parents:
diff changeset
   273
    TX_ENTRY
36
hgs
parents: 35
diff changeset
   274
    // Make our own network access manager to allow file retrieval from local cache,
35
hgs
parents:
diff changeset
   275
    // since configuration for the default network access manager seems to be
hgs
parents:
diff changeset
   276
    // to always redownload from network.
36
hgs
parents: 35
diff changeset
   277
    if ( !mShareNetAccMan )
hgs
parents: 35
diff changeset
   278
    {
hgs
parents: 35
diff changeset
   279
        TX_LOG_ARGS( "share: construct network access manager" )
hgs
parents: 35
diff changeset
   280
        mShareNetAccMan = new MpNetworkAccessManager( this );
hgs
parents: 35
diff changeset
   281
    }
35
hgs
parents:
diff changeset
   282
    TX_EXIT
hgs
parents:
diff changeset
   283
}
hgs
parents:
diff changeset
   284
36
hgs
parents: 35
diff changeset
   285
/*!
hgs
parents: 35
diff changeset
   286
 Initialize the web view.
hgs
parents: 35
diff changeset
   287
 */
35
hgs
parents:
diff changeset
   288
void MpDetailsShareDialog::initWebView()
hgs
parents:
diff changeset
   289
{
hgs
parents:
diff changeset
   290
    TX_ENTRY
36
hgs
parents: 35
diff changeset
   291
    if ( !mShareWebView )
hgs
parents: 35
diff changeset
   292
    {
hgs
parents: 35
diff changeset
   293
        TX_LOG_ARGS( "share: construct share web view" )
hgs
parents: 35
diff changeset
   294
        mShareWebView = new MpShareWebView( this );
hgs
parents: 35
diff changeset
   295
        mShareWebView->page()->setNetworkAccessManager( mShareNetAccMan );
hgs
parents: 35
diff changeset
   296
        mShareWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
hgs
parents: 35
diff changeset
   297
        mShareWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
hgs
parents: 35
diff changeset
   298
        setContentWidget( mShareWebView );
hgs
parents: 35
diff changeset
   299
        addContext();
hgs
parents: 35
diff changeset
   300
        mProgressbar = new HbProgressDialog(HbProgressDialog::WaitDialog);
hgs
parents: 35
diff changeset
   301
        mProgressbar->setText(tr("Loading"));
hgs
parents: 35
diff changeset
   302
    }
35
hgs
parents:
diff changeset
   303
    TX_EXIT
hgs
parents:
diff changeset
   304
}
hgs
parents:
diff changeset
   305
36
hgs
parents: 35
diff changeset
   306
/*!
hgs
parents: 35
diff changeset
   307
 Initialize signals and slots.
hgs
parents: 35
diff changeset
   308
 */
35
hgs
parents:
diff changeset
   309
void MpDetailsShareDialog::initSignalSlots()
hgs
parents:
diff changeset
   310
{
hgs
parents:
diff changeset
   311
    TX_ENTRY
36
hgs
parents: 35
diff changeset
   312
    // Connect various signals to slots for networking.
hgs
parents: 35
diff changeset
   313
    connect( mShareNetAccMan, SIGNAL( sslErrors( QNetworkReply*, const QList< QSslError >& ) ),
hgs
parents: 35
diff changeset
   314
             this, SLOT( handleRequestSSLErrors( QNetworkReply*, const QList< QSslError >& ) ) );
hgs
parents: 35
diff changeset
   315
    connect( mShareNetAccMan, SIGNAL( finished( QNetworkReply* ) ), this, SLOT( handleRequestFinished( QNetworkReply* ) ) );
hgs
parents: 35
diff changeset
   316
35
hgs
parents:
diff changeset
   317
    // Connect various signals to slots for interface to webview.
hgs
parents:
diff changeset
   318
    connect( mShareWebView, SIGNAL( loadFinished( bool ) ), SLOT( onIndexLoad( bool ) ) );
hgs
parents:
diff changeset
   319
    connect( mShareWebView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared() ), this, SLOT( addContext() ) );
hgs
parents:
diff changeset
   320
    connect( mShareWebView->page(), SIGNAL( windowCloseRequested() ), this, SIGNAL( closeShareDialog() ) );
36
hgs
parents: 35
diff changeset
   321
    connect( mProgressbar, SIGNAL(cancelled()), this, SIGNAL( closeShareDialog() ) );
35
hgs
parents:
diff changeset
   322
    TX_EXIT
hgs
parents:
diff changeset
   323
}
hgs
parents:
diff changeset
   324
hgs
parents:
diff changeset
   325
/*!
hgs
parents:
diff changeset
   326
 initUser is used as temporary solution until Single Sign On is implemented in platform.
hgs
parents:
diff changeset
   327
 */
hgs
parents:
diff changeset
   328
bool MpDetailsShareDialog::initUser()
hgs
parents:
diff changeset
   329
{
hgs
parents:
diff changeset
   330
    TX_ENTRY
hgs
parents:
diff changeset
   331
    bool result = false;
hgs
parents:
diff changeset
   332
#ifdef SHARE_PLAYER_RND
hgs
parents:
diff changeset
   333
    // ovicredentials.txt is used as temporary solution until Single Sign On is implemented in platform.
hgs
parents:
diff changeset
   334
    QFile file( RND_OVI_LOGIN_FILE );
hgs
parents:
diff changeset
   335
    if ( !file.open( QFile::ReadOnly ) )
hgs
parents:
diff changeset
   336
    {
36
hgs
parents: 35
diff changeset
   337
        // There must be e:ovicredentials.txt in the filesystem but don't show error dialog
hgs
parents: 35
diff changeset
   338
        // otherwise it will appear as soon as detailsview is created.
hgs
parents: 35
diff changeset
   339
        result = false;
35
hgs
parents:
diff changeset
   340
    }
hgs
parents:
diff changeset
   341
    else
hgs
parents:
diff changeset
   342
    {
hgs
parents:
diff changeset
   343
        QTextStream stream ( &file );
hgs
parents:
diff changeset
   344
        QString strCred = stream.readLine( 0 );
hgs
parents:
diff changeset
   345
        file.close();
hgs
parents:
diff changeset
   346
        QStringList slCred = strCred.split( ":" );
hgs
parents:
diff changeset
   347
        if ( slCred.length() > 1 )
hgs
parents:
diff changeset
   348
        {
hgs
parents:
diff changeset
   349
            mShareData.setUsername( slCred[ 0 ] );
hgs
parents:
diff changeset
   350
            mShareData.setPassword( slCred[ 1 ] );
hgs
parents:
diff changeset
   351
            result = true;
hgs
parents:
diff changeset
   352
        }
hgs
parents:
diff changeset
   353
        else
hgs
parents:
diff changeset
   354
        {
hgs
parents:
diff changeset
   355
            errorHandler( "share", QString( RND_OVI_LOGIN_FILE ) + " username:password expected" );
hgs
parents:
diff changeset
   356
        }
hgs
parents:
diff changeset
   357
    }
hgs
parents:
diff changeset
   358
    TX_LOG_ARGS( "share: credentials " << mShareData.username() << " / " << mShareData.password() )
hgs
parents:
diff changeset
   359
#else
hgs
parents:
diff changeset
   360
    // TODO: Single Sign On stuff.
hgs
parents:
diff changeset
   361
#endif // SHARE_PLAYER_RND
hgs
parents:
diff changeset
   362
    TX_EXIT
hgs
parents:
diff changeset
   363
    return result;
hgs
parents:
diff changeset
   364
}
hgs
parents:
diff changeset
   365
hgs
parents:
diff changeset
   366
/*!
36
hgs
parents: 35
diff changeset
   367
 Returns true if the dialog has been fully initialized.
hgs
parents: 35
diff changeset
   368
  */
hgs
parents: 35
diff changeset
   369
bool MpDetailsShareDialog::isInitialized() const
hgs
parents: 35
diff changeset
   370
{
hgs
parents: 35
diff changeset
   371
    return mIsInitialized;
hgs
parents: 35
diff changeset
   372
}
hgs
parents: 35
diff changeset
   373
hgs
parents: 35
diff changeset
   374
/*!
hgs
parents: 35
diff changeset
   375
 Attempt to cache the publishing player files from internet
hgs
parents: 35
diff changeset
   376
 to improve user experience for first-time use.
hgs
parents: 35
diff changeset
   377
 If the files are already in the cache and have not expired,
hgs
parents: 35
diff changeset
   378
 then this should not do anything.
hgs
parents: 35
diff changeset
   379
 */
hgs
parents: 35
diff changeset
   380
void MpDetailsShareDialog::cachePublishingPlayerFiles()
hgs
parents: 35
diff changeset
   381
{
hgs
parents: 35
diff changeset
   382
    TX_ENTRY
hgs
parents: 35
diff changeset
   383
    // We need the network access manager, so make sure it is initialized.
hgs
parents: 35
diff changeset
   384
    if ( !mShareNetAccMan )
hgs
parents: 35
diff changeset
   385
    {
hgs
parents: 35
diff changeset
   386
        initNetworkAccessManager();
hgs
parents: 35
diff changeset
   387
    }
hgs
parents: 35
diff changeset
   388
    // Attempt to get the required publishing player files from the net in advance.
hgs
parents: 35
diff changeset
   389
    // We don't listen to any signal that the download succeeded or failed
hgs
parents: 35
diff changeset
   390
    // since we will let it silently fail at this stage.
hgs
parents: 35
diff changeset
   391
    // These URLs are also included in index.html resource, and the two must
hgs
parents: 35
diff changeset
   392
    // be kept the same.
hgs
parents: 35
diff changeset
   393
    mShareNetAccMan->get( QNetworkRequest( QUrl(
hgs
parents: 35
diff changeset
   394
            "http://hf.ci.wipsl.com/PleiXXPTsup/noheva-be/css/ovi.player.share.ui.css" ) ) );
hgs
parents: 35
diff changeset
   395
    mShareNetAccMan->get( QNetworkRequest( QUrl(
hgs
parents: 35
diff changeset
   396
            "http://hf.ci.wipsl.com/PleiXXPTsup/noheva-be/js/publishplayer.js" ) ) );
hgs
parents: 35
diff changeset
   397
    TX_EXIT
hgs
parents: 35
diff changeset
   398
}
hgs
parents: 35
diff changeset
   399
hgs
parents: 35
diff changeset
   400
/*!
35
hgs
parents:
diff changeset
   401
 Release resources from share player.
hgs
parents:
diff changeset
   402
 */
hgs
parents:
diff changeset
   403
void MpDetailsShareDialog::logoutPlayer()
hgs
parents:
diff changeset
   404
{
hgs
parents:
diff changeset
   405
    TX_ENTRY
36
hgs
parents: 35
diff changeset
   406
    if ( mShareWebView )
35
hgs
parents:
diff changeset
   407
    {
hgs
parents:
diff changeset
   408
        mShareWebView->page()->mainFrame()->evaluateJavaScript( "music.teardown();" );
hgs
parents:
diff changeset
   409
    }
hgs
parents:
diff changeset
   410
    TX_EXIT
hgs
parents:
diff changeset
   411
}
hgs
parents:
diff changeset
   412
hgs
parents:
diff changeset
   413
/*!
hgs
parents:
diff changeset
   414
 Adds the shared data context to the javascript of the loaded page.
hgs
parents:
diff changeset
   415
 */
hgs
parents:
diff changeset
   416
void MpDetailsShareDialog::addContext()
hgs
parents:
diff changeset
   417
{
hgs
parents:
diff changeset
   418
    TX_ENTRY
36
hgs
parents: 35
diff changeset
   419
    if ( mShareWebView )
35
hgs
parents:
diff changeset
   420
    {
hgs
parents:
diff changeset
   421
        mShareWebView->page()->mainFrame()->addToJavaScriptWindowObject( "context", &mShareData );
hgs
parents:
diff changeset
   422
    }
hgs
parents:
diff changeset
   423
    TX_EXIT
hgs
parents:
diff changeset
   424
}
hgs
parents:
diff changeset
   425
hgs
parents:
diff changeset
   426
/*!
hgs
parents:
diff changeset
   427
 Updates the shared data context in the javascript of the loaded page.
hgs
parents:
diff changeset
   428
 */
hgs
parents:
diff changeset
   429
void MpDetailsShareDialog::updateSharedData()
hgs
parents:
diff changeset
   430
{
hgs
parents:
diff changeset
   431
    TX_ENTRY
36
hgs
parents: 35
diff changeset
   432
    if ( mShareWebView )
35
hgs
parents:
diff changeset
   433
    {
36
hgs
parents: 35
diff changeset
   434
        // We don't need to call updateContextArea when the track URL has been updated.
hgs
parents: 35
diff changeset
   435
        //mShareWebView->page()->mainFrame()->evaluateJavaScript( "music.updateContextArea();" );
35
hgs
parents:
diff changeset
   436
        mShareWebView->page()->mainFrame()->evaluateJavaScript( "music.updateMetadata();" );
hgs
parents:
diff changeset
   437
    }
hgs
parents:
diff changeset
   438
    TX_EXIT
hgs
parents:
diff changeset
   439
}
hgs
parents:
diff changeset
   440
hgs
parents:
diff changeset
   441
/*!
hgs
parents:
diff changeset
   442
 Slot to call when index.html loading completes.
hgs
parents:
diff changeset
   443
 */
hgs
parents:
diff changeset
   444
void MpDetailsShareDialog::onIndexLoad( bool aOk )
hgs
parents:
diff changeset
   445
{
hgs
parents:
diff changeset
   446
    TX_ENTRY
hgs
parents:
diff changeset
   447
    if ( !aOk )
hgs
parents:
diff changeset
   448
    {
hgs
parents:
diff changeset
   449
        // Close the popup window, failed to load index.html.
hgs
parents:
diff changeset
   450
        // This is pretty serious and most likely unrecoverable error.
hgs
parents:
diff changeset
   451
        // Only thing we can do really is to close the share player
hgs
parents:
diff changeset
   452
        // dialog - TODO do we need to show any error message to user?
hgs
parents:
diff changeset
   453
        TX_LOG_ARGS( "share: failed to load index.html" )
hgs
parents:
diff changeset
   454
        emit closeShareDialog();
hgs
parents:
diff changeset
   455
    }
hgs
parents:
diff changeset
   456
    TX_EXIT
hgs
parents:
diff changeset
   457
}
hgs
parents:
diff changeset
   458
hgs
parents:
diff changeset
   459
/*!
hgs
parents:
diff changeset
   460
 Slot to call for debug output.
hgs
parents:
diff changeset
   461
 */
hgs
parents:
diff changeset
   462
void MpDetailsShareDialog::debugJs( QString s )
hgs
parents:
diff changeset
   463
{
hgs
parents:
diff changeset
   464
    TX_ENTRY
hgs
parents:
diff changeset
   465
    TX_LOG_ARGS( "share: debugJs: " << s )
hgs
parents:
diff changeset
   466
    TX_EXIT
hgs
parents:
diff changeset
   467
}
hgs
parents:
diff changeset
   468
hgs
parents:
diff changeset
   469
/*!
hgs
parents:
diff changeset
   470
 Slot to call for displaying an error message to the user.
hgs
parents:
diff changeset
   471
 */
36
hgs
parents: 35
diff changeset
   472
void MpDetailsShareDialog::errorHandler( QString aError, QString aMessage )
35
hgs
parents:
diff changeset
   473
{
hgs
parents:
diff changeset
   474
    TX_ENTRY
36
hgs
parents: 35
diff changeset
   475
    // If error argument ends with "_SUCCESS", then this should be an info message.
hgs
parents: 35
diff changeset
   476
    // If error argument ends with "_FAILED" or something else, then this should be a warning message.
hgs
parents: 35
diff changeset
   477
    TX_LOG_ARGS( "share: errorHandler: " << aError << ": " << aMessage )
hgs
parents: 35
diff changeset
   478
    if ( aError.endsWith( "_SUCCESS" ) )
hgs
parents: 35
diff changeset
   479
    {
hgs
parents: 35
diff changeset
   480
        // TODO this method seems to be deprecated?
hgs
parents: 35
diff changeset
   481
        HbMessageBox::information( tr( "%1" ).arg( aError ) + ": " + tr( "%1" ).arg( aMessage ) ); // For week16 hbwidgets
hgs
parents: 35
diff changeset
   482
    }
hgs
parents: 35
diff changeset
   483
    else
hgs
parents: 35
diff changeset
   484
    {
hgs
parents: 35
diff changeset
   485
        // TODO this method seems to be deprecated?
hgs
parents: 35
diff changeset
   486
        HbMessageBox::warning( tr( "%1" ).arg( aError ) + ": " + tr( "%1" ).arg( aMessage ) ); // For week16 hbwidgets
hgs
parents: 35
diff changeset
   487
        // HbMessageBox::launchWarningMessageBox( tr( "%1" ).arg( aError ) + ": " + tr( "%1" ).arg( message ) ); // For week12 hbwidgets
hgs
parents: 35
diff changeset
   488
    }
35
hgs
parents:
diff changeset
   489
    TX_EXIT
hgs
parents:
diff changeset
   490
}
hgs
parents:
diff changeset
   491
hgs
parents:
diff changeset
   492
/*!
hgs
parents:
diff changeset
   493
 Slot to call to clear the web view cache.
hgs
parents:
diff changeset
   494
 */
hgs
parents:
diff changeset
   495
void MpDetailsShareDialog::clearCache()
hgs
parents:
diff changeset
   496
{
hgs
parents:
diff changeset
   497
    TX_ENTRY
hgs
parents:
diff changeset
   498
    QAbstractNetworkCache* cache = mShareNetAccMan ? mShareNetAccMan->cache() : NULL;
hgs
parents:
diff changeset
   499
    if ( cache )
hgs
parents:
diff changeset
   500
    {
hgs
parents:
diff changeset
   501
        TX_LOG_ARGS( "share: clearCache: clearing cache" )
hgs
parents:
diff changeset
   502
        cache->clear();
hgs
parents:
diff changeset
   503
#ifdef SHARE_PLAYER_RND
hgs
parents:
diff changeset
   504
        errorHandler( "Cache", "Cleared cache!" );
hgs
parents:
diff changeset
   505
#endif
hgs
parents:
diff changeset
   506
    }
hgs
parents:
diff changeset
   507
    else
hgs
parents:
diff changeset
   508
    {
hgs
parents:
diff changeset
   509
        TX_LOG_ARGS( "share: clearCache: unable to clear cache" )
hgs
parents:
diff changeset
   510
#ifdef SHARE_PLAYER_RND
hgs
parents:
diff changeset
   511
        errorHandler( "Cache", "Could not clear cache!" );
hgs
parents:
diff changeset
   512
#endif
hgs
parents:
diff changeset
   513
    }
hgs
parents:
diff changeset
   514
    TX_EXIT
hgs
parents:
diff changeset
   515
}
hgs
parents:
diff changeset
   516
36
hgs
parents: 35
diff changeset
   517
/*!
hgs
parents: 35
diff changeset
   518
 Slot to show the publishing window after html elements are created in javascript.
hgs
parents: 35
diff changeset
   519
 */
hgs
parents: 35
diff changeset
   520
void MpDetailsShareDialog::showWindow()
hgs
parents: 35
diff changeset
   521
{
hgs
parents: 35
diff changeset
   522
    TX_ENTRY
hgs
parents: 35
diff changeset
   523
    if (mProgressbar)
hgs
parents: 35
diff changeset
   524
        mProgressbar->close();
hgs
parents: 35
diff changeset
   525
    show();
hgs
parents: 35
diff changeset
   526
    TX_EXIT
hgs
parents: 35
diff changeset
   527
}
hgs
parents: 35
diff changeset
   528
hgs
parents: 35
diff changeset
   529
/*!
hgs
parents: 35
diff changeset
   530
 Slot to show progress dialog if the publishing window is not loaded in .3 sec.
hgs
parents: 35
diff changeset
   531
 */
hgs
parents: 35
diff changeset
   532
void MpDetailsShareDialog::showProgressDialog()
hgs
parents: 35
diff changeset
   533
{
hgs
parents: 35
diff changeset
   534
    TX_ENTRY
hgs
parents: 35
diff changeset
   535
    if (!isVisible())
hgs
parents: 35
diff changeset
   536
        mProgressbar->show();
hgs
parents: 35
diff changeset
   537
    TX_EXIT
hgs
parents: 35
diff changeset
   538
}
hgs
parents: 35
diff changeset
   539
hgs
parents: 35
diff changeset
   540
/*!
hgs
parents: 35
diff changeset
   541
 Slot to SSL errors in network request. We will ignore any errors.
hgs
parents: 35
diff changeset
   542
 */
hgs
parents: 35
diff changeset
   543
void MpDetailsShareDialog::handleRequestSSLErrors( QNetworkReply* aReply, const QList< QSslError >& aErrors )
hgs
parents: 35
diff changeset
   544
{
hgs
parents: 35
diff changeset
   545
    TX_ENTRY
hgs
parents: 35
diff changeset
   546
    aReply->ignoreSslErrors();
hgs
parents: 35
diff changeset
   547
    for( int i = 0; i < aErrors.count(); i++ )
hgs
parents: 35
diff changeset
   548
    {
hgs
parents: 35
diff changeset
   549
        TX_LOG_ARGS( "SSL error " << aErrors.at( i ).errorString() );
hgs
parents: 35
diff changeset
   550
    }
hgs
parents: 35
diff changeset
   551
    TX_EXIT
hgs
parents: 35
diff changeset
   552
}
hgs
parents: 35
diff changeset
   553
hgs
parents: 35
diff changeset
   554
/*!
hgs
parents: 35
diff changeset
   555
 Slot to handle network request completion.
hgs
parents: 35
diff changeset
   556
 */
hgs
parents: 35
diff changeset
   557
void MpDetailsShareDialog::handleRequestFinished( QNetworkReply* aReply )
hgs
parents: 35
diff changeset
   558
{
hgs
parents: 35
diff changeset
   559
    TX_ENTRY
hgs
parents: 35
diff changeset
   560
    if ( aReply->error() != QNetworkReply::NoError )
hgs
parents: 35
diff changeset
   561
    {
hgs
parents: 35
diff changeset
   562
        TX_LOG_ARGS( "Network request error " << aReply->error() << aReply->errorString() );
hgs
parents: 35
diff changeset
   563
        // TODO what to do now?
hgs
parents: 35
diff changeset
   564
    }
hgs
parents: 35
diff changeset
   565
    TX_EXIT
hgs
parents: 35
diff changeset
   566
}
hgs
parents: 35
diff changeset
   567
35
hgs
parents:
diff changeset
   568
#endif // SHARE_FUNC_ENABLED