Implement creation, deletion and switching of playlists (Idlists)

This commit is contained in:
Thomas Frauendorfer 2008-02-08 14:36:30 +01:00
parent 0da2995880
commit d93f2ee188
14 changed files with 517 additions and 3 deletions

8
src/dialogs/dialogs.pri Normal file
View file

@ -0,0 +1,8 @@
HEADERS += playlistchooser.h
SOURCES += playlistchooser.cpp
FORMS += playlistchooser.ui
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD

View file

@ -0,0 +1,132 @@
/**
* This file is a part of Promoe, an XMMS2 client
*
* Copyright (C) 2008 Thomas Frauendorfer
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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.
*/
// FIXME: because somewhere something with the includes is wrons, this line
// is needed
#include "XMMSHandler.h"
#include <QRegExp>
#include <QStringList>
#include <QList>
#include <QListWidgetItem>
#include "playlistchooser.h"
#include "xcollection.h"
PlaylistChooser::PlaylistChooser (QWidget *parent, XCollection *coll)
: QDialog (parent)
{
setupUi (this);
setAttribute (Qt::WA_DeleteOnClose);
m_collection = coll;
// FIXME: implement creation of new Playlists
// playlistCreateButton->setEnabled (false);
// playlistRemoveButton->setEnabled (false);
// fill the List with Playlistnames.
// Sort out playlists that start with '_'
QRegExp regex = QRegExp ("^[^_]");
QStringList lists = coll->list ("Playlists").filter (regex);
playlistsListWidget->setSortingEnabled (true);
playlistsListWidget->addItems (lists);
connect (coll, SIGNAL (collectionModified (QString, QString, int, QString)),
this, SLOT (handle_playlists_modified (QString, QString, int,
QString)));
}
void
PlaylistChooser::handle_playlists_modified (QString name, QString ns,
int type, QString newname)
{
if (ns != "Playlists") {
return;
}
switch (type) {
case XMMS_COLLECTION_CHANGED_ADD:
if (!name.startsWith("_")) {
playlistsListWidget->addItem(name);
}
break;
case XMMS_COLLECTION_CHANGED_REMOVE: {
QList<QListWidgetItem *> list
= playlistsListWidget->findItems (name, Qt::MatchExactly);
if (!list.empty ()) {
// we should only have one exatly matching String
QListWidgetItem* item = list.first ();
int idx = playlistsListWidget->row (item);
item = playlistsListWidget->takeItem (idx);
delete item;
}
}
break;
case XMMS_COLLECTION_CHANGED_RENAME: {
// remove the old entry
QList<QListWidgetItem *> list
= playlistsListWidget->findItems (name, Qt::MatchExactly);
if (!list.empty ()) {
// we should only have one exatly matching String
QListWidgetItem* item = list.first ();
int idx = playlistsListWidget->row (item);
item = playlistsListWidget->takeItem (idx);
delete item;
}
// and add the new one
if (!newname.startsWith("_")) {
playlistsListWidget->addItem(newname);
}
}
break;
default:
break;
}
}
void
PlaylistChooser::on_playlistCreateButton_clicked ()
{
QString name = playlistTextEdit->text ();
// only create new playlist, if it doesn't already exist
if (m_collection->list ("Playlists").contains (name)) return;
m_collection->addIdlist (name);
}
void
PlaylistChooser::on_playlistRemoveButton_clicked ()
{
QList<QListWidgetItem *> list = playlistsListWidget->selectedItems ();
if (list.empty ()) return; // nothing to do
// TODO: if we change the selectionmodel to multiselection,
// change this tp remove more than one item
QListWidgetItem* item = list.first ();
QString name = item->text ();
m_collection->remove (name, "Playlists");
}
void
PlaylistChooser::on_playlistsListWidget_itemDoubleClicked (QListWidgetItem* item)
{
QString name = item->text ();
m_collection->setActivePlaylist (name);
}

View file

@ -0,0 +1,46 @@
/**
* This file is a part of Promoe, an XMMS2 client
*
* Copyright (C) 2008 Thomas Frauendorfer
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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.
*/
#ifndef __PLAYLISTCHOOSER_H__
#define __PLAYLISTCHOOSER_H__
#include "ui_playlistchooser.h"
#include <QDialog>
class QListWidgetItem;
class XCollection;
class PlaylistChooser : public QDialog, private Ui::PlaylistChooser {
Q_OBJECT
public:
PlaylistChooser (QWidget *parent, XCollection *coll);
private slots:
void handle_playlists_modified (QString, QString, int, QString);
void on_playlistCreateButton_clicked ();
void on_playlistRemoveButton_clicked ();
void on_playlistsListWidget_itemDoubleClicked (QListWidgetItem* item);
private:
XCollection* m_collection;
};
#endif

View file

@ -0,0 +1,108 @@
<ui version="4.0" >
<class>PlaylistChooser</class>
<widget class="QDialog" name="PlaylistChooser" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle" >
<string>Playlists</string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLineEdit" name="playlistTextEdit" />
</item>
<item>
<widget class="QPushButton" name="playlistCreateButton" >
<property name="text" >
<string>Create</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="playlistsListWidget" >
<property name="verticalScrollBarPolicy" >
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="horizontalScrollBarPolicy" >
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="playlistRemoveButton" >
<property name="text" >
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="closeButton" >
<property name="text" >
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>closeButton</sender>
<signal>clicked()</signal>
<receiver>PlaylistChooser</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel" >
<x>217</x>
<y>279</y>
</hint>
<hint type="destinationlabel" >
<x>129</x>
<y>124</y>
</hint>
</hints>
</connection>
<connection>
<sender>playlistsListWidget</sender>
<signal>currentTextChanged(QString)</signal>
<receiver>playlistTextEdit</receiver>
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel" >
<x>129</x>
<y>150</y>
</hint>
<hint type="destinationlabel" >
<x>87</x>
<y>21</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -26,6 +26,7 @@
#include "playlistshade.h"
#include "playlistmenu.h"
#include "FileDialog.h"
#include "playlistchooser.h"
#include <QMouseEvent>
#include <QPaintEvent>
@ -277,6 +278,8 @@ PlaylistWidget::addButtons (void)
Skin::PLS_LST_DEC);
b = new PlaylistMenuButton (m_lst, Skin::PLS_LST_NEW_0,
Skin::PLS_LST_NEW_1);
connect (b, SIGNAL (activated ()),
this, SLOT(openPlaylistChooser ()));
b = new PlaylistMenuButton (m_lst, Skin::PLS_LST_SAV_0,
Skin::PLS_LST_SAV_1);
b = new PlaylistMenuButton (m_lst, Skin::PLS_LST_OPN_0,
@ -505,3 +508,10 @@ PlaylistWidget::paintEvent (QPaintEvent *event)
paint.end ();
}
void
PlaylistWidget::openPlaylistChooser ()
{
XMMSHandler &client = XMMSHandler::getInstance ();
PlaylistChooser *tmp = new PlaylistChooser (this, client.xcollection ());
tmp->show ();
}

View file

@ -86,6 +86,9 @@ class PlaylistWidget : public QWidget {
void menuAddDir ();
void menuAddFile ();
protected slots:
void openPlaylistChooser ();
private:
void resizeEvent (QResizeEvent *event);
void paintEvent (QPaintEvent *event);

View file

@ -2,6 +2,7 @@ include($$PWD/widgets/widgets.pri)
include($$PWD/mainwindow/mainwindow.pri)
include($$PWD/playlist/playlist.pri)
include($$PWD/equalizer/equalizer.pri)
include($$PWD/dialogs/dialogs.pri)
HEADERS += PixWidget.h \
Skin.h \