Added license information
[someplayer] / src / libraryform.cpp
index 8ce4c1d..a6ff189 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * SomePlayer - An alternate music player for Maemo 5
+ * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 #include "libraryform.h"
 #include "ui_libraryform.h"
 #include "library.h"
@@ -46,7 +65,7 @@ LibraryForm::LibraryForm(Library *lib, QWidget *parent) :
        _lib = lib;
        _model = new QStandardItemModel(this);
        _state = STATE_NONE;
-    ui->setupUi(this);
+       ui->setupUi(this);
        connect(ui->playerButton, SIGNAL(clicked()), this, SLOT(_player()));
        connect(ui->viewButton, SIGNAL(clicked()), this, SLOT(_view_button()));
        connect(ui->playlistsButton, SIGNAL(clicked()), this, SLOT(_playlists_button()));
@@ -271,14 +290,17 @@ void LibraryForm::_delete_button() {
                QModelIndexList selected = ui->listView->selectionModel()->selectedIndexes();
                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--) {
-                       _lib->removePlaylist(_model->item(to_delete.at(i))->data().toString());
-                       _model->removeRow(to_delete.at(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));
+                       }
                }
        }
 }
@@ -292,3 +314,44 @@ void LibraryForm::_delete_track(Track track) {
 void LibraryForm::_use_button() {
        _lib->saveCurrentPlaylist(_current_playlist);
 }
+
+void LibraryForm::search(QString &pattern) {
+       _search_pattern = pattern;
+       _search_current_id = -1;
+       nextItem();
+}
+
+void LibraryForm::nextItem() {
+       QString data = _model->index(_search_current_id, 0).data().toString();
+       for (int i = _search_current_id+1; i < _model->rowCount(); i++) {
+               data = _model->index(i, 0).data().toString();
+               if (data.contains(_search_pattern, Qt::CaseInsensitive)) {
+                       _search_current_id = i;
+                       break;
+               }
+       }
+       QModelIndex id = _model->index(_search_current_id, 0);
+       ui->listView->selectionModel()->clearSelection();
+       ui->listView->selectionModel()->select(id, QItemSelectionModel::Select);
+       ui->listView->scrollTo(id);
+}
+
+void LibraryForm::prevItem() {
+       QString data = _model->index(_search_current_id, 0).data().toString();
+       for (int i = _search_current_id-1; i >= 0; i--) {
+               data = _model->index(i, 0).data().toString();
+               if (data.contains(_search_pattern, Qt::CaseInsensitive)) {
+                       _search_current_id = i;
+                       break;
+               }
+       }
+       QModelIndex id = _model->index(_search_current_id, 0);
+       ui->listView->selectionModel()->clearSelection();
+       ui->listView->selectionModel()->select(id, QItemSelectionModel::Select);
+       ui->listView->scrollTo(id);
+}
+
+void LibraryForm::cancelSearch() {
+       _search_pattern = "";
+       ui->listView->selectionModel()->clearSelection();
+}