~andreas-pokorny/telepathy-ofono/control-proximity-handling-in-powerd

106 by Andreas Pokorny
Request proximity based screen blanking from powerd
1
/**
2
 * Copyright (C) 2014 Canonical, Ltd.
3
 *
4
 * This program is free software: you can redistribute it and/or modify it under
5
 * the terms of the GNU Lesser General Public License version 3, as published by
6
 * the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 * Lesser General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU Lesser General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 *
16
 * Authors: Andreas Pokorny <andreas.pokorny@canonical.com>
17
 */
18
19
#include "powerdaudiomodemediator.h"
20
21
PowerDAudioModeMediator::PowerDAudioModeMediator(PowerD &powerd)
22
    : powerd(powerd)
23
{
24
}
25
26
void PowerDAudioModeMediator::audioModeChanged(const QString &mode)
27
{
28
    PowerD::PowerState expectedState =
29
        (mode == "speaker" || mode == "bluetooth") ?
30
        PowerD::ActiveDisplay :
31
        PowerD::ActiveDisplayWithProximityBlanking;
32
33
    if (!last_request || last_request->state != expectedState)
34
    {
35
        decltype(last_request) old_request{ std::move(last_request) };
36
        last_request.reset(new PendingRequest{ powerd.requestState(expectedState), expectedState });
37
38
        if (last_request->cookie.isEmpty())
39
            last_request.reset();
40
41
        if (old_request)
42
            powerd.clearState( old_request->cookie );
43
    }
44
}
45
109 by Andreas Pokorny
Fixes power state change requests when multiple calls are active
46
void PowerDAudioModeMediator::audioOutputClosed()
106 by Andreas Pokorny
Request proximity based screen blanking from powerd
47
{
48
    if (last_request)
49
    {
50
        powerd.clearState( last_request->cookie );
51
        last_request.reset();
52
    }
53
}