diff --git a/app/app.pro b/app/app.pro index 505a7c8..8dea0ac 100644 --- a/app/app.pro +++ b/app/app.pro @@ -109,7 +109,6 @@ SOURCES += \ src/BooksCoverModel.cpp \ src/BooksCoverWidget.cpp \ src/BooksDialogManager.cpp \ - src/BooksFeedback.cpp \ src/BooksHints.cpp \ src/BooksImageProvider.cpp \ src/BooksImportModel.cpp \ @@ -153,7 +152,6 @@ HEADERS += \ src/BooksCoverWidget.h \ src/BooksDefs.h \ src/BooksDialogManager.h \ - src/BooksFeedback.h \ src/BooksHints.h \ src/BooksImageProvider.h \ src/BooksImportModel.h \ diff --git a/app/qml/BooksBookView.qml b/app/qml/BooksBookView.qml index 6e97e3e..71fc337 100644 --- a/app/qml/BooksBookView.qml +++ b/app/qml/BooksBookView.qml @@ -32,6 +32,7 @@ */ import QtQuick 2.0 +import QtFeedback 5.0 import Sailfish.Silica 1.0 import org.nemomobile.notifications 1.0 import harbour.books 1.0 @@ -45,7 +46,8 @@ SilicaFlickable { id: root property variant book - property bool selecting + readonly property bool selecting: bookView.currentItem && bookView.currentItem.selecting + readonly property bool selectionEmpty: !bookView.currentItem || bookView.currentItem.selectionEmpty signal closeBook() signal pageClicked(var page) @@ -71,6 +73,7 @@ SilicaFlickable { readonly property bool haveVolumeDownAction: Settings.volumeDownAction !== BooksSettings.ActionNone readonly property bool haveKeyAction: haveVolumeUpAction || haveVolumeDownAction + property var hapticFeedback property var linkMenu property var imageView property var footnoteView @@ -89,6 +92,17 @@ SilicaFlickable { onBookChanged: if (!book) pager.currentPage = 0 + onSelectingChanged: { + if (selecting) { + if (!hapticFeedback) { + hapticFeedback = hapticFeedbackComponent.createObject(root) + } + hapticFeedback.play() + } else if (!selectionEmpty) { + notification.publish() + } + } + Component { id: linkMenuComponent BooksLinkMenu { } @@ -104,6 +118,11 @@ SilicaFlickable { BooksFootnoteView { } } + Component { + id: hapticFeedbackComponent + ThemeEffect { effect: ThemeEffect.Press } + } + PullDownMenu { MenuItem { //% "Back to library" @@ -143,6 +162,7 @@ SilicaFlickable { flickDeceleration: maximumFlickVelocity orientation: ListView.Horizontal snapMode: ListView.SnapOneItem + highlightRangeMode: ListView.StrictlyEnforceRange spacing: Theme.paddingMedium opacity: loading ? 0 : 1 visible: opacity > 0 @@ -199,25 +219,10 @@ SilicaFlickable { rightSpaceReserved: pageTools.visible ? pageTools.rightSpaceUsed: 0 titleVisible: _currentState.title pageNumberVisible: _currentState.page - currentPage: bookViewWatcher.currentIndex == index + currentPage: bookViewWatcher.currentIndex === index title: bookModel.title onJumpToPage: bookView.jumpTo(page) onPushPosition: stackModel.pushPosition(position) // bookView.jumpTo(page) - onCurrentPageChanged: { - if (currentPage) { - root.selecting = pageView.selecting - } - } - onSelectingChanged: { - if (currentPage) { - if (pageView.selecting) { - BooksFeedback.start("push_gesture") - } else { - notification.publish() - } - root.selecting = pageView.selecting - } - } onPageClicked: { root.pageClicked(index) if (Settings.turnPageByTap && mouseY > bookModel.topMargin && mouseY < (pageView.height - bookModel.topMargin)) { @@ -235,28 +240,22 @@ SilicaFlickable { } } onImagePressed: { - if (currentPage) { - if (!imageView) { - imageView = imageViewComponent.createObject(root) - } - imageView.show(url,rect) + if (!imageView) { + imageView = imageViewComponent.createObject(root) } + imageView.show(url,rect) } onBrowserLinkPressed: { - if (currentPage) { - if (!linkMenu) { - linkMenu = linkMenuComponent.createObject(root) - } - linkMenu.show(url) + if (!linkMenu) { + linkMenu = linkMenuComponent.createObject(root) } + linkMenu.show(url) } onFootnotePressed: { - if (bookViewWatcher.currentIndex == index) { - if (!footnoteView) { - footnoteView = footnoteViewComponent.createObject(root) - } - footnoteView.show(touchX,touchY,text,url) + if (!footnoteView) { + footnoteView = footnoteViewComponent.createObject(root) } + footnoteView.show(touchX,touchY,text,url) } } diff --git a/app/qml/BooksPageView.qml b/app/qml/BooksPageView.qml index d674eb8..2e3f391 100644 --- a/app/qml/BooksPageView.qml +++ b/app/qml/BooksPageView.qml @@ -1,6 +1,6 @@ /* - Copyright (C) 2015-2018 Jolla Ltd. - Copyright (C) 2015-2018 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: @@ -8,14 +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 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. + 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 LIMITED TO, THE @@ -44,6 +45,7 @@ Item { property alias topMargin: widget.topMargin property alias bottomMargin: widget.bottomMargin property alias selecting: widget.selecting + property alias selectionEmpty: widget.selectionEmpty property alias currentPage: widget.currentPage property alias title: titleLabel.text property real leftSpaceReserved diff --git a/app/src/BooksFeedback.cpp b/app/src/BooksFeedback.cpp deleted file mode 100644 index fed19d5..0000000 --- a/app/src/BooksFeedback.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2017-2020 Jolla Ltd. - * Copyright (C) 2017-2020 Slava Monich - * - * 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: - * - * 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 - * 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 "BooksFeedback.h" -#include "HarbourDebug.h" - -#include -#include -#include -#include - -#define NGFD_CONNECTION QDBusConnection::systemBus() -#define NGFD_SERVICE "com.nokia.NonGraphicFeedback1.Backend" -#define NGFD_PATH "/com/nokia/NonGraphicFeedback1" -#define NGFD_INTERFACE "com.nokia.NonGraphicFeedback1" - -#define NGFD_STATUS_FAILED (0) -#define NGFD_STATUS_COMPLETED (1) -#define NGFD_STATUS_PLAYING (2) -#define NGFD_STATUS_PAUSED (3) - -class BooksFeedback::Private : QDBusAbstractInterface { - Q_OBJECT - -public: - Private(QObject* aParent); - - bool start(QString aEvent); - void stop(); - void stop(uint aEventId); - -public Q_SLOTS: - void onPlayFinished(QDBusPendingCallWatcher* aCall); - void onStatusChanged(uint aId, uint aStatus); - -Q_SIGNALS: - void Status(uint aId, uint aStatus); - -public: - uint iEventId; - bool iPlaying; -}; - -BooksFeedback::Private::Private(QObject* aParent) : - QDBusAbstractInterface(NGFD_SERVICE,NGFD_PATH, NGFD_INTERFACE, - NGFD_CONNECTION, aParent), iEventId(0), iPlaying(false) -{ - connect(this, SIGNAL(Status(uint,uint)), SLOT(onStatusChanged(uint,uint))); -} - -bool BooksFeedback::Private::start(QString aEvent) -{ - if (!iPlaying) { - iPlaying = true; - HDEBUG(aEvent); - connect(new QDBusPendingCallWatcher(asyncCall(QString("Play"), - aEvent, QVariantMap()), this), - SIGNAL(finished(QDBusPendingCallWatcher*)), - SLOT(onPlayFinished(QDBusPendingCallWatcher*))); - return true; - } - return false; -} - -void BooksFeedback::Private::stop(uint aEventId) -{ - HDEBUG(aEventId); - asyncCall(QString("Stop"), iPlaying); -} - -void BooksFeedback::Private::stop() -{ - if (iPlaying) { - iPlaying = false; - if (iEventId) { - stop(iEventId); - iEventId = 0; - } - } -} - -void BooksFeedback::Private::onPlayFinished(QDBusPendingCallWatcher* aCall) -{ - QDBusPendingReply reply = *aCall; - if (reply.isError()) { - HWARN(reply.error()); - iPlaying = false; - } else { - uint eventId= reply.value(); - HDEBUG(eventId); - if (iPlaying) { - iEventId = eventId; - } else { - stop(eventId); - } - } - aCall->deleteLater(); -} - -void BooksFeedback::Private::onStatusChanged(uint aId, uint aStatus) -{ - HDEBUG(aId << aStatus); - switch (aStatus) { - case NGFD_STATUS_PLAYING: - case NGFD_STATUS_PAUSED: - break; - default: - if (aId == iEventId) { - iEventId = 0; - iPlaying = false; - } - break; - } -} - -BooksFeedback::BooksFeedback(QObject* aParent) : - QObject(aParent), - iPrivate(new Private(this)) -{ -} - -bool BooksFeedback::start(QString aEvent) -{ - return iPrivate->start(aEvent); -} - -void BooksFeedback::stop() -{ - iPrivate->stop(); -} - -// Callback for qmlRegisterSingletonType -QObject* BooksFeedback::createSingleton(QQmlEngine*, QJSEngine*) -{ - return new BooksFeedback; -} - -#include "BooksFeedback.moc" diff --git a/app/src/BooksFeedback.h b/app/src/BooksFeedback.h deleted file mode 100644 index 2666dcb..0000000 --- a/app/src/BooksFeedback.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2017-2020 Jolla Ltd. - * Copyright (C) 2017-2020 Slava Monich - * - * 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: - * - * 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 - * 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. - */ - -#ifndef BOOKS_FEEDBACK_H -#define BOOKS_FEEDBACK_H - -#include - -class BooksFeedback : public QObject -{ - Q_OBJECT - -public: - explicit BooksFeedback(QObject* aParent = NULL); - - Q_INVOKABLE bool start(QString aEvent); - Q_INVOKABLE void stop(); - - // Callback for qmlRegisterSingletonType - static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript); - -private: - class Private; - Private* iPrivate; -}; - -QML_DECLARE_TYPE(BooksFeedback) - -#endif // BOOKS_FEEDBACK_H diff --git a/app/src/main.cpp b/app/src/main.cpp index b1fad44..f9b876e 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -46,7 +46,6 @@ #include "BooksListWatcher.h" #include "BooksCoverWidget.h" #include "BooksTaskQueue.h" -#include "BooksFeedback.h" #include "BooksHints.h" #include "HarbourDisplayBlanking.h" @@ -88,7 +87,6 @@ Q_DECL_EXPORT int main(int argc, char **argv) BOOKS_QML_REGISTER(HarbourDisplayBlanking, "DisplayBlanking"); BOOKS_QML_REGISTER_SINGLETON(HarbourTheme, "HarbourTheme"); BOOKS_QML_REGISTER_SINGLETON(BooksHints, "BooksHints"); - BOOKS_QML_REGISTER_SINGLETON(BooksFeedback, "BooksFeedback"); QLocale locale; QTranslator* translator = new QTranslator(app);