mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-14 18:35:16 +01:00
Added iPod-like behavior to previous button
This commit is contained in:
parent
a61eac109c
commit
1120f97844
@ -32,6 +32,7 @@
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QtDebug>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QSettings>
|
||||
|
||||
#include "config.h"
|
||||
#include "core/application.h"
|
||||
@ -50,6 +51,8 @@
|
||||
|
||||
using std::shared_ptr;
|
||||
|
||||
const char* Player::kSettingsGroup = "Player";
|
||||
|
||||
Player::Player(Application* app, QObject* parent)
|
||||
: PlayerInterface(parent),
|
||||
app_(app),
|
||||
@ -58,7 +61,8 @@ Player::Player(Application* app, QObject* parent)
|
||||
stream_change_type_(Engine::First),
|
||||
last_state_(Engine::Empty),
|
||||
nb_errors_received_(0),
|
||||
volume_before_mute_(50) {
|
||||
volume_before_mute_(50),
|
||||
last_pressed_previous_(QDateTime::currentDateTime()) {
|
||||
settings_.beginGroup("Player");
|
||||
|
||||
SetVolume(settings_.value("volume", 50).toInt());
|
||||
@ -90,7 +94,16 @@ void Player::Init() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Player::ReloadSettings() { engine_->ReloadSettings(); }
|
||||
void Player::ReloadSettings() {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
menu_previousmode_ = PreviousBehaviour(
|
||||
s.value("menu_previousmode", PreviousBehaviour_DontRestart).toInt());
|
||||
s.endGroup();
|
||||
|
||||
engine_->ReloadSettings();
|
||||
}
|
||||
|
||||
void Player::HandleLoadResult(const UrlHandler::LoadResult& result) {
|
||||
switch (result.type_) {
|
||||
@ -290,6 +303,18 @@ void Player::Previous() { PreviousItem(Engine::Manual); }
|
||||
void Player::PreviousItem(Engine::TrackChangeFlags change) {
|
||||
const bool ignore_repeat_track = change & Engine::Manual;
|
||||
|
||||
if (menu_previousmode_ == PreviousBehaviour_Restart) {
|
||||
// Check if it has been over two seconds since previous button was pressed
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
if (last_pressed_previous_.isValid() &&
|
||||
last_pressed_previous_.secsTo(now) >= 2) {
|
||||
last_pressed_previous_ = now;
|
||||
PlayAt(app_->playlist_manager()->active()->current_row(), change, false);
|
||||
return;
|
||||
}
|
||||
last_pressed_previous_ = now;
|
||||
}
|
||||
|
||||
int i = app_->playlist_manager()->active()->previous_row(ignore_repeat_track);
|
||||
app_->playlist_manager()->active()->set_current_row(i);
|
||||
if (i == -1) {
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "config.h"
|
||||
#include "core/song.h"
|
||||
@ -91,7 +92,7 @@ class PlayerInterface : public QObject {
|
||||
virtual void Play() = 0;
|
||||
virtual void ShowOSD() = 0;
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void Playing();
|
||||
void Paused();
|
||||
void Stopped();
|
||||
@ -119,6 +120,14 @@ class Player : public PlayerInterface {
|
||||
explicit Player(Application* app, QObject* parent = nullptr);
|
||||
~Player();
|
||||
|
||||
static const char* kSettingsGroup;
|
||||
|
||||
// Don't change the values
|
||||
enum PreviousBehaviour {
|
||||
PreviousBehaviour_DontRestart = 1,
|
||||
PreviousBehaviour_Restart = 2
|
||||
};
|
||||
|
||||
void Init();
|
||||
|
||||
EngineBase* engine() const { return engine_.get(); }
|
||||
@ -197,6 +206,9 @@ class Player : public PlayerInterface {
|
||||
QUrl loading_async_;
|
||||
|
||||
int volume_before_mute_;
|
||||
|
||||
QDateTime last_pressed_previous_;
|
||||
PreviousBehaviour menu_previousmode_;
|
||||
};
|
||||
|
||||
#endif // CORE_PLAYER_H_
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "behavioursettingspage.h"
|
||||
#include "mainwindow.h"
|
||||
#include "core/player.h"
|
||||
#include "ui_behavioursettingspage.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "playlist/playlisttabbar.h"
|
||||
@ -50,6 +51,9 @@ BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog* dialog)
|
||||
ui_->menu_playmode->setItemData(1, MainWindow::PlayBehaviour_IfStopped);
|
||||
ui_->menu_playmode->setItemData(2, MainWindow::PlayBehaviour_Always);
|
||||
|
||||
ui_->menu_previousmode->setItemData(0, Player::PreviousBehaviour_DontRestart);
|
||||
ui_->menu_previousmode->setItemData(1, Player::PreviousBehaviour_Restart);
|
||||
|
||||
// Populate the language combo box. We do this by looking at all the
|
||||
// compiled in translations.
|
||||
QDir dir(":/translations/");
|
||||
@ -180,6 +184,10 @@ void BehaviourSettingsPage::Save() {
|
||||
MainWindow::PlayBehaviour menu_playmode = MainWindow::PlayBehaviour(
|
||||
ui_->menu_playmode->itemData(ui_->menu_playmode->currentIndex()).toInt());
|
||||
|
||||
Player::PreviousBehaviour menu_previousmode = Player::PreviousBehaviour(
|
||||
ui_->menu_previousmode->itemData(ui_->menu_previousmode->currentIndex())
|
||||
.toInt());
|
||||
|
||||
Playlist::Path path = Playlist::Path_Automatic;
|
||||
if (ui_->b_automatic_path->isChecked()) {
|
||||
path = Playlist::Path_Automatic;
|
||||
@ -202,6 +210,10 @@ void BehaviourSettingsPage::Save() {
|
||||
ui_->resume_after_start_->isChecked());
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup(Player::kSettingsGroup);
|
||||
s.setValue("menu_previousmode", menu_previousmode);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("General");
|
||||
s.setValue("language", language_map_.contains(ui_->language->currentText())
|
||||
? language_map_[ui_->language->currentText()]
|
||||
|
@ -177,6 +177,32 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_previous">
|
||||
<property name="title">
|
||||
<string>Pressing "Previous" in player will...</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_18">
|
||||
<item>
|
||||
<widget class="QComboBox" name="menu_previousmode">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Jump to previous song right away</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Restart song, then jump to previous if pressed again (iPod behavior)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_7">
|
||||
<property name="title">
|
||||
|
@ -216,6 +216,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
|
||||
int volume = app_->player()->GetVolume();
|
||||
ui_->volume->setValue(volume);
|
||||
VolumeChanged(volume);
|
||||
app_->player()->ReloadSettings();
|
||||
|
||||
// Initialise the global search widget
|
||||
StyleHelper::setBaseColor(palette().color(QPalette::Highlight).darker());
|
||||
|
Loading…
Reference in New Issue
Block a user