From 62f1fde90ae02c73308d260d6a172e0e4763b923 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 30 Jun 2013 22:06:55 +0200 Subject: [PATCH] Move NetworkActivityWidget to libtomahawk-widgets --- CMakeLists.txt | 1 + CMakeModules/NSIS.template.in | 4 + TomahawkAddLibrary.cmake | 94 +++++++++++++++++++ TomahawkAddPlugin.cmake | 2 + src/libtomahawk/CMakeLists.txt | 4 +- src/libtomahawk/ViewManager.cpp | 25 +---- src/libtomahawk/ViewManager.h | 4 - src/libtomahawk/widgets/Breadcrumb.h | 6 +- src/libtomahawk/widgets/CMakeLists.txt | 17 ++++ .../widgets/NetworkActivityWidget.h | 4 +- src/libtomahawk/widgets/WidgetsDllMacro.h | 33 +++++++ src/tomahawk/CMakeLists.txt | 1 + src/tomahawk/sourcetree/SourcesModel.cpp | 29 +++--- 13 files changed, 183 insertions(+), 41 deletions(-) create mode 100644 TomahawkAddLibrary.cmake create mode 100644 src/libtomahawk/widgets/CMakeLists.txt create mode 100644 src/libtomahawk/widgets/WidgetsDllMacro.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ec1fafae6..d16fdf086 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -316,6 +316,7 @@ IF( NOT APPLE ) ENDIF( NOT APPLE ) SET( TOMAHAWK_LIBRARIES tomahawklib ) +SET( TOMAHAWK_WIDGETS_LIBRARIES tomahawk-widgets ) ADD_SUBDIRECTORY( thirdparty ) ADD_SUBDIRECTORY( src ) diff --git a/CMakeModules/NSIS.template.in b/CMakeModules/NSIS.template.in index 08ee16a95..bf38c9d25 100644 --- a/CMakeModules/NSIS.template.in +++ b/CMakeModules/NSIS.template.in @@ -276,6 +276,8 @@ Section "Tomahawk Player" SEC_TOMAHAWK_PLAYER File "${INSTALL_PATH}\bin\tomahawk_crash_reporter.exe" File "${INSTALL_PATH}\bin\libtomahawk.dll" + File "${INSTALL_PATH}\bin\libtomahawk-widgets.dll" + ; plugins File "${INSTALL_PATH}\lib\libtomahawk_*_*.dll" !endif @@ -286,6 +288,8 @@ Section "Tomahawk Player" SEC_TOMAHAWK_PLAYER File "${BUILD_PATH}\tomahawk_crash_reporter.exe" File "${BUILD_PATH}\libtomahawk.dll" + File "${BUILD_PATH}\libtomahawk-widgets.dll" + ; plugins File "${BUILD_PATH}\libtomahawk_*_*.dll" !endif diff --git a/TomahawkAddLibrary.cmake b/TomahawkAddLibrary.cmake new file mode 100644 index 000000000..f10b303b5 --- /dev/null +++ b/TomahawkAddLibrary.cmake @@ -0,0 +1,94 @@ +include( CMakeParseArguments ) + +function(tomahawk_add_library) + # parse arguments (name needs to be saved before passing ARGN into the macro) + set(NAME ${ARGV0}) + set(options NO_INSTALL NO_VERSION) + set(oneValueArgs NAME TYPE EXPORT_MACRO TARGET TARGET_TYPE EXPORT VERSION SOVERSION) + set(multiValueArgs SOURCES UI LINK_LIBRARIES COMPILE_DEFINITIONS) + cmake_parse_arguments(LIBRARY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(LIBRARY_NAME ${NAME}) + + +# message("*** Arguments for ${LIBRARY_NAME}") +# message("Sources: ${LIBRARY_SOURCES}") +# message("Link libraries: ${LIBRARY_LINK_LIBRARIES}") +# message("UI: ${LIBRARY_UI}") +# message("TARGET_TYPE: ${LIBRARY_TARGET_TYPE}") +# message("EXPORT_MACRO: ${LIBRARY_EXPORT_MACRO}") +# message("NO_INSTALL: ${LIBRARY_NO_INSTALL}") + + set(target ${LIBRARY_NAME}) + + # qt stuff + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + if(LIBRARY_UI) + qt_wrap_ui(LIBRARY_UI_SOURCES ${LIBRARY_UI}) + list(APPEND LIBRARY_SOURCES ${LIBRARY_UI_SOURCES}) + endif() + + # add resources from current dir + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/resources.qrc") + qt_add_resources(LIBRARY_RC_SOURCES "resources.qrc") + list(APPEND LIBRARY_SOURCES ${LIBRARY_RC_SOURCES}) + unset(LIBRARY_RC_SOURCES) + endif() + + # add target + if(LIBRARY_TARGET_TYPE STREQUAL "STATIC") + add_library(${target} STATIC ${LIBRARY_SOURCES}) + elseif(LIBRARY_TARGET_TYPE STREQUAL "MODULE") + add_library(${target} MODULE ${LIBRARY_SOURCES}) + else() # default + add_library(${target} SHARED ${LIBRARY_SOURCES}) + endif() + + # HACK: add qt modules - every lib should define its own set of modules + qt5_use_modules(${target} Core Network Widgets Sql Xml DBus) + + + # definitions - can this be moved into set_target_properties below? + add_definitions(${QT_DEFINITIONS}) + set_target_properties(${target} PROPERTIES AUTOMOC TRUE) + + if(LIBRARY_EXPORT_MACRO) + set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_EXPORT_MACRO}) + endif() + + if(LIBRARY_COMPILE_DEFINITIONS) + # Dear CMake, i hate you! Sincerely, domme + # At least in CMake 2.8.8, you CANNOT set more than one COMPILE_DEFINITIONS value + # only takes the first one if called multiple times or bails out with wrong number of arguments + # when passing in a list, thus i redefine the export macro here in hope it won't mess up other targets + add_definitions( "-D${LIBRARY_EXPORT_MACRO}" ) + + set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_COMPILE_DEFINITIONS}) + endif() + + # add link targets + target_link_libraries(${target} ${TOMAHAWK_LIBRARIES}) + if(LIBRARY_LINK_LIBRARIES) + target_link_libraries(${target} ${LIBRARY_LINK_LIBRARIES}) + endif() + + # add soversion + if(NOT LIBRARY_NO_VERSION) + set_target_properties(${target} PROPERTIES VERSION ${LIBRARY_VERSION}) + + if(NOT LIBRARY_SOVERSION) + set(LIBRARY_SOVERSION ${LIBRARY_VERSION}) + endif() + + set_target_properties(${target} PROPERTIES SOVERSION ${LIBRARY_SOVERSION}) + endif() + + # make installation optional, maybe useful for dummy plugins one day + if(NOT LIBRARY_NO_INSTALL) + include(GNUInstallDirs) + if(NOT LIBRARY_EXPORT) + install(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR}) + else() + install(TARGETS ${target} EXPORT ${LIBRARY_EXPORT} DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + endif() +endfunction() diff --git a/TomahawkAddPlugin.cmake b/TomahawkAddPlugin.cmake index 206c9d42b..183c126a7 100644 --- a/TomahawkAddPlugin.cmake +++ b/TomahawkAddPlugin.cmake @@ -43,5 +43,7 @@ function(tomahawk_add_plugin) list(APPEND tomahawk_add_library_args "LINK_LIBRARIES" "${PLUGIN_LINK_LIBRARIES}") endif() + list(APPEND tomahawk_add_library_args "NO_VERSION") + tomahawk_add_library(${tomahawk_add_library_args}) endfunction() diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index a168b3483..005e9cfc9 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -159,7 +159,6 @@ set( libGuiSources widgets/PlayableCover.cpp widgets/SocialPlaylistWidget.cpp widgets/SourceTreePopupDialog.cpp - widgets/NetworkActivityWidget.cpp widgets/infowidgets/SourceInfoWidget.cpp widgets/infowidgets/ArtistInfoWidget.cpp widgets/infowidgets/AlbumInfoWidget.cpp @@ -379,7 +378,6 @@ set( libUI ${libUI} widgets/WhatsHotWidget.ui widgets/NewReleasesWidget.ui widgets/SocialPlaylistWidget.ui - widgets/NetworkActivityWidget.ui widgets/infowidgets/SourceInfoWidget.ui widgets/infowidgets/ArtistInfoWidget.ui widgets/infowidgets/AlbumInfoWidget.ui @@ -524,6 +522,8 @@ TARGET_LINK_LIBRARIES( tomahawklib ${LINK_LIBRARIES} ) +add_subdirectory( widgets ) + INSTALL( TARGETS tomahawklib EXPORT TomahawkLibraryDepends RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index 7655d54ea..1f907a963 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -49,7 +49,6 @@ #include "widgets/NewReleasesWidget.h" #include "widgets/Dashboard.h" #include "widgets/WhatsHotWidget.h" -#include "widgets/NetworkActivityWidget.h" #include "widgets/infowidgets/SourceInfoWidget.h" #include "widgets/infowidgets/ArtistInfoWidget.h" #include "widgets/infowidgets/AlbumInfoWidget.h" @@ -85,7 +84,6 @@ ViewManager::ViewManager( QObject* parent ) , m_newReleasesWidget( 0 ) , m_recentPlaysWidget( 0 ) , m_inboxWidget( 0 ) - , m_networkActivityWidget( 0 ) , m_currentPage( 0 ) { s_instance = this; @@ -130,7 +128,6 @@ ViewManager::ViewManager( QObject* parent ) ViewManager::~ViewManager() { - delete m_networkActivityWidget; delete m_whatsHotWidget; delete m_newReleasesWidget; delete m_dashboard; @@ -495,17 +492,6 @@ ViewManager::showInboxPage() } -ViewPage *ViewManager::showNetworkActivityPage() -{ - if ( !m_networkActivityWidget ) - { - m_networkActivityWidget = new NetworkActivityWidget( m_widget ); - } - - return show( m_networkActivityWidget ); -} - - void ViewManager::setFilter( const QString& filter ) { @@ -896,11 +882,6 @@ ViewManager::inboxWidget() const return m_inboxWidget; } -ViewPage *ViewManager::networkActivityWidget() const -{ - return m_networkActivityWidget; -} - ViewPage* ViewManager::dynamicPageWidget( const QString& pageName ) const @@ -941,7 +922,11 @@ ViewManager::showDynamicPage( const QString& pageName ) Q_ASSERT(false); return 0; } - m_dynamicPages.insert( pageName, m_dynamicPagesInstanceLoaders.value( pageName )() ); + + ViewPage* viewPage = m_dynamicPagesInstanceLoaders.value( pageName )(); + Q_ASSERT(viewPage); + m_dynamicPages.insert( pageName, viewPage ); + m_dynamicPagesInstanceLoaders.remove( pageName ); } diff --git a/src/libtomahawk/ViewManager.h b/src/libtomahawk/ViewManager.h index 3857844bf..7cca529da 100644 --- a/src/libtomahawk/ViewManager.h +++ b/src/libtomahawk/ViewManager.h @@ -60,7 +60,6 @@ class Dashboard; class WhatsHotWidget; class QPushButton; class InboxModel; -class NetworkActivityWidget; namespace Tomahawk { @@ -99,7 +98,6 @@ public: Tomahawk::ViewPage* recentPlaysWidget() const; Tomahawk::ViewPage* superCollectionView() const; Tomahawk::ViewPage* inboxWidget() const; - Tomahawk::ViewPage* networkActivityWidget() const; Tomahawk::ViewPage* dynamicPageWidget( const QString& pageName ) const; @@ -145,7 +143,6 @@ public slots: Tomahawk::ViewPage* showNewReleasesPage(); Tomahawk::ViewPage* showRecentPlaysPage(); Tomahawk::ViewPage* showInboxPage(); - Tomahawk::ViewPage* showNetworkActivityPage(); void addDynamicPage( const QString& pageName, const QString& text, const QIcon& icon, boost::function< Tomahawk::ViewPage*() > instanceLoader ); Tomahawk::ViewPage* showDynamicPage( const QString& pageName ); @@ -201,7 +198,6 @@ private: Tomahawk::ViewPage* m_recentPlaysWidget; Tomahawk::ViewPage* m_inboxWidget; InboxModel* m_inboxModel; - NetworkActivityWidget* m_networkActivityWidget; QHash< QString, Tomahawk::ViewPage* > m_dynamicPages; QHash< QString, boost::function< Tomahawk::ViewPage*() > > m_dynamicPagesInstanceLoaders; diff --git a/src/libtomahawk/widgets/Breadcrumb.h b/src/libtomahawk/widgets/Breadcrumb.h index fa07c688c..b3d911ef2 100644 --- a/src/libtomahawk/widgets/Breadcrumb.h +++ b/src/libtomahawk/widgets/Breadcrumb.h @@ -39,7 +39,11 @@ class BreadcrumbButton; * Items that have a DefaultRole set will automatically select the default unless the user has * made a previous selection, which is saved in the UserSelection role */ -class Breadcrumb : public QWidget + +//HACK: I'm exporting this, so I can move view pages to libtomahawk-widgets one by one +//TODO: In the end this class should go there too (and be made private again?) +#include "../DllMacro.h" +class DLLEXPORT Breadcrumb : public QWidget { Q_OBJECT public: diff --git a/src/libtomahawk/widgets/CMakeLists.txt b/src/libtomahawk/widgets/CMakeLists.txt new file mode 100644 index 000000000..af9260248 --- /dev/null +++ b/src/libtomahawk/widgets/CMakeLists.txt @@ -0,0 +1,17 @@ + +set(TOMAHAWK_WIDGETS_LIBRARY_TARGET tomahawk-widgets) + +list(APPEND ${TOMAHAWK_WIDGETS_LIBRARY_TARGET}_SOURCES + NetworkActivityWidget.cpp +) + +list(APPEND ${TOMAHAWK_WIDGETS_LIBRARY_TARGET}_UI + NetworkActivityWidget.ui +) + +tomahawk_add_library(${TOMAHAWK_WIDGETS_LIBRARY_TARGET} + SOURCES ${${TOMAHAWK_WIDGETS_LIBRARY_TARGET}_SOURCES} + UI ${${TOMAHAWK_WIDGETS_LIBRARY_TARGET}_UI} + EXPORT TomahawkLibraryDepends + VERSION ${TOMAHAWK_VERSION_SHORT} +) diff --git a/src/libtomahawk/widgets/NetworkActivityWidget.h b/src/libtomahawk/widgets/NetworkActivityWidget.h index cf8513ea9..fb9d20658 100644 --- a/src/libtomahawk/widgets/NetworkActivityWidget.h +++ b/src/libtomahawk/widgets/NetworkActivityWidget.h @@ -21,6 +21,8 @@ #include "ViewPage.h" +#include "WidgetsDllMacro.h" + class AnimatedSpinner; class NetworkActivityWidgetPrivate; class PlaylistModel; @@ -32,7 +34,7 @@ namespace Ui class NetworkActivityWidget; } -class NetworkActivityWidget : public QWidget, public Tomahawk::ViewPage +class TOMAHAWK_WIDGETS_EXPORT NetworkActivityWidget : public QWidget, public Tomahawk::ViewPage { Q_OBJECT public: diff --git a/src/libtomahawk/widgets/WidgetsDllMacro.h b/src/libtomahawk/widgets/WidgetsDllMacro.h new file mode 100644 index 000000000..424bcc612 --- /dev/null +++ b/src/libtomahawk/widgets/WidgetsDllMacro.h @@ -0,0 +1,33 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef WIDGETSDLLMACRO_H +#define WIDGETSDLLMACRO_H + +#include + +#ifndef TOMAHAWK_WIDGETS_EXPORT +# if defined (tomahawk_widgets_EXPORTS) +# define TOMAHAWK_WIDGETS_EXPORT Q_DECL_EXPORT +# else +# define TOMAHAWK_WIDGETS_EXPORT Q_DECL_IMPORT +# endif +#endif + +#endif // WIDGETSDLLMACRO_H diff --git a/src/tomahawk/CMakeLists.txt b/src/tomahawk/CMakeLists.txt index d5f4203ad..c0967ff3f 100644 --- a/src/tomahawk/CMakeLists.txt +++ b/src/tomahawk/CMakeLists.txt @@ -187,6 +187,7 @@ ENDIF() TARGET_LINK_LIBRARIES( tomahawk ${LINK_LIBRARIES} + ${TOMAHAWK_WIDGETS_LIBRARIES} ${TOMAHAWK_LIBRARIES} ${PHONON_LIBS} ${OS_SPECIFIC_LINK_LIBRARIES} diff --git a/src/tomahawk/sourcetree/SourcesModel.cpp b/src/tomahawk/sourcetree/SourcesModel.cpp index 8a9b6fdf5..dfa71912b 100644 --- a/src/tomahawk/sourcetree/SourcesModel.cpp +++ b/src/tomahawk/sourcetree/SourcesModel.cpp @@ -20,11 +20,6 @@ #include "sourcetree/SourcesModel.h" -#include -#include - -#include - #include "sourcetree/items/ScriptCollectionItem.h" #include "sourcetree/items/SourceTreeItem.h" #include "sourcetree/items/SourceItem.h" @@ -38,6 +33,7 @@ #include "collection/Collection.h" #include "Source.h" #include "ViewManager.h" +#include "widgets/NetworkActivityWidget.h" #include "GlobalActionManager.h" #include "DropJob.h" #include "items/PlaylistItems.h" @@ -47,6 +43,13 @@ #include "utils/ImageRegistry.h" #include "utils/Logger.h" +#include +#include + +#include +#include +#include + using namespace Tomahawk; @@ -57,6 +60,7 @@ SourcesModel::SourcesModel( QObject* parent ) { m_rootItem = new SourceTreeItem( this, 0, Invalid ); + connect( ViewManager::instance(), SIGNAL( viewPageAdded( QString, QString, QIcon ) ), SLOT( appendPageItem( QString, QString, QIcon ) ) ); appendGroups(); onSourcesAdded( SourceList::instance()->sources() ); @@ -77,9 +81,6 @@ SourcesModel::SourcesModel( QObject* parent ) this, SLOT( onScriptCollectionAdded( Tomahawk::collection_ptr ) ) ); connect( SourceList::instance(), SIGNAL( scriptCollectionRemoved( Tomahawk::collection_ptr ) ), this, SLOT( onScriptCollectionRemoved( Tomahawk::collection_ptr ) ) ); - - - connect( ViewManager::instance(), SIGNAL( viewPageAdded( QString, QString, QIcon ) ), SLOT( appendPageItem( QString, QString, QIcon ) ) ); } @@ -316,11 +317,6 @@ SourcesModel::appendGroups() LovedTracksItem* loved = new LovedTracksItem( this, m_browse ); loved->setSortValue( 2 ); - GenericPageItem* networkActivity = new GenericPageItem( this, m_browse, tr( "Network Activity" ), TomahawkUtils::defaultPixmap( TomahawkUtils::NetworkActivity, TomahawkUtils::Original ), - boost::bind( &ViewManager::showNetworkActivityPage, ViewManager::instance() ), - boost::bind( &ViewManager::networkActivityWidget, ViewManager::instance() ) ); - networkActivity->setSortValue( 3 ); - GenericPageItem* recent = new GenericPageItem( this, m_browse, tr( "Recently Played" ), ImageRegistry::instance()->icon( RESPATH "images/recently-played.svg" ), boost::bind( &ViewManager::showRecentPlaysPage, ViewManager::instance() ), boost::bind( &ViewManager::recentPlaysWidget, ViewManager::instance() ) ); @@ -345,6 +341,13 @@ SourcesModel::appendGroups() m_cloudGroup = new GroupItem( this, m_rootItem, tr( "Cloud" ), 5 ); endInsertRows(); + + // addDynamicPage takes care of begin/endInsertRows itself + ViewManager::instance()->addDynamicPage("network_activity", + tr( "Network Activity" ), + TomahawkUtils::defaultPixmap( TomahawkUtils::NetworkActivity, TomahawkUtils::Original ), + boost::lambda::bind( boost::lambda::new_ptr< NetworkActivityWidget >() ) + ); } void