Merge remote branch 'maemo/master'
[someplayer] / src / libraryform.cpp
index a6ff189..bd1ff2f 100644 (file)
@@ -26,9 +26,9 @@
 #include <QModelIndexList>
 #include "track.h"
 #include "playlist.h"
-#include <QDebug>
 #include <QTime>
 #include <QQueue>
+#include <QMessageBox>
 
 using namespace SomePlayer::DataObjects;
 
@@ -72,6 +72,7 @@ LibraryForm::LibraryForm(Library *lib, QWidget *parent) :
        connect(ui->dynamicButton, SIGNAL(clicked()), this, SLOT(_dynamic_button()));
        connect(ui->listView, SIGNAL(clicked(QModelIndex)), this, SLOT(_process_list_click(QModelIndex)));
        connect(ui->addButton, SIGNAL(clicked()), this, SLOT(_add_button()));
+       connect(ui->selectAllButton, SIGNAL(clicked()), this, SLOT(_toggle_select_all_button()));
        connect(ui->backButton, SIGNAL(clicked()), this, SLOT(_back_button()));
        connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(_delete_button()));
        connect(ui->useButton, SIGNAL(clicked()), this, SLOT(_use_button()));
@@ -277,14 +278,15 @@ void LibraryForm::_delete_button() {
                ui->listView->selectionModel()->clearSelection();
                QQueue<int> to_delete;
                foreach (QModelIndex id, selected) {
-                       _delete_track(_current_tracks.at(id.row()));
                        to_delete.append(id.row());
                }
                qSort(to_delete);
                int count = to_delete.count();
                for (int i = count-1; i >= 0; i--) {
-                       _current_tracks.removeAt(to_delete.at(i));
+                       _current_playlist.removeTrackAt(to_delete.at(i));
                }
+               _current_tracks = _current_playlist.tracks();
+               _lib->savePlaylist(_current_playlist);
                __fill_model_tracks(_model, _current_tracks);
        } else if (_state == STATE_PLAYLIST) {
                QModelIndexList selected = ui->listView->selectionModel()->selectedIndexes();
@@ -297,7 +299,6 @@ void LibraryForm::_delete_button() {
                for (int i = count-1; i >= 0; i--) {
                        QString name = _model->item(to_delete.at(i))->text();
                        if (name != _CURRENT_PLAYLIST_SUBST_) {
-                               qDebug() << "deleting " << name;
                                _lib->removePlaylist(name);
                                _model->removeRow(to_delete.at(i));
                        }
@@ -313,6 +314,7 @@ void LibraryForm::_delete_track(Track track) {
 
 void LibraryForm::_use_button() {
        _lib->saveCurrentPlaylist(_current_playlist);
+       _current_playlist = _lib->getCurrentPlaylist();
 }
 
 void LibraryForm::search(QString &pattern) {
@@ -355,3 +357,42 @@ void LibraryForm::cancelSearch() {
        _search_pattern = "";
        ui->listView->selectionModel()->clearSelection();
 }
+
+void LibraryForm::refresh() {
+       switch (_state) {
+       case STATE_ARTIST:
+               _view_button();
+               break;
+       case STATE_ALBUM:
+               __fill_model(_model, _lib->getAlbumsForArtist(_current_artist));
+               break;
+       case STATE_PLAYLIST:
+               _playlists_button();
+               break;
+       case STATE_DYNAMIC:
+               _dynamic_button();
+               break;
+       case STATE_PLAYLIST_TRACK:
+               _current_playlist = _lib->getPlaylist(_current_playlist.name());
+               _current_tracks = _current_playlist.tracks();
+               __fill_model_tracks(_model, _current_tracks);
+               break;
+       case STATE_TRACK:
+               _current_tracks = _lib->getTracksForAlbum(_current_album, _current_artist);
+               __fill_model_tracks(_model, _current_tracks);
+               break;
+       default:
+               return;
+       }
+}
+
+void LibraryForm::_toggle_select_all_button() {
+       if (ui->listView->selectionModel()->selectedIndexes().count() == ui->listView->model()->rowCount()) {
+               ui->listView->selectionModel()->clearSelection();
+               ui->selectAllButton->setIcon(QIcon(":/icons/select_all.png"));
+       } else {
+               ui->listView->selectAll();
+               ui->selectAllButton->setIcon(QIcon(":/icons/deselect_all.png"));
+       }
+}
+