Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options for double clicking a song in the playlist #4991

Merged
merged 6 commits into from
Aug 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions src/ui/behavioursettingspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog* dialog)
MainWindow::PlayBehaviour_IfStopped);
ui_->doubleclick_playmode->setItemData(2, MainWindow::PlayBehaviour_Always);

ui_->doubleclick_playlist_addmode->setItemData(
0, MainWindow::PlaylistAddBehaviour_Play);
ui_->doubleclick_playlist_addmode->setItemData(
1, MainWindow::PlaylistAddBehaviour_Enqueue);
ui_->doubleclick_playlist_addmode->setItemData(
2, MainWindow::PlaylistAddBehaviour_PlayNext);
ui_->doubleclick_playlist_addmode->setItemData(
3, MainWindow::PlaylistAddBehaviour_Nothing);

ui_->doubleclick_playlist_playmode->setItemData(
0, MainWindow::PlaylistPlayBehaviour_Never);
ui_->doubleclick_playlist_playmode->setItemData(
1, MainWindow::PlaylistPlayBehaviour_IfStopped);
ui_->doubleclick_playlist_playmode->setItemData(
2, MainWindow::PlaylistPlayBehaviour_Always);

ui_->menu_playmode->setItemData(0, MainWindow::PlayBehaviour_Never);
ui_->menu_playmode->setItemData(1, MainWindow::PlayBehaviour_IfStopped);
ui_->menu_playmode->setItemData(2, MainWindow::PlayBehaviour_Always);
Expand All @@ -65,9 +81,9 @@ BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog* dialog)

QString code = lang_re.cap(1);
QString lookup_code = QString(code)
.replace("@latin", "_Latn")
.replace("_CN", "_Hans_CN")
.replace("_TW", "_Hant_TW");
.replace("@latin", "_Latn")
.replace("_CN", "_Hans_CN")
.replace("_TW", "_Hant_TW");
QString language_name =
QLocale::languageToString(QLocale(lookup_code).language());
#if QT_VERSION >= 0x040800
Expand Down Expand Up @@ -109,6 +125,14 @@ void BehaviourSettingsPage::Load() {
ui_->doubleclick_playmode->findData(
s.value("doubleclick_playmode", MainWindow::PlayBehaviour_IfStopped)
.toInt()));
ui_->doubleclick_playlist_addmode->setCurrentIndex(
ui_->doubleclick_playlist_addmode->findData(
s.value("doubleclick_playlist_addmode",
MainWindow::PlaylistAddBehaviour_Play).toInt()));
ui_->doubleclick_playlist_playmode->setCurrentIndex(
ui_->doubleclick_playlist_playmode->findData(
s.value("doubleclick_playlist_playmode",
MainWindow::PlaylistPlayBehaviour_IfStopped).toInt()));
ui_->menu_playmode->setCurrentIndex(ui_->menu_playmode->findData(
s.value("menu_playmode", MainWindow::PlayBehaviour_IfStopped).toInt()));

Expand All @@ -131,7 +155,8 @@ void BehaviourSettingsPage::Load() {

s.beginGroup(Player::kSettingsGroup);
ui_->menu_previousmode->setCurrentIndex(ui_->menu_previousmode->findData(
s.value("menu_previousmode", Player::PreviousBehaviour_DontRestart).toInt()));
s.value("menu_previousmode", Player::PreviousBehaviour_DontRestart)
.toInt()));
ui_->seek_step_sec->setValue(s.value("seek_step_sec", 10).toInt());
s.endGroup();

Expand Down Expand Up @@ -192,6 +217,16 @@ void BehaviourSettingsPage::Save() {
ui_->doubleclick_playmode->itemData(
ui_->doubleclick_playmode->currentIndex())
.toInt());
MainWindow::PlaylistAddBehaviour doubleclick_playlist_addmode =
MainWindow::PlaylistAddBehaviour(
ui_->doubleclick_playlist_addmode
->itemData(ui_->doubleclick_playlist_addmode->currentIndex())
.toInt());
MainWindow::PlaylistPlayBehaviour doubleclick_playlist_playmode =
MainWindow::PlaylistPlayBehaviour(
ui_->doubleclick_playlist_playmode
->itemData(ui_->doubleclick_playlist_playmode->currentIndex())
.toInt());
MainWindow::PlayBehaviour menu_playmode = MainWindow::PlayBehaviour(
ui_->menu_playmode->itemData(ui_->menu_playmode->currentIndex()).toInt());

Expand All @@ -216,6 +251,8 @@ void BehaviourSettingsPage::Save() {
s.setValue("startupbehaviour", int(behaviour));
s.setValue("doubleclick_addmode", doubleclick_addmode);
s.setValue("doubleclick_playmode", doubleclick_playmode);
s.setValue("doubleclick_playlist_addmode", doubleclick_playlist_addmode);
s.setValue("doubleclick_playlist_playmode", doubleclick_playlist_playmode);
s.setValue("menu_playmode", menu_playmode);
s.setValue("resume_playback_after_start",
ui_->resume_after_start_->isChecked());
Expand Down
58 changes: 58 additions & 0 deletions src/ui/behavioursettingspage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,64 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2CPL">
<property name="title">
<string>Double clicking a song in the playlist will...</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_doubleclick_playlist">
<item>
<widget class="QComboBox" name="doubleclick_playlist_addmode">
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Change the currently playing song</string>
</property>
</item>
<item>
<property name="text">
<string>Add to the queue</string>
</property>
</item>
<item>
<property name="text">
<string>Replace the queue</string>
</property>
</item>
<item>
<property name="text">
<string>Do nothing</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="doubleclick_playlist_playmode">
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>Never start playing</string>
</property>
</item>
<item>
<property name="text">
<string>Play if there is nothing already playing</string>
</property>
</item>
<item>
<property name="text">
<string>Always start playing</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_seekstep">
<property name="title">
Expand Down
70 changes: 69 additions & 1 deletion src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
SLOT(PlayIndex(QModelIndex)));

connect(ui_->playlist->view(), SIGNAL(doubleClicked(QModelIndex)),
SLOT(PlayIndex(QModelIndex)));
SLOT(PlaylistDoubleClick(QModelIndex)));
connect(ui_->playlist->view(), SIGNAL(PlayItem(QModelIndex)),
SLOT(PlayIndex(QModelIndex)));
connect(ui_->playlist->view(), SIGNAL(PlayPause()), app_->player(),
Expand Down Expand Up @@ -990,6 +990,12 @@ void MainWindow::ReloadSettings() {
AddBehaviour(s.value("doubleclick_addmode", AddBehaviour_Append).toInt());
doubleclick_playmode_ = PlayBehaviour(
s.value("doubleclick_playmode", PlayBehaviour_IfStopped).toInt());
doubleclick_playlist_addmode_ =
PlaylistAddBehaviour(s.value("doubleclick_playlist_addmode",
PlaylistAddBehaviour_Play).toInt());
doubleclick_playlist_playmode_ =
PlaylistPlayBehaviour(s.value("doubleclick_playlist_playmode",
PlaylistPlayBehaviour_IfStopped).toInt());
menu_playmode_ =
PlayBehaviour(s.value("menu_playmode", PlayBehaviour_IfStopped).toInt());
}
Expand Down Expand Up @@ -1227,6 +1233,68 @@ void MainWindow::PlayIndex(const QModelIndex& index) {
app_->player()->PlayAt(row, Engine::Manual, true);
}

void MainWindow::PlaylistDoubleClick(const QModelIndex& index) {
if (!index.isValid()) return;

int row = index.row();
if (index.model() == app_->playlist_manager()->current()->proxy()) {
// The index was in the proxy model (might've been filtered), so we need
// to get the actual row in the source model.
row =
app_->playlist_manager()->current()->proxy()->mapToSource(index).row();
}

QModelIndexList dummyIndexList;

// the following block considers each possible combination of options
// for double clicking on playlist entries
switch (doubleclick_playlist_addmode_) {
case PlaylistAddBehaviour_Play:
switch (doubleclick_playlist_playmode_) {
case PlaylistPlayBehaviour_IfStopped:
if (app_->player()->GetState() == Engine::Playing) {
break; // don't play if already playing
} // otherwise, behave the same as for "Always" (no break statement)

case PlaylistPlayBehaviour_Always:
app_->playlist_manager()->SetActiveToCurrent();
app_->player()->PlayAt(row, Engine::Manual, true);
break;

case PlaylistPlayBehaviour_Never:
// deliberately do nothing here
break;
}
break;

case PlaylistAddBehaviour_PlayNext:
app_->playlist_manager()->current()->queue()->Clear();
// continue as if enqueueing (no break statement)
case PlaylistAddBehaviour_Enqueue:
dummyIndexList.append(index);
app_->playlist_manager()->current()->queue()->ToggleTracks(
dummyIndexList);
switch (doubleclick_playlist_playmode_) {
case PlaylistPlayBehaviour_Always:
case PlaylistPlayBehaviour_IfStopped:
if (app_->player()->GetState() != Engine::Playing) {
app_->player()->PlayAt(
app_->playlist_manager()->current()->queue()->TakeNext(),
Engine::Manual, true);
}
break;
case PlaylistPlayBehaviour_Never:
// deliberately do nothing here
break;
}
break;

case PlaylistAddBehaviour_Nothing:
// deliberately do nothing here
break;
}
}

void MainWindow::VolumeWheelEvent(int delta) {
ui_->volume->setValue(ui_->volume->value() + delta / 30);
}
Expand Down
18 changes: 18 additions & 0 deletions src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ class MainWindow : public QMainWindow, public PlatformInterface {
PlayBehaviour_Always = 3,
};

// Don't change the values
enum PlaylistAddBehaviour {
PlaylistAddBehaviour_Play = 1,
PlaylistAddBehaviour_Enqueue = 2,
PlaylistAddBehaviour_PlayNext = 3,
PlaylistAddBehaviour_Nothing = 4
};

// Don't change the values
enum PlaylistPlayBehaviour {
PlaylistPlayBehaviour_Never = 1,
PlaylistPlayBehaviour_IfStopped = 2,
PlaylistPlayBehaviour_Always = 3,
};

void SetHiddenInTray(bool hidden);
void CommandlineOptionsReceived(const CommandlineOptions& options);

Expand Down Expand Up @@ -178,6 +193,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void ChangeLibraryQueryMode(QAction* action);

void PlayIndex(const QModelIndex& index);
void PlaylistDoubleClick(const QModelIndex& index);
void StopAfterCurrent();

void SongChanged(const Song& song);
Expand Down Expand Up @@ -362,6 +378,8 @@ class MainWindow : public QMainWindow, public PlatformInterface {
Engine::State saved_playback_state_;
AddBehaviour doubleclick_addmode_;
PlayBehaviour doubleclick_playmode_;
PlaylistAddBehaviour doubleclick_playlist_addmode_;
PlaylistPlayBehaviour doubleclick_playlist_playmode_;
PlayBehaviour menu_playmode_;

BackgroundStreams* background_streams_;
Expand Down