From caf858b581dfbc5bbe85bd57772b1ab63a06d8b2 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 16 Oct 2016 23:36:13 +0300 Subject: [PATCH] [app] Use shared instance of BooksSettings --- app/qml/BooksBookView.qml | 7 +++--- app/qml/BooksMain.qml | 12 +++++----- app/qml/BooksMainPage.qml | 21 +++++++++--------- app/qml/BooksPageTools.qml | 19 ++++++++-------- app/qml/BooksPageView.qml | 7 +++--- app/qml/BooksPager.qml | 17 +++++++------- app/qml/BooksShelfView.qml | 8 +++---- app/qml/BooksStorageView.qml | 17 +++++++------- app/src/BooksBookModel.cpp | 40 +++++---------------------------- app/src/BooksBookModel.h | 8 +------ app/src/BooksPageWidget.cpp | 43 ++++++------------------------------ app/src/BooksPageWidget.h | 7 +----- app/src/BooksSettings.cpp | 20 +++++++++++++++++ app/src/BooksSettings.h | 4 ++++ app/src/ZLibrary.cpp | 3 +++ 15 files changed, 97 insertions(+), 136 deletions(-) diff --git a/app/qml/BooksBookView.qml b/app/qml/BooksBookView.qml index 665763c..68c3593 100644 --- a/app/qml/BooksBookView.qml +++ b/app/qml/BooksBookView.qml @@ -44,7 +44,7 @@ SilicaFlickable { property int _currentPage: bookListWatcher.currentIndex property bool _loading: minLoadingDelay.running || bookModel.loading - property var _currentState: _visibilityStates[globalSettings.pageDetails % _visibilityStates.length] + property var _currentState: _visibilityStates[Settings.pageDetails % _visibilityStates.length] readonly property var _visibilityStates: [ { pager: false, page: false, title: false, tools: false }, { pager: false, page: true, title: true, tools: false }, @@ -77,7 +77,7 @@ SilicaFlickable { Component { id: imageViewComponent BooksImageView { - imageBackground: globalSettings.pageBackgroundColor + imageBackground: Settings.pageBackgroundColor } } @@ -114,7 +114,6 @@ SilicaFlickable { rightMargin: Theme.horizontalPageMargin topMargin: Theme.itemSizeSmall bottomMargin: Theme.itemSizeSmall - settings: globalSettings onJumpToPage: bookView.jumpTo(index) onCurrentPageChanged: { if (linkMenu) linkMenu.hide() @@ -163,7 +162,7 @@ SilicaFlickable { onJumpToPage: bookView.jumpTo(page) onPageClicked: { root.pageClicked(index) - globalSettings.pageDetails = (globalSettings.pageDetails+ 1) % _visibilityStates.length + Settings.pageDetails = (Settings.pageDetails+ 1) % _visibilityStates.length } onImagePressed: { if (_currentPage == index) { diff --git a/app/qml/BooksMain.qml b/app/qml/BooksMain.qml index 93255eb..235e6b1 100644 --- a/app/qml/BooksMain.qml +++ b/app/qml/BooksMain.qml @@ -7,14 +7,15 @@ 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. - * Neither the name of the Jolla Ltd nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. + * Neither the name of Jolla Ltd nor the names of its contributors 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 @@ -36,7 +37,7 @@ import harbour.books 1.0 ApplicationWindow { id: window allowedOrientations: { - switch (globalSettings.orientation) { + switch (Settings.orientation) { default: case BooksSettings.OrientationAny: return Orientation.All case BooksSettings.OrientationPortrait: return Orientation.Portrait @@ -50,7 +51,6 @@ ApplicationWindow { property variant currentShelf: mainPage.currentShelf - BooksSettings { id: globalSettings } BooksHints { id: globalHints } SystemState { id: globalSystemState } @@ -58,7 +58,7 @@ ApplicationWindow { cover: Component { BooksCoverPage { - book: globalSettings.currentBook + book: Settings.currentBook shelf: currentShelf } } diff --git a/app/qml/BooksMainPage.qml b/app/qml/BooksMainPage.qml index 146cd5a..18345a6 100644 --- a/app/qml/BooksMainPage.qml +++ b/app/qml/BooksMainPage.qml @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Jolla Ltd. + Copyright (C) 2015-2016 Jolla Ltd. Contact: Slava Monich You may use this file under the terms of BSD license as follows: @@ -7,14 +7,15 @@ 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. - * Neither the name of the Jolla Ltd nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. + * Neither the name of Jolla Ltd nor the names of its contributors 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 @@ -44,13 +45,13 @@ Page { property Item _bookView function createBookViewIfNeeded() { - if (globalSettings.currentBook && !_bookView) { + if (Settings.currentBook && !_bookView) { _bookView = bookViewComponent.createObject(root) } } Connections { - target: globalSettings + target: Settings onCurrentBookChanged: createBookViewIfNeeded() } @@ -60,8 +61,8 @@ Page { anchors.fill: parent opacity: book ? 1 : 0 visible: opacity > 0 - book: globalSettings.currentBook ? globalSettings.currentBook : null - onCloseBook: globalSettings.currentBook = null + book: Settings.currentBook ? Settings.currentBook : null + onCloseBook: Settings.currentBook = null Behavior on opacity { FadeAnimation {} } } } @@ -69,10 +70,10 @@ Page { BooksStorageView { id: storageView anchors.fill: parent - opacity: globalSettings.currentBook ? 0 : 1 + opacity: Settings.currentBook ? 0 : 1 visible: opacity > 0 Behavior on opacity { FadeAnimation {} } - onOpenBook: globalSettings.currentBook = book + onOpenBook: Settings.currentBook = book } Component.onCompleted: createBookViewIfNeeded() diff --git a/app/qml/BooksPageTools.qml b/app/qml/BooksPageTools.qml index e465872..0351654 100644 --- a/app/qml/BooksPageTools.qml +++ b/app/qml/BooksPageTools.qml @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Jolla Ltd. + Copyright (C) 2015-2016 Jolla Ltd. Contact: Slava Monich You may use this file under the terms of BSD license as follows: @@ -7,14 +7,15 @@ 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. - * Neither the name of the Jolla Ltd nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. + * Neither the name of Jolla Ltd nor the names of its contributors 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 @@ -57,7 +58,7 @@ Item { left: parent.left verticalCenter: parent.verticalCenter } - onClicked: globalSettings.invertColors = !globalSettings.invertColors + onClicked: Settings.invertColors = !Settings.invertColors Image { id: dayModeImage @@ -69,7 +70,7 @@ Item { } height: Math.ceil(parent.height/2) sourceSize.height: height - opacity: globalSettings.invertColors ? 0.5 : 0 + opacity: Settings.invertColors ? 0.5 : 0 visible: opacity > 0 Behavior on opacity { FadeAnimation {} } } @@ -78,7 +79,7 @@ Item { source: "images/night-mode.svg" anchors.fill: dayModeImage sourceSize.height: height - opacity: globalSettings.invertColors ? 0 : 0.25 + opacity: Settings.invertColors ? 0 : 0.25 visible: opacity > 0 Behavior on opacity { FadeAnimation {} } } @@ -104,7 +105,7 @@ Item { } height: Math.ceil(parent.height/2) sourceSize.height: height - opacity: globalSettings.invertColors ? 1 : 0.5 + opacity: Settings.invertColors ? 1 : 0.5 Behavior on opacity { FadeAnimation {} } } onClicked: pageTools.increaseFontSize() @@ -128,7 +129,7 @@ Item { } height: Math.ceil(parent.height/2) sourceSize.height: height - opacity: globalSettings.invertColors ? 1 : 0.5 + opacity: Settings.invertColors ? 1 : 0.5 Behavior on opacity { FadeAnimation {} } } onClicked: pageTools.decreaseFontSize() diff --git a/app/qml/BooksPageView.qml b/app/qml/BooksPageView.qml index a89fb39..34a1c8c 100644 --- a/app/qml/BooksPageView.qml +++ b/app/qml/BooksPageView.qml @@ -57,7 +57,6 @@ Item { PageWidget { id: widget anchors.fill: parent - settings: globalSettings model: bookModel onBrowserLinkPressed: view.browserLinkPressed(url) onImagePressed: view.imagePressed(url, rect) @@ -76,7 +75,7 @@ Item { } centerX: Math.floor(view.width/2) - anchors.leftMargin height: Theme.itemSizeExtraSmall - color: globalSettings.primaryPageToolColor + color: Settings.primaryPageToolColor opacity: titleVisible ? 1 : 0 } @@ -91,7 +90,7 @@ Item { Image { id: pressImage - source: globalSettings.invertColors ? "images/press-invert.svg" : "images/press.svg" + source: Settings.invertColors ? "images/press-invert.svg" : "images/press.svg" visible: opacity > 0 opacity: 0 readonly property int maxsize: Math.max(view.width, view.height) @@ -146,7 +145,7 @@ Item { height: Theme.itemSizeExtraSmall font.pixelSize: Theme.fontSizeSmall verticalAlignment: Text.AlignVCenter - color: globalSettings.primaryPageToolColor + color: Settings.primaryPageToolColor opacity: pageNumberVisible ? 1 : 0 visible: opacity > 0 Behavior on opacity { FadeAnimation {} } diff --git a/app/qml/BooksPager.qml b/app/qml/BooksPager.qml index b57e60c..3ea9a93 100644 --- a/app/qml/BooksPager.qml +++ b/app/qml/BooksPager.qml @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Jolla Ltd. + Copyright (C) 2015-2016 Jolla Ltd. Contact: Slava Monich You may use this file under the terms of BSD license as follows: @@ -7,14 +7,15 @@ 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. - * Neither the name of the Jolla Ltd nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. + * Neither the name of Jolla Ltd nor the names of its contributors 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 @@ -56,10 +57,10 @@ Item { minimumValue: 0 valueText: "" label: "" - primaryColor: globalSettings.primaryPageToolColor - secondaryColor: globalSettings.primaryPageToolColor - highlightColor: globalSettings.highlightPageToolColor - secondaryHighlightColor: globalSettings.highlightPageToolColor + primaryColor: Settings.primaryPageToolColor + secondaryColor: Settings.primaryPageToolColor + highlightColor: Settings.highlightPageToolColor + secondaryHighlightColor: Settings.highlightPageToolColor onValueChanged: root.pageChanged(value) } } diff --git a/app/qml/BooksShelfView.qml b/app/qml/BooksShelfView.qml index 463087a..5130514 100644 --- a/app/qml/BooksShelfView.qml +++ b/app/qml/BooksShelfView.qml @@ -74,13 +74,13 @@ Item { editMode: shelfView.editMode onRelativePathChanged: longStartTimer.restart() onPathChanged: { - if (globalSettings.currentStorage === device && _completed) { - globalSettings.currentFolder = path + if (Settings.currentStorage === device && _completed) { + Settings.currentFolder = path } } onDeviceChanged: { - if (device === globalSettings.currentStorage) { - relativePath = globalSettings.relativePath + if (device === Settings.currentStorage) { + relativePath = Settings.relativePath } } Component.onCompleted: _completed = true diff --git a/app/qml/BooksStorageView.qml b/app/qml/BooksStorageView.qml index cccc70f..df2853b 100644 --- a/app/qml/BooksStorageView.qml +++ b/app/qml/BooksStorageView.qml @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Jolla Ltd. + Copyright (C) 2015-2016 Jolla Ltd. Contact: Slava Monich You may use this file under the terms of BSD license as follows: @@ -7,14 +7,15 @@ 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. - * Neither the name of the Jolla Ltd nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. + * Neither the name of Jolla Ltd nor the names of its contributors 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 @@ -85,7 +86,7 @@ SilicaFlickable { onCurrentShelfChanged: { if (storageList.completed && currentShelf) { - globalSettings.currentFolder = currentShelf.path + Settings.currentFolder = currentShelf.path } } @@ -187,14 +188,14 @@ SilicaFlickable { } Component.onCompleted: { - var index = model.deviceIndex(globalSettings.currentStorage) + var index = model.deviceIndex(Settings.currentStorage) // positionViewAtIndex doesn't work here, update contentX directly if (index >= 0) { contentX = (width + spacing) * index } else { // Most likely, removable storage is gone - console.log(globalSettings.currentFolder, "is gone") - globalSettings.currentFolder = currentShelf ? currentShelf.path : "" + console.log(Settings.currentFolder, "is gone") + Settings.currentFolder = currentShelf ? currentShelf.path : "" } completed = true } diff --git a/app/src/BooksBookModel.cpp b/app/src/BooksBookModel.cpp index 974dba3..510874c 100644 --- a/app/src/BooksBookModel.cpp +++ b/app/src/BooksBookModel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Jolla Ltd. + * Copyright (C) 2015-2016 Jolla Ltd. * Contact: Slava Monich * * You may use this file under the terms of the BSD license as follows: @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * * Neither the name of Nemo Mobile nor the names of its contributors + * * Neither the name of Jolla Ltd nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * @@ -206,13 +206,14 @@ BooksBookModel::BooksBookModel(QObject* aParent) : iCurrentPage(-1), iProgress(0), iBook(NULL), - iSettings(NULL), iTask(NULL), iData(NULL), iData2(NULL), - iTaskQueue(BooksTaskQueue::defaultQueue()), - iTextStyle(BooksTextStyle::defaults()) + iSettings(BooksSettings::sharedInstance()), + iTaskQueue(BooksTaskQueue::defaultQueue()) { + iTextStyle = iSettings->textStyle(fontSizeAdjust()); + connect(iSettings.data(), SIGNAL(textStyleChanged()), SLOT(onTextStyleChanged())); HDEBUG("created"); #if QT_VERSION < 0x050000 setRoleNames(roleNames()); @@ -254,7 +255,6 @@ void BooksBookModel::setBook(BooksBook* aBook) iTitle = QString(); HDEBUG(""); } - updateTextStyle(); startReset(ReasonLoading, true); if (oldTitle != iTitle) { Q_EMIT titleChanged(); @@ -270,34 +270,6 @@ bool BooksBookModel::loading() const return (iTask != NULL); } -void BooksBookModel::setSettings(BooksSettings* aSettings) -{ - if (iSettings != aSettings) { - shared_ptr oldTextStyle(iTextStyle); - if (iSettings) iSettings->disconnect(this); - iSettings = aSettings; - if (iSettings) { - connect(iSettings, SIGNAL(textStyleChanged()), SLOT(onTextStyleChanged())); - } - if (updateTextStyle()) { - startReset(); - } - Q_EMIT textStyleChanged(); - Q_EMIT settingsChanged(); - } -} - -bool BooksBookModel::updateTextStyle() -{ - shared_ptr oldTextStyle(iTextStyle); - if (iSettings) { - iTextStyle = iSettings->textStyle(fontSizeAdjust()); - } else { - iTextStyle = BooksTextStyle::defaults(); - } - return !BooksTextStyle::equalLayout(oldTextStyle, iTextStyle); -} - bool BooksBookModel::increaseFontSize() { return iBook && iBook->setFontSizeAdjust(iBook->fontSizeAdjust()+1); diff --git a/app/src/BooksBookModel.h b/app/src/BooksBookModel.h index 3d53c33..42be433 100644 --- a/app/src/BooksBookModel.h +++ b/app/src/BooksBookModel.h @@ -69,7 +69,6 @@ class BooksBookModel: public QAbstractListModel, private BooksLoadingProperty Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) Q_PROPERTY(BooksBook* book READ book WRITE setBook NOTIFY bookChanged) - Q_PROPERTY(BooksSettings* settings READ settings WRITE setSettings NOTIFY settingsChanged) Q_PROPERTY(ResetReason resetReason READ resetReason NOTIFY resetReasonChanged) public: @@ -104,9 +103,6 @@ public: BooksBook* book() const { return iBook; } void setBook(BooksBook* aBook); - BooksSettings* settings() const { return iSettings; } - void setSettings(BooksSettings* aModel); - int leftMargin() const { return iMargins.iLeft; } int rightMargin() const { return iMargins.iRight; } int topMargin() const { return iMargins.iTop; } @@ -137,7 +133,6 @@ private: void updateSize(); void updateModel(int aPrevPageCount); void startReset(ResetReason aReason = ReasonUnknown, bool aFull = true); - bool updateTextStyle(); private Q_SLOTS: void onResetProgress(int aProgress); @@ -154,7 +149,6 @@ Q_SIGNALS: void pageMarksChanged(); void progressChanged(); void currentPageChanged(); - void settingsChanged(); void leftMarginChanged(); void rightMarginChanged(); void topMarginChanged(); @@ -175,10 +169,10 @@ private: BooksMargins iMargins; BooksBook* iBook; shared_ptr iBookRef; - BooksSettings* iSettings; Task* iTask; Data* iData; Data* iData2; + QSharedPointer iSettings; shared_ptr iTaskQueue; shared_ptr iTextStyle; }; diff --git a/app/src/BooksPageWidget.cpp b/app/src/BooksPageWidget.cpp index 001efdf..d5eea61 100644 --- a/app/src/BooksPageWidget.cpp +++ b/app/src/BooksPageWidget.cpp @@ -254,11 +254,11 @@ void BooksPageWidget::PressTask::performTask() BooksPageWidget::BooksPageWidget(QQuickItem* aParent) : QQuickPaintedItem(aParent), + iSettings(BooksSettings::sharedInstance()), iTaskQueue(BooksTaskQueue::defaultQueue()), iTextStyle(BooksTextStyle::defaults()), iResizeTimer(new QTimer(this)), iModel(NULL), - iSettings(NULL), iResetTask(NULL), iRenderTask(NULL), iPressTask(NULL), @@ -266,8 +266,13 @@ BooksPageWidget::BooksPageWidget(QQuickItem* aParent) : iEmpty(false), iPage(-1) { + connect(iSettings.data(), + SIGNAL(invertColorsChanged()), + SLOT(onInvertColorsChanged())); + setFillColor(qtColor(iSettings->invertColors() ? + BooksTextView::INVERTED_BACKGROUND : + BooksTextView::DEFAULT_BACKGROUND)); setFlag(ItemHasContents, true); - setFillColor(qtColor(BooksTextView::DEFAULT_BACKGROUND)); iResizeTimer->setSingleShot(true); iResizeTimer->setInterval(0); connect(iResizeTimer, SIGNAL(timeout()), SLOT(onResizeTimeout())); @@ -318,40 +323,6 @@ void BooksPageWidget::setModel(BooksBookModel* aModel) } } -void BooksPageWidget::setSettings(BooksSettings* aSettings) -{ - if (iSettings != aSettings) { - const bool colorsWereInverted = invertColors(); - shared_ptr oldTextStyle(iTextStyle); - if (iSettings) iSettings->disconnect(this); - iSettings = aSettings; - if (iSettings) { - connect(iSettings, - SIGNAL(invertColorsChanged()), - SLOT(onInvertColorsChanged())); - } else { - iTextStyle = BooksTextStyle::defaults(); - } - const bool colorsAreInverted = invertColors(); - if (colorsWereInverted != colorsAreInverted) { - setFillColor(qtColor(colorsAreInverted ? - BooksTextView::INVERTED_BACKGROUND : - BooksTextView::DEFAULT_BACKGROUND)); - } - if (!BooksTextStyle::equalLayout(oldTextStyle, iTextStyle)) { - resetView(); - } else if (colorsWereInverted != colorsAreInverted) { - if (!iData.isNull() && !iData->iView.isNull()) { - iData->iView->setInvertColors(colorsAreInverted); - scheduleRepaint(); - } else { - update(); - } - } - Q_EMIT settingsChanged(); - } -} - void BooksPageWidget::onTextStyleChanged() { HDEBUG(iPage); diff --git a/app/src/BooksPageWidget.h b/app/src/BooksPageWidget.h index 3834432..0671284 100644 --- a/app/src/BooksPageWidget.h +++ b/app/src/BooksPageWidget.h @@ -58,7 +58,6 @@ class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) Q_PROPERTY(BooksBookModel* model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(BooksSettings* settings READ settings WRITE setSettings NOTIFY settingsChanged) public: class Data; @@ -74,9 +73,6 @@ public: BooksBookModel* model() const { return iModel; } void setModel(BooksBookModel* aModel); - BooksSettings* settings() const { return iSettings; } - void setSettings(BooksSettings* aSettings); - int leftMargin() const { return iMargins.iLeft; } int rightMargin() const { return iMargins.iRight; } int topMargin() const { return iMargins.iTop; } @@ -96,7 +92,6 @@ Q_SIGNALS: void loadingChanged(); void pageChanged(); void modelChanged(); - void settingsChanged(); void leftMarginChanged(); void rightMarginChanged(); void topMarginChanged(); @@ -134,12 +129,12 @@ private: class RenderTask; class PressTask; + QSharedPointer iSettings; shared_ptr iTaskQueue; shared_ptr iTextStyle; BooksPos iPageMark; QTimer* iResizeTimer; BooksBookModel* iModel; - BooksSettings* iSettings; BooksMargins iMargins; shared_ptr iData; shared_ptr iImage; diff --git a/app/src/BooksSettings.cpp b/app/src/BooksSettings.cpp index 9f4c6e6..6cc97c3 100644 --- a/app/src/BooksSettings.cpp +++ b/app/src/BooksSettings.cpp @@ -200,6 +200,13 @@ BooksSettings::TextStyle::allowHyphenations() const // BooksSettings // ========================================================================== +class BooksSettings::Private { +public: + static QWeakPointer sSharedInstance; +}; + +QWeakPointer BooksSettings::Private::sSharedInstance; + BooksSettings::BooksSettings(QObject* aParent) : QObject(aParent), iFontSizeConf(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)), @@ -222,6 +229,19 @@ BooksSettings::BooksSettings(QObject* aParent) : connect(iOrientationConf, SIGNAL(valueChanged()), SIGNAL(orientationChanged())); } +QSharedPointer +BooksSettings::sharedInstance() +{ + QSharedPointer 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(new BooksSettings, &QObject::deleteLater); + Private::sSharedInstance = instance; + } + return instance; +} + bool BooksSettings::increaseFontSize() { diff --git a/app/src/BooksSettings.h b/app/src/BooksSettings.h index bbdfbf5..529a2d5 100644 --- a/app/src/BooksSettings.h +++ b/app/src/BooksSettings.h @@ -38,6 +38,7 @@ #include "ZLTextStyle.h" #include #include +#include class MGConfItem; @@ -75,6 +76,8 @@ public: explicit BooksSettings(QObject* aParent = NULL); + static QSharedPointer sharedInstance(); + Q_INVOKABLE bool increaseFontSize(); Q_INVOKABLE bool decreaseFontSize(); @@ -128,6 +131,7 @@ private: int fontSize(int aFontSizeAdjust) const; private: + class Private; MGConfItem* iFontSizeConf; MGConfItem* iPageDetailsConf; MGConfItem* iInvertColorsConf; diff --git a/app/src/ZLibrary.cpp b/app/src/ZLibrary.cpp index 62e5d94..1dcbf30 100644 --- a/app/src/ZLibrary.cpp +++ b/app/src/ZLibrary.cpp @@ -36,6 +36,7 @@ #include "BooksPaintContext.h" #include "BooksDialogManager.h" #include "BooksImageProvider.h" +#include "BooksSettings.h" #include "HarbourDebug.h" @@ -192,12 +193,14 @@ void ZLibrary::run(ZLApplication* aApp) QQuickView* view = SailfishApp::createView(); QQmlContext* root = view->rootContext(); + QSharedPointer settings = BooksSettings::sharedInstance(); root->engine()->addImageProvider(BooksImageProvider::PROVIDER_ID, new BooksImageProvider(root)); root->setContextProperty("PointsPerInch", booksPPI); root->setContextProperty("MaximumHintCount", 1); root->setContextProperty("BooksSettingsMenu", QVariant::fromValue(BOOKS_SETTINGS_MENU)); + root->setContextProperty("Settings", settings.data()); view->setTitle(qtTrId("harbour-books-app-name")); view->setSource(QUrl::fromLocalFile(qml));