From 0cf6c18de4a830fa21d0407f7da65ee640c7f5df Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Wed, 17 Oct 2007 14:11:45 +0200 Subject: [PATCH] Implement removing of items in the Playlist --- lib/playlistmodel.cpp | 21 +++++++++++++++++++++ lib/playlistmodel.h | 2 ++ src/Playlist.cpp | 6 +++++- src/PlaylistView.cpp | 16 ++++++++++++++-- src/PlaylistView.h | 2 ++ 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/playlistmodel.cpp b/lib/playlistmodel.cpp index 42df036..57e6121 100644 --- a/lib/playlistmodel.cpp +++ b/lib/playlistmodel.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -514,3 +515,23 @@ PlaylistModel::get_all_id () { return m_plist; } + +void +PlaylistModel::removeRows (QModelIndexList index_list) +{ + QList idlist; + + for (int i = 0; i < index_list.size (); ++i) { + QModelIndex idx = index_list.at(i); + if (idx.column () != 0) + continue; + + idlist.append (idx.row ()); + } + qSort (idlist); + + /* Update of m_plist is done in handle_change through server notification */ + for (int i = idlist.size () - 1; i >= 0; --i){ + m_client->playlist ()->removeEntry (idlist.at(i)); + } +} diff --git a/lib/playlistmodel.h b/lib/playlistmodel.h index d4f6860..1bfbf17 100644 --- a/lib/playlistmodel.h +++ b/lib/playlistmodel.h @@ -111,6 +111,8 @@ class PlaylistModel : public QAbstractItemModel void set_playlist (const QString &); + void removeRows (QModelIndexList); + protected: XClient *m_client; QList < unsigned int > m_plist; diff --git a/src/Playlist.cpp b/src/Playlist.cpp index 5ce1ff6..174e5af 100644 --- a/src/Playlist.cpp +++ b/src/Playlist.cpp @@ -359,12 +359,16 @@ PlaylistWidget::addButtons (void) Skin::PLS_MSC_BTN_1); b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_ALL_0, Skin::PLS_DEL_ALL_1); - connect (b, SIGNAL(activated ()), + connect (b, SIGNAL (activated ()), &XMMSHandler::getInstance(), SLOT (playlistClear ())); b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_CRP_0, Skin::PLS_DEL_CRP_1); + connect (b, SIGNAL (activated ()), + m_view, SLOT (cropSelected ())); b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_FIL_0, Skin::PLS_DEL_FIL_1); + connect (b, SIGNAL (activated ()), + m_view, SLOT (removeSelected ())); // connect (b, SIGNAL(activated ()), m_list, SLOT (deleteFiles ())); /* Selection menu */ diff --git a/src/PlaylistView.cpp b/src/PlaylistView.cpp index 44a4c5b..3736732 100644 --- a/src/PlaylistView.cpp +++ b/src/PlaylistView.cpp @@ -1,4 +1,4 @@ -// TODO might not need those +// TODO might not need those two #include #include "XMMSHandler.h" @@ -119,6 +119,18 @@ PlaylistView::invertSelection () { QItemSelectionModel::NoUpdate); } +void +PlaylistView::cropSelected () { + invertSelection (); + removeSelected (); + selectAll (); +} + +void +PlaylistView::removeSelected () { + qobject_cast (model ())->removeRows (selectedIndexes ()); +} + void PlaylistView::setModel (QAbstractItemModel *model) { QListView::setModel (model); @@ -144,6 +156,7 @@ PlaylistView::contextMenuEvent (QContextMenuEvent *e) qm.addAction (a); a = new QAction (tr ("Remove selected"), this); + connect (a, SIGNAL (triggered ()), this, SLOT (removeSelected ())); qm.addAction (a); qm.addSeparator (); @@ -222,7 +235,6 @@ PlaylistView::mouseDoubleClickEvent (QMouseEvent *event) XMMSHandler &xmmsh = XMMSHandler::getInstance (); xmmsh.requestTrackChange (index.row()); - // TODO check for status first. if (m_status == XMMS_PLAYBACK_STATUS_STOP || m_status == XMMS_PLAYBACK_STATUS_PAUSE) { xmmsh.play (); diff --git a/src/PlaylistView.h b/src/PlaylistView.h index daed5cc..b40b727 100644 --- a/src/PlaylistView.h +++ b/src/PlaylistView.h @@ -38,6 +38,8 @@ class PlaylistView : public QListView { void handleStatus (const Xmms::Playback::Status st); void invertSelection (void); + void cropSelected (void); + void removeSelected (void); void settingsSaved (void); void setPixmaps (Skin *skin);