Skip to content
Open
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
9 changes: 7 additions & 2 deletions kokovp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ KokoVP::KokoVP(QWidget *parent)

KokoVP::~KokoVP()
{
if (Config::i().get("audio/persistent_audio_volume").toBool()) {
//Save player properties here to avoid deadlock
Config::i().set(PlayerController::volumeLevelConfigKey, player->getProp("volume"));
Config::i().set(PlayerController::audioMutedConfigKey, player->getProp("mute"));
}
fileSettings->saveSettingsFor(player->lastOpenFile(), true); // Always save time-pos on exit
}

Expand Down Expand Up @@ -284,7 +289,7 @@ void KokoVP::populateMenu()
BistableAction *muteAct = new BistableAction(Qt::Key_M, audioMenu, "mute");
muteAct->setCheckable(true);
muteAct->setPassiveState(tr("Mute"), QIcon::fromTheme("audio-volume-high"));
muteAct->setActiveState(tr("Mute"), QIcon::fromTheme("audio-volume-muted"));
muteAct->setActiveState(tr("Unmute"), QIcon::fromTheme("audio-volume-muted"));
connect(player->prop("mute"), &PropertyObserver::changedBool, muteAct, &BistableAction::switchState);
connect(muteAct, &QAction::toggled, player->prop("mute"), &PropertyObserver::set);

Expand Down Expand Up @@ -499,7 +504,7 @@ void KokoVP::handleTracks()
}

if (Config::i().get("play_mode/keep_props", true).toBool())
fileSettings->loadSettingsFor(player->currentFile(), Config::i().get("play_mode/keep_timepos", true).toBool());
fileSettings->loadSettingsFor(player->currentFile(), Config::i().get("play_mode/keep_timepos", true).toBool(), Config::i().get("audio/persistent_audio_volume", false).toBool());

player->setProp("pause", false);
}
Expand Down
4 changes: 4 additions & 0 deletions mpv_qthelper.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Originally copied from https://github.com/mpv-player/mpv-examples/blob/master/libmpv/common/qthelper.hpp
*/

#ifndef LIBMPV_QTHELPER_H_
#define LIBMPV_QTHELPER_H_

Expand Down
8 changes: 6 additions & 2 deletions persistency/filesettingshash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ QString FileSettingsHash::configFile(const QString & filename) {
return base_dir +"/"+ hash[0] +"/"+ hash + ".ini";
}

bool FileSettingsHash::loadSettingsFor(QString filename, bool loadTimepos) {
bool FileSettingsHash::loadSettingsFor(QString filename, bool loadTimepos, bool persistentVolume) {
QString config_file = configFile(filename);
if (!QFile::exists(config_file))
return false;
Expand All @@ -55,8 +55,12 @@ bool FileSettingsHash::loadSettingsFor(QString filename, bool loadTimepos) {
QSettings settings(config_file, QSettings::IniFormat);

settings.beginGroup("props");
for (auto &p : persistentProps)
for (auto &p : persistentProps) {
if (persistentVolume && "volume" == p)
continue;
qDebug() << "Loading property " << p << ".\n";
p_player->prop(p)->set(settings.value(p));
}

if (loadTimepos)
p_player->seekAbsolute(settings.value("time-pos").toDouble());
Expand Down
3 changes: 2 additions & 1 deletion persistency/filesettingshash.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class FileSettingsHash : public QObject
Q_OBJECT
public:
FileSettingsHash(QString directory, PlayerController *player, QObject *parent = nullptr);
bool loadSettingsFor(QString filename, bool loadTimepos = true);
bool loadSettingsFor(QString filename, bool loadTimepos = true, bool persistentVolume = false);
bool saveSettingsFor(QString filename, bool saveTimepos = true);

private:
void updateCurrentProps(QVariant value);
QString configFile(const QString & filename);
Expand Down
7 changes: 6 additions & 1 deletion playercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "playercontroller.h"
#include "config.h"
#include "extensions.h"
#include "playerwidget.h"
#include "helper.h"

const QString PlayerController::volumeLevelConfigKey = QString("audio/volume_level");
const QString PlayerController::audioMutedConfigKey = QString("audio/muted");

PlayerController::PlayerController(PlayerWidget *parent)
: QObject{parent}
{
p = parent;
prop("volume")->set(50);
prop("volume")->set(Config::i().get(volumeLevelConfigKey, 50).toInt());
prop("mute")->set(Config::i().get(audioMutedConfigKey, false).toBool());
prop("pause")->set(true);
p->setProp("audio-file-auto-exts", Extensions.audio());
connect(p, &PlayerWidget::fileLoaded, this, &PlayerController::handleFileLoad);
Expand Down
3 changes: 3 additions & 0 deletions playercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class PlayerController : public QObject

explicit PlayerController(PlayerWidget *parent = nullptr);

static const QString volumeLevelConfigKey;
static const QString audioMutedConfigKey;

QString currentFile() { return getProp("path").toString(); }
QString lastOpenFile() { return lastFile; }

Expand Down
2 changes: 2 additions & 0 deletions prefs/prefmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void PrefMain::load()
ui->cbAutoPlayNext->setChecked(Config::i().get("play_mode/next_on_eof").toBool());
ui->cbRememberFileSettings->setChecked(Config::i().get("play_mode/keep_props").toBool());
ui->cbRememberTimePos->setChecked(Config::i().get("play_mode/keep_timepos").toBool());
ui->cbPersistentAudioVolume->setChecked(Config::i().get("audio/persistent_audio_volume").toBool());
ui->cbHwdec->setCurrentIndex(ui->cbHwdec->findData(Config::i().get("misc/hwdec").toString()));

Config::i().beginGroup("steps");
Expand All @@ -65,6 +66,7 @@ void PrefMain::save()
Config::i().set("play_mode/next_on_eof", ui->cbAutoPlayNext->isChecked());
Config::i().set("play_mode/keep_props", ui->cbRememberFileSettings->isChecked());
Config::i().set("play_mode/keep_timepos", ui->cbRememberTimePos->isChecked());
Config::i().set("audio/persistent_audio_volume", ui->cbPersistentAudioVolume->isChecked());
Config::i().set("misc/hwdec", ui->cbHwdec->currentData());

Config::i().beginGroup("steps");
Expand Down
9 changes: 8 additions & 1 deletion prefs/prefmain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbPersistentAudioVolume">
<property name="text">
<string>Persistent Audio Volume</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand Down Expand Up @@ -295,7 +302,7 @@
</customwidget>
</customwidgets>
<resources>
<include location="../icons/res.qrc"/>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>
1 change: 1 addition & 0 deletions singleinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#include "singleinstance.h"

#include <QDebug>
#include <QLocalSocket>
#include <QLocalServer>

Expand Down