diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 6ab1070da..ba70a6c8a 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -44,6 +44,7 @@ set( libGuiSources infobar/InfoBar.cpp playlist/InboxModel.cpp + playlist/InboxView.cpp playlist/FlexibleHeader.cpp playlist/FlexibleView.cpp playlist/TreeModel.cpp @@ -269,6 +270,7 @@ list(APPEND libSources database/DatabaseCommand_SetTrackAttributes.cpp database/DatabaseCommand_PlaybackCharts.cpp database/DatabaseCommand_ShareTrack.cpp + database/DatabaseCommand_DeleteInboxEntry.cpp database/Database.cpp database/TomahawkSqlQuery.cpp database/IdThreadWorker.cpp diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index a616da83e..c5c93023e 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -39,6 +39,7 @@ #include "TomahawkSettings.h" #include "playlist/InboxModel.h" +#include "playlist/InboxView.h" #include "playlist/PlaylistLargeItemDelegate.h" #include "playlist/RecentlyPlayedModel.h" #include "playlist/dynamic/widgets/DynamicWidget.h" @@ -440,7 +441,7 @@ ViewManager::showInboxPage() { if ( !m_inboxWidget ) { - TrackView* inboxView = new TrackView( m_widget ); + TrackView* inboxView = new InboxView( m_widget ); PlaylistLargeItemDelegate* delegate = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::Inbox, diff --git a/src/libtomahawk/database/DatabaseCommand_DeleteInboxEntry.cpp b/src/libtomahawk/database/DatabaseCommand_DeleteInboxEntry.cpp new file mode 100644 index 000000000..6cbfe7267 --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_DeleteInboxEntry.cpp @@ -0,0 +1,60 @@ +/* === 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 "DatabaseCommand_DeleteInboxEntry.h" +#include "DatabaseImpl.h" +#include "Query.h" + + +DatabaseCommand_DeleteInboxEntry::DatabaseCommand_DeleteInboxEntry( const Tomahawk::query_ptr& query, + QObject* parent ) + : DatabaseCommand( parent ) + , m_query( query ) +{ +} + + +void +DatabaseCommand_DeleteInboxEntry::exec( DatabaseImpl* dbi ) +{ + TomahawkSqlQuery query = dbi->newquery(); + + Q_ASSERT( !m_query.isNull() ); + + if ( m_query->track().isEmpty() || m_query->artist().isEmpty() ) + { + emit done(); + return; + } + + query.prepare( + "DELETE FROM social_attributes " + "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( "Inbox" ); + query.addBindValue( m_query->track() ); + query.addBindValue( m_query->artist() ); + + query.exec(); + + emit done(); +} diff --git a/src/libtomahawk/database/DatabaseCommand_DeleteInboxEntry.h b/src/libtomahawk/database/DatabaseCommand_DeleteInboxEntry.h new file mode 100644 index 000000000..c2f3f4b7a --- /dev/null +++ b/src/libtomahawk/database/DatabaseCommand_DeleteInboxEntry.h @@ -0,0 +1,44 @@ +/* === 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 DATABASECOMMAND_DELETEINBOXENTRY_H +#define DATABASECOMMAND_DELETEINBOXENTRY_H + +#include "DatabaseCommand.h" + +class DatabaseCommand_DeleteInboxEntry : public DatabaseCommand +{ + Q_OBJECT +public: + explicit DatabaseCommand_DeleteInboxEntry( const Tomahawk::query_ptr& query, 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 "deleteinboxentry"; } + +signals: + void done(); + +private: + Tomahawk::query_ptr m_query; +}; + +#endif // DATABASECOMMAND_DELETEINBOXENTRY_H diff --git a/src/libtomahawk/playlist/InboxModel.cpp b/src/libtomahawk/playlist/InboxModel.cpp index 03b9d954d..6169144cc 100644 --- a/src/libtomahawk/playlist/InboxModel.cpp +++ b/src/libtomahawk/playlist/InboxModel.cpp @@ -20,6 +20,7 @@ #include "database/Database.h" #include "database/DatabaseCommand_GenericSelect.h" +#include "database/DatabaseCommand_DeleteInboxEntry.h" #include "SourceList.h" #include "utils/Logger.h" #include "utils/Closure.h" @@ -117,6 +118,20 @@ InboxModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int ro } +void +InboxModel::removeIndex( const QModelIndex& index, bool moreToCome ) +{ + PlayableItem* item = itemFromIndex( index ); + if ( item && !item->query().isNull() ) + { + DatabaseCommand_DeleteInboxEntry* cmd = new DatabaseCommand_DeleteInboxEntry( item->query() ); + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + } + + PlaylistModel::removeIndex( index, moreToCome ); +} + + void InboxModel::clear() { diff --git a/src/libtomahawk/playlist/InboxModel.h b/src/libtomahawk/playlist/InboxModel.h index 4ae757725..57c846f7c 100644 --- a/src/libtomahawk/playlist/InboxModel.h +++ b/src/libtomahawk/playlist/InboxModel.h @@ -39,6 +39,8 @@ public slots: */ virtual void insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int row = 0 ); + virtual void removeIndex( const QModelIndex &index, bool moreToCome ); + virtual void clear(); private slots: diff --git a/src/libtomahawk/playlist/InboxView.cpp b/src/libtomahawk/playlist/InboxView.cpp new file mode 100644 index 000000000..83ea65a70 --- /dev/null +++ b/src/libtomahawk/playlist/InboxView.cpp @@ -0,0 +1,38 @@ +/* === 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 "InboxView.h" +#include "InboxModel.h" +#include "PlayableProxyModel.h" + +InboxView::InboxView(QWidget *parent) : + TrackView(parent) +{ +} + + +void +InboxView::deleteSelectedItems() +{ + InboxModel* inboxModel = qobject_cast< InboxModel* >( model() ); + if ( inboxModel != 0 ) + { + proxyModel()->removeIndexes( selectedIndexes() ); + } +} diff --git a/src/libtomahawk/playlist/InboxView.h b/src/libtomahawk/playlist/InboxView.h new file mode 100644 index 000000000..298422b69 --- /dev/null +++ b/src/libtomahawk/playlist/InboxView.h @@ -0,0 +1,38 @@ +/* === 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 INBOXVIEW_H +#define INBOXVIEW_H + +#include "TrackView.h" + +class InboxView : public TrackView +{ + Q_OBJECT +public: + explicit InboxView( QWidget* parent = 0 ); + +public slots: + /** + * Reimplemented in order to ignore PlayableModel::isReadOnly() + */ + virtual void deleteSelectedItems(); +}; + +#endif // INBOXVIEW_H diff --git a/src/libtomahawk/playlist/TrackView.h b/src/libtomahawk/playlist/TrackView.h index c9e091f0b..4991d4662 100644 --- a/src/libtomahawk/playlist/TrackView.h +++ b/src/libtomahawk/playlist/TrackView.h @@ -91,7 +91,7 @@ public: public slots: virtual void onItemActivated( const QModelIndex& index ); - void deleteSelectedItems(); + virtual void deleteSelectedItems(); void playItem(); void onMenuTriggered( int action );