1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

A bit nicer resolver error handling

This commit is contained in:
Leo Franchi 2011-09-13 22:35:30 -04:00
parent 9572c440ea
commit 1367d82006
4 changed files with 24 additions and 7 deletions

View File

@ -67,7 +67,8 @@ Q_OBJECT
public:
enum ErrorState {
NoError,
FileNotFound
FileNotFound,
FailedToLoad
};
ExternalResolver( const QString& filePath ) { m_filePath = filePath; }

View File

@ -170,6 +170,8 @@ QtScriptResolver::QtScriptResolver( const QString& scriptPath )
tLog() << Q_FUNC_INFO << "Loading JS resolver:" << scriptPath;
m_engine = new ScriptEngine( this );
m_name = QFileInfo( filePath() ).baseName();
if ( !QFile::exists( filePath() ) )
{
tLog() << Q_FUNC_INFO << "Failed loading JavaScript resolver:" << scriptPath;

View File

@ -59,6 +59,9 @@ ScriptResolver::ScriptResolver( const QString& exe )
if ( !TomahawkUtils::nam() )
return;
// set the name to the binary, if we launch properly we'll get the name the resolver reports
m_name = QFileInfo( filePath() ).baseName();
sendConfig();
}
@ -125,8 +128,8 @@ ScriptResolver::reload()
m_error = Tomahawk::ExternalResolver::FileNotFound;
else
{
m_proc.start( filePath() );
m_error = Tomahawk::ExternalResolver::NoError;
m_proc.start( filePath() );
sendConfig();
}
@ -271,6 +274,9 @@ ScriptResolver::cmdExited( int code, QProcess::ExitStatus status )
tLog() << Q_FUNC_INFO << "SCRIPT EXITED, code" << code << "status" << status << filePath();
Tomahawk::Pipeline::instance()->removeResolver( this );
m_error = ExternalResolver::FailedToLoad;
emit changed();
if ( m_stopped )
{
tLog() << "*** Script resolver stopped ";

View File

@ -53,7 +53,9 @@ ResolverConfigDelegate::paint( QPainter* painter, const QStyleOptionViewItem& op
path.setItalic( true );
path.setPointSize( path.pointSize() - 1 );
const bool fileFound = (Tomahawk::ExternalResolver::ErrorState)index.data( ResolversModel::ErrorState ).toInt() == Tomahawk::ExternalResolver::FileNotFound;
const bool error = (Tomahawk::ExternalResolver::ErrorState)index.data( ResolversModel::ErrorState ).toInt() != Tomahawk::ExternalResolver::NoError;
const bool fileNotFound = (Tomahawk::ExternalResolver::ErrorState)index.data( ResolversModel::ErrorState ).toInt() == Tomahawk::ExternalResolver::FileNotFound;
const bool failedToLoad = (Tomahawk::ExternalResolver::ErrorState)index.data( ResolversModel::ErrorState ).toInt() == Tomahawk::ExternalResolver::FailedToLoad;
QFontMetrics bfm( name );
QFontMetrics sfm( path );
@ -97,14 +99,20 @@ ResolverConfigDelegate::paint( QPainter* painter, const QStyleOptionViewItem& op
painter->save();
painter->setFont( path );
QString pathStr = index.data( ResolversModel::ResolverPath ).toString();
if( fileFound )
if( error )
{
painter->setPen( QColor( Qt::red ).lighter( 150 ) );
pathStr = tr( "Not found: %1" ).arg( pathStr );
} else
{
} else {
painter->setPen( Qt::gray );
}
if( fileNotFound ) {
pathStr = tr( "Not found: %1" ).arg( pathStr );
} else if ( failedToLoad )
{
pathStr = tr( "Failed to load: %1" ).arg( pathStr );
}
textRect.moveTop( itemRect.height() / 2 + top );
pathStr = sfm.elidedText( pathStr, Qt::ElideMiddle, textRect.width() );
painter->drawText( textRect, pathStr );