1 /***************************************************************************
2  *   Copyright (C) 2016 by Jan Grulich <jgrulich@redhat.com>               *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
18  ***************************************************************************/
19 
20 
21 #ifndef POWERDEVIL_BUNDLEDACTIONS_WIRELESSPOWERSAVING_H
22 #define POWERDEVIL_BUNDLEDACTIONS_WIRELESSPOWERSAVING_H
23 
24 #include <powerdevilaction.h>
25 #include <powerdevilbackendinterface.h>
26 
27 #include <BluezQt/Manager>
28 
29 namespace PowerDevil {
30 namespace BundledActions {
31 
32 class WirelessPowerSaving : public PowerDevil::Action
33 {
34     Q_OBJECT
35     Q_DISABLE_COPY(WirelessPowerSaving)
36     Q_CLASSINFO("D-Bus Interface", "org.kde.Solid.PowerManagement.Actions.WirelessPowerSaving")
37 
38 public:
39     enum PowerSavingOption {
40         NoAction = 0,
41         TurnOff = 1,
42         TurnOn = 2
43     };
44 
45     explicit WirelessPowerSaving(QObject* parent);
46     ~WirelessPowerSaving() override = default;
47 
48 protected:
49     void onProfileUnload() override;
50     void onWakeupFromIdle() override;
51     void onIdleTimeout(int msec) override;
52     void onProfileLoad() override;
53     void triggerImpl(const QVariantMap& args) override;
54     bool isSupported() override;
55 
56 public:
57     bool loadAction(const KConfigGroup& config) override;
58 
59 public Q_SLOTS:
60     // DBus export
61     void setBluetoothEnabled(bool enabled);
62     void setMobileBroadbandEnabled(bool enabled);
63     void setWirelessEnabled(bool enabled);
64 
65 private:
66     BluezQt::Manager *m_btManager;
67 
68     QString m_currentProfile;
69     QString m_lastProfile;
70 
71     // Options for current profile
72     PowerSavingOption m_currentProfileWifiOption;
73     PowerSavingOption m_currentProfileWwanOption;
74     PowerSavingOption m_currentProfileBtOption;
75 
76     // Options for previous profile
77     PowerSavingOption m_lastProfileWifiOption;
78     PowerSavingOption m_lastProfileWwanOption;
79     PowerSavingOption m_lastProfileBtOption;
80 
81     // State of devices before we change that due to changed profile
82     bool m_lastWifiState;
83     bool m_lastWwanState;
84     bool m_lastBtState;
85 };
86 
87 }
88 
89 }
90 
91 #endif // POWERDEVIL_BUNDLEDACTIONS_WIRELESSPOWERSAVING_H
92