[SCM] ktp-kded-integration-module packaging branch, master, updated. debian/15.12.1-2-382-gbd961c2
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:12:29 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-kded-module.git;a=commitdiff;h=df34b30
The following commit has been merged in the master branch:
commit df34b3042404048fefea04b8a4d0dfa03fc2ddf3
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date: Mon Sep 26 19:44:26 2011 +0200
Initial commit
---
CMakeLists.txt | 47 +++++++-
autoaway.cpp | 73 +++++++++++++
autoaway.h | 52 +++++++++
cmake/modules/FindTelepathyQt4.cmake | 43 ++++++++
config/CMakeLists.txt | 22 ++++
config/kcm_telepathy_kded_module_config.desktop | 19 ++++
config/telepathy-kded-config.cpp | 102 ++++++++++++++++++
config/telepathy-kded-config.h | 50 +++++++++
config/telepathy-kded-config.ui | 137 ++++++++++++++++++++++++
main.cpp | 6 --
telepathy-kded-module.kdev4 | 4 -
telepathy-module.cpp | 92 ++++++++++++++++
telepathy-module.h | 54 ++++++++++
telepathy-mpris.cpp | 127 ++++++++++++++++++++++
telepathy-mpris.h | 47 ++++++++
telepathy_kded_module.desktop | 10 ++
16 files changed, 874 insertions(+), 11 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4b652c3..b1ab638 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,49 @@
project(telepathy-kded-module)
-add_executable(telepathy-kded-module main.cpp)
+set (CMAKE_MODULE_PATH
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
+ ${CMAKE_MODULE_PATH}
+)
+find_package (KDE4 REQUIRED)
+find_package (TelepathyQt4 0.7.1 REQUIRED)
+
+# set some default settings
+include (KDE4Defaults)
+
+# make some more macros available
+include (MacroLibrary)
+
+add_definitions (${KDE4_DEFINITIONS})
+
+include_directories (${KDE4_INCLUDES}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${TELEPATHY_QT4_INCLUDE_DIR}
+)
+
+set (telepathy_module_SRCS
+ telepathy-module.cpp
+)
+
+kde4_add_plugin (kded_telepathy_module autoaway.cpp telepathy-mpris.cpp
+ ${telepathy_module_SRCS}
+)
+
+target_link_libraries (kded_telepathy_module
+ ${KDE4_KDECORE_LIBS}
+ ${TELEPATHY_QT4_LIBRARIES}
+ kidletime
+
+)
+
+install (TARGETS kded_telepathy_module
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
+
+install (FILES telepathy_kded_module.desktop
+ DESTINATION ${SERVICES_INSTALL_DIR}/kded
+)
+
+
+add_subdirectory(config)
\ No newline at end of file
diff --git a/autoaway.cpp b/autoaway.cpp
new file mode 100644
index 0000000..f73d6a6
--- /dev/null
+++ b/autoaway.cpp
@@ -0,0 +1,73 @@
+/*
+ Auto away-presence setter-class
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "autoaway.h"
+
+#include <KIdleTime>
+#include <TelepathyQt4/AccountManager>
+#include <TelepathyQt4/AccountSet>
+#include <KDebug>
+
+AutoAway::AutoAway(const Tp::AccountManagerPtr& am, QObject* parent)
+ : QObject(parent)
+{
+ m_accountManager = am;
+ m_awayTimeoutId = KIdleTime::instance()->addIdleTimeout(10 * 1000);
+ m_extAwayTimeoutId = KIdleTime::instance()->addIdleTimeout(20 * 1000);
+ m_prevPresence = Tp::Presence::available();
+
+ connect(KIdleTime::instance(), SIGNAL(timeoutReached(int)),
+ this, SLOT(timeoutReached(int)));
+
+ connect(KIdleTime::instance(), SIGNAL(resumingFromIdle()),
+ this, SLOT(backFromIdle()));
+}
+
+AutoAway::~AutoAway()
+{
+}
+
+void AutoAway::timeoutReached(int id)
+{
+ KIdleTime::instance()->catchNextResumeEvent();
+ if (id == m_awayTimeoutId) {
+ if (!m_accountManager->onlineAccounts()->accounts().isEmpty()) {
+ if (m_accountManager->onlineAccounts()->accounts().first()->currentPresence().type() != Tp::Presence::away().type() ||
+ m_accountManager->onlineAccounts()->accounts().first()->currentPresence().type() != Tp::Presence::xa().type() ||
+ m_accountManager->onlineAccounts()->accounts().first()->currentPresence().type() != Tp::Presence::hidden().type()) {
+
+ m_prevPresence = m_accountManager->onlineAccounts()->accounts().first()->currentPresence();
+ emit setPresence(Tp::Presence::away());
+
+ }
+ } else if (id == m_extAwayTimeoutId) {
+ if (!m_accountManager->onlineAccounts()->accounts().isEmpty()) {
+ if (m_accountManager->onlineAccounts()->accounts().first()->currentPresence().type() == Tp::Presence::away().type()) {
+ emit setPresence(Tp::Presence::xa());
+ }
+ }
+ }
+ }
+}
+
+void AutoAway::backFromIdle()
+{
+ kDebug();
+ emit setPresence(m_prevPresence);
+}
diff --git a/autoaway.h b/autoaway.h
new file mode 100644
index 0000000..4b716fa
--- /dev/null
+++ b/autoaway.h
@@ -0,0 +1,52 @@
+/*
+ Auto away-presence setter-class
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#ifndef AUTOAWAY_H
+#define AUTOAWAY_H
+
+#include <QObject>
+
+#include <TelepathyQt4/Presence>
+#include <TelepathyQt4/AccountManager>
+
+class AutoAway : public QObject
+{
+ Q_OBJECT
+
+public:
+ AutoAway(const Tp::AccountManagerPtr& am, QObject* parent = 0);
+ ~AutoAway();
+
+Q_SIGNALS:
+ void setPresence(const Tp::Presence &presence);
+
+private Q_SLOTS:
+ void timeoutReached(int);
+ void backFromIdle();
+
+private:
+ int m_awayTimeoutId;
+ int m_extAwayTimeoutId;
+
+ Tp::Presence m_prevPresence;
+ Tp::AccountManagerPtr m_accountManager;
+};
+
+#endif // AUTOAWAY_H
diff --git a/cmake/modules/FindTelepathyQt4.cmake b/cmake/modules/FindTelepathyQt4.cmake
new file mode 100644
index 0000000..c7f8f91
--- /dev/null
+++ b/cmake/modules/FindTelepathyQt4.cmake
@@ -0,0 +1,43 @@
+# Try to find the Qt4 binding of the Telepathy library
+# TELEPATHY_QT4_FOUND - system has TelepathyQt4
+# TELEPATHY_QT4_INCLUDE_DIR - the TelepathyQt4 include directory
+# TELEPATHY_QT4_LIBRARIES - Link these to use TelepathyQt4
+
+# Copyright (c) 2008, Allen Winter <winter at kde.org>
+# Copyright (c) 2009, Andre Moreira Magalhaes <andrunko at gmail.com>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+set(TELEPATHY_QT4_FIND_REQUIRED ${TelepathyQt4_FIND_REQUIRED})
+if(TELEPATHY_QT4_INCLUDE_DIR AND TELEPATHY_QT4_LIBRARIES)
+ # Already in cache, be silent
+ set(TELEPATHY_QT4_FIND_QUIETLY TRUE)
+endif(TELEPATHY_QT4_INCLUDE_DIR AND TELEPATHY_QT4_LIBRARIES)
+
+find_package(PkgConfig)
+if(PKG_CONFIG_FOUND)
+ if (TelepathyQt4_FIND_VERSION_EXACT)
+ pkg_check_modules(PC_TELEPATHY_QT4 QUIET TelepathyQt4=${TelepathyQt4_FIND_VERSION})
+ else (TelepathyQt4_FIND_VERSION_EXACT)
+ pkg_check_modules(PC_TELEPATHY_QT4 QUIET TelepathyQt4>=${TelepathyQt4_FIND_VERSION})
+ endif (TelepathyQt4_FIND_VERSION_EXACT)
+endif(PKG_CONFIG_FOUND)
+
+find_path(TELEPATHY_QT4_INCLUDE_DIR
+ NAMES TelepathyQt4/Types
+ HINTS
+ ${PC_TELEPATHY_QT4_INCLUDEDIR}
+ ${PC_TELEPATHY_QT4_INCLUDE_DIRS}
+)
+
+find_library(TELEPATHY_QT4_LIBRARIES
+ NAMES telepathy-qt4
+ HINTS
+ ${PC_TELEPATHY_QT4_LIBDIR}
+ ${PC_TELEPATHY_QT4_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(TELEPATHY_QT4 DEFAULT_MSG
+ TELEPATHY_QT4_LIBRARIES TELEPATHY_QT4_INCLUDE_DIR)
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
new file mode 100644
index 0000000..401cd0a
--- /dev/null
+++ b/config/CMakeLists.txt
@@ -0,0 +1,22 @@
+set(telepathy_kded_module_config_SRCS
+ telepathy-kded-config.cpp
+)
+
+set(telepathy_kded_module_config_UI
+ telepathy-kded-config.ui
+)
+
+kde4_add_ui_files(telepathy_kded_module_config_SRCS ${telepathy_kded_module_config_UI})
+
+kde4_add_plugin(kcm_telepathy_kded_module_config
+ ${telepathy_kded_module_config_SRCS})
+
+target_link_libraries(kcm_telepathy_kded_module_config ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KCMUTILS_LIBS} )
+
+
+install(TARGETS kcm_telepathy_kded_module_config
+ DESTINATION ${PLUGIN_INSTALL_DIR})
+
+install (FILES kcm_telepathy_kded_module_config.desktop
+ DESTINATION ${SERVICES_INSTALL_DIR}
+)
diff --git a/config/kcm_telepathy_kded_module_config.desktop b/config/kcm_telepathy_kded_module_config.desktop
new file mode 100644
index 0000000..b19a85d
--- /dev/null
+++ b/config/kcm_telepathy_kded_module_config.desktop
@@ -0,0 +1,19 @@
+[Desktop Entry]
+Icon=preferences-other
+StartupNotify=true
+Terminal=false
+Type=Service
+X-KDE-ServiceTypes=KCModule
+X-DBUS-StartupType=
+X-KDE-HasReadOnlyMode=false
+X-KDE-Library=kcm_telepathy_kded_module_config
+X-KDE-ParentApp=kcontrol
+X-KDE-SubstituteUID=false
+X-KDE-RootOnly=false
+X-KDE-System-Settings-Parent-Category=im-and-voip
+Categories=Qt;KDE;X-KDE-settings-network;
+
+Name=General
+Name[x-test]=xxGeneralxx
+Comment=General settings for IM and VoIP
+Comment[x-test]=xxGeneral settings for IM and VoIPxx
diff --git a/config/telepathy-kded-config.cpp b/config/telepathy-kded-config.cpp
new file mode 100644
index 0000000..0e1647d
--- /dev/null
+++ b/config/telepathy-kded-config.cpp
@@ -0,0 +1,102 @@
+/*
+ KControl Module for general Telepathy integration configs
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include "telepathy-kded-config.h"
+#include "ui_telepathy-kded-config.h"
+
+#include <KPluginFactory>
+#include <KLocalizedString>
+
+K_PLUGIN_FACTORY(KCMTelepathyKDEDModuleConfigFactory, registerPlugin<TelepathyKDEDConfig>();)
+K_EXPORT_PLUGIN(KCMTelepathyKDEDModuleConfigFactory("telepathy_kded_module_config", "kcm_telepathy_kded_module_config"))
+
+
+TelepathyKDEDConfig::TelepathyKDEDConfig(QWidget *parent, const QVariantList& args)
+ : KCModule(KCMTelepathyKDEDModuleConfigFactory::componentData(), parent, args),
+ ui(new Ui::TelepathyKDEDUi())
+{
+ ui->setupUi(this);
+
+ //FIXME: figure out how to use i18ncp without argument for suffix
+ ui->m_awayMins->setSuffix(i18nc("Unit after number in spinbox, denotes time unit 'minutes', keep the leading whitespace!",
+ " minutes"));
+
+ ui->m_xaMins->setSuffix(i18nc("Unit after number in spinbox, denotes time unit 'minutes', keep the leading whitespace!",
+ " minutes"));
+
+ connect(ui->m_awayCheckBox, SIGNAL(clicked(bool)),
+ this, SLOT(autoAwayChecked(bool)));
+}
+
+TelepathyKDEDConfig::~TelepathyKDEDConfig()
+{
+
+}
+
+void TelepathyKDEDConfig::load()
+{
+ KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+ KConfigGroup kdedConfig = config->group("KDED");
+
+ //check if auto-away is enabled
+ bool autoAwayEnabled = kdedConfig.readEntry("autoAwayEnabled", true);
+
+ //default away time is 5 minutes
+ int awayTime = kdedConfig.readEntry("awayAfter", 5);
+
+ ui->m_awayCheckBox->setChecked(autoAwayEnabled);
+ ui->m_awayMins->setValue(awayTime);
+ ui->m_awayMins->setEnabled(autoAwayEnabled);
+
+ //check for x-away
+ bool autoXAEnabled = kdedConfig.readEntry("autoXAEnabled", true);
+
+ //default x-away time is 15 minutes
+ int xaTime = kdedConfig.readEntry("xaAfter", 15);
+
+ //enable auto-x-away only if auto-away is enabled
+ ui->m_xaCheckBox->setChecked(autoXAEnabled && autoAwayEnabled);
+ ui->m_xaMins->setValue(xaTime);
+ ui->m_xaMins->setEnabled(autoXAEnabled && autoAwayEnabled);
+
+ //check if 'Now playing..' is enabled
+ bool nowPlayingEnabled = kdedConfig.readEntry("nowPlayingEnabled", true);
+
+ ui->m_nowPlayingCheckBox->setChecked(nowPlayingEnabled);
+}
+
+void TelepathyKDEDConfig::save()
+{
+ KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+ KConfigGroup kdedConfig = config->group("KDED");
+
+ kdedConfig.writeEntry("autoAwayEnabled", ui->m_awayCheckBox->isChecked());
+ kdedConfig.writeEntry("awayAfter", ui->m_awayMins->value());
+ kdedConfig.writeEntry("autoXAEnabled", ui->m_xaCheckBox->isChecked());
+ kdedConfig.writeEntry("xaAfter", ui->m_xaMins->value());
+ kdedConfig.writeEntry("nowPlayingEnabled", ui->m_nowPlayingCheckBox->isChecked());
+ kdedConfig.sync();
+}
+
+void TelepathyKDEDConfig::autoAwayChecked(bool checked)
+{
+ ui->m_xaCheckBox->setEnabled(checked);
+ ui->m_xaMins->setEnabled(checked);
+}
diff --git a/config/telepathy-kded-config.h b/config/telepathy-kded-config.h
new file mode 100644
index 0000000..92fea0f
--- /dev/null
+++ b/config/telepathy-kded-config.h
@@ -0,0 +1,50 @@
+/*
+ KControl Module for general Telepathy integration configs
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#ifndef TELEPATHY_KDED_CONFIG_H
+#define TELEPATHY_KDED_CONFIG_H
+
+#include <KCModule>
+
+namespace Ui {
+ class TelepathyKDEDUi;
+}
+
+class TelepathyKDEDConfig : public KCModule
+{
+ Q_OBJECT
+
+public:
+ TelepathyKDEDConfig(QWidget* parent, const QVariantList& args);
+ virtual ~TelepathyKDEDConfig();
+
+public Q_SLOTS:
+ void load();
+ void save();
+
+private Q_SLOTS:
+ void autoAwayChecked(bool checked);
+
+private:
+ Ui::TelepathyKDEDUi *ui;
+
+};
+
+#endif // TELEPATHY_KDED_CONFIG_H
diff --git a/config/telepathy-kded-config.ui b/config/telepathy-kded-config.ui
new file mode 100644
index 0000000..d3b3802
--- /dev/null
+++ b/config/telepathy-kded-config.ui
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TelepathyKDEDUi</class>
+ <widget class="QWidget" name="TelepathyKDEDUi">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QCheckBox" name="m_awayCheckBox">
+ <property name="text">
+ <string>Set me as 'Away' after</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <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>
+ <item>
+ <widget class="QSpinBox" name="m_awayMins">
+ <property name="suffix">
+ <string/>
+ </property>
+ <property name="value">
+ <number>5</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>16</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="m_xaCheckBox">
+ <property name="text">
+ <string>Set me as 'Not Available' after</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <property name="autoExclusive">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="m_xaMins">
+ <property name="suffix">
+ <string/>
+ </property>
+ <property name="value">
+ <number>15</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="m_nowPlayingCheckBox">
+ <property name="text">
+ <string>Enable 'Now playing...' presence</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </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>
diff --git a/main.cpp b/main.cpp
deleted file mode 100644
index 8bb47f1..0000000
--- a/main.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <iostream>
-
-int main(int argc, char **argv) {
- std::cout << "Hello, world!" << std::endl;
- return 0;
-}
diff --git a/telepathy-kded-module.kdev4 b/telepathy-kded-module.kdev4
deleted file mode 100644
index 380ec32..0000000
--- a/telepathy-kded-module.kdev4
+++ /dev/null
@@ -1,4 +0,0 @@
-[Project]
-Name=telepathy-kded-module
-Manager=KDevCMakeManager
-VersionControl=kdevgit
diff --git a/telepathy-module.cpp b/telepathy-module.cpp
new file mode 100644
index 0000000..6f2f44c
--- /dev/null
+++ b/telepathy-module.cpp
@@ -0,0 +1,92 @@
+/*
+ KDE integration module for Telepathy
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "telepathy-module.h"
+
+#include <KPluginFactory>
+
+#include <TelepathyQt4/AccountFactory>
+#include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/PendingReady>
+
+#include "telepathy-mpris.h"
+#include "autoaway.h"
+#include <KDebug>
+#include <TelepathyQt4/Debug>
+
+K_PLUGIN_FACTORY(TelepathyModuleFactory, registerPlugin<TelepathyModule>(); )
+K_EXPORT_PLUGIN(TelepathyModuleFactory("telepathy_module"))
+
+TelepathyModule::TelepathyModule(QObject* parent, const QList<QVariant>& args)
+ : KDEDModule(parent)
+{
+ Tp::registerTypes();
+ Tp::enableDebug(false);
+ Tp::enableWarnings(false);
+
+ // Start setting up the Telepathy AccountManager.
+ Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(),
+ Tp::Features() << Tp::Account::FeatureCore);
+
+ Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(),
+ Tp::Features() << Tp::Connection::FeatureCore);
+
+ Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
+
+ m_accountManager = Tp::AccountManager::create(QDBusConnection::sessionBus(),
+ accountFactory,
+ connectionFactory,
+ channelFactory);
+
+
+ connect(m_accountManager->becomeReady(),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onAccountManagerReady(Tp::PendingOperation*)));
+}
+
+TelepathyModule::~TelepathyModule()
+{
+}
+
+void TelepathyModule::onAccountManagerReady(Tp::PendingOperation* op)
+{
+ if (op->isError()) {
+ return;
+ }
+
+ m_autoAway = new AutoAway(m_accountManager, this);
+ connect(m_autoAway, SIGNAL(setPresence(Tp::Presence)),
+ this, SLOT(setPresence(Tp::Presence)));
+
+ m_mpris = new TelepathyMPRIS(m_accountManager, this);
+ connect(m_mpris, SIGNAL(setPresence(Tp::Presence)),
+ this, SLOT(setPresence(Tp::Presence)));
+}
+
+void TelepathyModule::setPresence(const Tp::Presence &presence)
+{
+ kDebug() << "Setting presence to" << presence.status() << presence.statusMessage();
+ foreach (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
+ if (account->isEnabled() && account->isValid() && account->isOnline()) {
+ account->setRequestedPresence(presence);
+ }
+ }
+}
+
+#include "telepathy-module.moc"
diff --git a/telepathy-module.h b/telepathy-module.h
new file mode 100644
index 0000000..61128a2
--- /dev/null
+++ b/telepathy-module.h
@@ -0,0 +1,54 @@
+/*
+ KDE integration module for Telepathy
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#ifndef TELEPATHY_MODULE_H
+#define TELEPATHY_MODULE_H
+
+#include <KDEDModule>
+
+#include <TelepathyQt4/AccountManager>
+
+class TelepathyMPRIS;
+class AutoAway;
+namespace Tp {
+ class PendingOperation;
+}
+
+class TelepathyModule : public KDEDModule
+{
+ Q_OBJECT
+
+public:
+ TelepathyModule(QObject *parent, const QList<QVariant> &args);
+ ~TelepathyModule();
+
+public Q_SLOTS:
+ void setPresence(const Tp::Presence& presence);
+
+private Q_SLOTS:
+ void onAccountManagerReady(Tp::PendingOperation*);
+
+private:
+ Tp::AccountManagerPtr m_accountManager;
+ AutoAway *m_autoAway;
+ TelepathyMPRIS *m_mpris;
+};
+
+#endif // TELEPATHY_MODULE_H
diff --git a/telepathy-mpris.cpp b/telepathy-mpris.cpp
new file mode 100644
index 0000000..036df5a
--- /dev/null
+++ b/telepathy-mpris.cpp
@@ -0,0 +1,127 @@
+/*
+ Now playing... presence plugin
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "telepathy-mpris.h"
+
+#include <QDBusConnectionInterface>
+#include <QDBusInterface>
+#include <QDBusReply>
+#include <QVariant>
+#include <KDebug>
+#include <TelepathyQt4/AccountSet>
+
+TelepathyMPRIS::TelepathyMPRIS(const Tp::AccountManagerPtr am, QObject* parent) : QObject(parent)
+{
+ m_accountManager = am;
+
+ if (am->onlineAccounts()->accounts().isEmpty()) {
+ return;
+ }
+
+ m_originalPresence = am->onlineAccounts()->accounts().first()->currentPresence().statusMessage();
+
+ QDBusConnectionInterface *i = QDBusConnection::sessionBus().interface();
+ QStringList mprisServices = i->registeredServiceNames().value().filter("org.mpris.MediaPlayer2");
+
+ QString artist;
+ QString title;
+ QString album;
+
+ foreach (const QString &service, mprisServices) {
+ QDBusInterface mprisInterface(service, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player");
+ if (mprisInterface.property("PlaybackStatus") == QLatin1String("Playing")) {
+ QMap<QString, QVariant> metadata = mprisInterface.property("Metadata").toMap();
+ artist = metadata.value("xesam:artist").toString();
+ title = metadata.value("xesam:title").toString();
+ album = metadata.value("xesam:album").toString();
+
+ QDBusConnection::sessionBus().connect(
+ "org.mpris.MediaPlayer2.clementine",
+ "/org/mpris/MediaPlayer2",
+ "org.freedesktop.DBus.Properties",
+ "PropertiesChanged",
+ this,
+ SLOT(onPlayerSignalReceived(const QString& ,
+ const QVariantMap& ,
+ const QStringList& )) );
+
+ break;
+ }
+ }
+
+ if (!am->onlineAccounts()->accounts().isEmpty()) {
+ Tp::Presence currentPresence = am->onlineAccounts()->accounts().first()->currentPresence();
+
+ Tp::SimplePresence presence;
+ presence.type = currentPresence.type();
+ presence.status = currentPresence.status();
+ presence.statusMessage = QString("Now listening to %1 by %2 from album %3").arg(title, artist, album);
+
+ kDebug() << "Setting presence message to" << presence.statusMessage;
+
+ emit setPresence(presence);
+ }
+}
+
+TelepathyMPRIS::~TelepathyMPRIS()
+{
+
+}
+
+void TelepathyMPRIS::onPlayerSignalReceived(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
+{
+ if (m_accountManager->onlineAccounts()->accounts().isEmpty()) {
+ return;
+ }
+ //FIXME We can do less lame parsing
+ foreach (const QVariant &property, changedProperties.values()) {
+ if (property.typeName() == QLatin1String("QDBusArgument")) {
+ QString artist;
+ QString title;
+ QString album;
+
+ QDBusArgument g = property.value<QDBusArgument>();
+ QMap<QString, QVariant> k = qdbus_cast<QMap<QString, QVariant> >(g);
+ title = k.value("xesam:title").toString();
+ artist = k.value("xesam:artist").toString();
+ album = k.value("xesam:album").toString();
+
+ Tp::Presence currentPresence = m_accountManager->onlineAccounts()->accounts().first()->currentPresence();
+
+ Tp::SimplePresence presence;
+ presence.type = currentPresence.type();
+ presence.status = currentPresence.status();
+ presence.statusMessage = QString("Now listening to %1 by %2 from album %3").arg(title, artist, album);
+
+ emit setPresence(presence);
+ }
+
+ if (property.typeName() == QLatin1String("QString")) {
+ if (property.toString() == QLatin1String("Paused")) {
+ Tp::Presence currentPresence = m_accountManager->onlineAccounts()->accounts().first()->currentPresence();
+
+ Tp::SimplePresence presence;
+ presence.type = currentPresence.type();
+ presence.status = currentPresence.status();
+ presence.statusMessage = m_originalPresence;
+ }
+ }
+ }
+
+}
diff --git a/telepathy-mpris.h b/telepathy-mpris.h
new file mode 100644
index 0000000..334616d
--- /dev/null
+++ b/telepathy-mpris.h
@@ -0,0 +1,47 @@
+/*
+ Now playing... presence plugin
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#ifndef TELEPATHY_MPRIS_H
+#define TELEPATHY_MPRIS_H
+
+#include <QObject>
+#include <TelepathyQt4/Presence>
+#include <TelepathyQt4/AccountManager>
+
+class TelepathyMPRIS : public QObject
+{
+ Q_OBJECT
+
+public:
+ TelepathyMPRIS(const Tp::AccountManagerPtr am, QObject *parent = 0);
+ virtual ~TelepathyMPRIS();
+
+public Q_SLOTS:
+ void onPlayerSignalReceived(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
+
+Q_SIGNALS:
+ void setPresence(const Tp::Presence &presence);
+
+private:
+ Tp::AccountManagerPtr m_accountManager;
+ QString m_originalPresence;
+};
+
+#endif // TELEPATHY_MPRIS_H
diff --git a/telepathy_kded_module.desktop b/telepathy_kded_module.desktop
new file mode 100644
index 0000000..0f8720c
--- /dev/null
+++ b/telepathy_kded_module.desktop
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Type=Service
+X-KDE-ServiceTypes=KDEDModule
+X-KDE-Library=telepathy_module
+X-KDE-DBus-ModuleName=telepathy_module
+X-KDE-Kded-autoload=true
+X-KDE-Kded-phase=2
+X-KDE-Kded-load-on-demand=false
+Name=Telepathy KDED Module
+Comment=TBD
\ No newline at end of file
--
ktp-kded-integration-module packaging
More information about the pkg-kde-commits
mailing list