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

List:       kde-commits
Subject:    [amarok/spotify] src/core-impl/collections/spotifycollection: Show spotify resolver messages in popu
From:       Bart Cerneels <bart.cerneels () kde ! org>
Date:       2012-11-06 20:22:52
Message-ID: 20121106202252.AC433A60CB () git ! kde ! org
[Download RAW message or body]

Git commit 29f063f3669115e29cca50ab43a2e76075cd33ac by Bart Cerneels.
Committed on 06/11/2012 at 20:44.
Pushed by shanachie into branch 'spotify'.

Show spotify resolver messages in popup widget.

M  +52   -49   src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp
M  +8    -1    src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h
M  +28   -10   src/core-impl/collections/spotifycollection/SpotifySettingsWidget.ui
M  +3    -2    src/core-impl/collections/spotifycollection/support/Controller.cpp
M  +1    -1    src/core-impl/collections/spotifycollection/support/Controller.h

http://commits.kde.org/amarok/29f063f3669115e29cca50ab43a2e76075cd33ac

diff --git a/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp \
b/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp index \
                82a0fc8..3274f62 100644
--- a/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp
+++ b/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.cpp
@@ -16,6 +16,7 @@
 #define DEBUG_PREFIX "SpotifySettings"
 
 #include "SpotifySettingsDialog.h"
+#include "SpotifyDownloadDialog.h"
 
 #include "ui_SpotifySettingsWidget.h"
 #include "ui_SpotifyDownloadDialog.h"
@@ -25,7 +26,7 @@
 #include "support/Controller.h"
 
 #include <KLocale>
-#include <KMessageBox>
+#include <KMessageWidget>
 #include <KZip>
 
 #include <QBuffer>
@@ -34,8 +35,9 @@
 #include <QtGlobal>
 
 SpotifySettingsDialog::SpotifySettingsDialog( QWidget* parent, const QVariantList& \
                args )
-: KDialog( parent )
-, m_downloadReply( 0 )
+    : KDialog( parent )
+    , m_settingsWidget(new Ui::SpotifySettingsWidget)
+    , m_downloadReply( 0 )
 {
     DEBUG_BLOCK
 
@@ -48,8 +50,8 @@ SpotifySettingsDialog::SpotifySettingsDialog( QWidget* parent, \
const QVariantLis  enableButtonApply( false );
 
     QWidget *w = new QWidget(this);
-    m_settingsWidget = new Ui::SpotifySettingsWidget;
     m_settingsWidget->setupUi( w );
+    m_settingsWidget->messageWidget->hide();
     setMainWidget( w );
 
     connect( this, SIGNAL( okClicked() ),
@@ -78,28 +80,15 @@ SpotifySettingsDialog::SpotifySettingsDialog( QWidget* parent, \
const QVariantLis  {
         if( SpotifyConfig::supportedPlatformName().isEmpty() )
         {
-            KMessageBox::information( this,
-                                      i18n( "Your platform is not currently \
                supported by Amarok Spotify resolver." ),
-                                      i18n( "Spotify resolver" ) );
-            slotCancel();
-            return;
+            m_settingsWidget->messageWidget->setText(i18n( "Your platform is not \
currently " +                                           "supported by Amarok Spotify \
resolver." )); +            m_settingsWidget->messageWidget->animatedShow();
         }
 
-        int res = KMessageBox::questionYesNo( this,
-                    i18n( "Spotify resolver is missing or not installed correctly on \
                your system."
-                          "This program is required by Spotify collection."
-                          "Do you want to download and install it now?" ),
-                    i18n( "Spotify resolver" ) );
-        if( res == KMessageBox::Yes )
-        {
-            m_config.reset();
-            tryDownloadResolver();
-        }
-        else
-        {
-            // Close config dialog
-            slotCancel();
-        }
+        m_downloadDialog = new Ui::SpotifyDownloadDialog;
+        m_config.reset();
+        connect(m_downloadDialog->buttonBox, SIGNAL(accepted()),
+                SLOT(tryDownloadResolver()));
     }
 }
 
@@ -151,12 +140,42 @@ SpotifySettingsDialog::slotTryLogin()
         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))); +
     controller->login( m_settingsWidget->lineUsername->text(),
                        m_settingsWidget->linePassword->text(),
                        m_settingsWidget->checkHighQuality->isChecked() );
     save();
 }
 
+void SpotifySettingsDialog::slotLoginSuccess(const QString &username)
+{
+    m_settingsWidget->messageWidget->setText(i18n("%1 logged in").arg(username));
+    m_settingsWidget->messageWidget->setMessageType(KMessageWidget::Positive);
+    m_settingsWidget->messageWidget->animatedShow();
+}
+
+void SpotifySettingsDialog::slotLogonFailed(const QString &message)
+{
+    //TODO: translate message
+    m_settingsWidget->messageWidget->setText(message);
+    m_settingsWidget->messageWidget->setMessageType(KMessageWidget::Error);
+    m_settingsWidget->messageWidget->animatedShow();
+}
+
+void SpotifySettingsDialog::slotCustomMessage(const QString &messageType,
+                                              const QVariantMap &map)
+{
+    debug() << messageType;
+    debug() << map;
+    //TODO: take message from map and display in m_settingsWidget->messageWidget
+    m_settingsWidget->messageWidget->setText("custom message received");
+    m_settingsWidget->messageWidget->animatedShow();
+}
+
 void
 SpotifySettingsDialog::tryDownloadResolver()
 {
@@ -194,10 +213,7 @@ void
 SpotifySettingsDialog::slotDownloadError( QNetworkReply::NetworkError error )
 {
     Q_UNUSED( error )
-
-    KMessageBox::error( this, i18n( "Error occured while downloading Spotify \
                resolver." ));
-
-    slotCancel();
+    //TODO: display error to the user
 }
 
 void
@@ -216,12 +232,7 @@ SpotifySettingsDialog::slotDownloadFinished()
     if( m_downloadReply->error() != QNetworkReply::NoError )
     {
         debug() << "Downloading is interrupted due to " << \
                m_downloadReply->errorString();
-        KMessageBox::warningYesNo( this,
-                i18n( "Error occured while downloading Spotify resolver,"
-                      "please check your internet connection and try again later." ) \
                );
-
-        // Don't show the settings dialog
-        slotCancel();
+        //TODO: display error to the user
         return;
     }
 
@@ -235,9 +246,8 @@ SpotifySettingsDialog::slotDownloadFinished()
     KZip archive( data_buffer.data() );
     if( !archive.open( QIODevice::ReadOnly ) || !archive.directory() )
     {
-        KMessageBox::error( this, i18n( "Failed to read data from the downloaded \
                file. "
-                                        "Please try again later." ) );
-        slotCancel();
+        //TODO: display error to the user
+        debug() << i18n( "Failed to read data from the downloaded file. Please try \
again later." );  return;
     }
 
@@ -246,9 +256,10 @@ SpotifySettingsDialog::slotDownloadFinished()
     QFile file( m_config.resolverPath() );
     if( !file.exists() )
     {
-        KMessageBox::error( this, i18n( "Failed to extract the Spotify resolver to \
                %1 "
-                                        "Please check if the path is writeable." \
                ).arg( SpotifyConfig::resolverDownloadPath() ) );
-        slotCancel();
+        //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 );
@@ -258,15 +269,7 @@ SpotifySettingsDialog::slotDownloadFinished()
     controller->setFilePath( m_config.resolverPath() );
     controller->reload();
 
-    // Restore widgets
-    m_downloadDialog->progDownload->hide();
-    m_settingsWidget->frameMain->show();
-    m_settingsWidget->lblNote->show();
-
-    enableButtonOk( true );
-    enableButton( Default, true );
-
-    adjustSize();
+    //TODO: load the settingsWidget
 }
 
 void
diff --git a/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h \
b/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h index \
                b0491e7..a486eb1 100644
--- a/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h
+++ b/src/core-impl/collections/spotifycollection/SpotifySettingsDialog.h
@@ -27,6 +27,8 @@ namespace Ui {
     class SpotifyDownloadDialog;
 }
 
+class KMessageWidget;
+
 class SpotifySettingsDialog: public KDialog
 {
     Q_OBJECT
@@ -47,13 +49,18 @@ public Q_SLOTS:
 
 private Q_SLOTS:
     void slotTryLogin();
+    void slotLoginSuccess(const QString &user);
+    void slotLogonFailed(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:
-    void tryDownloadResolver();
     Ui::SpotifySettingsWidget *m_settingsWidget;
+    KMessageWidget *m_messageWidget;
     Ui::SpotifyDownloadDialog *m_downloadDialog;
     SpotifyConfig m_config;
     QNetworkReply* m_downloadReply;
diff --git a/src/core-impl/collections/spotifycollection/SpotifySettingsWidget.ui \
b/src/core-impl/collections/spotifycollection/SpotifySettingsWidget.ui index \
                167c233..cec44ed 100644
--- a/src/core-impl/collections/spotifycollection/SpotifySettingsWidget.ui
+++ b/src/core-impl/collections/spotifycollection/SpotifySettingsWidget.ui
@@ -7,24 +7,24 @@
     <x>0</x>
     <y>0</y>
     <width>320</width>
-    <height>263</height>
+    <height>319</height>
    </rect>
   </property>
   <property name="windowTitle">
-   <string>Form</string>
+   <string>Spotify Settings</string>
   </property>
-  <layout class="QGridLayout" name="gridLayout">
-   <item row="4" column="0">
-    <widget class="QLabel" name="lblNote">
-     <property name="text">
-      <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Note: &lt;br/&gt;Spotify \
service is only avaiable in certain countries. And content and policy may vary in \
different regions.&lt;/p&gt;&lt;p&gt;Only Spotify Premium user can use this feature. \
You may need to subscribe Premium first to continue using it with \
Amarok.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> +  <layout class="QVBoxLayout" \
name="verticalLayout_2"> +   <item>
+    <widget class="KMessageWidget" name="messageWidget">
+     <property name="frameShape">
+      <enum>QFrame::StyledPanel</enum>
      </property>
-     <property name="wordWrap">
-      <bool>true</bool>
+     <property name="frameShadow">
+      <enum>QFrame::Raised</enum>
      </property>
     </widget>
    </item>
-   <item row="3" column="0">
+   <item>
     <widget class="QFrame" name="frameMain">
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
@@ -65,8 +65,26 @@
      </layout>
     </widget>
    </item>
+   <item>
+    <widget class="QLabel" name="lblNote">
+     <property name="text">
+      <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Note: &lt;br/&gt;Spotify \
service is only avaiable in certain countries. And content and policy may vary in \
different regions.&lt;/p&gt;&lt;p&gt;Only Spotify Premium user can use this feature. \
You may need to subscribe Premium first to continue using it with \
Amarok.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> +     </property>
+     <property name="wordWrap">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </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/support/Controller.cpp \
b/src/core-impl/collections/spotifycollection/support/Controller.cpp index \
                142f3ed..b6e63e7 100644
--- a/src/core-impl/collections/spotifycollection/support/Controller.cpp
+++ b/src/core-impl/collections/spotifycollection/support/Controller.cpp
@@ -564,6 +564,7 @@ Controller::handleLoginResponse( const QVariantMap& map )
 {
     bool success = map["success"].toBool();
     QString user = map["username"].toString();
+    QString message = map["message"].toString();
     if( success )
     {
         showMessage( i18n( "Logged in to Spotify as %1" ).arg( user ) );
@@ -572,7 +573,7 @@ Controller::handleLoginResponse( const QVariantMap& map )
     else
     {
         showMessage( i18n( "Spotify login failed" ) );
-        emit loginFailed();
+        emit loginFailed( message );
     }
 
     m_loggedIn = success;
@@ -607,7 +608,7 @@ Controller::handleUserchanged( const QVariantMap& map )
 void
 Controller::handleSpotifyError( const QVariantMap& map )
 {
-    Q_UNUSED( map )
+    emit customMessage("SpotifyError", map);
 }
 
 void
diff --git a/src/core-impl/collections/spotifycollection/support/Controller.h \
b/src/core-impl/collections/spotifycollection/support/Controller.h index \
                5f78f0f..ae64497 100644
--- a/src/core-impl/collections/spotifycollection/support/Controller.h
+++ b/src/core-impl/collections/spotifycollection/support/Controller.h
@@ -140,7 +140,7 @@ signals:
 
     void userChanged();
     void loginSuccess( const QString& user );
-    void loginFailed();
+    void loginFailed( const QString &message );
 
     void spotifyReady();
     void queryReady( const Spotify::Query* query );


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

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