Implement removing of items in the Playlist

This commit is contained in:
Thomas Frauendorfer 2007-10-17 14:11:45 +02:00
parent eef3e53bd9
commit 0cf6c18de4
5 changed files with 44 additions and 3 deletions

View file

@ -19,6 +19,7 @@
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QHash> #include <QHash>
#include <QVariant> #include <QVariant>
#include <QIcon>
#include <QMimeData> #include <QMimeData>
#include <QSettings> #include <QSettings>
#include <QUrl> #include <QUrl>
@ -514,3 +515,23 @@ PlaylistModel::get_all_id ()
{ {
return m_plist; return m_plist;
} }
void
PlaylistModel::removeRows (QModelIndexList index_list)
{
QList<uint32_t> 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));
}
}

View file

@ -111,6 +111,8 @@ class PlaylistModel : public QAbstractItemModel
void set_playlist (const QString &); void set_playlist (const QString &);
void removeRows (QModelIndexList);
protected: protected:
XClient *m_client; XClient *m_client;
QList < unsigned int > m_plist; QList < unsigned int > m_plist;

View file

@ -359,12 +359,16 @@ PlaylistWidget::addButtons (void)
Skin::PLS_MSC_BTN_1); Skin::PLS_MSC_BTN_1);
b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_ALL_0, b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_ALL_0,
Skin::PLS_DEL_ALL_1); Skin::PLS_DEL_ALL_1);
connect (b, SIGNAL(activated ()), connect (b, SIGNAL (activated ()),
&XMMSHandler::getInstance(), SLOT (playlistClear ())); &XMMSHandler::getInstance(), SLOT (playlistClear ()));
b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_CRP_0, b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_CRP_0,
Skin::PLS_DEL_CRP_1); Skin::PLS_DEL_CRP_1);
connect (b, SIGNAL (activated ()),
m_view, SLOT (cropSelected ()));
b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_FIL_0, b = new PlaylistMenuButton (m_del, Skin::PLS_DEL_FIL_0,
Skin::PLS_DEL_FIL_1); Skin::PLS_DEL_FIL_1);
connect (b, SIGNAL (activated ()),
m_view, SLOT (removeSelected ()));
// connect (b, SIGNAL(activated ()), m_list, SLOT (deleteFiles ())); // connect (b, SIGNAL(activated ()), m_list, SLOT (deleteFiles ()));
/* Selection menu */ /* Selection menu */

View file

@ -1,4 +1,4 @@
// TODO might not need those // TODO might not need those two
#include <xmmsclient/xmmsclient++.h> #include <xmmsclient/xmmsclient++.h>
#include "XMMSHandler.h" #include "XMMSHandler.h"
@ -119,6 +119,18 @@ PlaylistView::invertSelection () {
QItemSelectionModel::NoUpdate); QItemSelectionModel::NoUpdate);
} }
void
PlaylistView::cropSelected () {
invertSelection ();
removeSelected ();
selectAll ();
}
void
PlaylistView::removeSelected () {
qobject_cast<PlaylistModel *> (model ())->removeRows (selectedIndexes ());
}
void void
PlaylistView::setModel (QAbstractItemModel *model) { PlaylistView::setModel (QAbstractItemModel *model) {
QListView::setModel (model); QListView::setModel (model);
@ -144,6 +156,7 @@ PlaylistView::contextMenuEvent (QContextMenuEvent *e)
qm.addAction (a); qm.addAction (a);
a = new QAction (tr ("Remove selected"), this); a = new QAction (tr ("Remove selected"), this);
connect (a, SIGNAL (triggered ()), this, SLOT (removeSelected ()));
qm.addAction (a); qm.addAction (a);
qm.addSeparator (); qm.addSeparator ();
@ -222,7 +235,6 @@ PlaylistView::mouseDoubleClickEvent (QMouseEvent *event)
XMMSHandler &xmmsh = XMMSHandler::getInstance (); XMMSHandler &xmmsh = XMMSHandler::getInstance ();
xmmsh.requestTrackChange (index.row()); xmmsh.requestTrackChange (index.row());
// TODO check for status first.
if (m_status == XMMS_PLAYBACK_STATUS_STOP || if (m_status == XMMS_PLAYBACK_STATUS_STOP ||
m_status == XMMS_PLAYBACK_STATUS_PAUSE) { m_status == XMMS_PLAYBACK_STATUS_PAUSE) {
xmmsh.play (); xmmsh.play ();

View file

@ -38,6 +38,8 @@ class PlaylistView : public QListView {
void handleStatus (const Xmms::Playback::Status st); void handleStatus (const Xmms::Playback::Status st);
void invertSelection (void); void invertSelection (void);
void cropSelected (void);
void removeSelected (void);
void settingsSaved (void); void settingsSaved (void);
void setPixmaps (Skin *skin); void setPixmaps (Skin *skin);