mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
A bit nicer resolver error handling
This commit is contained in:
@@ -67,7 +67,8 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
enum ErrorState {
|
enum ErrorState {
|
||||||
NoError,
|
NoError,
|
||||||
FileNotFound
|
FileNotFound,
|
||||||
|
FailedToLoad
|
||||||
};
|
};
|
||||||
|
|
||||||
ExternalResolver( const QString& filePath ) { m_filePath = filePath; }
|
ExternalResolver( const QString& filePath ) { m_filePath = filePath; }
|
||||||
|
@@ -170,6 +170,8 @@ QtScriptResolver::QtScriptResolver( const QString& scriptPath )
|
|||||||
tLog() << Q_FUNC_INFO << "Loading JS resolver:" << scriptPath;
|
tLog() << Q_FUNC_INFO << "Loading JS resolver:" << scriptPath;
|
||||||
|
|
||||||
m_engine = new ScriptEngine( this );
|
m_engine = new ScriptEngine( this );
|
||||||
|
m_name = QFileInfo( filePath() ).baseName();
|
||||||
|
|
||||||
if ( !QFile::exists( filePath() ) )
|
if ( !QFile::exists( filePath() ) )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Failed loading JavaScript resolver:" << scriptPath;
|
tLog() << Q_FUNC_INFO << "Failed loading JavaScript resolver:" << scriptPath;
|
||||||
|
@@ -59,6 +59,9 @@ ScriptResolver::ScriptResolver( const QString& exe )
|
|||||||
if ( !TomahawkUtils::nam() )
|
if ( !TomahawkUtils::nam() )
|
||||||
return;
|
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();
|
sendConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,8 +128,8 @@ ScriptResolver::reload()
|
|||||||
m_error = Tomahawk::ExternalResolver::FileNotFound;
|
m_error = Tomahawk::ExternalResolver::FileNotFound;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_proc.start( filePath() );
|
|
||||||
m_error = Tomahawk::ExternalResolver::NoError;
|
m_error = Tomahawk::ExternalResolver::NoError;
|
||||||
|
m_proc.start( filePath() );
|
||||||
|
|
||||||
sendConfig();
|
sendConfig();
|
||||||
}
|
}
|
||||||
@@ -271,6 +274,9 @@ ScriptResolver::cmdExited( int code, QProcess::ExitStatus status )
|
|||||||
tLog() << Q_FUNC_INFO << "SCRIPT EXITED, code" << code << "status" << status << filePath();
|
tLog() << Q_FUNC_INFO << "SCRIPT EXITED, code" << code << "status" << status << filePath();
|
||||||
Tomahawk::Pipeline::instance()->removeResolver( this );
|
Tomahawk::Pipeline::instance()->removeResolver( this );
|
||||||
|
|
||||||
|
m_error = ExternalResolver::FailedToLoad;
|
||||||
|
emit changed();
|
||||||
|
|
||||||
if ( m_stopped )
|
if ( m_stopped )
|
||||||
{
|
{
|
||||||
tLog() << "*** Script resolver stopped ";
|
tLog() << "*** Script resolver stopped ";
|
||||||
|
@@ -53,7 +53,9 @@ ResolverConfigDelegate::paint( QPainter* painter, const QStyleOptionViewItem& op
|
|||||||
path.setItalic( true );
|
path.setItalic( true );
|
||||||
path.setPointSize( path.pointSize() - 1 );
|
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 bfm( name );
|
||||||
QFontMetrics sfm( path );
|
QFontMetrics sfm( path );
|
||||||
@@ -97,14 +99,20 @@ ResolverConfigDelegate::paint( QPainter* painter, const QStyleOptionViewItem& op
|
|||||||
painter->save();
|
painter->save();
|
||||||
painter->setFont( path );
|
painter->setFont( path );
|
||||||
QString pathStr = index.data( ResolversModel::ResolverPath ).toString();
|
QString pathStr = index.data( ResolversModel::ResolverPath ).toString();
|
||||||
if( fileFound )
|
if( error )
|
||||||
{
|
{
|
||||||
painter->setPen( QColor( Qt::red ).lighter( 150 ) );
|
painter->setPen( QColor( Qt::red ).lighter( 150 ) );
|
||||||
pathStr = tr( "Not found: %1" ).arg( pathStr );
|
} else {
|
||||||
} else
|
|
||||||
{
|
|
||||||
painter->setPen( Qt::gray );
|
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 );
|
textRect.moveTop( itemRect.height() / 2 + top );
|
||||||
pathStr = sfm.elidedText( pathStr, Qt::ElideMiddle, textRect.width() );
|
pathStr = sfm.elidedText( pathStr, Qt::ElideMiddle, textRect.width() );
|
||||||
painter->drawText( textRect, pathStr );
|
painter->drawText( textRect, pathStr );
|
||||||
|
Reference in New Issue
Block a user