generic: adjust to media classes changes

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-02-26 09:57:00 +02:00
parent b4a0ab12b3
commit f58eba713f
13 changed files with 517 additions and 8 deletions

View file

@ -31,6 +31,7 @@ add_subdirectory( locale )
add_subdirectory( kded )
add_subdirectory( knotify )
add_subdirectory( componentchooser )
add_subdirectory( mediaplayer )
add_subdirectory( menus )
add_subdirectory( dnssd )
add_subdirectory( emoticons )

View file

@ -477,6 +477,7 @@ void KAccessApp::xkbBellNotify(XkbBellNotifyEvent *event)
// as creating the player is expensive, delay the creation
if (!_player) {
_player = new KAudioPlayer(this);
_player->setPlayerID("kaccess");
}
_player->load(_currentPlayerSource);
}

View file

@ -91,7 +91,9 @@ Name[x-test]=xxKDE Accessibility Toolxx
Name[zh_CN]=KDE
Name[zh_TW]=KDE
Exec=kaccess
Icon=preferences-desktop-accessibility
X-DBUS-StartupType=None
X-KDE-Library=kcm_access
X-KDE-ParentApp=kcontrol
X-DocPath=kcontrol/kcmaccess/index.html
X-KDE-MediaPlayer=kaccess

View file

@ -17,7 +17,6 @@
#undef explicit
class KDialog;
#include <QLabel>
class KComboBox;
class KAccessApp : public KUniqueApplication

View file

@ -0,0 +1,14 @@
########### next target ###############
kde4_add_plugin(kcm_kmediaplayer kcmplayer.cpp)
target_link_libraries(kcm_kmediaplayer
${KDE4_KIO_LIBS}
KDE4::kmediaplayer
)
install(TARGETS kcm_kmediaplayer DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
install(FILES kcmplayer.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})

View file

@ -0,0 +1,220 @@
/* This file is part of the KDE libraries
Copyright (C) 2016 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kaboutdata.h>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <kdesktopfile.h>
#include <kconfiggroup.h>
#include <kservice.h>
#include <kicon.h>
#include "kcmplayer.h"
#include "ui_kcmplayer.h"
K_PLUGIN_FACTORY(PlayerFactory, registerPlugin<KCMPlayer>();)
K_EXPORT_PLUGIN(PlayerFactory("kcmplayer"))
KCMPlayer::KCMPlayer(QWidget *parent, const QVariantList &arguments)
: KCModule(PlayerFactory::componentData(), parent)
{
m_ui = new Ui_KCMPlayer();
m_ui->setupUi(this);
m_settings = new KSettings("kmediaplayer", KSettings::FullConfig);
setButtons(KCModule::Default | KCModule::Apply);
KAboutData* ab = new KAboutData(
"kcmplayer", 0, ki18n("KMediaPlayer"), "1.0",
ki18n("System Media Player Configuration"),
KAboutData::License_GPL, ki18n("(c) 2016 Ivailo Monev"));
ab->addAuthor(ki18n("Ivailo Monev"), KLocalizedString(), "xakepa10@gmail.com");
setAboutData(ab);
Q_UNUSED(arguments);
const QString globalaudio = m_settings->value("global/audiooutput", "auto").toString();
const int globalvolume = m_settings->value("global/volume", 90).toInt();
const bool globalmute = m_settings->value("global/mute", false).toBool();
KAudioPlayer player(this);
const QStringList audiooutputs = player.audiooutputs();
player.deleteLater();
m_ui->w_audiooutput->addItems(audiooutputs);
m_ui->w_appaudiooutput->addItems(audiooutputs);
const int audioindex = m_ui->w_audiooutput->findText(globalaudio);
m_ui->w_audiooutput->setCurrentIndex(audioindex);
m_ui->w_volume->setValue(globalvolume);
m_ui->w_mute->setChecked(globalmute);
connect(m_ui->w_audiooutput, SIGNAL(currentIndexChanged(QString)),
this, SLOT(setGlobalOutput(QString)));
connect(m_ui->w_volume, SIGNAL(valueChanged(int)),
this, SLOT(setGlobalVolume(int)));
connect(m_ui->w_mute, SIGNAL(stateChanged(int)),
this, SLOT(setGlobalMute(int)));
// NOTE: this catches all .desktop files
const KService::List servicefiles = KService::allServices();
foreach (const KService::Ptr service, servicefiles ) {
const QStringList servids = service.data()->property("X-KDE-MediaPlayer", QVariant::StringList).toStringList();
const KIcon servicon = KIcon(service.data()->icon());
foreach (const QString &id, servids) {
m_ui->w_application->addItem(servicon, id);
}
}
connect(m_ui->w_application, SIGNAL(currentIndexChanged(QString)),
this, SLOT(setApplicationSettings(QString)));
connect(m_ui->w_appaudiooutput, SIGNAL(currentIndexChanged(QString)),
this, SLOT(setApplicationOutput(QString)));
connect(m_ui->w_appvolume, SIGNAL(valueChanged(int)),
this, SLOT(setApplicationVolume(int)));
connect(m_ui->w_appmute, SIGNAL(stateChanged(int)),
this, SLOT(setApplicationMute(int)));
}
KCMPlayer::~KCMPlayer()
{
m_settings->sync();
delete m_settings;
delete m_ui;
}
void KCMPlayer::defaults()
{
// TODO:
}
void KCMPlayer::load()
{
// Qt::MatchFixedString is basicly case-insensitive
const int appindex = m_ui->w_application->findText(QCoreApplication::applicationName(), Qt::MatchFixedString);
if (appindex >= 0) {
m_ui->w_application->setCurrentIndex(appindex);
} else {
// just to load the appplication values
m_ui->w_application->setCurrentIndex(1);
m_ui->w_application->setCurrentIndex(0);
}
emit changed(false);
}
void KCMPlayer::save()
{
if (m_settings && m_settings->isWritable()) {
m_settings->setValue("global/audiooutput", m_ui->w_audiooutput->currentText());
m_settings->setValue("global/volume", m_ui->w_volume->value());
m_settings->setValue("global/mute", m_ui->w_mute->isChecked());
m_settings->sync();
} else {
kWarning() << i18n("Could not save global state");
}
if (!m_application.isEmpty()) {
if (m_settings && m_settings->isWritable()) {
m_settings->setValue(m_application + "/audiooutput", m_ui->w_appaudiooutput->currentText());
m_settings->setValue(m_application + "/volume", m_ui->w_appvolume->value());
m_settings->setValue(m_application + "/mute", m_ui->w_appmute->isChecked());
m_settings->sync();
} else {
kWarning() << i18n("Could not save application state");
}
}
emit changed(false);
}
void KCMPlayer::setGlobalOutput(QString output)
{
kDebug() << output;
if (m_settings->value("global/audiooutput").toString() != output) {
emit changed(true);
} else {
emit changed(false);
}
}
void KCMPlayer::setGlobalVolume(int volume)
{
kDebug() << volume;
if (m_settings->value("global/volume").toInt() != volume) {
emit changed(true);
} else {
emit changed(false);
}
}
void KCMPlayer::setGlobalMute(int mute)
{
kDebug() << mute;
if (m_settings->value("global/mute").toBool() != bool(mute)) {
emit changed(true);
} else {
emit changed(false);
}
}
void KCMPlayer::setApplicationSettings(QString application)
{
m_application = application;
QString appaudio = m_settings->value(m_application + "/audiooutput", "auto").toString();
int appvolume = m_settings->value(m_application + "/volume", 90).toInt();
bool appmute = m_settings->value(m_application +"/mute", false).toBool();
const int audioindex = m_ui->w_appaudiooutput->findText(appaudio);
m_ui->w_appaudiooutput->setCurrentIndex(audioindex);
m_ui->w_appvolume->setValue(appvolume);
m_ui->w_appmute->setChecked(appmute);
}
void KCMPlayer::setApplicationOutput(QString output)
{
kDebug() << output;
if (m_settings->value(m_application + "/audiooutput").toString() != output) {
emit changed(true);
} else {
emit changed(false);
}
}
void KCMPlayer::setApplicationVolume(int volume)
{
kDebug() << volume;
if (m_settings->value(m_application + "/volume").toInt() != volume) {
emit changed(true);
} else {
emit changed(false);
}
}
void KCMPlayer::setApplicationMute(int mute)
{
kDebug() << mute;
if (m_settings->value(m_application + "/mute").toBool() != bool(mute)) {
emit changed(true);
} else {
emit changed(false);
}
}
#include "moc_kcmplayer.cpp"

View file

@ -0,0 +1,16 @@
[Desktop Entry]
Exec=kcmshell4 kcmplayer
Icon=preferences-desktop-sound
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kcm_kmediaplayer
X-KDE-ParentApp=kcontrol
X-KDE-System-Settings-Parent-Category=audio-and-video
X-KDE-Weight=50
Name=Media Player
Comment=System Media Player Configuration
X-KDE-Keywords=AudioVideo,Audio,Video
Categories=Qt;KDE;X-KDE-settings-sound;

View file

@ -0,0 +1,58 @@
/* This file is part of the KDE libraries
Copyright (C) 2016 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCMPLAYER_H
#define KCMPLAYER_H
#include <kcmodule.h>
#include <kmediaplayer.h>
#include <ksettings.h>
QT_BEGIN_NAMESPACE
class Ui_KCMPlayer;
QT_END_NAMESPACE
class KCMPlayer : public KCModule
{
Q_OBJECT
public:
KCMPlayer(QWidget *parent, const QVariantList &arguments);
~KCMPlayer();
public slots:
void defaults();
void save();
void load();
void setGlobalOutput(QString output);
void setGlobalVolume(int volume);
void setGlobalMute(int mute);
void setApplicationSettings(QString application);
void setApplicationOutput(QString output);
void setApplicationVolume(int volume);
void setApplicationMute(int mute);
private:
Ui_KCMPlayer *m_ui;
KSettings *m_settings;
QString m_application;
};
#endif // KCMPLAYER_H

View file

@ -0,0 +1,197 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KCMPlayer</class>
<widget class="QWidget" name="KCMPlayer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>526</width>
<height>344</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Global</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Audio output</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="w_audiooutput"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Volume</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>359</width>
<height>193</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QSlider" name="w_volume">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="w_mute">
<property name="text">
<string>Mute</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Global settings do not override per-application settings, they apply to applications which have not been setup yet&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Applications</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Application</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="w_application">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Audio output</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="w_appaudiooutput"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Volume</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="w_appvolume">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="w_appmute">
<property name="text">
<string>Mute</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>433</width>
<height>134</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -177,4 +177,4 @@ Icon=preferences-desktop-notification
X-DBUS-ServiceName=org.kde.knotify
X-DBUS-StartupType=Unique
X-KDE-StartupNotify=false
X-KDE-MediaPlayer=true
X-KDE-MediaPlayer=knotify

View file

@ -60,6 +60,7 @@ NotifyBySound::NotifyBySound(QObject *parent) : KNotifyPlugin(parent),d(new Priv
connect(d->signalmapper, SIGNAL(mapped(int)), this, SLOT(slotSoundFinished(int)));
d->currentPlayer = new KAudioPlayer(this);
d->currentPlayer->setPlayerID("knotify");
loadConfig();
}
@ -124,6 +125,7 @@ void NotifyBySound::notify( int eventId, KNotifyConfig * config )
if (d->currentPlayer && d->currentPlayer->isPlaying()) {
kDebug() << "creating new player";
player = new KAudioPlayer(this);
player->setPlayerID("knotify");
}
connect(player, SIGNAL(finished()), d->signalmapper, SLOT(map()));
d->signalmapper->setMapping(player, eventId);

View file

@ -111,12 +111,9 @@ void AudioPreview::initView( const QString& mimeType )
description->setText( desc );
description->adjustSize();
m_player = new KMediaWidget( this );
if ( m_player )
{
m_player->show();
m_player->open( url.url() );
}
m_player->player()->setPlayerID("audio_rename_plugin");
m_player->show();
m_player->open( url.url() );
}
void AudioPreview::downloadFile( const QString& url )

View file

@ -1,5 +1,6 @@
[Desktop Entry]
Type=Service
Icon=edit-rename
Name=Audio Preview
Name[af]=Klankvoorskou
Name[ar]=معاينة صوت
@ -85,3 +86,4 @@ Name[zh_CN]=音频预览
Name[zh_TW]=
X-KDE-Library=librenaudioplugin
X-KDE-ServiceTypes=RenameDialog/Plugin,audio/mpeg,audio/x-wav,application/ogg
X-KDE-MediaPlayer=audio_rename_plugin