/
batterynotifier.h
153 lines (136 loc) · 4.92 KB
/
batterynotifier.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** Copyright (C) 2012-2019 Jolla Ltd.
** Copyright (c) 2019 Open Mobile Platform LLC.
**
** Contact: Robin Burchell <robin.burchell@jollamobile.com>
**
** This file is part of lipstick.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#ifndef BATTERYNOTIFIER_H
#define BATTERYNOTIFIER_H
#include <QObject>
#include <QTimer>
#include <qmcechargertype.h>
#include <qmcechargerstate.h>
#include <qmcebatterystatus.h>
#include <qmcebatterylevel.h>
#include <qmcepowersavemode.h>
#include <qmcedisplay.h>
#include <qmcetklock.h>
#include <qmcecallstate.h>
#include <qusbmoded.h>
class NotificationManager;
class BackgroundActivity;
/*!
* Implements the configuration and state for the battery, the power save mode.
*/
class BatteryNotifier : public QObject
{
Q_OBJECT
public:
/*!
* Creates a new battery business logic.
*
* \param the parent QObject
*/
BatteryNotifier(QObject *parent = NULL);
/*!
* Destroys the battery business logic.
*/
virtual ~BatteryNotifier();
private slots:
void onNotificationClosed(uint id, uint reason);
void onChargerTypeChanged();
void onChargerStateChanged();
void onBatteryStatusChanged();
void onBatteryLevelChanged();
void onPowerSaveModeChanged();
void onDisplayChanged();
void onTkLockChanged();
void onCallStateChanged();
void onTargetUsbModeChanged();
void onBatteryLowTimeout();
void onChargingFailureTimeout();
void onEvaluateStateTimeout();
private:
enum NotificationType {
NotificationCharging,
NotificationChargingComplete,
NotificationRemoveCharger,
NotificationChargingNotStarted,
NotificationRechargeBattery,
NotificationEnteringPSM,
NotificationExitingPSM,
NotificationLowBattery,
NotificationNotEnoughPower,
NotificationFirst = NotificationCharging,
NotificationLast = NotificationNotEnoughPower,
};
struct QueuedNotification {
NotificationType m_type;
uint m_id;
};
struct State {
QMceChargerType::Type m_chargerType = QMceChargerType::None;
bool m_chargerState = false;
QMceBatteryStatus::Status m_batteryStatus = QMceBatteryStatus::Ok;
int m_batteryLevel = 50;
int m_minimumBatteryLevel = 0;
bool m_powerSaveMode = false;
QMceDisplay::State m_displayState = QMceDisplay::DisplayOn;
bool m_tkLock = false;
QMceCallState::State m_callState = QMceCallState::None;
QMceCallState::Type m_callType = QMceCallState::Normal;
QString m_usbMode;
bool m_suppressCharging = false;
};
typedef QSet<NotificationType> NotificationTypeSet;
typedef QList<NotificationType> NotificationTypeList;
//! Sends a notification based on the notification type
void sendNotification(BatteryNotifier::NotificationType type);
//! Removes any active notifications in the given type set
void removeNotifications(const NotificationTypeSet &toRemove);
//! Starts the low battery notifier if not already started
void startLowBatteryNotifier();
//! Stops the low battery notifier if not already stopped
void stopLowBatteryNotifier();
//! Adjust delay for the next repeated low battery warning
void updateLowBatteryNotifier();
static bool notificationTriggeringEdge(NotificationType type);
static bool evaluateNotificationLevel(NotificationType type,
const State &state);
void evaluateNotificationTriggering(NotificationType type,
const State &previousState,
const State ¤tState,
NotificationTypeSet &toRemove,
NotificationTypeList &toSend);
void updateDerivedProperties();
void scheduleStateEvaluation();
QList<QueuedNotification> m_notifications;
QTimer m_evaluateStateTimer;
QTimer m_chargingFailureTimer;
State m_currentState;
State m_previousState;
int m_lowBatteryRepeatLevel;
NotificationManager *m_notificationManager;
QMceChargerType *m_mceChargerType;
QMceChargerState *m_mceChargerState;
QMceBatteryStatus *m_mceBatteryStatus;;
QMceBatteryLevel *m_mceBatteryLevel;
QMcePowerSaveMode *m_mcePowerSaveMode;
QMceDisplay *m_mceDisplay;
QMceTkLock *m_mceTkLock;
QMceCallState *m_mceCallState;
QUsbModed *m_usbModed;
BackgroundActivity *m_lowBatteryRepeatActivity;
};
#endif