diff --git a/kcontrol/CMakeLists.txt b/kcontrol/CMakeLists.txt index bf411b53..7159df16 100644 --- a/kcontrol/CMakeLists.txt +++ b/kcontrol/CMakeLists.txt @@ -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 ) diff --git a/kcontrol/access/kaccess.cpp b/kcontrol/access/kaccess.cpp index 448175d5..1e2dd6cc 100644 --- a/kcontrol/access/kaccess.cpp +++ b/kcontrol/access/kaccess.cpp @@ -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); } diff --git a/kcontrol/access/kaccess.desktop b/kcontrol/access/kaccess.desktop index 3e0262ea..095a2a5c 100644 --- a/kcontrol/access/kaccess.desktop +++ b/kcontrol/access/kaccess.desktop @@ -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 diff --git a/kcontrol/access/kaccess.h b/kcontrol/access/kaccess.h index f7ec8643..8791f775 100644 --- a/kcontrol/access/kaccess.h +++ b/kcontrol/access/kaccess.h @@ -17,7 +17,6 @@ #undef explicit class KDialog; -#include class KComboBox; class KAccessApp : public KUniqueApplication diff --git a/kcontrol/mediaplayer/CMakeLists.txt b/kcontrol/mediaplayer/CMakeLists.txt new file mode 100644 index 00000000..ca13a8e0 --- /dev/null +++ b/kcontrol/mediaplayer/CMakeLists.txt @@ -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}) + + diff --git a/kcontrol/mediaplayer/kcmplayer.cpp b/kcontrol/mediaplayer/kcmplayer.cpp new file mode 100644 index 00000000..fc3168fd --- /dev/null +++ b/kcontrol/mediaplayer/kcmplayer.cpp @@ -0,0 +1,220 @@ +/* This file is part of the KDE libraries + Copyright (C) 2016 Ivailo Monev + + 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kcmplayer.h" +#include "ui_kcmplayer.h" + +K_PLUGIN_FACTORY(PlayerFactory, registerPlugin();) +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" diff --git a/kcontrol/mediaplayer/kcmplayer.desktop b/kcontrol/mediaplayer/kcmplayer.desktop new file mode 100644 index 00000000..9150cd19 --- /dev/null +++ b/kcontrol/mediaplayer/kcmplayer.desktop @@ -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; diff --git a/kcontrol/mediaplayer/kcmplayer.h b/kcontrol/mediaplayer/kcmplayer.h new file mode 100644 index 00000000..f9fd926b --- /dev/null +++ b/kcontrol/mediaplayer/kcmplayer.h @@ -0,0 +1,58 @@ +/* This file is part of the KDE libraries + Copyright (C) 2016 Ivailo Monev + + 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 +#include +#include + +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 diff --git a/kcontrol/mediaplayer/kcmplayer.ui b/kcontrol/mediaplayer/kcmplayer.ui new file mode 100644 index 00000000..81025af8 --- /dev/null +++ b/kcontrol/mediaplayer/kcmplayer.ui @@ -0,0 +1,197 @@ + + + KCMPlayer + + + + 0 + 0 + 526 + 344 + + + + Form + + + + + + 0 + + + + Global + + + + + + Audio output + + + + + + + + + + Volume + + + + + + + Qt::Vertical + + + + 359 + 193 + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + Mute + + + + + + + <html><head/><body><p><span style=" font-weight:600;">Global settings do not override per-application settings, they apply to applications which have not been setup yet</span></p></body></html> + + + Qt::RichText + + + true + + + + + + + + Applications + + + + + + Application + + + + + + + + 0 + 0 + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Audio output + + + + + + + + + + Volume + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + Mute + + + + + + + Qt::Vertical + + + + 433 + 134 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + diff --git a/knotify/knotify4.desktop b/knotify/knotify4.desktop index dcce2580..a204c668 100644 --- a/knotify/knotify4.desktop +++ b/knotify/knotify4.desktop @@ -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 diff --git a/knotify/notifybysound.cpp b/knotify/notifybysound.cpp index b0b7ad62..ff20ee37 100644 --- a/knotify/notifybysound.cpp +++ b/knotify/notifybysound.cpp @@ -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); diff --git a/renamedlgplugins/audio/audiopreview.cpp b/renamedlgplugins/audio/audiopreview.cpp index 624d855a..d6f6c955 100644 --- a/renamedlgplugins/audio/audiopreview.cpp +++ b/renamedlgplugins/audio/audiopreview.cpp @@ -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 ) diff --git a/renamedlgplugins/audio/renaudiodlg.desktop b/renamedlgplugins/audio/renaudiodlg.desktop index cac17681..0257d5ac 100644 --- a/renamedlgplugins/audio/renaudiodlg.desktop +++ b/renamedlgplugins/audio/renaudiodlg.desktop @@ -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