Skip to content

Commit

Permalink
[foilnotes] Share notes via NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Nov 22, 2021
1 parent 8ed974c commit 174a4fb
Show file tree
Hide file tree
Showing 27 changed files with 2,366 additions and 62 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
[submodule "foil-ui"]
path = foil-ui
url = https://github.com/monich/foil-ui.git
[submodule "libgnfcdc"]
path = libgnfcdc
url = https://github.com/monich/libgnfcdc.git
[submodule "libqnfcdc"]
path = libqnfcdc
url = https://github.com/monich/libqnfcdc.git
121 changes: 116 additions & 5 deletions app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ openrepos {

TARGET = $${PREFIX}-$${NAME}
CONFIG += sailfishapp link_pkgconfig
PKGCONFIG += sailfishapp mlite5 glib-2.0 gobject-2.0
PKGCONFIG += sailfishapp mlite5 glib-2.0 gobject-2.0 gio-unix-2.0
QT += qml quick sql

isEmpty(VERSION) {
VERSION = 1.0.27
}

V1 = $$system(echo $$VERSION | cut -f1 -d.)
V2 = $$system(echo $$VERSION | cut -f2 -d.)
V3 = $$system(echo $$VERSION | cut -f3 -d.)
DEFINES += VERSION_MAJOR=$$V1 VERSION_MINOR=$$V2 VERSION_MICRO=$$V3

QMAKE_CXXFLAGS += -Wno-unused-parameter
QMAKE_CFLAGS += -Wno-unused-parameter

Expand Down Expand Up @@ -43,7 +52,8 @@ HARBOUR_LIB_SRC = $${HARBOUR_LIB_DIR}/src
HARBOUR_LIB_QML = $${HARBOUR_LIB_DIR}/qml

LIBGLIBUTIL_DIR = $${_PRO_FILE_PWD_}/libglibutil
LIBGLIBUTIL_INCLUDE = $${LIBGLIBUTIL_DIR}/include
LIBGNFCDC_DIR = $${_PRO_FILE_PWD_}/libgnfcdc
LIBQNFCDC_DIR = $${_PRO_FILE_PWD_}/libqnfcdc

FOIL_DIR = $${_PRO_FILE_PWD_}/foil
LIBFOIL_DIR = $${FOIL_DIR}/libfoil
Expand Down Expand Up @@ -72,7 +82,6 @@ INCLUDEPATH += \
$${LIBFOIL_SRC} \
$${LIBFOIL_INCLUDE} \
$${LIBFOILMSG_INCLUDE} \
$${LIBGLIBUTIL_INCLUDE} \
$${LIBQRENCODE_DIR}

HEADERS += \
Expand All @@ -81,6 +90,10 @@ HEADERS += \
src/FoilNotesDefs.h \
src/FoilNotesHints.h \
src/FoilNotesModel.h \
src/FoilNotesNfcShare.h \
src/FoilNotesNfcShareClient.h \
src/FoilNotesNfcShareService.h \
src/FoilNotesNfcShareProtocol.h \
src/FoilNotesPlaintextModel.h \
src/FoilNotesSearchModel.h \
src/FoilNotesSettings.h
Expand All @@ -90,6 +103,9 @@ SOURCES += \
src/FoilNotesBaseModel.cpp \
src/FoilNotesHints.cpp \
src/FoilNotesModel.cpp \
src/FoilNotesNfcShareClient.cpp \
src/FoilNotesNfcShareService.cpp \
src/FoilNotesNfcShareProtocol.cpp \
src/FoilNotesPlaintextModel.cpp \
src/FoilNotesSearchModel.cpp \
src/FoilNotesSettings.cpp \
Expand All @@ -98,14 +114,109 @@ SOURCES += \
SOURCES += \
$${LIBFOIL_SRC}/*.c \
$${LIBFOIL_SRC}/openssl/*.c \
$${LIBFOILMSG_SRC}/*.c \
$${LIBGLIBUTIL_DIR}/src/*.c
$${LIBFOILMSG_SRC}/*.c

HEADERS += \
$${LIBFOIL_INCLUDE}/*.h \
$${LIBFOILMSG_INCLUDE}/*.h \

# NFC stuff

# libqnfcdc

LIBQNFCDC_INCLUDE = $${LIBQNFCDC_DIR}/include
LIBQNFCDC_SRC = $${LIBQNFCDC_DIR}/src

INCLUDEPATH += \
$${LIBQNFCDC_INCLUDE}

HEADERS += \
$${LIBQNFCDC_INCLUDE}/NfcAdapter.h \
$${LIBQNFCDC_INCLUDE}/NfcMode.h \
$${LIBQNFCDC_INCLUDE}/NfcSystem.h \
$${LIBQNFCDC_INCLUDE}/NfcPeer.h

SOURCES += \
$${LIBQNFCDC_SRC}/NfcAdapter.cpp \
$${LIBQNFCDC_SRC}/NfcMode.cpp \
$${LIBQNFCDC_SRC}/NfcSystem.cpp \
$${LIBQNFCDC_SRC}/NfcPeer.cpp

# libglibutil

LIBGLIBUTIL_SRC = $${LIBGLIBUTIL_DIR}/src
LIBGLIBUTIL_INCLUDE = $${LIBGLIBUTIL_DIR}/include

INCLUDEPATH += \
$${LIBGLIBUTIL_INCLUDE}

HEADERS += \
$${LIBGLIBUTIL_INCLUDE}/*.h

SOURCES += \
$${LIBGLIBUTIL_DIR}/src/*.c

# libgnfcdc

LIBGNFCDC_INCLUDE = $${LIBGNFCDC_DIR}/include
LIBGNFCDC_SRC = $${LIBGNFCDC_DIR}/src
LIBGNFCDC_SPEC = $${LIBGNFCDC_DIR}/spec

INCLUDEPATH += \
$${LIBGNFCDC_INCLUDE}

HEADERS += \
$${LIBGNFCDC_INCLUDE}/*.h \
$${LIBGNFCDC_SRC}/*.h

SOURCES += \
$${LIBGNFCDC_SRC}/*.c

OTHER_FILES += \
$${LIBGNFCDC_SPEC}/*.xml

defineTest(generateStub) {
xml = $${LIBGNFCDC_SPEC}/org.sailfishos.nfc.$${1}.xml
cmd = gdbus-codegen --generate-c-code org.sailfishos.nfc.$${1} $${xml}

gen_h = org.sailfishos.nfc.$${1}.h
gen_c = org.sailfishos.nfc.$${1}.c
target_h = org_sailfishos_nfc_$${1}_h
target_c = org_sailfishos_nfc_$${1}_c

$${target_h}.target = $${gen_h}
$${target_h}.depends = $${xml}
$${target_h}.commands = $${cmd}
export($${target_h}.target)
export($${target_h}.depends)
export($${target_h}.commands)

GENERATED_HEADERS += $${gen_h}
PRE_TARGETDEPS += $${gen_h}
QMAKE_EXTRA_TARGETS += $${target_h}

$${target_c}.target = $${gen_c}
$${target_c}.depends = $${gen_h}
export($${target_c}.target)
export($${target_c}.depends)

GENERATED_SOURCES += $${gen_c}
QMAKE_EXTRA_TARGETS += $${target_c}
PRE_TARGETDEPS += $${gen_c}

export(QMAKE_EXTRA_TARGETS)
export(GENERATED_SOURCES)
export(PRE_TARGETDEPS)
}

generateStub(Adapter)
generateStub(Daemon)
generateStub(IsoDep)
generateStub(LocalService)
generateStub(Settings)
generateStub(Peer)
generateStub(Tag)

# foil-ui

FOIL_UI_COMPONENTS = \
Expand Down
1 change: 1 addition & 0 deletions libgnfcdc
Submodule libgnfcdc added at 138764
1 change: 1 addition & 0 deletions libqnfcdc
Submodule libqnfcdc added at 5e84f7
139 changes: 139 additions & 0 deletions qml/NfcSharePage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import harbour.foilnotes 1.0

import "harbour"

Dialog {
id: thisPage

acceptDestinationAction: PageStackAction.Pop
forwardNavigation: false

property color noteColor
property string noteText

Component.onCompleted: {
shareClient.sharePlaintext(noteColor, noteText)
}

NfcMode {
enableModes: NfcSystem.P2PTarget + NfcSystem.P2PInitiator
disableModes: NfcSystem.ReaderWriter
active: Qt.application.active && thisPage.status === PageStatus.Active
}

NfcPeer {
id: peer
path: NfcAdapter.peerPath
}

FoilNotesNfcShareClient {
id: shareClient
onDone: {
backNavigation = false
forwardNavigation = true
accept()
}
}

Item {
id: iconArea

anchors {
top: parent.top
bottom: parent.bottom
bottomMargin: isLandscape ? 0 : Math.round(2 * thisPage.height / 3)
left: parent.left
right: parent.right
rightMargin: isLandscape ? Math.round(2 * thisPage.width / 3) : 0
}

HarbourHighlightIcon {
anchors.centerIn: parent
sourceSize.height: Theme.itemSizeHuge
highlightColor: !NfcSystem.enabled ? Theme.secondaryColor :
peer.present ? Theme.highlightColor :
Theme.primaryColor
scale: peer.present ? 1.2 : 1
source: "images/nfc.svg"

Behavior on scale {
SpringAnimation {
spring: 5
mass: 0.5
damping: 0.1
duration: 200
}
}
}
}

Item {
id: contentArea

anchors {
bottom: parent.bottom
right: parent.right
}

InfoLabel {
id: infoLabel

// Something like ViewPlaceholder but without a pulley hint
visible: opacity > 0
verticalAlignment: Text.AlignVCenter
anchors {
top: parent.top
bottom: parent.bottom
}
// NOTE: if NFC is completely unavailable we should
// never get here in the first place
text:(!NfcSystem.enabled || !NfcSystem.present) ?
//: Full screen info label
//% "NFC is off"
qsTrId("foilnotes-nfc_share-info-nfc_off") :
shareClient.state === FoilNotesNfcShareClient.Idle ?
//: Full screen info label
//% "Touch another NFC capable device with Foil Notes running full screen."
qsTrId("foilnotes-nfc_share-info-ready") :
""
Behavior on opacity { FadeAnimation { duration: 150 } }
}

BusyIndicator {
anchors.centerIn: parent
size: BusyIndicatorSize.Large
running: infoLabel.text === ""
}
}

states: [
State {
name: "portrait"
when: !isLandscape
changes: [
AnchorChanges {
target: contentArea
anchors {
left: thisPage.left
top: iconArea.bottom
}
}
]
},
State {
name: "landscape"
when: isLandscape
changes: [
AnchorChanges {
target: contentArea
anchors {
left: iconArea.right
top: thisPage.top
}
}
]
}
]
}
19 changes: 19 additions & 0 deletions qml/NotePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ Page {
onClicked: page.performAction()
}
MenuItem {
id: nfcShareMenuItem

//: Share current note via NFC
//% "Share via NFC"
text: qsTrId("foilnotes-menu-nfc_share")
visible: NfcSystem.present && NfcSystem.enabled
onClicked: {
pageStack.push(Qt.resolvedUrl("NfcSharePage.qml"), {
allowedOrientations: page.allowedOrientations,
noteColor: page.color,
noteText: page.body
})
}
}
MenuItem {
id: qrCodeMenuItem

//: Show QR code for the current note
//% "Show QR code"
text: qsTrId("foilnotes-menu-show_qrcode")
Expand All @@ -126,6 +143,8 @@ Page {
//% "Select color"
text: qsTrId("foilnotes-menu-select_color")
onClicked: page.pickColor()
// Don't show more than 4 menu items in landscape
visible: isPortrait || !actionMenuItem.visible || !nfcShareMenuItem.visible || !qrCodeMenuItem.visible
}
MenuItem {
//: Delete this note from note page
Expand Down
Loading

0 comments on commit 174a4fb

Please sign in to comment.