Add option to disable volume control
This commit is contained in:
@@ -87,7 +87,7 @@
|
||||
#include "organise/organisedialog.h"
|
||||
#include "widgets/fancytabwidget.h"
|
||||
#include "widgets/playingwidget.h"
|
||||
#include "widgets/sliderwidget.h"
|
||||
#include "widgets/volumeslider.h"
|
||||
#include "widgets/fileview.h"
|
||||
#include "widgets/multiloadingindicator.h"
|
||||
#include "widgets/osd.h"
|
||||
@@ -131,6 +131,7 @@
|
||||
#include "transcoder/transcodedialog.h"
|
||||
#include "settings/settingsdialog.h"
|
||||
#include "settings/behavioursettingspage.h"
|
||||
#include "settings/backendsettingspage.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#ifdef HAVE_STREAM_TIDAL
|
||||
# include "settings/tidalsettingspage.h"
|
||||
@@ -248,10 +249,6 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
|
||||
context_view_->SetApplication(app_, collection_view_->view(), album_cover_choice_controller_);
|
||||
ui_->widget_playing->SetApplication(app_, album_cover_choice_controller_);
|
||||
|
||||
int volume = app_->player()->GetVolume();
|
||||
ui_->volume->setValue(volume);
|
||||
VolumeChanged(volume);
|
||||
|
||||
// Initialise the search widget
|
||||
StyleHelper::setBaseColor(palette().color(QPalette::Highlight).darker());
|
||||
|
||||
@@ -286,6 +283,9 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
|
||||
app_->player()->SetAnalyzer(ui_->analyzer);
|
||||
app_->player()->SetEqualizer(equalizer_.get());
|
||||
app_->player()->Init();
|
||||
int volume = app_->player()->GetVolume();
|
||||
ui_->volume->setValue(volume);
|
||||
VolumeChanged(volume);
|
||||
|
||||
// Models
|
||||
qLog(Debug) << "Creating models";
|
||||
@@ -830,6 +830,21 @@ void MainWindow::ReloadSettings() {
|
||||
album_cover_choice_controller_->search_cover_auto_action()->setChecked(settings.value("search_for_cover_auto", true).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||
bool volume_control = settings.value("volume_control", true).toBool();
|
||||
settings.endGroup();
|
||||
if (volume_control != ui_->volume->isEnabled()) {
|
||||
ui_->volume->SetEnabled(volume_control);
|
||||
if (volume_control) {
|
||||
if (!ui_->action_mute->isVisible()) ui_->action_mute->setVisible(true);
|
||||
if (tray_icon_ && !tray_icon_->MuteEnabled()) tray_icon_->SetMuteEnabled(true);
|
||||
}
|
||||
else {
|
||||
if (ui_->action_mute->isVisible()) ui_->action_mute->setVisible(false);
|
||||
if (tray_icon_ && tray_icon_->MuteEnabled()) tray_icon_->SetMuteEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_STREAM_TIDAL
|
||||
settings.beginGroup(TidalSettingsPage::kSettingsGroup);
|
||||
bool enable_tidal = settings.value("enabled", false).toBool();
|
||||
|
||||
@@ -225,7 +225,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Amarok::VolumeSlider" name="volume">
|
||||
<widget class="VolumeSlider" name="volume">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -773,9 +773,9 @@
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Amarok::VolumeSlider</class>
|
||||
<class>VolumeSlider</class>
|
||||
<extends>QSlider</extends>
|
||||
<header>widgets/sliderwidget.h</header>
|
||||
<header>widgets/volumeslider.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AnalyzerContainer</class>
|
||||
|
||||
@@ -79,29 +79,30 @@
|
||||
|
||||
using std::shared_ptr;
|
||||
|
||||
const char *Player::kSettingsGroup = "Player";
|
||||
|
||||
Player::Player(Application *app, QObject *parent)
|
||||
: PlayerInterface(parent),
|
||||
app_(app),
|
||||
stream_change_type_(Engine::First),
|
||||
last_state_(Engine::Empty),
|
||||
nb_errors_received_(0),
|
||||
volume_before_mute_(50),
|
||||
volume_before_mute_(100),
|
||||
last_pressed_previous_(QDateTime::currentDateTime()),
|
||||
continue_on_error_(false),
|
||||
greyout_(true),
|
||||
menu_previousmode_(PreviousBehaviour_DontRestart),
|
||||
seek_step_sec_(10) {
|
||||
seek_step_sec_(10),
|
||||
volume_control_(true)
|
||||
{
|
||||
|
||||
settings_.beginGroup(kSettingsGroup);
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||
Engine::EngineType enginetype = Engine::EngineTypeFromName(s.value("engine", EngineName(Engine::GStreamer)).toString().toLower());
|
||||
s.endGroup();
|
||||
|
||||
CreateEngine(enginetype);
|
||||
settings_.beginGroup("Player");
|
||||
|
||||
int volume = settings_.value("volume", 50).toInt();
|
||||
SetVolume(volume);
|
||||
|
||||
}
|
||||
|
||||
@@ -175,6 +176,15 @@ Engine::EngineType Player::CreateEngine(Engine::EngineType enginetype) {
|
||||
|
||||
void Player::Init() {
|
||||
|
||||
QSettings s;
|
||||
|
||||
if (!engine_.get()) {
|
||||
s.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||
Engine::EngineType enginetype = Engine::EngineTypeFromName(s.value("engine", EngineName(Engine::GStreamer)).toString().toLower());
|
||||
s.endGroup();
|
||||
CreateEngine(enginetype);
|
||||
}
|
||||
|
||||
if (!engine_->Init()) { qFatal("Error initialising audio engine"); }
|
||||
|
||||
analyzer_->SetEngine(engine_.get());
|
||||
@@ -188,9 +198,6 @@ void Player::Init() {
|
||||
connect(engine_.get(), SIGNAL(TrackEnded()), SLOT(TrackEnded()));
|
||||
connect(engine_.get(), SIGNAL(MetaData(Engine::SimpleMetaBundle)), SLOT(EngineMetadataReceived(Engine::SimpleMetaBundle)));
|
||||
|
||||
int volume = settings_.value("volume", 50).toInt();
|
||||
engine_->SetVolume(volume);
|
||||
|
||||
// Equalizer
|
||||
qLog(Debug) << "Creating equalizer";
|
||||
connect(equalizer_, SIGNAL(ParametersChanged(int,QList<int>)), app_->player()->engine(), SLOT(SetEqualizerParameters(int,QList<int>)));
|
||||
@@ -201,6 +208,15 @@ void Player::Init() {
|
||||
engine_->SetEqualizerParameters(equalizer_->preamp_value(), equalizer_->gain_values());
|
||||
engine_->SetStereoBalance(equalizer_->stereo_balance());
|
||||
|
||||
s.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||
volume_control_ = s.value("volume_control", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
if (volume_control_) {
|
||||
int volume = settings_.value("volume", 100).toInt();
|
||||
SetVolume(volume);
|
||||
}
|
||||
|
||||
ReloadSettings();
|
||||
|
||||
}
|
||||
@@ -219,6 +235,11 @@ void Player::ReloadSettings() {
|
||||
seek_step_sec_ = s.value("seek_step_sec", 10).toInt();
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||
bool volume_control = s.value("volume_control", true).toBool();
|
||||
if (!volume_control && GetVolume() != 100) SetVolume(100);
|
||||
s.endGroup();
|
||||
|
||||
engine_->ReloadSettings();
|
||||
|
||||
}
|
||||
@@ -631,6 +652,8 @@ PlaylistItemPtr Player::GetItemAt(int pos) const {
|
||||
|
||||
void Player::Mute() {
|
||||
|
||||
if (!volume_control_) return;
|
||||
|
||||
const int current_volume = engine_->volume();
|
||||
|
||||
if (current_volume == 0) {
|
||||
@@ -640,6 +663,7 @@ void Player::Mute() {
|
||||
volume_before_mute_ = current_volume;
|
||||
SetVolume(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Player::Pause() { engine_->Pause(); }
|
||||
|
||||
@@ -102,6 +102,7 @@ class PlayerInterface : public QObject {
|
||||
void Stopped();
|
||||
void Error();
|
||||
void PlaylistFinished();
|
||||
void VolumeEnabled(bool);
|
||||
void VolumeChanged(int volume);
|
||||
void Error(const QString &message);
|
||||
void TrackSkipped(PlaylistItemPtr old_track);
|
||||
@@ -206,10 +207,11 @@ class Player : public PlayerInterface {
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
QSettings settings_;
|
||||
AnalyzerContainer *analyzer_;
|
||||
Equalizer *equalizer_;
|
||||
|
||||
QSettings settings_;
|
||||
|
||||
PlaylistItemPtr current_item_;
|
||||
|
||||
std::unique_ptr<EngineBase> engine_;
|
||||
@@ -228,6 +230,8 @@ class Player : public PlayerInterface {
|
||||
PreviousBehaviour menu_previousmode_;
|
||||
int seek_step_sec_;
|
||||
|
||||
bool volume_control_;
|
||||
|
||||
};
|
||||
|
||||
#endif // PLAYER_H
|
||||
|
||||
@@ -55,6 +55,9 @@ class QtSystemTrayIcon : public SystemTrayIcon {
|
||||
void SetNowPlaying(const Song &song, const QString &image_path);
|
||||
void ClearNowPlaying();
|
||||
|
||||
bool MuteEnabled() { return action_mute_->isVisible(); }
|
||||
void SetMuteEnabled(bool enabled) { action_mute_->setVisible(enabled); }
|
||||
|
||||
protected:
|
||||
// SystemTrayIcon
|
||||
void UpdateIcon();
|
||||
|
||||
@@ -50,6 +50,9 @@ class SystemTrayIcon : public QObject {
|
||||
virtual void SetNowPlaying(const Song &song, const QString &image_path) {}
|
||||
virtual void ClearNowPlaying() {}
|
||||
|
||||
virtual bool MuteEnabled() { return false; }
|
||||
virtual void SetMuteEnabled(bool enabled) {}
|
||||
|
||||
static SystemTrayIcon *CreateSystemTrayIcon(QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
|
||||
Reference in New Issue
Block a user