Commit fbf84eb7 authored by Volker Krause's avatar Volker Krause
Browse files

Rename KPkPass::File to Pass

That matches better how Apple calls things.
parent 3f86afef
......@@ -15,7 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <file.h>
#include <pass.h>
#include <boardingpass.h>
#include <QLocale>
......@@ -32,7 +32,7 @@ private slots:
void testBoardingPass()
{
std::unique_ptr<KPkPass::File> file(KPkPass::File::fromFile(QLatin1String(SOURCE_DIR "/data/boardingpass.pkpass")));
std::unique_ptr<KPkPass::Pass> file(KPkPass::Pass::fromFile(QLatin1String(SOURCE_DIR "/data/boardingpass.pkpass")));
QVERIFY(file);
QCOMPARE(file->logoText(), QLatin1String("Boarding Pass"));
......
......@@ -18,7 +18,7 @@
#include "pkpassimageprovider.h"
#include "pkpassmanager.h"
#include <KPkPass/File>
#include <KPkPass/Pass>
#include <QDebug>
#include <QGuiApplication>
......
......@@ -18,7 +18,7 @@
#include "pkpassmanager.h"
#include "logging.h"
#include <KPkPass/File>
#include <KPkPass/Pass>
#include <QDebug>
#include <QDir>
......@@ -51,14 +51,14 @@ QVector<QString> PkPassManager::passes() const
return passIds;
}
KPkPass::File* PkPassManager::pass(const QString& passId)
KPkPass::Pass* PkPassManager::pass(const QString& passId)
{
const auto it = m_passes.constFind(passId);
if (it != m_passes.constEnd())
return it.value();
const auto basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/passes/");
auto file = KPkPass::File::fromFile(basePath + passId + QLatin1String(".pkpass"), this);
auto file = KPkPass::Pass::fromFile(basePath + passId + QLatin1String(".pkpass"), this);
// TODO error handling
m_passes.insert(passId, file);
return file;
......@@ -83,7 +83,7 @@ void PkPassManager::doImportPass(const QUrl& url, PkPassManager::ImportMode mode
const auto basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/passes");
QDir::root().mkpath(basePath);
std::unique_ptr<KPkPass::File> file(KPkPass::File::fromFile(url.toLocalFile()));
std::unique_ptr<KPkPass::Pass> file(KPkPass::Pass::fromFile(url.toLocalFile()));
if (!file)
return; // TODO error handling
if (file->passTypeIdentifier().isEmpty() || file->serialNumber().isEmpty())
......
......@@ -22,7 +22,7 @@
#include <QObject>
namespace KPkPass {
class File;
class Pass;
}
class PkPassManager : public QObject
......@@ -34,7 +34,7 @@ public:
QVector<QString> passes() const;
KPkPass::File* pass(const QString &passId);
KPkPass::Pass* pass(const QString &passId);
Q_INVOKABLE void importPass(const QUrl &url);
void importPassFromTempFile(const QString &tmpFile);
......@@ -47,7 +47,7 @@ private:
enum ImportMode { Copy, Move };
void doImportPass(const QUrl &url, ImportMode mode);
QHash<QString, KPkPass::File*> m_passes;
QHash<QString, KPkPass::Pass*> m_passes;
};
#endif // PKPASSMANAGER_H
......@@ -18,7 +18,7 @@
#include "timelinemodel.h"
#include "pkpassmanager.h"
#include <KPkPass/File>
#include <KPkPass/Pass>
#include <QDebug>
#include <QLocale>
......
......@@ -4,7 +4,7 @@ set(pkpass_srcs
barcode.cpp
boardingpass.cpp
field.cpp
file.cpp
pass.cpp
)
ecm_qt_declare_logging_category(pkpass_srcs
HEADER logging.h
......@@ -31,7 +31,7 @@ ecm_generate_headers(KPkPass_HEADERS
Barcode
BoardingPass
Field
File
Pass
PREFIX KPkPass
REQUIRED_HEADERS KPkPass_HEADERS
)
......
......@@ -16,7 +16,7 @@
*/
#include "barcode.h"
#include "file.h"
#include "pass.h"
#include <QJsonObject>
......@@ -26,9 +26,9 @@ Barcode::Barcode()
{
}
Barcode::Barcode(const QJsonObject &obj, const File *file)
Barcode::Barcode(const QJsonObject &obj, const Pass *pass)
{
m_altText = file->message(obj.value(QLatin1String("altText")).toString());
m_altText = pass->message(obj.value(QLatin1String("altText")).toString());
const auto format = obj.value(QLatin1String("format")).toString();
if (format == QLatin1String("PKBarcodeFormatQR"))
m_format = QR;
......
......@@ -27,7 +27,7 @@ class QJsonObject;
namespace KPkPass {
class File;
class Pass;
/** A pass barcode element. */
class KPKPASS_EXPORT Barcode
......@@ -57,8 +57,8 @@ public:
QString message() const;
private:
friend class File;
explicit Barcode(const QJsonObject &obj, const File *file);
friend class Pass;
explicit Barcode(const QJsonObject &obj, const Pass *file);
QString m_altText;
QString m_message;
......
......@@ -22,7 +22,7 @@
using namespace KPkPass;
BoardingPass::BoardingPass(QObject *parent)
: File(QStringLiteral("boardingPass"), parent)
: Pass(QStringLiteral("boardingPass"), parent)
{
}
......
......@@ -20,12 +20,12 @@
#ifndef KPKPASS_BOARDINGPASS_H
#define KPKPASS_BOARDINGPASS_H
#include "file.h"
#include "pass.h"
namespace KPkPass {
/** Boarding pass */
class KPKPASS_EXPORT BoardingPass : public File
class KPKPASS_EXPORT BoardingPass : public Pass
{
Q_GADGET
Q_PROPERTY(TransitType transitType READ transitType)
......
......@@ -18,7 +18,7 @@
*/
#include "field.h"
#include "file.h"
#include "pass.h"
#include <QJsonObject>
......@@ -27,7 +27,7 @@ using namespace KPkPass;
namespace KPkPass {
class FieldPrivate {
public:
const File *file = nullptr;
const Pass *pass = nullptr;
QJsonObject obj;
};
}
......@@ -42,37 +42,34 @@ Field::Field(Field&&) = default;
Field::~Field() = default;
Field& Field::operator=(const Field&) = default;
Field::Field(const QJsonObject &obj, const File *file)
Field::Field(const QJsonObject &obj, const Pass *pass)
: d(new FieldPrivate)
{
d->file = file;
d->pass = pass;
d->obj = obj;
}
QString Field::key() const
{
if (d->file) {
return d->obj.value(QLatin1String("key")).toString();
}
return {};
return d->obj.value(QLatin1String("key")).toString();
}
QString Field::label() const
{
if (d->file) {
return d->file->message(d->obj.value(QLatin1String("label")).toString());
if (d->pass) {
return d->pass->message(d->obj.value(QLatin1String("label")).toString());
}
return {};
}
QVariant Field::value() const
{
if (!d->file) {
if (!d->pass) {
return {};
}
auto v = d->file->message(d->obj.value(QLatin1String("attributedValue")).toString());
auto v = d->pass->message(d->obj.value(QLatin1String("attributedValue")).toString());
if (v.isEmpty()) {
v = d->file->message(d->obj.value(QLatin1String("value")).toString());
v = d->pass->message(d->obj.value(QLatin1String("value")).toString());
}
// TODO number and date/time detection
return v;
......@@ -86,10 +83,10 @@ QString Field::valueDisplayString() const
QString Field::changeMessage() const
{
if (!d->file) {
if (!d->pass) {
return {};
}
auto msg = d->file->message(d->obj.value(QLatin1String("changeMessage")).toString());
auto msg = d->pass->message(d->obj.value(QLatin1String("changeMessage")).toString());
msg = msg.replace(QLatin1String("%@"), valueDisplayString());
return msg;
}
......@@ -31,10 +31,10 @@ class QJsonObject;
namespace KPkPass {
class File;
class Pass;
class FieldPrivate;
/** Field element in a KPkPass::File.
/** Field element in a KPkPass::Pass.
* @see https://developer.apple.com/library/content/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/FieldDictionary.html
*/
class KPKPASS_EXPORT Field
......@@ -73,8 +73,8 @@ public:
// TODO add textAlignment property
private:
friend class File;
explicit Field(const QJsonObject &obj, const File *file);
friend class Pass;
explicit Field(const QJsonObject &obj, const Pass *pass);
std::shared_ptr<FieldPrivate> d;
};
......
......@@ -17,7 +17,7 @@
02110-1301, USA.
*/
#include "file.h"
#include "pass.h"
#include "boardingpass.h"
#include "logging.h"
......@@ -36,25 +36,25 @@
using namespace KPkPass;
File::File(const QString &passType, QObject *parent)
Pass::Pass (const QString &passType, QObject *parent)
: QObject(parent)
, m_passType(passType)
{
}
File::~File() = default;
Pass::~Pass() = default;
QJsonObject File::data() const
QJsonObject Pass::data() const
{
return m_passObj;
}
QJsonObject File::passData() const
QJsonObject Pass::passData() const
{
return m_passObj.value(m_passType).toObject();
}
QString File::message(const QString &key) const
QString Pass::message(const QString &key) const
{
const auto it = m_messages.constFind(key);
if (it != m_messages.constEnd()) {
......@@ -63,12 +63,12 @@ QString File::message(const QString &key) const
return key;
}
QString File::passTypeIdentifier() const
QString Pass::passTypeIdentifier() const
{
return m_passObj.value(QLatin1String("passTypeIdentifier")).toString();
}
QString File::serialNumber() const
QString Pass::serialNumber() const
{
return m_passObj.value(QLatin1String("serialNumber")).toString();
}
......@@ -84,17 +84,17 @@ static QColor parseColor(const QString &s)
return QColor(s);
}
QColor File::backgroundColor() const
QColor Pass::backgroundColor() const
{
return parseColor(m_passObj.value(QLatin1String("backgroundColor")).toString());
}
QColor File::foregroundColor() const
QColor Pass::foregroundColor() const
{
return parseColor(m_passObj.value(QLatin1String("foregroundColor")).toString());
}
QColor File::labelColor() const
QColor Pass::labelColor() const
{
const auto c = parseColor(m_passObj.value(QLatin1String("labelColor")).toString());
if (c.isValid()) {
......@@ -103,12 +103,12 @@ QColor File::labelColor() const
return foregroundColor();
}
QString File::logoText() const
QString Pass::logoText() const
{
return message(m_passObj.value(QLatin1String("logoText")).toString());
}
QImage File::logo(unsigned int devicePixelRatio) const
QImage Pass::logo(unsigned int devicePixelRatio) const
{
const KArchiveFile *file = nullptr;
for (; devicePixelRatio > 1; --devicePixelRatio) {
......@@ -126,12 +126,12 @@ QImage File::logo(unsigned int devicePixelRatio) const
return img;
}
QDateTime File::relevantDate() const
QDateTime Pass::relevantDate() const
{
return QDateTime::fromString(m_passObj.value(QLatin1String("relevantDate")).toString(), Qt::ISODate);
}
QVector<Barcode> File::barcodes() const
QVector<Barcode> Pass::barcodes() const
{
QVector<Barcode> codes;
......@@ -151,32 +151,32 @@ QVector<Barcode> File::barcodes() const
return codes;
}
QVector<Field> File::auxiliaryFields() const
QVector<Field> Pass::auxiliaryFields() const
{
return fields(QLatin1String("auxiliaryFields"));
}
QVector<Field> File::backFields() const
QVector<Field> Pass::backFields() const
{
return fields(QLatin1String("backFields"));
}
QVector<Field> File::headerFields() const
QVector<Field> Pass::headerFields() const
{
return fields(QLatin1String("headerFields"));
}
QVector<Field> File::primaryFields() const
QVector<Field> Pass::primaryFields() const
{
return fields(QLatin1String("primaryFields"));
}
QVector<Field> File::secondaryFields() const
QVector<Field> Pass::secondaryFields() const
{
return fields(QLatin1String("secondaryFields"));
}
File *File::fromData(const QByteArray &data, QObject *parent)
Pass *Pass::fromData(const QByteArray &data, QObject *parent)
{
std::unique_ptr<QBuffer> buffer(new QBuffer);
buffer->setData(data);
......@@ -184,7 +184,7 @@ File *File::fromData(const QByteArray &data, QObject *parent)
return fromData(std::move(buffer), parent);
}
File *File::fromData(std::unique_ptr<QIODevice> device, QObject *parent)
Pass *Pass::fromData(std::unique_ptr<QIODevice> device, QObject *parent)
{
std::unique_ptr<KZip> zip(new KZip(device.get()));
if (!zip->open(QIODevice::ReadOnly)) {
......@@ -199,13 +199,13 @@ File *File::fromData(std::unique_ptr<QIODevice> device, QObject *parent)
std::unique_ptr<QIODevice> dev(file->createDevice());
const auto passObj = QJsonDocument::fromJson(dev->readAll()).object();
File *pass = nullptr;
Pass *pass = nullptr;
if (passObj.contains(QLatin1String("boardingPass"))) {
pass = new BoardingPass(parent);
}
// TODO: coupon, eventTicket, storeCard, generic
else {
pass = new File(QStringLiteral("generic"), parent);
pass = new Pass (QStringLiteral("generic"), parent);
}
pass->m_buffer = std::move(device);
......@@ -215,7 +215,7 @@ File *File::fromData(std::unique_ptr<QIODevice> device, QObject *parent)
return pass;
}
File *File::fromFile(const QString &fileName, QObject *parent)
Pass *Pass::fromFile(const QString &fileName, QObject *parent)
{
std::unique_ptr<QFile> file(new QFile(fileName));
if (file->open(QFile::ReadOnly)) {
......@@ -225,7 +225,7 @@ File *File::fromFile(const QString &fileName, QObject *parent)
return nullptr;
}
void File::parse()
void Pass::parse()
{
// find the message catalog
auto lang = QLocale().name();
......@@ -280,7 +280,7 @@ static QString unquote(const QStringRef &str)
return res;
}
bool File::parseMessages(const QString &lang)
bool Pass::parseMessages(const QString &lang)
{
auto entry = m_zip->directory()->entry(lang);
if (!entry || !entry->isDirectory()) {
......@@ -337,7 +337,7 @@ bool File::parseMessages(const QString &lang)
return !m_messages.isEmpty();
}
QVector<Field> File::fields(const QLatin1String &fieldType) const
QVector<Field> Pass::fields(const QLatin1String &fieldType) const
{
const auto a = passData().value(fieldType).toArray();
QVector<Field> f;
......@@ -357,32 +357,32 @@ static QVariantList toVariantList(const QVector<T> &elems)
return l;
}
QVariantList File::auxiliaryFieldsVariant() const
QVariantList Pass::auxiliaryFieldsVariant() const
{
return toVariantList(auxiliaryFields());
}
QVariantList File::backFieldsVariant() const
QVariantList Pass::backFieldsVariant() const
{
return toVariantList(backFields());
}
QVariantList File::headerFieldsVariant() const
QVariantList Pass::headerFieldsVariant() const
{
return toVariantList(headerFields());
}
QVariantList File::primaryFieldsVariant() const
QVariantList Pass::primaryFieldsVariant() const
{
return toVariantList(primaryFields());
}
QVariantList File::secondaryFieldsVariant() const
QVariantList Pass::secondaryFieldsVariant() const
{
return toVariantList(secondaryFields());
}
QVariantList File::barcodesVariant() const
QVariantList Pass::barcodesVariant() const
{
return toVariantList(barcodes());
}
......@@ -17,8 +17,8 @@
02110-1301, USA.
*/
#ifndef KPKPASS_FILE_H
#define KPKPASS_FILE_H
#ifndef KPKPASS_PASS_H
#define KPKPASS_PASS_H
#include "kpkpass_export.h"
#include "barcode.h"
......@@ -45,8 +45,10 @@ namespace KPkPass {
class Barcode;
/** Base class for a pkpass file. */
class KPKPASS_EXPORT File : public QObject
/** Base class for a pkpass file.
* @see https://developer.apple.com/library/content/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/TopLevel.html
*/
class KPKPASS_EXPORT Pass : public QObject
{
Q_OBJECT
Q_PROPERTY(QString passTypeIdentifier READ passTypeIdentifier CONSTANT)
......@@ -67,7 +69,7 @@ class KPKPASS_EXPORT File : public QObject
Q_PROPERTY(QVariantList barcodes READ barcodesVariant CONSTANT)
public:
virtual ~File();
virtual ~Pass();
/** Content of the pass.json file. */
QJsonObject data() const;
......@@ -96,15 +98,17 @@ public:
QVector<Barcode> barcodes() const;
/** Create a appropriate sub-class based on the pkpass file type. */
static File *fromData(const QByteArray &data, QObject *parent = nullptr);
static Pass *fromData(const QByteArray &data, QObject *parent = nullptr);
/** Create a appropriate sub-class based on the pkpass file type. */
static File *fromFile(const QString &fileName, QObject *parent = nullptr);
static Pass *fromFile(const QString &fileName, QObject *parent = nullptr);
protected:
explicit File(const QString &passType, QObject *parent = nullptr);
///@cond internal
explicit Pass (const QString &passType, QObject *parent = nullptr);
///@endcond
private:
static File *fromData(std::unique_ptr<QIODevice> device, QObject *parent);
static Pass *fromData(std::unique_ptr<QIODevice> device, QObject *parent);
void parse();
bool parseMessages(const QString &lang);
......@@ -125,4 +129,4 @@ private:
}
#endif // KPKPASS_FILE_H
#endif // KPKPASS_PASS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment