-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume.cpp
69 lines (58 loc) · 1.18 KB
/
volume.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "volume.h"
Volume::Volume(QObject *parent)
:
QObject(parent)
{
// TODO: check errors and report
m_commands.loadCommands();
m_currentVolume = m_settings.readInt(Settings::Volume);
changeVolume(m_currentVolume);
}
Volume::~Volume()
{
}
void Volume::volumeUp()
{
m_currentVolume += 5;
if (m_currentVolume > 100)
{
m_currentVolume = 100;
}
changeVolume(m_currentVolume);
}
void Volume::volumeDown()
{
m_currentVolume -= 5;
if (m_currentVolume < 0)
{
m_currentVolume = 0;
}
changeVolume(m_currentVolume);
}
void Volume::changeVolume(int volume)
{
m_commands.executeCommand(Commands::SetVolume, m_currentVolume);
if (volume == 0)
{
m_commands.executeCommand(Commands::Mute);
}
m_settings.writeInt(Settings::Volume, m_currentVolume);
emit volumeChanged(m_currentVolume);
}
int Volume::currentVolume() const
{
return m_currentVolume;
}
/*
* Unnused
QString Volume::volumeFrom(const QString& amixerOutput)
{
QRegExp rx("\\[(\\d{1,3})%\\]");
if (rx.indexIn(amixerOutput) > -1)
{
QString volume = rx.cap(1);
return volume;
}
return QString();
}
*/