diff --git a/lib/xclient.cpp b/lib/xclient.cpp index 93c7b56..554786b 100644 --- a/lib/xclient.cpp +++ b/lib/xclient.cpp @@ -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; } diff --git a/lib/xcollection.cpp b/lib/xcollection.cpp index 7c23e6b..91a0833 100644 --- a/lib/xcollection.cpp +++ b/lib/xcollection.cpp @@ -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; -} diff --git a/lib/xcollection.h b/lib/xcollection.h index 97dde19..4fa9661 100644 --- a/lib/xcollection.h +++ b/lib/xcollection.h @@ -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 diff --git a/lib/xconfig.cpp b/lib/xconfig.cpp index 80784ab..47ff5c0 100644 --- a/lib/xconfig.cpp +++ b/lib/xconfig.cpp @@ -20,18 +20,18 @@ #include -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); } } diff --git a/lib/xconfig.h b/lib/xconfig.h index fc7145d..a8cdaab 100644 --- a/lib/xconfig.h +++ b/lib/xconfig.h @@ -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); diff --git a/src/dialogs/playlistchooser.cpp b/src/dialogs/playlistchooser.cpp index c154639..de71891 100644 --- a/src/dialogs/playlistchooser.cpp +++ b/src/dialogs/playlistchooser.cpp @@ -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 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 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 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 list = playlistsListWidget->selectedItems (); - if (list.empty ()) return; // nothing to do + QList 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 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 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 () != ""))); +} diff --git a/src/dialogs/playlistchooser.h b/src/dialogs/playlistchooser.h index 225067f..2a9230c 100644 --- a/src/dialogs/playlistchooser.h +++ b/src/dialogs/playlistchooser.h @@ -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; }; diff --git a/src/dialogs/playlistchooser.ui b/src/dialogs/playlistchooser.ui index 2c52be3..89528f5 100644 --- a/src/dialogs/playlistchooser.ui +++ b/src/dialogs/playlistchooser.ui @@ -5,8 +5,8 @@ 0 0 - 260 - 301 + 266 + 302 @@ -16,10 +16,10 @@ - + - + Create @@ -28,7 +28,7 @@ - + Qt::ScrollBarAsNeeded @@ -40,7 +40,7 @@ - + Remove @@ -59,6 +59,19 @@ + + + + <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> + + + Select + + + @@ -89,9 +102,9 @@ - playlistsListWidget + listWidget currentTextChanged(QString) - playlistTextEdit + textEdit setText(QString)