Fixed incorrect track metadata displaying
[someplayer] / src / playerform.cpp
index 538ae17..58de1b8 100644 (file)
@@ -116,7 +116,7 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        _pls_sort_form->hide();
 
        connect(ui->libraryButton, SIGNAL(clicked()), this, SLOT(_library()));
-       connect(ui->viewButton, SIGNAL(clicked()), this, SLOT(_toggle_view()));
+       connect(ui->viewButton, SIGNAL(clicked()), this, SLOT(toggleView()));
        connect(ui->playlistView, SIGNAL(clicked(QModelIndex)), this, SLOT(_process_click(QModelIndex)));
        connect(ui->playpauseButton, SIGNAL(clicked()), _player, SLOT(toggle()));
        connect(ui->nextButton, SIGNAL(clicked()), _player, SLOT(next()));
@@ -124,8 +124,8 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        connect(ui->prevButton, SIGNAL(clicked()), _player, SLOT(prev()));
        connect(_player, SIGNAL(trackChanged(Track)), this, SLOT(_track_changed(Track)));
        connect(_player, SIGNAL(tick(int,int)), this, SLOT(_tick(int,int)));
-       connect(ui->randomButton, SIGNAL(clicked()), this, SLOT(_toggle_random()));
-       connect(ui->repeatButton, SIGNAL(clicked()), this, SLOT(_toggle_repeat()));
+       connect(ui->randomButton, SIGNAL(clicked()), this, SLOT(toggleRandom()));
+       connect(ui->repeatButton, SIGNAL(clicked()), this, SLOT(toggleRepeat()));
        connect(ui->seekSlider, SIGNAL(sliderMoved(int)), _player, SLOT(seek(int)));
        connect(ui->playlistView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(_sort_playlist()));
        connect(__clear_playlist, SIGNAL(triggered()), this, SIGNAL(clearPlaylist()));
@@ -138,7 +138,7 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        connect(_player, SIGNAL(trackDone(Track)), _lib, SLOT(updateTrackCount(Track)));
        connect(_tag_resolver, SIGNAL(decoded(Track)), this, SLOT(_track_decoded(Track)));
        connect(ui->dirButton, SIGNAL(clicked()), this, SLOT(_dirview()));
-       connect(ui->moreButton, SIGNAL(clicked()), this, SLOT(_tools_widget_toggle()));
+       connect(ui->moreButton, SIGNAL(clicked()), this, SLOT(toggleToolsWidget()));
        connect(_tools_widget, SIGNAL(search(QString)), this, SLOT(search(QString)));
        connect(_tools_widget, SIGNAL(nextSearch()), this, SLOT(nextItem()));
        connect(_tools_widget, SIGNAL(prevSearch()), this, SLOT(prevItem()));
@@ -198,7 +198,7 @@ void PlayerForm::reload(bool reread) {
        }
 }
 
-void PlayerForm::_toggle_view() {
+void PlayerForm::toggleView() {
        int index = ui->stackedWidget->currentIndex();
        index = (!index % 2);
        if (index) {
@@ -268,11 +268,21 @@ void PlayerForm::_slider_released() {
 }
 
 void PlayerForm::_custom_context_menu_requested(const QPoint &pos) {
+       // fix for 'favorite' state of selected track:
+       QList<QModelIndex> idx = ui->playlistView->selectionModel()->selectedIndexes();
+       if (idx.isEmpty())
+               return;
+       int id = idx.first().row();
+       Track cur = _current_playlist.tracks().at(id);
+       if (!cur.source().isEmpty()) {
+               bool isf = _lib->isFavorite(cur);
+               _context_menu->actions().at(2)->setText(isf ? tr("Remove from favorites") : tr("Add to favorites"));
+       }
+       // end
        _context_menu->exec(pos);
 }
 
 void PlayerForm::_delete_track() {
-       CONFIRM_ACTION(this, tr("Delete track?"))
        QList<QModelIndex> idx = ui->playlistView->selectionModel()->selectedIndexes();
        if (idx.isEmpty())
                return;
@@ -310,8 +320,7 @@ void PlayerForm::_add_to_favorites() {
                        _lib->removeFromFavorites(cur);
                }
                isf = _lib->isFavorite(cur);
-               ui->cfavButton->setChecked(isf && !ui->cfavButton->icon().isNull());
-               _context_menu->actions().at(2)->setText(isf ? tr("Remove from favorites") : tr("Add to favorites"));
+               ui->cfavButton->setChecked(isf && !ui->cfavButton->icon().isNull() && id == _track_renderer->activeRow());
        }
 
 }
@@ -330,7 +339,7 @@ void PlayerForm::_state_changed(PlayerState state) {
        }
 }
 
-void PlayerForm::_toggle_random() {
+void PlayerForm::toggleRandom() {
        _player->toggleRandom();
        if (_player->random()) {
                ui->randomButton->setIcon(QIcon(":/icons/"+_icons_theme+"/random_on.png"));
@@ -339,7 +348,7 @@ void PlayerForm::_toggle_random() {
        }
 }
 
-void PlayerForm::_toggle_repeat() {
+void PlayerForm::toggleRepeat() {
        _player->toggleRepeat();
        if (_player->repeat() == REPEAT_ALL) {
                ui->repeatButton->setIcon(QIcon(":/icons/"+_icons_theme+"/repeat_all.png"));
@@ -441,6 +450,7 @@ void PlayerForm::_edit_tags() {
                reload(true);
                emit refreshLibrary();
        }
+       _display_track(track);
 }
 
 void PlayerForm::stop() {
@@ -590,7 +600,10 @@ void PlayerForm::portraitMode() {
        _pls_sort_form->portraitMode();
 }
 
-void PlayerForm::_tools_widget_toggle() {
+void PlayerForm::toggleToolsWidget() {
+       if (0 != ui->stackedWidget->currentIndex()) {
+               return;
+       }
        if (_tools_widget->isVisible()) {
                ui->moreButton->setIcon(QIcon(":/icons/"+_icons_theme+"/more.png"));
                _tools_widget->hide();
@@ -813,3 +826,7 @@ void PlayerForm::_playlist_sorted() {
        ui->playlistView->setColumnWidth(0, 50);
        _track_renderer->setActiveRow(_current_playlist.tracks().indexOf(_player->current()));
 }
+
+void PlayerForm::toggle() {
+       _player->toggle();
+}