From 04fc5f6f378bbdbcec12193777b692956e514e62 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 20 Jan 2013 19:59:15 +0100 Subject: [PATCH] Initial commit for listening suggestions. Dbcmd and stubs. --- src/libtomahawk/CMakeLists.txt | 2 + src/libtomahawk/ViewManager.cpp | 52 ++++++++++ src/libtomahawk/ViewManager.h | 7 ++ .../database/DatabaseCommand_ShareTrack.cpp | 97 +++++++++++++++++++ .../database/DatabaseCommand_ShareTrack.h | 79 +++++++++++++++ src/libtomahawk/playlist/InboxModel.cpp | 27 ++++++ src/libtomahawk/playlist/InboxModel.h | 39 ++++++++ .../playlist/PlaylistLargeItemDelegate.h | 2 +- src/libtomahawk/utils/TomahawkUtils.h | 1 + src/libtomahawk/utils/TomahawkUtilsGui.cpp | 4 + src/sourcetree/SourcesModel.cpp | 5 + 11 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp create mode 100644 src/libtomahawk/database/DatabaseCommand_ShareTrack.h create mode 100644 src/libtomahawk/playlist/InboxModel.cpp create mode 100644 src/libtomahawk/playlist/InboxModel.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 327217f66..6ab1070da 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -43,6 +43,7 @@ set( libGuiSources infobar/InfoBar.cpp + playlist/InboxModel.cpp playlist/FlexibleHeader.cpp playlist/FlexibleView.cpp playlist/TreeModel.cpp @@ -267,6 +268,7 @@ list(APPEND libSources database/DatabaseCommand_TrackAttributes.cpp database/DatabaseCommand_SetTrackAttributes.cpp database/DatabaseCommand_PlaybackCharts.cpp + database/DatabaseCommand_ShareTrack.cpp database/Database.cpp database/TomahawkSqlQuery.cpp database/IdThreadWorker.cpp diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index 6477b8e7d..ee2eb3fcb 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -3,6 +3,7 @@ * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Jeff Mitchell * Copyright 2010-2012, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +38,7 @@ #include "SourceList.h" #include "TomahawkSettings.h" +#include "playlist/InboxModel.h" #include "playlist/PlaylistLargeItemDelegate.h" #include "playlist/RecentlyPlayedModel.h" #include "playlist/dynamic/widgets/DynamicWidget.h" @@ -78,6 +80,7 @@ ViewManager::ViewManager( QObject* parent ) , m_whatsHotWidget( 0 ) , m_newReleasesWidget( 0 ) , m_recentPlaysWidget( 0 ) + , m_inboxWidget( 0 ) , m_currentPage( 0 ) , m_loaded( false ) { @@ -87,6 +90,11 @@ ViewManager::ViewManager( QObject* parent ) m_infobar = new InfoBar(); m_stack = new QStackedWidget(); + m_inboxModel = new InboxModel( this ); + m_inboxModel->setTitle( tr( "Inbox" ) ); + m_inboxModel->setDescription( tr( "Listening suggestions from your friends" ) ); + m_inboxModel->setIcon( TomahawkUtils::defaultPixmap( TomahawkUtils::Inbox ) ); + m_contextWidget = new ContextWidget(); m_widget->layout()->addWidget( m_infobar ); @@ -124,6 +132,7 @@ ViewManager::~ViewManager() delete m_newReleasesWidget; delete m_welcomeWidget; delete m_recentPlaysWidget; + delete m_inboxWidget; delete m_contextWidget; delete m_widget; } @@ -426,6 +435,37 @@ ViewManager::showRecentPlaysPage() } +Tomahawk::ViewPage * +ViewManager::showInboxPage() +{ + if ( !m_inboxWidget ) + { + TrackView* inboxView = new TrackView( m_widget ); + + PlaylistLargeItemDelegate* delegate = + new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::/*Inbox*/LovedTracks, + inboxView, + inboxView->proxyModel() ); + connect( delegate, SIGNAL( updateIndex( QModelIndex ) ), + inboxView, SLOT( update( QModelIndex ) ) ); + inboxView->setItemDelegate( delegate ); + + inboxView->setPlayableModel( m_inboxModel ); + inboxView->setEmptyTip( tr( "No listening suggestions here." ) ); + + inboxView->setGuid( "inbox" ); + + inboxView->proxyModel()->setStyle( PlayableProxyModel::Large ); + inboxView->setSortingEnabled( false ); + inboxView->setHeaderHidden( true ); + + m_inboxWidget = inboxView; + } + + return show( m_inboxWidget ); +} + + void ViewManager::setFilter( const QString& filter ) { @@ -806,9 +846,21 @@ ViewManager::recentPlaysWidget() const return m_recentPlaysWidget; } +Tomahawk::ViewPage* +ViewManager::inboxWidget() const +{ + return m_inboxWidget; +} + Tomahawk::ViewPage* ViewManager::superCollectionView() const { return m_superCollectionView; } + +InboxModel* +ViewManager::inboxModel() +{ + return m_inboxModel; +} diff --git a/src/libtomahawk/ViewManager.h b/src/libtomahawk/ViewManager.h index 7d0346700..0b890733b 100644 --- a/src/libtomahawk/ViewManager.h +++ b/src/libtomahawk/ViewManager.h @@ -55,6 +55,7 @@ class NewReleasesWidget; class WelcomeWidget; class WhatsHotWidget; class QPushButton; +class InboxModel; namespace Tomahawk { @@ -92,6 +93,9 @@ public: Tomahawk::ViewPage* newReleasesWidget() const; Tomahawk::ViewPage* recentPlaysWidget() const; Tomahawk::ViewPage* superCollectionView() const; + Tomahawk::ViewPage* inboxWidget() const; + + InboxModel* inboxModel(); /// Get the view page for the given item. Not pretty... Tomahawk::ViewPage* pageForPlaylist( const Tomahawk::playlist_ptr& pl ) const; @@ -130,6 +134,7 @@ public slots: Tomahawk::ViewPage* showWhatsHotPage(); Tomahawk::ViewPage* showNewReleasesPage(); Tomahawk::ViewPage* showRecentPlaysPage(); + Tomahawk::ViewPage* showInboxPage(); void showCurrentTrack(); // Returns the shown viewpage @@ -181,6 +186,8 @@ private: WhatsHotWidget* m_whatsHotWidget; NewReleasesWidget* m_newReleasesWidget; Tomahawk::ViewPage* m_recentPlaysWidget; + Tomahawk::ViewPage* m_inboxWidget; + InboxModel* m_inboxModel; QList< Tomahawk::collection_ptr > m_superCollections; diff --git a/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp b/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp new file mode 100644 index 000000000..18cacf101 --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp @@ -0,0 +1,97 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "DatabaseCommand_ShareTrack.h" + +#include "Artist.h" +#include "Database.h" +#include "DatabaseImpl.h" +#include "network/Servent.h" +#include "ViewManager.h" +#include "playlist/InboxModel.h" + +DatabaseCommand_ShareTrack::DatabaseCommand_ShareTrack( QObject* parent ) + : DatabaseCommandLoggable( parent ) +{} + + +DatabaseCommand_ShareTrack::DatabaseCommand_ShareTrack( const Tomahawk::query_ptr& query, + const QString& recipientDbid, + QObject* parent ) + : DatabaseCommandLoggable( parent ) + , m_query( query ) + , m_recipient( recipientDbid ) +{ + setSource( SourceList::instance()->getLocal() ); + + setArtist( query->artist() ); + setTrack( query->track() ); +} + + +DatabaseCommand_ShareTrack::DatabaseCommand_ShareTrack( const Tomahawk::result_ptr& result, + const QString& recipientDbid, + QObject* parent ) + : DatabaseCommandLoggable( parent ) + , m_result( result ) + , m_recipient( recipientDbid ) +{ + setSource( SourceList::instance()->getLocal() ); + + setArtist( result->artist()->name() ); + setTrack( result->track() ); +} + +void +DatabaseCommand_ShareTrack::exec( DatabaseImpl* dbi ) +{ + Q_ASSERT( !source().isNull() ); +} + +void +DatabaseCommand_ShareTrack::postCommitHook() +{ + if ( !m_query.isNull() ) + return; + + if ( source()->isLocal() ) + Servent::instance()->triggerDBSync(); + + QString myDbid = Database::instance()->impl()->dbid(); + QString sourceDbid = source()->userName(); //userName is actually a dbid -_-' + if ( myDbid != m_recipient || sourceDbid == m_recipient ) + return; + + //From here on, everything happens only on the recipient, and only if recipient!=source + if ( !m_result.isNull() && m_query.isNull() ) + { + m_query = m_result->toQuery(); + } + else + { + m_query = Tomahawk::Query::get( m_artist, m_track, QString() ); + } + + if ( m_query.isNull() ) + return; + + QMetaObject::invokeMethod( ViewManager::instance()->inboxModel(), + "appendQuery", + Qt::QueuedConnection, + Q_ARG( const Tomahawk::query_ptr&, m_query ) ); +} diff --git a/src/libtomahawk/database/DatabaseCommand_ShareTrack.h b/src/libtomahawk/database/DatabaseCommand_ShareTrack.h new file mode 100644 index 000000000..ecc351f75 --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_ShareTrack.h @@ -0,0 +1,79 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 DATABASECOMMAND_SHARETRACK_H +#define DATABASECOMMAND_SHARETRACK_H + +#include +#include + +#include "database/DatabaseCommandLoggable.h" +#include "SourceList.h" +#include "Typedefs.h" + +#include "DllMacro.h" + +class DatabaseCommand_ShareTrack : public DatabaseCommandLoggable +{ + Q_OBJECT + Q_PROPERTY( QString artist READ artist WRITE setArtist ) + Q_PROPERTY( QString track READ track WRITE setTrack ) + Q_PROPERTY( QString recipient READ recipient WRITE setRecipient ) + +public: + explicit DatabaseCommand_ShareTrack( QObject* parent = 0 ); + + explicit DatabaseCommand_ShareTrack( const Tomahawk::query_ptr& query, + const QString& recipientDbid, + QObject* parent = 0 ); + + explicit DatabaseCommand_ShareTrack( const Tomahawk::result_ptr& result, + const QString& recipientDbid, + QObject* parent = 0 ); + + //TODO: construct from result instead? + + virtual QString commandname() const { return "sharetrack"; } + + virtual void exec( DatabaseImpl* ); + virtual void postCommitHook(); + + virtual bool doesMutates() const { return false; } + virtual bool singletonCmd() const { return false; } + virtual bool localOnly() const { return false; } + virtual bool groupable() const { return true; } + + QString artist() const { return m_artist; } + void setArtist( const QString& s ) { m_artist = s; } + + QString track() const { return m_track; } + void setTrack( const QString& s ) { m_track = s; } + + QString recipient() const { return m_recipient; } + void setRecipient( const QString& s ) { m_recipient = s; } + +private: + Tomahawk::query_ptr m_query; + Tomahawk::result_ptr m_result; + + QString m_artist; + QString m_track; + QString m_recipient; +}; + +#endif // DATABASECOMMAND_SHARETRACK_H diff --git a/src/libtomahawk/playlist/InboxModel.cpp b/src/libtomahawk/playlist/InboxModel.cpp new file mode 100644 index 000000000..56ebe44fe --- /dev/null +++ b/src/libtomahawk/playlist/InboxModel.cpp @@ -0,0 +1,27 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "InboxModel.h" + +InboxModel::InboxModel( QObject* parent ) + : PlaylistModel( parent ) +{ +} + +InboxModel::~InboxModel() +{} diff --git a/src/libtomahawk/playlist/InboxModel.h b/src/libtomahawk/playlist/InboxModel.h new file mode 100644 index 000000000..0a9d50249 --- /dev/null +++ b/src/libtomahawk/playlist/InboxModel.h @@ -0,0 +1,39 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 INBOXMODEL_H +#define INBOXMODEL_H + +#include "PlaylistModel.h" +#include "Typedefs.h" +#include "DllMacro.h" + +class DLLEXPORT InboxModel : public PlaylistModel +{ + Q_OBJECT +public: + explicit InboxModel( QObject* parent = 0 ); + virtual ~InboxModel(); + +signals: + +public slots: + +}; + +#endif // INBOXMODEL_H diff --git a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.h b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.h index eb6cf7e54..a5c24d8e1 100644 --- a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.h +++ b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.h @@ -41,7 +41,7 @@ Q_OBJECT public: enum DisplayMode - { LovedTracks, RecentlyPlayed, LatestAdditions }; + { LovedTracks, RecentlyPlayed, LatestAdditions, Inbox }; PlaylistLargeItemDelegate( DisplayMode mode, TrackView* parent = 0, PlayableProxyModel* proxy = 0 ); diff --git a/src/libtomahawk/utils/TomahawkUtils.h b/src/libtomahawk/utils/TomahawkUtils.h index edd84ec9d..c2528c074 100644 --- a/src/libtomahawk/utils/TomahawkUtils.h +++ b/src/libtomahawk/utils/TomahawkUtils.h @@ -121,6 +121,7 @@ namespace TomahawkUtils SipPluginOnline, SipPluginOffline, ResolverBundle, + Inbox, Invalid }; diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.cpp b/src/libtomahawk/utils/TomahawkUtilsGui.cpp index c444e21f0..853d8a344 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.cpp +++ b/src/libtomahawk/utils/TomahawkUtilsGui.cpp @@ -711,6 +711,10 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size ) pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/drop-all-songs.svg", size ); break; + case Inbox: + pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/downloading.svg", size ); + break; + default: break; } diff --git a/src/sourcetree/SourcesModel.cpp b/src/sourcetree/SourcesModel.cpp index 6dfb0696d..fbda25521 100644 --- a/src/sourcetree/SourcesModel.cpp +++ b/src/sourcetree/SourcesModel.cpp @@ -326,6 +326,11 @@ SourcesModel::appendGroups() boost::bind( &ViewManager::newReleasesWidget, ViewManager::instance() ) ); newReleases->setSortValue( 5 ); + GenericPageItem* inbox = new GenericPageItem( this, browse, tr( "Inbox" ), ImageRegistry::instance()->icon( RESPATH "images/downloading.svg" ), + boost::bind( &ViewManager::showInboxPage, ViewManager::instance() ), + boost::bind( &ViewManager::inboxWidget, ViewManager::instance() ) ); + inbox->setSortValue( 6 ); + m_collectionsGroup = new GroupItem( this, m_rootItem, tr( "Friends" ), 4 ); m_cloudGroup = new GroupItem( this, m_rootItem, tr( "Cloud" ), 5 );