[app] Made low battery level configurable via dconf

There's no UI for it, though
This commit is contained in:
Slava Monich 2023-05-22 02:32:54 +03:00
parent cb9b7f9180
commit f554f1f950
3 changed files with 108 additions and 91 deletions

View file

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2015-2021 Jolla Ltd.
Copyright (C) 2015-2023 Slava Monich <slava@monich.com> Copyright (C) 2015-2023 Slava Monich <slava@monich.com>
Copyright (C) 2015-2021 Jolla Ltd.
You may use this file under the terms of BSD license as follows: You may use this file under the terms of BSD license as follows:
@ -18,17 +18,15 @@
contributors may be used to endorse or promote products derived contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/ */
import QtQuick 2.0 import QtQuick 2.0
@ -57,7 +55,7 @@ ApplicationWindow {
Settings.currentBook && Settings.keepDisplayOn && Settings.currentBook && Settings.keepDisplayOn &&
(HarbourBattery.batteryState === HarbourBattery.BatteryStateCharging || (HarbourBattery.batteryState === HarbourBattery.BatteryStateCharging ||
HarbourBattery.batteryLevel === 0 || // Zero if unknown (not reported by mce) HarbourBattery.batteryLevel === 0 || // Zero if unknown (not reported by mce)
HarbourBattery.batteryLevel >= 20) HarbourBattery.batteryLevel >= Settings.lowBatteryLevel)
} }
Binding { Binding {

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2015-2022 Jolla Ltd. * Copyright (C) 2015-2022 Jolla Ltd.
* Copyright (C) 2015-2022 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -18,17 +18,15 @@
* contributors may be used to endorse or promote products derived * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "BooksSettings.h" #include "BooksSettings.h"
@ -54,8 +52,9 @@
#define KEY_CURRENT_BOOK DCONF_PATH_("currentBook") #define KEY_CURRENT_BOOK DCONF_PATH_("currentBook")
#define KEY_CURRENT_FOLDER DCONF_PATH_("currentFolder") #define KEY_CURRENT_FOLDER DCONF_PATH_("currentFolder")
#define KEY_REMOVABLE_ROOT DCONF_PATH_("removableRoot") #define KEY_REMOVABLE_ROOT DCONF_PATH_("removableRoot")
#define KEY_KEEP_DISPLAY_ON DCONF_PATH_("keepDisplayOn")
#define KEY_BOOK_PULL_DOWN_MENU DCONF_PATH_("bookPullDownMenu") #define KEY_BOOK_PULL_DOWN_MENU DCONF_PATH_("bookPullDownMenu")
#define KEY_KEEP_DISPLAY_ON DCONF_PATH_("keepDisplayOn")
#define KEY_LOW_BATTERY_LEVEL DCONF_PATH_("lowBatteryLevel")
#define KEY_VOLUME_UP_ACTION DCONF_PATH_("volumeUpAction") #define KEY_VOLUME_UP_ACTION DCONF_PATH_("volumeUpAction")
#define KEY_VOLUME_DOWN_ACTION DCONF_PATH_("volumeDownAction") #define KEY_VOLUME_DOWN_ACTION DCONF_PATH_("volumeDownAction")
#define KEY_ORIENTATION DCONF_PATH_("orientation") #define KEY_ORIENTATION DCONF_PATH_("orientation")
@ -69,11 +68,12 @@
#define DEFAULT_CURRENT_BOOK QString() #define DEFAULT_CURRENT_BOOK QString()
#define DEFAULT_CURRENT_FOLDER QString() #define DEFAULT_CURRENT_FOLDER QString()
#define DEFAULT_REMOVABLE_ROOT "Books" #define DEFAULT_REMOVABLE_ROOT "Books"
#define DEFAULT_KEEP_DISPLAY_ON false
#define DEFAULT_BOOK_PULL_DOWN_MENU true #define DEFAULT_BOOK_PULL_DOWN_MENU true
#define DEFAULT_VOLUME_UP_ACTION (BooksSettings::ActionNextPage) #define DEFAULT_KEEP_DISPLAY_ON false
#define DEFAULT_VOLUME_DOWN_ACTION (BooksSettings::ActionPreviousPage) #define DEFAULT_LOW_BATTERY_LEVEL 20 // percent
#define DEFAULT_ORIENTATION (BooksSettings::OrientationAny) #define DEFAULT_VOLUME_UP_ACTION BooksSettings::ActionNextPage
#define DEFAULT_VOLUME_DOWN_ACTION BooksSettings::ActionPreviousPage
#define DEFAULT_ORIENTATION BooksSettings::OrientationAny
// ========================================================================== // ==========================================================================
// BooksSettings::TextStyle // BooksSettings::TextStyle
@ -257,8 +257,9 @@ public:
MGConfItem* iPageDetailsFixedConf; MGConfItem* iPageDetailsFixedConf;
MGConfItem* iTurnPageByTapConf; MGConfItem* iTurnPageByTapConf;
MGConfItem* iSampleBookCopiedConf; MGConfItem* iSampleBookCopiedConf;
MGConfItem* iKeepDisplayOnConf;
MGConfItem* iBookPullDownMenuConf; MGConfItem* iBookPullDownMenuConf;
MGConfItem* iKeepDisplayOnConf;
MGConfItem* iLowBatteryLevelConf;
MGConfItem* iVolumeUpActionConf; MGConfItem* iVolumeUpActionConf;
MGConfItem* iVolumeDownActionConf; MGConfItem* iVolumeDownActionConf;
MGConfItem* iCurrentFolderConf; MGConfItem* iCurrentFolderConf;
@ -282,8 +283,9 @@ BooksSettings::Private::Private(BooksSettings* aParent) :
iPageDetailsFixedConf(new MGConfItem(KEY_PAGE_DETAILS_FIXED, this)), iPageDetailsFixedConf(new MGConfItem(KEY_PAGE_DETAILS_FIXED, this)),
iTurnPageByTapConf(new MGConfItem(KEY_TURN_PAGE_BY_TAP, this)), iTurnPageByTapConf(new MGConfItem(KEY_TURN_PAGE_BY_TAP, this)),
iSampleBookCopiedConf(new MGConfItem(KEY_SAMPLE_BOOK_COPIED, this)), iSampleBookCopiedConf(new MGConfItem(KEY_SAMPLE_BOOK_COPIED, this)),
iKeepDisplayOnConf(new MGConfItem(KEY_KEEP_DISPLAY_ON, this)),
iBookPullDownMenuConf(new MGConfItem(KEY_BOOK_PULL_DOWN_MENU, this)), iBookPullDownMenuConf(new MGConfItem(KEY_BOOK_PULL_DOWN_MENU, this)),
iKeepDisplayOnConf(new MGConfItem(KEY_KEEP_DISPLAY_ON, this)),
iLowBatteryLevelConf(new MGConfItem(KEY_LOW_BATTERY_LEVEL, this)),
iVolumeUpActionConf(new MGConfItem(KEY_VOLUME_UP_ACTION, this)), iVolumeUpActionConf(new MGConfItem(KEY_VOLUME_UP_ACTION, this)),
iVolumeDownActionConf(new MGConfItem(KEY_VOLUME_DOWN_ACTION, this)), iVolumeDownActionConf(new MGConfItem(KEY_VOLUME_DOWN_ACTION, this)),
iCurrentFolderConf(new MGConfItem(KEY_CURRENT_FOLDER, this)), iCurrentFolderConf(new MGConfItem(KEY_CURRENT_FOLDER, this)),
@ -303,8 +305,9 @@ BooksSettings::Private::Private(BooksSettings* aParent) :
connect(iPageDetailsFixedConf, SIGNAL(valueChanged()), aParent, SIGNAL(pageDetailsFixedChanged())); connect(iPageDetailsFixedConf, SIGNAL(valueChanged()), aParent, SIGNAL(pageDetailsFixedChanged()));
connect(iTurnPageByTapConf, SIGNAL(valueChanged()), aParent, SIGNAL(turnPageByTapChanged())); connect(iTurnPageByTapConf, SIGNAL(valueChanged()), aParent, SIGNAL(turnPageByTapChanged()));
connect(iSampleBookCopiedConf, SIGNAL(valueChanged()), aParent, SIGNAL(sampleBookCopiedChanged())); connect(iSampleBookCopiedConf, SIGNAL(valueChanged()), aParent, SIGNAL(sampleBookCopiedChanged()));
connect(iKeepDisplayOnConf, SIGNAL(valueChanged()), aParent, SIGNAL(keepDisplayOnChanged()));
connect(iBookPullDownMenuConf, SIGNAL(valueChanged()), aParent, SIGNAL(bookPullDownMenuChanged())); connect(iBookPullDownMenuConf, SIGNAL(valueChanged()), aParent, SIGNAL(bookPullDownMenuChanged()));
connect(iKeepDisplayOnConf, SIGNAL(valueChanged()), aParent, SIGNAL(keepDisplayOnChanged()));
connect(iLowBatteryLevelConf, SIGNAL(valueChanged()), aParent, SIGNAL(lowBatteryLevelChanged()));
connect(iVolumeUpActionConf, SIGNAL(valueChanged()), aParent, SIGNAL(volumeUpActionChanged())); connect(iVolumeUpActionConf, SIGNAL(valueChanged()), aParent, SIGNAL(volumeUpActionChanged()));
connect(iVolumeDownActionConf, SIGNAL(valueChanged()), aParent, SIGNAL(volumeDownActionChanged())); connect(iVolumeDownActionConf, SIGNAL(valueChanged()), aParent, SIGNAL(volumeDownActionChanged()));
connect(iOrientationConf, SIGNAL(valueChanged()), aParent, SIGNAL(orientationChanged())); connect(iOrientationConf, SIGNAL(valueChanged()), aParent, SIGNAL(orientationChanged()));
@ -686,20 +689,6 @@ BooksSettings::setTurnPageByTap(
iPrivate->iTurnPageByTapConf->set(aValue); iPrivate->iTurnPageByTapConf->set(aValue);
} }
bool
BooksSettings::keepDisplayOn() const
{
return iPrivate->iKeepDisplayOnConf->value(DEFAULT_KEEP_DISPLAY_ON).toBool();
}
void
BooksSettings::setKeepDisplayOn(
bool aValue)
{
HDEBUG(aValue);
iPrivate->iKeepDisplayOnConf->set(aValue);
}
bool bool
BooksSettings::bookPullDownMenu() const BooksSettings::bookPullDownMenu() const
{ {
@ -727,6 +716,33 @@ BooksSettings::setSampleBookCopied()
iPrivate->iSampleBookCopiedConf->set(true); iPrivate->iSampleBookCopiedConf->set(true);
} }
bool
BooksSettings::keepDisplayOn() const
{
return iPrivate->iKeepDisplayOnConf->value(DEFAULT_KEEP_DISPLAY_ON).toBool();
}
void
BooksSettings::setKeepDisplayOn(
bool aValue)
{
HDEBUG(aValue);
iPrivate->iKeepDisplayOnConf->set(aValue);
}
int
BooksSettings::lowBatteryLevel() const
{
return iPrivate->iLowBatteryLevelConf->value(DEFAULT_LOW_BATTERY_LEVEL).toInt();
}
void
BooksSettings::setLowBatteryLevel(
int aValue)
{
HDEBUG(aValue);
iPrivate->iLowBatteryLevelConf->set(aValue);
}
BooksSettings::Action BooksSettings::Action
BooksSettings::volumeUpAction() const BooksSettings::volumeUpAction() const

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2023 Slava Monich <slava@monich.com>
* Copyright (C) 2015-2022 Jolla Ltd. * Copyright (C) 2015-2022 Jolla Ltd.
* Copyright (C) 2015-2022 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -18,17 +18,15 @@
* contributors may be used to endorse or promote products derived * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef BOOKS_SETTINGS_H #ifndef BOOKS_SETTINGS_H
@ -54,8 +52,9 @@ class BooksSettings : public BooksSettingsBase
Q_PROPERTY(bool pageDetailsFixed READ pageDetailsFixed WRITE setPageDetailsFixed NOTIFY pageDetailsFixedChanged) Q_PROPERTY(bool pageDetailsFixed READ pageDetailsFixed WRITE setPageDetailsFixed NOTIFY pageDetailsFixedChanged)
Q_PROPERTY(bool turnPageByTap READ turnPageByTap WRITE setTurnPageByTap NOTIFY turnPageByTapChanged) Q_PROPERTY(bool turnPageByTap READ turnPageByTap WRITE setTurnPageByTap NOTIFY turnPageByTapChanged)
Q_PROPERTY(bool sampleBookCopied READ sampleBookCopied NOTIFY sampleBookCopiedChanged) Q_PROPERTY(bool sampleBookCopied READ sampleBookCopied NOTIFY sampleBookCopiedChanged)
Q_PROPERTY(bool keepDisplayOn READ keepDisplayOn WRITE setKeepDisplayOn NOTIFY keepDisplayOnChanged)
Q_PROPERTY(bool bookPullDownMenu READ bookPullDownMenu WRITE setBookPullDownMenu NOTIFY bookPullDownMenuChanged) Q_PROPERTY(bool bookPullDownMenu READ bookPullDownMenu WRITE setBookPullDownMenu NOTIFY bookPullDownMenuChanged)
Q_PROPERTY(bool keepDisplayOn READ keepDisplayOn WRITE setKeepDisplayOn NOTIFY keepDisplayOnChanged)
Q_PROPERTY(int lowBatteryLevel READ lowBatteryLevel WRITE setLowBatteryLevel NOTIFY lowBatteryLevelChanged)
Q_PROPERTY(int volumeUpAction READ volumeUpAction WRITE setVolumeUpAction NOTIFY volumeUpActionChanged) Q_PROPERTY(int volumeUpAction READ volumeUpAction WRITE setVolumeUpAction NOTIFY volumeUpActionChanged)
Q_PROPERTY(int volumeDownAction READ volumeDownAction WRITE setVolumeDownAction NOTIFY volumeDownActionChanged) Q_PROPERTY(int volumeDownAction READ volumeDownAction WRITE setVolumeDownAction NOTIFY volumeDownActionChanged)
Q_PROPERTY(QObject* currentBook READ currentBook WRITE setCurrentBook NOTIFY currentBookChanged) Q_PROPERTY(QObject* currentBook READ currentBook WRITE setCurrentBook NOTIFY currentBookChanged)
@ -111,15 +110,18 @@ public:
bool turnPageByTap() const; bool turnPageByTap() const;
void setTurnPageByTap(bool); void setTurnPageByTap(bool);
bool keepDisplayOn() const;
void setKeepDisplayOn(bool);
bool bookPullDownMenu() const; bool bookPullDownMenu() const;
void setBookPullDownMenu(bool); void setBookPullDownMenu(bool);
bool sampleBookCopied() const; bool sampleBookCopied() const;
void setSampleBookCopied(); void setSampleBookCopied();
bool keepDisplayOn() const;
void setKeepDisplayOn(bool);
int lowBatteryLevel() const;
void setLowBatteryLevel(int);
Action volumeUpAction() const; Action volumeUpAction() const;
void setVolumeUpAction(int); void setVolumeUpAction(int);
@ -150,8 +152,9 @@ Q_SIGNALS:
void pageDetailsFixedChanged(); void pageDetailsFixedChanged();
void turnPageByTapChanged(); void turnPageByTapChanged();
void sampleBookCopiedChanged(); void sampleBookCopiedChanged();
void keepDisplayOnChanged();
void bookPullDownMenuChanged(); void bookPullDownMenuChanged();
void keepDisplayOnChanged();
void lowBatteryLevelChanged();
void volumeUpActionChanged(); void volumeUpActionChanged();
void volumeDownActionChanged(); void volumeDownActionChanged();
void currentBookChanged(); void currentBookChanged();