Skip to content

Commit

Permalink
Convert volume control service to a data provider
Browse files Browse the repository at this point in the history
Issue: #154
  • Loading branch information
plfiorini committed Apr 12, 2014
1 parent 870d7f1 commit 63e9194
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 153 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ set(HAVE_SYSTEMD ${systemd_FOUND})
# Find polkit-qt-1
find_package(PolkitQt5-1)

# Find ALSA
find_package(ALSA)

# Subdirectories
add_subdirectory(data)
add_subdirectory(headers)
Expand Down
8 changes: 8 additions & 0 deletions data/dataproviders/mixer.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Desktop Entry]
Name=Mixer
Comment=Control audio mixer
X-Hawaii-PluginInfo-Name=org.hawaii.dataproviders.mixer
X-Hawaii-PluginInfo-Author=Pier Luigi Fiorini <[email protected]>
X-Hawaii-PluginInfo-Email[email protected]
X-Hawaii-PluginInfo-Website=http://www.maui-project.org
X-Hawaii-PluginInfo-License=LGPLv2.1+
5 changes: 0 additions & 5 deletions src/client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Find ALSA
find_package(ALSA)

include_directories(
${Qt5Gui_PRIVATE_INCLUDE_DIRS}
${QtConfiguration_INCLUDE_DIRS}
Expand All @@ -16,7 +13,6 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/services
${CMAKE_CURRENT_SOURCE_DIR}/services/powermanager
${CMAKE_CURRENT_SOURCE_DIR}/services/processlauncher
${CMAKE_CURRENT_SOURCE_DIR}/services/volumecontrol
${CMAKE_CURRENT_SOURCE_DIR}/services/sessionmanager
${CMAKE_CURRENT_SOURCE_DIR}/wayland
)
Expand Down Expand Up @@ -44,7 +40,6 @@ set(SOURCES
services/powermanager/systemdpowerbackend.cpp
services/powermanager/upowerpowerbackend.cpp
services/processlauncher/processlauncher.cpp
services/volumecontrol/volumecontrol.cpp
services/sessionmanager/sessionmanager.cpp
views/backgroundview.cpp
views/configview.cpp
Expand Down
2 changes: 0 additions & 2 deletions src/client/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "servicefactory.h"
#include "sessionmanager.h"
#include "shortcut.h"
#include "volumecontrol.h"
#include "window.h"
#include "workspace.h"

Expand Down Expand Up @@ -74,5 +73,4 @@ void Registration::registerFactories()
ServiceFactory::registerFactory<PowerManager>();
ServiceFactory::registerFactory<ProcessLauncher>();
ServiceFactory::registerFactory<SessionManager>();
ServiceFactory::registerFactory<VolumeControl>();
}
3 changes: 3 additions & 0 deletions src/dataproviders/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
add_subdirectory(datetime)
if(ALSA_FOUND)
add_subdirectory(mixer)
endif()
17 changes: 17 additions & 0 deletions src/dataproviders/mixer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include_directories(
${Hawaii_INCLUDE_DIRS}
)

add_definitions(-DQT_PLUGIN)

set(SOURCES
mixerprovider.cpp
mixersource.cpp
)

add_library(hawaiimixer SHARED ${SOURCES})
qt5_use_modules(hawaiimixer Core)
target_link_libraries(hawaiimixer Hawaii)

install(TARGETS hawaiimixer LIBRARY
DESTINATION ${CMAKE_INSTALL_DATAPROVIDERSDIR})
19 changes: 19 additions & 0 deletions src/dataproviders/mixer/mixer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"PluginInfo": {
"Authors": [
"Pier Luigi Fiorini <[email protected]>"
],
"Contact": {
"Email": "[email protected]",
"Website": "http://www.maui-project.org"
},
"Description": {
"en": {
"Comment": "Control audio mixer",
"Name": "Mixer"
}
},
"InternalName": "org.hawaii.dataproviders.mixer",
"License": "LGPLv2.1+"
}
}
54 changes: 54 additions & 0 deletions src/dataproviders/mixer/mixerprovider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/****************************************************************************
* This file is part of Hawaii Shell.
*
* Copyright (C) 2012-2014 Pier Luigi Fiorini <[email protected]>
*
* Author(s):
* Pier Luigi Fiorini
*
* $BEGIN_LICENSE:GPL2+$
*
* 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) 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 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/>.
*
* $END_LICENSE$
***************************************************************************/

#include "mixerprovider.h"
#include "mixersource.h"

MixerProvider::MixerProvider(QObject *parent)
: Hawaii::DataProvider(parent)
{
// Update date and time information every 500ms
setPollingInterval(500);

// Add master source
addSource(new MixerSource(this));
}

void MixerProvider::setMute(bool value)
{
MixerSource *mixer = qobject_cast<MixerSource *>(source("Master"));
if (mixer)
mixer->setMute(value);
}

void MixerProvider::setVolume(int value)
{
MixerSource *mixer = qobject_cast<MixerSource *>(source("Master"));
if (mixer)
mixer->setVolume(value);
}

#include "moc_mixerprovider.cpp"
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,22 @@
* $END_LICENSE$
***************************************************************************/

#ifndef VOLUMECONTROL_H
#define VOLUMECONTROL_H
#ifndef MIXERPROVIDER_H
#define MIXERPROVIDER_H

#include <QtCore/QObject>
#include <Hawaii/DataProvider>

class VolumeControlPrivate;

class VolumeControl : public QObject
class MixerProvider : public Hawaii::DataProvider
{
Q_OBJECT
Q_PROPERTY(bool muted READ isMute WRITE setMute NOTIFY muteChanged)
Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged)
Q_DECLARE_PRIVATE(VolumeControl)
Q_PLUGIN_METADATA(IID "org.hawaii.dataproviders.mixer" FILE "mixer.json")
Q_INTERFACES(Hawaii::DataProvider)
public:
VolumeControl(QObject *parent = 0);
~VolumeControl();

constexpr static const char *name() { return "VolumeControl"; }
MixerProvider(QObject *parent = 0);

bool isMute() const;
public Q_SLOTS:
void setMute(bool value);

int volume() const;
void setVolume(int value);

Q_SIGNALS:
void muteChanged(bool value);
void volumeChanged(int value);

private:
Q_PRIVATE_SLOT(d_func(), void _q_upTriggered())
Q_PRIVATE_SLOT(d_func(), void _q_downTriggered())
Q_PRIVATE_SLOT(d_func(), void _q_muteTriggered())

VolumeControlPrivate *const d_ptr;
};

#endif // VOLUMECONTROL_H
#endif // MIXERPROVIDER_H
Loading

0 comments on commit 63e9194

Please sign in to comment.