Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qrshare] Compatibility with out-of-process sharing
  • Loading branch information
monich committed Jun 17, 2021
1 parent 34580c1 commit b9e2cde
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 48 deletions.
24 changes: 11 additions & 13 deletions shareplugin/qml/QRShare.qml
Expand Up @@ -2,21 +2,18 @@ import QtQuick 2.0
import Sailfish.Silica 1.0
import com.monich.qrshare 1.0

Page {
Item {
id: page

property url source
property variant content: ({})
property string methodId
property string displayName
property int accountId
property string accountName
property var shareEndDestination
property real verticalMargins
property bool hideInactiveMenu
property alias menuWidth: menu.width

readonly property var generators: [ qrCodeGenerator, aztecCodeGenerator ]
readonly property string text: content ?
readonly property string text:
('data' in content) ? content.data :
('status' in content) ? content.status : "" : ""
('status' in content) ? content.status : ""

QrCodeGenerator {
id: qrCodeGenerator
Expand Down Expand Up @@ -56,6 +53,9 @@ Page {
id: menu

visible: view.currentItem && view.currentItem.needPullDownMenu
opacity: (active || !hideInactiveMenu) ? 1 : 0

Behavior on opacity { FadeAnimation { } }

property string savedCode

Expand All @@ -81,13 +81,11 @@ Page {
}
}

PageHeader { id: header }

SilicaListView {
id: view

anchors.centerIn: parent
height: Math.min(parent.width, parent.height - 2 * header.height)
height: Math.min(parent.width, parent.height - 2 * verticalMargins)
width: parent.width
orientation: ListView.Horizontal
snapMode: ListView.SnapOneItem
Expand Down Expand Up @@ -183,7 +181,7 @@ Page {
id: label

text: generator.textTooLong
anchors.verticalCenter: parent.verticalCenter
anchors.top: parent.verticalCenter
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions shareplugin/qml/QRShareItem.qml
@@ -0,0 +1,33 @@
import QtQuick 2.0
import Sailfish.Silica 1.0

Item {
property var shareAction

width: parent.width
height: isLandscape ? (Screen.width - Theme.itemSizeLarge - 2 * Theme.paddingLarge) : Screen.width

property Item orientationComponent
readonly property int orientation: orientationComponent ? orientationComponent.orientation : Orientation.None
readonly property bool isLandscape: (orientation === Orientation.Landscape || orientation === Orientation.LandscapeInverted)

onIsLandscapeChanged: console.log(isLandscape, height)

Component.onCompleted: {
var parentItem = parent
while (parentItem) {
if ('orientation' in parentItem) {
orientationComponent = parentItem
break
}
parentItem = parentItem.parent
}
}

QRShare {
anchors.fill: parent
content: (shareAction && 'resources' in shareAction && shareAction.resources.length > 0) ? shareAction.resources[0] : undefined
menuWidth: width - 2 * Theme.itemSizeSmall - 4 * Theme.paddingMedium
hideInactiveMenu: true
}
}
21 changes: 21 additions & 0 deletions shareplugin/qml/QRSharePage.qml
@@ -0,0 +1,21 @@
import QtQuick 2.0
import Sailfish.Silica 1.0

Page {
property url source
property alias content: qrShare.content
property string methodId
property string displayName
property int accountId
property string accountName
property var shareEndDestination

PageHeader { id: header }

QRShare {
id: qrShare

anchors.fill: parent
verticalMargins: header.height
}
}
2 changes: 1 addition & 1 deletion shareplugin/shareplugin.pro
Expand Up @@ -43,7 +43,7 @@ SOURCES += \
QRSHARE_UI_FILES = \
qrshare.svg \
qml/unhappy.svg \
qml/QRShare.qml
qml/*.qml

OTHER_FILES += $$QRSHARE_UI_FILES

Expand Down
7 changes: 4 additions & 3 deletions shareplugin/src/qrshare.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (C) 2019 Slava Monich <slava@monich.com>
* Copyright (C) 2019-2021 Jolla Ltd.
* Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -35,7 +35,8 @@
#define QRSHARE_H

#define QRSHARE_PLUGIN_ID "QRShare"
#define QRSHARE_UI_PATH QRSHARE_UI_DIR "/QRShare.qml"
#define QRSHARE_PAGE_PATH QRSHARE_UI_DIR "/QRSharePage.qml"
#define QRSHARE_ITEM_PATH QRSHARE_UI_DIR "/QRShareItem.qml"
#define QRSHARE_ICON_PNG QRSHARE_UI_DIR "/qrshare.png"
#define QRSHARE_ICON_SVG QRSHARE_UI_DIR "/qrshare.svg"

Expand Down
62 changes: 44 additions & 18 deletions shareplugin/src/qrshareplugin.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2019-2020 Jolla Ltd.
* Copyright (C) 2019-2020 Slava Monich <slava@monich.com>
* Copyright (C) 2019-2021 Jolla Ltd.
* Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -47,8 +47,37 @@
#include <rpm/rpmts.h>
#include <rpm/rpmdb.h>

static QVector<uint> getPackageVersion(rpmts aRpmTs, const char* aPackage)
{
QVector<uint> version;
rpmdbMatchIterator mi = rpmtsInitIterator(aRpmTs, RPMDBI_NAME, aPackage, 0);
if (mi) {
Header h = rpmdbNextIterator(mi);
if (h) {
const char* v = headerGetString(h, RPMTAG_VERSION);
if (v) {
qDebug() << aPackage << v;
const QStringList parts(QString(v).split('.', QString::SkipEmptyParts));
const int n = qMin(parts.count(),3);
for (int i = 0; i < n; i++) {
const QString part(parts.at(i));
bool ok = false;
int val = part.toUInt(&ok);
if (ok) {
version.append(val);
} else {
break;
}
}
}
}
rpmdbFreeIterator(mi);
}
return version;
}

QRSharePlugin::QRSharePlugin() :
iCreatePluginInfoFunc(QRShareCreatePluginInfo2)
iCreatePluginInfoFunc(QRShareCreatePluginInfo2OutOfProcess)
{
// Load translations
QTranslator* tr = new QTranslator(this);
Expand All @@ -67,26 +96,23 @@ QRSharePlugin::QRSharePlugin() :

// Figure out which version of plugin API is expected from us
if (rpmReadConfigFiles(NULL, NULL) == 0) {
const char* name = "nemo-transferengine-qt5";
rpmts ts = rpmtsCreate();
if (ts) {
rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_NAME, name, 0);
if (mi) {
Header h = rpmdbNextIterator(mi);
if (h) {
const char* v = headerGetString(h, RPMTAG_VERSION);
if (v) {
qDebug() << name << v;
// API break at 0.2.0
if (v[0] == '0' && v[1] == '.' && v[2] < '2') {
iCreatePluginInfoFunc = QRShareCreatePluginInfo1;
}
}
// Detect native transferengine plugin API break
QVector<uint> v = getPackageVersion(ts, "nemo-transferengine-qt5");
// API break at 0.2.0
if (v.count() >= 2 && v.at(0) == 0 && v.at(1) < 2) {
iCreatePluginInfoFunc = QRShareCreatePluginInfo1;
} else {
// Detect QML API break
v = getPackageVersion(ts, "declarative-transferengine-qt5");
// API break at 0.4.0
if (v.count() >= 2 && v.at(0) == 0 && v.at(1) < 4) {
iCreatePluginInfoFunc = QRShareCreatePluginInfo2InProcess;
}
rpmdbFreeIterator(mi);
}
rpmtsFree(ts);
}
rpmtsFree(ts);
} else {
// Check what's the latest librpm.so.x in /usr/lib
QDir dir("/usr/lib");
Expand Down
7 changes: 4 additions & 3 deletions shareplugin/src/qrshareplugininfo.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (C) 2019 Slava Monich <slava@monich.com>
* Copyright (C) 2019-2021 Jolla Ltd.
* Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -37,6 +37,7 @@
class TransferPluginInfo;

TransferPluginInfo* QRShareCreatePluginInfo1();
TransferPluginInfo* QRShareCreatePluginInfo2();
TransferPluginInfo* QRShareCreatePluginInfo2InProcess();
TransferPluginInfo* QRShareCreatePluginInfo2OutOfProcess();

#endif // QRSHARE_PLUGIN_INFO_H
6 changes: 3 additions & 3 deletions shareplugin/src/qrshareplugininfo1.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2019-2020 Jolla Ltd.
* Copyright (C) 2019-2020 Slava Monich <slava@monich.com>
* Copyright (C) 2019-2021 Jolla Ltd.
* Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -57,7 +57,7 @@ QRSharePluginInfo1::QRSharePluginInfo1()
//% "QR Share"
info.displayName = qtTrId("qrshare-display_name");
info.methodId = QRSHARE_PLUGIN_ID;
info.shareUIPath = QRSHARE_UI_PATH;
info.shareUIPath = QRSHARE_PAGE_PATH;
info.capabilitities.append("text/*");

iInfoList.append(info);
Expand Down
21 changes: 14 additions & 7 deletions shareplugin/src/qrshareplugininfo2.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2019-2020 Jolla Ltd.
* Copyright (C) 2019-2020 Slava Monich <slava@monich.com>
* Copyright (C) 2019-2021 Jolla Ltd.
* Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand Down Expand Up @@ -42,7 +42,7 @@

class QRSharePluginInfo2 : public TransferPluginInfo {
public:
QRSharePluginInfo2();
QRSharePluginInfo2(const char* aQmlPath);

QList<TransferMethodInfo> info() const Q_DECL_OVERRIDE;
void query() Q_DECL_OVERRIDE;
Expand All @@ -52,7 +52,7 @@ class QRSharePluginInfo2 : public TransferPluginInfo {
QList<TransferMethodInfo> iInfoList;
};

QRSharePluginInfo2::QRSharePluginInfo2()
QRSharePluginInfo2::QRSharePluginInfo2(const char* aQmlPath)
{
TransferMethodInfo info;
QFileInfo png(QRSHARE_ICON_PNG);
Expand All @@ -61,7 +61,7 @@ QRSharePluginInfo2::QRSharePluginInfo2()
//% "QR Share"
info.displayName = qtTrId("qrshare-display_name");
info.methodId = QRSHARE_PLUGIN_ID;
info.shareUIPath = QRSHARE_UI_PATH;
info.shareUIPath = aQmlPath;
info.capabilitities.append("text/*");
info.accountIcon = QUrl::fromLocalFile(png.exists() ?
png.absoluteFilePath() : QString(QRSHARE_ICON_SVG)).toString();
Expand All @@ -84,7 +84,14 @@ bool QRSharePluginInfo2::ready() const
return true;
}

TransferPluginInfo* QRShareCreatePluginInfo2()
TransferPluginInfo* QRShareCreatePluginInfo2InProcess()
{
return new QRSharePluginInfo2;
// In-process sharing
return new QRSharePluginInfo2(QRSHARE_PAGE_PATH);
}

TransferPluginInfo* QRShareCreatePluginInfo2OutOfProcess()
{
// Out-of-process sharing (Sailfish OS >= 4.2.0)
return new QRSharePluginInfo2(QRSHARE_ITEM_PATH);
}

0 comments on commit b9e2cde

Please sign in to comment.