sailfish-safe

Sailfish frontend for safe(1)
git clone git://git.z3bra.org/sailfish-safe.git
Log | Files | Refs | README | LICENSE

commit 1193e8ca390e4f236b9915c33baa6aabb2e313ee
parent 28c9776bda3ca635a02edcb38fb84ff2a10a2594
Author: Daniel Vrátil <dvratil@kde.org>
Date:   Sun,  3 Feb 2019 18:15:51 +0100

Update the cover page

Diffstat:
Mharbour-passilic.pro | 6++++--
Mqml/cover/CoverPage.qml | 19+++++--------------
Aqml/images/cover.png | 0
Asrc/imageprovider.cpp | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/imageprovider.h | 38++++++++++++++++++++++++++++++++++++++
Msrc/main.cpp | 10+++++++++-
6 files changed, 136 insertions(+), 17 deletions(-)

diff --git a/harbour-passilic.pro b/harbour-passilic.pro @@ -7,6 +7,7 @@ INCLUDEPATH += 3rdparty/kitemmodels/ SOURCES += \ src/main.cpp \ src/abbreviations.cpp \ + src/imageprovider.cpp \ src/passwordfiltermodel.cpp \ src/passwordprovider.cpp \ src/passwordsmodel.cpp \ @@ -16,6 +17,7 @@ SOURCES += \ HEADERS += \ src/abbreviations.h \ + src/imageprovider.h \ src/passwordfiltermodel.h \ src/passwordprovider.h \ src/passwordsmodel.h \ @@ -26,13 +28,13 @@ DISTFILES += \ qml/harbour-passilic.qml \ qml/cover/CoverPage.qml \ qml/pages/PasswordListPage.qml \ + qml/pages/PassphraseRequester.qml \ rpm/harbour-passilic.changes.in \ rpm/harbour-passilic.changes.run.in \ rpm/harbour-passilic.spec \ rpm/harbour-passilic.yaml \ translations/*.ts \ - harbour-passilic.desktop \ - qml/pages/PassphraseRequester.qml + harbour-passilic.desktop SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172 diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml @@ -2,21 +2,12 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 CoverBackground { - Label { - id: label - anchors.centerIn: parent - text: qsTr("My Cover") - } - CoverActionList { - id: coverAction - - CoverAction { - iconSource: "image://theme/icon-cover-next" - } + Image { + source: "image://passImage/cover.png?" + Theme.primaryColor + anchors.centerIn: parent - CoverAction { - iconSource: "image://theme/icon-cover-pause" - } + width: parent.width - 2 * Theme.paddingLarge + height: sourceSize.height * width / sourceSize.width } } diff --git a/qml/images/cover.png b/qml/images/cover.png Binary files differ. diff --git a/src/imageprovider.cpp b/src/imageprovider.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2019 Daniel Vrátil <dvratil@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "imageprovider.h" + +#include <QPainter> +#include <QColor> +#include <QMap> + +#include <sailfishapp.h> + +namespace { + +static const auto schemaMap = QMap<QString, QString>{ + {{QStringLiteral("passIcon"), QStringLiteral("icons")}, + {QStringLiteral("passImage"), QStringLiteral("images")}} +}; + +static QString pathForSchema(const QString &schema) +{ + return schemaMap.value(schema); +} + +} + +ImageProvider::ImageProvider(const QString &schema) + : QQuickImageProvider(QQuickImageProvider::Pixmap) + , mSchema(schema) +{ + Q_ASSERT(schemaMap.contains(schema)); +} + +// Based on https://together.jolla.com/question/44325/iconbutton-how-to-use-own-icons-with-highlight/ +QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) +{ + const auto parts = id.splitRef(QLatin1Char('?')); + + auto source = findSource(parts.at(0)); + if (size) { + *size = source.size(); + } + + if (parts.size() > 1) { + const auto color = parts.at(1).toString(); + if (QColor::isValidColor(color)) { + QPainter painter(&source); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(source.rect(), color); + painter.end(); + } + } + + if (requestedSize.width() > 0 && requestedSize.height() > 0) { + return source.scaled(requestedSize, Qt::IgnoreAspectRatio); + } else { + return source; + } +} + +QPixmap ImageProvider::findSource(const QStringRef &name) +{ + const QString imgPath = QStringLiteral("qml/") % pathForSchema(mSchema) % QStringLiteral("/") % name; + return QPixmap(SailfishApp::pathTo(imgPath).toString(QUrl::RemoveScheme)); +} diff --git a/src/imageprovider.h b/src/imageprovider.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 Daniel Vrátil <dvratil@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef IMAGEPROVIDER_H +#define IMAGEROVIDER_H + +#include <QQuickImageProvider> + +class ImageProvider : public QQuickImageProvider +{ +public: + explicit ImageProvider(const QString &schema); + + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override; + +private: + QPixmap findSource(const QStringRef &name); + + QString mSchema; +}; + +#endif // IMAGEPROVIDER diff --git a/src/main.cpp b/src/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Daniel Vrátil <dvratil@kde.org> + * Copyright (C) 2019 Daniel Vrátil <dvratil@kde.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -20,6 +20,7 @@ #include "passwordsmodel.h" #include "passwordfiltermodel.h" #include "passwordsortproxymodel.h" +#include "imageprovider.h" #ifdef QT_QML_DEBUG #include <QtQuick> @@ -28,6 +29,11 @@ #include <sailfishapp.h> +void addImageProvider(QQmlEngine *engine, const QString &id) +{ + engine->addImageProvider(id, new ImageProvider(id)); +} + int main(int argc, char *argv[]) { QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv)); @@ -37,6 +43,8 @@ int main(int argc, char *argv[]) qmlRegisterType<PasswordFilterModel>("harbour.passilic", 1, 0, "PasswordFilterModel"); qmlRegisterType<PasswordSortProxyModel>("harbour.passilic", 1, 0, "PasswordSortProxyModel"); + addImageProvider(view->engine(), QStringLiteral("passIcon")); + addImageProvider(view->engine(), QStringLiteral("passImage")); view->setSource(SailfishApp::pathToMainQml()); view->show();