mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-30 19:15:08 +01:00
Add an option to restart playback when starting.
Fixes issue 359.
This commit is contained in:
parent
f68f6ddf42
commit
9504bb7653
@ -99,6 +99,7 @@ void BehaviourSettingsPage::Load() {
|
||||
case MainWindow::Startup_AlwaysShow: ui_->b_always_show_->setChecked(true); break;
|
||||
case MainWindow::Startup_Remember: ui_->b_remember_->setChecked(true); break;
|
||||
}
|
||||
ui_->resume_after_start_->setChecked(s.value("resume_playback_after_start", false).toBool());
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("General");
|
||||
@ -136,6 +137,7 @@ void BehaviourSettingsPage::Save() {
|
||||
s.setValue("doubleclick_addmode", doubleclick_addmode);
|
||||
s.setValue("doubleclick_playmode", doubleclick_playmode);
|
||||
s.setValue("menu_playmode", menu_playmode);
|
||||
s.setValue("resume_playback_after_start", ui_->resume_after_start_->isChecked());
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("General");
|
||||
|
@ -102,6 +102,16 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="resume_after_start_">
|
||||
<property name="text">
|
||||
<string>Resume playback on start</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="b_grey_out_deleted_">
|
||||
<property name="text">
|
||||
|
@ -192,6 +192,8 @@ MainWindow::MainWindow(Application* app,
|
||||
library_sort_model_(new QSortFilterProxyModel(this)),
|
||||
track_position_timer_(new QTimer(this)),
|
||||
was_maximized_(false),
|
||||
saved_playback_position_(0),
|
||||
saved_playback_state_(Engine::Empty),
|
||||
doubleclick_addmode_(AddBehaviour_Append),
|
||||
doubleclick_playmode_(PlayBehaviour_IfStopped),
|
||||
menu_playmode_(PlayBehaviour_IfStopped)
|
||||
@ -754,6 +756,8 @@ MainWindow::MainWindow(Application* app,
|
||||
|
||||
CheckFullRescanRevisions();
|
||||
|
||||
LoadPlaybackStatus();
|
||||
|
||||
qLog(Debug) << "Started";
|
||||
}
|
||||
|
||||
@ -963,6 +967,45 @@ void MainWindow::SaveGeometry() {
|
||||
settings_.setValue("tab_mode", ui_->tabs->mode());
|
||||
}
|
||||
|
||||
void MainWindow::SavePlaybackStatus() {
|
||||
QSettings settings;
|
||||
settings.beginGroup(MainWindow::kSettingsGroup);
|
||||
settings.setValue("playback_state", app_->player()->GetState());
|
||||
if (app_->player()->GetState() == Engine::Playing ||
|
||||
app_->player()->GetState() == Engine::Paused) {
|
||||
settings.setValue("playback_position", app_->player()->engine()->position_nanosec() / kNsecPerSec);
|
||||
} else {
|
||||
settings.setValue("playback_position", 0);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::LoadPlaybackStatus() {
|
||||
QSettings settings;
|
||||
settings.beginGroup(MainWindow::kSettingsGroup);
|
||||
bool resume_playback = settings.value("resume_playback_after_start", false).toBool();
|
||||
saved_playback_state_ = static_cast<Engine::State>
|
||||
(settings.value("playback_state", Engine::Empty).toInt());
|
||||
saved_playback_position_ = settings.value("playback_position", 0).toDouble();
|
||||
if (!resume_playback ||
|
||||
saved_playback_state_ == Engine::Empty ||
|
||||
saved_playback_state_ == Engine::Idle) {
|
||||
return;
|
||||
}
|
||||
|
||||
QTimer::singleShot(100, this, SLOT(ResumePlayback()));
|
||||
}
|
||||
|
||||
void MainWindow::ResumePlayback() {
|
||||
qLog(Debug) << "Resuming playback";
|
||||
app_->player()->Play();
|
||||
|
||||
app_->player()->SeekTo(saved_playback_position_);
|
||||
|
||||
if (saved_playback_state_ == Engine::Paused) {
|
||||
app_->player()->Pause();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::PlayIndex(const QModelIndex& index) {
|
||||
if (!index.isValid())
|
||||
return;
|
||||
@ -2098,6 +2141,7 @@ bool MainWindow::winEvent(MSG* msg, long*) {
|
||||
#endif // Q_OS_WIN32
|
||||
|
||||
void MainWindow::Exit() {
|
||||
SavePlaybackStatus();
|
||||
if(app_->player()->engine()->is_fadeout_enabled()) {
|
||||
// To shut down the application when fadeout will be finished
|
||||
connect(app_->player()->engine(), SIGNAL(FadeoutFinishedSignal()), qApp, SLOT(quit()));
|
||||
|
@ -238,6 +238,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
void ShowSongInfoConfig();
|
||||
|
||||
void SaveGeometry();
|
||||
void SavePlaybackStatus();
|
||||
void LoadPlaybackStatus();
|
||||
void ResumePlayback();
|
||||
|
||||
void AddSongInfoGenerator(smart_playlists::GeneratorPtr gen);
|
||||
|
||||
@ -335,6 +338,8 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
QSettings settings_;
|
||||
|
||||
bool was_maximized_;
|
||||
int saved_playback_position_;
|
||||
Engine::State saved_playback_state_;
|
||||
AddBehaviour doubleclick_addmode_;
|
||||
PlayBehaviour doubleclick_playmode_;
|
||||
PlayBehaviour menu_playmode_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user