From be76cc49d3e65979a4ee64c4dac0126c52d2635e Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 13 May 2012 17:36:32 -0400 Subject: [PATCH] add error handling to resolver in stall so we hide the spinner --- src/AccountDelegate.cpp | 8 ++++++ src/AccountDelegate.h | 2 ++ src/SettingsDialog.cpp | 5 ++-- src/libtomahawk/AtticaManager.cpp | 26 ++++++++++++------- src/libtomahawk/AtticaManager.h | 1 + src/libtomahawk/accounts/AccountModel.cpp | 17 ++++++++++++ src/libtomahawk/accounts/AccountModel.h | 3 +++ .../accounts/AccountModelFilterProxy.cpp | 9 +++++++ .../accounts/AccountModelFilterProxy.h | 2 ++ src/libtomahawk/utils/TomahawkUtils.cpp | 4 +-- 10 files changed, 63 insertions(+), 14 deletions(-) diff --git a/src/AccountDelegate.cpp b/src/AccountDelegate.cpp index 95e5ce418..505257a89 100644 --- a/src/AccountDelegate.cpp +++ b/src/AccountDelegate.cpp @@ -734,6 +734,14 @@ AccountDelegate::doneInstalling ( const QPersistentModelIndex& idx ) } +void +AccountDelegate::errorInstalling( const QPersistentModelIndex& idx ) +{ + // Just hide the loading spinner as we do after a successful install + doneInstalling( idx ); +} + + void AccountDelegate::doUpdateIndex( const QPersistentModelIndex& idx ) { diff --git a/src/AccountDelegate.h b/src/AccountDelegate.h index 2028eb09b..82e59f4d2 100644 --- a/src/AccountDelegate.h +++ b/src/AccountDelegate.h @@ -43,6 +43,8 @@ public: public slots: void startInstalling( const QPersistentModelIndex& idx ); void doneInstalling ( const QPersistentModelIndex& idx ); + void errorInstalling ( const QPersistentModelIndex& idx ); + void doUpdateIndex( const QPersistentModelIndex& idx ); diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 6cd2f5266..a03e36262 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -97,7 +97,7 @@ SettingsDialog::SettingsDialog( QWidget *parent ) ui->enableProxyCheckBox->setChecked( useProxy ); ui->proxyButton->setEnabled( useProxy ); - + createIcons(); #ifdef Q_WS_X11 ui->listWidget->setFrameShape( QFrame::StyledPanel ); @@ -142,6 +142,7 @@ SettingsDialog::SettingsDialog( QWidget *parent ) connect( m_accountProxy, SIGNAL( startInstalling( QPersistentModelIndex ) ), accountDelegate, SLOT( startInstalling(QPersistentModelIndex) ) ); connect( m_accountProxy, SIGNAL( doneInstalling( QPersistentModelIndex ) ), accountDelegate, SLOT( doneInstalling(QPersistentModelIndex) ) ); + connect( m_accountProxy, SIGNAL( errorInstalling( QPersistentModelIndex ) ), accountDelegate, SLOT( errorInstalling(QPersistentModelIndex) ) ); connect( m_accountProxy, SIGNAL( scrollTo( QModelIndex ) ), this, SLOT( scrollTo( QModelIndex ) ) ); ui->accountsView->setModel( m_accountProxy ); @@ -262,7 +263,7 @@ SettingsDialog::~SettingsDialog() } else qDebug() << "Settings dialog cancelled, NOT saving prefs."; - + delete ui; } diff --git a/src/libtomahawk/AtticaManager.cpp b/src/libtomahawk/AtticaManager.cpp index 4be683ea1..99479690c 100644 --- a/src/libtomahawk/AtticaManager.cpp +++ b/src/libtomahawk/AtticaManager.cpp @@ -503,6 +503,9 @@ AtticaManager::payloadFetched() QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() ); Q_ASSERT( reply ); + bool installedSuccessfully = false; + const QString resolverId = reply->property( "resolverId" ).toString(); + // we got a zip file, save it to a temporary file, then unzip it to our destination data dir if ( reply->error() == QNetworkReply::NoError ) { @@ -515,8 +518,6 @@ AtticaManager::payloadFetched() f.write( reply->readAll() ); f.close(); - bool installedSuccessfully = false; - const QString resolverId = reply->property( "resolverId" ).toString(); if ( m_resolverStates[ resolverId ].binary ) { // First ensure the signature matches. If we can't verify it, abort! @@ -554,19 +555,24 @@ AtticaManager::payloadFetched() installedSuccessfully = true; } } - - if ( installedSuccessfully ) - { - m_resolverStates[ resolverId ].state = Installed; - TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_resolverStates ); - emit resolverInstalled( resolverId ); - emit resolverStateChanged( resolverId ); - } } else { tLog() << "Failed to download attica payload...:" << reply->errorString(); } + + + if ( installedSuccessfully ) + { + m_resolverStates[ resolverId ].state = Installed; + TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_resolverStates ); + emit resolverInstalled( resolverId ); + emit resolverStateChanged( resolverId ); + } + else + { + emit resolverInstallationFailed( resolverId ); + } } diff --git a/src/libtomahawk/AtticaManager.h b/src/libtomahawk/AtticaManager.h index 70517c334..c5bf607a2 100644 --- a/src/libtomahawk/AtticaManager.h +++ b/src/libtomahawk/AtticaManager.h @@ -109,6 +109,7 @@ signals: void resolverStateChanged( const QString& resolverId ); void resolverInstalled( const QString& resolverId ); void resolverUninstalled( const QString& resolverId ); + void resolverInstallationFailed( const QString& resolverId ); private slots: void providerAdded( const Attica::Provider& ); diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index f58014435..5ddaf3cf1 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -35,6 +35,7 @@ AccountModel::AccountModel( QObject* parent ) : QAbstractListModel( parent ) { connect( AtticaManager::instance(), SIGNAL( resolversLoaded( Attica::Content::List ) ), this, SLOT( loadData() ) ); + connect( AtticaManager::instance(), SIGNAL( resolverInstallationFailed( QString ) ), this, SLOT( resolverInstallFailed( QString ) ) ); connect( AccountManager::instance(), SIGNAL( added( Tomahawk::Accounts::Account* ) ), this, SLOT( accountAdded( Tomahawk::Accounts::Account* ) ) ); connect( AccountManager::instance(), SIGNAL( removed( Tomahawk::Accounts::Account* ) ), this, SLOT( accountRemoved( Tomahawk::Accounts::Account* ) ) ); @@ -689,6 +690,22 @@ AccountModel::accountRemoved( Account* account ) } +void +AccountModel::resolverInstallFailed( const QString& resolverId ) +{ + for ( int i = 0; i < m_accounts.size(); i++ ) + { + if ( m_accounts[ i ]->type == AccountModelNode::AtticaType && m_accounts[ i ]->atticaContent.id() == resolverId ) + { + qDebug() << "Got failed attica install in account mode, emitting signal!"; + emit errorInstalling( index( i, 0, QModelIndex() ) ); + + return; + } + } +} + + int AccountModel::rowCount( const QModelIndex& ) const { diff --git a/src/libtomahawk/accounts/AccountModel.h b/src/libtomahawk/accounts/AccountModel.h index 68fcb89f6..e383b6ec6 100644 --- a/src/libtomahawk/accounts/AccountModel.h +++ b/src/libtomahawk/accounts/AccountModel.h @@ -96,6 +96,8 @@ signals: void startInstalling( const QPersistentModelIndex& idx ); void doneInstalling( const QPersistentModelIndex& idx ); + void errorInstalling( const QPersistentModelIndex& idx ); + private slots: void loadData(); @@ -103,6 +105,7 @@ private slots: void accountRemoved( Tomahawk::Accounts::Account* ); void accountStateChanged( Account*, Accounts::Account::ConnectionState ); + void resolverInstallFailed( const QString& resolverId ); private: QList< AccountModelNode* > m_accounts; QSet< QString > m_waitingForAtticaInstall; diff --git a/src/libtomahawk/accounts/AccountModelFilterProxy.cpp b/src/libtomahawk/accounts/AccountModelFilterProxy.cpp index 1a559faed..2e3b9bc8d 100644 --- a/src/libtomahawk/accounts/AccountModelFilterProxy.cpp +++ b/src/libtomahawk/accounts/AccountModelFilterProxy.cpp @@ -38,6 +38,7 @@ AccountModelFilterProxy::setSourceModel( QAbstractItemModel* sourceModel ) connect( sourceModel, SIGNAL( scrollTo( QModelIndex ) ), this, SLOT( onScrollTo( QModelIndex ) ) ); connect( sourceModel, SIGNAL( startInstalling( QPersistentModelIndex ) ), this, SLOT( onStartInstalling( QPersistentModelIndex ) ) ); connect( sourceModel, SIGNAL( doneInstalling( QPersistentModelIndex ) ), this, SLOT( onDoneInstalling( QPersistentModelIndex ) ) ); + connect( sourceModel, SIGNAL( doneInstalling( QPersistentModelIndex ) ), this, SLOT( errorInstalling( QPersistentModelIndex ) ) ); QSortFilterProxyModel::setSourceModel( sourceModel ); } @@ -86,3 +87,11 @@ AccountModelFilterProxy::onStartInstalling( const QPersistentModelIndex& idx ) { emit startInstalling( mapFromSource( idx ) ); } + + +void +AccountModelFilterProxy::onErrorInstalling( const QPersistentModelIndex& idx ) +{ + emit errorInstalling( mapFromSource( idx ) ); +} + diff --git a/src/libtomahawk/accounts/AccountModelFilterProxy.h b/src/libtomahawk/accounts/AccountModelFilterProxy.h index 75021c6b1..2a8868fd8 100644 --- a/src/libtomahawk/accounts/AccountModelFilterProxy.h +++ b/src/libtomahawk/accounts/AccountModelFilterProxy.h @@ -42,6 +42,7 @@ signals: void startInstalling( const QPersistentModelIndex& idx ); void doneInstalling( const QPersistentModelIndex& idx ); + void errorInstalling( const QPersistentModelIndex& idx ); protected: virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex& sourceParent ) const; @@ -51,6 +52,7 @@ private slots: void onStartInstalling( const QPersistentModelIndex& idx ); void onDoneInstalling( const QPersistentModelIndex& idx ); + void onErrorInstalling( const QPersistentModelIndex& idx ); private: Tomahawk::Accounts::AccountType m_filterType; diff --git a/src/libtomahawk/utils/TomahawkUtils.cpp b/src/libtomahawk/utils/TomahawkUtils.cpp index 7c3256861..101954090 100644 --- a/src/libtomahawk/utils/TomahawkUtils.cpp +++ b/src/libtomahawk/utils/TomahawkUtils.cpp @@ -783,7 +783,7 @@ extractScriptPayload( const QString& filename, const QString& resolverId ) bool -TomahawkUtils::unzipFileInFolder( const QString &zipFileName, const QDir &folder ) +unzipFileInFolder( const QString &zipFileName, const QDir &folder ) { Q_ASSERT( !zipFileName.isEmpty() ); Q_ASSERT( folder.exists() ); @@ -878,7 +878,7 @@ extractBinaryResolver( const QString& zipFilename, const QString& resolverId, QO qDebug() << "OS X: Copying binary resolver from to:" << src << dest; copyWithAuthentication( src, dest, 0 ); -#elif Q_OS_WIN +#elif defined(Q_OS_WIN) #endif // No support for binary resolvers on linux! Shouldn't even have been allowed to see/install..