File: powerdevilaction.cpp

package info (click to toggle)
powerdevil 4%3A6.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,680 kB
  • sloc: cpp: 13,284; xml: 1,911; python: 1,204; sh: 19; makefile: 10
file content (101 lines) | stat: -rw-r--r-- 2,206 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 *   SPDX-FileCopyrightText: 2010 Dario Freddi <drf@kde.org>
 *
 *   SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "powerdevilaction.h"

#include "powerdevil_debug.h"
#include "powerdevilcore.h"

#include <QDebug>

namespace PowerDevil
{

Action::Action(QObject *parent)
    : QObject(parent)
{
    m_core = qobject_cast<PowerDevil::Core *>(parent);
}

Action::~Action()
{
}

void Action::registerIdleTimeout(std::chrono::milliseconds timeout)
{
    m_registeredIdleTimeouts.append(timeout);
    m_core->registerActionTimeout(this, timeout);
}

void Action::unregisterIdleTimeouts()
{
    // Remove all registered idle timeouts, if any
    m_core->unregisterActionTimeouts(this);
    m_registeredIdleTimeouts.clear();
}

void Action::unloadAction()
{
    unregisterIdleTimeouts();
}

bool Action::isSupported()
{
    return true;
}

Core *Action::core() const
{
    return m_core;
}

void Action::trigger(const QVariantMap &args)
{
    if (args.contains(QStringLiteral("Explicit")) && args[QStringLiteral("Explicit")].toBool()) {
        // The action was explicitly triggered by the user, hence any policy check is bypassed.
        triggerImpl(args);
    } else {
        // The action was taken automatically: let's check if we have the rights to do that
        PolicyAgent::RequiredPolicies unsatisfiablePolicies = PolicyAgent::instance()->requirePolicyCheck(m_requiredPolicies);
        if (unsatisfiablePolicies == PolicyAgent::None) {
            // Ok, let's trigger the action
            triggerImpl(args);
        } else {
            // TODO: Notify somehow?
            qCWarning(POWERDEVIL) << "Unsatisfied policies, the action has been aborted";
        }
    }
}

void Action::setRequiredPolicies(PolicyAgent::RequiredPolicies requiredPolicies)
{
    m_requiredPolicies = requiredPolicies;
}

void Action::triggerImpl(const QVariantMap &args)
{
    Q_UNUSED(args);
}

void Action::onIdleTimeout(std::chrono::milliseconds /*timeout*/)
{
}

void Action::onWakeupFromIdle()
{
}

void Action::onProfileLoad(const QString & /*previousProfile*/, const QString & /*newProfile*/)
{
}

void Action::onProfileUnload()
{
}

} // namespace PowerDevil

#include "moc_powerdevilaction.cpp"