2015-06-28 14:22:35 +03:00
|
|
|
/*
|
2018-05-16 23:55:43 +03:00
|
|
|
* Copyright (C) 2015-2018 Jolla Ltd.
|
|
|
|
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
2015-06-28 14:22:35 +03:00
|
|
|
*
|
|
|
|
* You may use this file under the terms of the BSD license as follows:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2016-06-23 18:34:13 +03:00
|
|
|
* * Neither the name of Jolla Ltd nor the names of its contributors
|
2015-06-28 14:22:35 +03:00
|
|
|
* may be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (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 "BooksTextStyle.h"
|
2016-10-08 23:36:28 +03:00
|
|
|
#include "BooksTextView.h"
|
2015-06-28 14:22:35 +03:00
|
|
|
#include "BooksBook.h"
|
|
|
|
#include "BooksDefs.h"
|
2015-07-15 22:59:00 +03:00
|
|
|
#include "BooksUtil.h"
|
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
#include "HarbourDebug.h"
|
|
|
|
|
|
|
|
#include <MGConfItem>
|
|
|
|
|
2017-08-08 16:09:01 +03:00
|
|
|
#define DCONF_PATH BOOKS_DCONF_ROOT
|
|
|
|
#define KEY_FONT_SIZE "fontSize"
|
|
|
|
#define KEY_PAGE_DETAILS "pageDetails"
|
2018-07-23 00:52:14 +03:00
|
|
|
#define KEY_PAGE_DETAILS_FIXED "pageDetailsFixed"
|
2018-07-23 23:55:56 +03:00
|
|
|
#define KEY_TURN_PAGE_BY_TAP "turnPageByTap"
|
2017-08-08 16:09:01 +03:00
|
|
|
#define KEY_CURRENT_BOOK "currentBook"
|
|
|
|
#define KEY_CURRENT_FOLDER "currentFolder"
|
|
|
|
#define KEY_REMOVABLE_ROOT "removableRoot"
|
|
|
|
#define KEY_INVERT_COLORS "invertColors"
|
2018-05-16 23:55:43 +03:00
|
|
|
#define KEY_KEEP_DISPLAY_ON "keepDisplayOn"
|
2017-08-08 16:09:01 +03:00
|
|
|
#define KEY_VOLUME_UP_ACTION "volumeUpAction"
|
|
|
|
#define KEY_VOLUME_DOWN_ACTION "volumeDownAction"
|
|
|
|
#define KEY_ORIENTATION "orientation"
|
|
|
|
|
|
|
|
#define DEFAULT_FONT_SIZE 0
|
|
|
|
#define DEFAULT_PAGE_DETAILS 0
|
2018-07-23 00:52:14 +03:00
|
|
|
#define DEFAULT_PAGE_DETAILS_FIXED false
|
2018-07-23 23:55:56 +03:00
|
|
|
#define DEFAULT_TURN_PAGE_BY_TAP false
|
2017-08-08 16:09:01 +03:00
|
|
|
#define DEFAULT_CURRENT_BOOK QString()
|
|
|
|
#define DEFAULT_CURRENT_FOLDER QString()
|
|
|
|
#define DEFAULT_REMOVABLE_ROOT "Books"
|
|
|
|
#define DEFAULT_INVERT_COLORS false
|
2018-05-16 23:55:43 +03:00
|
|
|
#define DEFAULT_KEEP_DISPLAY_ON false
|
2017-08-08 16:09:01 +03:00
|
|
|
#define DEFAULT_VOLUME_UP_ACTION (BooksSettings::ActionNextPage)
|
|
|
|
#define DEFAULT_VOLUME_DOWN_ACTION (BooksSettings::ActionPreviousPage)
|
|
|
|
#define DEFAULT_ORIENTATION (BooksSettings::OrientationAny)
|
2015-06-28 14:22:35 +03:00
|
|
|
|
2015-08-23 14:47:25 +03:00
|
|
|
#define PAGETOOL_COLOR QColor(128,128,128) // any bg
|
|
|
|
#define NORMAL_PAGETOOL_HIGHLIGHT_COLOR QColor(64,64,64) // on white
|
|
|
|
#define INVERTED_PAGETOOL_HIGHLIGHT_COLOR QColor(192,192,192) // on black
|
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
// ==========================================================================
|
|
|
|
// BooksSettings::TextStyle
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
class BooksSettings::TextStyle : public ZLTextStyle
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextStyle(int aFontSizeModifier) :
|
|
|
|
iDefaultStyle(BooksTextStyle::defaults()),
|
|
|
|
iFontSize(iDefaultStyle->fontSize() + 2*aFontSizeModifier)
|
|
|
|
{ HDEBUG(iFontSize); }
|
|
|
|
|
|
|
|
bool isDecorated() const;
|
|
|
|
|
2015-08-09 00:54:38 +03:00
|
|
|
const std::vector<std::string> &fontFamilies() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
int fontSize() const;
|
|
|
|
bool bold() const;
|
|
|
|
bool italic() const;
|
|
|
|
|
|
|
|
const std::string &colorStyle() const;
|
|
|
|
|
|
|
|
short spaceBefore(const ZLTextStyleEntry::Metrics& aMetrics) const;
|
|
|
|
short spaceAfter(const ZLTextStyleEntry::Metrics& aMetrics) const;
|
|
|
|
short lineStartIndent(const ZLTextStyleEntry::Metrics& aMetrics, bool aRtl) const;
|
|
|
|
short lineEndIndent(const ZLTextStyleEntry::Metrics& aMetrics, bool aRtl) const;
|
|
|
|
short firstLineIndentDelta(const ZLTextStyleEntry::Metrics& aMetrics) const;
|
|
|
|
int verticalShift() const;
|
|
|
|
|
|
|
|
ZLTextAlignmentType alignment() const;
|
|
|
|
|
|
|
|
double lineSpace() const;
|
|
|
|
bool allowHyphenations() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
shared_ptr<ZLTextStyle> iDefaultStyle;
|
|
|
|
int iFontSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::string&
|
|
|
|
BooksSettings::TextStyle::colorStyle() const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->colorStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BooksSettings::TextStyle::isDecorated() const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->isDecorated();
|
|
|
|
}
|
|
|
|
|
2015-08-09 00:54:38 +03:00
|
|
|
const std::vector<std::string>&
|
|
|
|
BooksSettings::TextStyle::fontFamilies() const
|
2015-06-28 14:22:35 +03:00
|
|
|
{
|
2015-08-09 00:54:38 +03:00
|
|
|
return iDefaultStyle->fontFamilies();
|
2015-06-28 14:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
BooksSettings::TextStyle::fontSize() const
|
|
|
|
{
|
|
|
|
return iFontSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BooksSettings::TextStyle::bold() const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->bold();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BooksSettings::TextStyle::italic() const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->italic();
|
|
|
|
}
|
|
|
|
|
|
|
|
short
|
|
|
|
BooksSettings::TextStyle::spaceBefore(
|
|
|
|
const ZLTextStyleEntry::Metrics& aMetrics) const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->spaceBefore(aMetrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
short
|
|
|
|
BooksSettings::TextStyle::spaceAfter(
|
|
|
|
const ZLTextStyleEntry::Metrics& aMetrics) const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->spaceAfter(aMetrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
short
|
|
|
|
BooksSettings::TextStyle::lineStartIndent(
|
|
|
|
const ZLTextStyleEntry::Metrics& aMetrics,
|
|
|
|
bool aRtl) const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->lineStartIndent(aMetrics, aRtl);
|
|
|
|
}
|
|
|
|
|
|
|
|
short
|
|
|
|
BooksSettings::TextStyle::lineEndIndent(
|
|
|
|
const ZLTextStyleEntry::Metrics& aMetrics,
|
|
|
|
bool aRtl) const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->lineEndIndent(aMetrics, aRtl);
|
|
|
|
}
|
|
|
|
|
|
|
|
short
|
|
|
|
BooksSettings::TextStyle::firstLineIndentDelta(
|
|
|
|
const ZLTextStyleEntry::Metrics& aMetrics) const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->firstLineIndentDelta(aMetrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
BooksSettings::TextStyle::verticalShift() const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->verticalShift();
|
|
|
|
}
|
|
|
|
|
|
|
|
ZLTextAlignmentType
|
|
|
|
BooksSettings::TextStyle::alignment() const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->alignment();
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
BooksSettings::TextStyle::lineSpace() const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->lineSpace();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BooksSettings::TextStyle::allowHyphenations() const
|
|
|
|
{
|
|
|
|
return iDefaultStyle->allowHyphenations();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ==========================================================================
|
2016-10-17 00:48:25 +03:00
|
|
|
// BooksSettings::Private
|
2015-06-28 14:22:35 +03:00
|
|
|
// ==========================================================================
|
|
|
|
|
2016-10-17 00:48:25 +03:00
|
|
|
class BooksSettings::Private : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
Private(BooksSettings* aParent);
|
|
|
|
|
|
|
|
bool updateCurrentBook();
|
|
|
|
bool updateCurrentStorage();
|
|
|
|
int currentFontSize() const;
|
|
|
|
int fontSize(int aFontSizeAdjust) const;
|
|
|
|
QString currentFolder() const;
|
|
|
|
shared_ptr<ZLTextStyle> textStyle(int aFontSizeAdjust) const;
|
|
|
|
void setCurrentBook(QObject* aBook);
|
2017-08-08 16:09:01 +03:00
|
|
|
static Action getAction(MGConfItem* aItem, Action aDefault);
|
2016-10-17 00:48:25 +03:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void onFontSizeValueChanged();
|
|
|
|
void onCurrentBookPathChanged();
|
|
|
|
void onCurrentFolderChanged();
|
|
|
|
|
2016-10-16 23:36:13 +03:00
|
|
|
public:
|
|
|
|
static QWeakPointer<BooksSettings> sSharedInstance;
|
2016-10-17 00:48:25 +03:00
|
|
|
BooksSettings* iParent;
|
|
|
|
MGConfItem* iFontSizeConf;
|
|
|
|
MGConfItem* iPageDetailsConf;
|
2018-07-23 00:52:14 +03:00
|
|
|
MGConfItem* iPageDetailsFixedConf;
|
2018-07-23 23:55:56 +03:00
|
|
|
MGConfItem* iTurnPageByTapConf;
|
2016-10-17 00:48:25 +03:00
|
|
|
MGConfItem* iInvertColorsConf;
|
2018-05-16 23:55:43 +03:00
|
|
|
MGConfItem* iKeepDisplayOnConf;
|
2017-08-08 16:09:01 +03:00
|
|
|
MGConfItem* iVolumeUpActionConf;
|
|
|
|
MGConfItem* iVolumeDownActionConf;
|
2016-10-17 00:48:25 +03:00
|
|
|
MGConfItem* iCurrentFolderConf;
|
|
|
|
MGConfItem* iCurrentBookPathConf;
|
|
|
|
MGConfItem* iOrientationConf;
|
2016-10-22 20:43:00 +03:00
|
|
|
MGConfItem* iRemovableRootConf;
|
2016-10-17 00:48:25 +03:00
|
|
|
mutable shared_ptr<ZLTextStyle> iTextStyle[FontSizeSteps+1];
|
|
|
|
BooksBook* iCurrentBook;
|
|
|
|
QString iCurrentStorageDevice;
|
|
|
|
int iFontSize;
|
2016-10-16 23:36:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
QWeakPointer<BooksSettings> BooksSettings::Private::sSharedInstance;
|
|
|
|
|
2016-10-17 00:48:25 +03:00
|
|
|
BooksSettings::Private::Private(BooksSettings* aParent) :
|
2015-06-28 14:22:35 +03:00
|
|
|
QObject(aParent),
|
2016-10-17 00:48:25 +03:00
|
|
|
iParent(aParent),
|
2015-12-13 14:46:53 +03:00
|
|
|
iFontSizeConf(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
|
|
|
|
iPageDetailsConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)),
|
2018-07-23 00:52:14 +03:00
|
|
|
iPageDetailsFixedConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS_FIXED, this)),
|
2018-07-23 23:55:56 +03:00
|
|
|
iTurnPageByTapConf(new MGConfItem(DCONF_PATH KEY_TURN_PAGE_BY_TAP, this)),
|
2015-12-13 14:46:53 +03:00
|
|
|
iInvertColorsConf(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)),
|
2018-05-16 23:55:43 +03:00
|
|
|
iKeepDisplayOnConf(new MGConfItem(DCONF_PATH KEY_KEEP_DISPLAY_ON, this)),
|
2017-08-08 16:09:01 +03:00
|
|
|
iVolumeUpActionConf(new MGConfItem(DCONF_PATH KEY_VOLUME_UP_ACTION, this)),
|
|
|
|
iVolumeDownActionConf(new MGConfItem(DCONF_PATH KEY_VOLUME_DOWN_ACTION, this)),
|
2015-12-13 14:46:53 +03:00
|
|
|
iCurrentFolderConf(new MGConfItem(DCONF_PATH KEY_CURRENT_FOLDER, this)),
|
|
|
|
iCurrentBookPathConf(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)),
|
2016-10-07 19:40:18 +03:00
|
|
|
iOrientationConf(new MGConfItem(DCONF_PATH KEY_ORIENTATION, this)),
|
2016-10-22 20:43:00 +03:00
|
|
|
iRemovableRootConf(new MGConfItem(DCONF_PATH KEY_REMOVABLE_ROOT, this)),
|
2016-10-17 00:48:25 +03:00
|
|
|
iCurrentBook(NULL)
|
2015-12-13 14:46:53 +03:00
|
|
|
{
|
2016-10-17 00:48:25 +03:00
|
|
|
iFontSize = currentFontSize();
|
2015-12-13 14:46:53 +03:00
|
|
|
connect(iFontSizeConf, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged()));
|
|
|
|
connect(iCurrentFolderConf, SIGNAL(valueChanged()), SLOT(onCurrentFolderChanged()));
|
|
|
|
connect(iCurrentBookPathConf, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
|
2016-10-17 00:48:25 +03:00
|
|
|
connect(iPageDetailsConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageDetailsChanged()));
|
2018-07-23 00:52:14 +03:00
|
|
|
connect(iPageDetailsFixedConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageDetailsFixedChanged()));
|
2018-07-23 23:55:56 +03:00
|
|
|
connect(iTurnPageByTapConf, SIGNAL(valueChanged()), iParent, SIGNAL(turnPageByTapChanged()));
|
2016-10-17 00:48:25 +03:00
|
|
|
connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(invertColorsChanged()));
|
|
|
|
connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageBackgroundColorChanged()));
|
2018-05-16 23:55:43 +03:00
|
|
|
connect(iKeepDisplayOnConf, SIGNAL(valueChanged()), iParent, SIGNAL(keepDisplayOnChanged()));
|
2017-08-08 16:09:01 +03:00
|
|
|
connect(iVolumeUpActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeUpActionChanged()));
|
|
|
|
connect(iVolumeDownActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeDownActionChanged()));
|
2016-10-17 00:48:25 +03:00
|
|
|
connect(iOrientationConf, SIGNAL(valueChanged()), iParent, SIGNAL(orientationChanged()));
|
2016-10-22 20:43:00 +03:00
|
|
|
connect(iRemovableRootConf, SIGNAL(valueChanged()), iParent, SIGNAL(removableRootChanged()));
|
2015-08-23 14:47:25 +03:00
|
|
|
}
|
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
int
|
2016-10-17 00:48:25 +03:00
|
|
|
BooksSettings::Private::currentFontSize() const
|
2015-06-28 14:22:35 +03:00
|
|
|
{
|
2015-12-13 14:46:53 +03:00
|
|
|
const int fontSize = iFontSizeConf->value(DEFAULT_FONT_SIZE).toInt();
|
|
|
|
if (fontSize < MinFontSize) {
|
|
|
|
return MinFontSize;
|
|
|
|
} else if (fontSize > MaxFontSize) {
|
|
|
|
return MaxFontSize;
|
|
|
|
} else {
|
|
|
|
return fontSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-10-17 00:48:25 +03:00
|
|
|
BooksSettings::Private::fontSize(
|
2015-12-13 14:46:53 +03:00
|
|
|
int aFontSizeAdjust) const
|
|
|
|
{
|
|
|
|
const int fontSize = iFontSize + aFontSizeAdjust;
|
|
|
|
if (fontSize < MinFontSize) {
|
|
|
|
return MinFontSize;
|
|
|
|
} else if (fontSize > MaxFontSize) {
|
|
|
|
return MaxFontSize;
|
|
|
|
} else {
|
|
|
|
return fontSize;
|
|
|
|
}
|
2015-06-28 14:22:35 +03:00
|
|
|
}
|
|
|
|
|
2016-10-17 00:48:25 +03:00
|
|
|
shared_ptr<ZLTextStyle>
|
|
|
|
BooksSettings::Private::textStyle(
|
|
|
|
int aFontSizeAdjust) const
|
|
|
|
{
|
|
|
|
const int size = fontSize(aFontSizeAdjust);
|
|
|
|
const int i = size - MinFontSize;
|
|
|
|
shared_ptr<ZLTextStyle> style = iTextStyle[i];
|
|
|
|
if (style.isNull()) {
|
|
|
|
style = new TextStyle(size);
|
|
|
|
iTextStyle[i] = style;
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
BooksSettings::Private::currentFolder() const
|
|
|
|
{
|
|
|
|
return iCurrentFolderConf->value(DEFAULT_CURRENT_FOLDER).toString();
|
|
|
|
}
|
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
void
|
2016-10-17 00:48:25 +03:00
|
|
|
BooksSettings::Private::setCurrentBook(
|
|
|
|
QObject* aBook)
|
2015-06-28 14:22:35 +03:00
|
|
|
{
|
2016-10-17 00:48:25 +03:00
|
|
|
BooksBook* book = qobject_cast<BooksBook*>(aBook);
|
|
|
|
if (iCurrentBook != book) {
|
|
|
|
if (iCurrentBook) iCurrentBook->release();
|
|
|
|
if (book) {
|
|
|
|
HDEBUG(book->path());
|
|
|
|
(iCurrentBook = book)->retain();
|
|
|
|
iCurrentBookPathConf->set(book->path());
|
|
|
|
} else {
|
|
|
|
iCurrentBook = NULL;
|
|
|
|
iCurrentBookPathConf->set(QString());
|
|
|
|
}
|
|
|
|
Q_EMIT iParent->currentBookChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BooksSettings::Private::updateCurrentBook()
|
|
|
|
{
|
|
|
|
QString path = iCurrentBookPathConf->value(DEFAULT_CURRENT_BOOK).toString();
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
if (iCurrentBook) {
|
|
|
|
iCurrentBook->release();
|
|
|
|
iCurrentBook = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (!iCurrentBook || iCurrentBook->path() != path) {
|
|
|
|
shared_ptr<Book> book = BooksUtil::bookFromFile(path);
|
|
|
|
if (!book.isNull()) {
|
|
|
|
QString rel;
|
|
|
|
QFileInfo info(path);
|
|
|
|
BooksStorageManager* mgr = BooksStorageManager::instance();
|
|
|
|
BooksStorage storage = mgr->storageForPath(info.path(), &rel);
|
|
|
|
if (storage.isValid()) {
|
|
|
|
if (iCurrentBook) iCurrentBook->release();
|
|
|
|
iCurrentBook = new BooksBook(storage, rel, book);
|
|
|
|
iCurrentBook->requestCoverImage();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (iCurrentBook) {
|
|
|
|
iCurrentBook->release();
|
|
|
|
iCurrentBook = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BooksSettings::Private::updateCurrentStorage()
|
|
|
|
{
|
|
|
|
BooksStorageManager* mgr = BooksStorageManager::instance();
|
|
|
|
BooksStorage storage = mgr->storageForPath(currentFolder());
|
|
|
|
if (storage.isValid() && storage.device() != iCurrentStorageDevice) {
|
|
|
|
iCurrentStorageDevice = storage.device();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-06-28 14:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-17 00:48:25 +03:00
|
|
|
BooksSettings::Private::onFontSizeValueChanged()
|
2015-06-28 14:22:35 +03:00
|
|
|
{
|
2015-12-13 14:46:53 +03:00
|
|
|
const int newSize = currentFontSize();
|
2015-06-28 14:22:35 +03:00
|
|
|
HDEBUG(newSize);
|
2015-12-13 14:46:53 +03:00
|
|
|
if (iFontSize != newSize) {
|
|
|
|
iFontSize = newSize;
|
|
|
|
for (int i=0; i<=FontSizeSteps; i++) {
|
|
|
|
iTextStyle[i].reset();
|
|
|
|
}
|
2016-10-17 00:48:25 +03:00
|
|
|
Q_EMIT iParent->fontSizeChanged();
|
|
|
|
Q_EMIT iParent->textStyleChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::Private::onCurrentFolderChanged()
|
|
|
|
{
|
|
|
|
if (updateCurrentStorage()) {
|
|
|
|
Q_EMIT iParent->currentStorageChanged();
|
|
|
|
}
|
|
|
|
Q_EMIT iParent->currentFolderChanged();
|
|
|
|
Q_EMIT iParent->relativePathChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::Private::onCurrentBookPathChanged()
|
|
|
|
{
|
|
|
|
if (updateCurrentBook()) {
|
|
|
|
Q_EMIT iParent->currentBookChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 16:09:01 +03:00
|
|
|
BooksSettings::Action
|
|
|
|
BooksSettings::Private::getAction(
|
|
|
|
MGConfItem* aItem,
|
|
|
|
Action aDefault)
|
|
|
|
{
|
|
|
|
// Need to cast int to enum right away to force "enumeration value not
|
|
|
|
// handled in switch" warning if we miss one of the actions:
|
|
|
|
Action value = (Action)aItem->value(aDefault).toInt();
|
|
|
|
switch (value) {
|
|
|
|
case ActionNone:
|
|
|
|
case ActionPreviousPage:
|
|
|
|
case ActionNextPage:
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return aDefault;
|
|
|
|
}
|
|
|
|
|
2016-10-17 00:48:25 +03:00
|
|
|
// ==========================================================================
|
|
|
|
// BooksSettings
|
|
|
|
// ==========================================================================
|
|
|
|
|
2017-08-08 16:09:01 +03:00
|
|
|
BooksSettings::BooksSettings(QObject* aParent) :
|
|
|
|
QObject(aParent),
|
2016-10-17 00:48:25 +03:00
|
|
|
iPrivate(new Private(this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QSharedPointer<BooksSettings>
|
|
|
|
BooksSettings::sharedInstance()
|
|
|
|
{
|
|
|
|
QSharedPointer<BooksSettings> instance = Private::sSharedInstance;
|
|
|
|
if (instance.isNull()) {
|
|
|
|
// QObject::deleteLater protects against trouble in case if the
|
|
|
|
// recipient of the signal drops the last shared reference.
|
|
|
|
instance = QSharedPointer<BooksSettings>(new BooksSettings, &QObject::deleteLater);
|
|
|
|
Private::sSharedInstance = instance;
|
2016-10-22 20:43:00 +03:00
|
|
|
// Finish initialization. These invoke BooksStorageManager::instance()
|
|
|
|
// which in turn calls BooksSettings::sharedInstance() to call
|
|
|
|
// removableRoot(). Now that Private::sSharedInstance is set, it
|
|
|
|
// won't cause infinite recursion although the returned BooksSettings
|
|
|
|
// object will be slightly under-initialized, so to speak. But that's
|
|
|
|
// ok as long as BooksStorageManager::instance() doesn't need anything
|
|
|
|
// from BooksSettings other than removableRoot()
|
|
|
|
instance->iPrivate->updateCurrentBook();
|
|
|
|
instance->iPrivate->updateCurrentStorage();
|
2016-10-17 00:48:25 +03:00
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BooksSettings::increaseFontSize()
|
|
|
|
{
|
|
|
|
if (iPrivate->iFontSize < MaxFontSize) {
|
|
|
|
setFontSize(iPrivate->iFontSize+1);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BooksSettings::decreaseFontSize()
|
|
|
|
{
|
|
|
|
if (iPrivate->iFontSize > MinFontSize) {
|
|
|
|
setFontSize(iPrivate->iFontSize-1);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2015-12-13 14:46:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 00:48:25 +03:00
|
|
|
void
|
|
|
|
BooksSettings::setFontSize(
|
|
|
|
int aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
|
|
|
iPrivate->iFontSizeConf->set(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
BooksSettings::fontSize() const
|
|
|
|
{
|
|
|
|
return iPrivate->iFontSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
BooksSettings::currentStorage() const
|
|
|
|
{
|
|
|
|
return iPrivate->iCurrentStorageDevice;
|
|
|
|
}
|
|
|
|
|
2015-12-13 14:46:53 +03:00
|
|
|
shared_ptr<ZLTextStyle>
|
|
|
|
BooksSettings::textStyle(
|
|
|
|
int aFontSizeAdjust) const
|
|
|
|
{
|
2016-10-17 00:48:25 +03:00
|
|
|
return iPrivate->textStyle(aFontSizeAdjust);
|
2015-06-28 14:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
BooksSettings::pageDetails() const
|
|
|
|
{
|
2016-10-17 00:48:25 +03:00
|
|
|
return iPrivate->iPageDetailsConf->value(DEFAULT_PAGE_DETAILS).toInt();
|
2015-06-28 14:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::setPageDetails(
|
|
|
|
int aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
2016-10-17 00:48:25 +03:00
|
|
|
iPrivate->iPageDetailsConf->set(aValue);
|
2015-06-28 14:22:35 +03:00
|
|
|
}
|
|
|
|
|
2018-07-23 00:52:14 +03:00
|
|
|
bool
|
|
|
|
BooksSettings::pageDetailsFixed() const
|
|
|
|
{
|
|
|
|
return iPrivate->iPageDetailsFixedConf->value(DEFAULT_PAGE_DETAILS_FIXED).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::setPageDetailsFixed(
|
|
|
|
bool aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
|
|
|
iPrivate->iPageDetailsFixedConf->set(aValue);
|
|
|
|
}
|
|
|
|
|
2018-07-23 23:55:56 +03:00
|
|
|
bool
|
|
|
|
BooksSettings::turnPageByTap() const
|
|
|
|
{
|
|
|
|
return iPrivate->iTurnPageByTapConf->value(DEFAULT_TURN_PAGE_BY_TAP).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::setTurnPageByTap(
|
|
|
|
bool aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
|
|
|
iPrivate->iTurnPageByTapConf->set(aValue);
|
|
|
|
}
|
|
|
|
|
2015-07-11 01:35:13 +03:00
|
|
|
bool
|
|
|
|
BooksSettings::invertColors() const
|
|
|
|
{
|
2016-10-17 00:48:25 +03:00
|
|
|
return iPrivate->iInvertColorsConf->value(DEFAULT_INVERT_COLORS).toBool();
|
2015-07-11 01:35:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::setInvertColors(
|
|
|
|
bool aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
2016-10-17 00:48:25 +03:00
|
|
|
iPrivate->iInvertColorsConf->set(aValue);
|
2015-07-11 01:35:13 +03:00
|
|
|
}
|
|
|
|
|
2018-05-16 23:55:43 +03:00
|
|
|
bool
|
|
|
|
BooksSettings::keepDisplayOn() const
|
|
|
|
{
|
|
|
|
return iPrivate->iKeepDisplayOnConf->value(DEFAULT_KEEP_DISPLAY_ON).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::setKeepDisplayOn(
|
|
|
|
bool aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
|
|
|
iPrivate->iKeepDisplayOnConf->set(aValue);
|
|
|
|
}
|
|
|
|
|
2017-08-08 16:09:01 +03:00
|
|
|
BooksSettings::Action
|
|
|
|
BooksSettings::volumeUpAction() const
|
|
|
|
{
|
|
|
|
return Private::getAction(iPrivate->iVolumeUpActionConf,
|
|
|
|
DEFAULT_VOLUME_UP_ACTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::setVolumeUpAction(
|
|
|
|
int aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
|
|
|
iPrivate->iVolumeUpActionConf->set(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
BooksSettings::Action
|
|
|
|
BooksSettings::volumeDownAction() const
|
|
|
|
{
|
|
|
|
return Private::getAction(iPrivate->iVolumeDownActionConf,
|
|
|
|
DEFAULT_VOLUME_DOWN_ACTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BooksSettings::setVolumeDownAction(
|
|
|
|
int aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
|
|
|
iPrivate->iVolumeDownActionConf->set(aValue);
|
|
|
|
}
|
|
|
|
|
2016-10-22 20:43:00 +03:00
|
|
|
QString
|
|
|
|
BooksSettings::removableRoot() const
|
|
|
|
{
|
|
|
|
return iPrivate->iRemovableRootConf->value(DEFAULT_REMOVABLE_ROOT).toString();
|
|
|
|
}
|
|
|
|
|
2016-06-23 18:34:13 +03:00
|
|
|
QString
|
|
|
|
BooksSettings::relativePath() const
|
|
|
|
{
|
|
|
|
QString rel;
|
|
|
|
BooksStorageManager::instance()->storageForPath(currentFolder(), &rel);
|
|
|
|
return rel;
|
|
|
|
}
|
|
|
|
|
2015-08-19 00:35:34 +03:00
|
|
|
QString
|
2015-08-19 18:18:25 +03:00
|
|
|
BooksSettings::currentFolder() const
|
2015-08-19 00:35:34 +03:00
|
|
|
{
|
2016-10-17 00:48:25 +03:00
|
|
|
return iPrivate->currentFolder();
|
2015-08-19 00:35:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-19 18:18:25 +03:00
|
|
|
BooksSettings::setCurrentFolder(
|
2015-08-19 00:35:34 +03:00
|
|
|
QString aValue)
|
|
|
|
{
|
|
|
|
HDEBUG(aValue);
|
2016-10-17 00:48:25 +03:00
|
|
|
iPrivate->iCurrentFolderConf->set(aValue);
|
2015-08-19 00:35:34 +03:00
|
|
|
}
|
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
QObject*
|
|
|
|
BooksSettings::currentBook() const
|
|
|
|
{
|
2016-10-17 00:48:25 +03:00
|
|
|
return iPrivate->iCurrentBook;
|
2015-06-28 14:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-12-13 14:46:53 +03:00
|
|
|
BooksSettings::setCurrentBook(
|
|
|
|
QObject* aBook)
|
2015-06-28 14:22:35 +03:00
|
|
|
{
|
2016-10-17 00:48:25 +03:00
|
|
|
iPrivate->setCurrentBook(aBook);
|
2015-06-28 14:22:35 +03:00
|
|
|
}
|
2015-08-23 14:47:25 +03:00
|
|
|
|
|
|
|
QColor
|
|
|
|
BooksSettings::primaryPageToolColor() const
|
|
|
|
{
|
|
|
|
return PAGETOOL_COLOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor
|
|
|
|
BooksSettings::highlightPageToolColor() const
|
|
|
|
{
|
|
|
|
return invertColors() ?
|
|
|
|
INVERTED_PAGETOOL_HIGHLIGHT_COLOR :
|
|
|
|
NORMAL_PAGETOOL_HIGHLIGHT_COLOR;
|
|
|
|
}
|
2016-10-07 19:40:18 +03:00
|
|
|
|
2016-10-08 23:36:28 +03:00
|
|
|
QColor
|
|
|
|
BooksSettings::pageBackgroundColor() const
|
|
|
|
{
|
|
|
|
return qtColor(invertColors() ?
|
|
|
|
BooksTextView::INVERTED_BACKGROUND :
|
|
|
|
BooksTextView::DEFAULT_BACKGROUND);
|
|
|
|
}
|
|
|
|
|
2016-10-07 19:40:18 +03:00
|
|
|
BooksSettings::Orientation
|
|
|
|
BooksSettings::orientation() const
|
|
|
|
{
|
|
|
|
// Need to cast int to enum right away to force "enumeration value not
|
|
|
|
// handled in switch" warning if we miss one of the Orientation:
|
|
|
|
Orientation value = (Orientation)
|
2016-10-17 00:48:25 +03:00
|
|
|
iPrivate->iOrientationConf->value(DEFAULT_ORIENTATION).toInt();
|
2016-10-07 19:40:18 +03:00
|
|
|
switch (value) {
|
|
|
|
case OrientationAny:
|
|
|
|
case OrientationPortrait:
|
|
|
|
case OrientationLandscape:
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return DEFAULT_ORIENTATION;
|
|
|
|
}
|
2016-10-17 00:48:25 +03:00
|
|
|
|
|
|
|
#include "BooksSettings.moc"
|