diff --git a/data/images/artistpage-background-tile.png b/data/images/artistpage-background-tile.png deleted file mode 100644 index e3e635823..000000000 Binary files a/data/images/artistpage-background-tile.png and /dev/null differ diff --git a/resource.qrc b/resource.qrc deleted file mode 100644 index e69de29bb..000000000 diff --git a/resources.qrc b/resources.qrc index b853e65a3..31c2acd60 100644 --- a/resources.qrc +++ b/resources.qrc @@ -148,6 +148,7 @@ data/images/jump-link.png data/images/scrollbar-vertical-handle.png data/images/scrollbar-horizontal-handle.png - data/images/playlist-subscribed.png + data/images/subscribe-on.png + data/images/subscribe-off.png diff --git a/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h b/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h index b5de8e4b9..3345a8c4b 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h +++ b/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h @@ -2,7 +2,7 @@ * * Copyright 2010-2012, Leo Franchi * Copyright 2012, Hugo Lindström - * + * * 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 @@ -74,7 +74,7 @@ public slots: void tomahawkPlaylistRenamed( const QString&, const QString& ); void aboutToDelete(); - + private slots: // SpotifyResolver message handlers, all take msgtype, msg as argument void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg, const QVariant& extraData ); diff --git a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h index 79c582d89..a58feb0f1 100644 --- a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h +++ b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h @@ -78,7 +78,11 @@ public: static void registerUpdaterFactory( PlaylistUpdaterFactory* f ); virtual bool sync() const { return false; } + virtual void setSync( bool ) {} + + virtual bool canSubscribe() const { return false; } virtual bool subscribed() const { return false; } + virtual void setSubscribed( bool ) {} signals: void changed(); diff --git a/src/libtomahawk/playlist/XspfUpdater.cpp b/src/libtomahawk/playlist/XspfUpdater.cpp index 879184ba2..585707c9c 100644 --- a/src/libtomahawk/playlist/XspfUpdater.cpp +++ b/src/libtomahawk/playlist/XspfUpdater.cpp @@ -144,6 +144,8 @@ XspfUpdater::setAutoUpdate( bool autoUpdate ) // Update immediately as well if ( m_autoUpdate ) QTimer::singleShot( 0, this, SLOT( updateNow() ) ); + + emit changed(); } void @@ -158,3 +160,10 @@ XspfUpdater::setInterval( int intervalMsecs ) m_timer->setInterval( intervalMsecs ); } + + +void +XspfUpdater::setSubscribed( bool subscribed ) +{ + setAutoUpdate( subscribed ); +} diff --git a/src/libtomahawk/playlist/XspfUpdater.h b/src/libtomahawk/playlist/XspfUpdater.h index c83efd18b..6cff1d875 100644 --- a/src/libtomahawk/playlist/XspfUpdater.h +++ b/src/libtomahawk/playlist/XspfUpdater.h @@ -48,7 +48,9 @@ public: void setInterval( int intervalMsecs ) ; int intervalMsecs() const { return m_timer->interval(); } - bool subscribed() const { return true; } + bool canSubscribe() const { return true; } + bool subscribed() const { return m_autoUpdate; } + void setSubscribed( bool subscribed ); public slots: void updateNow(); diff --git a/src/sourcetree/SourceDelegate.cpp b/src/sourcetree/SourceDelegate.cpp index 0548b2870..233fb15c2 100644 --- a/src/sourcetree/SourceDelegate.cpp +++ b/src/sourcetree/SourceDelegate.cpp @@ -554,7 +554,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co QStyledItemDelegate::paint( painter, o, index ); PlaylistItem* plItem = qobject_cast< PlaylistItem* >( item ); - if ( plItem->subscribed() && !plItem->subscribedIcon().isNull() ) + if ( plItem->canSubscribe() && !plItem->subscribedIcon().isNull() ) { const int padding = 2; const int imgWidth = o.rect.height() - 2*padding; @@ -655,10 +655,29 @@ SourceDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt } } } + else if ( event->type() == QEvent::MouseButtonRelease && type == SourcesModel::StaticPlaylist ) + { + PlaylistItem* plItem = qobject_cast< PlaylistItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() ); + Q_ASSERT( plItem ); + + QMouseEvent* mev = static_cast< QMouseEvent* >( event ); + if ( plItem->canSubscribe() && !plItem->subscribedIcon().isNull() ) + { + const int padding = 2; + const int imgWidth = option.rect.height() - 2*padding; + const QRect subRect( option.rect.right() - padding - imgWidth, option.rect.top() + padding, imgWidth, imgWidth ); + + if ( subRect.contains( mev->pos() ) ) + { + // Toggle playlist subscription + plItem->setSubscribed( !plItem->subscribed() ); + } + } + } } // We emit our own clicked() signal instead of relying on QTreeView's, because that is fired whether or not a delegate accepts - // a mouse press event. Since we want to swallow click events when they are on headphones other action items, here wemake sure we only + // a mouse press event. Since we want to swallow click events when they are on headphones other action items, here we make sure we only // emit if we really want to if ( event->type() == QEvent::MouseButtonRelease ) { diff --git a/src/sourcetree/items/PlaylistItems.cpp b/src/sourcetree/items/PlaylistItems.cpp index 5925bdcda..c36313796 100644 --- a/src/sourcetree/items/PlaylistItems.cpp +++ b/src/sourcetree/items/PlaylistItems.cpp @@ -40,6 +40,8 @@ using namespace Tomahawk; PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const playlist_ptr& pl, int index ) : SourceTreeItem( mdl, parent, SourcesModel::StaticPlaylist, index ) , m_loaded( false ) + , m_canSubscribe( false ) + , m_showSubscribed( false ) , m_playlist( pl ) { connect( pl.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), @@ -293,18 +295,22 @@ PlaylistItem::createOverlay() if ( m_playlist->updaters().isEmpty() ) return false; - m_showSubscribed = false; + m_showSubscribed = false; + m_canSubscribe = false; foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() ) { - if ( updater->subscribed() ) + if ( updater->canSubscribe() ) { - m_showSubscribed = true; + m_canSubscribe = true; + m_showSubscribed = updater->subscribed(); break; } } - if ( m_showSubscribed && m_subscribedIcon.isNull() ) - m_subscribedIcon = QPixmap( RESPATH "images/playlist-subscribed.png" ); + if ( m_canSubscribe && m_showSubscribed && m_subscribedOnIcon.isNull() ) + m_subscribedOnIcon = QPixmap( RESPATH "images/subscribe-on.png" ); + else if ( m_canSubscribe && !m_showSubscribed && m_subscribedOffIcon.isNull() ) + m_subscribedOffIcon = QPixmap( RESPATH "images/subscribe-off.png" ); QList< QPixmap > icons; foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() ) @@ -313,6 +319,9 @@ PlaylistItem::createOverlay() icons << updater->typeIcon(); } + m_overlaidIcon = QIcon(); + m_overlaidUpdaters = m_playlist->updaters(); + if ( icons.isEmpty() ) return false; @@ -321,8 +330,6 @@ PlaylistItem::createOverlay() if ( icons.size() > 2 ) icons = icons.mid( 0, 2 ); - m_overlaidIcon = QIcon(); - m_overlaidUpdaters = m_playlist->updaters(); QPixmap base = m_icon.pixmap( 48, 48 ); QPainter p( &base ); @@ -384,6 +391,27 @@ PlaylistItem::activateCurrent() } +void +PlaylistItem::setSubscribed( bool subscribed ) +{ + Q_ASSERT( !m_overlaidUpdaters.isEmpty() ); + if ( m_overlaidUpdaters.isEmpty() ) + { + qWarning() << "NO playlist updater but got a toggle subscribed action on the playlist item!?"; + return; + } + else if ( m_overlaidUpdaters.size() > 1 ) + { + qWarning() << "Got TWO subscribed updaters at the same time? Toggling both... wtf"; + } + + foreach( PlaylistUpdaterInterface* updater, m_overlaidUpdaters ) + { + updater->setSubscribed( subscribed ); + } +} + + DynamicPlaylistItem::DynamicPlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const dynplaylist_ptr& pl, int index ) : PlaylistItem( mdl, parent, pl.staticCast< Playlist >(), index ) , m_dynplaylist( pl ) diff --git a/src/sourcetree/items/PlaylistItems.h b/src/sourcetree/items/PlaylistItems.h index f5d1b34c3..e1bc3ea6e 100644 --- a/src/sourcetree/items/PlaylistItems.h +++ b/src/sourcetree/items/PlaylistItems.h @@ -42,9 +42,11 @@ public: virtual SourceTreeItem* activateCurrent(); + // subscription management + bool canSubscribe() const { return m_canSubscribe; } bool subscribed() const { return m_showSubscribed; } - QPixmap subscribedIcon() const { return m_subscribedIcon; } - QList< QAction* > subscribedActions() const; + QPixmap subscribedIcon() const { return m_showSubscribed ? m_subscribedOnIcon : m_subscribedOffIcon; } + void setSubscribed( bool subscribed ); public slots: virtual void activate(); @@ -62,10 +64,10 @@ private slots: private: bool createOverlay(); - bool m_loaded, m_showSubscribed; + bool m_loaded, m_canSubscribe, m_showSubscribed; Tomahawk::playlist_ptr m_playlist; QIcon m_icon, m_overlaidIcon; - QPixmap m_subscribedIcon; + QPixmap m_subscribedOnIcon, m_subscribedOffIcon; QList m_overlaidUpdaters; }; Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::DropTypes)