1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-13 12:31:52 +02:00

Show errors when fetching information from the network. Fixes TWK-515

This commit is contained in:
Leo Franchi 2012-02-25 19:39:35 -05:00
parent 42220a8c95
commit 36b2a585f9
20 changed files with 185 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -134,5 +134,6 @@
<file>data/images/no-album-no-case.png</file>
<file>data/images/rdio.png</file>
<file>data/sql/dbmigrate-27_to_28.sql</file>
<file>data/images/process-stop.png</file>
</qresource>
</RCC>

View File

@ -38,6 +38,7 @@ set( libGuiSources
jobview/PipelineStatusItem.cpp
jobview/TransferStatusItem.cpp
jobview/LatchedStatusItem.cpp
jobview/ErrorStatusMessage.cpp
infobar/infobar.cpp
@ -276,6 +277,7 @@ set( libGuiHeaders
jobview/PipelineStatusItem.h
jobview/TransferStatusItem.h
jobview/LatchedStatusItem.h
jobview/ErrorStatusMessage.h
thirdparty/Qocoa/qsearchfield.h
)

View File

@ -35,6 +35,8 @@
#include "utils/xspfloader.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#ifdef QCA2_FOUND
#include "utils/groovesharkparser.h"
#endif //QCA2_FOUND

View File

@ -23,6 +23,8 @@
#include "query.h"
#include "infosystem/infosystem.h"
#include "utils/xspfloader.h"
#include <QObject>
#include <QStringList>
#include <QMimeData>

View File

@ -0,0 +1,56 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ErrorStatusMessage.h"
#include "utils/tomahawkutils.h"
#include <QTimer>
QPixmap* ErrorStatusMessage::s_pixmap = 0;
ErrorStatusMessage::ErrorStatusMessage( const QString& message, int timeoutSecs ) :
JobStatusItem()
, m_message( message )
{
m_timer = new QTimer( this );
m_timer->setInterval( timeoutSecs * 1000 );
m_timer->setSingleShot( true );
connect( m_timer, SIGNAL( timeout() ), this, SIGNAL( finished() ) );
if ( !s_pixmap )
s_pixmap = new QPixmap( RESPATH "images/process-stop.png" );
m_timer->start();
}
QPixmap
ErrorStatusMessage::icon() const
{
Q_ASSERT( s_pixmap );
return *s_pixmap;
}
QString
ErrorStatusMessage::mainText() const
{
return m_message;
}

View File

@ -0,0 +1,47 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ERRORSTATUSMESSAGE_H
#define ERRORSTATUSMESSAGE_H
#include "JobStatusItem.h"
class QTimer;
class QPixmap;
class ErrorStatusMessage : public JobStatusItem
{
Q_OBJECT
public:
explicit ErrorStatusMessage( const QString& errorMessage, int defaultTimeoutSecs = 8 );
QString type() const { return "errormessage"; }
QString rightColumnText() const { return QString(); }
QPixmap icon() const;
QString mainText() const;
bool allowMultiLine() const { return true; }
private:
QString m_message;
QTimer* m_timer;
static QPixmap* s_pixmap;
};
#endif // ERRORSTATUSMESSAGE_H

View File

@ -23,14 +23,16 @@
#include <QPainter>
#include <QApplication>
#include <QListView>
#define ROW_HEIGHT 20
#define ICON_PADDING 1
#define PADDING 2
JobStatusDelegate::JobStatusDelegate( QObject* parent )
: QStyledItemDelegate ( parent )
, m_parentView( qobject_cast< QListView* >( parent ) )
{
Q_ASSERT( m_parentView );
}
JobStatusDelegate::~JobStatusDelegate()
@ -70,16 +72,36 @@ JobStatusDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
}
const int mainW = rightEdge - 3*PADDING - iconRect.right();
const bool allowMultiLine = index.data( JobStatusModel::AllowMultiLineRole ).toBool();
QString mainText = index.data( Qt::DisplayRole ).toString();
mainText = fm.elidedText( mainText, Qt::ElideRight, mainW );
painter->drawText( QRect( iconRect.right() + 2*PADDING, PADDING + opt.rect.y(), mainW, opt.rect.height() - 2*PADDING ), Qt::AlignLeft | Qt::AlignVCenter, mainText );
QTextOption to( Qt::AlignLeft | Qt::AlignVCenter );
if ( !allowMultiLine )
mainText = fm.elidedText( mainText, Qt::ElideRight, mainW );
else
to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
painter->drawText( QRect( iconRect.right() + 2*PADDING, PADDING + opt.rect.y(), mainW, opt.rect.height() - 2*PADDING ), mainText, to );
}
QSize
JobStatusDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
// return QStyledItemDelegate::sizeHint( option, index );
const int w = QStyledItemDelegate::sizeHint ( option, index ).width();
return QSize( w, ROW_HEIGHT );
const bool allowMultiLine = index.data( JobStatusModel::AllowMultiLineRole ).toBool();
if ( !allowMultiLine )
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT );
else if ( m_cachedMultiLineHeights.contains( index ) )
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), m_cachedMultiLineHeights[ index ] );
// Don't elide, but stretch across as many rows as required
QStyleOptionViewItemV4 opt = option;
initStyleOption( &opt, index );
const QString text = index.data( Qt::DisplayRole ).toString();
const int leftEdge = ICON_PADDING + ROW_HEIGHT + 2*PADDING;
const QRect rect = opt.fontMetrics.boundingRect( leftEdge, opt.rect.top(), m_parentView->width() - leftEdge, 200, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, text );
m_cachedMultiLineHeights.insert( index, rect.height() + 4*PADDING );
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), rect.height() + 4*PADDING );
}

View File

@ -22,6 +22,7 @@
#include <QStyledItemDelegate>
class QPainter;
class QListView;
class JobStatusDelegate : public QStyledItemDelegate
{
@ -33,6 +34,10 @@ public:
virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private:
mutable QHash< QPersistentModelIndex, int > m_cachedMultiLineHeights;
QListView* m_parentView;
};
#endif // JOBSTATUSDELEGATE_H

View File

@ -53,6 +53,7 @@ public:
* and a count will be shown instead.
*/
virtual bool collapseItem() const { return false; }
virtual bool allowMultiLine() const { return false; }
signals:
/// Ask for an update

View File

@ -100,6 +100,8 @@ JobStatusModel::data( const QModelIndex& index, int role ) const
else
return item->rightColumnText();
}
case AllowMultiLineRole:
return item->allowMultiLine();
}
return QVariant();

View File

@ -31,7 +31,8 @@ public:
enum JobRoles {
// DecorationRole is icon
// DisplayRole is main col
RightColumnRole = Qt::UserRole + 1
RightColumnRole = Qt::UserRole + 1,
AllowMultiLineRole = Qt::UserRole + 2
};
explicit JobStatusModel( QObject* parent = 0 );

View File

@ -56,9 +56,7 @@ JobStatusView::JobStatusView( AnimatedSplitter* parent )
m_view->setFrameShape( QFrame::NoFrame );
m_view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
// new QTreeWidgetItem( m_tree );
m_view->setUniformItemSizes( true );
m_view->setUniformItemSizes( false );
#ifndef Q_WS_WIN
QFont f = font();

View File

@ -27,6 +27,7 @@
#include "dropjob.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "dropjobnotifier.h"
#include "viewmanager.h"
@ -198,6 +199,7 @@ GroovesharkParser::groovesharkLookupFinished()
} else
{
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Grooveshark information from the network!" ) ) );
tLog() << "Error in network request to grooveshark for track decoding:" << r->errorString();
}

View File

@ -25,6 +25,7 @@
#include "sourcelist.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include <qjson/parser.h>
@ -166,6 +167,7 @@ ItunesParser::itunesResponseLookupFinished()
} else
{
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching iTunes information from the network!" ) ) );
tLog() << "Error in network request to Itunes for track decoding:" << r->errorString();
}

View File

@ -26,6 +26,7 @@
#include "dropjob.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "dropjobnotifier.h"
#include "viewmanager.h"
#include "sourcelist.h"
@ -189,6 +190,7 @@ RdioParser::rdioReturned()
} else
{
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Rdio information from the network!" ) ) );
tLog() << "Error in network request to Rdio for track decoding:" << r->errorString();
}

View File

@ -22,6 +22,9 @@
#include "utils/logger.h"
#include "utils/tomahawkutils.h"
#include "query.h"
#include "jobview/ErrorStatusMessage.h"
#include "jobview/JobStatusModel.h"
#include "jobview/JobStatusView.h"=
#include <qjson/parser.h>
@ -78,6 +81,9 @@ ShortenedLinkParser::lookupFinished()
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
Q_ASSERT( r );
if ( r->error() != QNetworkReply::NoError )
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Network error parsing shortened link!" ) ) );
QVariant redir = r->attribute( QNetworkRequest::RedirectionTargetAttribute );
if ( redir.isValid() && !redir.toUrl().isEmpty() )
{

View File

@ -26,6 +26,7 @@
#include "dropjob.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "dropjobnotifier.h"
#include "viewmanager.h"
@ -220,6 +221,7 @@ SpotifyParser::spotifyBrowseFinished()
} else
{
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Spotify information from the network!" ) ) );
tLog() << "Error in network request to Spotify for track decoding:" << r->errorString();
}

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011-2012, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,6 +25,9 @@
#include "utils/tomahawkutils.h"
#include "utils/logger.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "sourcelist.h"
#include "playlist.h"
@ -32,6 +36,20 @@
using namespace Tomahawk;
QString
XSPFLoader::errorToString( XSPFErrorCode error )
{
switch ( error )
{
case ParseError:
return tr( "Failed to parse contents of XSPF playlist" );
case InvalidTrackError:
return tr( "Some playlist entries were found without artist and track name, they will be omitted");
case FetchError:
return tr( "Failed to fetch the desired playlist from the network, or the desired file does not exist" );
}
}
XSPFLoader::XSPFLoader( bool autoCreate, bool autoUpdate, QObject *parent )
: QObject( parent )
, m_autoCreate( autoCreate )
@ -97,6 +115,7 @@ void
XSPFLoader::reportError()
{
emit error( FetchError );
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( errorToString( FetchError) ) );
deleteLater();
}

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011-2012, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -48,6 +49,8 @@ public:
void setOverrideTitle( const QString& newTitle );
void setAutoResolveTracks( bool autoResolve ) { m_autoResolve = autoResolve; }
static QString errorToString( XSPFErrorCode error );
signals:
void error( XSPFLoader::XSPFErrorCode error );
void ok( const Tomahawk::playlist_ptr& );