diff --git a/kded/plugins/pausemusic/CMakeLists.txt b/kded/plugins/pausemusic/CMakeLists.txt index d49cb7b2b..dc4927290 100644 --- a/kded/plugins/pausemusic/CMakeLists.txt +++ b/kded/plugins/pausemusic/CMakeLists.txt @@ -29,3 +29,19 @@ target_link_libraries(kdeconnect_pausemusic install(TARGETS kdeconnect_pausemusic DESTINATION ${PLUGIN_INSTALL_DIR} ) install(FILES kdeconnect_pausemusic.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +####################################### +# Config + +set( kdeconnect_pausemusic_config_SRCS pausemusic_config.cpp ) +kde4_add_ui_files( kdeconnect_pausemusic_config_SRCS pausemusic_config.ui ) + +kde4_add_plugin( kdeconnect_pausemusic_config ${kdeconnect_pausemusic_config_SRCS} ) +target_link_libraries( kdeconnect_pausemusic_config + ${KDE4_KDECORE_LIBS} + ${KDE4_KDEUI_LIBS} +) + +install( TARGETS kdeconnect_pausemusic_config DESTINATION ${PLUGIN_INSTALL_DIR} ) +install( FILES kdeconnect_pausemusic_config.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) diff --git a/kded/plugins/pausemusic/kdeconnect_pausemusic_config.desktop b/kded/plugins/pausemusic/kdeconnect_pausemusic_config.desktop new file mode 100644 index 000000000..0c12a6a52 --- /dev/null +++ b/kded/plugins/pausemusic/kdeconnect_pausemusic_config.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=KCModule + +X-KDE-Library=kdeconnect_pausemusic_config +X-KDE-ParentComponents=kdeconnect_pausemusic + +Name=Pause Music plugin settings + +Categories=Qt;KDE;X-KDE-settings-kdeconnect; diff --git a/kded/plugins/pausemusic/pausemusic_config.cpp b/kded/plugins/pausemusic/pausemusic_config.cpp new file mode 100644 index 000000000..9d470ead9 --- /dev/null +++ b/kded/plugins/pausemusic/pausemusic_config.cpp @@ -0,0 +1,78 @@ +/** + * Copyright 2013 Albert Vaca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "pausemusic_config.h" + +#include +#include +#include + +#include "../../kdebugnamespace.h" + +#include "ui_pausemusic_config.h" + +K_PLUGIN_FACTORY(PauseMusicConfigFactory, registerPlugin();) +K_EXPORT_PLUGIN(PauseMusicConfigFactory("kdeconnect_pausemusic_config", "kdeconnect_pausemusic_config")) + +PauseMusicConfig::PauseMusicConfig(QWidget *parent, const QVariantList& ) + : KCModule(PauseMusicConfigFactory::componentData(), parent) + , m_ui(new Ui::PauseMusicConfigUi()) + , m_cfg(KSharedConfig::openConfig("kdeconnect/plugins/pausemusic")) +{ + m_ui->setupUi(this); + + connect(m_ui->rad_ringing, SIGNAL(toggled(bool)), this, SLOT(changed())); + connect(m_ui->rad_talking, SIGNAL(toggled(bool)), this, SLOT(changed())); +} + +PauseMusicConfig::~PauseMusicConfig() +{ + delete m_ui; +} + +void PauseMusicConfig::defaults() +{ + KCModule::defaults(); + m_ui->rad_talking->setChecked(false); + m_ui->rad_ringing->setChecked(true); + + Q_EMIT changed(true); +} + + +void PauseMusicConfig::load() +{ + KCModule::load(); + bool talking = m_cfg->group("pause_condition").readEntry("talking_only", false); + m_ui->rad_talking->setChecked(talking); + m_ui->rad_ringing->setChecked(!talking); + + Q_EMIT changed(false); +} + + +void PauseMusicConfig::save() +{ + m_cfg->group("pause_condition").writeEntry("talking_only", m_ui->rad_talking->isChecked()); + KCModule::save(); + + Q_EMIT changed(false); +} + diff --git a/kded/plugins/pausemusic/pausemusic_config.h b/kded/plugins/pausemusic/pausemusic_config.h new file mode 100644 index 000000000..075e2958d --- /dev/null +++ b/kded/plugins/pausemusic/pausemusic_config.h @@ -0,0 +1,50 @@ +/** + * Copyright 2013 Albert Vaca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef PAUSEMUSIC_CONFIG_H +#define PAUSEMUSIC_CONFIG_H + +#include +#include + +namespace Ui { + class PauseMusicConfigUi; +} + +class PauseMusicConfig + : public KCModule +{ + Q_OBJECT +public: + PauseMusicConfig(QWidget *parent, const QVariantList&); + virtual ~PauseMusicConfig(); + +public Q_SLOTS: + virtual void save(); + virtual void load(); + virtual void defaults(); + +private: + Ui::PauseMusicConfigUi* m_ui; + KSharedConfigPtr m_cfg; + +}; + +#endif diff --git a/kded/plugins/pausemusic/pausemusic_config.ui b/kded/plugins/pausemusic/pausemusic_config.ui new file mode 100644 index 000000000..8c4f5ffbe --- /dev/null +++ b/kded/plugins/pausemusic/pausemusic_config.ui @@ -0,0 +1,66 @@ + + + PauseMusicConfigUi + + + Qt::WindowModal + + + + 0 + 0 + 252 + 175 + + + + Pause music plugin + + + + + + + 0 + 0 + + + + Pause condition + + + + + + Pause as soon as phone rings + + + + + + + Pause only while talking + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/kded/plugins/pausemusic/pausemusicplugin.cpp b/kded/plugins/pausemusic/pausemusicplugin.cpp index 5844ea6c1..a0e8b1657 100644 --- a/kded/plugins/pausemusic/pausemusicplugin.cpp +++ b/kded/plugins/pausemusic/pausemusicplugin.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include + #include "../../kdebugnamespace.h" K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PauseMusicPlugin >(); ) @@ -33,25 +36,26 @@ K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_pausemusic", "kdeconnect_pa PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args) : KdeConnectPlugin(parent, args) - , pauseWhen(PauseWhenRinging) //TODO: Be able to change this from plugin settings { + } bool PauseMusicPlugin::receivePackage(const NetworkPackage& np) { - switch(pauseWhen) { - case PauseWhenRinging: - if (np.get("event") != "ringing" && np.get("event") != "talking") { - return true; - } - break; - case PauseWhenTalking: - if (np.get("event") != "talking") { - return true; - } - break; - case NeverPause: + //FIXME: There should be a better way to listen to changes in the config file instead of reading the value each time + KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/kdeconnect_pausemusic"); + bool pauseOnlyWhenTalking = config->group("pause_condition").readEntry("talking_only", false); + + if (pauseOnlyWhenTalking) { + qDebug() << "pause when talking"; + if (np.get("event") != "talking") { return true; + } + } else { //Pause as soon as it rings + qDebug() << "pause when ringing"; + if (np.get("event") != "ringing" && np.get("event") != "talking") { + return true; + } } bool pauseConditionFulfilled = !np.get("isCancel"); diff --git a/kded/plugins/pausemusic/pausemusicplugin.h b/kded/plugins/pausemusic/pausemusicplugin.h index 8cd0c371e..2b5b32b00 100644 --- a/kded/plugins/pausemusic/pausemusicplugin.h +++ b/kded/plugins/pausemusic/pausemusicplugin.h @@ -40,8 +40,6 @@ public Q_SLOTS: virtual void connected() { }; private: - enum PauseCondtions { PauseWhenTalking, PauseWhenRinging, NeverPause }; - PauseCondtions pauseWhen; QSet pausedSources; };