1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-09-14 16:02:33 +02:00

Compare commits

..

67 Commits

Author SHA1 Message Date
Dominik Schmidt
018e4276a9 Allow creating basic data types from QtConcurrent::run
When QObjects are created from QtConcurrent::run they live in a pooled thread that doesn't handle events/signals/slots properly
2016-02-18 00:51:02 +01:00
Christian Muehlhaeuser
dc80d19a08 Merge pull request #399 from tomahawk-player/things
Various download and branding improvements
2016-02-17 20:32:06 +01:00
Dominik Schmidt
93745b19ef Deployment scripts branding update 2016-02-17 19:37:46 +01:00
Dominik Schmidt
1b7b7ca4b3 Bump snorenotify requirement 2016-02-17 19:37:46 +01:00
Dominik Schmidt
3808e230d4 Make result more thread safe 2016-02-17 19:37:46 +01:00
Dominik Schmidt
0bdb8061e2 Do not set empty mimetype on results 2016-02-17 19:37:46 +01:00
Dominik Schmidt
87278456f4 Add download context menu to all playlist views but database collections 2016-02-17 19:37:46 +01:00
Dominik Schmidt
a5693d6663 Workaround preview widget flicker in column view 2016-02-17 19:37:46 +01:00
Dominik Schmidt
6416b34e8c Don't reset column sort order on collection updated 2016-02-17 19:37:45 +01:00
Dominik Schmidt
f95bd4aab8 Correctly paint hover state in DropDownButton 2016-02-17 19:37:45 +01:00
Dominik Schmidt
996d112ebb Fix DropDownButton font size and boldness 2016-02-17 19:37:45 +01:00
Dominik Schmidt
fc413ac103 Fix download all assert/crash 2016-02-17 19:37:45 +01:00
Dominik Schmidt
2020aad725 Download and branding improvements 2016-02-17 19:37:33 +01:00
Christian Muehlhaeuser
198201aec2 Don't try to reset hover-state if there is none. This speeds up collection browsing. 2016-02-17 12:15:24 +01:00
Christian Muehlhaeuser
6b84630ba1 Reset GridView's hover-state on wheel event. 2016-02-17 12:15:24 +01:00
Christian Muehlhaeuser
205dfca60d Don't use native windows for each widget. This is insane. Thanks Domme for figuring this out. 2016-02-17 01:57:39 +01:00
Dominik Schmidt
ca2da81132 Don't parse artists/albums for non-fulltext queries 2016-02-16 17:11:52 +01:00
Dominik Schmidt
08004ddbd4 Allow returning arrays or maps from resolve/search in JS 2016-02-16 16:47:58 +01:00
Dominik Schmidt
4dadbb5acd Support album and artist results in JSResolvers 2016-02-16 14:53:39 +01:00
Christian Muehlhaeuser
dee504c997 Use correct units for filesize. 2016-02-16 14:40:25 +01:00
Christian Muehlhaeuser
81dae62349 Merge pull request #438 from tomahawk-player/makeresolverdevelopmentgreatagain-wip
Add "Open Account Debugger" menu to ScriptAccounts in SettingsDialog
2016-02-16 02:00:41 +01:00
Dominik Schmidt
3c00f36df6 Add ScriptAccount debugger menu to SettingsDialog/AccountListWidget 2016-02-16 01:59:45 +01:00
Christian Muehlhaeuser
f13ea2f6df Merge pull request #436 from tomahawk-player/makeresolverdevelopmentgreatagain
Show debugger for script errors
2016-02-15 17:04:25 +01:00
Dominik Schmidt
2f4eb75745 Show debugger (WebInspector for JS) when clicking script errors 2016-02-14 13:50:05 +01:00
Dominik Schmidt
942eded60d Make JobStatusItems clickable 2016-02-14 13:41:20 +01:00
Dominik Schmidt
1b2ec05ea3 Move infoplugin wrong thread log message above assert 2016-02-12 22:16:42 +01:00
Dominik Schmidt
3875b10bb4 Don't leak spotify info plugin 2016-02-12 22:13:58 +01:00
Dominik Schmidt
f396f59922 Fix xmpp info plugin 2016-02-12 22:13:39 +01:00
Dominik Schmidt
7271a95942 Add friendlyName to XMPP info plugin 2016-02-12 22:12:54 +01:00
Dominik Schmidt
9737b7a8bc Make InfoPluginPtr a QSharedPointer 2016-02-12 21:37:47 +01:00
Dominik Schmidt
d87f966d9e Merge pull request #429 from midzer/patch1
erasing in an iteration and pass by reference
2016-02-10 12:11:23 +01:00
Dominik Schmidt
cb3ccd5a76 Protect m_formats access with mutex in Result 2016-02-10 00:21:31 +01:00
Dennis
f81858e28a pass by reference 2016-02-10 00:07:09 +01:00
Dennis
8fbc0319ba Erase elements from QStringList safely 2016-02-09 23:59:43 +01:00
Christian Muehlhaeuser
e7d83835d2 What a typo. 2016-02-07 11:39:04 +01:00
Christian Muehlhaeuser
6035889b90 Coding style. 2016-02-06 07:07:53 +01:00
Christian Muehlhaeuser
2bb0113515 Make sure Query's resultSorter provides stable sorting. 2016-02-06 07:07:53 +01:00
Christian Muehlhaeuser
8ee8721dda Merge pull request #423 from cash/patch-1
fixed a typo in PlaydarApi documentation
2016-02-02 00:30:35 +01:00
Cash Costello
293b3b1b4f fixed a typo in PlaydarApi documentation 2016-02-01 18:01:29 -05:00
Dominik Schmidt
ba0cc1a00c Don't assert for linkParser plugins, placeholder for real implementation 2016-02-01 15:18:06 +01:00
Dominik Schmidt
759bfbe63b Merge pull request #388 from theli-ua/nonalphanum
Improve track matching with non-alphanum character differences
2016-01-29 00:58:20 +01:00
Anton Romanov
e3877bf0bf Improve track matching with non-alphanum character differences 2016-01-28 15:52:15 -08:00
Dominik Schmidt
f1cf645f31 Ship D3DCompiler_43.dll to make QtDeclarative work 2016-01-28 22:16:11 +01:00
Dominik Schmidt
62dea3a196 Merge pull request #416 from theli-ua/resolver_sort
only use resolvers to compare if there are resolvers tied to results
2016-01-28 00:44:50 +01:00
Dominik Schmidt
09f68fa2f5 Use v09 synchrotron 2016-01-28 00:34:57 +01:00
Anton Romanov
944827c48c only use resolvers to compare if there are resolvers tied to results 2016-01-27 15:01:45 -08:00
Dominik Schmidt
771b2f5ae1 Add resolve default implementation in Tomahawk.Resolver 2016-01-27 18:03:40 +01:00
Dominik Schmidt
d50c16740a Fix crash in parseResultVariantList for broken track data 2016-01-27 17:31:48 +01:00
Dominik Schmidt
a5968b58e5 Update dll names 2016-01-26 02:11:10 +00:00
Dominik Schmidt
5f20308177 Go back to lowercase installer names on windows 2016-01-26 02:10:53 +00:00
Dominik Schmidt
1710813dc8 Correct indentation in NSIS.template.in 2016-01-25 16:03:27 +01:00
Dominik Schmidt
7fd306ca07 Don't use processEvents and still don't block ui for loading a script collection 2016-01-25 16:03:27 +01:00
Christian Muehlhaeuser
bdaf1ef2f4 Merge pull request #405 from theli-ua/resolver_sort
Sort equal results by resolver's weight
2016-01-20 22:18:26 +01:00
Anton Romanov
c068d8c9e3 Left goes to the left, right to the right 2016-01-20 12:45:55 -08:00
Anton Romanov
1e6b8b3747 Fix sorting order 2016-01-19 16:35:38 -08:00
Anton Romanov
0535d09f08 Sort equal results by resolver's weight 2016-01-19 11:11:11 -08:00
Christian Muehlhaeuser
c93302c563 Revert "Process events while parsing potentially very long script responses"
This reverts commit 1025e77d3e.
2016-01-18 11:04:19 +01:00
Christian Muehlhaeuser
1192c668b0 Too much whitespace in debug output. 2016-01-18 11:03:09 +01:00
Dominik Schmidt
53b27d0ea1 Fix isDown state in ImageButton 2016-01-18 04:55:48 +01:00
Dominik Schmidt
9ebe155313 Clean up PlayableProxyModel::columnCount 2016-01-18 03:19:01 +01:00
Dominik Schmidt
ddf030037e Fix artist colum not being rearrangable 2016-01-18 03:15:00 +01:00
Dominik Schmidt
5d950bd139 Add colum mapping to PlayableProxyModel 2016-01-18 02:50:19 +01:00
Dominik Schmidt
eab1ccee74 Fix #381: Show scrollbars for biography as needed 2016-01-18 00:21:26 +01:00
Dominik Schmidt
1025e77d3e Process events while parsing potentially very long script responses 2016-01-18 00:21:09 +01:00
Christian Muehlhaeuser
53de4319b6 Merge pull request #400 from tomahawk-player/fix-dropdownbutton
Fix DropDownButton in Playlist view
2016-01-15 18:26:57 +01:00
Dominik Schmidt
4eee01d8bf Fix DropDownButton in Playlist view 2016-01-15 18:10:28 +01:00
Dominik Schmidt
5bd69fe09c Automatically link against libc++ if found and compiler is clang 2016-01-15 04:12:12 +01:00
118 changed files with 2097 additions and 1194 deletions

View File

@@ -307,11 +307,10 @@ else()
message(STATUS "${CMAKE_CXX_COMPILER} does not support C++11, please use a
different compiler")
endif()
if(LIBCPP_FOUND AND APPLE)
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR APPLE) AND LIBCPP_FOUND)
tomahawk_add_cxx_flags( "-stdlib=libc++" )
endif()
macro_optional_find_package(Echonest 2.3.0)
macro_log_feature(ECHONEST_FOUND "Echonest" "Qt library for communicating with The Echo Nest" "http://projects.kde.org/libechonest" TRUE "" "libechonest 2.3.0 is needed for dynamic playlists and the infosystem")
@@ -404,7 +403,7 @@ if( WIN32 )
endif( WIN32 )
if( WIN32 OR APPLE )
macro_optional_find_package(LibsnoreQt5 0.5.70 QUIET)
macro_optional_find_package(LibsnoreQt5 0.6.0 QUIET)
macro_log_feature(LibsnoreQt5_FOUND "Libsnore" "Library for notifications" "https://projects.kde.org/projects/playground/libs/snorenotify" FALSE "" "")
endif()

View File

@@ -18,11 +18,10 @@
!ifndef MINGW_ROOT
!define MINGW_ROOT "/usr/i686-w64-mingw32/sys-root/mingw"
!endif
!define APPLICATION_NAME "Tomahawk"
!define TARGET_NAME "tomahawk"
!define APPLICATION_NAME "@CPACK_PACKAGE_NAME@"
!define TARGET_NAME "@CPACK_PACKAGE_TARGET_NAME@"
;define app id needed for Windows 8 notifications
!define AppUserModelId @TOMAHAWK_APPLICATION_PACKAGE_NAME@
!define AppUserModelId "@TOMAHAWK_APPLICATION_PACKAGE_NAME@"
!define MINGW_BIN "${MINGW_ROOT}/bin"
!define MINGW_LIB "${MINGW_ROOT}/lib"
@@ -347,105 +346,108 @@ Section "${APPLICATION_NAME}" SEC_TOMAHAWK_PLAYER
File "${QT_DLL_PATH}\icudata56.dll"
File "${QT_DLL_PATH}\icui18n56.dll"
;SQLite driver
SetOutPath "$INSTDIR\sqldrivers"
File "${SQLITE_DLL_PATH}\qsqlite.dll"
SetOutPath "$INSTDIR"
File "${MINGW_BIN}\libsqlite3-0.dll"
;SQLite driver
SetOutPath "$INSTDIR\sqldrivers"
File "${SQLITE_DLL_PATH}\qsqlite.dll"
SetOutPath "$INSTDIR"
File "${MINGW_BIN}\libsqlite3-0.dll"
;Qt platform plugins
SetOutPath "$INSTDIR\platforms"
File "${MINGW_LIB}/qt5/plugins/platforms/qwindows.dll"
SetOutPath "$INSTDIR"
;Qt platform plugins
SetOutPath "$INSTDIR\platforms"
File "${MINGW_LIB}/qt5/plugins/platforms/qwindows.dll"
SetOutPath "$INSTDIR"
;Image plugins
SetOutPath "$INSTDIR\imageformats"
File "${IMAGEFORMATS_DLL_PATH}\qgif.dll"
File "${IMAGEFORMATS_DLL_PATH}\qjpeg.dll"
File "${IMAGEFORMATS_DLL_PATH}\qsvg.dll"
SetOutPath "$INSTDIR"
;Image plugins
SetOutPath "$INSTDIR\imageformats"
File "${IMAGEFORMATS_DLL_PATH}\qgif.dll"
File "${IMAGEFORMATS_DLL_PATH}\qjpeg.dll"
File "${IMAGEFORMATS_DLL_PATH}\qsvg.dll"
SetOutPath "$INSTDIR"
;Qt qml plugins
SetOutPath "$INSTDIR\QtQuick.2"
File /r /x *.debug "${QT_QML_PATH}\QtQuick.2\*"
SetOutPath "$INSTDIR\QtQuick\Window.2"
File /r /x *.debug "${QT_QML_PATH}\QtQuick\Window.2\*"
SetOutPath "$INSTDIR"
;Qt qml plugins
SetOutPath "$INSTDIR\QtQuick.2"
File /r /x *.debug "${QT_QML_PATH}\QtQuick.2\*"
SetOutPath "$INSTDIR\QtQuick\Window.2"
File /r /x *.debug "${QT_QML_PATH}\QtQuick\Window.2\*"
SetOutPath "$INSTDIR"
;Cygwin/c++ stuff
File "${MINGW_BIN}\libgcc_s_sjlj-1.dll"
File "${MINGW_BIN}\libstdc++-6.dll"
;Cygwin/c++ stuff
File "${MINGW_BIN}\libgcc_s_sjlj-1.dll"
File "${MINGW_BIN}\libstdc++-6.dll"
;VLC
File "${VLC_BIN}\libvlc.dll"
File "${VLC_BIN}\libvlccore.dll"
SetOutPath "$INSTDIR\plugins"
File /r "${VLC_PLUGIN_PATH}\*.dll"
SetOutPath "$INSTDIR"
;VLC
File "${VLC_BIN}\libvlc.dll"
File "${VLC_BIN}\libvlccore.dll"
SetOutPath "$INSTDIR\plugins"
File /r "${VLC_PLUGIN_PATH}\*.dll"
SetOutPath "$INSTDIR"
; Other
File "${MINGW_BIN}\libtag.dll"
File "${MINGW_BIN}\libpng16-16.dll"
File "${MINGW_BIN}\libjpeg-8.dll"
File "${MINGW_BIN}\zlib1.dll"
File "${MINGW_BIN}\libfreetype-6.dll"
File "${MINGW_BIN}\libglib-2.0-0.dll"
File "${MINGW_BIN}\libharfbuzz-0.dll"
; Other
File "${MINGW_BIN}\libtag.dll"
File "${MINGW_BIN}\libpng16-16.dll"
File "${MINGW_BIN}\libjpeg-8.dll"
File "${MINGW_BIN}\zlib1.dll"
File "${MINGW_BIN}\libfreetype-6.dll"
File "${MINGW_BIN}\libglib-2.0-0.dll"
File "${MINGW_BIN}\libharfbuzz-0.dll"
File "${MINGW_BIN}\libechonest5.dll"
File "${MINGW_BIN}\liblastfm5.dll"
File "${MINGW_BIN}\libquazip5.dll"
File "${MINGW_BIN}\libqt5keychain.dll"
; ANGLE
File "${MINGW_BIN}\D3DCompiler_43.dll"
; GnuTLS
File "${MINGW_BIN}\libgnutls-28.dll"
File "${MINGW_BIN}\libtasn1-6.dll"
File "${MINGW_BIN}\libgmp-10.dll"
File "${MINGW_BIN}\libhogweed-2-4.dll"
File "${MINGW_BIN}\libintl-8.dll"
File "${MINGW_BIN}\libnettle-4-6.dll"
File "${MINGW_BIN}\libp11-kit-0.dll"
File "${MINGW_BIN}\libffi-6.dll"
File "${MINGW_BIN}\libechonest5.dll"
File "${MINGW_BIN}\liblastfm5.dll"
File "${MINGW_BIN}\libquazip5.dll"
File "${MINGW_BIN}\libqt5keychain.dll"
; Snorenotify
File "${MINGW_BIN}\SnoreToast.exe"
File "${MINGW_BIN}\libsnore-qt5.dll"
File "${MINGW_BIN}\libsnoresettings-qt5.dll"
File "${MINGW_BIN}\snoresettings.exe"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_backend_growl.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_settings_backend_growl.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_backend_snarl.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_settings_backend_snarl.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_backend_snore.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_settings_backend_snore.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_backend_windowstoast.dll"
; GnuTLS
File "${MINGW_BIN}\libgnutls-28.dll"
File "${MINGW_BIN}\libtasn1-6.dll"
File "${MINGW_BIN}\libgmp-10.dll"
File "${MINGW_BIN}\libhogweed-4-1.dll"
File "${MINGW_BIN}\libintl-8.dll"
File "${MINGW_BIN}\libnettle-6-1.dll"
File "${MINGW_BIN}\libp11-kit-0.dll"
File "${MINGW_BIN}\libffi-6.dll"
; Snoregrowl
File "${MINGW_BIN}\libsnoregrowl++.dll"
File "${MINGW_BIN}\libsnoregrowl.dll"
; Snorenotify
File "${MINGW_BIN}\SnoreToast.exe"
File "${MINGW_BIN}\libsnore-qt5.dll"
File "${MINGW_BIN}\libsnoresettings-qt5.dll"
File "${MINGW_BIN}\snoresettings.exe"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_backend_growl.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_settings_backend_growl.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_backend_snarl.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_settings_backend_snarl.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_backend_snore.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_settings_backend_snore.dll"
File "${MINGW_LIB}\plugins\libsnore-qt5\libsnore_backend_windowstoast.dll"
; Snoregrowl
File "${MINGW_BIN}\libsnoregrowl++.dll"
File "${MINGW_BIN}\libsnoregrowl.dll"
; Jabber
File "${MINGW_BIN}\libjreen-qt5.dll"
File "${MINGW_BIN}\libidn-11.dll"
File "${MINGW_BIN}\libgsasl-7.dll"
File "${MINGW_BIN}\libqca-qt5.dll"
SetOutPath "$INSTDIR\crypto"
File "${MINGW_LIB}\qca-qt5\crypto\libqca-ossl.dll"
SetOutPath "$INSTDIR"
File "${MINGW_BIN}\libssl-10.dll"
File "${MINGW_BIN}\libcrypto-10.dll"
File "${MINGW_BIN}\libjreen-qt5.dll"
File "${MINGW_BIN}\libidn-11.dll"
File "${MINGW_BIN}\libgsasl-7.dll"
File "${MINGW_BIN}\libqca-qt5.dll"
SetOutPath "$INSTDIR\crypto"
File "${MINGW_LIB}\qca-qt5\crypto\libqca-ossl.dll"
SetOutPath "$INSTDIR"
File "${MINGW_BIN}\libssl-10.dll"
File "${MINGW_BIN}\libcrypto-10.dll"
; LucenePlusPlus
File "${MINGW_BIN}\liblucene++.dll"
File "${MINGW_BIN}\libboost_system-mt.dll"
File "${MINGW_BIN}\libboost_filesystem-mt.dll"
File "${MINGW_BIN}\libboost_iostreams-mt.dll"
File "${MINGW_BIN}\libboost_regex-mt.dll"
File "${MINGW_BIN}\libboost_thread-mt.dll"
File "${MINGW_BIN}\libbz2-1.dll"
; LucenePlusPlus
File "${MINGW_BIN}\liblucene++.dll"
File "${MINGW_BIN}\libboost_system-mt.dll"
File "${MINGW_BIN}\libboost_filesystem-mt.dll"
File "${MINGW_BIN}\libboost_iostreams-mt.dll"
File "${MINGW_BIN}\libboost_regex-mt.dll"
File "${MINGW_BIN}\libboost_thread-mt.dll"
File "${MINGW_BIN}\libbz2-1.dll"
File "${MINGW_BIN}\libqtsparkle-qt5.dll"
File "${MINGW_BIN}\libKF5Attica.dll"
File "${MINGW_BIN}\libqtsparkle-qt5.dll"
File "${MINGW_BIN}\libKF5Attica.dll"
SectionEnd
SectionGroup "Shortcuts"

View File

@@ -2,7 +2,7 @@ INCLUDE( InstallRequiredSystemLibraries )
SET( CPACK_PACKAGE_CONTACT "Dominik Schmidt <domme@tomahawk-player.org>" )
SET( CPACK_PACKAGE_FILE_NAME "${TOMAHAWK_APPLICATION_NAME}-${TOMAHAWK_VERSION}" ) # Package file name without extension. Also a directory of installer cmake-2.5.0-Linux-i686
SET( CPACK_PACKAGE_FILE_NAME "${TOMAHAWK_TARGET_NAME}-${TOMAHAWK_VERSION}" ) # Package file name without extension. Also a directory of installer cmake-2.5.0-Linux-i686
# CPACK_GENERATOR CPack generator to be used STGZ;TGZ;TZ
# CPACK_INCLUDE_TOPLEVEL_DIRECTORY Controls whether CPack adds a top-level directory, usually of the form ProjectName-Version-OS, to the top of package tree. 0 to disable, 1 to enable
@@ -13,7 +13,9 @@ SET( CPACK_PACKAGE_DESCRIPTION_SUMMARY ${TOMAHAWK_DESCRIPTION_SUMMARY} ) # Des
SET( CPACK_PACKAGE_INSTALL_DIRECTORY ${TOMAHAWK_APPLICATION_NAME} ) # Installation directory on the target system -> C:\Program Files\fellody
SET( CPACK_PACKAGE_INSTALL_REGISTRY_KEY ${TOMAHAWK_APPLICATION_NAME} ) # Registry key used when installing this project CMake 2.5.0
SET( CPACK_PACKAGE_NAME ${TOMAHAWK_APPLICATION_NAME} ) # Package name, defaults to the project name
SET( CPACK_PACKAGE_TARGET_NAME ${TOMAHAWK_TARGET_NAME} ) # Used to build library and executable names
SET( CPACK_PACKAGE_VENDOR ${TOMAHAWK_ORGANIZATION_NAME} ) # Package vendor name
SET( TOMAHAWK_APPLICATION_PACKAGE_NAME ${TOMAHAWK_APPLICATION_PACKAGE_NAME} )
SET( CPACK_PACKAGE_VERSION_MAJOR ${TOMAHAWK_VERSION_MAJOR} )
SET( CPACK_PACKAGE_VERSION_MINOR ${TOMAHAWK_VERSION_MINOR} )
SET( CPACK_PACKAGE_VERSION_PATCH ${TOMAHAWK_VERSION_PATCH} )

View File

@@ -273,19 +273,29 @@ Tomahawk.Resolver = {
getStreamUrl: function (params) {
return params;
},
resolve: function() {
},
_adapter_resolve: function (params) {
return RSVP.Promise.resolve(this.resolve(params)).then(function (results) {
return {
'tracks': results
};
if(Array.isArray(results)) {
return {
'tracks': results
};
}
return results;
});
},
_adapter_search: function (params) {
return RSVP.Promise.resolve(this.search(params)).then(function (results) {
return {
'tracks': results
};
if(Array.isArray(results)) {
return {
'tracks': results
};
}
return results;
});
},

View File

@@ -24,13 +24,6 @@ include_directories(
add_definitions(-D_WEBSOCKETPP_CPP11_STL_)
if(APPLE)
# http://stackoverflow.com/questions/7226753/osx-lion-xcode-4-1-how-do-i-setup-a-c0x-project/7236451#7236451
add_definitions(-std=c++11 -stdlib=libc++ -U__STRICT_ANSI__)
set(PLATFORM_SPECIFIC_LINK_LIBRARIES "/usr/lib/libc++.dylib")
else()
add_definitions(-std=c++0x)
endif()
tomahawk_add_plugin(hatchet
TYPE account

View File

@@ -69,6 +69,13 @@ Tomahawk::InfoSystem::XmppInfoPlugin::init()
}
const QString
Tomahawk::InfoSystem::XmppInfoPlugin::friendlyName() const
{
return "xmpp";
}
void
Tomahawk::InfoSystem::XmppInfoPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
{

View File

@@ -38,6 +38,8 @@ namespace Tomahawk {
XmppInfoPlugin(XmppSipPlugin* parent);
virtual ~XmppInfoPlugin();
const QString friendlyName() const override;
signals:
void publishTune( QUrl url, Tomahawk::InfoSystem::InfoStringHash trackInfo );

View File

@@ -194,9 +194,9 @@ InfoSystem::InfoPluginPtr
XmppSipPlugin::infoPlugin()
{
if ( m_infoPlugin.isNull() )
m_infoPlugin = QPointer< Tomahawk::InfoSystem::XmppInfoPlugin >( new Tomahawk::InfoSystem::XmppInfoPlugin( this ) );
m_infoPlugin = QSharedPointer< Tomahawk::InfoSystem::XmppInfoPlugin >( new Tomahawk::InfoSystem::XmppInfoPlugin( this ) );
return InfoSystem::InfoPluginPtr( m_infoPlugin.data() );
return m_infoPlugin;
}
@@ -285,7 +285,7 @@ XmppSipPlugin::onConnect()
// load XmppInfoPlugin
if ( infoPlugin() && Tomahawk::InfoSystem::InfoSystem::instance()->workerThread() )
{
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
infoPlugin()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
}
@@ -359,7 +359,6 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
if ( !m_infoPlugin.isNull() )
{
Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin() );
delete m_infoPlugin;
}
}

View File

@@ -128,7 +128,7 @@ private:
int m_currentPort;
QString m_currentResource;
QPointer< Tomahawk::InfoSystem::XmppInfoPlugin > m_infoPlugin;
QSharedPointer< Tomahawk::InfoSystem::XmppInfoPlugin > m_infoPlugin;
Tomahawk::Accounts::Account::ConnectionState m_state;
// sort out

View File

@@ -34,7 +34,7 @@ public:
* Creates a Playdar HTTP interface
* @param ha Address to listen on
* @param port Port to listen on with HTTP
* @param sport Pot to listen on with HTTPS
* @param sport Port to listen on with HTTPS
* @param parent
*/
explicit PlaydarApi( QHostAddress ha, qint16 port, qint16 sport, QObject *parent = 0 );

View File

@@ -33,6 +33,7 @@
#include <QReadWriteLock>
#include <QPixmapCache>
#include <QCoreApplication>
using namespace Tomahawk;
@@ -75,6 +76,7 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr
}
album_ptr album = album_ptr( new Album( name, artist ), &Album::deleteLater );
album->moveToThread( QCoreApplication::instance()->thread() );
album->setWeakRef( album.toWeakRef() );
album->loadId( autoCreate );
s_albumsByName.insert( key, album );

View File

@@ -36,6 +36,7 @@
#include <QReadWriteLock>
#include <QPixmapCache>
#include <QCoreApplication>
using namespace Tomahawk;
@@ -109,6 +110,7 @@ Artist::get( unsigned int id, const QString& name )
}
artist_ptr a = artist_ptr( new Artist( id, name ), &Artist::deleteLater );
a->moveToThread( QCoreApplication::instance()->thread() );
a->setWeakRef( a.toWeakRef() );
s_artistsByName.insert( key, a );

View File

@@ -67,7 +67,7 @@ AtticaManager::AtticaManager( QObject* parent )
connect( &m_manager, SIGNAL( providerAdded( Attica::Provider ) ), this, SLOT( providerAdded( Attica::Provider ) ) );
// resolvers
// m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org/resolvers/providers.xml" ) );
// m_manager.addProviderFile( QUrl( "http://v09.bakery.tomahawk-player.org/resolvers/providers.xml" ) );
const QString url = QString( "%1/resolvers/providers.xml?version=%2" ).arg( hostname() ).arg( TomahawkUtils::appFriendlyVersion() );
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( url ) ) );
@@ -116,7 +116,7 @@ AtticaManager::fetchMissingIcons()
QString
AtticaManager::hostname() const
{
return "http://bakery.tomahawk-player.org";
return "http://v09.bakery.tomahawk-player.org";
}

View File

@@ -37,6 +37,7 @@ set( libGuiSources
jobview/ErrorStatusMessage.cpp
jobview/IndexingJobItem.cpp
jobview/InboxJobItem.cpp
jobview/ScriptErrorStatusMessage.cpp
playlist/InboxModel.cpp
playlist/InboxView.cpp
@@ -126,8 +127,6 @@ set( libGuiSources
utils/LinkGenerator.cpp
utils/LinkGeneratorPlugin.cpp
utils/TomaHkLinkGeneratorPlugin.cpp
utils/LinkParser.cpp
utils/LinkParserPlugin.cpp
viewpages/SearchViewPage.cpp
viewpages/SourceViewPage.cpp
@@ -352,6 +351,8 @@ list(APPEND libSources
resolvers/ScriptCommand_AllArtists.cpp
resolvers/ScriptCommand_AllAlbums.cpp
resolvers/ScriptCommand_AllTracks.cpp
resolvers/ScriptCommand_LookupUrl.cpp
resolvers/ScriptCommandQueue.cpp
resolvers/ScriptPluginFactory.cpp
# ScriptPlugins
@@ -359,8 +360,6 @@ list(APPEND libSources
resolvers/plugins/ScriptCollectionFactory.cpp
resolvers/ScriptInfoPlugin.cpp
resolvers/plugins/ScriptInfoPluginFactory.cpp
resolvers/plugins/ScriptLinkParserPlugin.cpp
resolvers/plugins/ScriptLinkParserPluginFactory.cpp
sip/SipPlugin.cpp
@@ -368,7 +367,6 @@ list(APPEND libSources
sip/PeerInfo.cpp
sip/SipStatusMessage.cpp
utils/UrlType.cpp
utils/Cloudstream.cpp
utils/Json.cpp
utils/TomahawkUtils.cpp
@@ -420,7 +418,7 @@ include_directories(
${Boost_INCLUDE_DIR}
${LIBPORTFWD_INCLUDE_DIR}
${QUAZIP_INCLUDE_DIR}
${QUAZIP_INCLUDE_DIRS}
${QTKEYCHAIN_INCLUDE_DIRS}
)

View File

@@ -4,7 +4,6 @@
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2011-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2011-2012, Christian Muehlhaeuser <muesli@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
@@ -36,7 +35,6 @@
#include "utils/Logger.h"
#include "utils/TomahawkUtils.h"
#include "utils/XspfLoader.h"
#include "utils/LinkParser.h"
#include "Artist.h"
#include "Album.h"
@@ -174,7 +172,12 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
if ( url.contains( "grooveshark.com" ) && url.contains( "playlist" ) )
return true;
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypePlaylist );
// Check Scriptresolvers
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() )
{
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypePlaylist ) )
return true;
}
}
if ( acceptedType.testFlag( Track ) )
@@ -195,7 +198,12 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
|| url.contains( "playlists" ) ) ) )
return true;
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypeTrack );
// Check Scriptresolvers
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() )
{
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypeTrack ) )
return true;
}
}
if ( acceptedType.testFlag( Album ) )
@@ -207,7 +215,12 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
if ( url.contains( "rdio.com" ) && ( url.contains( "artist" ) && url.contains( "album" ) && !url.contains( "track" ) ) )
return true;
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypeAlbum );
// Check Scriptresolvers
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() )
{
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypeAlbum ) )
return true;
}
}
if ( acceptedType.testFlag( Artist ) )
@@ -219,7 +232,12 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
if ( url.contains( "rdio.com" ) && ( url.contains( "artist" ) && !url.contains( "album" ) && !url.contains( "track" ) ) )
return true;
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypeArtist );
// Check Scriptresolvers
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() )
{
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypeArtist ) )
return true;
}
}
// We whitelist certain url-shorteners since they do some link checking. Often playable (e.g. spotify) links hide behind them,
@@ -245,9 +263,14 @@ bool
DropJob::validateLocalFiles(const QString &paths, const QString &suffix)
{
QStringList filePaths = paths.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
for ( QStringList::iterator it = filePaths.begin(); it != filePaths.end(); ++it )
QStringList::iterator it = filePaths.begin();
while ( it != filePaths.end() )
{
if ( !validateLocalFile( *it, suffix ) )
filePaths.erase( it );
it = filePaths.erase( it );
else
++it;
}
return !filePaths.isEmpty();
}
@@ -285,7 +308,15 @@ DropJob::isDropType( DropJob::DropType desired, const QMimeData* data )
if ( ShortenedLinkParser::handlesUrl( url ) )
return true;
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypePlaylist );
// Check Scriptresolvers
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() )
{
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypePlaylist ) )
{
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Accepting current drop as a playlist" << resolver->name();
return true;
}
}
}
@@ -735,12 +766,16 @@ DropJob::handleTrackUrls( const QString& urls )
foreach ( QString track, tracks )
{
QList< QSharedPointer< Utils::LinkParserPlugin > > parserPlugins = Utils::LinkParser::instance()->parserPluginsForUrl( track, Utils::UrlTypeAny );
if( !parserPlugins.isEmpty() )
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() )
{
Tomahawk::Utils::LinkParser::instance()->lookupUrl( track, parserPlugins );
connect( Tomahawk::Utils::LinkParser::instance(), SIGNAL( informationFound( QString, QSharedPointer<QObject> ) ), this, SLOT( informationForUrl( QString, QSharedPointer<QObject> ) ) );
m_queryCount++;
if ( resolver->canParseUrl( track, ExternalResolver::UrlTypeAny ) )
{
ScriptCommand_LookupUrl* cmd = new ScriptCommand_LookupUrl( resolver, track );
connect( cmd, SIGNAL( information( QString, QSharedPointer<QObject> ) ), this, SLOT( informationForUrl( QString, QSharedPointer<QObject> ) ) );
cmd->enqueue();
m_queryCount++;
break;
}
}
}
}

View File

@@ -5,7 +5,6 @@
* Copyright (C) 2011-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright (C) 2013, Uwe L. Korn <uwelk@xhochy.com>
* Copyright (C) 2013, Teo Mrnjavac <teo@kde.org>
* Copyright (C) 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
@@ -36,13 +35,13 @@
#include "playlist/TrackView.h"
#include "playlist/PlayableModel.h"
#include "resolvers/ExternalResolver.h"
#include "resolvers/ScriptCommand_LookupUrl.h"
#include "utils/JspfLoader.h"
#include "utils/Logger.h"
#include "utils/SpotifyParser.h"
#include "utils/XspfLoader.h"
#include "utils/XspfGenerator.h"
#include "viewpages/SearchViewPage.h"
#include "utils/LinkParser.h"
#include "Pipeline.h"
#include "TomahawkSettings.h"
@@ -163,12 +162,27 @@ GlobalActionManager::openUrl( const QString& url )
else if ( url.contains( "open.spotify.com" ) || url.startsWith( "spotify:" ) )
return openSpotifyLink( url );
// Can we parse the Url using LinkParser?
QList< QSharedPointer< Utils::LinkParserPlugin > > parserPlugins = Utils::LinkParser::instance()->parserPluginsForUrl( url, Utils::UrlTypeAny );
if( !parserPlugins.isEmpty() )
// Can we parse the Url using a ScriptResolver?
bool canParse = false;
QList< QPointer< ExternalResolver > > possibleResolvers;
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() )
{
Tomahawk::Utils::LinkParser::instance()->lookupUrl( url, parserPlugins );
connect( Tomahawk::Utils::LinkParser::instance(), SIGNAL( informationFound( QString, QSharedPointer<QObject> ) ), this, SLOT( informationForUrl( QString, QSharedPointer<QObject> ) ), Qt::UniqueConnection );
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypeAny ) )
{
canParse = true;
possibleResolvers << resolver;
}
}
if ( canParse )
{
m_queuedUrl = url;
foreach ( QPointer<ExternalResolver> resolver, possibleResolvers )
{
ScriptCommand_LookupUrl* cmd = new ScriptCommand_LookupUrl( resolver, url );
connect( cmd, SIGNAL( information( QString, QSharedPointer<QObject> ) ), this, SLOT( informationForUrl( QString, QSharedPointer<QObject> ) ) );
cmd->enqueue();
}
return true;
}

View File

@@ -595,8 +595,8 @@ Pipeline::shunt( const query_ptr& q )
// we get here if we disable a resolver while a query is resolving
// OR we are just out of resolvers while query is still resolving
//since we seem to at least tried to kick off all of the resolvers,
//remove the '.keep' entry
// since we seem to at least tried to kick off all of the resolvers,
// remove the '.keep' entry
decQIDState( q, nullptr );
return;
}
@@ -636,7 +636,7 @@ Pipeline::checkQIDState( const Tomahawk::query_ptr& query )
Q_D( Pipeline );
QMutexLocker lock( &d->mut );
tDebug() << Q_FUNC_INFO << " " << query->id() << " " << d->qidsState.count( query->id() );
tDebug() << Q_FUNC_INFO << query->id() << d->qidsState.count( query->id() );
if ( d->qidsState.contains( query->id() ) )
{

View File

@@ -33,6 +33,7 @@
#include <QtAlgorithms>
#include <QDebug>
#include <QCoreApplication>
using namespace Tomahawk;
@@ -47,6 +48,7 @@ Query::get( const QString& artist, const QString& track, const QString& album, c
autoResolve = false;
query_ptr q = query_ptr( new Query( Track::get( artist, track, album ), qid, autoResolve ), &QObject::deleteLater );
q->moveToThread( QCoreApplication::instance()->thread() );
q->setWeakRef( q.toWeakRef() );
if ( autoResolve )
@@ -403,12 +405,17 @@ Query::resultSorter( const result_ptr& left, const result_ptr& right )
{
return false;
}
if ( !right->isPreview() )
if ( left->isPreview() != right->isPreview() )
{
return false;
return !left->isPreview();
}
return true;
if ( left->resolvedBy() != nullptr && right->resolvedBy() != nullptr )
{
return left->resolvedBy()->weight() > right->resolvedBy()->weight();
}
return left->id() > right->id();
}
if ( left->isPreview() != right->isPreview() )
@@ -636,6 +643,11 @@ Query::howSimilar( const Tomahawk::result_ptr& r )
qTrackname = queryTrack()->trackSortname();
}
//Cleanup symbols for minor naming differences
qArtistname.remove(QRegExp(QString::fromUtf8("[-`~!@#$%^&*()_—+=|:;<>«»,.?/{}\'\"\\[\\]\\\\]")));
qTrackname.remove(QRegExp(QString::fromUtf8("[-`~!@#$%^&*()_—+=|:;<>«»,.?/{}\'\"\\[\\]\\\\]")));
qAlbumname.remove(QRegExp(QString::fromUtf8("[-`~!@#$%^&*()_—+=|:;<>«»,.?/{}\'\"\\[\\]\\\\]")));
// normal edit distance
const int artdist = TomahawkUtils::levenshtein( qArtistname, rArtistname );
const int trkdist = TomahawkUtils::levenshtein( qTrackname, rTrackname );

View File

@@ -35,6 +35,8 @@
#include "Track.h"
#include "Typedefs.h"
#include <QCoreApplication>
using namespace Tomahawk;
static QHash< QString, result_wptr > s_results;
@@ -69,6 +71,7 @@ Result::get( const QString& url, const track_ptr& track )
}
result_ptr r = result_ptr( new Result( url, track ), &Result::deleteLater );
r->moveToThread( QCoreApplication::instance()->thread() );
r->setWeakRef( r.toWeakRef() );
s_results.insert( url, r );
@@ -132,11 +135,19 @@ Result::deleteLater()
void
Result::onResolverRemoved( Tomahawk::Resolver* resolver )
{
m_mutex.lock();
if ( m_resolver.data() == resolver )
{
m_resolver = 0;
m_mutex.unlock();
emit statusChanged();
}
else
{
m_mutex.unlock();
}
}
@@ -150,6 +161,8 @@ Result::resolvedByCollection() const
QString
Result::url() const
{
QMutexLocker lock( &m_mutex );
return m_url;
}
@@ -157,6 +170,8 @@ Result::url() const
bool
Result::checked() const
{
QMutexLocker lock( &m_mutex );
return m_checked;
}
@@ -164,6 +179,8 @@ Result::checked() const
bool
Result::isPreview() const
{
QMutexLocker lock( &m_mutex );
return m_isPreview;
}
@@ -171,6 +188,8 @@ Result::isPreview() const
QString
Result::mimetype() const
{
QMutexLocker lock( &m_mutex );
return m_mimetype;
}
@@ -178,6 +197,8 @@ Result::mimetype() const
RID
Result::id() const
{
QMutexLocker lock( &m_mutex );
if ( m_rid.isEmpty() )
m_rid = uuid();
@@ -194,6 +215,8 @@ Result::isOnline() const
}
else
{
QMutexLocker lock( &m_mutex );
return !m_resolver.isNull();
}
}
@@ -214,24 +237,26 @@ Result::playable() const
QVariant
Result::toVariant() const
{
track_ptr t = track();
QVariantMap m;
m.insert( "artist", m_track->artist() );
m.insert( "album", m_track->album() );
m.insert( "track", m_track->track() );
m.insert( "artist", t->artist() );
m.insert( "album", t->album() );
m.insert( "track", t->track() );
m.insert( "source", friendlySource() );
m.insert( "mimetype", mimetype() );
m.insert( "size", size() );
m.insert( "bitrate", bitrate() );
m.insert( "duration", m_track->duration() );
m.insert( "duration", t->duration() );
// m.insert( "score", score() );
m.insert( "sid", id() );
m.insert( "discnumber", m_track->discnumber() );
m.insert( "albumpos", m_track->albumpos() );
m.insert( "discnumber", t->discnumber() );
m.insert( "albumpos", t->albumpos() );
m.insert( "preview", isPreview() );
m.insert( "purchaseUrl", purchaseUrl() );
if ( !m_track->composer().isEmpty() )
m.insert( "composer", m_track->composer() );
if ( !t->composer().isEmpty() )
m.insert( "composer", t->composer() );
return m;
}
@@ -240,20 +265,25 @@ Result::toVariant() const
QString
Result::toString() const
{
if ( m_track )
m_mutex.lock();
track_ptr track = m_track;
QString url = m_url;
m_mutex.unlock();
if ( track )
{
return QString( "Result(%1) %2 - %3%4 (%5)" )
.arg( id() )
.arg( m_track->artist() )
.arg( m_track->track() )
.arg( m_track->album().isEmpty() ? QString() : QString( " on %1" ).arg( m_track->album() ) )
.arg( m_url );
.arg( track->artist() )
.arg( track->track() )
.arg( track->album().isEmpty() ? QString() : QString( " on %1" ).arg( track->album() ) )
.arg( url );
}
else
{
return QString( "Result(%1) (%2)" )
.arg( id() )
.arg( m_url );
.arg( url );
}
}
@@ -261,6 +291,8 @@ Result::toString() const
Tomahawk::query_ptr
Result::toQuery()
{
QMutexLocker l( &m_mutex );
if ( m_query.isNull() )
{
query_ptr query = Tomahawk::Query::get( m_track );
@@ -270,12 +302,15 @@ Result::toQuery()
m_query = query->weakRef();
QList<Tomahawk::result_ptr> rl;
rl << weakRef().toStrongRef();
rl << m_ownRef.toStrongRef();
m_mutex.unlock();
query->addResults( rl );
m_mutex.lock();
query->setResolveFinished( true );
return query;
}
return m_query.toStrongRef();
}
@@ -295,9 +330,10 @@ Result::onOffline()
void
Result::setResolvedByCollection( const Tomahawk::collection_ptr& collection , bool emitOnlineEvents )
Result::setResolvedByCollection( const Tomahawk::collection_ptr& collection, bool emitOnlineEvents )
{
m_collection = collection;
if ( emitOnlineEvents )
{
Q_ASSERT( !collection.isNull() );
@@ -311,6 +347,8 @@ Result::setResolvedByCollection( const Tomahawk::collection_ptr& collection , bo
void
Result::setFriendlySource( const QString& s )
{
QMutexLocker lock( &m_mutex );
m_friendlySource = s;
}
@@ -318,6 +356,8 @@ Result::setFriendlySource( const QString& s )
void
Result::setPreview( bool isPreview )
{
QMutexLocker lock( &m_mutex );
m_isPreview = isPreview;
}
@@ -325,6 +365,8 @@ Result::setPreview( bool isPreview )
void
Result::setPurchaseUrl( const QString& u )
{
QMutexLocker lock( &m_mutex );
m_purchaseUrl = u;
}
@@ -332,6 +374,8 @@ Result::setPurchaseUrl( const QString& u )
void
Result::setLinkUrl( const QString& u )
{
QMutexLocker lock( &m_mutex );
m_linkUrl = u;
}
@@ -339,6 +383,8 @@ Result::setLinkUrl( const QString& u )
void
Result::setChecked( bool checked )
{
QMutexLocker lock( &m_mutex );
m_checked = checked;
}
@@ -346,6 +392,8 @@ Result::setChecked( bool checked )
void
Result::setMimetype( const QString& mimetype )
{
QMutexLocker lock( &m_mutex );
m_mimetype = mimetype;
}
@@ -353,6 +401,8 @@ Result::setMimetype( const QString& mimetype )
void
Result::setBitrate( unsigned int bitrate )
{
QMutexLocker lock( &m_mutex );
m_bitrate = bitrate;
}
@@ -360,6 +410,8 @@ Result::setBitrate( unsigned int bitrate )
void
Result::setSize( unsigned int size )
{
QMutexLocker lock( &m_mutex );
m_size = size;
}
@@ -367,6 +419,8 @@ Result::setSize( unsigned int size )
void
Result::setModificationTime( unsigned int modtime )
{
QMutexLocker lock( &m_mutex );
m_modtime = modtime;
}
@@ -374,6 +428,8 @@ Result::setModificationTime( unsigned int modtime )
void
Result::setTrack( const track_ptr& track )
{
QMutexLocker lock( &m_mutex );
m_track = track;
}
@@ -381,6 +437,8 @@ Result::setTrack( const track_ptr& track )
unsigned int
Result::fileId() const
{
QMutexLocker lock( &m_mutex );
return m_fileId;
}
@@ -390,6 +448,8 @@ Result::friendlySource() const
{
if ( resolvedByCollection().isNull() )
{
QMutexLocker lock( &m_mutex );
return m_friendlySource;
}
else
@@ -400,6 +460,8 @@ Result::friendlySource() const
QString
Result::purchaseUrl() const
{
QMutexLocker lock( &m_mutex );
return m_purchaseUrl;
}
@@ -407,6 +469,8 @@ Result::purchaseUrl() const
QString
Result::linkUrl() const
{
QMutexLocker lock( &m_mutex );
return m_linkUrl;
}
@@ -416,6 +480,8 @@ Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) c
{
if ( resolvedByCollection().isNull() )
{
//QMutexLocker lock( &m_mutex );
const ExternalResolver* resolver = qobject_cast< ExternalResolver* >( m_resolver.data() );
if ( !resolver )
{
@@ -466,6 +532,8 @@ Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) c
unsigned int
Result::bitrate() const
{
QMutexLocker lock( &m_mutex );
return m_bitrate;
}
@@ -473,6 +541,8 @@ Result::bitrate() const
unsigned int
Result::size() const
{
QMutexLocker lock( &m_mutex );
return m_size;
}
@@ -480,6 +550,8 @@ Result::size() const
unsigned int
Result::modificationTime() const
{
QMutexLocker lock( &m_mutex );
return m_modtime;
}
@@ -487,6 +559,8 @@ Result::modificationTime() const
void
Result::setFileId( unsigned int id )
{
QMutexLocker lock( &m_mutex );
m_fileId = id;
}
@@ -494,6 +568,8 @@ Result::setFileId( unsigned int id )
Tomahawk::Resolver*
Result::resolvedBy() const
{
QMutexLocker lock( &m_mutex );
if ( !m_collection.isNull() )
return m_collection.data();
@@ -504,12 +580,16 @@ Result::resolvedBy() const
void
Result::setResolvedByResolver( Tomahawk::Resolver* resolver )
{
QMutexLocker lock( &m_mutex );
m_resolver = QPointer< Tomahawk::Resolver >( resolver );
}
QPointer< Resolver > Result::resolvedByResolver() const
{
QMutexLocker lock( &m_mutex );
return m_resolver;
}
@@ -525,16 +605,29 @@ Result::doneEditing()
track_ptr
Result::track() const
{
QMutexLocker lock( &m_mutex );
return m_track;
}
QList< DownloadFormat >
Result::downloadFormats() const
{
QMutexLocker lock( &m_mutex );
return m_formats;
}
void
Result::setDownloadFormats( const QList<DownloadFormat>& formats )
{
if ( formats.isEmpty() )
return;
QMutexLocker lock( &m_mutex );
m_formats.clear();
foreach ( const DownloadFormat& format, formats )
{
@@ -562,7 +655,7 @@ Result::setDownloadFormats( const QList<DownloadFormat>& formats )
void
Result::onSettingsChanged()
{
if ( TomahawkSettings::instance()->downloadsPreferredFormat().toLower() != m_formats.first().extension.toLower() )
if ( TomahawkSettings::instance()->downloadsPreferredFormat().toLower() != downloadFormats().first().extension.toLower() )
{
setDownloadFormats( downloadFormats() );
emit updated();
@@ -599,6 +692,8 @@ Result::onDownloadJobStateChanged( DownloadJob::TrackState newState, DownloadJob
QWeakPointer<Result>
Result::weakRef()
{
QMutexLocker lock( &m_mutex );
return m_ownRef;
}
@@ -606,5 +701,7 @@ Result::weakRef()
void
Result::setWeakRef( QWeakPointer<Result> weakRef )
{
QMutexLocker lock( &m_mutex );
m_ownRef = weakRef;
}

View File

@@ -31,6 +31,7 @@
#include <QPixmap>
#include <QPointer>
#include <QVariant>
#include <QMutex>
class MetadataEditor;
@@ -131,7 +132,7 @@ public:
track_ptr track() const;
QList<DownloadFormat> downloadFormats() const { return m_formats; }
QList< DownloadFormat > downloadFormats() const;
void setDownloadFormats( const QList<DownloadFormat>& formats );
downloadjob_ptr downloadJob() const { return m_downloadJob; }
@@ -161,6 +162,8 @@ private:
explicit Result( const QString& url, const Tomahawk::track_ptr& track );
explicit Result();
mutable QMutex m_mutex;
mutable RID m_rid;
collection_wptr m_collection;
QPointer< Tomahawk::Resolver > m_resolver;

View File

@@ -37,6 +37,7 @@
#include <QtAlgorithms>
#include <QDateTime>
#include <QReadWriteLock>
#include <QCoreApplication>
using namespace Tomahawk;
@@ -92,6 +93,7 @@ Track::get( const QString& artist, const QString& track, const QString& album, c
}
track_ptr t = track_ptr( new Track( artist, track, album, albumArtist, duration, composer, albumpos, discnumber ), &Track::deleteLater );
t->moveToThread( QCoreApplication::instance()->thread() );
t->setWeakRef( t.toWeakRef() );
s_tracksByName.insert( key, t );

View File

@@ -19,8 +19,7 @@
#include "TrackData.h"
#include <QtAlgorithms>
#include <QReadWriteLock>
#include "audio/AudioEngine.h"
#include "collection/Collection.h"
@@ -41,6 +40,10 @@
#include "PlaylistEntry.h"
#include "SourceList.h"
#include <QtAlgorithms>
#include <QReadWriteLock>
#include <QCoreApplication>
using namespace Tomahawk;
QHash< QString, trackdata_wptr > TrackData::s_trackDatasByName = QHash< QString, trackdata_wptr >();
@@ -84,6 +87,7 @@ TrackData::get( unsigned int id, const QString& artist, const QString& track )
}
trackdata_ptr t = trackdata_ptr( new TrackData( id, artist, track ), &TrackData::deleteLater );
t->moveToThread( QCoreApplication::instance()->thread() );
t->setWeakRef( t.toWeakRef() );
s_trackDatasByName.insert( key, t );

View File

@@ -253,7 +253,7 @@ namespace Tomahawk
typedef QHash< QString, QString > InfoStringHash;
typedef QPair< QVariantMap, QVariant > PushInfoPair;
typedef QPointer< InfoPlugin > InfoPluginPtr;
typedef QSharedPointer< InfoPlugin > InfoPluginPtr;
}
namespace Network

View File

@@ -79,7 +79,7 @@ ResolverAccountFactory::createFromPath( const QString& path )
}
Account*
ResolverAccount*
ResolverAccountFactory::createFromPath( const QString& path, const QString& factory, bool isAttica )
{
qDebug() << "Creating ResolverAccount from path:" << path << "is attica" << isAttica;
@@ -110,57 +110,8 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
if ( pathInfo.suffix() == "axe" )
{
QString uniqueName = uuid();
QDir dir( TomahawkUtils::extractScriptPayload( pathInfo.filePath(),
uniqueName,
MANUALRESOLVERS_DIR ) );
if ( !( dir.exists() && dir.isReadable() ) ) //decompression fubar
if ( !installAxe( realPath, configuration ) )
{
displayError( tr( "Resolver installation error: cannot open bundle." ) );
return 0;
}
if ( !dir.cd( "content" ) ) //more fubar
{
displayError( tr( "Resolver installation error: incomplete bundle." ) );
return 0;
}
QString metadataFilePath = dir.absoluteFilePath( "metadata.json" );
configuration = metadataFromJsonFile( metadataFilePath );
configuration[ "bundleDir" ] = uniqueName;
if ( !configuration[ "pluginName" ].isNull() && !configuration[ "pluginName" ].toString().isEmpty() )
{
dir.cdUp();
if ( !dir.cdUp() ) //we're in MANUALRESOLVERS_DIR
return 0;
QString name = configuration[ "pluginName" ].toString();
QString namePath = dir.absoluteFilePath( name );
QFileInfo npI( namePath );
if ( npI.exists() && npI.isDir() )
{
TomahawkUtils::removeDirectory( namePath );
}
dir.rename( uniqueName, name );
configuration[ "bundleDir" ] = name;
if ( !dir.cd( QString( "%1/content" ).arg( name ) ) ) //should work if it worked once
return 0;
}
expandPaths( dir, configuration );
realPath = configuration[ "path" ].toString();
if ( realPath.isEmpty() )
{
displayError( tr( "Resolver installation error: bad metadata in bundle." ) );
return 0;
}
}
@@ -221,6 +172,71 @@ ResolverAccountFactory::createFromPath( const QString& path, const QString& fact
}
bool
ResolverAccountFactory::installAxe( QString& realPath, QVariantHash& configuration )
{
const QFileInfo pathInfo( realPath );
QString uniqueName = uuid();
QDir dir( TomahawkUtils::extractScriptPayload( pathInfo.filePath(),
uniqueName,
MANUALRESOLVERS_DIR ) );
if ( !( dir.exists() && dir.isReadable() ) ) //decompression fubar
{
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
tr( "Resolver installation error: cannot open bundle." ) ) );
return 0;
}
if ( !dir.cd( "content" ) ) //more fubar
{
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
tr( "Resolver installation error: incomplete bundle." ) ) );
return 0;
}
QString metadataFilePath = dir.absoluteFilePath( "metadata.json" );
configuration = metadataFromJsonFile( metadataFilePath );
configuration[ "bundleDir" ] = uniqueName;
if ( !configuration[ "pluginName" ].isNull() && !configuration[ "pluginName" ].toString().isEmpty() )
{
dir.cdUp();
if ( !dir.cdUp() ) //we're in MANUALRESOLVERS_DIR
return 0;
QString name = configuration[ "pluginName" ].toString();
QString namePath = dir.absoluteFilePath( name );
QFileInfo npI( namePath );
if ( npI.exists() && npI.isDir() )
{
TomahawkUtils::removeDirectory( namePath );
}
dir.rename( uniqueName, name );
configuration[ "bundleDir" ] = name;
if ( !dir.cd( QString( "%1/content" ).arg( name ) ) ) //should work if it worked once
return 0;
}
expandPaths( dir, configuration );
realPath = configuration[ "path" ].toString();
if ( realPath.isEmpty() )
{
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
tr( "Resolver installation error: bad metadata in bundle." ) ) );
return 0;
}
return true;
}
QVariantHash
ResolverAccountFactory::metadataFromJsonFile( const QString& path )
{
@@ -517,7 +533,8 @@ ResolverAccount::removeBundle()
}
void ResolverAccount::testConfig()
void
ResolverAccount::testConfig()
{
// HACK: move to JSAccount once we have that properly
JSResolver* resolver = qobject_cast< Tomahawk::JSResolver* >( m_resolver );
@@ -535,6 +552,13 @@ void ResolverAccount::testConfig()
}
ExternalResolverGui*
ResolverAccount::resolver() const
{
return m_resolver;
}
void
ResolverAccount::onTestConfig( const QVariantMap& result )
{

View File

@@ -33,6 +33,8 @@ class ExternalResolverGui;
namespace Accounts {
class ResolverAccount;
class DLLEXPORT ResolverAccountFactory : public AccountFactory
{
Q_OBJECT
@@ -53,7 +55,10 @@ public:
Account* createFromPath( const QString& path ) override;
// Internal use
static Account* createFromPath( const QString& path, const QString& factoryId, bool isAttica );
static ResolverAccount* createFromPath( const QString& path, const QString& factoryId, bool isAttica );
// YES, non const parameters!
static bool installAxe( QString& realPath, QVariantHash& configuration );
private:
static void displayError( const QString& error );
@@ -101,6 +106,8 @@ public:
void testConfig() override;
ExternalResolverGui* resolver() const;
private slots:
void resolverChanged();
void onTestConfig( const QVariantMap& result );

View File

@@ -71,7 +71,7 @@ LastFmAccount::LastFmAccount( const QString& accountId )
if ( infoPlugin() && Tomahawk::InfoSystem::InfoSystem::instance()->workerThread() )
{
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
infoPlugin()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
}
}
@@ -82,7 +82,6 @@ LastFmAccount::~LastFmAccount()
if ( m_infoPlugin )
{
Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin() );
delete m_infoPlugin;
}
delete m_resolver.data();
@@ -168,9 +167,11 @@ InfoPluginPtr
LastFmAccount::infoPlugin()
{
if ( m_infoPlugin.isNull() )
m_infoPlugin = QPointer< LastFmInfoPlugin >( new LastFmInfoPlugin( this ) );
{
m_infoPlugin = QSharedPointer< LastFmInfoPlugin>( new LastFmInfoPlugin( this ) );
}
return InfoPluginPtr( m_infoPlugin.data() );
return m_infoPlugin;
}
bool

View File

@@ -105,7 +105,7 @@ private:
void hookupResolver();
QPointer<Tomahawk::ExternalResolverGui> m_resolver;
QPointer<Tomahawk::InfoSystem::LastFmInfoPlugin> m_infoPlugin;
QSharedPointer<Tomahawk::InfoSystem::LastFmInfoPlugin> m_infoPlugin;
QPointer<LastFmConfig> m_configWidget;
};

View File

@@ -116,6 +116,12 @@ SpotifyAccount::~SpotifyAccount()
{
clearUser();
if ( m_infoPlugin )
{
Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin() );
}
if ( m_spotifyResolver.isNull() )
return;
@@ -135,7 +141,7 @@ SpotifyAccount::init()
if ( infoPlugin() && Tomahawk::InfoSystem::InfoSystem::instance()->workerThread() )
{
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
infoPlugin()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
}
@@ -366,10 +372,10 @@ SpotifyAccount::infoPlugin()
{
if ( m_infoPlugin.isNull() )
{
m_infoPlugin = QPointer< InfoSystem::SpotifyInfoPlugin >( new InfoSystem::SpotifyInfoPlugin( this ) );
m_infoPlugin = QSharedPointer< InfoSystem::SpotifyInfoPlugin >( new InfoSystem::SpotifyInfoPlugin( this ) );
}
return InfoSystem::InfoPluginPtr( m_infoPlugin.data() );
return m_infoPlugin;
}
@@ -842,28 +848,15 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
const QString qid = msg.value( "qid" ).toString();
if ( m_qidToSlotMap.contains( qid ) )
{
QPointer< QObject > receiver = m_qidToSlotMap[ qid ].first;
QObject* receiver = m_qidToSlotMap[ qid ].first;
QString slot = m_qidToSlotMap[ qid ].second;
m_qidToSlotMap.remove( qid );
QVariant extraData;
if ( m_qidToExtraData.contains( qid ) )
extraData = m_qidToExtraData.take( qid );
// FIXME: SpotifyParser is sometimes a dangling pointer, haven't found a real way to reproduce: happens sometimes when dropping a playlist url onto the sidebar
//Q_ASSERT( !receiver.isNull() );
if ( !receiver.isNull() )
{
QMetaObject::invokeMethod( receiver, slot.toLatin1(), Q_ARG( QString, msgType ), Q_ARG( QVariantMap, msg ), Q_ARG( QVariant, extraData ) );
}
else
{
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
tr( "Spotify account could not finish action. Try again." )
) );
}
QMetaObject::invokeMethod( receiver, slot.toLatin1(), Q_ARG( QString, msgType ), Q_ARG( QVariantMap, msg ), Q_ARG( QVariant, extraData ) );
}
else if ( msgType == "allPlaylists" )
{

View File

@@ -170,9 +170,9 @@ private:
QPointer<SpotifyAccountConfig> m_configWidget;
QPointer<QWidget> m_aboutWidget;
QPointer<ScriptResolver> m_spotifyResolver;
QPointer< InfoSystem::SpotifyInfoPlugin > m_infoPlugin;
QSharedPointer< InfoSystem::SpotifyInfoPlugin > m_infoPlugin;
QMap<QString, QPair< QPointer< QObject >, QString> > m_qidToSlotMap;
QMap<QString, QPair<QObject*, QString> > m_qidToSlotMap;
QMap<QString, QVariant > m_qidToExtraData;
// List of synced spotify playlists in config UI

View File

@@ -277,7 +277,7 @@ SpotifyAccountConfig::showLoggedIn()
m_ui->verticalLayout->insertWidget( 1, m_loggedInUser, 0, Qt::AlignCenter );
}
qDebug() << "Showing logged in withuserame:" << m_verifiedUsername;
qDebug() << "Showing logged in with username:" << m_verifiedUsername;
m_loggedInUser->show();
m_loggedInUser->setText( tr( "Logged in as %1" ).arg( m_verifiedUsername ) );

View File

@@ -669,7 +669,7 @@ AudioEngine::performLoadIODevice( const result_ptr& result, const QString& url )
void
AudioEngine::performLoadTrack( const Tomahawk::result_ptr result, const QString url, QSharedPointer< QIODevice > io )
AudioEngine::performLoadTrack( const Tomahawk::result_ptr result, const QString& url, QSharedPointer< QIODevice > io )
{
if ( QThread::currentThread() != thread() )
{

View File

@@ -186,7 +186,7 @@ private slots:
void performLoadIODevice( const Tomahawk::result_ptr& result, const QString& url ); //only call from loadTrack kthxbi
void performLoadTrack( const Tomahawk::result_ptr result, const QString url, QSharedPointer< QIODevice > io ); //only call from loadTrack or performLoadIODevice kthxbi
void performLoadTrack( const Tomahawk::result_ptr result, const QString& url, QSharedPointer< QIODevice > io ); //only call from loadTrack or performLoadIODevice kthxbi
void loadPreviousTrack();
void loadNextTrack();

View File

@@ -277,8 +277,8 @@ InfoSystem::addInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin )
if ( plugin.data()->thread() != m_infoSystemWorkerThreadController->worker()->thread() )
{
tLog() << Q_FUNC_INFO << "The object must be moved to the worker thread first, see InfoSystem::workerThread(): " << plugin->friendlyName();
Q_ASSERT( false );
tDebug() << Q_FUNC_INFO << "The object must be moved to the worker thread first, see InfoSystem::workerThread()";
return;
}

View File

@@ -58,13 +58,7 @@ InfoSystemWorker::InfoSystemWorker()
InfoSystemWorker::~InfoSystemWorker()
{
tDebug() << Q_FUNC_INFO << " beginning";
Q_FOREACH( InfoPluginPtr plugin, m_plugins )
{
if( plugin )
delete plugin.data();
}
tDebug() << Q_FUNC_INFO << " finished";
tDebug() << Q_FUNC_INFO;
}
@@ -136,29 +130,6 @@ InfoSystemWorker::addInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin )
emit updatedSupportedGetTypes( QSet< InfoType >::fromList( m_infoGetMap.keys() ) );
emit updatedSupportedPushTypes( QSet< InfoType >::fromList( m_infoPushMap.keys() ) );
connect( plugin.data(), SIGNAL( destroyed( QObject* ) ), SLOT( onInfoPluginDeleted() ) );
}
void
InfoSystemWorker::onInfoPluginDeleted()
{
foreach( const InfoPluginPtr& plugin, m_plugins )
{
if ( plugin.isNull() )
{
m_plugins.removeOne( plugin );
foreach( InfoType type, m_infoGetMap.keys() )
{
m_infoGetMap[type].removeOne( plugin );
}
foreach( InfoType type, m_infoPushMap.keys() )
{
m_infoPushMap[type].removeOne( plugin );
}
}
}
}

View File

@@ -72,7 +72,6 @@ public slots:
private slots:
void checkTimeoutsTimerFired();
void onInfoPluginDeleted();
private:
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &getTypes, const QSet< InfoType > &pushTypes );

View File

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

View File

@@ -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

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( 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()
{

View File

@@ -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;

View File

@@ -1,10 +1,10 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 2016 Dominik Schmidt <domme@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 2 of the License, or
* 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,
@@ -15,10 +15,23 @@
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LinkParserPlugin.h"
#include "LinkParser.h"
#include "ScriptErrorStatusMessage.h"
#include "../utils/Logger.h"
Tomahawk::Utils::LinkParserPlugin::~LinkParserPlugin()
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

@@ -1,10 +1,10 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 2016 Dominik Schmidt <domme@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 2 of the License, or
* 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,
@@ -16,25 +16,24 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef TOMAHAWK_UTILS_URLTYPE_H
#define TOMAHAWK_UTILS_URLTYPE_H
#ifndef SCRIPTERRORSTATUSMESSAGE_H
#define SCRIPTERRORSTATUSMESSAGE_H
namespace Tomahawk {
#include "ErrorStatusMessage.h"
#include "../resolvers/ScriptAccount.h"
namespace Utils {
#include "DllMacro.h"
enum UrlType
class DLLEXPORT ScriptErrorStatusMessage : public ErrorStatusMessage
{
UrlTypeAny = 0x00,
UrlTypePlaylist = 0x01,
UrlTypeTrack = 0x02,
UrlTypeAlbum = 0x04,
UrlTypeArtist = 0x08,
UrlTypeXspf = 0x10
Q_OBJECT
public:
explicit ScriptErrorStatusMessage( const QString& scriptErrorMessage, Tomahawk::ScriptAccount* );
void activated() override;
private:
QPointer< Tomahawk::ScriptAccount > m_account;
};
} // namespace Utils
} // namespace Tomahawk
#endif // TOMAHAWK_UTILS_URLTYPE_H
#endif // SCRIPTERRORSTATUSMESSAGE_H

View File

@@ -118,6 +118,10 @@ ColumnView::setModel( QAbstractItemModel* model )
void
ColumnView::setTreeModel( TreeModel* model )
{
// HACK: without setting a new preview widget, the old preview widget is shown in the first column while loading the artists.
m_previewWidget = new ColumnViewPreviewWidget( this );
setPreviewWidget( m_previewWidget );
m_model = model;
if ( m_proxyModel )

View File

@@ -96,8 +96,10 @@ ContextView::ContextView( QWidget* parent, const QString& caption )
connect( m_captionLabel, SIGNAL( clicked() ), SIGNAL( closeClicked() ) );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), SLOT( onQuerySelected( Tomahawk::query_ptr ) ) );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), m_detailView, SLOT( setQuery( Tomahawk::query_ptr ) ) );
connect( m_trackView, SIGNAL( modelChanged() ), SLOT( onModelChanged() ) );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), m_detailView, SLOT( setQuery( Tomahawk::query_ptr ) ) );
connect( m_detailView, SIGNAL( downloadAll() ), SLOT( onDownloadAll() ) );
connect( m_detailView, SIGNAL( downloadCancel() ), SLOT( onDownloadCancel() ) );
TomahawkUtils::fixMargins( this );
}

View File

@@ -20,11 +20,15 @@
#include "GridItemDelegate.h"
#include <QApplication>
#include <QDesktopServices>
#include <QPainter>
#include <QAbstractItemView>
#include <QMouseEvent>
#include <QTimeLine>
#include "DownloadManager.h"
#include "DownloadJob.h"
#include "Artist.h"
#include "Query.h"
#include "Result.h"
@@ -35,12 +39,14 @@
#include "playlist/PlayableItem.h"
#include "playlist/PlayableProxyModel.h"
#include "widgets/HoverControls.h"
#include "widgets/DropDownButton.h"
#include "widgets/ImageButton.h"
#include "utils/TomahawkStyle.h"
#include "utils/TomahawkUtilsGui.h"
#include "utils/PixmapDelegateFader.h"
#include "utils/Closure.h"
#include "utils/AnimatedSpinner.h"
#include "utils/WebPopup.h"
#include "utils/DpiScaler.h"
#include "utils/Logger.h"
@@ -55,6 +61,7 @@ GridItemDelegate::GridItemDelegate( QAbstractItemView* parent, PlayableProxyMode
, m_model( proxy )
, m_itemWidth( 0 )
, m_showPosition( false )
, m_showBuyButtons( false )
, m_wordWrapping( false )
, m_margin( TomahawkUtils::DpiScaler::scaledY( parent, 32 ) )
{
@@ -93,7 +100,8 @@ GridItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelInde
if ( !m_wordWrapping )
return QSize( m_itemWidth, m_itemWidth + fm.height() + m_margin * 0.8 );
return QSize( m_itemWidth, m_itemWidth + fm.height() + fms.height() + m_margin * 0.8 );
const int buyButtonHeight = m_showBuyButtons ? 40 : 0;
return QSize( m_itemWidth, m_itemWidth + fm.height() + fms.height() + buyButtonHeight + m_margin * 0.8 );
}
}
@@ -275,6 +283,11 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->setFont( f );
}
if ( m_showBuyButtons && !item->query().isNull() )
{
textRect.adjust( 0, 0, 0, -40 );
}
to.setAlignment( Qt::AlignLeft | Qt::AlignTop );
text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - m_margin / 4 );
painter->drawText( textRect, text, to );
@@ -286,6 +299,7 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
}
painter->restore();
painter->save();
painter->setOpacity( 0.6 );
painter->setFont( m_smallFont );
@@ -304,6 +318,48 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
// Calculate rect of artist on-hover button click area
m_artistNameRects[ index ] = painter->fontMetrics().boundingRect( textRect, Qt::AlignLeft | Qt::AlignBottom, text );
painter->restore();
if ( m_showBuyButtons && !item->query().isNull() )
{
QRect r = textRect;
r.setY( textRect.y() + textRect.height() + 8 );
r.setHeight( 32 );
m_buyButtonRects[ index ] = r;
QString text;
if ( item->result() &&
( ( !item->result()->downloadFormats().isEmpty() && !DownloadManager::instance()->localFileForDownload( item->result()->downloadFormats().first().url.toString() ).isEmpty() ) ||
( item->result()->downloadJob() && item->result()->downloadJob()->state() == DownloadJob::Finished ) ) )
{
text = tr( "View in Finder" );
}
else if ( item->query() && item->query()->numResults( true ) && !item->query()->results().first()->downloadFormats().isEmpty() )
{
text = tr( "Download %1" ).arg( item->query()->results().first()->downloadFormats().first().extension.toUpper() );
}
else if ( item->query()->numResults( true ) && !item->query()->results().first()->purchaseUrl().isEmpty() )
{
text = tr( "Buy" );
}
if ( !item->result() || !item->result()->downloadJob() )
{
if ( !text.isEmpty() )
DropDownButton::drawPrimitive( painter, r, text, m_hoveringOverBuyButton == index, false );
}
else
{
painter->setPen( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND.darker() );
painter->setBrush( TomahawkStyle::PLAYLIST_PROGRESS_BACKGROUND );
painter->drawRect( r.adjusted( 2, 2, -2, -2 ) );
painter->setPen( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND );
painter->setBrush( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND );
QRect fillp = r.adjusted( 3, 3, -3, -3 );
fillp.setWidth( float(fillp.width()) * ( float(item->result()->downloadJob()->progressPercentage()) / 100.0 ) );
painter->drawRect( fillp );
}
}
}
painter->restore();
@@ -362,6 +418,7 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
bool hoveringArtist = false;
bool hoveringAlbum = false;
bool hoveringBuyButton = false;
if ( m_artistNameRects.contains( index ) )
{
const QRect artistNameRect = m_artistNameRects[ index ];
@@ -372,6 +429,11 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
const QRect albumNameRect = m_albumNameRects[ index ];
hoveringAlbum = albumNameRect.contains( ev->pos() );
}
if ( m_buyButtonRects.contains( index ) )
{
const QRect buyButtonRect = m_buyButtonRects[ index ];
hoveringBuyButton = buyButtonRect.contains( ev->pos() );
}
QRect coverRect = m_view->visualRect( index );
coverRect.setHeight( coverRect.width() );
@@ -379,7 +441,7 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
if ( event->type() == QEvent::MouseMove )
{
if ( hoveringArtist || hoveringAlbum )
if ( hoveringArtist || hoveringAlbum || hoveringBuyButton )
m_view->setCursor( Qt::PointingHandCursor );
else
m_view->setCursor( Qt::ArrowCursor );
@@ -435,6 +497,17 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
emit updateIndex( index );
}
if ( m_hoveringOverBuyButton != index || ( !hoveringBuyButton && m_hoveringOverBuyButton.isValid() ) )
{
emit updateIndex( m_hoveringOverBuyButton );
if ( hoveringBuyButton )
m_hoveringOverBuyButton = index;
else
m_hoveringOverBuyButton = QPersistentModelIndex();
emit updateIndex( index );
}
if ( m_hoverIndex != index || !hoveringCover )
{
@@ -544,6 +617,27 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
}
}
if ( hoveringBuyButton )
{
if ( event->type() == QEvent::MouseButtonRelease )
{
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
if ( !item )
return false;
if ( item->query() && item->query()->numResults( true ) && !item->query()->results().first()->downloadFormats().isEmpty() )
{
m_view->edit( index );
return true;
}
else
{
WebPopup* popup = new WebPopup( item->query()->results().first()->purchaseUrl(), QSize( 400, 800 ) );
connect( item->query()->results().first().data(), SIGNAL( destroyed() ), popup, SLOT( close() ) );
}
}
}
return false;
}
@@ -555,6 +649,7 @@ GridItemDelegate::modelChanged()
m_albumNameRects.clear();
m_hoveringOverArtist = QPersistentModelIndex();
m_hoveringOverAlbum = QPersistentModelIndex();
m_hoveringOverBuyButton = QPersistentModelIndex();
m_hoverIndex = QPersistentModelIndex();
clearButtons();
@@ -687,6 +782,10 @@ GridItemDelegate::resetHoverIndex()
idx = m_hoveringOverAlbum;
m_hoveringOverAlbum = QPersistentModelIndex();
doUpdateIndex( idx );
idx = m_hoveringOverBuyButton;
m_hoveringOverBuyButton = QPersistentModelIndex();
doUpdateIndex( idx );
}
@@ -758,3 +857,97 @@ GridItemDelegate::eventFilter( QObject* obj, QEvent* event )
else
return QObject::eventFilter( obj, event );
}
QWidget*
GridItemDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
Q_ASSERT( item );
if ( item->result() && !item->result()->downloadFormats().isEmpty() &&
!DownloadManager::instance()->localFileForDownload( item->result()->downloadFormats().first().url.toString() ).isEmpty() )
{
QDesktopServices::openUrl( QUrl::fromLocalFile( QFileInfo( DownloadManager::instance()->localFileForDownload( item->result()->downloadFormats().first().url.toString() ) ).absolutePath() ) );
}
else if ( item->result() && item->result()->downloadJob() && item->result()->downloadJob()->state() == DownloadJob::Finished )
{
QDesktopServices::openUrl( QUrl::fromLocalFile( QFileInfo( item->result()->downloadJob()->localFile() ).absolutePath() ) );
}
else if ( item->result() &&
!item->result()->downloadFormats().isEmpty() && !item->result()->downloadJob() )
{
QStringList formats;
foreach ( const DownloadFormat& format, item->result()->downloadFormats() )
{
formats << tr( "Download %1" ).arg( format.extension.toUpper() );
}
DropDownButton* editor = new DropDownButton( parent );
editor->addItems( formats );
NewClosure( editor, SIGNAL( clicked() ),
const_cast<GridItemDelegate*>(this), SLOT( addDownloadJob( const QModelIndex&, QWidget* ) ), index, (QWidget*)editor );
NewClosure( editor, SIGNAL( activated( int ) ),
const_cast<GridItemDelegate*>(this), SLOT( addDownloadJob( const QModelIndex&, QWidget* ) ), index, (QWidget*)editor );
return editor;
}
return 0;
}
void
GridItemDelegate::addDownloadJob( const QModelIndex& index, QWidget* editor )
{
PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
Q_ASSERT( item );
m_view->closePersistentEditor( index );
DropDownButton* cb = static_cast< DropDownButton* >(editor);
if ( !item->result()->downloadFormats().isEmpty() )
DownloadManager::instance()->addJob( item->result()->toDownloadJob( item->result()->downloadFormats().at( cb->currentIndex() ) ) );
}
void
GridItemDelegate::closeEditor( const QModelIndex& index, QWidget* editor )
{
PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
Q_ASSERT( item );
m_view->closePersistentEditor( index );
DropDownButton* cb = static_cast< DropDownButton* >(editor);
editor->deleteLater();
}
void
GridItemDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
QStyledItemDelegate::updateEditorGeometry( editor, option, index );
DropDownButton* comboBox = static_cast<DropDownButton*>(editor);
comboBox->resize( option.rect.size() - QSize( 8, 0 ) );
comboBox->move( option.rect.x() + 4, option.rect.y() );
if ( m_downloadDropDownRects.contains( index ) )
{
editor->setGeometry( m_downloadDropDownRects.value( index ) );
}
if ( !comboBox->property( "shownPopup" ).toBool() )
{
comboBox->showPopup();
comboBox->setProperty( "shownPopup", true );
}
}
void
GridItemDelegate::setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const
{
}

View File

@@ -48,6 +48,7 @@ public:
QSize itemSize() const;
void setItemWidth( int width ) { m_itemWidth = width; }
void setShowBuyButtons( bool enabled ) { m_showBuyButtons = enabled; }
public slots:
void resetHoverIndex();
@@ -61,6 +62,10 @@ protected:
bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
bool eventFilter( QObject* obj, QEvent* event );
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const;
signals:
void updateIndex( const QModelIndex& idx );
@@ -82,6 +87,9 @@ private slots:
void fadingFrameChanged( const QPersistentModelIndex& );
void fadingFrameFinished( const QPersistentModelIndex& );
void closeEditor( const QModelIndex& index, QWidget* editor );
void addDownloadJob( const QModelIndex& index, QWidget* editor );
private:
QTimeLine* createTimeline( QTimeLine::Direction direction, int startFrame = 0 );
void clearButtons();
@@ -90,15 +98,19 @@ private:
PlayableProxyModel* m_model;
int m_itemWidth;
bool m_showPosition;
bool m_showBuyButtons;
bool m_wordWrapping;
mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects;
mutable QHash< QPersistentModelIndex, QRect > m_albumNameRects;
mutable QHash< QPersistentModelIndex, QRect > m_buyButtonRects;
mutable QHash< QPersistentModelIndex, QRect > m_downloadDropDownRects;
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_covers;
QPersistentModelIndex m_hoverIndex;
QPersistentModelIndex m_hoveringOverArtist;
QPersistentModelIndex m_hoveringOverAlbum;
QPersistentModelIndex m_hoveringOverBuyButton;
mutable QHash< QPersistentModelIndex, QWidget* > m_spinner;
mutable QHash< QPersistentModelIndex, HoverControls* > m_hoverControls;

View File

@@ -255,6 +255,8 @@ void GridView::wheelEvent( QWheelEvent* e )
// ^ scroll step is 1/8 of the estimated row height
QListView::wheelEvent( e );
m_delegate->resetHoverIndex();
}

View File

@@ -119,8 +119,9 @@ int
PlayableModel::columnCount( const QModelIndex& parent ) const
{
Q_UNUSED( parent );
Q_D( const PlayableModel );
return 13;
return d->header.length();
}
@@ -444,14 +445,21 @@ PlayableModel::flags( const QModelIndex& index ) const
if ( index.isValid() )
{
Qt::ItemFlags returnFlags = defaultFlags;
if ( index.column() == 0 )
{
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
returnFlags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
}
else if ( index.column() == PlayableModel::Download )
{
return Qt::ItemIsEditable | defaultFlags;
returnFlags |= Qt::ItemIsEditable | defaultFlags;
}
if ( areAllColumnsEditable() ) {
returnFlags |= Qt::ItemIsEditable;
}
return returnFlags;
}
return Qt::ItemIsDropEnabled | defaultFlags;
@@ -1019,7 +1027,7 @@ PlayableModel::appendAlbums( const QList< Tomahawk::album_ptr >& albums )
void
PlayableModel::appendAlbums( const Tomahawk::collection_ptr& collection )
{
emit loadingStarted();
startLoading();
insertAlbums( collection, rowCount( QModelIndex() ) );
}
@@ -1034,7 +1042,7 @@ PlayableModel::appendQueries( const QList< Tomahawk::query_ptr >& queries )
void
PlayableModel::appendTracks( const QList< Tomahawk::track_ptr >& tracks, const QList< Tomahawk::PlaybackLog >& logs )
{
emit loadingStarted();
startLoading();
QList< Tomahawk::query_ptr > queries;
foreach ( const track_ptr& track, tracks )
{
@@ -1048,7 +1056,7 @@ PlayableModel::appendTracks( const QList< Tomahawk::track_ptr >& tracks, const Q
void
PlayableModel::appendTracks( const Tomahawk::collection_ptr& collection )
{
emit loadingStarted();
startLoading();
insertTracks( collection, rowCount( QModelIndex() ) );
}
@@ -1171,6 +1179,22 @@ PlayableModel::setIcon( const QPixmap& pixmap )
}
void
PlayableModel::setAllColumnsEditable( bool editable )
{
Q_D( PlayableModel );
d->areAllColumnsEditable = editable;
}
bool
PlayableModel::areAllColumnsEditable() const
{
Q_D( const PlayableModel );
return d->areAllColumnsEditable;
}
int
PlayableModel::trackCount() const
{

View File

@@ -96,6 +96,11 @@ public:
virtual QPixmap icon() const;
virtual void setIcon( const QPixmap& pixmap );
// HACK: we need to set column 0 editable for DropDownButton in TrackView
void setAllColumnsEditable( bool editable );
bool areAllColumnsEditable() const;
virtual int trackCount() const;
virtual int itemCount() const;

View File

@@ -38,6 +38,7 @@ public:
, rootItem( new PlayableItem( 0 ) )
, readOnly( true )
, loading( _loading )
, areAllColumnsEditable( false )
{
}
@@ -58,6 +59,7 @@ private:
QStringList header;
bool loading;
bool areAllColumnsEditable;
};
#endif // PLAYABLEMODEL_P_H

View File

@@ -607,25 +607,7 @@ PlayableProxyModel::columnCount( const QModelIndex& parent ) const
{
Q_UNUSED( parent );
switch ( m_style )
{
case SingleColumn:
return 1;
break;
case Collection:
return 10;
break;
case Locker:
return 11;
break;
case Detailed:
default:
return 12;
break;
}
return m_headerStyle[ m_style ].length();
}
@@ -733,6 +715,13 @@ PlayableProxyModel::setFilter( const QString& pattern )
}
int
PlayableProxyModel::mapSourceColumnToColumn( PlayableModel::Columns column )
{
return m_headerStyle[ m_style ].indexOf( column );
}
void
PlayableProxyModel::setCurrentIndex( const QModelIndex& index )
{

View File

@@ -98,6 +98,8 @@ public:
virtual void setFilter( const QString& pattern );
virtual void updateDetailedInfo( const QModelIndex& index );
int mapSourceColumnToColumn( PlayableModel::Columns column );
signals:
void filterChanged( const QString& filter );

View File

@@ -23,6 +23,7 @@
#include <QAbstractTextDocumentLayout>
#include <QApplication>
#include <QDateTime>
#include <QDesktopServices>
#include <QMouseEvent>
#include <QPainter>
#include <QDesktopServices>
@@ -51,6 +52,7 @@
#include "utils/Closure.h"
#include "utils/TomahawkStyle.h"
#include "utils/TomahawkUtilsGui.h"
#include "utils/WebPopup.h"
#include "utils/Logger.h"
using namespace Tomahawk;
@@ -123,16 +125,16 @@ PlaylistItemDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem&
PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
Q_ASSERT( item );
if ( index.column() == PlayableModel::Download && item->result() && !item->result()->downloadFormats().isEmpty() &&
if ( /*index.column() == PlayableModel::Download &&*/ item->result() && !item->result()->downloadFormats().isEmpty() &&
!DownloadManager::instance()->localFileForDownload( item->result()->downloadFormats().first().url.toString() ).isEmpty() )
{
QDesktopServices::openUrl( QUrl::fromLocalFile( QFileInfo( DownloadManager::instance()->localFileForDownload( item->result()->downloadFormats().first().url.toString() ) ).absolutePath() ) );
}
else if ( index.column() == PlayableModel::Download && item->result() && item->result()->downloadJob() && item->result()->downloadJob()->state() == DownloadJob::Finished )
else if ( /*index.column() == PlayableModel::Download &&*/ item->result() && item->result()->downloadJob() && item->result()->downloadJob()->state() == DownloadJob::Finished )
{
QDesktopServices::openUrl( QUrl::fromLocalFile( QFileInfo( item->result()->downloadJob()->localFile() ).absolutePath() ) );
}
else if ( index.column() == PlayableModel::Download && item->result() &&
else if ( /*index.column() == PlayableModel::Download &&*/ item->result() &&
!item->result()->downloadFormats().isEmpty() && !item->result()->downloadJob() )
{
QStringList formats;
@@ -192,9 +194,14 @@ PlaylistItemDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionV
comboBox->resize( option.rect.size() - QSize( 8, 0 ) );
comboBox->move( option.rect.x() + 4, option.rect.y() );
if ( m_downloadDropDownRects.contains( index ) )
{
editor->setGeometry( m_downloadDropDownRects.value( index ) );
}
if ( !comboBox->property( "shownPopup" ).toBool() )
{
// comboBox->showPopup();
comboBox->showPopup();
comboBox->setProperty( "shownPopup", true );
}
}
@@ -291,7 +298,8 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
}
else if ( !item->result()->downloadJob() )
{
DropDownButton::drawPrimitive( painter, optc.rect, optc.currentText );
DropDownButton::drawPrimitive( painter, optc.rect, optc.currentText, hoveringOver() == index, true );
/* QApplication::style()->drawComplexControl( QStyle::CC_ComboBox, &optc, painter, 0 );
optc.rect.adjust( 4, 0, 0, 0 );
QApplication::style()->drawControl( QStyle::CE_ComboBoxLabel, &optc, painter, 0 );*/
@@ -604,6 +612,7 @@ QRect
PlaylistItemDelegate::drawTrack( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QRect& rect, PlayableItem* item ) const
{
const track_ptr track = item->query()->track();
const bool hasOnlineResults = ( item->query()->numResults( true ) > 0 );
painter->save();
painter->setRenderHint( QPainter::TextAntialiasing );
@@ -630,21 +639,87 @@ PlaylistItemDelegate::drawTrack( QPainter* painter, const QStyleOptionViewItem&
QRect numberRect = QRect( r.x(), r.y(), numberWidth, r.height() );
QRect extraRect = QRect( r.x() + r.width() - durationWidth, r.y(), durationWidth, r.height() );
QRect stateRect;
if ( option.state & QStyle::State_Selected || hoveringOver() == index )
QRect stateRect = extraRect.adjusted( 0, 0, 0, 0 );
if ( option.state & QStyle::State_Selected || hoveringOver() == index )
{
int h = extraRect.height() / 3;
if ( track->loved() )
{
painter->save();
painter->setOpacity( 0.5 );
int h = extraRect.height() / 3;
stateRect = extraRect.adjusted( -16, extraRect.height() / 2 - h / 2, 0, 0 );
stateRect.setHeight( h );
stateRect.setWidth( stateRect.height() );
painter->drawPixmap( stateRect, ImageRegistry::instance()->pixmap( RESPATH "images/love.svg", stateRect.size() ) );
QRect r = stateRect.adjusted( -16, extraRect.height() / 2 - h / 2, 0, 0 );
r.setHeight( h );
r.setWidth( r.height() );
painter->drawPixmap( r, ImageRegistry::instance()->pixmap( RESPATH "images/love.svg", r.size() ) );
painter->restore();
stateWidth = stateRect.width() + 16;
stateWidth += r.width() + 16;
}
if ( hasOnlineResults && !item->query()->results().first()->purchaseUrl().isEmpty() )
{
QRect r = stateRect.adjusted( -stateWidth -144, 6, 0, -6 );
r.setWidth( 144 );
DropDownButton::drawPrimitive( painter, r, tr( "Buy" ), m_hoveringOverBuyButton == index, false );
m_buyButtonRects[ index ] = r;
stateWidth += r.width() + 16;
}
}
if ( hasOnlineResults && !item->query()->results().first()->downloadFormats().isEmpty() )
{
painter->save();
QStyleOptionComboBox optc;
optc.rect = stateRect.adjusted( -stateWidth -144, 6, 0, -6 );
optc.rect.setWidth( 144 );
m_downloadDropDownRects[ index ] = optc.rect;
stateWidth += optc.rect.width() + 16;
optc.editable = false;
optc.currentText = tr( "Download %1" ).arg( item->query()->results().first()->downloadFormats().first().extension.toUpper() );
optc.palette = m_view->palette();
if ( option.state & QStyle::State_Selected && option.state & QStyle::State_Active )
optc.state = QStyle::State_Active | QStyle::State_Selected | QStyle::State_Enabled;
else
optc.state = QStyle::State_Active | QStyle::State_Enabled;
if ( !DownloadManager::instance()->localFileForDownload( item->query()->results().first()->downloadFormats().first().url.toString() ).isEmpty() )
{
painter->setPen( optc.palette.text().color() );
const QString text = painter->fontMetrics().elidedText( tr( "View in Finder" ), Qt::ElideRight, optc.rect.width() - 3 );
painter->drawText( optc.rect, text, QTextOption( Qt::AlignCenter ) );
}
else if ( !item->query()->results().first()->downloadJob() )
{
DropDownButton::drawPrimitive( painter, optc.rect, optc.currentText, hoveringOver() == index, true );
}
else
{
if ( item->query()->results().first()->downloadJob()->state() == DownloadJob::Finished )
{
painter->setPen( optc.palette.text().color() );
const QString text = painter->fontMetrics().elidedText( tr( "View in Finder" ), Qt::ElideRight, optc.rect.width() - 3 );
painter->drawText( optc.rect, text, QTextOption( Qt::AlignCenter ) );
}
else
{
painter->setPen( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND.darker() );
painter->setBrush( TomahawkStyle::PLAYLIST_PROGRESS_BACKGROUND );
painter->drawRect( optc.rect.adjusted( 2, 2, -2, -2 ) );
painter->setPen( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND );
painter->setBrush( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND );
QRect fillp = optc.rect.adjusted( 3, 3, -3, -3 );
fillp.setWidth( float(fillp.width()) * ( float(item->query()->results().first()->downloadJob()->progressPercentage()) / 100.0 ) );
painter->drawRect( fillp );
}
}
painter->restore();
}
const int remWidth = r.width() - numberWidth - durationWidth;
QRect titleRect = QRect( numberRect.x() + numberRect.width(), r.y(), (double)remWidth * 0.5, r.height() );
@@ -708,6 +783,7 @@ PlaylistItemDelegate::drawTrack( QPainter* painter, const QStyleOptionViewItem&
int h = extraRect.height() / 2;
QRect playIconRect = extraRect.adjusted( extraRect.width() - h - 8, h / 2, -8, -h / 2 );
playIconRect.setWidth( playIconRect.height() );
painter->drawPixmap( playIconRect, ImageRegistry::instance()->pixmap( RESPATH "images/play.svg", playIconRect.size() ) );
double duration = (double)AudioEngine::instance()->currentTrackTotalTime();
@@ -759,8 +835,11 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
bool hoveringArtist = false;
bool hoveringInfo = false;
bool hoveringLove = false;
bool hoveringBuy = false;
bool hoveringDownloadDropDown = false;
Tomahawk::source_ptr hoveredAvatar;
QRect hoveredAvatarRect;
if ( m_infoButtonRects.contains( index ) )
{
const QRect infoRect = m_infoButtonRects[ index ];
@@ -779,6 +858,18 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
hoveringLove = loveRect.contains( ev->pos() );
}
if ( m_buyButtonRects.contains( index ) )
{
const QRect buyRect = m_buyButtonRects[ index ];
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
hoveringBuy = buyRect.contains( ev->pos() );
}
if ( m_downloadDropDownRects.contains( index ) )
{
const QRect downloadDropDownRect = m_downloadDropDownRects[ index ];
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
hoveringDownloadDropDown = downloadDropDownRect.contains( ev->pos() );
}
if ( m_avatarBoxRects.contains( index ) )
{
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
@@ -796,7 +887,7 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
if ( event->type() == QEvent::MouseMove )
{
if ( hoveringInfo || hoveringLove || hoveringArtist )
if ( hoveringInfo || hoveringLove || hoveringArtist || hoveringBuy )
m_view->setCursor( Qt::PointingHandCursor );
else
m_view->setCursor( Qt::ArrowCursor );
@@ -820,6 +911,23 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
emit updateIndex( m_hoveringOverArtist );
m_hoveringOverArtist = QModelIndex();
}
if ( hoveringBuy && m_hoveringOverBuyButton != index )
{
QPersistentModelIndex ti = m_hoveringOverBuyButton;
m_hoveringOverBuyButton = index;
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( ti ) );
item->requestRepaint();
emit updateIndex( m_hoveringOverBuyButton );
}
if ( !hoveringBuy && m_hoveringOverBuyButton.isValid() )
{
QPersistentModelIndex ti = m_hoveringOverBuyButton;
m_hoveringOverBuyButton = QModelIndex();
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( ti ) );
item->requestRepaint();
}
if ( m_hoveringOver != index )
{
@@ -849,6 +957,11 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
{
item->query()->queryTrack()->setLoved( !item->query()->queryTrack()->loved() );
}
else if ( hoveringBuy )
{
WebPopup* popup = new WebPopup( item->query()->results().first()->purchaseUrl(), QSize( 400, 800 ) );
connect( item->query()->results().first().data(), SIGNAL( destroyed() ), popup, SLOT( close() ) );
}
else if ( hoveringInfo )
{
if ( m_model->style() == PlayableProxyModel::SingleColumn )
@@ -883,9 +996,11 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
}
}
}
else if ( m_view->proxyModel()->style() == PlayableProxyModel::Locker && index.column() == PlayableModel::Download )
else if ( ( m_view->proxyModel()->style() == PlayableProxyModel::Locker && index.column() == PlayableModel::Download ) || hoveringDownloadDropDown )
{
m_model->sourceModel()->setAllColumnsEditable( true );
m_view->edit( index );
m_model->sourceModel()->setAllColumnsEditable( false );
return true;
}
@@ -900,15 +1015,17 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
void
PlaylistItemDelegate::resetHoverIndex()
{
if ( !m_model )
if ( !m_model || !m_hoveringOver.isValid() )
return;
QPersistentModelIndex idx = m_hoveringOver;
m_hoveringOver = QModelIndex();
m_hoveringOverArtist = QModelIndex();
m_hoveringOverBuyButton = QModelIndex();
m_infoButtonRects.clear();
m_loveButtonRects.clear();
m_buyButtonRects.clear();
m_artistNameRects.clear();
QModelIndex itemIdx = m_model->mapToSource( idx );
@@ -920,7 +1037,6 @@ PlaylistItemDelegate::resetHoverIndex()
}
emit updateIndex( idx );
m_view->repaint();
}

View File

@@ -116,10 +116,13 @@ private:
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
mutable QHash< QPersistentModelIndex, QRect > m_infoButtonRects;
mutable QHash< QPersistentModelIndex, QRect > m_loveButtonRects;
mutable QHash< QPersistentModelIndex, QRect > m_buyButtonRects;
mutable QHash< QPersistentModelIndex, QRect > m_downloadDropDownRects;
mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects;
mutable QHash< QPersistentModelIndex, QHash< Tomahawk::source_ptr, QRect > > m_avatarBoxRects;
QPersistentModelIndex m_hoveringOver;
QPersistentModelIndex m_hoveringOverArtist;
QPersistentModelIndex m_hoveringOverBuyButton;
mutable QPersistentModelIndex m_nowPlaying;
TrackView* m_view;

View File

@@ -19,6 +19,7 @@
#include "TrackDetailView.h"
#include <QLabel>
#include <QPushButton>
#include <QScrollArea>
#include <QSizePolicy>
#include <QVBoxLayout>
@@ -35,6 +36,7 @@
#include "utils/ImageRegistry.h"
#include "utils/TomahawkUtilsGui.h"
#include "utils/Closure.h"
#include "utils/WebPopup.h"
#include "utils/Logger.h"
using namespace Tomahawk;
@@ -42,6 +44,7 @@ using namespace Tomahawk;
TrackDetailView::TrackDetailView( QWidget* parent )
: QWidget( parent )
, DpiScaler( this )
, m_buyButtonVisible( false )
{
setFixedWidth( scaledX( 200 ) );
setContentsMargins( 0, 0, 0, 0 );
@@ -118,11 +121,21 @@ TrackDetailView::TrackDetailView( QWidget* parent )
TomahawkStyle::styleScrollBar( m_resultsScrollArea->verticalScrollBar() );
m_resultsScrollArea->hide();
m_buyButton = new QPushButton;
m_buyButton->setStyleSheet( "QPushButton:hover { font-size: 12px; color: #ffffff; background: #000000; border-style: solid; border-radius: 0px; border-width: 2px; border-color: #2b2b2b; }"
"QPushButton { font-size: 12px; color: #ffffff; background-color: #000000; border-style: solid; border-radius: 0px; border-width: 0px; }" );
m_buyButton->setMinimumHeight( 30 );
m_buyButton->setText( tr( "Buy Album" ) );
m_buyButton->setVisible( false );
connect( m_buyButton, SIGNAL( clicked() ), SLOT( onBuyButtonClicked() ) );
QVBoxLayout* layout = new QVBoxLayout;
TomahawkUtils::unmarginLayout( layout );
layout->addWidget( m_playableCover );
layout->addSpacerItem( new QSpacerItem( 0, 8, QSizePolicy::Minimum, QSizePolicy::Fixed ) );
layout->addWidget( m_nameLabel );
layout->addSpacerItem( new QSpacerItem( 0, 4, QSizePolicy::Minimum, QSizePolicy::Fixed ) );
layout->addWidget( m_buyButton );
layout->addWidget( m_dateLabel );
layout->addWidget( m_infoBox );
layout->addSpacerItem( new QSpacerItem( 0, 32, QSizePolicy::Minimum, QSizePolicy::Fixed ) );
@@ -134,6 +147,9 @@ TrackDetailView::TrackDetailView( QWidget* parent )
setLayout( layout );
setQuery( query_ptr() );
connect( DownloadManager::instance(), SIGNAL( stateChanged( DownloadManager::DownloadManagerState, DownloadManager::DownloadManagerState ) ),
SLOT( onDownloadManagerStateChanged( DownloadManager::DownloadManagerState, DownloadManager::DownloadManagerState ) ) );
}
@@ -154,6 +170,10 @@ TrackDetailView::setQuery( const Tomahawk::query_ptr& query )
{
if ( m_query )
{
if ( m_query->track()->albumPtr() && !m_query->track()->albumPtr()->name().isEmpty() )
{
disconnect( m_query->track()->albumPtr().data(), SIGNAL( updated() ), this, SLOT( onAlbumUpdated() ) );
}
disconnect( m_query->track().data(), SIGNAL( updated() ), this, SLOT( onCoverUpdated() ) );
disconnect( m_query->track().data(), SIGNAL( socialActionsLoaded() ), this, SLOT( onSocialActionsLoaded() ) );
disconnect( m_query.data(), SIGNAL( resultsChanged() ), this, SLOT( onResultsChanged() ) );
@@ -164,6 +184,7 @@ TrackDetailView::setQuery( const Tomahawk::query_ptr& query )
onResultsChanged();
setSocialActions();
onCoverUpdated();
onAlbumUpdated();
if ( !query )
{
@@ -174,20 +195,85 @@ TrackDetailView::setQuery( const Tomahawk::query_ptr& query )
m_dateLabel->setText( tr( "Unknown Release-Date" ) );
connect( m_query->track().data(), SIGNAL( updated() ), SLOT( onCoverUpdated() ) );
connect( m_query->track().data(), SIGNAL( socialActionsLoaded() ), SLOT( onSocialActionsLoaded() ) );
connect( m_query.data(), SIGNAL( resultsChanged() ), SLOT( onResultsChanged() ) );
connect( m_query.data(), SIGNAL( resultsChanged() ), SLOT( onAlbumUpdated() ) );
}
void
TrackDetailView::onAlbumUpdated()
{
if ( !m_query )
return;
if ( m_query->track()->albumPtr() && !m_query->track()->albumPtr()->name().isEmpty() )
{
m_nameLabel->setType( QueryLabel::Album );
m_nameLabel->setAlbum( m_query->track()->albumPtr() );
connect( m_query->track()->albumPtr().data(), SIGNAL( updated() ), SLOT( onAlbumUpdated() ), Qt::UniqueConnection );
if ( m_buyButtonVisible )
{
if ( m_query->track()->albumPtr()->purchased() )
{
m_buyButton->setText( tr( "Download Album" ) );
m_buyButton->setVisible( true );
}
else
{
m_buyButton->setText( tr( "Buy Album" ) );
m_buyButton->setVisible( !m_query->track()->albumPtr()->purchaseUrl().isEmpty() );
}
}
}
else
{
m_nameLabel->setType( QueryLabel::Artist );
m_nameLabel->setArtist( m_query->track()->artistPtr() );
m_buyButton->setVisible( false );
}
}
void
TrackDetailView::onBuyButtonClicked()
{
if ( DownloadManager::instance()->state() == DownloadManager::Running )
{
emit downloadCancel();
return;
}
connect( m_query->track().data(), SIGNAL( updated() ), SLOT( onCoverUpdated() ) );
connect( m_query->track().data(), SIGNAL( socialActionsLoaded() ), SLOT( onSocialActionsLoaded() ) );
connect( m_query.data(), SIGNAL( resultsChanged() ), SLOT( onResultsChanged() ) );
if ( m_query && m_query->track()->albumPtr() )
{
if ( m_query->track()->albumPtr()->purchased() )
{
emit downloadAll();
}
else
{
WebPopup* popup = new WebPopup( m_query->track()->albumPtr()->purchaseUrl(), QSize( 400, 800 ) );
connect( m_query->track()->albumPtr().data(), SIGNAL( destroyed() ), popup, SLOT( close() ) );
}
}
}
void
TrackDetailView::onDownloadManagerStateChanged( DownloadManager::DownloadManagerState newState, DownloadManager::DownloadManagerState oldState )
{
tDebug() << Q_FUNC_INFO;
if ( newState == DownloadManager::Running )
{
m_buyButton->setText( tr( "Cancel Download" ) );
}
else
{
onAlbumUpdated();
}
}
@@ -304,3 +390,10 @@ TrackDetailView::onResultsChanged()
m_resultsScrollArea->hide();
}
}
void
TrackDetailView::setBuyButtonVisible( bool visible )
{
m_buyButtonVisible = visible;
}

View File

@@ -23,6 +23,7 @@
#include "Query.h"
#include "utils/DpiScaler.h"
#include "DownloadManager.h"
#include "DllMacro.h"
class QLabel;
@@ -30,6 +31,7 @@ class CaptionLabel;
class PlayableCover;
class QueryLabel;
class QScrollArea;
class QPushButton;
class DLLEXPORT TrackDetailView : public QWidget, private TomahawkUtils::DpiScaler
{
@@ -39,21 +41,29 @@ public:
explicit TrackDetailView( QWidget* parent = 0 );
~TrackDetailView();
void setBuyButtonVisible( bool visible );
public slots:
virtual void setQuery( const Tomahawk::query_ptr& query );
void setPlaylistInterface( const Tomahawk::playlistinterface_ptr& playlistInterface );
signals:
void downloadAll();
void downloadCancel();
protected:
protected slots:
private slots:
void onAlbumUpdated();
void onCoverUpdated();
void onSocialActionsLoaded();
void onResultsChanged();
void onBuyButtonClicked();
void onDownloadManagerStateChanged( DownloadManager::DownloadManagerState newState, DownloadManager::DownloadManagerState oldState );
private:
void setSocialActions();
@@ -65,6 +75,8 @@ private:
QLabel* m_lovedIcon;
QLabel* m_lovedLabel;
CaptionLabel* m_resultsBoxLabel;
QPushButton* m_buyButton;
bool m_buyButtonVisible;
QWidget* m_infoBox;
QWidget* m_resultsBox;

View File

@@ -23,7 +23,9 @@
#include "PlayableModel.h"
#include "PlayableProxyModel.h"
#include "PlayableItem.h"
#include "DownloadManager.h"
#include "DropJob.h"
#include "Result.h"
#include "Source.h"
#include "TomahawkSettings.h"
#include "audio/AudioEngine.h"
@@ -45,6 +47,9 @@
#include <QScrollBar>
#include <QDrag>
// HACK
#include <QTableView>
#define SCROLL_TIMEOUT 280
using namespace Tomahawk;
@@ -83,6 +88,13 @@ TrackView::TrackView( QWidget* parent )
setEditTriggers( NoEditTriggers );
setHeader( m_header );
// HACK: enable moving of first column: QTBUG-33974 / https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused;
unused.setVerticalHeader( header() );
header()->setParent( this );
unused.setVerticalHeader( new QHeaderView( Qt::Horizontal, &unused ) );
setSortingEnabled( true );
sortByColumn( -1 );
setContextMenuPolicy( Qt::CustomContextMenu );
@@ -677,7 +689,6 @@ TrackView::wheelEvent( QWheelEvent* event )
QTreeView::wheelEvent( event );
m_delegate->resetHoverIndex();
repaint();
}
@@ -764,6 +775,44 @@ TrackView::onCustomContextMenu( const QPoint& pos )
m_contextMenu->setSupportedActions( m_contextMenu->supportedActions() | ContextMenu::ActionMarkListened
| ContextMenu::ActionDelete );
if ( proxyModel()->style() != PlayableProxyModel::Collection )
{
bool allDownloaded = true;
bool noneDownloadable = true;
bool downloadable = false;
foreach ( const QModelIndex& index, selectedIndexes() )
{
if ( index.column() )
continue;
PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( index ) );
if( item->query()->results().isEmpty() )
continue;
downloadable = !item->query()->results().first()->downloadFormats().isEmpty();
if ( downloadable )
{
noneDownloadable = false;
}
if ( downloadable && DownloadManager::instance()->localFileForDownload( item->query()->results().first()->downloadFormats().first().url.toString() ).isEmpty() )
{
allDownloaded = false;
}
if ( !allDownloaded || !noneDownloadable )
{
break;
}
}
if ( !allDownloaded || !noneDownloadable )
{
m_contextMenu->setSupportedActions( m_contextMenu->supportedActions() | ContextMenu::ActionDownload );
}
}
QList<query_ptr> queries;
foreach ( const QModelIndex& index, selectedIndexes() )
{
@@ -795,6 +844,10 @@ TrackView::onMenuTriggered( int action )
deleteSelectedItems();
break;
case ContextMenu::ActionDownload:
downloadSelectedItems();
break;
default:
break;
}
@@ -870,6 +923,30 @@ TrackView::deleteSelectedItems()
}
void
TrackView::downloadSelectedItems()
{
foreach ( const QModelIndex& index, selectedIndexes() )
{
if ( index.column() )
continue;
PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( index ) );
if ( !item )
continue;
if ( item->query()->results().isEmpty() || item->query()->results().first()->downloadFormats().isEmpty() )
continue;
if ( !DownloadManager::instance()->localFileForDownload( item->query()->results().first()->downloadFormats().first().url.toString() ).isEmpty() )
continue;
DownloadManager::instance()->addJob( item->result()->toDownloadJob( item->result()->downloadFormats().first() ) );
}
}
void
TrackView::verifySize()
{

View File

@@ -89,6 +89,7 @@ public:
public slots:
virtual void onItemActivated( const QModelIndex& index );
virtual void downloadSelectedItems();
virtual void deleteSelectedItems();
void playItem();

View File

@@ -3,7 +3,6 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.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
@@ -25,6 +24,8 @@
#include "Source.h"
#include "DllMacro.h"
#include "Resolver.h"
#include "ScriptCommandQueue.h"
#include "ScriptCommand_LookupUrl.h"
#include "Typedefs.h"
#include <QObject>
@@ -44,6 +45,7 @@ class DLLEXPORT ExternalResolver : public Resolver
{
Q_OBJECT
friend class ScriptCommandQueue;
friend class ScriptCommand_LookupUrl;
public:
@@ -59,13 +61,26 @@ public:
Browsable = 0x1, // can be represented in one or more collection tree views
PlaylistSync = 0x2, // can sync playlists
AccountFactory = 0x4, // can configure multiple accounts at the same time
UrlLookup = 0x8 // can be queried for information on an Url
};
Q_DECLARE_FLAGS( Capabilities, Capability )
Q_FLAGS( Capabilities )
enum UrlType
{
UrlTypeAny = 0x00,
UrlTypePlaylist = 0x01,
UrlTypeTrack = 0x02,
UrlTypeAlbum = 0x04,
UrlTypeArtist = 0x08,
UrlTypeXspf = 0x10
};
Q_DECLARE_FLAGS( UrlTypes, UrlType )
Q_FLAGS( UrlTypes )
ExternalResolver( const QString& filePath )
: m_filePath( filePath )
{}
: m_commandQueue( new ScriptCommandQueue( this ) )
{ m_filePath = filePath; }
QString filePath() const { return m_filePath; }
virtual void setIcon( const QPixmap& ) {}
@@ -77,6 +92,12 @@ public:
virtual bool running() const = 0;
virtual Capabilities capabilities() const = 0;
// UrlLookup, sync call
virtual bool canParseUrl( const QString& url, UrlType type ) = 0;
virtual void enqueue( const QSharedPointer< ScriptCommand >& req )
{ m_commandQueue->enqueue( req ); }
public slots:
virtual void start() = 0;
virtual void stop() = 0;
@@ -91,6 +112,11 @@ signals:
protected:
void setFilePath( const QString& path ) { m_filePath = path; }
ScriptCommandQueue* m_commandQueue;
// Should only be called by ScriptCommands
// UrlLookup
virtual void lookupUrl( const QString& url ) = 0;
private:
QString m_filePath;

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
JSAccount::serializeQVariantMap( const QVariantMap& map )
{

View File

@@ -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;

View File

@@ -4,7 +4,6 @@
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
* 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
@@ -46,6 +45,10 @@
#include "ScriptInfoPlugin.h"
#include "JSAccount.h"
#include "ScriptJob.h"
// lookupUrl stuff
#include "playlist/PlaylistTemplate.h"
#include "playlist/XspfPlaylistTemplate.h"
#include "database/Database.h"
#include "database/DatabaseImpl.h"
@@ -319,6 +322,191 @@ JSResolver::start()
}
bool
JSResolver::canParseUrl( const QString& url, UrlType type )
{
Q_D( const JSResolver );
if ( d->capabilities.testFlag( UrlLookup ) )
{
QVariantMap arguments;
arguments["url"] = url;
arguments["type"] = (int) type;
return scriptObject()->syncInvoke( "canParseUrl", arguments ).toBool();
}
else
{
// We cannot do URL lookup.
return false;
}
}
void
JSResolver::lookupUrl( const QString& url )
{
Q_D( const JSResolver );
if ( !d->capabilities.testFlag( UrlLookup ) )
{
emit informationFound( url, QSharedPointer<QObject>() );
return;
}
QVariantMap arguments;
arguments["url"] = url;
Tomahawk::ScriptJob* job = scriptObject()->invoke( "lookupUrl", arguments );
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onLookupUrlRequestDone( QVariantMap ) ) );
job->setProperty( "url", url );
job->start();
}
void
JSResolver::onLookupUrlRequestDone( const QVariantMap& result )
{
sender()->deleteLater();
QString url = sender()->property( "url" ).toString();
tLog() << "ON LOOKUP URL REQUEST DONE" << url << result;
// It may seem a bit weird, but currently no slot should do anything
// more as we starting on a new URL and not task are waiting for it yet.
m_pendingUrl = QString();
m_pendingAlbum = album_ptr();
UrlTypes type = (UrlTypes) result.value( "type" ).toInt();
if ( type == UrlTypeArtist )
{
QString name = result.value( "name" ).toString();
Q_ASSERT( !name.isEmpty() );
emit informationFound( url, Artist::get( name, true ).objectCast<QObject>() );
}
else if ( type == UrlTypeAlbum )
{
QString name = result.value( "name" ).toString();
QString artist = result.value( "artist" ).toString();
album_ptr album = Album::get( Artist::get( artist, true ), name );
m_pendingUrl = url;
m_pendingAlbum = album;
connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
SLOT( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ) );
if ( !album->tracks().isEmpty() )
{
emit informationFound( url, album.objectCast<QObject>() );
}
}
else if ( type == UrlTypeTrack )
{
Tomahawk::query_ptr query = parseTrack( result );
if ( query.isNull() )
{
// A valid track result shoud have non-empty title and artist.
tLog() << Q_FUNC_INFO << name() << "Got empty track information for " << url;
emit informationFound( url, QSharedPointer<QObject>() );
}
else
{
emit informationFound( url, query.objectCast<QObject>() );
}
}
else if ( type == UrlTypePlaylist )
{
QString guid = result.value( "guid" ).toString();
Q_ASSERT( !guid.isEmpty() );
// Append nodeid to guid to make it globally unique.
guid += instanceUUID();
// Do we already have this playlist loaded?
{
playlist_ptr playlist = Playlist::get( guid );
if ( !playlist.isNull() )
{
emit informationFound( url, playlist.objectCast<QObject>() );
return;
}
}
// Get all information to build a new playlist but do not build it until we know,
// if it is really handled as a playlist and not as a set of tracks.
Tomahawk::source_ptr source = SourceList::instance()->getLocal();
const QString title = result.value( "title" ).toString();
const QString info = result.value( "info" ).toString();
const QString creator = result.value( "creator" ).toString();
QList<query_ptr> queries;
foreach( QVariant track, result.value( "tracks" ).toList() )
{
query_ptr query = parseTrack( track.toMap() );
if ( !query.isNull() )
{
queries << query;
}
}
tLog( LOGVERBOSE ) << Q_FUNC_INFO << name() << "Got playlist for " << url;
playlisttemplate_ptr pltemplate( new PlaylistTemplate( source, guid, title, info, creator, false, queries ) );
emit informationFound( url, pltemplate.objectCast<QObject>() );
}
else if ( type == UrlTypeXspf )
{
QString xspfUrl = result.value( "url" ).toString();
Q_ASSERT( !xspfUrl.isEmpty() );
QString guid = QString( "xspf-%1-%2" ).arg( xspfUrl.toUtf8().toBase64().constData() ).arg( instanceUUID() );
// Do we already have this playlist loaded?
{
playlist_ptr playlist = Playlist::get( guid );
if ( !playlist.isNull() )
{
emit informationFound( url, playlist.objectCast<QObject>() );
return;
}
}
// Get all information to build a new playlist but do not build it until we know,
// if it is really handled as a playlist and not as a set of tracks.
Tomahawk::source_ptr source = SourceList::instance()->getLocal();
QSharedPointer<XspfPlaylistTemplate> pltemplate( new XspfPlaylistTemplate( xspfUrl, source, guid ) );
NewClosure( pltemplate, SIGNAL( tracksLoaded( QList< Tomahawk::query_ptr > ) ),
this, SLOT( pltemplateTracksLoadedForUrl( QString, Tomahawk::playlisttemplate_ptr ) ),
url, pltemplate.objectCast<Tomahawk::PlaylistTemplate>() );
tLog( LOGVERBOSE ) << Q_FUNC_INFO << name() << "Got playlist for " << url;
pltemplate->load();
}
else
{
tLog( LOGVERBOSE ) << Q_FUNC_INFO << name() << "No usable information found for " << url;
emit informationFound( url, QSharedPointer<QObject>() );
}
}
query_ptr
JSResolver::parseTrack( const QVariantMap& track )
{
QString title = track.value( "track" ).toString();
QString artist = track.value( "artist" ).toString();
QString album = track.value( "album" ).toString();
if ( title.isEmpty() || artist.isEmpty() )
{
return query_ptr();
}
Tomahawk::query_ptr query = Tomahawk::Query::get( artist, title, album );
QString resultHint = track.value( "hint" ).toString();
if ( !resultHint.isEmpty() )
{
query->setResultHint( resultHint );
query->setSaveHTTPResultHint( true );
}
return query;
}
void
JSResolver::tracksAdded( const QList<query_ptr>&, const ModelMode, const collection_ptr&)
{
@@ -332,6 +520,14 @@ JSResolver::tracksAdded( const QList<query_ptr>&, const ModelMode, const collect
}
void
JSResolver::pltemplateTracksLoadedForUrl( const QString& url, const playlisttemplate_ptr& pltemplate )
{
tLog() << Q_FUNC_INFO;
emit informationFound( url, pltemplate.objectCast<QObject>() );
}
Tomahawk::ExternalResolver::ErrorState
JSResolver::error() const
{
@@ -345,7 +541,6 @@ void
JSResolver::resolve( const Tomahawk::query_ptr& query )
{
ScriptJob* job = scriptAccount()->resolve( scriptObject(), query, "resolver" );
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onResolveRequestDone( QVariantMap ) ) );
job->start();
@@ -367,15 +562,24 @@ JSResolver::onResolveRequestDone( const QVariantMap& data )
}
else
{
if ( !data.value( "artists" ).isNull() )
{
QList< artist_ptr > artists = scriptAccount()->parseArtistVariantList( data.value( "artists" ).toList() );
Tomahawk::Pipeline::instance()->reportArtists( qid, artists );
}
if ( !data.value( "albums" ).isNull() )
{
QList< album_ptr > albums = scriptAccount()->parseAlbumVariantList( data.value( "albums" ).toList() );
Tomahawk::Pipeline::instance()->reportAlbums( qid, albums );
}
QList< Tomahawk::result_ptr > results = scriptAccount()->parseResultVariantList( data.value( "tracks" ).toList() );
foreach( const result_ptr& result, results )
{
result->setResolvedByResolver( this );
result->setFriendlySource( name() );
}
Tomahawk::Pipeline::instance()->reportResults( qid, this, results );
}
@@ -492,6 +696,13 @@ JSResolver::resolverUserConfig()
}
QString
JSResolver::instanceUUID()
{
return Tomahawk::Database::instance()->impl()->dbid();
}
ScriptJob*
JSResolver::getStreamUrl( const result_ptr& result )
{

View File

@@ -4,7 +4,6 @@
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
* 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
@@ -70,6 +69,8 @@ public:
void setIcon( const QPixmap& icon ) override;
bool canParseUrl( const QString& url, UrlType type ) override;
QVariantMap loadDataFromWidgets();
ScriptAccount* scriptAccount() const;
@@ -81,6 +82,9 @@ public slots:
void stop() override;
void start() override;
// For UrlLookup
void lookupUrl( const QString& url ) override;
signals:
void stopped();
@@ -89,6 +93,7 @@ protected:
private slots:
void onResolveRequestDone(const QVariantMap& data);
void onLookupUrlRequestDone(const QVariantMap& data);
private:
void init();
@@ -102,11 +107,15 @@ private:
Q_DECLARE_PRIVATE( JSResolver )
QScopedPointer<JSResolverPrivate> d_ptr;
// TODO: collection stuff, get rid of collection scriptcommands
// TODO: move lookupUrl stuff to its own plugin type
QString instanceUUID();
static Tomahawk::query_ptr parseTrack( const QVariantMap& track );
QString m_pendingUrl;
Tomahawk::album_ptr m_pendingAlbum;
private slots:
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::ModelMode, const Tomahawk::collection_ptr& collection );
void pltemplateTracksLoadedForUrl( const QString& url, const Tomahawk::playlisttemplate_ptr& pltemplate );
};
} // ns: Tomahawk

View File

@@ -1,7 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 2011 Leo Franchi <lfranchi@kde.org>
* Copyright (C) 2014-2016, Dominik Schmidt <domme@tomahawk-player.org>
* Copyright (C) 2014 Dominik Schmidt <domme@tomahawk-player.org>
* Copyright (C) 2015, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@@ -23,7 +23,6 @@
#include "../utils/Logger.h"
#include "../Typedefs.h"
#include "plugins/ScriptLinkParserPluginFactory.h"
#include "plugins/ScriptCollectionFactory.h"
#include "plugins/ScriptInfoPluginFactory.h"
@@ -33,6 +32,8 @@
#include "ScriptInfoPlugin.h"
// TODO:
#include "../Artist.h"
#include "../Album.h"
#include "../Result.h"
#include "../Track.h"
#include <QTime>
@@ -45,7 +46,6 @@ ScriptAccount::ScriptAccount( const QString& name )
: QObject()
, m_name( name )
, m_stopped( true )
, m_linkParserPluginFactory( new ScriptLinkParserPluginFactory() )
, m_collectionFactory( new ScriptCollectionFactory() )
, m_infoPluginFactory( new ScriptInfoPluginFactory() )
{
@@ -54,7 +54,6 @@ ScriptAccount::ScriptAccount( const QString& name )
ScriptAccount::~ScriptAccount()
{
delete m_linkParserPluginFactory;
delete m_collectionFactory;
delete m_infoPluginFactory;
}
@@ -65,7 +64,6 @@ ScriptAccount::start()
{
m_stopped = false;
m_linkParserPluginFactory->addAllPlugins();
m_collectionFactory->addAllPlugins();
m_infoPluginFactory->addAllPlugins();
}
@@ -76,7 +74,6 @@ ScriptAccount::stop()
{
m_stopped = true;
m_linkParserPluginFactory->removeAllPlugins();
m_collectionFactory->removeAllPlugins();
m_infoPluginFactory->removeAllPlugins();
}
@@ -198,11 +195,7 @@ ScriptAccount::unregisterScriptPlugin( const QString& type, const QString& objec
return;
}
if( type == "linkParser" )
{
m_linkParserPluginFactory->unregisterPlugin( object );
}
else if ( type == "collection" )
if ( type == "collection" )
{
m_collectionFactory->unregisterPlugin( object );
}
@@ -210,6 +203,10 @@ ScriptAccount::unregisterScriptPlugin( const QString& type, const QString& objec
{
m_infoPluginFactory->unregisterPlugin( object );
}
else if( type == "linkParser" )
{
// TODO
}
else
{
tLog() << "This plugin type is not handled by Tomahawk or simply cannot be removed yet";
@@ -242,7 +239,7 @@ ScriptAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr&
}
else if( type == "linkParser" )
{
m_linkParserPluginFactory->registerPlugin( object, this );
tLog() << "Plugin registered linkParser, which is not implemented yet. UrlLookup won't work";
}
else if ( type == "infoPlugin" )
{
@@ -260,6 +257,12 @@ ScriptAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr&
}
void
ScriptAccount::showDebugger()
{
}
void
ScriptAccount::onJobDeleted( const QString& jobId )
{
@@ -267,15 +270,67 @@ ScriptAccount::onJobDeleted( const QString& jobId )
}
QList< Tomahawk::artist_ptr >
ScriptAccount::parseArtistVariantList( const QVariantList& artistList )
{
QList< Tomahawk::artist_ptr > artists;
QString artist;
foreach( const QVariant& a, artistList )
{
artist = a.toString().trimmed();
if ( artist.isEmpty() )
continue;
artists << Tomahawk::Artist::get( artist );
}
return artists;
}
QList< Tomahawk::album_ptr >
ScriptAccount::parseAlbumVariantList( const QVariantList& albumList )
{
QList< Tomahawk::album_ptr > albums;
QString artistString;
QString albumString;
foreach( const QVariant& av, albumList )
{
QVariantMap m = av.toMap();
artistString = m.value( "artist" ).toString().trimmed();
albumString = m.value( "album" ).toString().trimmed();
if ( artistString.isEmpty() || albumString.isEmpty() )
continue;
albums << Tomahawk::Album::get( Tomahawk::Artist::get( artistString ), albumString );
}
return albums;
}
QList< Tomahawk::result_ptr >
ScriptAccount::parseResultVariantList( const QVariantList& reslist )
{
QList< Tomahawk::result_ptr > results;
foreach( const QVariant& rv, reslist )
{
QVariantMap m = rv.toMap();
const QString artistString = m.value("artist").toString().trimmed();
const QString trackString = m.value("track").toString().trimmed();
if ( artistString.isEmpty() || trackString.isEmpty() )
{
tLog() << Q_FUNC_INFO << "Could not parse Track" << m;
continue;
}
int duration = m.value( "duration", 0 ).toInt();
if ( duration <= 0 && m.contains( "durationString" ) )
{
@@ -283,8 +338,8 @@ ScriptAccount::parseResultVariantList( const QVariantList& reslist )
duration = time.secsTo( QTime( 0, 0 ) ) * -1;
}
Tomahawk::track_ptr track = Tomahawk::Track::get( m.value( "artist" ).toString(),
m.value( "track" ).toString(),
Tomahawk::track_ptr track = Tomahawk::Track::get( artistString,
trackString,
m.value( "album" ).toString(),
m.value( "albumArtist" ).toString(),
duration,
@@ -315,11 +370,17 @@ ScriptAccount::parseResultVariantList( const QVariantList& reslist )
// rp->track()->setAttributes( attr );
}
rp->setMimetype( m.value( "mimetype" ).toString() );
if ( rp->mimetype().isEmpty() )
QString mimetype = m.value( "mimetype" ).toString();
if ( mimetype.isEmpty() )
{
rp->setMimetype( TomahawkUtils::extensionToMimetype( m.value( "extension" ).toString() ) );
Q_ASSERT( !rp->mimetype().isEmpty() );
mimetype = TomahawkUtils::extensionToMimetype( m.value( "extension" ).toString() );
}
Q_ASSERT( !mimetype.isEmpty() );
if ( !mimetype.isEmpty() )
{
rp->setMimetype( mimetype );
}
rp->setFriendlySource( name() );

View File

@@ -1,7 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 2011 Leo Franchi <lfranchi@kde.org>
* Copyright (C) 2014-2016, Dominik Schmidt <domme@tomahawk-player.org>
* Copyright (C) 2014 Dominik Schmidt <domme@tomahawk-player.org>
* Copyright (C) 2015, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@@ -39,7 +39,6 @@ namespace Tomahawk {
class ScriptObject;
class ScriptJob;
class ScriptLinkParserPluginFactory;
class ScriptCollectionFactory;
class ScriptInfoPluginFactory;
@@ -77,7 +76,11 @@ public:
virtual void scriptPluginFactory( const QString& type, const scriptobject_ptr& object );
virtual void showDebugger();
// helpers
QList< Tomahawk::artist_ptr > parseArtistVariantList( const QVariantList& artistList );
QList< Tomahawk::album_ptr > parseAlbumVariantList( const QVariantList& albumList );
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType );
@@ -95,7 +98,6 @@ private: // TODO: pimple, might be renamed before tho
QHash< QString, scriptobject_ptr > m_objects;
// port to QScopedPointer when pimple'd
ScriptLinkParserPluginFactory* m_linkParserPluginFactory;
ScriptCollectionFactory* m_collectionFactory;
ScriptInfoPluginFactory* m_infoPluginFactory;
};

View File

@@ -34,6 +34,7 @@ signals:
virtual void done() = 0;
protected:
friend class ScriptCommandQueue;
virtual void exec() = 0;
virtual void reportFailure() = 0;
};

View File

@@ -0,0 +1,107 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.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 "ScriptCommandQueue.h"
#include <QMetaType>
#include <QMutex>
using namespace Tomahawk;
ScriptCommandQueue::ScriptCommandQueue( QObject* parent )
: QObject( parent )
, m_timer( new QTimer( this ) )
{
m_timer->setSingleShot( true );
}
void
ScriptCommandQueue::enqueue( const QSharedPointer< ScriptCommand >& req )
{
QMutexLocker locker( &m_mutex );
m_queue.append( req );
locker.unlock();
if ( m_queue.count() == 1 )
nextCommand();
}
void
ScriptCommandQueue::nextCommand()
{
if ( m_queue.isEmpty() )
return;
QSharedPointer< ScriptCommand > req = m_queue.first();
connect( req.data(), SIGNAL( done() ),
this, SLOT( onCommandDone() ) );
connect( m_timer, SIGNAL( timeout() ),
this, SLOT( onTimeout() ) );
m_timer->start( 20000 );
req->exec();
}
void
ScriptCommandQueue::onCommandDone()
{
if ( m_queue.isEmpty() || !m_timer->isActive() ) //the timeout already happened or some other weird thing
return; //nothing to do here
m_timer->stop();
QMutexLocker locker( &m_mutex );
const QSharedPointer< ScriptCommand > req = m_queue.first();
m_queue.removeAll( req );
locker.unlock();
disconnect( req.data(), SIGNAL( done() ),
this, SLOT( onCommandDone() ) );
disconnect( m_timer, SIGNAL( timeout() ),
this, SLOT( onTimeout() ) );
if ( !m_queue.isEmpty() )
nextCommand();
}
void
ScriptCommandQueue::onTimeout()
{
m_timer->stop();
QMutexLocker locker( &m_mutex );
const QSharedPointer< ScriptCommand > req = m_queue.first();
m_queue.removeAll( req );
locker.unlock();
req->reportFailure();
disconnect( req.data(), SIGNAL( done() ),
this, SLOT( onCommandDone() ) );
disconnect( m_timer, SIGNAL( timeout() ),
this, SLOT( onTimeout() ) );
if ( !m_queue.isEmpty() )
nextCommand();
}

View File

@@ -0,0 +1,57 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.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 SCRIPTCOMMANDQUEUE_H
#define SCRIPTCOMMANDQUEUE_H
#include "ScriptCommand.h"
#include <QQueue>
#include <QSharedPointer>
#include <QTimer>
#include <QMetaType>
#include <QMutex>
namespace Tomahawk
{
class ScriptCommandQueue : public QObject
{
Q_OBJECT
public:
explicit ScriptCommandQueue( QObject* parent = 0 );
virtual ~ScriptCommandQueue() {}
void enqueue( const QSharedPointer< ScriptCommand >& req );
private slots:
void nextCommand();
void onCommandDone();
void onTimeout();
private:
QQueue< QSharedPointer< ScriptCommand > > m_queue;
QTimer* m_timer;
QMutex m_mutex;
};
} // ns: Tomahawk
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::ScriptCommand > )
#endif // SCRIPTCOMMANDQUEUE_H

View File

@@ -28,6 +28,8 @@
#include "utils/Logger.h"
#include "../Result.h"
#include <QtConcurrentRun>
using namespace Tomahawk;
ScriptCommand_AllTracks::ScriptCommand_AllTracks( const Tomahawk::collection_ptr& collection,
@@ -117,20 +119,22 @@ ScriptCommand_AllTracks::onTracksJobDone( const QVariantMap& result )
QSharedPointer< ScriptCollection > collection = m_collection.objectCast< ScriptCollection >();
Q_ASSERT( !collection.isNull() );
QList< Tomahawk::result_ptr > t = collection->scriptAccount()->parseResultVariantList( result[ "tracks" ].toList() );
QList< Tomahawk::query_ptr > queries;
foreach ( const Tomahawk::result_ptr& result, t )
QtConcurrent::run( [] ( ScriptCommand_AllTracks* t, ScriptJob* job, const QVariantMap& result, const QSharedPointer< ScriptCollection >& collection )
{
result->setResolvedByCollection( m_collection );
queries.append( result->toQuery() );
}
QList< Tomahawk::result_ptr > results = collection->scriptAccount()->parseResultVariantList( result[ "tracks" ].toList() );
tDebug() << Q_FUNC_INFO << "about to push" << queries.count() << "tracks";
QList< Tomahawk::query_ptr > queries;
foreach ( const Tomahawk::result_ptr& result, results )
{
result->setResolvedByCollection( collection );
queries.append( result->toQuery() );
}
emit tracks( queries );
emit done();
tDebug() << Q_FUNC_INFO << "about to push" << queries.count() << "tracks";
job->deleteLater();
emit t->tracks( queries );
emit t->done();
job->deleteLater();
}, this, job, result, collection );
}

View File

@@ -0,0 +1,78 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
*
* 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 "ScriptCommand_LookupUrl_p.h"
#include "PlaylistEntry.h"
using namespace Tomahawk;
ScriptCommand_LookupUrl::ScriptCommand_LookupUrl( Tomahawk::ExternalResolver* resolver, const QString& url, QObject* parent )
: ScriptCommand( parent )
, d_ptr( new ScriptCommand_LookupUrlPrivate( this, resolver, url ) )
{
}
ScriptCommand_LookupUrl::~ScriptCommand_LookupUrl()
{
delete d_ptr;
}
void
ScriptCommand_LookupUrl::enqueue()
{
Q_D( ScriptCommand_LookupUrl );
d->resolver->enqueue( QSharedPointer< ScriptCommand >( this ) );
}
void
ScriptCommand_LookupUrl::exec()
{
Q_D( ScriptCommand_LookupUrl );
connect( d->resolver, SIGNAL( informationFound( QString , QSharedPointer<QObject> ) ),
this, SLOT( onResolverDone( QString, QSharedPointer<QObject> ) ) );
d->resolver->lookupUrl( d->url );
}
void
ScriptCommand_LookupUrl::reportFailure()
{
Q_D( ScriptCommand_LookupUrl );
emit information( d->url, QSharedPointer<QObject>() );
emit done();
}
void
ScriptCommand_LookupUrl::onResolverDone( const QString& url, const QSharedPointer<QObject>& _information )
{
Q_D( ScriptCommand_LookupUrl );
qDebug() << Q_FUNC_INFO << url << _information.isNull();
if ( url != d->url )
{
// This data is not for us, skip.
return;
}
emit information( d->url, _information );
emit done();
}

View File

@@ -0,0 +1,64 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
*
* 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 SCRIPTCOMMAND_LOOKUPURL_H
#define SCRIPTCOMMAND_LOOKUPURL_H
#include "ScriptCommand.h"
#include "DllMacro.h"
#include "Typedefs.h"
#include <QVariant>
namespace Tomahawk
{
class ScriptCommand_LookupUrlPrivate;
class ExternalResolver;
class DLLEXPORT ScriptCommand_LookupUrl : public ScriptCommand
{
Q_OBJECT
public:
explicit ScriptCommand_LookupUrl( Tomahawk::ExternalResolver* resolver,
const QString& url,
QObject* parent = nullptr );
virtual ~ScriptCommand_LookupUrl();
void enqueue();
signals:
void information( const QString& url, const QSharedPointer<QObject>& variant );
void done();
protected:
void exec() override;
void reportFailure() override;
private slots:
void onResolverDone( const QString& url, const QSharedPointer<QObject>& information );
private:
Q_DECLARE_PRIVATE( ScriptCommand_LookupUrl )
ScriptCommand_LookupUrlPrivate* d_ptr;
};
} // ns: Tomahawk
#endif // SCRIPTCOMMAND_LOOKUPURL_H

View File

@@ -1,7 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
* 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
@@ -17,33 +16,33 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOMAHAWK_SCRIPTLINKGENERATORPLUGIN_P_H
#define TOMAHAWK_SCRIPTLINKGENERATORPLUGIN_P_H
#ifndef SCRIPTCOMMAND_LOOKUPURL_P_H
#define SCRIPTCOMMAND_LOOKUPURL_P_H
#include "ScriptLinkParserPlugin.h"
#include "ScriptCommand_LookupUrl.h"
namespace Tomahawk
#include "ExternalResolver.h"
namespace Tomahawk
{
class ScriptLinkParserPluginPrivate
class ScriptCommand_LookupUrlPrivate
{
public:
ScriptLinkParserPluginPrivate( ScriptLinkParserPlugin* q, const scriptobject_ptr& scriptObject, ScriptAccount* scriptAccount )
ScriptCommand_LookupUrlPrivate( ScriptCommand_LookupUrl* q, Tomahawk::ExternalResolver* _resolver, const QString& _url )
: q_ptr ( q )
, scriptObject( scriptObject )
, scriptAccount( scriptAccount )
, url( _url )
, resolver( _resolver )
{
}
ScriptLinkParserPlugin* q_ptr;
Q_DECLARE_PUBLIC ( ScriptLinkParserPlugin )
ScriptCommand_LookupUrl* q_ptr;
Q_DECLARE_PUBLIC ( ScriptCommand_LookupUrl )
private:
scriptobject_ptr scriptObject;
ScriptAccount* scriptAccount;
QString pendingUrl;
album_ptr pendingAlbum;
QString url;
Tomahawk::ExternalResolver* resolver;
};
} // ns: Tomahawk
#endif // TOMAHAWK_SCRIPTLINKGENERATORPLUGIN_P_H
#endif // SCRIPTCOMMAND_LOOKUPURL_P_H

View File

@@ -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
}
@@ -110,7 +99,7 @@ ScriptEngine::sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errli
QMessageBox question( TomahawkUtils::tomahawkWindow() );
question.setWindowTitle( tr( "SSL Error" ) );
question.setText( tr( "You have asked Tomahawk to connect securely to <b>%1</b>, but we can't confirm that your connection is secure:<br><br>"
question.setText( tr( "You have asked %applicationName to connect securely to <b>%1</b>, but we can't confirm that your connection is secure:<br><br>"
"<b>%2</b><br><br>"
"Do you want to trust this connection?" )
.arg( qnr->url().host() )
@@ -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()
{

View File

@@ -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;

View File

@@ -3,7 +3,6 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.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
@@ -40,7 +39,6 @@
#include <QFileInfo>
#include <QNetworkAccessManager>
#include <QNetworkProxy>
#include <QTimer>
#ifdef Q_OS_WIN
#include <shlwapi.h>

View File

@@ -3,7 +3,6 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.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
@@ -64,6 +63,8 @@ public:
void sendMessage( const QVariantMap& map );
bool canParseUrl( const QString&, UrlType ) Q_DECL_OVERRIDE { return false; }
signals:
void terminated();
void customMessage( const QString& msgType, const QVariantMap& msg );
@@ -73,6 +74,9 @@ public slots:
void resolve( const Tomahawk::query_ptr& query ) Q_DECL_OVERRIDE;
void start() Q_DECL_OVERRIDE;
void lookupUrl( const QString& ) Q_DECL_OVERRIDE {}
private slots:
void readStderr();
void readStdout();

View File

@@ -25,14 +25,14 @@ using namespace Tomahawk;
void
ScriptInfoPluginFactory::addPlugin( const QSharedPointer< ScriptInfoPlugin >& infoPlugin ) const
{
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin.data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin );
}
void
ScriptInfoPluginFactory::removePlugin( const QSharedPointer< ScriptInfoPlugin >& infoPlugin ) const
{
Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin.data() );
Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin );
}
@@ -42,10 +42,10 @@ ScriptInfoPluginFactory::createPlugin( const scriptobject_ptr& object, ScriptAcc
// create infoplugin instance
ScriptInfoPlugin* scriptInfoPlugin = new ScriptInfoPlugin( object, scriptAccount->name() );
Tomahawk::InfoSystem::InfoPluginPtr infoPlugin( scriptInfoPlugin );
QSharedPointer< ScriptInfoPlugin > infoPlugin( scriptInfoPlugin );
// move it to infosystem thread
infoPlugin->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
return QSharedPointer< ScriptInfoPlugin >( scriptInfoPlugin );
return infoPlugin;
}

View File

@@ -1,228 +0,0 @@
/* === 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 "ScriptLinkParserPlugin_p.h"
#include "../ScriptJob.h"
#include "../ScriptObject.h"
#include "../../utils/Logger.h"
#include "../ScriptAccount.h"
#include "../../database/Database.h"
#include "../../database/DatabaseImpl.h"
#include "../../SourceList.h"
#include "../../Artist.h"
#include "../../Album.h"
#include "../../playlist/PlaylistTemplate.h"
#include "../../playlist/XspfPlaylistTemplate.h"
using namespace Tomahawk;
ScriptLinkParserPlugin::ScriptLinkParserPlugin( const scriptobject_ptr& scriptObject, ScriptAccount* account )
: Utils::LinkParserPlugin()
, ScriptPlugin( scriptObject )
, d_ptr( new ScriptLinkParserPluginPrivate( this, scriptObject, account ) )
{
}
ScriptLinkParserPlugin::~ScriptLinkParserPlugin()
{
}
bool
ScriptLinkParserPlugin::canParseUrl( const QString& url, Tomahawk::Utils::UrlType type ) const
{
QVariantMap arguments;
arguments["url"] = url;
arguments["type"] = (int) type;
return scriptObject()->syncInvoke( "canParseUrl", arguments ).toBool();
}
void
ScriptLinkParserPlugin::lookupUrl( const QString& url ) const
{
QVariantMap arguments;
arguments["url"] = url;
Tomahawk::ScriptJob* job = scriptObject()->invoke( "lookupUrl", arguments );
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onLookupUrlRequestDone( QVariantMap ) ) );
job->setProperty( "url", url );
job->start();
}
void
ScriptLinkParserPlugin::onLookupUrlRequestDone( const QVariantMap& result )
{
Q_D( ScriptLinkParserPlugin );
sender()->deleteLater();
QString url = sender()->property( "url" ).toString();
tLog() << "ON LOOKUP URL REQUEST DONE" << url << result;
// It may seem a bit weird, but currently no slot should do anything
// more as we starting on a new URL and not task are waiting for it yet.
d->pendingUrl = QString();
d->pendingAlbum = album_ptr();
Utils::UrlType type = (Utils::UrlType) result.value( "type" ).toInt();
if ( type == Utils::UrlTypeArtist )
{
QString name = result.value( "name" ).toString();
Q_ASSERT( !name.isEmpty() );
emit informationFound( url, Artist::get( name, true ).objectCast<QObject>() );
}
else if ( type == Utils::UrlTypeAlbum )
{
QString name = result.value( "name" ).toString();
QString artist = result.value( "artist" ).toString();
album_ptr album = Album::get( Artist::get( artist, true ), name );
d->pendingUrl = url;
d->pendingAlbum = album;
connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
SLOT( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ) );
if ( !album->tracks().isEmpty() )
{
emit informationFound( url, album.objectCast<QObject>() );
}
}
else if ( type == Utils::UrlTypeTrack )
{
Tomahawk::query_ptr query = parseTrack( result );
if ( query.isNull() )
{
// A valid track result shoud have non-empty title and artist.
tLog() << Q_FUNC_INFO << d->scriptAccount->name() << "Got empty track information for " << url;
emit informationFound( url, QSharedPointer<QObject>() );
}
else
{
emit informationFound( url, query.objectCast<QObject>() );
}
}
else if ( type == Utils::UrlTypePlaylist )
{
QString guid = result.value( "guid" ).toString();
Q_ASSERT( !guid.isEmpty() );
// Append nodeid to guid to make it globally unique.
guid += instanceUUID();
// Do we already have this playlist loaded?
{
playlist_ptr playlist = Playlist::get( guid );
if ( !playlist.isNull() )
{
emit informationFound( url, playlist.objectCast<QObject>() );
return;
}
}
// Get all information to build a new playlist but do not build it until we know,
// if it is really handled as a playlist and not as a set of tracks.
Tomahawk::source_ptr source = SourceList::instance()->getLocal();
const QString title = result.value( "title" ).toString();
const QString info = result.value( "info" ).toString();
const QString creator = result.value( "creator" ).toString();
QList<query_ptr> queries;
foreach( QVariant track, result.value( "tracks" ).toList() )
{
query_ptr query = parseTrack( track.toMap() );
if ( !query.isNull() )
{
queries << query;
}
}
tLog( LOGVERBOSE ) << Q_FUNC_INFO << d->scriptAccount->name() << "Got playlist for " << url;
playlisttemplate_ptr pltemplate( new PlaylistTemplate( source, guid, title, info, creator, false, queries ) );
emit informationFound( url, pltemplate.objectCast<QObject>() );
}
else if ( type == Utils::UrlTypeXspf )
{
QString xspfUrl = result.value( "url" ).toString();
Q_ASSERT( !xspfUrl.isEmpty() );
QString guid = QString( "xspf-%1-%2" ).arg( xspfUrl.toUtf8().toBase64().constData() ).arg( instanceUUID() );
// Do we already have this playlist loaded?
{
playlist_ptr playlist = Playlist::get( guid );
if ( !playlist.isNull() )
{
emit informationFound( url, playlist.objectCast<QObject>() );
return;
}
}
// Get all information to build a new playlist but do not build it until we know,
// if it is really handled as a playlist and not as a set of tracks.
Tomahawk::source_ptr source = SourceList::instance()->getLocal();
QSharedPointer<XspfPlaylistTemplate> pltemplate( new XspfPlaylistTemplate( xspfUrl, source, guid ) );
NewClosure( pltemplate, SIGNAL( tracksLoaded( QList< Tomahawk::query_ptr > ) ),
this, SLOT( pltemplateTracksLoadedForUrl( QString, Tomahawk::playlisttemplate_ptr ) ),
url, pltemplate.objectCast<Tomahawk::PlaylistTemplate>() );
tLog( LOGVERBOSE ) << Q_FUNC_INFO << d->scriptAccount->name() << "Got playlist for " << url;
pltemplate->load();
}
else
{
tLog( LOGVERBOSE ) << Q_FUNC_INFO << d->scriptAccount->name() << "No usable information found for " << url;
emit informationFound( url, QSharedPointer<QObject>() );
}
}
void
ScriptLinkParserPlugin::pltemplateTracksLoadedForUrl( const QString& url, const playlisttemplate_ptr& pltemplate )
{
tLog() << Q_FUNC_INFO;
emit informationFound( url, pltemplate.objectCast<QObject>() );
}
QString
ScriptLinkParserPlugin::instanceUUID()
{
return Tomahawk::Database::instance()->impl()->dbid();
}
Tomahawk::query_ptr
ScriptLinkParserPlugin::parseTrack( const QVariantMap& track )
{
QString title = track.value( "track" ).toString();
QString artist = track.value( "artist" ).toString();
QString album = track.value( "album" ).toString();
if ( title.isEmpty() || artist.isEmpty() )
{
return query_ptr();
}
Tomahawk::query_ptr query = Tomahawk::Query::get( artist, title, album );
QString resultHint = track.value( "hint" ).toString();
if ( !resultHint.isEmpty() )
{
query->setResultHint( resultHint );
query->setSaveHTTPResultHint( true );
}
return query;
}

View File

@@ -1,61 +0,0 @@
/* === 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 TOMAHAWK_SCRIPTLINKPARSERPLUGIN_H
#define TOMAHAWK_SCRIPTLINKPARSERPLUGIN_H
#include "../../resolvers/ScriptPlugin.h"
#include "../../utils/LinkParserPlugin.h"
#include <QObject>
#include "DllMacro.h"
namespace Tomahawk
{
class ScriptObject;
class ScriptLinkParserPluginPrivate;
class DLLEXPORT ScriptLinkParserPlugin : public Utils::LinkParserPlugin, public ScriptPlugin
{
Q_OBJECT
public:
ScriptLinkParserPlugin( const scriptobject_ptr& scriptObject, ScriptAccount* account );
virtual ~ScriptLinkParserPlugin();
bool canParseUrl( const QString& url, Tomahawk::Utils::UrlType type ) const override;
void lookupUrl( const QString& url ) const override;
private slots:
void onLookupUrlRequestDone( const QVariantMap& result );
void pltemplateTracksLoadedForUrl( const QString& url, const playlisttemplate_ptr& pltemplate );
private:
QString instanceUUID();
static Tomahawk::query_ptr parseTrack( const QVariantMap& track );
private:
Q_DECLARE_PRIVATE( ScriptLinkParserPlugin )
QScopedPointer<ScriptLinkParserPluginPrivate> d_ptr;
};
}; // ns: Tomahawk
#endif // TOMAHAWK_SCRIPTLINKPARSERPLUGIN_H

View File

@@ -1,39 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 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 2 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 "ScriptLinkParserPluginFactory.h"
#include "../ScriptAccount.h"
#include "../../utils/LinkParser.h"
#include "../../utils/LinkParserPlugin.h"
using namespace Tomahawk;
void ScriptLinkParserPluginFactory::addPlugin( const QSharedPointer <ScriptLinkParserPlugin >& plugin ) const
{
Tomahawk::Utils::LinkParser::instance()->addPlugin( plugin );
}
void ScriptLinkParserPluginFactory::removePlugin( const QSharedPointer< ScriptLinkParserPlugin >& plugin ) const
{
Tomahawk::Utils::LinkParser::instance()->removePlugin( plugin );
}
QSharedPointer< ScriptLinkParserPlugin > ScriptLinkParserPluginFactory::createPlugin( const scriptobject_ptr& object, ScriptAccount* scriptAccount )
{
return QSharedPointer< ScriptLinkParserPlugin >( new ScriptLinkParserPlugin( object, scriptAccount ) );
}

View File

@@ -1,41 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 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 2 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/>.
*/
#pragma once
#ifndef TOMAHAWK_SCRIPTLINKPARSERPLUGINFACTORY_H
#define TOMAHAWK_SCRIPTLINKPARSERPLUGINFACTORY_H
#include "Typedefs.h"
#include "ScriptLinkParserPlugin.h"
#include "../ScriptPluginFactory.h"
namespace Tomahawk
{
class ScriptAccount;
class DLLEXPORT ScriptLinkParserPluginFactory : public ScriptPluginFactory< ScriptLinkParserPlugin >
{
QSharedPointer< ScriptLinkParserPlugin > createPlugin( const scriptobject_ptr&, ScriptAccount* ) override;
void addPlugin( const QSharedPointer< ScriptLinkParserPlugin >& scriptPlugin ) const override;
void removePlugin( const QSharedPointer< ScriptLinkParserPlugin >& scriptPlugin ) const override;
};
} // ns: Tomahawk
#endif // TOMAHAWK_SCRIPTLINKPARSERPLUGINFACTORY_H

View File

@@ -1,122 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 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 2 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 "LinkParser.h"
#include "TomahawkUtils.h"
#include "Logger.h"
#include "../resolvers/SyncScriptJob.h"
using namespace Tomahawk;
using namespace Tomahawk::Utils;
LinkParser* LinkParser::s_instance = 0;
LinkParser*
LinkParser::instance()
{
if ( !s_instance )
s_instance = new LinkParser;
return s_instance;
}
LinkParser::LinkParser( QObject* parent )
: QObject( parent )
{
}
LinkParser::~LinkParser()
{
}
void LinkParser::addPlugin( const QSharedPointer< LinkParserPlugin >& plugin )
{
m_plugins.append( plugin );
connect( plugin.data(), SIGNAL( informationFound( QString, QSharedPointer<QObject> ) ), SLOT( onInformationFound( QString, QSharedPointer<QObject> ) ) );
}
void
LinkParser::removePlugin( const QSharedPointer< LinkParserPlugin >& plugin )
{
if ( !plugin.isNull() )
{
disconnect( plugin.data(), 0, this, 0);
}
QMutableListIterator< QSharedPointer< LinkParserPlugin > > iter( m_plugins );
while ( iter.hasNext() )
{
QSharedPointer< LinkParserPlugin > ptr = iter.next();
if ( ptr.data() == plugin.data() || ptr.isNull() )
{
iter.remove();
}
}
}
bool
LinkParser::canParseUrl( const QString& url, UrlType type ) const
{
return !parserPluginsForUrl( url, type).isEmpty();
}
QList< QSharedPointer< LinkParserPlugin > >
LinkParser::parserPluginsForUrl( const QString& url, Tomahawk::Utils::UrlType type ) const
{
QList< QSharedPointer< LinkParserPlugin > > plugins;
foreach ( const QSharedPointer< LinkParserPlugin >& plugin, m_plugins )
{
if ( plugin->canParseUrl( url, type ) )
{
plugins.append( plugin );
}
}
return plugins;
}
void
LinkParser::lookupUrl( const QString& url, const QList< QSharedPointer < LinkParserPlugin > >& parserPlugins ) const
{
foreach ( const QSharedPointer< LinkParserPlugin >& plugin, parserPlugins )
{
if ( !plugin.isNull() )
{
plugin->lookupUrl( url );
}
}
}
void
LinkParser::onInformationFound( const QString& url, const QSharedPointer<QObject>& information )
{
tLog() << Q_FUNC_INFO << url;
emit informationFound( url, information );
}

View File

@@ -1,69 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 2014 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 2 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/>.
*/
#pragma once
#ifndef TOMAHAWK_UTILS_LINKPARSER_H
#define TOMAHAWK_UTILS_LINKPARSER_H
#include "../resolvers/ScriptJob.h"
#include "LinkParserPlugin.h"
#include "UrlType.h"
#include "../DllMacro.h"
#include "../Typedefs.h"
#include <memory>
namespace Tomahawk {
namespace Utils {
class LinkParserPlugin;
class DLLEXPORT LinkParser : public QObject
{
Q_OBJECT
public:
static LinkParser* instance();
virtual ~LinkParser();
void addPlugin( const QSharedPointer< LinkParserPlugin >& plugin );
void removePlugin( const QSharedPointer< LinkParserPlugin >& plugin );
bool canParseUrl( const QString& url, UrlType type ) const;
QList< QSharedPointer < LinkParserPlugin > > parserPluginsForUrl( const QString& url, UrlType type ) const;
void lookupUrl( const QString& url, const QList< QSharedPointer < LinkParserPlugin > >& parserPlugins = QList< QSharedPointer < LinkParserPlugin > >() ) const;
signals:
void informationFound( const QString& url, const QSharedPointer<QObject>& information );
private slots:
void onInformationFound( const QString& url, const QSharedPointer<QObject>& information );
private:
explicit LinkParser( QObject* parent = 0 );
QList< QSharedPointer < LinkParserPlugin > > m_plugins;
static LinkParser* s_instance;
};
} // namespace Utils
} // namespace Tomahawk
#endif // TOMAHAWK_UTILS_LINKPARSER_H

View File

@@ -1,50 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 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 2 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/>.
*/
#pragma once
#ifndef TOMAHAWK_UTILS_LINKPARSERPLUGIN_H
#define TOMAHAWK_UTILS_LINKPARSERPLUGIN_H
#include "../DllMacro.h"
#include "../Typedefs.h"
#include "UrlType.h"
namespace Tomahawk {
class ScriptJob;
namespace Utils {
class DLLEXPORT LinkParserPlugin : public QObject
{
Q_OBJECT
public:
virtual ~LinkParserPlugin();
virtual bool canParseUrl( const QString& url, Tomahawk::Utils::UrlType type ) const = 0;
virtual void lookupUrl( const QString& url ) const = 0;
signals:
void informationFound( const QString&, const QSharedPointer<QObject>& );
};
} // namespace Utils
} // namespace Tomahawk
#endif // TOMAHAWK_UTILS_LINKPARSERPLUGIN_H

View File

@@ -24,6 +24,7 @@
#include "PluginLoader_p.h"
#include "config.h"
#include "TomahawkVersion.h"
#include "utils/Logger.h"
@@ -153,7 +154,7 @@ PluginLoader::pluginFilenames( const QString& name ) const
QStringList fileNames;
foreach( const QString& extension, extensions )
{
fileNames << QString("libtomahawk_%1_%2.%3")
fileNames << QString("lib" TOMAHAWK_TARGET_NAME "_%1_%2.%3")
.arg( d_ptr->type )
.arg( name )
.arg( extension );
@@ -174,12 +175,8 @@ PluginLoader::pluginPaths( const QString& name ) const
tDebug() << Q_FUNC_INFO << "Checking directory for" << type << "plugins:" << pluginDir.absolutePath();
foreach ( QString fileName, pluginDir.entryList( pluginFilenames( name ), QDir::Files ) )
{
//TODO: do we really need to check this?!
if ( fileName.startsWith( QString( "libtomahawk_%1" ).arg( type ) ) )
{
const QString path = pluginDir.absoluteFilePath( fileName );
paths << path;
}
const QString path = pluginDir.absoluteFilePath( fileName );
paths << path;
}
}

View File

@@ -211,11 +211,19 @@ TomahawkStyle::styleScrollBar( QScrollBar* scrollBar )
void
TomahawkStyle::loadFonts()
{
#ifdef Q_OS_MAC
QDir dir( QCoreApplication::applicationDirPath() + "/../Resources/Fonts" );
#else
QDir dir( ":/data/fonts" );
#endif
foreach ( const QString& fileName, dir.entryList() )
{
tDebug( LOGVERBOSE ) << "Trying to add font resource:" << fileName;
tDebug( LOGVERBOSE ) << "Trying to add font resource:" << dir.absolutePath() << fileName;
#ifdef Q_OS_MAC
const int id = QFontDatabase::addApplicationFont( dir.absolutePath() + "/" + fileName );
#else
const int id = QFontDatabase::addApplicationFont( ":/data/fonts/" + fileName );
#endif
if ( id >= 0 )
{
tDebug( LOGVERBOSE ) << "Added font:" << id << QFontDatabase::applicationFontFamilies( id ).first();

View File

@@ -102,6 +102,7 @@ namespace TomahawkStyle
static const QColor PLAYLIST_BUTTON_BACKGROUND = QColor( "#111111" );
static const QColor PLAYLIST_BUTTON_FOREGROUND = QColor( "#ffffff" );
static const QColor PLAYLIST_BUTTON_HOVER_BACKGROUND = QColor( "#111111" );
static const QColor PLAYLIST_PROGRESS_BACKGROUND = QColor( "#ffffff" );
static const QColor PLAYLIST_PROGRESS_FOREGROUND = QColor( "#E61878" );

View File

@@ -320,11 +320,11 @@ filesizeToString( unsigned int size )
if ( mb )
{
return QString( "%1.%2 Mb" ).arg( mb ).arg( int( ( kb % 1024 ) / 102.4 ) );
return QString( "%1.%2 MB" ).arg( mb ).arg( int( ( kb % 1024 ) / 102.4 ) );
}
else if ( kb )
{
return QString( "%1 Kb" ).arg( kb );
return QString( "%1 KB" ).arg( kb );
}
else
return QString::number( size );

View File

@@ -1,19 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 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 2 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 "UrlType.h"

View File

@@ -29,6 +29,7 @@
#include "Source.h"
#include "MetaPlaylistInterface.h"
#include "playlist/TrackView.h"
#include "playlist/TrackDetailView.h"
#include "widgets/BasicHeader.h"
#include "database/DatabaseCommand_AllTracks.h"
@@ -58,6 +59,7 @@ AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* par
m_tracksModel->setMode( Mixed );
// We need to set the model on the view before loading the playlist, so spinners & co are connected
ui->albumView->trackDetailView()->setBuyButtonVisible( true );
ui->albumView->trackView()->setPlayableModel( m_tracksModel );
ui->albumView->setCaption( tr( "Album Details" ) );
@@ -186,4 +188,4 @@ AlbumInfoWidget::pixmap() const
return Tomahawk::ViewPage::pixmap();
else
return m_pixmap;
}
}

View File

@@ -107,6 +107,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
ui->topHits->setItemWidth( scaledX( 140 ) );
ui->topHits->proxyModel()->setHideDupeItems( true );
ui->topHits->delegate()->setWordWrapping( true );
ui->topHits->delegate()->setShowBuyButtons( true );
ui->topHits->setFixedHeight( ui->topHits->itemSize().height() + ui->topHits->spacing() * 2 );
m_topHitsModel = new PlayableModel( ui->topHits );
@@ -121,7 +122,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
ui->biography->setObjectName( "biography" );
ui->biography->setContentsMargins( 0, 0, 0, 0 );
ui->biography->page()->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
ui->biography->page()->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
ui->biography->page()->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAsNeeded );
ui->biography->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
ui->biography->installEventFilter( this );

View File

@@ -20,6 +20,7 @@
#include "CollectionViewPage.h"
#include <QRadioButton>
#include <QPushButton>
#include <QStackedWidget>
#include <QVBoxLayout>
@@ -32,7 +33,6 @@
#include "playlist/GridView.h"
#include "playlist/PlayableProxyModelPlaylistInterface.h"
#include "resolvers/ScriptCollection.h"
#include "DownloadManager.h"
#include "TomahawkSettings.h"
#include "utils/ImageRegistry.h"
#include "utils/TomahawkStyle.h"
@@ -58,10 +58,13 @@ CollectionViewPage::CollectionViewPage( const Tomahawk::collection_ptr& collecti
qRegisterMetaType< CollectionViewPageMode >( "CollectionViewPageMode" );
m_header->setBackground( ImageRegistry::instance()->pixmap( RESPATH "images/collection_background.png", QSize( 0, 0 ) ), false );
setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultCollection, TomahawkUtils::Original, QSize( 256, 256 ) ) );
m_columnView->proxyModel()->setStyle( PlayableProxyModel::SingleColumn );
PlayableProxyModel* trackViewProxyModel = m_trackView->proxyModel();
if ( collection->backendType() == Collection::ScriptCollectionType )
{
m_trackView->proxyModel()->setStyle( PlayableProxyModel::Locker );
@@ -70,8 +73,15 @@ CollectionViewPage::CollectionViewPage( const Tomahawk::collection_ptr& collecti
{
m_trackView->proxyModel()->setStyle( PlayableProxyModel::Collection );
}
// mapSourceColumnToColumn depends on the just set PlayableProxyModel::PlayableItemStyle
m_trackView->setColumnHidden( trackViewProxyModel->mapSourceColumnToColumn( PlayableModel::Composer ), true );
m_trackView->setColumnHidden( trackViewProxyModel->mapSourceColumnToColumn( PlayableModel::Origin ), true );
m_trackView->setColumnHidden( trackViewProxyModel->mapSourceColumnToColumn( PlayableModel::Score ), true );
m_trackView->setColumnHidden( trackViewProxyModel->mapSourceColumnToColumn( PlayableModel::Bitrate ), true );
m_trackView->setGuid( QString( "trackview/flat" ) );
m_trackView->setSortingEnabled( true );
m_trackView->sortByColumn( 0, Qt::AscendingOrder );
{
m_albumView->setAutoResize( false );
@@ -122,8 +132,11 @@ CollectionViewPage::CollectionViewPage( const Tomahawk::collection_ptr& collecti
if ( collection->backendType() == Collection::ScriptCollectionType )
{
QAbstractButton* downloadButton = m_header->addButton( tr( "Download All" ) );
connect( downloadButton, SIGNAL( clicked() ), SLOT( onDownloadAll() ) );
m_downloadAllButton = m_header->addButton( tr( "Download All" ) );
connect( m_downloadAllButton, SIGNAL( clicked() ), SLOT( onDownloadAll() ) );
connect( DownloadManager::instance(), SIGNAL( stateChanged( DownloadManager::DownloadManagerState, DownloadManager::DownloadManagerState ) ),
SLOT( onDownloadManagerStateChanged( DownloadManager::DownloadManagerState, DownloadManager::DownloadManagerState ) ) );
m_header->setRefreshVisible( true );
connect( m_header, SIGNAL( refresh() ), SLOT( onCollectionChanged() ) );
@@ -192,8 +205,6 @@ CollectionViewPage::setFlatModel( PlayableModel* model )
m_flatModel = model;
m_trackView->setPlayableModel( model );
m_trackView->setSortingEnabled( true );
m_trackView->sortByColumn( 0, Qt::AscendingOrder );
if ( oldModel )
{
@@ -381,6 +392,8 @@ CollectionViewPage::restoreViewMode()
} else {
setCurrentMode( mode );
}
onCollectionChanged();
}
@@ -437,14 +450,40 @@ CollectionViewPage::onCollectionChanged()
void
CollectionViewPage::onDownloadAll()
{
for ( int i = 0; i < m_flatModel->rowCount( QModelIndex() ); i++ )
if ( DownloadManager::instance()->state() == DownloadManager::Running )
{
PlayableItem* item = m_flatModel->itemFromIndex( m_flatModel->index( i, 0, QModelIndex() ) );
if ( !item )
continue;
DownloadManager::instance()->cancelAll();
}
else
{
for ( int i = 0; i < m_trackView->proxyModel()->rowCount( QModelIndex() ); i++ )
{
PlayableItem* item = m_trackView->proxyModel()->itemFromIndex( m_trackView->proxyModel()->mapToSource( m_trackView->proxyModel()->index( i, 0, QModelIndex() ) ) );
if ( !item )
continue;
if ( !item->result()->downloadFormats().isEmpty() )
DownloadManager::instance()->addJob( item->result()->toDownloadJob( item->result()->downloadFormats().first() ) );
QList< DownloadFormat > formats = item->query()->results().first()->downloadFormats();
if ( formats.isEmpty() || !DownloadManager::instance()->localFileForDownload( formats.first().url.toString() ).isEmpty() )
continue;
if ( !item->result()->downloadFormats().isEmpty() )
DownloadManager::instance()->addJob( item->result()->toDownloadJob( item->result()->downloadFormats().first() ) );
}
}
}
void
CollectionViewPage::onDownloadManagerStateChanged( DownloadManager::DownloadManagerState newState, DownloadManager::DownloadManagerState oldState )
{
tDebug() << Q_FUNC_INFO;
if ( newState == DownloadManager::Running )
{
m_downloadAllButton->setText( tr( "Cancel Download" ) );
}
else
{
m_downloadAllButton->setText( tr( "Download All" ) );
}
}
@@ -459,5 +498,14 @@ CollectionViewPage::isTemporaryPage() const
bool
CollectionViewPage::isBeingPlayed() const
{
return m_playlistInterface->hasChildInterface( AudioEngine::instance()->currentTrackPlaylist() );
if ( !playlistInterface() )
return false;
if ( playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() )
return true;
if ( playlistInterface()->hasChildInterface( AudioEngine::instance()->currentTrackPlaylist() ) )
return true;
return false;
}

View File

@@ -22,8 +22,10 @@
#include "ViewPage.h"
#include "PlaylistInterface.h"
#include "DownloadManager.h"
#include "DllMacro.h"
class QPushButton;
class QStackedWidget;
class GridView;
@@ -83,10 +85,12 @@ private slots:
void onCollectionChanged();
void onDownloadAll();
void onDownloadManagerStateChanged( DownloadManager::DownloadManagerState newState, DownloadManager::DownloadManagerState oldState );
private:
FilterHeader* m_header;
QPixmap m_pixmap;
QPushButton* m_downloadAllButton;
ColumnView* m_columnView;
TrackView* m_trackView;

View File

@@ -100,6 +100,7 @@ SearchWidget::SearchWidget( const QString& search, QWidget* parent )
ui->tracks->setItemWidth( TomahawkUtils::DpiScaler::scaledX( this, 140 ) );
// ui->tracks->proxyModel()->setHideDupeItems( true );
ui->tracks->delegate()->setWordWrapping( true );
ui->tracks->delegate()->setShowBuyButtons( true );
ui->tracks->setFixedHeight( ui->tracks->itemSize().height() + ui->tracks->spacing() * 2 );
m_resultsModel = new PlayableModel( ui->tracks );
@@ -372,13 +373,18 @@ SearchWidget::onAlbumsFound( const QList<Tomahawk::album_ptr>& albums )
int distance = TomahawkUtils::levenshtein( m_search, album->name() );
int maxlen = qMax( m_search.length(), album->name().length() );
float score = (float)( maxlen - distance ) / maxlen;
float scoreAlbum = (float)( maxlen - distance ) / maxlen;
if ( score <= 0.1 )
distance = TomahawkUtils::levenshtein( m_search, album->artist()->name() );
maxlen = qMax( m_search.length(), album->artist()->name().length() );
float scoreArtist = (float)( maxlen - distance ) / maxlen;
float scoreMax = qMax( scoreAlbum, scoreArtist );
if ( scoreMax <= 0.1 )
continue;
m_albums.insert( album, score );
// tDebug() << Q_FUNC_INFO << "found album:" << album->name() << "score:" << score;
m_albums.insert( album, scoreMax );
// tDebug() << Q_FUNC_INFO << "found album:" << album->name() << "scoreMax:" << scoreMax;
}
// updateAlbums();

View File

@@ -132,10 +132,16 @@ BasicHeader::setPixmap( const QPixmap& pixmap, bool tinted )
}
QAbstractButton*
QPushButton*
BasicHeader::addButton( const QString& text )
{
QPushButton* button = new QPushButton( this );
button->setStyleSheet( "QPushButton:hover { font-size: 12px; color: #2b2b2b; background: #f8f8f8; border-style: solid; border-radius: 0px; border-width: 2px; border-color: #2b2b2b; }"
"QPushButton { font-size: 12px; color: #ffffff; background-color: #000000; border-style: solid; border-radius: 0px; border-width: 0px; }" );
button->setMinimumHeight( 30 );
button->setMinimumWidth( 132 );
button->setText( text );
ui->horizontalLayout->addSpacing( 8 );

View File

@@ -26,6 +26,7 @@
#include "widgets/BackgroundWidget.h"
#include "DllMacro.h"
class QPushButton;
class QLabel;
class ElidedLabel;
class QPaintEvent;
@@ -40,7 +41,7 @@ public:
QScopedPointer<Ui::HeaderWidget> ui;
QAbstractButton* addButton( const QString& text );
QPushButton* addButton( const QString& text );
public slots:
virtual void setCaption( const QString& s );

View File

@@ -32,7 +32,9 @@ using namespace Tomahawk;
DropDownButton::DropDownButton( QWidget* parent )
: QComboBox( parent )
, m_hovering( false )
{
setAttribute( Qt::WA_Hover, true );
}
@@ -46,44 +48,59 @@ DropDownButton::paintEvent( QPaintEvent* event )
{
// QComboBox::paintEvent( event );
QPainter p( this );
drawPrimitive( &p, contentsRect(), currentText() );
setupPainter( &p );
drawPrimitive( &p, contentsRect(), currentText(), m_hovering, true );
}
void
DropDownButton::drawPrimitive( QPainter* p, const QRect& rect, const QString& text )
DropDownButton::drawPrimitive( QPainter* p, const QRect& rect, const QString& text, bool hovering, bool itemsAvailable )
{
p->save();
setupPainter( p );
p->setRenderHint( QPainter::TextAntialiasing );
QRect r = rect.adjusted( 2, 2, -2, -2 );
p->setPen( TomahawkStyle::PLAYLIST_BUTTON_BACKGROUND.darker() );
p->setBrush( TomahawkStyle::PLAYLIST_BUTTON_BACKGROUND );
QColor bgColor = hovering ? TomahawkStyle::PLAYLIST_BUTTON_HOVER_BACKGROUND : TomahawkStyle::PLAYLIST_BUTTON_BACKGROUND;
p->setOpacity( 1.0 );
p->setPen( bgColor );
p->setBrush( bgColor );
p->drawRect( r );
// paint divider
p->setPen( TomahawkStyle::PLAYLIST_BUTTON_FOREGROUND );
p->drawLine( QPoint( r.right() - 24, r.top() + 3 ), QPoint( r.right() - 24, r.bottom() - 3 ) );
int dropdownWidth = 0;
// paint drop-down arrow
p->save();
QPainterPath dropPath;
dropPath.moveTo( QPointF( r.right() - 14, float(r.top()) + float(r.height()) * 0.5 - 1.5 ) );
QPointF currentPosition = dropPath.currentPosition();
dropPath.lineTo( currentPosition.x() + 6, currentPosition.y() );
dropPath.lineTo( currentPosition.x() + 3, currentPosition.y() + 3 );
dropPath.closeSubpath();
p->setPen( TomahawkStyle::PLAYLIST_BUTTON_FOREGROUND );
p->setBrush( TomahawkStyle::PLAYLIST_BUTTON_FOREGROUND );
p->setRenderHint( QPainter::Antialiasing, false );
p->drawPath( dropPath );
p->restore();
if ( itemsAvailable )
{
// paint divider
p->drawLine( QPoint( r.right() - 24, r.top() + 3 ), QPoint( r.right() - 24, r.bottom() - 3 ) );
// paint drop-down arrow
p->save();
QPainterPath dropPath;
dropPath.moveTo( QPointF( r.right() - 14, float(r.top()) + float(r.height()) * 0.5 - 1.5 ) );
QPointF currentPosition = dropPath.currentPosition();
dropPath.lineTo( currentPosition.x() + 6, currentPosition.y() );
dropPath.lineTo( currentPosition.x() + 3, currentPosition.y() + 3 );
dropPath.closeSubpath();
p->setPen( TomahawkStyle::PLAYLIST_BUTTON_FOREGROUND );
p->setBrush( TomahawkStyle::PLAYLIST_BUTTON_FOREGROUND );
p->setRenderHint( QPainter::Antialiasing, false );
p->drawPath( dropPath );
p->restore();
dropdownWidth = 24;
}
// paint label
const QFontMetrics fm( p->font() );
r.adjust( 0, 0, -24, 0 ); // center-align left of the divider
p->drawText( r, Qt::AlignCenter, fm.elidedText( text, Qt::ElideRight, r.width() ) );
r.adjust( 0, 0, -dropdownWidth, 0 ); // center-align left of the divider
p->drawText( r, Qt::AlignCenter, fm.elidedText( text.toUpper(), Qt::ElideRight, r.width() ) );
p->restore();
}
@@ -101,3 +118,29 @@ DropDownButton::mousePressEvent( QMouseEvent* event )
event->accept();
emit clicked();
}
void
DropDownButton::enterEvent( QEvent * event )
{
m_hovering = true;
QWidget::enterEvent(event);
}
void
DropDownButton::leaveEvent( QEvent* event )
{
m_hovering = false;
QWidget::leaveEvent(event);
}
void
DropDownButton::setupPainter( QPainter* p )
{
QFont f = p->font();
f.setPointSize( TomahawkUtils::defaultFontSize() - 1 );
f.setBold( true );
p->setFont( f );
}

View File

@@ -32,7 +32,7 @@ public:
explicit DropDownButton( QWidget* parent = 0 );
virtual ~DropDownButton();
static void drawPrimitive( QPainter* p, const QRect& rect, const QString& text );
static void drawPrimitive( QPainter* p, const QRect& rect, const QString& text, bool hovering, bool itemsAvailable );
public slots:
@@ -42,10 +42,15 @@ signals:
protected:
void paintEvent( QPaintEvent* event );
void mousePressEvent( QMouseEvent* event );
void enterEvent( QEvent* event );
void leaveEvent( QEvent* event );
private slots:
private:
static void setupPainter( QPainter* p );
bool m_hovering;
};
#endif // DROPDOWNBUTTON_H

View File

@@ -85,7 +85,7 @@ ImageButton::paintEvent( QPaintEvent* event )
p.setClipRect( event->rect() );
QIcon::Mode mode = isDown()
? QIcon::Active
? QIcon::Selected
: QIcon::Normal;
QIcon::State state = isChecked()

View File

@@ -1,5 +1,3 @@
SET( TOMAHAWK_LIBRARIES tomahawklib )
SET( OS_SPECIFIC_LINK_LIBRARIES
${OS_SPECIFIC_LINK_LIBRARIES}
${COREAUDIO_LIBRARY}

View File

@@ -1,5 +1,3 @@
set(TOMAHAWK_APPLICATION_TARGET "tomahawk-bin")
include( ECMAddAppIcon )
# SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
@@ -9,6 +7,8 @@ IF( NOT CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT CMAKE_BUILD_TYPE STREQUAL "R
MESSAGE( "Building in debug mode, enabling all debug updates" )
ENDIF()
set(TOMAHAWK_APPLICATION_TARGET ${TOMAHAWK_TARGET_NAME}-bin)
# build plugins
# use glob, but hardcoded list for now:
#FILE( GLOB plugindirs "src/plugins/*" )
@@ -154,19 +154,18 @@ else()
ecm_add_app_icon(tomahawkSources ICONS ${TOMAHAWK_ICONS})
endif()
qt_add_resources( RC_SRCS "../../resources.qrc" )
SET( final_src ${final_src} ${tomahawkUI_H} ${tomahawkMoc} ${tomahawkSources} ${RC_SRCS} )
if(APPLE)
set(TOMAHAWK_RUNTIME_OUTPUT_NAME "Tomahawk")
if(APPLE OR WIN32)
set(TOMAHAWK_RUNTIME_OUTPUT_NAME "${TOMAHAWK_APPLICATION_NAME}")
else()
set(TOMAHAWK_RUNTIME_OUTPUT_NAME "tomahawk")
set(TOMAHAWK_RUNTIME_OUTPUT_NAME "${TOMAHAWK_TARGET_NAME}")
endif()
ADD_EXECUTABLE( ${TOMAHAWK_APPLICATION_TARGET} WIN32 MACOSX_BUNDLE ${final_src} )
SET_TARGET_PROPERTIES(${TOMAHAWK_APPLICATION_TARGET}
SET_TARGET_PROPERTIES( ${TOMAHAWK_APPLICATION_TARGET}
PROPERTIES
AUTOMOC TRUE
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_BINARY_DIR}/Info.plist"
@@ -210,8 +209,7 @@ TARGET_LINK_LIBRARIES( ${TOMAHAWK_APPLICATION_TARGET}
IF( APPLE )
IF( HAVE_SPARKLE )
MESSAGE("Sparkle Found, installing framekwork in bundle")
INSTALL(DIRECTORY "${SPARKLE}/Versions/Current/Resources" DESTINATION "${CMAKE_BINARY_DIR}/Tomahawk.app/Contents/Frameworks/Sparkle.framework")
INSTALL(DIRECTORY "${SPARKLE}/Versions/Current/Resources" DESTINATION "${CMAKE_BINARY_DIR}/${TOMAHAWK_APPLICATION_NAME}.app/Contents/Frameworks/Sparkle.framework")
ENDIF( HAVE_SPARKLE )
ENDIF( APPLE )

Some files were not shown because too many files have changed in this diff Show More