Added a config dialog to pausemusic plugin

Before this it was not possible to change the pause condition (was a TODO).
This commit is contained in:
Albert Vaca 2013-11-22 22:49:40 +01:00
parent 958be9dc25
commit 2fdffd5cfd
7 changed files with 237 additions and 15 deletions

View file

@ -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} )

View file

@ -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;

View file

@ -0,0 +1,78 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "pausemusic_config.h"
#include <KPluginFactory>
#include <KSharedConfig>
#include <KConfigGroup>
#include "../../kdebugnamespace.h"
#include "ui_pausemusic_config.h"
K_PLUGIN_FACTORY(PauseMusicConfigFactory, registerPlugin<PauseMusicConfig>();)
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);
}

View file

@ -0,0 +1,50 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef PAUSEMUSIC_CONFIG_H
#define PAUSEMUSIC_CONFIG_H
#include <kcmodule.h>
#include <ksharedconfig.h>
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

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PauseMusicConfigUi</class>
<widget class="QWidget" name="PauseMusicConfigUi">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<height>175</height>
</rect>
</property>
<property name="windowTitle">
<string>Pause music plugin</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Pause condition</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="rad_ringing">
<property name="text">
<string>Pause as soon as phone rings</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rad_talking">
<property name="text">
<string>Pause only while talking</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -26,6 +26,9 @@
#include <QDBusReply>
#include <QDBusMessage>
#include <KSharedConfig>
#include <KConfigGroup>
#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<QString>("event") != "ringing" && np.get<QString>("event") != "talking") {
return true;
}
break;
case PauseWhenTalking:
if (np.get<QString>("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<QString>("event") != "talking") {
return true;
}
} else { //Pause as soon as it rings
qDebug() << "pause when ringing";
if (np.get<QString>("event") != "ringing" && np.get<QString>("event") != "talking") {
return true;
}
}
bool pauseConditionFulfilled = !np.get<bool>("isCancel");

View file

@ -40,8 +40,6 @@ public Q_SLOTS:
virtual void connected() { };
private:
enum PauseCondtions { PauseWhenTalking, PauseWhenRinging, NeverPause };
PauseCondtions pauseWhen;
QSet<QString> pausedSources;
};