[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [amarok/spotify] src/core-impl/collections/spotifycollection: Complete major refactor of SettingsDia
From:       Bart Cerneels <bart.cerneels () kde ! org>
Date:       2012-11-07 21:49:52
Message-ID: 20121107214952.9C55CA6091 () git ! kde ! org
[Download RAW message or body]

Git commit 90a93512c1cddb36577f244bf3eac8ddef0d38e8 by Bart Cerneels.
Committed on 07/11/2012 at 16:44.
Pushed by shanachie into branch 'spotify'.

Complete major refactor of SettingsDialog.

* Separate download dialog containing all the download logic.
* Download dialog called from SettingsDialog c'tor.
* resolver path, name and url are static in SpotifyCollection.
* Dialogs now use KMessageWidget for inline error and success messages.

M  +49   -7    src/core-impl/collections/spotifycollection/SpotifyCollection.cpp
M  +9    -0    src/core-impl/collections/spotifycollection/SpotifyCollection.h
M  +1    -44   src/core-impl/collections/spotifycollection/SpotifyConfig.cpp
M  +0    -10   src/core-impl/collections/spotifycollection/SpotifyConfig.h
M  +129  -3    src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.cpp
M  +25   -1    src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.h
M  +18   -0    src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.ui
M  +13   -134  src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp
M  +2    -12   src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h

http://commits.kde.org/amarok/90a93512c1cddb36577f244bf3eac8ddef0d38e8

diff --git a/src/core-impl/collections/spotifycollection/SpotifyCollection.cpp \
b/src/core-impl/collections/spotifycollection/SpotifyCollection.cpp index 3b47a67..2faf96e 100644
--- a/src/core-impl/collections/spotifycollection/SpotifyCollection.cpp
+++ b/src/core-impl/collections/spotifycollection/SpotifyCollection.cpp
@@ -33,7 +33,9 @@
 #include "core/support/Debug.h"
 
 #include <KIcon>
+#include <KStandardDirs>
 
+#include <QSysInfo>
 #include <QTimer>
 
 namespace Collections
@@ -68,9 +70,10 @@ namespace Collections
         // Load credentials
         m_config.load();
 
-        m_controller = The::SpotifyController( m_config.resolverPath() );
+        m_controller = The::SpotifyController( SpotifyCollection::resolverPath() );
 #ifdef Q_OS_LINUX
-        m_controller->environment().insert("LD_LIBRARY_PATH", SpotifyConfig::resolverDownloadPath());
+        m_controller->environment().insert("LD_LIBRARY_PATH",
+                                           SpotifyCollection::resolverDownloadPath());
 #endif
 
         Q_ASSERT( m_controller != 0 );
@@ -108,7 +111,7 @@ namespace Collections
     {
         DEBUG_BLOCK
 
-        m_controller->setFilePath( m_config.resolverPath() );
+        m_controller->setFilePath( SpotifyCollection::resolverPath() );
         if( !m_controller->loggedIn()
             && !m_config.username().isEmpty()
             && !m_config.password().isEmpty() )
@@ -138,6 +141,46 @@ namespace Collections
         m_collectionIsManaged = false;
     }
 
+    const QString
+    SpotifyCollection::supportedPlatformName()
+    {
+    #ifdef Q_OS_WIN32
+        return "win32";
+    #else
+    #ifdef Q_OS_LINUX
+        return QString("linux%1").arg(QSysInfo::WordSize);
+    #else
+        return QString();
+    #endif
+    #endif
+    }
+
+    //TODO: replace with link on files.kde.org or redirect from amarok.kde.org
+    const QString SpotifyCollection::s_resolverDownloadUrl =
+            "http://hades.name/static/amarok/";
+
+    const QString
+    SpotifyCollection::defaultResolverName()
+    {
+        return QString("spotify_resolver_%1").arg(supportedPlatformName());
+    }
+
+    const QString
+    SpotifyCollection::resolverDownloadPath()
+    {
+        return KStandardDirs::locateLocal( "data", "amarok" );
+    }
+
+    const QString SpotifyCollection::resolverDownloadUrl()
+    {
+        return s_resolverDownloadUrl + defaultResolverName() + ".zip";
+    }
+
+    const QString SpotifyCollection::resolverPath()
+    {
+        return resolverDownloadPath() + "/" + defaultResolverName();
+    }
+
     SpotifyCollection::SpotifyCollection( Spotify::Controller *controller )
         : m_collectionId( i18n( "Spotify Collection" ) )
         , m_memoryCollection( new MemoryCollection )
@@ -400,11 +443,10 @@ namespace Collections
     void
     SpotifyCollection::slotConfigure()
     {
-        // settingDialog will be deleted after closed
-        SpotifySettingsDialog* settingDialog = new SpotifySettingsDialog;
-        settingDialog->setModal( true );
+        SpotifySettingsDialog settingDialog;
+        settingDialog.setModal( true );
         // This will return immediately
-        settingDialog->show();
+        settingDialog.exec();
     }
 
     void
diff --git a/src/core-impl/collections/spotifycollection/SpotifyCollection.h \
b/src/core-impl/collections/spotifycollection/SpotifyCollection.h index 96370c2..724e0cc 100644
--- a/src/core-impl/collections/spotifycollection/SpotifyCollection.h
+++ b/src/core-impl/collections/spotifycollection/SpotifyCollection.h
@@ -28,6 +28,7 @@
 
 class QAction;
 
+//TODO: move out of Collections namespace
 namespace Collections
 {
     class MemoryCollection;
@@ -60,6 +61,14 @@ namespace Collections
     {
         Q_OBJECT
         public:
+
+            static const QString s_resolverDownloadUrl;
+            static const QString supportedPlatformName();
+            static const QString defaultResolverName();
+            static const QString resolverDownloadPath();
+            static const QString resolverDownloadUrl();
+            static const QString resolverPath();
+
             SpotifyCollection( Spotify::Controller* controller );
             ~SpotifyCollection();
 
diff --git a/src/core-impl/collections/spotifycollection/SpotifyConfig.cpp \
b/src/core-impl/collections/spotifycollection/SpotifyConfig.cpp index 697181f..baa8994 100644
--- a/src/core-impl/collections/spotifycollection/SpotifyConfig.cpp
+++ b/src/core-impl/collections/spotifycollection/SpotifyConfig.cpp
@@ -22,17 +22,11 @@
 #include <KConfig>
 #include <KConfigGroup>
 #include <KMessageBox>
-#include <KStandardDirs>
 #include <KWallet/Wallet>
 
-#include <QSysInfo>
-
-const QString SpotifyConfig::m_resolverDownloadUrl = "http://hades.name/static/amarok/";
-
 SpotifyConfig::SpotifyConfig()
 : m_username ()
 , m_password ()
-, m_resolverPath ()
 , m_highQuality( false )
 , m_wallet ( 0 )
 {
@@ -88,8 +82,6 @@ SpotifyConfig::load()
         m_password = QByteArray::fromBase64( config.readEntry( "password", QString() ).toLocal8Bit() );
     }
 
-    m_resolverPath = config.readEntry( "resolver", KStandardDirs::locateLocal( "data",
-                                     QString("amarok/%1").arg( defaultResolverName() ) ) );
     m_highQuality = config.readEntry( "highquality", false );
 }
 
@@ -104,6 +96,7 @@ SpotifyConfig::save()
 
     if( !m_wallet )
     {
+        //TODO: move this question to the settings dialog
         // KWallet not loaded, tell user that we won't save the password
         int result = KMessageBox::questionYesNoCancel( (QWidget*)this,
                 i18n( "Cannot find KWallet, credentials will be saved in plaintext, continue?" ),
@@ -141,12 +134,6 @@ SpotifyConfig::save()
         }
     }
 
-    // Set default resolver path
-    if( m_resolverPath.isEmpty() )
-        m_resolverPath = KStandardDirs::locateLocal( "data",
-                           QString("amarok/%1").arg( defaultResolverName() ) );
-
-    config.writeEntry( "resolver", m_resolverPath );
     config.writeEntry( "highquality", m_highQuality );
 }
 
@@ -157,36 +144,6 @@ SpotifyConfig::reset()
     warning() << "Reset Spotify config";
     m_username = "";
     m_password = "";
-    // Use the the API key embedded in Spotify resolver
-    m_resolverPath = KStandardDirs::locateLocal( "data",
-                       QString("amarok/%1").arg( defaultResolverName() ) );
-    debug() << "Resolver path: " << m_resolverPath;
-}
-
-const QString
-SpotifyConfig::supportedPlatformName()
-{
-#ifdef Q_OS_WIN32
-    return "win32";
-#else
-#ifdef Q_OS_LINUX
-    return QString("linux%1").arg(QSysInfo::WordSize);
-#else
-    return QString();
-#endif
-#endif
-}
-
-const QString
-SpotifyConfig::defaultResolverName()
-{
-    return QString("spotify_resolver_%1").arg(supportedPlatformName());
-}
-
-const QString
-SpotifyConfig::resolverDownloadPath()
-{
-    return KStandardDirs::locateLocal( "data", "amarok" );
 }
 
 #include "SpotifyConfig.moc"
diff --git a/src/core-impl/collections/spotifycollection/SpotifyConfig.h \
b/src/core-impl/collections/spotifycollection/SpotifyConfig.h index 05373f2..581e1cd 100644
--- a/src/core-impl/collections/spotifycollection/SpotifyConfig.h
+++ b/src/core-impl/collections/spotifycollection/SpotifyConfig.h
@@ -31,9 +31,6 @@ public:
     ~SpotifyConfig();
 
     static const char *configSectionName() { return "Collection_Spotify"; }
-    static const QString supportedPlatformName();
-    static const QString defaultResolverName();
-    static const QString resolverDownloadPath();
 
     const QString username() const { return m_username; }
     void setUsername( const QString& username ) { m_username = username; }
@@ -41,11 +38,6 @@ public:
     const QString password() const { return m_password; }
     void setPassword( const QString& password ) { m_password = password; }
 
-    const QString resolverPath() const { return m_resolverPath; }
-    void setResolverPath( const QString& path ) { m_resolverPath = path; }
-
-    const QString resolverDownloadUrl() const { return m_resolverDownloadUrl + defaultResolverName() + \
                ".zip"; }
-
     bool highQuality() const { return m_highQuality; }
     void setHighQuality( const bool highquality ) { m_highQuality = highquality; }
 
@@ -57,9 +49,7 @@ public slots:
 private:
     QString m_username;
     QString m_password;
-    QString m_resolverPath;
     bool m_highQuality;
-    const static QString m_resolverDownloadUrl;
 
     KWallet::Wallet* m_wallet;
 };
diff --git a/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.cpp \
b/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.cpp index 3809b6a..8c9c642 100644
--- a/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.cpp
+++ b/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.cpp
@@ -1,14 +1,140 @@
+/****************************************************************************************
+ * Copyright (c) 2012 Ryan Feng <odayfans@gmail.com>                                    *
+ * Copyright (c) 2012 Bart Cerneels <bart.cerneels@kde.org>                             *
+ *                                                                                      *
+ * This program is free software; you can redistribute it and/or modify it under        *
+ * the terms of the GNU General Public License as published by the Free Software        *
+ * Foundation; either version 2 of the License, or (at your option) any later           *
+ * version.                                                                             *
+ *                                                                                      *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
+ *                                                                                      *
+ * You should have received a copy of the GNU General Public License along with         *
+ * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
+ ****************************************************************************************/
+
 #include "SpotifyDownloadDialog.h"
 #include "ui_SpotifyDownloadDialog.h"
 
+#include "SpotifyCollection.h"
+
+#include "core/support/Debug.h"
+#include "network/NetworkAccessManagerProxy.h"
+#include "support/Controller.h"
+
+#include <KZip>
+
+#include <QBuffer>
+#include <QFile>
+
 SpotifyDownloadDialog::SpotifyDownloadDialog(QWidget *parent) :
     QDialog(parent),
-    ui(new Ui::SpotifyDownloadDialog)
+    m_ui(new Ui::SpotifyDownloadDialog)
+  , m_downloadReply( 0 )
 {
-    ui->setupUi(this);
+    m_ui->setupUi(this);
+    m_ui->messageWidget->hide();
+    connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(tryDownloadResolver()));
+    connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
+    if( Collections::SpotifyCollection::supportedPlatformName().isEmpty() )
+    {
+        m_ui->messageWidget->setText(i18n( "Your platform is not currently "
+                                           "supported by Amarok Spotify resolver." ));
+        m_ui->messageWidget->animatedShow();
+        m_ui->buttonBox->setEnabled(false);
+    }
 }
 
 SpotifyDownloadDialog::~SpotifyDownloadDialog()
 {
-    delete ui;
+    delete m_ui;
+}
+
+void
+SpotifyDownloadDialog::tryDownloadResolver()
+{
+    debug() << "Trying to download: " << Collections::SpotifyCollection::resolverDownloadUrl();
+
+    NetworkAccessManagerProxy* manager = The::networkAccessManager();
+    QNetworkRequest request( Collections::SpotifyCollection::resolverDownloadUrl() );
+    QNetworkReply* reply = manager->get( request );
+    m_downloadReply = reply;
+
+    connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
+            this, SLOT( slotDownloadError( QNetworkReply::NetworkError ) ) );
+    connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ),
+            this, SLOT( slotDownloadProgress( qint64, qint64 ) ) );
+    connect( reply, SIGNAL( finished() ),
+            this, SLOT( slotDownloadFinished() ) );
+
+    //set-up progress bar
+    m_ui->progDownload->setMinimum( 0 );
+    m_ui->progDownload->setMaximum( 1000 );
+    m_ui->progDownload->setValue( 0 );
+}
+
+void
+SpotifyDownloadDialog::slotDownloadError( QNetworkReply::NetworkError error )
+{
+    Q_UNUSED(error);
+    QNetworkReply *reply = qobject_cast<QNetworkReply *>(QObject::sender());
+    Q_ASSERT(reply);
+    m_ui->messageWidget->setText(i18n("There was an error while downloading"
+                "the spotify resolver. Error message: %1.").arg(reply->errorString()));
+    m_ui->messageWidget->animatedShow();
+}
+
+void
+SpotifyDownloadDialog::slotDownloadProgress( qint64 current, qint64 total )
+{
+    int value = (double)current/total * m_ui->progDownload->maximum();
+
+    m_ui->progDownload->setValue( value );
+}
+
+void
+SpotifyDownloadDialog::slotDownloadFinished()
+{
+    if( m_downloadReply->error() != QNetworkReply::NoError )
+    {
+        m_ui->messageWidget->setText(i18n("Downloading is interrupted due to %1")
+                                        .arg(m_downloadReply->errorString()));
+        m_ui->messageWidget->animatedShow();
+        return;
+    }
+
+    QByteArray data( m_downloadReply->readAll() );
+    QScopedPointer<QBuffer> data_buffer(new QBuffer(&data));
+
+    KZip archive( data_buffer.data() );
+    if( !archive.open( QIODevice::ReadOnly ) || !archive.directory() )
+    {
+        m_ui->messageWidget->setText(i18n("Failed to read data from the downloaded file. "
+                                          "Please try again later."));
+        m_ui->messageWidget->animatedShow();
+        return;
+    }
+
+    archive.directory()->copyTo( Collections::SpotifyCollection::resolverDownloadPath() );
+
+    QFile file( Collections::SpotifyCollection::resolverPath() );
+    if( !file.exists() )
+    {
+        //TODO: display error to the user
+        m_ui->messageWidget->setText(i18n( "Failed to extract the Spotify resolver to %1 "
+                                           "Please check if the path is writeable." )
+                                .arg( Collections::SpotifyCollection::resolverDownloadPath() ));
+        m_ui->messageWidget->animatedShow();
+        return;
+    }
+    file.setPermissions( file.permissions() | QFile::ExeUser );
+
+    // Notify controller to load the resolver
+    Spotify::Controller* controller = The::SpotifyController();
+    controller->setFilePath( Collections::SpotifyCollection::resolverPath() );
+    controller->reload();
+
+    accept();
 }
diff --git a/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.h \
b/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.h index 8ef2d46..e75b6d2 100644
--- a/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.h
+++ b/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.h
@@ -1,7 +1,24 @@
+/****************************************************************************************
+ * Copyright (c) 2012 Ryan Feng <odayfans@gmail.com>                                    *
+ * Copyright (c) 2012 Bart Cerneels <bart.cerneels@kde.org>                             *
+ *                                                                                      *
+ * This program is free software; you can redistribute it and/or modify it under        *
+ * the terms of the GNU General Public License as published by the Free Software        *
+ * Foundation; either version 2 of the License, or (at your option) any later           *
+ * version.                                                                             *
+ *                                                                                      *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
+ *                                                                                      *
+ * You should have received a copy of the GNU General Public License along with         *
+ * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
+ ****************************************************************************************/
 #ifndef SPOTIFYDOWNLOADDIALOG_H
 #define SPOTIFYDOWNLOADDIALOG_H
 
 #include <QDialog>
+#include <QNetworkReply>
 
 namespace Ui {
 class SpotifyDownloadDialog;
@@ -15,8 +32,15 @@ public:
     explicit SpotifyDownloadDialog(QWidget *parent = 0);
     ~SpotifyDownloadDialog();
 
+private Q_SLOTS:
+    void slotDownloadError( QNetworkReply::NetworkError error );
+    void slotDownloadProgress( qint64 current, qint64 total );
+    void slotDownloadFinished();
+    void tryDownloadResolver();
+
 private:
-    Ui::SpotifyDownloadDialog *ui;
+    Ui::SpotifyDownloadDialog *m_ui;
+    QNetworkReply *m_downloadReply;
 };
 
 #endif // SPOTIFYDOWNLOADDIALOG_H
diff --git a/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.ui \
b/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.ui index 77d380e..9a1e65c 100644
--- a/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.ui
+++ b/src/core-impl/collections/spotifycollection/SpotifyDownloadDialog.ui
@@ -27,6 +27,16 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
+    <widget class="KMessageWidget" name="messageWidget">
+     <property name="frameShape">
+      <enum>QFrame::StyledPanel</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Raised</enum>
+     </property>
+    </widget>
+   </item>
+   <item>
     <widget class="QLabel" name="messageLabel">
      <property name="sizePolicy">
       <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -133,6 +143,14 @@ p, li { white-space: pre-wrap; }
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>KMessageWidget</class>
+   <extends>QFrame</extends>
+   <header location="global">kmessagewidget.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>
diff --git a/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp \
b/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp index 3274f62..61813b6 100644
--- a/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp
+++ b/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp
@@ -16,34 +16,29 @@
 #define DEBUG_PREFIX "SpotifySettings"
 
 #include "SpotifySettingsDialog.h"
-#include "SpotifyDownloadDialog.h"
-
 #include "ui_SpotifySettingsWidget.h"
-#include "ui_SpotifyDownloadDialog.h"
+#include "SpotifyDownloadDialog.h"
+#include "SpotifyCollection.h"
 
 #include "core/support/Debug.h"
-#include "network/NetworkAccessManagerProxy.h"
 #include "support/Controller.h"
 
 #include <KLocale>
-#include <KMessageWidget>
-#include <KZip>
 
-#include <QBuffer>
-#include <QFile>
 #include <QScopedPointer>
 #include <QtGlobal>
 
-SpotifySettingsDialog::SpotifySettingsDialog( QWidget* parent, const QVariantList& args )
+SpotifySettingsDialog::SpotifySettingsDialog( QWidget *parent )
     : KDialog( parent )
     , m_settingsWidget(new Ui::SpotifySettingsWidget)
-    , m_downloadReply( 0 )
 {
-    DEBUG_BLOCK
-
-    Q_UNUSED( args )
-
-    debug() << "Creating Spotify settings object...";
+    debug() << "Checking Spotify resolver: " << Collections::SpotifyCollection::resolverPath();
+    if( !QFile::exists( Collections::SpotifyCollection::resolverPath() ) )
+    {
+        SpotifyDownloadDialog dialog;
+        m_config.reset();
+        dialog.exec();
+    }
 
     setCaption( i18n( "Spotify configuration" ) );
     setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply | KDialog::Default );
@@ -74,22 +69,6 @@ SpotifySettingsDialog::SpotifySettingsDialog( QWidget* parent, const QVariantLis
 
     // Load config from KConfig or KWallet
     load();
-
-    debug() << "Checking Spotify resolver: " << m_config.resolverPath();
-    if( !QFile::exists( m_config.resolverPath() ) )
-    {
-        if( SpotifyConfig::supportedPlatformName().isEmpty() )
-        {
-            m_settingsWidget->messageWidget->setText(i18n( "Your platform is not currently "
-                                           "supported by Amarok Spotify resolver." ));
-            m_settingsWidget->messageWidget->animatedShow();
-        }
-
-        m_downloadDialog = new Ui::SpotifyDownloadDialog;
-        m_config.reset();
-        connect(m_downloadDialog->buttonBox, SIGNAL(accepted()),
-                SLOT(tryDownloadResolver()));
-    }
 }
 
 SpotifySettingsDialog::~SpotifySettingsDialog()
@@ -136,14 +115,14 @@ SpotifySettingsDialog::slotTryLogin()
 
     if( !controller->running() || !controller->loaded() )
     {
-        controller->setFilePath( m_config.resolverPath() );
+        controller->setFilePath( Collections::SpotifyCollection::resolverPath() );
         controller->start();
     }
 
     connect(controller, SIGNAL(customMessage(QString,QVariantMap)),
                         SLOT(slotCustomMessage(QString,QVariantMap)));
     connect(controller, SIGNAL(loginSuccess(QString)), SLOT(slotLoginSuccess(QString)));
-    connect(controller, SIGNAL(loginFailed(QString)), SLOT(slotLogonFailed(QString)));
+    connect(controller, SIGNAL(loginFailed(QString)), SLOT(slotLoginFailed(QString)));
 
     controller->login( m_settingsWidget->lineUsername->text(),
                        m_settingsWidget->linePassword->text(),
@@ -158,7 +137,7 @@ void SpotifySettingsDialog::slotLoginSuccess(const QString &username)
     m_settingsWidget->messageWidget->animatedShow();
 }
 
-void SpotifySettingsDialog::slotLogonFailed(const QString &message)
+void SpotifySettingsDialog::slotLoginFailed(const QString &message)
 {
     //TODO: translate message
     m_settingsWidget->messageWidget->setText(message);
@@ -177,102 +156,6 @@ void SpotifySettingsDialog::slotCustomMessage(const QString &messageType,
 }
 
 void
-SpotifySettingsDialog::tryDownloadResolver()
-{
-    DEBUG_BLOCK
-
-    if( m_config.resolverPath().isEmpty() )
-        m_config.reset();
-
-    debug() << "Trying to download: " << m_config.resolverDownloadUrl();
-
-    NetworkAccessManagerProxy* manager = The::networkAccessManager();
-    QNetworkRequest request( m_config.resolverDownloadUrl() );
-    QNetworkReply* reply = manager->get( request );
-    m_downloadReply = reply;
-
-    connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
-            this, SLOT( slotDownloadError( QNetworkReply::NetworkError ) ) );
-    connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ),
-            this, SLOT( slotDownloadProgress( qint64, qint64 ) ) );
-    connect( reply, SIGNAL( finished() ),
-            this, SLOT( slotDownloadFinished() ) );
-
-    //set-up progress bar
-    m_downloadDialog->progDownload->setMinimum( 0 );
-    m_downloadDialog->progDownload->setMaximum( 1000 );
-    m_downloadDialog->progDownload->setValue( 0 );
-    m_downloadDialog->progDownload->show();
-
-    enableButtonApply( false );
-    enableButtonOk( false );
-    enableButton( Default, false );
-}
-
-void
-SpotifySettingsDialog::slotDownloadError( QNetworkReply::NetworkError error )
-{
-    Q_UNUSED( error )
-    //TODO: display error to the user
-}
-
-void
-SpotifySettingsDialog::slotDownloadProgress( qint64 current, qint64 total )
-{
-    int value = (double)current/total * m_downloadDialog->progDownload->maximum();
-
-    m_downloadDialog->progDownload->setValue( value );
-}
-
-void
-SpotifySettingsDialog::slotDownloadFinished()
-{
-    DEBUG_BLOCK
-
-    if( m_downloadReply->error() != QNetworkReply::NoError )
-    {
-        debug() << "Downloading is interrupted due to " << m_downloadReply->errorString();
-        //TODO: display error to the user
-        return;
-    }
-
-    debug() << "Download finished.";
-
-    m_downloadDialog->progDownload->hide();
-
-    QByteArray data( m_downloadReply->readAll() );
-    QScopedPointer<QBuffer> data_buffer(new QBuffer(&data));
-
-    KZip archive( data_buffer.data() );
-    if( !archive.open( QIODevice::ReadOnly ) || !archive.directory() )
-    {
-        //TODO: display error to the user
-        debug() << i18n( "Failed to read data from the downloaded file. Please try again later." );
-        return;
-    }
-
-    archive.directory()->copyTo( SpotifyConfig::resolverDownloadPath() );
-
-    QFile file( m_config.resolverPath() );
-    if( !file.exists() )
-    {
-        //TODO: display error to the user
-        debug() << i18n( "Failed to extract the Spotify resolver to %1 "
-                                        "Please check if the path is writeable." )
-                                 .arg( SpotifyConfig::resolverDownloadPath() );
-        return;
-    }
-    file.setPermissions( file.permissions() | QFile::ExeUser );
-
-    // Notify controller to load the resolver
-    Spotify::Controller* controller = The::SpotifyController();
-    controller->setFilePath( m_config.resolverPath() );
-    controller->reload();
-
-    //TODO: load the settingsWidget
-}
-
-void
 SpotifySettingsDialog::slotSettingsChanged()
 {
     emit changed( true );
@@ -282,9 +165,5 @@ void
 SpotifySettingsDialog::slotCancel()
 {
     close();
-
-    if( m_downloadReply )
-        m_downloadReply->deleteLater();
-
     deleteLater();
 }
diff --git a/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h \
b/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h index a486eb1..9bc0d1b 100644
--- a/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h
+++ b/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h
@@ -20,8 +20,6 @@
 
 #include <KDialog>
 
-#include <QNetworkReply>
-
 namespace Ui {
     class SpotifySettingsWidget;
     class SpotifyDownloadDialog;
@@ -34,7 +32,7 @@ class SpotifySettingsDialog: public KDialog
     Q_OBJECT
 
 public:
-    explicit SpotifySettingsDialog( QWidget *parent = 0, const QVariantList &args = QVariantList() );
+    explicit SpotifySettingsDialog( QWidget *parent = 0 );
     virtual ~SpotifySettingsDialog();
 
 signals:
@@ -50,20 +48,12 @@ public Q_SLOTS:
 private Q_SLOTS:
     void slotTryLogin();
     void slotLoginSuccess(const QString &user);
-    void slotLogonFailed(const QString &message);
+    void slotLoginFailed(const QString &message);
     void slotCustomMessage(const QString &messageType, const QVariantMap &map);
 
-    void slotDownloadError( QNetworkReply::NetworkError error );
-    void slotDownloadProgress( qint64 current, qint64 total );
-    void slotDownloadFinished();
-    void tryDownloadResolver();
-
 private:
     Ui::SpotifySettingsWidget *m_settingsWidget;
-    KMessageWidget *m_messageWidget;
-    Ui::SpotifyDownloadDialog *m_downloadDialog;
     SpotifyConfig m_config;
-    QNetworkReply* m_downloadReply;
 };
 
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic