From d2bc2d10cd5de2b638eed0eefb9ec44873012ce8 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Mon, 3 Feb 2020 04:33:57 +0200 Subject: [PATCH] [app] Made BooksHints a singleton --- app/qml/BooksMain.qml | 1 - app/qml/BooksShelfView.qml | 10 +++++----- app/src/BooksHints.cpp | 28 +++++++++++++++++----------- app/src/BooksHints.h | 25 ++++++++++++++----------- app/src/main.cpp | 2 +- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/qml/BooksMain.qml b/app/qml/BooksMain.qml index 6afdf12..fd25f67 100644 --- a/app/qml/BooksMain.qml +++ b/app/qml/BooksMain.qml @@ -52,7 +52,6 @@ ApplicationWindow { property variant currentShelf: mainPage.currentShelf - BooksHints { id: globalHints } DisplayBlanking { pauseRequested: Qt.application.active && Settings.currentBook && diff --git a/app/qml/BooksShelfView.qml b/app/qml/BooksShelfView.qml index 706f62b..16e4846 100644 --- a/app/qml/BooksShelfView.qml +++ b/app/qml/BooksShelfView.qml @@ -1,6 +1,6 @@ /* - Copyright (C) 2015-2019 Jolla Ltd. - Copyright (C) 2015-2019 Slava Monich + Copyright (C) 2015-2020 Jolla Ltd. + Copyright (C) 2015-2020 Slava Monich You may use this file under the terms of BSD license as follows: @@ -313,7 +313,7 @@ Item { Loader { id: leftSwipeHintLoader anchors.fill: parent - active: globalHints.storageLeftSwipe < MaximumHintCount || running + active: BooksHints.storageLeftSwipe < MaximumHintCount || running property bool running sourceComponent: Component { HarbourHorizontalSwipeHint { @@ -321,12 +321,12 @@ Item { storageView.visible && shelfIndex == storageListWatcher.currentIndex && (shelfIndex+1) < storageModel.count && - globalHints.storageLeftSwipe < MaximumHintCount + BooksHints.storageLeftSwipe < MaximumHintCount //% "Swipe left to see what's on the SD-card" text: qsTrId("harbour-books-storage-view-swipe_left_hint") swipeRight: false - onHintShown: globalHints.storageLeftSwipe++ + onHintShown: BooksHints.storageLeftSwipe++ onHintRunningChanged: leftSwipeHintLoader.running = hintRunning } } diff --git a/app/src/BooksHints.cpp b/app/src/BooksHints.cpp index 34f0eb6..2d4ac1f 100644 --- a/app/src/BooksHints.cpp +++ b/app/src/BooksHints.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2015-2020 Jolla Ltd. + * Copyright (C) 2015-2020 Slava Monich * * You may use this file under the terms of the BSD license as follows: * @@ -8,15 +8,15 @@ * 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 Nemo Mobile nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the names of the copyright holders 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 @@ -61,3 +61,9 @@ BooksHints::setStorageLeftSwipe( HDEBUG(aValue); iStorageLeftSwipe->set(aValue); } + +// Callback for qmlRegisterSingletonType +QObject* BooksHints::createSingleton(QQmlEngine*, QJSEngine*) +{ + return new BooksHints; +} diff --git a/app/src/BooksHints.h b/app/src/BooksHints.h index 9e8657c..955f5ad 100644 --- a/app/src/BooksHints.h +++ b/app/src/BooksHints.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2015-2020 Jolla Ltd. + * Copyright (C) 2015-2020 Slava Monich * * You may use this file under the terms of the BSD license as follows: * @@ -8,15 +8,15 @@ * 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 Nemo Mobile nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the names of the copyright holders 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 @@ -50,6 +50,9 @@ public: int storageLeftSwipe() const; void setStorageLeftSwipe(int aValue); + // Callback for qmlRegisterSingletonType + static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript); + signals: void storageLeftSwipeChanged(); diff --git a/app/src/main.cpp b/app/src/main.cpp index b466589..1e7edf4 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -83,9 +83,9 @@ Q_DECL_EXPORT int main(int argc, char **argv) BOOKS_QML_REGISTER(BooksPageWidget, "PageWidget"); BOOKS_QML_REGISTER(BooksListWatcher, "ListWatcher"); BOOKS_QML_REGISTER(BooksCoverWidget, "BookCover"); - BOOKS_QML_REGISTER(BooksHints, "BooksHints"); BOOKS_QML_REGISTER(BooksSettings, "BooksSettings"); BOOKS_QML_REGISTER(HarbourDisplayBlanking, "DisplayBlanking"); + BOOKS_QML_REGISTER_SINGLETON(BooksHints, "BooksHints"); BOOKS_QML_REGISTER_SINGLETON(BooksFeedback, "BooksFeedback"); QLocale locale;