1 /*
2  * %kadu copyright begin%
3  * Copyright 2015 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
4  * %kadu copyright end%
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "sound-mute-action.h"
21 
22 #include "sound-manager.h"
23 
24 #include "configuration/configuration.h"
25 #include "configuration/deprecated-configuration-api.h"
26 #include "core/core.h"
27 #include "gui/actions/action.h"
28 
SoundMuteAction(QObject * parent)29 SoundMuteAction::SoundMuteAction(QObject *parent) :
30 		// using C++ initializers breaks Qt's lupdate
31 		ActionDescription(parent)
32 {
33 	setCheckable(true);
34 	setIcon(KaduIcon("audio-volume-high"));
35 	setName("muteSoundsAction");
36 	setText(tr("Play Sounds"));
37 	setType(ActionDescription::TypeGlobal);
38 }
39 
~SoundMuteAction()40 SoundMuteAction::~SoundMuteAction()
41 {
42 }
43 
setSoundManager(SoundManager * soundManager)44 void SoundMuteAction::setSoundManager(SoundManager *soundManager)
45 {
46 	m_soundManager = soundManager;
47 }
48 
actionTriggered(QAction * sender,bool toggled)49 void SoundMuteAction::actionTriggered(QAction *sender, bool toggled)
50 {
51 	Q_UNUSED(sender);
52 
53 	m_soundManager->setMute(!toggled);
54 	updateActionStates();
55 
56 	configuration()->deprecatedApi()->writeEntry("Sounds", "PlaySound", toggled);
57 }
58 
updateActionState(Action * action)59 void SoundMuteAction::updateActionState(Action *action)
60 {
61 	if (m_soundManager)
62 		action->setChecked(!m_soundManager->isMuted());
63 }
64