[app] Provide haptic feedback on entering/leaving selection mode

This commit is contained in:
Slava Monich 2017-12-03 03:19:17 +02:00
parent 2aa3b9e568
commit b16f5e986b
6 changed files with 226 additions and 2 deletions

View file

@ -104,6 +104,7 @@ SOURCES += \
src/BooksCoverModel.cpp \
src/BooksCoverWidget.cpp \
src/BooksDialogManager.cpp \
src/BooksFeedback.cpp \
src/BooksHints.cpp \
src/BooksImageProvider.cpp \
src/BooksImportModel.cpp \
@ -148,6 +149,7 @@ HEADERS += \
src/BooksCoverWidget.h \
src/BooksDefs.h \
src/BooksDialogManager.h \
src/BooksFeedback.h \
src/BooksHints.h \
src/BooksImageProvider.h \
src/BooksImportModel.h \

View file

@ -1,6 +1,6 @@
/*
Copyright (C) 2015-2017 Jolla Ltd.
Contact: Slava Monich <slava.monich@jolla.com>
Copyright (C) 2015-2017 Slava Monich <slava.monich@jolla.com>
You may use this file under the terms of BSD license as follows:
@ -193,6 +193,7 @@ SilicaFlickable {
}
}
onSelectingChanged: {
globalFeedback.start("push_gesture")
if (currentPage) {
root.selecting = pageView.selecting
}

View file

@ -52,6 +52,7 @@ ApplicationWindow {
property variant currentShelf: mainPage.currentShelf
BooksHints { id: globalHints }
BooksFeedback { id: globalFeedback }
SystemState { id: globalSystemState }
initialPage: BooksMainPage { id: mainPage }

162
app/src/BooksFeedback.cpp Normal file
View file

@ -0,0 +1,162 @@
/*
* Copyright (C) 2017 Jolla Ltd.
* Copyright (C) 2017 Slava Monich <slava.monich@jolla.com>
*
* 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.
* * 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 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 <QDBusConnection>
#include <QDBusAbstractInterface>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#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<uint> 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();
}
#include "BooksFeedback.moc"

56
app/src/BooksFeedback.h Normal file
View file

@ -0,0 +1,56 @@
/*
* Copyright (C) 2017 Jolla Ltd.
* Copyright (C) 2017 Slava Monich <slava.monich@jolla.com>
*
* 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.
* * 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 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 <QtQml>
class BooksFeedback : public QObject
{
Q_OBJECT
public:
explicit BooksFeedback(QObject* aParent = NULL);
Q_INVOKABLE bool start(QString aEvent);
Q_INVOKABLE void stop();
private:
class Private;
Private* iPrivate;
};
QML_DECLARE_TYPE(BooksFeedback)
#endif // BOOKS_FEEDBACK_H

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2015-2017 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@ -46,6 +46,7 @@
#include "BooksListWatcher.h"
#include "BooksCoverWidget.h"
#include "BooksTaskQueue.h"
#include "BooksFeedback.h"
#include "BooksHints.h"
#include "HarbourDebug.h"
@ -82,6 +83,7 @@ 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(BooksFeedback, "BooksFeedback");
BOOKS_QML_REGISTER(BooksHints, "BooksHints");
BOOKS_QML_REGISTER(BooksSettings, "BooksSettings");
HarbourLib::registerTypes(BOOKS_QML_PLUGIN,