[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kmix/kmix-improvements] /: Build daemon2 instead of daemon
From: Trever Fischer <tdfischer () fedoraproject ! org>
Date: 2012-09-24 10:49:01
Message-ID: 20120924104901.B7D16A60C9 () git ! kde ! org
[Download RAW message or body]
Git commit 4ae76de863992daed2fc443825e5354a2b82749b by Trever Fischer.
Committed on 24/09/2012 at 12:42.
Pushed by tdfischer into branch 'kmix-improvements'.
Build daemon2 instead of daemon
M +1 -1 CMakeLists.txt
A +55 -0 src/daemon2/Backend.cpp [License: LGPL (v2+)]
A +43 -0 src/daemon2/Backend.h [License: LGPL (v2+)]
A +62 -0 src/daemon2/BackendManager.cpp [License: LGPL (v2+)]
A +43 -0 src/daemon2/BackendManager.h [License: LGPL (v2+)]
A +56 -0 src/daemon2/CMakeLists.txt
A +39 -0 src/daemon2/Control.cpp [License: LGPL (v2+)]
A +55 -0 src/daemon2/Control.h [License: LGPL (v2+)]
A +54 -0 src/daemon2/ControlGroup.cpp [License: LGPL (v2+)]
A +48 -0 src/daemon2/ControlGroup.h [License: LGPL (v2+)]
A +77 -0 src/daemon2/KMixDApp.cpp [License: LGPL (v2+)]
A +48 -0 src/daemon2/KMixDApp.h [License: LGPL (v2+)]
A +131 -0 src/daemon2/backends/PulseAudio.cpp [License: LGPL (v2+)]
A +47 -0 src/daemon2/backends/PulseAudio.h [License: LGPL (v2+)]
A +91 -0 src/daemon2/backends/PulseControl.cpp [License: LGPL (v2+)]
A +51 -0 src/daemon2/backends/PulseControl.h [License: LGPL (v2+)]
A +28 -0 src/daemon2/main.cpp [License: LGPL (v2+)]
A +3 -0 src/daemon2/org.kde.kmixd.service.cmake
http://commits.kde.org/kmix/4ae76de863992daed2fc443825e5354a2b82749b
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c9b5944..9cb1097 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,7 +34,7 @@ add_subdirectory( doc )
add_subdirectory( icons )
add_subdirectory( pics )
add_subdirectory( profiles )
-add_subdirectory( src/daemon )
+add_subdirectory( src/daemon2 )
#add_subdirectory( tests )
if (PULSEAUDIO_FOUND)
diff --git a/src/daemon2/Backend.cpp b/src/daemon2/Backend.cpp
new file mode 100644
index 0000000..0825ad4
--- /dev/null
+++ b/src/daemon2/Backend.cpp
@@ -0,0 +1,55 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+
+#include "Backend.h"
+#include "Control.h"
+#include <QtCore/QDebug>
+
+Backend::Backend(QObject *parent)
+ : QObject(parent)
+{
+}
+
+Backend::~Backend()
+{
+}
+
+QList<Control*> Backend::controls() const
+{
+ return m_controls;
+}
+
+void Backend::registerControl(Control *control)
+{
+ m_controls << control;
+ emit controlAdded(control);
+ qDebug() << "New control:" << control->displayName();
+}
+
+void Backend::deregisterControl(Control *control)
+{
+ m_controls.removeOne(control);
+ emit controlRemoved(control);
+}
+
+bool Backend::open()
+{
+ return true;
+}
diff --git a/src/daemon2/Backend.h b/src/daemon2/Backend.h
new file mode 100644
index 0000000..ffdd9e2
--- /dev/null
+++ b/src/daemon2/Backend.h
@@ -0,0 +1,43 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+#ifndef BACKEND_H
+#define BACKEND_H
+
+#include <QtCore/QObject>
+class Control;
+
+class Backend : public QObject {
+ Q_OBJECT
+public:
+ Backend(QObject *parent = 0);
+ ~Backend();
+ QList<Control*> controls() const;
+ virtual bool open();
+signals:
+ void controlAdded(Control *control);
+ void controlRemoved(Control *control);
+protected:
+ void registerControl(Control *control);
+ void deregisterControl(Control *control);
+private:
+ QList<Control*> m_controls;
+};
+
+#endif //BACKEND_H
diff --git a/src/daemon2/BackendManager.cpp b/src/daemon2/BackendManager.cpp
new file mode 100644
index 0000000..bd96691
--- /dev/null
+++ b/src/daemon2/BackendManager.cpp
@@ -0,0 +1,62 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+
+#include "BackendManager.h"
+#include "Control.h"
+#include "ControlGroup.h"
+#include <QtCore/QStringList>
+#include <QtCore/QDebug>
+
+#include "backends/PulseAudio.h"
+
+BackendManager *BackendManager::s_instance = 0;
+
+BackendManager::BackendManager()
+{
+ m_groups << new ControlGroup("Test Group");
+ Backend *pulse = new Backends::PulseAudio(this);
+ connect(pulse, SIGNAL(controlAdded(Control *)), this, SLOT(controlAdded(Control \
*))); + m_backends << pulse;
+ pulse->open();
+}
+
+BackendManager *BackendManager::instance()
+{
+ if (s_instance == 0)
+ s_instance = new BackendManager();
+ return s_instance;
+}
+
+QStringList BackendManager::groups() const
+{
+ QStringList ret;
+ foreach(ControlGroup *group, m_groups) {
+ ret << group->displayName();
+ }
+ return ret;
+}
+
+void BackendManager::controlAdded(Control *control)
+{
+ qDebug() << "New control:" << control->displayName() << control->volumes();
+ m_groups[0]->addControl(control);
+}
+
+#include "BackendManager.moc"
diff --git a/src/daemon2/BackendManager.h b/src/daemon2/BackendManager.h
new file mode 100644
index 0000000..68edd26
--- /dev/null
+++ b/src/daemon2/BackendManager.h
@@ -0,0 +1,43 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+#ifndef BACKENDMANAGER_H
+#define BACKENDMANAGER_H
+
+#include <QtCore/QObject>
+
+class ControlGroup;
+class Backend;
+class Control;
+
+class BackendManager : public QObject {
+ Q_OBJECT
+public:
+ static BackendManager *instance();
+ QStringList groups() const;
+private slots:
+ void controlAdded(Control *control);
+private:
+ BackendManager();
+ static BackendManager *s_instance;
+ QList<Backend*> m_backends;
+ QList<ControlGroup*> m_groups;
+};
+
+#endif //BACKENDMANAGER_H
diff --git a/src/daemon2/CMakeLists.txt b/src/daemon2/CMakeLists.txt
new file mode 100644
index 0000000..c420820
--- /dev/null
+++ b/src/daemon2/CMakeLists.txt
@@ -0,0 +1,56 @@
+
+#set(kmixd_backend_SRCS
+# ../backends/mixer_backend.cpp
+# ../backends/mixer_mpris2.cpp
+# )
+#
+#if (HAVE_LIBASOUND2)
+# set(kmixd_backend_SRCS ${kmixd_backend_SRCS}
+# ../backends/mixer_alsa9.cpp )
+#endif (HAVE_LIBASOUND2)
+#
+#if (PULSEAUDIO_FOUND)
+# set(kmixd_backend_SRCS ${kmixd_backend_SRCS}
+# ../backends/mixer_pulse.cpp )
+#endif (PULSEAUDIO_FOUND)
+
+set(kmixd_SRCS
+ main.cpp
+ KMixDApp.cpp
+ Backend.cpp
+ BackendManager.cpp
+ ControlGroup.cpp
+ Control.cpp
+
+ backends/PulseAudio.cpp
+ backends/PulseControl.cpp
+)
+
+qt4_add_dbus_adaptor( kmixd_SRCS ../dbus/org.kde.kmix.kmixd.xml
+ KMixDApp.h KMixDApp )
+qt4_add_dbus_adaptor( kmixd_SRCS ../dbus/org.kde.kmix.control.xml
+ Control.h Control )
+
+kde4_add_executable(kmixd ${kmixd_SRCS} ${kmixd_backend_SRCS})
+
+target_link_libraries(kmixd
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTDBUS_LIBRARY}
+ ${KDE4_KDEUI_LIBS}
+ ${KDE4_SOLID_LIBS}
+)
+
+if (HAVE_LIBASOUND2)
+ target_link_libraries(kmixd ${ASOUND_LIBRARY})
+endif (HAVE_LIBASOUND2)
+
+if (PULSEAUDIO_FOUND)
+ target_link_libraries(kmixd ${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_MAINLOOP_LIBRARY} \
${GLIB2_LIBRARIES}) +endif (PULSEAUDIO_FOUND)
+
+install( TARGETS kmixd ${INSTALL_TARGETS_DEFAULT_ARGS} )
+
+configure_file(org.kde.kmixd.service.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kmixd.service)
+
+install( FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kmixd.service DESTINATION \
${DBUS_SERVICES_INSTALL_DIR} )
diff --git a/src/daemon2/Control.cpp b/src/daemon2/Control.cpp
new file mode 100644
index 0000000..c850272
--- /dev/null
+++ b/src/daemon2/Control.cpp
@@ -0,0 +1,39 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+#include "Control.h"
+#include "controladaptor.h"
+#include <QtDBus/QDBusConnection>
+
+QAtomicInt Control::s_id = 0;
+
+Control::Control(QObject *parent)
+ : QObject(parent)
+{
+ new ControlAdaptor(this);
+ QDBusConnection::sessionBus().registerObject(QString("/Controls/%1").arg(s_id), \
this); + s_id.ref();
+}
+
+Control::~Control()
+{
+ s_id.deref();
+}
+
+#include "Control.moc"
diff --git a/src/daemon2/Control.h b/src/daemon2/Control.h
new file mode 100644
index 0000000..a86cce3
--- /dev/null
+++ b/src/daemon2/Control.h
@@ -0,0 +1,55 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+#ifndef CONTROL_H
+#define CONTROL_H
+
+#include <QtCore/QObject>
+#include <QtCore/QMap>
+
+class Control : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString displayName READ displayName);
+ Q_PROPERTY(QString iconName READ iconName);
+ Q_PROPERTY(bool mute READ isMuted WRITE setMute);
+ Q_PROPERTY(bool canMute READ canMute);
+public:
+ typedef enum {
+ FrontLeft,
+ FrontRight,
+ Center,
+ RearLeft,
+ RearRight,
+ Subwoofer
+ } Channel;
+ Control(QObject *parent = 0);
+ ~Control();
+ virtual QString displayName() const = 0;
+ virtual QString iconName() const = 0;
+ virtual QMap<Channel, int> volumes() const = 0;
+ virtual void setVolume(Channel c, int v) = 0;
+ virtual bool isMuted() const = 0;
+ virtual void setMute(bool yes) = 0;
+ virtual bool canMute() const = 0;
+private:
+ static QAtomicInt s_id;
+};
+
+#endif //CONTROL_H
diff --git a/src/daemon2/ControlGroup.cpp b/src/daemon2/ControlGroup.cpp
new file mode 100644
index 0000000..737ce1c
--- /dev/null
+++ b/src/daemon2/ControlGroup.cpp
@@ -0,0 +1,54 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+#include "ControlGroup.h"
+#include "Control.h"
+#include <QtCore/QStringList>
+#include <QtDBus/QDBusConnection>
+
+QAtomicInt ControlGroup::s_id = 0;
+
+ControlGroup::ControlGroup(const QString &displayName, QObject *parent)
+ : QObject(parent)
+ , m_displayName(displayName)
+{
+ QDBusConnection::sessionBus().registerObject(QString("/groups/%1").arg(s_id), \
this); + s_id.ref();
+}
+
+ControlGroup::~ControlGroup()
+{
+ s_id.deref();
+}
+
+QString ControlGroup::displayName() const
+{
+ return m_displayName;
+}
+
+QStringList ControlGroup::controls() const
+{
+ return QStringList();
+}
+
+void ControlGroup::addControl(Control *control)
+{
+ m_controls[control->displayName()] = control;
+ emit controlAdded(control->displayName());
+}
diff --git a/src/daemon2/ControlGroup.h b/src/daemon2/ControlGroup.h
new file mode 100644
index 0000000..c1b5775
--- /dev/null
+++ b/src/daemon2/ControlGroup.h
@@ -0,0 +1,48 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+#ifndef CONTROLGROUP_H
+#define CONTROLGROUP_H
+
+#include <QtCore/QObject>
+#include <QtCore/QHash>
+
+class Control;
+
+class ControlGroup : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString displayName READ displayName);
+public:
+ ControlGroup(const QString &displayName, QObject *parent = 0);
+ ~ControlGroup();
+ QString displayName() const;
+ QStringList controls() const;
+ Control *getControl(const QString &name) const;
+public slots:
+ void addControl(Control *control);
+signals:
+ void controlAdded(const QString &name) const;
+private:
+ QHash<QString, Control*> m_controls;
+ QString m_displayName;
+ static QAtomicInt s_id;
+};
+
+#endif //CONTROLGROUP_H
diff --git a/src/daemon2/KMixDApp.cpp b/src/daemon2/KMixDApp.cpp
new file mode 100644
index 0000000..dd8e804
--- /dev/null
+++ b/src/daemon2/KMixDApp.cpp
@@ -0,0 +1,77 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+
+#include "KMixDApp.h"
+#include "kmixdadaptor.h"
+#include "ControlGroup.h"
+#include "BackendManager.h"
+#include "Control.h"
+
+#include <QtDBus/QDBusConnection>
+#include <QtCore/QDebug>
+
+KMixDApp::KMixDApp(int &argc, char **argv)
+ : QCoreApplication(argc, argv)
+{
+}
+
+KMixDApp::~KMixDApp()
+{
+}
+
+int KMixDApp::start()
+{
+ if (QDBusConnection::sessionBus().registerService("org.kde.kmixd")) {
+ new KMixDAdaptor(this);
+ QDBusConnection::sessionBus().registerObject("/KMixD", this);
+ foreach(const QString &groupName, BackendManager::instance()->groups()) {
+ qDebug() << "Group:" << groupName;
+ }
+ return exec();
+ }
+ return 1;
+}
+
+void KMixDApp::setMaster(const QString &masterID)
+{
+ Q_ASSERT(false);
+}
+
+QStringList KMixDApp::mixerGroups() const
+{
+ return BackendManager::instance()->groups();
+}
+
+QString KMixDApp::masterControl() const
+{
+ Q_ASSERT(false);
+ return QString();
+}
+
+int KMixDApp::masterVolume() const
+{
+ Q_ASSERT(false);
+ return 0;
+}
+
+void KMixDApp::setMasterVolume(int v)
+{
+ Q_ASSERT(false);
+}
diff --git a/src/daemon2/KMixDApp.h b/src/daemon2/KMixDApp.h
new file mode 100644
index 0000000..76e2c30
--- /dev/null
+++ b/src/daemon2/KMixDApp.h
@@ -0,0 +1,48 @@
+//-*-C++-*-
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+#ifndef KMixApp_h
+#define KMixApp_h
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QStringList>
+
+class KMixDApp : public QCoreApplication
+{
+ Q_OBJECT
+ Q_PROPERTY(QStringList mixerGroups READ mixerGroups);
+ Q_PROPERTY(QString masterControl READ masterControl);
+ Q_PROPERTY(int masterVolume READ masterVolume WRITE setMasterVolume);
+public:
+ KMixDApp(int &argc, char **argv);
+ ~KMixDApp();
+ int start();
+ void setMaster(const QString &masterID);
+ QStringList mixerGroups() const;
+ QString masterControl() const;
+
+ int masterVolume() const;
+ void setMasterVolume(int v);
+signals:
+ void groupAdded(const QString &name);
+ void groupRemoved(const QString &name);
+};
+
+#endif
diff --git a/src/daemon2/backends/PulseAudio.cpp \
b/src/daemon2/backends/PulseAudio.cpp new file mode 100644
index 0000000..647d6fe
--- /dev/null
+++ b/src/daemon2/backends/PulseAudio.cpp
@@ -0,0 +1,131 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+
+#include "PulseAudio.h"
+#include "PulseControl.h"
+#include <QtCore/QDebug>
+
+namespace Backends {
+
+PulseAudio::PulseAudio(QObject *parent)
+ : Backend(parent)
+{
+ m_loop = pa_glib_mainloop_new(NULL);
+ m_loopAPI = pa_glib_mainloop_get_api(m_loop);
+ m_context = pa_context_new(m_loopAPI, "KMix");
+}
+
+PulseAudio::~PulseAudio()
+{
+ if (m_context) {
+ pa_context_unref(m_context);
+ m_context = NULL;
+ }
+ if (m_loop) {
+ pa_glib_mainloop_free(m_loop);
+ m_loop = NULL;
+ }
+}
+
+void PulseAudio::sink_cb(pa_context *cxt, const pa_sink_info *info, int eol, \
gpointer user_data) { + PulseAudio *that = static_cast<PulseAudio*>(user_data);
+ qDebug() << eol;
+ if (eol < 0) {
+ qDebug() << pa_context_errno(cxt);
+ if (pa_context_errno(cxt) == PA_ERR_NOENTITY)
+ return;
+ }
+ if (eol > 0) {
+ return;
+ }
+ PulseControl *control;
+ qDebug() << "Event for" << info->index;
+ if (!that->m_sinks.contains(info->index)) {
+ control = new PulseControl(cxt, info, that);
+ QObject::connect(control, SIGNAL(scheduleRefresh(int)), that, \
SLOT(refreshSink(int))); + that->m_sinks[info->index] = control;
+ that->registerControl(control);
+ } else {
+ control->update(info);
+ }
+}
+
+void PulseAudio::refreshSink(int idx)
+{
+ qDebug() << "update queued for" << idx;
+ pa_context_get_sink_info_by_index(m_context, idx, sink_cb, this);
+}
+
+void PulseAudio::subscribe_cb(pa_context *cxt, pa_subscription_event_type t, \
uint32_t index, gpointer user_data) +{
+ qDebug() << "subscription" << t;
+ switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
+ case PA_SUBSCRIPTION_EVENT_SINK:
+ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == \
PA_SUBSCRIPTION_EVENT_REMOVE) { + //FIXME
+ } else {
+ pa_operation *op;
+ if (!(op = pa_context_get_sink_info_by_index(cxt, index, sink_cb, \
user_data))) { + qWarning() << "pa_context_get_sink_info_by_index \
failed"; + return;
+ }
+ pa_operation_unref(op);
+ }
+ break;
+ }
+}
+
+void PulseAudio::context_state_callback(pa_context *cxt, gpointer user_data)
+{
+ PulseAudio *that = static_cast<PulseAudio*>(user_data);
+ pa_context_state_t state = pa_context_get_state(cxt);
+ if (state == PA_CONTEXT_READY) {
+ pa_operation *op;
+ pa_context_set_subscribe_callback(cxt, subscribe_cb, that);
+ if (!(op = pa_context_subscribe(cxt, (pa_subscription_mask_t) (
+ PA_SUBSCRIPTION_MASK_SINK |
+ PA_SUBSCRIPTION_MASK_SOURCE |
+ PA_SUBSCRIPTION_MASK_CLIENT |
+ PA_SUBSCRIPTION_MASK_SINK_INPUT |
+ PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT),
+ NULL, NULL))) {
+ qWarning() << "pa_context_subscribe failed";
+ return;
+ }
+ pa_operation_unref(op);
+ if (!(op = pa_context_get_sink_info_list(cxt, sink_cb, that))) {
+ return;
+ }
+ pa_operation_unref(op);
+ }
+}
+
+bool PulseAudio::open()
+{
+ if (pa_context_connect(m_context, NULL, PA_CONTEXT_NOFAIL, 0) < 0) {
+ pa_context_unref(m_context);
+ m_context = NULL;
+ return false;
+ }
+ pa_context_set_state_callback(m_context, &context_state_callback, this);
+ return true;
+}
+
+} //namespace Backends
diff --git a/src/daemon2/backends/PulseAudio.h b/src/daemon2/backends/PulseAudio.h
new file mode 100644
index 0000000..12f0bad
--- /dev/null
+++ b/src/daemon2/backends/PulseAudio.h
@@ -0,0 +1,47 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+
+#include "Backend.h"
+#include <pulse/pulseaudio.h>
+#include <pulse/glib-mainloop.h>
+#include <QtCore/QMap>
+
+namespace Backends {
+class PulseControl;
+
+class PulseAudio : public Backend {
+ Q_OBJECT
+public:
+ PulseAudio(QObject *parent = 0);
+ ~PulseAudio();
+ bool open();
+private slots:
+ void refreshSink(int idx);
+private:
+ static void context_state_callback(pa_context *cxt, gpointer user_data);
+ static void sink_cb(pa_context *cxt, const pa_sink_info *info, int eol, gpointer \
user_data); + static void subscribe_cb(pa_context *cxt, pa_subscription_event_type \
t, uint32_t index, gpointer user_data); + pa_glib_mainloop *m_loop;
+ pa_mainloop_api *m_loopAPI;
+ pa_context *m_context;
+ QMap<int, PulseControl*> m_sinks;
+};
+
+} //namespace Backends
diff --git a/src/daemon2/backends/PulseControl.cpp \
b/src/daemon2/backends/PulseControl.cpp new file mode 100644
index 0000000..083e59d
--- /dev/null
+++ b/src/daemon2/backends/PulseControl.cpp
@@ -0,0 +1,91 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+
+#include "PulseControl.h"
+#include <QtCore/QMap>
+#include <QtCore/QDebug>
+
+namespace Backends {
+
+PulseControl::PulseControl(pa_context *cxt, const pa_sink_info *info, QObject \
*parent) + : Control(parent)
+ , m_context(cxt)
+ , m_info(*info)
+{
+}
+
+QString PulseControl::displayName() const
+{
+ return QString::fromUtf8(m_info.name);
+}
+
+QString PulseControl::iconName() const
+{
+ return QString::fromUtf8(pa_proplist_gets(m_info.proplist, \
PA_PROP_DEVICE_ICON_NAME)); +}
+
+QMap<Control::Channel, int> PulseControl::volumes() const
+{
+ QMap<Control::Channel, int> volumes;
+ for (uint8_t i = 0;i<m_info.volume.channels;i++) {
+ volumes[(Channel)i] = m_info.volume.values[i];
+ }
+ return volumes;
+}
+
+void PulseControl::setVolume(Channel c, int v)
+{
+ pa_cvolume volume = m_info.volume;
+ volume.values[(int)c] = v;
+ if (!pa_context_set_sink_volume_by_index(m_context, m_info.index, &volume, NULL, \
NULL)) { + qWarning() << "pa_context_set_sink_volume_by_index() failed";
+ }
+}
+
+bool PulseControl::isMuted() const
+{
+ return m_info.mute;
+}
+
+void PulseControl::cb_refresh(pa_context *c, int success, void* user_data)
+{
+ PulseControl *that = static_cast<PulseControl*>(user_data);
+ emit that->scheduleRefresh(that->m_info.index);
+}
+
+void PulseControl::setMute(bool yes)
+{
+ qDebug() << m_info.index << m_info.name;
+ pa_context_set_sink_mute_by_index(m_context, m_info.index, yes, cb_refresh, \
this); +}
+
+bool PulseControl::canMute() const
+{
+ return true;
+}
+
+void PulseControl::update(const pa_sink_info *info)
+{
+ //FIXME: Doesn't work!
+ //m_info = info;
+ qDebug() << "Mute:" << m_info.mute;
+}
+
+} //namespace Backends
diff --git a/src/daemon2/backends/PulseControl.h \
b/src/daemon2/backends/PulseControl.h new file mode 100644
index 0000000..dd8fa19
--- /dev/null
+++ b/src/daemon2/backends/PulseControl.h
@@ -0,0 +1,51 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+
+#ifndef PULSECONTROL_H
+#define PULSECONTROL_H
+#include "Control.h"
+#include <pulse/pulseaudio.h>
+#include <QtCore/QMap>
+
+namespace Backends {
+
+class PulseControl : public Control {
+ Q_OBJECT
+public:
+ PulseControl(pa_context *cxt, const pa_sink_info *info, QObject *parent = 0);
+ QString displayName() const;
+ QString iconName() const;
+ QMap<Channel, int> volumes() const;
+ void setVolume(Channel c, int v);
+ bool isMuted() const;
+ void setMute(bool yes);
+ bool canMute() const;
+ void update(const pa_sink_info *info);
+signals:
+ void scheduleRefresh(int index);
+private:
+ static void cb_refresh(pa_context *c, int success, void* user_data);
+ pa_context *m_context;
+ pa_sink_info m_info;
+};
+
+} //namespace Backends
+
+#endif //PULSECONTROL_H
diff --git a/src/daemon2/main.cpp b/src/daemon2/main.cpp
new file mode 100644
index 0000000..4f0feeb
--- /dev/null
+++ b/src/daemon2/main.cpp
@@ -0,0 +1,28 @@
+/*
+ * KMix -- KDE's full featured mini mixer
+ *
+ * Copyright (C) 2012 Trever Fischer <tdfischer@fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA \
02110-1301, USA. + */
+
+
+#include "KMixDApp.h"
+
+int main(int argc, char *argv[])
+{
+ KMixDApp app(argc, argv);
+ return app.start();
+}
diff --git a/src/daemon2/org.kde.kmixd.service.cmake \
b/src/daemon2/org.kde.kmixd.service.cmake new file mode 100644
index 0000000..7c9e8de
--- /dev/null
+++ b/src/daemon2/org.kde.kmixd.service.cmake
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.kde.kmixd
+Exec=@CMAKE_INSTALL_PREFIX@/bin/kmixd
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic