diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index bc005f915..f13891fe2 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -37,6 +37,7 @@ set( libGuiSources jobview/ErrorStatusMessage.cpp jobview/IndexingJobItem.cpp jobview/InboxJobItem.cpp + jobview/ScriptErrorStatusMessage.cpp playlist/InboxModel.cpp playlist/InboxView.cpp diff --git a/src/libtomahawk/jobview/JobStatusItem.cpp b/src/libtomahawk/jobview/JobStatusItem.cpp index 8c2dd2b1d..004375704 100644 --- a/src/libtomahawk/jobview/JobStatusItem.cpp +++ b/src/libtomahawk/jobview/JobStatusItem.cpp @@ -33,6 +33,12 @@ JobStatusItem::~JobStatusItem() } +void +JobStatusItem::activated() +{ +} + + bool JobStatusItem::allowMultiLine() const { diff --git a/src/libtomahawk/jobview/JobStatusItem.h b/src/libtomahawk/jobview/JobStatusItem.h index 71d323df3..b8531eb40 100644 --- a/src/libtomahawk/jobview/JobStatusItem.h +++ b/src/libtomahawk/jobview/JobStatusItem.h @@ -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 diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index 71e9793b8..7dd5fec48 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -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 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() { diff --git a/src/libtomahawk/jobview/JobStatusView.h b/src/libtomahawk/jobview/JobStatusView.h index b12b6bc14..8447b2463 100644 --- a/src/libtomahawk/jobview/JobStatusView.h +++ b/src/libtomahawk/jobview/JobStatusView.h @@ -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; diff --git a/src/libtomahawk/jobview/ScriptErrorStatusMessage.cpp b/src/libtomahawk/jobview/ScriptErrorStatusMessage.cpp new file mode 100644 index 000000000..51ac2f995 --- /dev/null +++ b/src/libtomahawk/jobview/ScriptErrorStatusMessage.cpp @@ -0,0 +1,37 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2016, Dominik Schmidt + * + * 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 . + */ + +#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(); +} + diff --git a/src/libtomahawk/jobview/ScriptErrorStatusMessage.h b/src/libtomahawk/jobview/ScriptErrorStatusMessage.h new file mode 100644 index 000000000..f3ffb1110 --- /dev/null +++ b/src/libtomahawk/jobview/ScriptErrorStatusMessage.h @@ -0,0 +1,39 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2016, Dominik Schmidt + * + * 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 . + */ + +#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 diff --git a/src/libtomahawk/resolvers/JSAccount.cpp b/src/libtomahawk/resolvers/JSAccount.cpp index e7a4ba90f..8e81d12a6 100644 --- a/src/libtomahawk/resolvers/JSAccount.cpp +++ b/src/libtomahawk/resolvers/JSAccount.cpp @@ -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 ) { diff --git a/src/libtomahawk/resolvers/JSAccount.h b/src/libtomahawk/resolvers/JSAccount.h index 7ac6a8de3..0de2b5322 100644 --- a/src/libtomahawk/resolvers/JSAccount.h +++ b/src/libtomahawk/resolvers/JSAccount.h @@ -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; diff --git a/src/libtomahawk/resolvers/ScriptAccount.cpp b/src/libtomahawk/resolvers/ScriptAccount.cpp index d324a33c5..7b7542a27 100644 --- a/src/libtomahawk/resolvers/ScriptAccount.cpp +++ b/src/libtomahawk/resolvers/ScriptAccount.cpp @@ -255,6 +255,12 @@ ScriptAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr& } +void +ScriptAccount::showDebugger() +{ +} + + void ScriptAccount::onJobDeleted( const QString& jobId ) { diff --git a/src/libtomahawk/resolvers/ScriptAccount.h b/src/libtomahawk/resolvers/ScriptAccount.h index ef126a1e8..1af02cddd 100644 --- a/src/libtomahawk/resolvers/ScriptAccount.h +++ b/src/libtomahawk/resolvers/ScriptAccount.h @@ -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 ); diff --git a/src/libtomahawk/resolvers/ScriptEngine.cpp b/src/libtomahawk/resolvers/ScriptEngine.cpp index bd76d627b..e544344ec 100644 --- a/src/libtomahawk/resolvers/ScriptEngine.cpp +++ b/src/libtomahawk/resolvers/ScriptEngine.cpp @@ -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() { diff --git a/src/libtomahawk/resolvers/ScriptEngine.h b/src/libtomahawk/resolvers/ScriptEngine.h index c70bb7502..7cf1cb022 100644 --- a/src/libtomahawk/resolvers/ScriptEngine.h +++ b/src/libtomahawk/resolvers/ScriptEngine.h @@ -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& errlist ); - void initWebInspector(); private: JSAccount* m_parent;