| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #include "gui/settings/settingsmediaplayer.h" |
| 4 | |
| 5 | #include "miscellaneous/application.h" |
| 6 | #include "miscellaneous/iconfactory.h" |
| 7 | #include "miscellaneous/settings.h" |
| 8 | |
| 9 | #if defined(ENABLE_MEDIAPLAYER_LIBMPV) |
| 10 | #include "gui/dialogs/filedialog.h" |
| 11 | #include "gui/mediaplayer/libmpv/libmpvbackend.h" |
| 12 | |
| 13 | #include <mpv/client.h> |
| 14 | #endif |
| 15 | |
| 16 | SettingsMediaPlayer::SettingsMediaPlayer(Settings* settings, QWidget* parent) : SettingsPanel(settings, parent) { |
| 17 | m_ui.setupUi(this); |
| 18 | } |
| 19 | |
| 20 | QIcon SettingsMediaPlayer::icon() const { |
| 21 | return qApp->icons()->fromTheme(QSL("kmplayer"), QSL("smplayer")); |
| 22 | } |
| 23 | |
| 24 | void SettingsMediaPlayer::loadSettings() { |
| 25 | connect(m_ui.m_gbMpvCustomConfigFolder, &QGroupBox::toggled, this, &SettingsMediaPlayer::dirtifySettings); |
| 26 | connect(m_ui.m_txtMpvConfigFolder, &QLineEdit::textChanged, this, &SettingsMediaPlayer::dirtifySettings); |
| 27 | |
| 28 | onBeginLoadSettings(); |
| 29 | |
| 30 | #if defined(ENABLE_MEDIAPLAYER_LIBMPV) |
| 31 | m_ui.m_txtBackend->setText(QSL("libmpv")); |
| 32 | m_ui.m_helpInfo->setHelpText(tr("You use modern libmpv-based media player backend with API version %1.") |
| 33 | .arg(mpv_client_api_version()), |
| 34 | false); |
| 35 | m_ui.m_stackedDetails->setCurrentWidget(m_ui.m_pageLibmpv); |
| 36 | |
| 37 | m_ui.m_gbMpvCustomConfigFolder |
| 38 | ->setChecked(settings()->value(GROUP(VideoPlayer), SETTING(VideoPlayer::MpvUseCustomConfigFolder)).toBool()); |
| 39 | m_ui.m_txtMpvConfigFolder->setText(QDir::toNativeSeparators(settings() |
| 40 | ->value(GROUP(VideoPlayer), |
| 41 | SETTING(VideoPlayer::MpvCustomConfigFolder)) |
| 42 | .toString())); |
| 43 | |
| 44 | connect(m_ui.m_btnMpvConfigFolder, &QPushButton::clicked, this, &SettingsMediaPlayer::selectMpvConfigFolder); |
| 45 | #elif defined(ENABLE_MEDIAPLAYER_QTMULTIMEDIA) |
| 46 | m_ui.m_txtBackend->setText(QSL("QtMultimedia")); |
| 47 | m_ui.m_helpInfo->setHelpText(tr("You use lightweight QtMultimedia-based media player backend. If some videos do not " |
| 48 | "play, then you likely need to install some codecs."), |
| 49 | false); |
| 50 | m_ui.m_stackedDetails->setCurrentWidget(m_ui.m_pageQtMultimedia); |
| 51 | #else |
| 52 | m_ui.m_txtBackend->setText(tr("no backend installed")); |
| 53 | m_ui.m_helpInfo->setHelpText(tr("You do not have any media player available. Media player is only supported on " |
| 54 | "modern platforms where needed libraries are available. You must manually recompile " |
| 55 | "%1 to be able to use media player.") |
| 56 | .arg(QSL(APP_NAME)), |
| 57 | true); |
| 58 | m_ui.m_stackedDetails->setCurrentWidget(m_ui.m_pageNothing); |
| 59 | #endif |
| 60 | |
| 61 | onEndLoadSettings(); |
| 62 | } |
| 63 | |
| 64 | #if defined(ENABLE_MEDIAPLAYER_LIBMPV) |
| 65 | void SettingsMediaPlayer::selectMpvConfigFolder() { |
| 66 | QString real_path = qApp->replaceUserDataFolderPlaceholder(m_ui.m_txtMpvConfigFolder->text()); |
| 67 | QString directory = FileDialog::existingDirectory(this, |
| 68 | tr("Select folder for your MPV configuration"), |
| 69 | real_path, |
| 70 | GENERAL_REMEMBERED_PATH); |
| 71 | |
| 72 | if (!directory.isEmpty()) { |
| 73 | m_ui.m_txtMpvConfigFolder->setText(QDir::toNativeSeparators(directory)); |
| 74 | } |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | void SettingsMediaPlayer::saveSettings() { |
| 79 | onBeginSaveSettings(); |
| 80 | |
| 81 | #if defined(ENABLE_MEDIAPLAYER_LIBMPV) |
| 82 | settings()->setValue(GROUP(VideoPlayer), |
| 83 | VideoPlayer::MpvUseCustomConfigFolder, |
| 84 | m_ui.m_gbMpvCustomConfigFolder->isChecked()); |
| 85 | settings()->setValue(GROUP(VideoPlayer), VideoPlayer::MpvCustomConfigFolder, m_ui.m_txtMpvConfigFolder->text()); |
| 86 | |
| 87 | if (m_ui.m_gbMpvCustomConfigFolder->isChecked()) { |
| 88 | LibMpvBackend::installCustomConfig(m_ui.m_txtMpvConfigFolder->text()); |
| 89 | } |
| 90 | #elif defined(ENABLE_MEDIAPLAYER_QTMULTIMEDIA) |
| 91 | |
| 92 | #else |
| 93 | |
| 94 | #endif |
| 95 | |
| 96 | onEndSaveSettings(); |
| 97 | } |