1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 20:00:13 +02:00

Merge pull request #436 from tomahawk-player/makeresolverdevelopmentgreatagain

Show debugger for script errors
This commit is contained in:
Christian Muehlhaeuser
2016-02-15 17:04:25 +01:00
13 changed files with 140 additions and 16 deletions

View File

@@ -37,6 +37,7 @@ set( libGuiSources
jobview/ErrorStatusMessage.cpp jobview/ErrorStatusMessage.cpp
jobview/IndexingJobItem.cpp jobview/IndexingJobItem.cpp
jobview/InboxJobItem.cpp jobview/InboxJobItem.cpp
jobview/ScriptErrorStatusMessage.cpp
playlist/InboxModel.cpp playlist/InboxModel.cpp
playlist/InboxView.cpp playlist/InboxView.cpp

View File

@@ -33,6 +33,12 @@ JobStatusItem::~JobStatusItem()
} }
void
JobStatusItem::activated()
{
}
bool bool
JobStatusItem::allowMultiLine() const JobStatusItem::allowMultiLine() const
{ {

View File

@@ -53,6 +53,8 @@ public:
virtual QString mainText() const = 0; virtual QString mainText() const = 0;
virtual QString rightColumnText() const { return QString(); }; virtual QString rightColumnText() const { return QString(); };
virtual void activated();
/** /**
* If collapse item is true, sending multiple items of the same type will "collapse" them into one * If collapse item is true, sending multiple items of the same type will "collapse" them into one
* instead of showing each individually. In this case, the right column from the item will be ignored * instead of showing each individually. In this case, the right column from the item will be ignored

View File

@@ -118,6 +118,7 @@ JobStatusView::setModel( JobStatusSortModel* m )
connect( m_view->model(), SIGNAL( customDelegateJobInserted( int, JobStatusItem* ) ), this, SLOT( customDelegateJobInserted( int, JobStatusItem* ) ) ); connect( m_view->model(), SIGNAL( customDelegateJobInserted( int, JobStatusItem* ) ), this, SLOT( customDelegateJobInserted( int, JobStatusItem* ) ) );
connect( m_view->model(), SIGNAL( customDelegateJobRemoved( int ) ), this, SLOT( customDelegateJobRemoved( int ) ) ); connect( m_view->model(), SIGNAL( customDelegateJobRemoved( int ) ), this, SLOT( customDelegateJobRemoved( int ) ) );
connect( m_view->model(), SIGNAL( refreshDelegates() ), this, SLOT( refreshDelegates() ) ); connect( m_view->model(), SIGNAL( refreshDelegates() ), this, SLOT( refreshDelegates() ) );
connect( m_view, SIGNAL( activated( QModelIndex ) ), this, SLOT( onItemActivated( QModelIndex ) ) );
foreach ( const QPointer<JobStatusItem> item, s_jobItems ) foreach ( const QPointer<JobStatusItem> item, s_jobItems )
{ {
@@ -184,6 +185,21 @@ JobStatusView::refreshDelegates()
} }
void
JobStatusView::onItemActivated( const QModelIndex& index )
{
QVariant itemVar = index.data( JobStatusModel::JobDataRole );
if ( !itemVar.canConvert< JobStatusItem* >() || !itemVar.value< JobStatusItem* >() )
{
tLog() << Q_FUNC_INFO << "unable to fetch JobStatusItem*";
return;
}
JobStatusItem* item = itemVar.value< JobStatusItem* >();
item->activated();
}
void void
JobStatusView::checkCount() JobStatusView::checkCount()
{ {

View File

@@ -59,6 +59,7 @@ private slots:
void customDelegateJobInserted( int row, JobStatusItem* item ); void customDelegateJobInserted( int row, JobStatusItem* item );
void customDelegateJobRemoved( int row ); void customDelegateJobRemoved( int row );
void refreshDelegates(); void refreshDelegates();
void onItemActivated( const QModelIndex& index );
private: private:
QListView* m_view; QListView* m_view;

View File

@@ -0,0 +1,37 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2016, Dominik Schmidt <domme@tomahawk-player.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 "ScriptErrorStatusMessage.h"
#include "../utils/Logger.h"
ScriptErrorStatusMessage::ScriptErrorStatusMessage( const QString& message, Tomahawk::ScriptAccount* account )
: ErrorStatusMessage( tr( "Script Error: %1" ).arg( message ) )
, m_account( account )
{
}
void
ScriptErrorStatusMessage::activated()
{
if ( m_account.isNull() )
return;
tDebug() << "ScriptErrorStatusMessage clicked: " << mainText() << m_account->name();
m_account->showDebugger();
}

View File

@@ -0,0 +1,39 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2016, Dominik Schmidt <domme@tomahawk-player.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 SCRIPTERRORSTATUSMESSAGE_H
#define SCRIPTERRORSTATUSMESSAGE_H
#include "ErrorStatusMessage.h"
#include "../resolvers/ScriptAccount.h"
#include "DllMacro.h"
class DLLEXPORT ScriptErrorStatusMessage : public ErrorStatusMessage
{
Q_OBJECT
public:
explicit ScriptErrorStatusMessage( const QString& scriptErrorMessage, Tomahawk::ScriptAccount* );
void activated() override;
private:
QPointer< Tomahawk::ScriptAccount > m_account;
};
#endif // SCRIPTERRORSTATUSMESSAGE_H

View File

@@ -67,6 +67,14 @@ JSAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr& obj
} }
void
JSAccount::showDebugger()
{
tLog() << Q_FUNC_INFO << name() << "Show debugger";
m_engine->showWebInspector();
}
QString QString
JSAccount::serializeQVariantMap( const QVariantMap& map ) JSAccount::serializeQVariantMap( const QVariantMap& map )
{ {

View File

@@ -69,6 +69,8 @@ public:
void setResolver( JSResolver* resolver ); void setResolver( JSResolver* resolver );
void scriptPluginFactory( const QString& type, const scriptobject_ptr& object ) override; void scriptPluginFactory( const QString& type, const scriptobject_ptr& object ) override;
void showDebugger() override;
static QString serializeQVariantMap(const QVariantMap& map); static QString serializeQVariantMap(const QVariantMap& map);
void reportNativeScriptJobResult( int resultId, const QVariantMap& result ) override; void reportNativeScriptJobResult( int resultId, const QVariantMap& result ) override;

View File

@@ -255,6 +255,12 @@ ScriptAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr&
} }
void
ScriptAccount::showDebugger()
{
}
void void
ScriptAccount::onJobDeleted( const QString& jobId ) ScriptAccount::onJobDeleted( const QString& jobId )
{ {

View File

@@ -76,6 +76,8 @@ public:
virtual void scriptPluginFactory( const QString& type, const scriptobject_ptr& object ); virtual void scriptPluginFactory( const QString& type, const scriptobject_ptr& object );
virtual void showDebugger();
// helpers // helpers
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist ); QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType ); ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType );

View File

@@ -21,7 +21,7 @@
#include "ScriptEngine.h" #include "ScriptEngine.h"
#include "jobview/ErrorStatusMessage.h" #include "jobview/ScriptErrorStatusMessage.h"
#include "jobview/JobStatusModel.h" #include "jobview/JobStatusModel.h"
#include "jobview/JobStatusView.h" #include "jobview/JobStatusView.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@@ -51,13 +51,13 @@ ScriptEngine::ScriptEngine( JSAccount* parent )
settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true ); settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
settings()->setOfflineStorageDefaultQuota(100 * 1024 * 1024 /* 100 Mb */); settings()->setOfflineStorageDefaultQuota(100 * 1024 * 1024 /* 100 Mb */);
settings()->setOfflineWebApplicationCacheQuota(100 * 1024 * 1024 /* 100 Mb */); settings()->setOfflineWebApplicationCacheQuota(100 * 1024 * 1024 /* 100 Mb */);
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
// HACK // HACK
QStringList cmdArgs = QCoreApplication::instance()->arguments(); QStringList cmdArgs = QCoreApplication::instance()->arguments();
int position = cmdArgs.indexOf( "--show-inspector" ) + 1; int position = cmdArgs.indexOf( "--show-inspector" ) + 1;
if ( position > 0 && !cmdArgs.at( position ).isEmpty() && parent->name().contains( cmdArgs.at( position ), Qt::CaseInsensitive ) ) { if ( position > 0 && !cmdArgs.at( position ).isEmpty() && parent->name().contains( cmdArgs.at( position ), Qt::CaseInsensitive ) ) {
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true ); QMetaObject::invokeMethod( this, "showWebInspector", Qt::QueuedConnection );
QMetaObject::invokeMethod( this, "initWebInspector", Qt::QueuedConnection );
} }
// Tomahawk is not a user agent // Tomahawk is not a user agent
@@ -74,24 +74,13 @@ ScriptEngine::ScriptEngine( JSAccount* parent )
} }
void
ScriptEngine::initWebInspector()
{
m_webInspector.reset( new QWebInspector() );
m_webInspector->setPage( this );
m_webInspector->setMinimumWidth( 800 );
m_webInspector->setMinimumHeight( 600 );
m_webInspector->show();
}
void void
ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID ) ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID )
{ {
tLog() << "JAVASCRIPT:" << QString( "%1:%2" ).arg( m_scriptPath ).arg( lineNumber ) << message << sourceID; tLog() << "JAVASCRIPT:" << QString( "%1:%2" ).arg( m_scriptPath ).arg( lineNumber ) << message << sourceID;
#ifdef QT_DEBUG #ifdef QT_DEBUG
QFileInfo scriptPath( m_scriptPath ); QFileInfo scriptPath( m_scriptPath );
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Resolver Error: %1:%2 %3" ).arg( scriptPath.fileName() ).arg( lineNumber ).arg( message ) ) ); JobStatusView::instance()->model()->addJob( new ScriptErrorStatusMessage( tr( "%1:%2 %3" ).arg( scriptPath.fileName() ).arg( lineNumber ).arg( message ), m_parent ) );
#endif #endif
} }
@@ -148,6 +137,21 @@ ScriptEngine::setScriptPath( const QString& scriptPath )
} }
void
ScriptEngine::showWebInspector()
{
if ( m_webInspector.isNull() )
{
m_webInspector.reset( new QWebInspector() );
m_webInspector->setPage( this );
m_webInspector->setMinimumWidth( 800 );
m_webInspector->setMinimumHeight( 600 );
}
m_webInspector->show();
}
bool bool
ScriptEngine::shouldInterruptJavaScript() ScriptEngine::shouldInterruptJavaScript()
{ {

View File

@@ -49,13 +49,13 @@ public:
public slots: public slots:
bool shouldInterruptJavaScript(); bool shouldInterruptJavaScript();
void showWebInspector();
protected: protected:
virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID ); virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID );
private slots: private slots:
void sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errlist ); void sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errlist );
void initWebInspector();
private: private:
JSAccount* m_parent; JSAccount* m_parent;