diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index fb39d0ef9..269697d04 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -274,6 +274,7 @@ list(APPEND libSources database/DatabaseCommand_PlaybackCharts.cpp database/DatabaseCommand_ShareTrack.cpp database/DatabaseCommand_DeleteInboxEntry.cpp + database/DatabaseCommand_ModifyInboxEntry.cpp database/Database.cpp database/TomahawkSqlQuery.cpp database/IdThreadWorker.cpp diff --git a/src/libtomahawk/database/DatabaseCommand_ModifyInboxEntry.cpp b/src/libtomahawk/database/DatabaseCommand_ModifyInboxEntry.cpp new file mode 100644 index 000000000..5055e7183 --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_ModifyInboxEntry.cpp @@ -0,0 +1,64 @@ +/* === 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_ModifyInboxEntry.h" +#include "DatabaseImpl.h" +#include "Query.h" + + +DatabaseCommand_ModifyInboxEntry::DatabaseCommand_ModifyInboxEntry( const Tomahawk::query_ptr& query, + bool newValue, + QObject* parent ) + : DatabaseCommand( parent ) + , m_query( query ) + , m_newValue( newValue ) +{ +} + + +void +DatabaseCommand_ModifyInboxEntry::exec( DatabaseImpl* dbi ) +{ + TomahawkSqlQuery query = dbi->newquery(); + + Q_ASSERT( !m_query.isNull() ); + + if ( m_query->queryTrack()->track().isEmpty() || m_query->queryTrack()->artist().isEmpty() ) + { + emit done(); + return; + } + + query.prepare( + "UPDATE social_attributes " + "SET v = ? " + "WHERE social_attributes.k = ? AND social_attributes.id = ( " + "SELECT id FROM track " + "WHERE track.name = ? AND track.artist = ( " + "SELECT id FROM artist WHERE artist.name = ? " + ") " + ")" ); + query.addBindValue( m_newValue ); + query.addBindValue( "Inbox" ); + query.addBindValue( m_query->queryTrack()->track() ); + query.addBindValue( m_query->queryTrack()->artist() ); + + query.exec(); + + emit done(); +} diff --git a/src/libtomahawk/database/DatabaseCommand_ModifyInboxEntry.h b/src/libtomahawk/database/DatabaseCommand_ModifyInboxEntry.h new file mode 100644 index 000000000..e8690ce03 --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_ModifyInboxEntry.h @@ -0,0 +1,44 @@ +/* === 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_MODIFYINBOXENTRY_H +#define DATABASECOMMAND_MODIFYINBOXENTRY_H + +#include "DatabaseCommand.h" + +class DatabaseCommand_ModifyInboxEntry : public DatabaseCommand +{ + Q_OBJECT +public: + explicit DatabaseCommand_ModifyInboxEntry( const Tomahawk::query_ptr& query, bool newValue, QObject *parent = 0 ); + + virtual void exec( DatabaseImpl* dbi ); + virtual bool doesMutates() const { return true; } + virtual bool groupable() const { return true; } + virtual bool localOnly() const { return true; } + virtual QString commandname() const { return "modifyinboxentry"; } + +signals: + void done(); + +private: + Tomahawk::query_ptr m_query; + bool m_newValue; +}; + +#endif // DATABASECOMMAND_MODIFYINBOXENTRY_H diff --git a/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp b/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp index a47010c1e..efca81086 100644 --- a/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp +++ b/src/libtomahawk/database/DatabaseCommand_ShareTrack.cpp @@ -90,7 +90,7 @@ DatabaseCommand_ShareTrack::postCommitHook() action.value = true; //unlistened action.timestamp = timestamp(); - QList< Tomahawk::SocialAction > actions; + QList< Tomahawk::SocialAction > actions = m_track->allSocialActions(); actions << action; m_track->setAllSocialActions( actions ); diff --git a/src/libtomahawk/playlist/InboxModel.cpp b/src/libtomahawk/playlist/InboxModel.cpp index e480d9bdc..8d3edf0fd 100644 --- a/src/libtomahawk/playlist/InboxModel.cpp +++ b/src/libtomahawk/playlist/InboxModel.cpp @@ -21,6 +21,7 @@ #include "database/Database.h" #include "database/DatabaseCommand_GenericSelect.h" #include "database/DatabaseCommand_DeleteInboxEntry.h" +#include "database/DatabaseCommand_ModifyInboxEntry.h" #include "SourceList.h" #include "utils/Logger.h" #include "utils/Closure.h" @@ -34,6 +35,9 @@ InboxModel::InboxModel( QObject* parent ) else NewClosure( SourceList::instance(), SIGNAL( ready() ), this, SLOT( loadTracks() ) ); + + connect( this, SIGNAL( currentIndexChanged() ), + SLOT( onCurrentIndexChanged() ) ); } @@ -44,28 +48,28 @@ InboxModel::~InboxModel() QList InboxModel::mergeSocialActions( QList first, QList second) { - foreach ( Tomahawk::SocialAction sa, second ) + foreach ( Tomahawk::SocialAction saInSecond, second ) { - if ( sa.action != "Inbox" ) + if ( saInSecond.action != "Inbox" ) { - first.append( sa ); + first.append( saInSecond ); continue; } bool contains = false; for ( int i = 0; i < first.count(); ++i ) { - Tomahawk::SocialAction &sb = first[ i ]; - if ( sa.source == sb.source ) + Tomahawk::SocialAction &saInFirst = first[ i ]; + if ( saInSecond.source == saInFirst.source ) { - sb.timestamp = qMax( sa.timestamp.toInt(), sb.timestamp.toInt() ); - sb.value = sa.value.toBool() && sb.value.toBool(); + saInFirst.timestamp = qMax( saInSecond.timestamp.toInt(), saInFirst.timestamp.toInt() ); + saInFirst.value = saInFirst.value.toBool() && saInSecond.value.toBool(); contains = true; break; } } if ( !contains ) - first.append( sa ); + first.append( saInSecond ); } return first; } @@ -88,8 +92,8 @@ InboxModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int ro if ( entry->query()->equals( existingEntry->query(), true /*ignoreCase*/) ) { //We got a dupe, let's merge the social actions - entry->query()->track()->setAllSocialActions( mergeSocialActions( existingEntry->query()->track()->allSocialActions(), - entry->query()->track()->allSocialActions() ) ); + entry->query()->queryTrack()->setAllSocialActions( mergeSocialActions( existingEntry->query()->queryTrack()->allSocialActions(), + entry->query()->queryTrack()->allSocialActions() ) ); toInsert.erase( jt ); break; } @@ -103,8 +107,8 @@ InboxModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int ro { if ( plEntry->query()->equals( toInsert.at( i )->query(), true ) ) { - plEntry->query()->track()->setAllSocialActions( mergeSocialActions( plEntry->query()->track()->allSocialActions(), - toInsert.at( i )->query()->track()->allSocialActions() ) ); + plEntry->query()->queryTrack()->setAllSocialActions( mergeSocialActions( plEntry->query()->queryTrack()->allSocialActions(), + toInsert.at( i )->query()->queryTrack()->allSocialActions() ) ); toInsert.removeAt( i ); dataChanged( index( playlistEntries().indexOf( plEntry ), 0, QModelIndex() ), @@ -189,7 +193,7 @@ InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > incoming ) QList< Tomahawk::SocialAction > actions; actions << action; - newQuery->track()->setAllSocialActions( actions ); + newQuery->queryTrack()->setAllSocialActions( actions ); newQuery->setProperty( "data", QVariant() ); //clear } @@ -206,3 +210,31 @@ InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > incoming ) } } + +void +InboxModel::onCurrentIndexChanged() +{ + QPersistentModelIndex idx = currentItem(); + if ( idx.isValid() ) + { + PlayableItem* item = itemFromIndex( idx ); + if ( item && !item->query().isNull() ) + { + Tomahawk::query_ptr qry = item->query(); + DatabaseCommand_ModifyInboxEntry* cmd = new DatabaseCommand_ModifyInboxEntry( qry, false ); + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + + QList< Tomahawk::SocialAction > actions = item->query()->queryTrack()->allSocialActions(); + for ( QList< Tomahawk::SocialAction >::iterator it = actions.begin(); + it != actions.end(); ++it ) + { + if ( it->action == "Inbox" ) + { + it->value = false; //listened! + } + } + item->query()->queryTrack()->setAllSocialActions( actions ); + } + } +} + diff --git a/src/libtomahawk/playlist/InboxModel.h b/src/libtomahawk/playlist/InboxModel.h index 605d82d8e..46284f49d 100644 --- a/src/libtomahawk/playlist/InboxModel.h +++ b/src/libtomahawk/playlist/InboxModel.h @@ -47,6 +47,7 @@ private slots: void loadTracks(); void tracksLoaded( QList< Tomahawk::query_ptr > ); + void onCurrentIndexChanged(); private: static QList< Tomahawk::SocialAction > mergeSocialActions( QList< Tomahawk::SocialAction > first, diff --git a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp index 216e77147..6a97b7c28 100644 --- a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp @@ -125,7 +125,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& if ( isUnlistened && ! item->isPlaying() ) { prepareStyleOption( &opt, index, item ); - opt.backgroundBrush = QColor( Qt::yellow ).lighter( 190 ); + opt.backgroundBrush = QColor( Qt::yellow ).lighter( 185 ); } else prepareStyleOption( &opt, index, item );