Improve the playlists-choose dialog

This commit is contained in:
Thomas Frauendorfer 2008-02-09 15:25:47 +01:00
parent d93f2ee188
commit 4c7317f71d
8 changed files with 191 additions and 52 deletions

View file

@ -74,7 +74,7 @@ XClient::XClient (QObject *parent, const std::string &name) : QObject (parent),
m_client = NULL;
m_isconnected = false;
m_cache = new XClientCache (this, this);
m_config = new XConfig (this, this);
m_config = new XConfig (this);
m_collection = new XCollection (this);
m_name = name;
}

View file

@ -39,6 +39,11 @@ XCollection::on_connect (XClient *client)
client->collection ()->list ("Playlists")
(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;
}
@ -93,6 +98,19 @@ XCollection::on_collection_modified (const Xmms::Dict &value)
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
XCollection::handle_playlists_list (const Xmms::List< std::string > &list)
{
@ -125,6 +143,16 @@ XCollection::setActivePlaylist (QString name) {
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
bool
XCollection::addIdlist (QString name) {
@ -134,12 +162,3 @@ XCollection::addIdlist (QString name) {
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;
}

View file

@ -30,22 +30,30 @@ class XCollection : public QObject
XCollection (XClient *client);
QStringList list (QString ns = "Playlists");
bool setActivePlaylist (QString name);
bool addIdlist (QString name);
bool remove (QString name, QString ns);
// idlist specific
bool setActivePlaylist (QString name);
QString activePlaylist () {return m_activePlaylist;}
bool addIdlist (QString name);
signals:
void collectionModified (QString collection, QString ns, int type,
QString newname);
void activePlaylistChanged (QString newActive, QString oldActive);
protected slots:
void on_connect (XClient *);
private:
bool on_collection_modified (const Xmms::Dict &value);
bool handle_playlists_list (const Xmms::List< std::string > &list);
bool handle_active_pls_changed (const std::string &name);
XClient *m_client;
QStringList m_playlists;
QString m_activePlaylist;
};
#endif

View file

@ -20,18 +20,18 @@
#include <QList>
XConfig::XConfig (QObject *parent, XClient *client) : QObject (parent)
XConfig::XConfig (XClient *parent) : QObject (parent)
{
m_ready = false;
connect (client, SIGNAL (gotConnection (XClient *)),
connect (parent, SIGNAL (gotConnection (XClient *)),
this, SLOT (on_connect (XClient *)));
connect (client, SIGNAL (disconnected (XClient *)),
connect (parent, SIGNAL (disconnected (XClient *)),
this, SLOT (on_disconnect (XClient *)));
if (client->isConnected ()) {
on_connect (client);
if (parent->isConnected ()) {
on_connect (parent);
}
}

View file

@ -27,7 +27,7 @@ class XConfig : public QObject
{
Q_OBJECT
public:
XConfig (QObject *parent, XClient *client);
XConfig (XClient *parent);
QString value_get (QString key);
bool value_set (QString key, QString value);

View file

@ -35,20 +35,28 @@ PlaylistChooser::PlaylistChooser (QWidget *parent, XCollection *coll)
m_collection = coll;
// FIXME: implement creation of new Playlists
// playlistCreateButton->setEnabled (false);
// playlistRemoveButton->setEnabled (false);
// the createButton will be enabled as soon as textEdit contains a name
// that is not equal to an existing Playlist
createButton->setEnabled (false);
// selectButton will be enabled when exactly one item is selected
selectButton->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);
listWidget->setSortingEnabled (true);
listWidget->addItems (lists);
connect (coll, SIGNAL (collectionModified (QString, QString, int, QString)),
this, SLOT (handle_playlists_modified (QString, QString, int,
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
@ -62,17 +70,21 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
switch (type) {
case XMMS_COLLECTION_CHANGED_ADD:
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;
case XMMS_COLLECTION_CHANGED_REMOVE: {
QList<QListWidgetItem *> list
= playlistsListWidget->findItems (name, Qt::MatchExactly);
= listWidget->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);
int idx = listWidget->row (item);
item = listWidget->takeItem (idx);
delete item;
}
}
@ -80,17 +92,17 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
case XMMS_COLLECTION_CHANGED_RENAME: {
// remove the old entry
QList<QListWidgetItem *> list
= playlistsListWidget->findItems (name, Qt::MatchExactly);
= listWidget->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);
int idx = listWidget->row (item);
item = listWidget->takeItem (idx);
delete item;
}
// and add the new one
if (!newname.startsWith("_")) {
playlistsListWidget->addItem(newname);
listWidget->addItem(newname);
}
}
break;
@ -102,20 +114,51 @@ PlaylistChooser::handle_playlists_modified (QString name, QString ns,
void
PlaylistChooser::on_playlistCreateButton_clicked ()
PlaylistChooser::handle_active_pls_changed (QString newActive,
QString oldActive)
{
QString name = playlistTextEdit->text ();
// only create new playlist, if it doesn't already exist
if (m_collection->list ("Playlists").contains (name)) return;
QListWidgetItem *item;
QFont font;
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
PlaylistChooser::on_playlistRemoveButton_clicked ()
PlaylistChooser::on_removeButton_clicked ()
{
QList<QListWidgetItem *> list = playlistsListWidget->selectedItems ();
if (list.empty ()) return; // nothing to do
QList<QListWidgetItem *> list = listWidget->selectedItems ();
if (list.empty ())
return; // nothing to do
// TODO: if we change the selectionmodel to multiselection,
// change this tp remove more than one item
@ -124,9 +167,58 @@ PlaylistChooser::on_playlistRemoveButton_clicked ()
m_collection->remove (name, "Playlists");
}
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 ();
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 () != "")));
}

View file

@ -32,14 +32,21 @@ class PlaylistChooser : public QDialog, private Ui::PlaylistChooser {
private slots:
// XCollection change handlers
void handle_playlists_modified (QString, QString, int, QString);
void handle_active_pls_changed (QString, QString);
void on_playlistCreateButton_clicked ();
void on_playlistRemoveButton_clicked ();
void on_playlistsListWidget_itemDoubleClicked (QListWidgetItem* item);
// autoconnect Slots
void on_removeButton_clicked ();
void on_createButton_clicked ();
void on_selectButton_clicked ();
void on_listWidget_itemDoubleClicked (QListWidgetItem* item);
void on_listWidget_itemSelectionChanged ();
void on_textEdit_textChanged ();
private:
bool playlistExists (QString name);
XCollection* m_collection;
};

View file

@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>301</height>
<width>266</width>
<height>302</height>
</rect>
</property>
<property name="windowTitle" >
@ -16,10 +16,10 @@
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLineEdit" name="playlistTextEdit" />
<widget class="QLineEdit" name="textEdit" />
</item>
<item>
<widget class="QPushButton" name="playlistCreateButton" >
<widget class="QPushButton" name="createButton" >
<property name="text" >
<string>Create</string>
</property>
@ -28,7 +28,7 @@
</layout>
</item>
<item>
<widget class="QListWidget" name="playlistsListWidget" >
<widget class="QListWidget" name="listWidget" >
<property name="verticalScrollBarPolicy" >
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
@ -40,7 +40,7 @@
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="playlistRemoveButton" >
<widget class="QPushButton" name="removeButton" >
<property name="text" >
<string>Remove</string>
</property>
@ -59,6 +59,19 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="selectButton" >
<property name="toolTip" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;">
&lt;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&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="text" >
<string>Select</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeButton" >
<property name="text" >
@ -89,9 +102,9 @@
</hints>
</connection>
<connection>
<sender>playlistsListWidget</sender>
<sender>listWidget</sender>
<signal>currentTextChanged(QString)</signal>
<receiver>playlistTextEdit</receiver>
<receiver>textEdit</receiver>
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel" >