mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-01-17 14:28:24 +01:00
Merge pull request #436 from tomahawk-player/makeresolverdevelopmentgreatagain
Show debugger for script errors
This commit is contained in:
commit
f13ea2f6df
@ -37,6 +37,7 @@ set( libGuiSources
|
||||
jobview/ErrorStatusMessage.cpp
|
||||
jobview/IndexingJobItem.cpp
|
||||
jobview/InboxJobItem.cpp
|
||||
jobview/ScriptErrorStatusMessage.cpp
|
||||
|
||||
playlist/InboxModel.cpp
|
||||
playlist/InboxView.cpp
|
||||
|
@ -33,6 +33,12 @@ JobStatusItem::~JobStatusItem()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JobStatusItem::activated()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
JobStatusItem::allowMultiLine() const
|
||||
{
|
||||
|
@ -53,6 +53,8 @@ public:
|
||||
virtual QString mainText() const = 0;
|
||||
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
|
||||
* instead of showing each individually. In this case, the right column from the item will be ignored
|
||||
|
@ -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( customDelegateJobRemoved( int ) ), this, SLOT( customDelegateJobRemoved( int ) ) );
|
||||
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 )
|
||||
{
|
||||
@ -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
|
||||
JobStatusView::checkCount()
|
||||
{
|
||||
|
@ -59,6 +59,7 @@ private slots:
|
||||
void customDelegateJobInserted( int row, JobStatusItem* item );
|
||||
void customDelegateJobRemoved( int row );
|
||||
void refreshDelegates();
|
||||
void onItemActivated( const QModelIndex& index );
|
||||
|
||||
private:
|
||||
QListView* m_view;
|
||||
|
37
src/libtomahawk/jobview/ScriptErrorStatusMessage.cpp
Normal file
37
src/libtomahawk/jobview/ScriptErrorStatusMessage.cpp
Normal 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();
|
||||
}
|
||||
|
39
src/libtomahawk/jobview/ScriptErrorStatusMessage.h
Normal file
39
src/libtomahawk/jobview/ScriptErrorStatusMessage.h
Normal 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
|
@ -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
|
||||
JSAccount::serializeQVariantMap( const QVariantMap& map )
|
||||
{
|
||||
|
@ -69,6 +69,8 @@ public:
|
||||
void setResolver( JSResolver* resolver );
|
||||
void scriptPluginFactory( const QString& type, const scriptobject_ptr& object ) override;
|
||||
|
||||
void showDebugger() override;
|
||||
|
||||
static QString serializeQVariantMap(const QVariantMap& map);
|
||||
|
||||
void reportNativeScriptJobResult( int resultId, const QVariantMap& result ) override;
|
||||
|
@ -255,6 +255,12 @@ ScriptAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr&
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptAccount::showDebugger()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptAccount::onJobDeleted( const QString& jobId )
|
||||
{
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
|
||||
virtual void scriptPluginFactory( const QString& type, const scriptobject_ptr& object );
|
||||
|
||||
virtual void showDebugger();
|
||||
|
||||
// helpers
|
||||
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
|
||||
ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType );
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
#include "jobview/ErrorStatusMessage.h"
|
||||
#include "jobview/ScriptErrorStatusMessage.h"
|
||||
#include "jobview/JobStatusModel.h"
|
||||
#include "jobview/JobStatusView.h"
|
||||
#include "utils/Logger.h"
|
||||
@ -51,13 +51,13 @@ ScriptEngine::ScriptEngine( JSAccount* parent )
|
||||
settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
|
||||
settings()->setOfflineStorageDefaultQuota(100 * 1024 * 1024 /* 100 Mb */);
|
||||
settings()->setOfflineWebApplicationCacheQuota(100 * 1024 * 1024 /* 100 Mb */);
|
||||
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
|
||||
|
||||
// HACK
|
||||
QStringList cmdArgs = QCoreApplication::instance()->arguments();
|
||||
int position = cmdArgs.indexOf( "--show-inspector" ) + 1;
|
||||
if ( position > 0 && !cmdArgs.at( position ).isEmpty() && parent->name().contains( cmdArgs.at( position ), Qt::CaseInsensitive ) ) {
|
||||
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
|
||||
QMetaObject::invokeMethod( this, "initWebInspector", Qt::QueuedConnection );
|
||||
QMetaObject::invokeMethod( this, "showWebInspector", Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
// 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
|
||||
ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID )
|
||||
{
|
||||
tLog() << "JAVASCRIPT:" << QString( "%1:%2" ).arg( m_scriptPath ).arg( lineNumber ) << message << sourceID;
|
||||
#ifdef QT_DEBUG
|
||||
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
|
||||
}
|
||||
|
||||
@ -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
|
||||
ScriptEngine::shouldInterruptJavaScript()
|
||||
{
|
||||
|
@ -49,13 +49,13 @@ public:
|
||||
|
||||
public slots:
|
||||
bool shouldInterruptJavaScript();
|
||||
void showWebInspector();
|
||||
|
||||
protected:
|
||||
virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID );
|
||||
|
||||
private slots:
|
||||
void sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errlist );
|
||||
void initWebInspector();
|
||||
|
||||
private:
|
||||
JSAccount* m_parent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user