Improve the playlists-choose dialog
This commit is contained in:
parent
d93f2ee188
commit
4c7317f71d
8 changed files with 191 additions and 52 deletions
|
@ -74,7 +74,7 @@ XClient::XClient (QObject *parent, const std::string &name) : QObject (parent),
|
||||||
m_client = NULL;
|
m_client = NULL;
|
||||||
m_isconnected = false;
|
m_isconnected = false;
|
||||||
m_cache = new XClientCache (this, this);
|
m_cache = new XClientCache (this, this);
|
||||||
m_config = new XConfig (this, this);
|
m_config = new XConfig (this);
|
||||||
m_collection = new XCollection (this);
|
m_collection = new XCollection (this);
|
||||||
m_name = name;
|
m_name = name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,11 @@ XCollection::on_connect (XClient *client)
|
||||||
client->collection ()->list ("Playlists")
|
client->collection ()->list ("Playlists")
|
||||||
(Xmms::bind (&XCollection::handle_playlists_list, this));
|
(Xmms::bind (&XCollection::handle_playlists_list, this));
|
||||||
|
|
||||||
|
client->playlist ()->currentActive ()
|
||||||
|
(Xmms::bind (&XCollection::handle_active_pls_changed, this));
|
||||||
|
client->playlist ()->broadcastLoaded ()
|
||||||
|
(Xmms::bind (&XCollection::handle_active_pls_changed, this));
|
||||||
|
|
||||||
m_client = client;
|
m_client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +98,19 @@ XCollection::on_collection_modified (const Xmms::Dict &value)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
XCollection::remove (QString name, QString ns) {
|
||||||
|
if (!m_client->isConnected ()) return false;
|
||||||
|
|
||||||
|
m_client->collection ()->remove (name.toStdString (), ns.toAscii ());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* idList (Playlist) stuff
|
||||||
|
*/
|
||||||
|
|
||||||
bool
|
bool
|
||||||
XCollection::handle_playlists_list (const Xmms::List< std::string > &list)
|
XCollection::handle_playlists_list (const Xmms::List< std::string > &list)
|
||||||
{
|
{
|
||||||
|
@ -125,6 +143,16 @@ XCollection::setActivePlaylist (QString name) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
XCollection::handle_active_pls_changed (const std::string &name) {
|
||||||
|
QString tmp = m_activePlaylist;
|
||||||
|
m_activePlaylist = XClient::stdToQ (name);
|
||||||
|
|
||||||
|
emit activePlaylistChanged (m_activePlaylist, tmp);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: should be done in a more generic way
|
// FIXME: should be done in a more generic way
|
||||||
bool
|
bool
|
||||||
XCollection::addIdlist (QString name) {
|
XCollection::addIdlist (QString name) {
|
||||||
|
@ -134,12 +162,3 @@ XCollection::addIdlist (QString name) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
XCollection::remove (QString name, QString ns) {
|
|
||||||
if (!m_client->isConnected ()) return false;
|
|
||||||
|
|
||||||
m_client->collection ()->remove (name.toStdString (), ns.toAscii ());
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,22 +30,30 @@ class XCollection : public QObject
|
||||||
XCollection (XClient *client);
|
XCollection (XClient *client);
|
||||||
QStringList list (QString ns = "Playlists");
|
QStringList list (QString ns = "Playlists");
|
||||||
|
|
||||||
bool setActivePlaylist (QString name);
|
|
||||||
bool addIdlist (QString name);
|
|
||||||
bool remove (QString name, QString ns);
|
bool remove (QString name, QString ns);
|
||||||
|
// idlist specific
|
||||||
|
bool setActivePlaylist (QString name);
|
||||||
|
QString activePlaylist () {return m_activePlaylist;}
|
||||||
|
bool addIdlist (QString name);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void collectionModified (QString collection, QString ns, int type,
|
void collectionModified (QString collection, QString ns, int type,
|
||||||
QString newname);
|
QString newname);
|
||||||
|
|
||||||
|
void activePlaylistChanged (QString newActive, QString oldActive);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_connect (XClient *);
|
void on_connect (XClient *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool on_collection_modified (const Xmms::Dict &value);
|
bool on_collection_modified (const Xmms::Dict &value);
|
||||||
bool handle_playlists_list (const Xmms::List< std::string > &list);
|
bool handle_playlists_list (const Xmms::List< std::string > &list);
|
||||||
|
bool handle_active_pls_changed (const std::string &name);
|
||||||
|
|
||||||
XClient *m_client;
|
XClient *m_client;
|
||||||
QStringList m_playlists;
|
QStringList m_playlists;
|
||||||
|
|
||||||
|
QString m_activePlaylist;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,18 +20,18 @@
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
XConfig::XConfig (QObject *parent, XClient *client) : QObject (parent)
|
XConfig::XConfig (XClient *parent) : QObject (parent)
|
||||||
{
|
{
|
||||||
m_ready = false;
|
m_ready = false;
|
||||||
|
|
||||||
connect (client, SIGNAL (gotConnection (XClient *)),
|
connect (parent, SIGNAL (gotConnection (XClient *)),
|
||||||
this, SLOT (on_connect (XClient *)));
|
this, SLOT (on_connect (XClient *)));
|
||||||
|
|
||||||
connect (client, SIGNAL (disconnected (XClient *)),
|
connect (parent, SIGNAL (disconnected (XClient *)),
|
||||||
this, SLOT (on_disconnect (XClient *)));
|
this, SLOT (on_disconnect (XClient *)));
|
||||||
|
|
||||||
if (client->isConnected ()) {
|
if (parent->isConnected ()) {
|
||||||
on_connect (client);
|
on_connect (parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ class XConfig : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
XConfig (QObject *parent, XClient *client);
|
XConfig (XClient *parent);
|
||||||
|
|
||||||
QString value_get (QString key);
|
QString value_get (QString key);
|
||||||
bool value_set (QString key, QString value);
|
bool value_set (QString key, QString value);
|
||||||
|
|
|
@ -35,20 +35,28 @@ PlaylistChooser::PlaylistChooser (QWidget *parent, XCollection *coll)
|
||||||
|
|
||||||
m_collection = coll;
|
m_collection = coll;
|
||||||
|
|
||||||
// FIXME: implement creation of new Playlists
|
// the createButton will be enabled as soon as textEdit contains a name
|
||||||
// playlistCreateButton->setEnabled (false);
|
// that is not equal to an existing Playlist
|
||||||
// playlistRemoveButton->setEnabled (false);
|
createButton->setEnabled (false);
|
||||||
|
|
||||||
|
// selectButton will be enabled when exactly one item is selected
|
||||||
|
selectButton->setEnabled (false);
|
||||||
|
|
||||||
// fill the List with Playlistnames.
|
// fill the List with Playlistnames.
|
||||||
// Sort out playlists that start with '_'
|
// Sort out playlists that start with '_'
|
||||||
QRegExp regex = QRegExp ("^[^_]");
|
QRegExp regex = QRegExp ("^[^_]");
|
||||||
QStringList lists = coll->list ("Playlists").filter (regex);
|
QStringList lists = coll->list ("Playlists").filter (regex);
|
||||||
playlistsListWidget->setSortingEnabled (true);
|
listWidget->setSortingEnabled (true);
|
||||||
playlistsListWidget->addItems (lists);
|
listWidget->addItems (lists);
|
||||||
connect (coll, SIGNAL (collectionModified (QString, QString, int, QString)),
|
connect (coll, SIGNAL (collectionModified (QString, QString, int, QString)),
|
||||||
this, SLOT (handle_playlists_modified (QString, QString, int,
|
this, SLOT (handle_playlists_modified (QString, QString, int,
|
||||||
QString)));
|
QString)));
|
||||||
|
|
||||||
|
// display active Playlist in bold Font
|
||||||
|
QString activePls = coll->activePlaylist ();
|
||||||
|
handle_active_pls_changed (activePls, "");
|
||||||
|
connect (coll, SIGNAL (activePlaylistChanged (QString, QString)),
|
||||||
|
this, SLOT (handle_active_pls_changed (QString, QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -62,17 +70,21 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case XMMS_COLLECTION_CHANGED_ADD:
|
case XMMS_COLLECTION_CHANGED_ADD:
|
||||||
if (!name.startsWith("_")) {
|
if (!name.startsWith("_")) {
|
||||||
playlistsListWidget->addItem(name);
|
listWidget->addItem(name);
|
||||||
|
}
|
||||||
|
// if we created the playlist, make is the active playlist
|
||||||
|
if (name == textEdit->text ()) {
|
||||||
|
m_collection->setActivePlaylist (name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XMMS_COLLECTION_CHANGED_REMOVE: {
|
case XMMS_COLLECTION_CHANGED_REMOVE: {
|
||||||
QList<QListWidgetItem *> list
|
QList<QListWidgetItem *> list
|
||||||
= playlistsListWidget->findItems (name, Qt::MatchExactly);
|
= listWidget->findItems (name, Qt::MatchExactly);
|
||||||
if (!list.empty ()) {
|
if (!list.empty ()) {
|
||||||
// we should only have one exatly matching String
|
// we should only have one exatly matching String
|
||||||
QListWidgetItem* item = list.first ();
|
QListWidgetItem* item = list.first ();
|
||||||
int idx = playlistsListWidget->row (item);
|
int idx = listWidget->row (item);
|
||||||
item = playlistsListWidget->takeItem (idx);
|
item = listWidget->takeItem (idx);
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,17 +92,17 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
|
||||||
case XMMS_COLLECTION_CHANGED_RENAME: {
|
case XMMS_COLLECTION_CHANGED_RENAME: {
|
||||||
// remove the old entry
|
// remove the old entry
|
||||||
QList<QListWidgetItem *> list
|
QList<QListWidgetItem *> list
|
||||||
= playlistsListWidget->findItems (name, Qt::MatchExactly);
|
= listWidget->findItems (name, Qt::MatchExactly);
|
||||||
if (!list.empty ()) {
|
if (!list.empty ()) {
|
||||||
// we should only have one exatly matching String
|
// we should only have one exatly matching String
|
||||||
QListWidgetItem* item = list.first ();
|
QListWidgetItem* item = list.first ();
|
||||||
int idx = playlistsListWidget->row (item);
|
int idx = listWidget->row (item);
|
||||||
item = playlistsListWidget->takeItem (idx);
|
item = listWidget->takeItem (idx);
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
// and add the new one
|
// and add the new one
|
||||||
if (!newname.startsWith("_")) {
|
if (!newname.startsWith("_")) {
|
||||||
playlistsListWidget->addItem(newname);
|
listWidget->addItem(newname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -102,20 +114,51 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistChooser::on_playlistCreateButton_clicked ()
|
PlaylistChooser::handle_active_pls_changed (QString newActive,
|
||||||
|
QString oldActive)
|
||||||
{
|
{
|
||||||
QString name = playlistTextEdit->text ();
|
QListWidgetItem *item;
|
||||||
// only create new playlist, if it doesn't already exist
|
QFont font;
|
||||||
if (m_collection->list ("Playlists").contains (name)) return;
|
QList <QListWidgetItem *> list;
|
||||||
|
|
||||||
m_collection->addIdlist (name);
|
// newActive and oldActive can match at most once each
|
||||||
|
// paint former active Playlist no longer in bold
|
||||||
|
list = listWidget->findItems (oldActive, Qt::MatchExactly);
|
||||||
|
if (!list.empty ()) {
|
||||||
|
item = list.first ();
|
||||||
|
font = item->font ();
|
||||||
|
font.setBold (false);
|
||||||
|
item->setFont (font);
|
||||||
|
}
|
||||||
|
|
||||||
|
// paint new active Playlist in bold
|
||||||
|
list = listWidget->findItems (newActive, Qt::MatchExactly);
|
||||||
|
if (!list.empty ()) {
|
||||||
|
item = list.first ();
|
||||||
|
font = item->font ();
|
||||||
|
font.setBold (true);
|
||||||
|
item->setFont (font);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the activestate of the selectButton
|
||||||
|
on_listWidget_itemSelectionChanged ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PlaylistChooser::playlistExists (QString name) {
|
||||||
|
// Use the information from m_collection, as listWidger
|
||||||
|
// doesn't contain hidden Playlists
|
||||||
|
return m_collection->list ("Playlists").contains (name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistChooser::on_playlistRemoveButton_clicked ()
|
PlaylistChooser::on_removeButton_clicked ()
|
||||||
{
|
{
|
||||||
QList<QListWidgetItem *> list = playlistsListWidget->selectedItems ();
|
QList<QListWidgetItem *> list = listWidget->selectedItems ();
|
||||||
if (list.empty ()) return; // nothing to do
|
if (list.empty ())
|
||||||
|
return; // nothing to do
|
||||||
|
|
||||||
// TODO: if we change the selectionmodel to multiselection,
|
// TODO: if we change the selectionmodel to multiselection,
|
||||||
// change this tp remove more than one item
|
// change this tp remove more than one item
|
||||||
|
@ -124,9 +167,58 @@ PlaylistChooser::on_playlistRemoveButton_clicked ()
|
||||||
m_collection->remove (name, "Playlists");
|
m_collection->remove (name, "Playlists");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistChooser::on_playlistsListWidget_itemDoubleClicked (QListWidgetItem* item)
|
PlaylistChooser::on_createButton_clicked ()
|
||||||
|
{
|
||||||
|
QString name = textEdit->text ();
|
||||||
|
// only create new playlist, if it doesn't already exist
|
||||||
|
if (playlistExists (name)) return;
|
||||||
|
|
||||||
|
m_collection->addIdlist (name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistChooser::on_selectButton_clicked ()
|
||||||
|
{
|
||||||
|
QList <QListWidgetItem *> list = listWidget->selectedItems ();
|
||||||
|
if (list.size () == 1) {
|
||||||
|
QListWidgetItem * item = list.first ();
|
||||||
|
m_collection->setActivePlaylist (item->text ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistChooser::on_listWidget_itemDoubleClicked (QListWidgetItem* item)
|
||||||
{
|
{
|
||||||
QString name = item->text ();
|
QString name = item->text ();
|
||||||
m_collection->setActivePlaylist (name);
|
m_collection->setActivePlaylist (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistChooser::on_listWidget_itemSelectionChanged ()
|
||||||
|
{
|
||||||
|
QList <QListWidgetItem *> list = listWidget->selectedItems ();
|
||||||
|
// enable selectButton, if one item is selected and does not represent
|
||||||
|
// the currently active playlist
|
||||||
|
selectButton->setEnabled ((list.size () == 1)
|
||||||
|
&& (list.first ()->text ()
|
||||||
|
!= m_collection->activePlaylist ()));
|
||||||
|
|
||||||
|
// enable removeButton if more than one item is selected
|
||||||
|
// or if the selected item is not the actice Playlist
|
||||||
|
removeButton->setEnabled ((list.size () > 1) ||
|
||||||
|
( (list.size () == 1) && (list.first ()->text ()
|
||||||
|
!= m_collection->activePlaylist ())));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistChooser::on_textEdit_textChanged ()
|
||||||
|
{
|
||||||
|
// Enable createButton only, if no playlist with that name exists
|
||||||
|
// and the textEdit is not empty
|
||||||
|
createButton->setEnabled ((!playlistExists (textEdit->text ())
|
||||||
|
&& (textEdit->text () != "")));
|
||||||
|
}
|
||||||
|
|
|
@ -32,14 +32,21 @@ class PlaylistChooser : public QDialog, private Ui::PlaylistChooser {
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
// XCollection change handlers
|
||||||
void handle_playlists_modified (QString, QString, int, QString);
|
void handle_playlists_modified (QString, QString, int, QString);
|
||||||
|
void handle_active_pls_changed (QString, QString);
|
||||||
|
|
||||||
void on_playlistCreateButton_clicked ();
|
// autoconnect Slots
|
||||||
void on_playlistRemoveButton_clicked ();
|
void on_removeButton_clicked ();
|
||||||
|
void on_createButton_clicked ();
|
||||||
void on_playlistsListWidget_itemDoubleClicked (QListWidgetItem* item);
|
void on_selectButton_clicked ();
|
||||||
|
void on_listWidget_itemDoubleClicked (QListWidgetItem* item);
|
||||||
|
void on_listWidget_itemSelectionChanged ();
|
||||||
|
void on_textEdit_textChanged ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool playlistExists (QString name);
|
||||||
|
|
||||||
XCollection* m_collection;
|
XCollection* m_collection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>260</width>
|
<width>266</width>
|
||||||
<height>301</height>
|
<height>302</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle" >
|
||||||
|
@ -16,10 +16,10 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" >
|
<layout class="QHBoxLayout" >
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="playlistTextEdit" />
|
<widget class="QLineEdit" name="textEdit" />
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="playlistCreateButton" >
|
<widget class="QPushButton" name="createButton" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>Create</string>
|
<string>Create</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="playlistsListWidget" >
|
<widget class="QListWidget" name="listWidget" >
|
||||||
<property name="verticalScrollBarPolicy" >
|
<property name="verticalScrollBarPolicy" >
|
||||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" >
|
<layout class="QHBoxLayout" >
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="playlistRemoveButton" >
|
<widget class="QPushButton" name="removeButton" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>Remove</string>
|
<string>Remove</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -59,6 +59,19 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="selectButton" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||||
|
p, li { white-space: pre-wrap; }
|
||||||
|
</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;">
|
||||||
|
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Set the currently selected playlist as active playlist</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Select</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="closeButton" >
|
<widget class="QPushButton" name="closeButton" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
|
@ -89,9 +102,9 @@
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>playlistsListWidget</sender>
|
<sender>listWidget</sender>
|
||||||
<signal>currentTextChanged(QString)</signal>
|
<signal>currentTextChanged(QString)</signal>
|
||||||
<receiver>playlistTextEdit</receiver>
|
<receiver>textEdit</receiver>
|
||||||
<slot>setText(QString)</slot>
|
<slot>setText(QString)</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel" >
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue