Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Itinerary
Commits
e77c04e7
Commit
e77c04e7
authored
Aug 05, 2021
by
Volker Krause
Browse files
Further unify file- and data-based import code paths
parent
9fb3838f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/app/applicationcontroller.cpp
View file @
e77c04e7
...
...
@@ -340,12 +340,11 @@ void ApplicationController::importLocalFile(const QUrl &url)
importBundle
(
url
);
}
}
else
{
const
auto
data
=
f
.
readAll
();
importReservationOrHealthCertificate
(
data
,
f
.
fileName
());
importData
(
f
.
readAll
(),
f
.
fileName
());
}
}
void
ApplicationController
::
importData
(
const
QByteArray
&
data
)
void
ApplicationController
::
importData
(
const
QByteArray
&
data
,
const
QString
&
fileName
)
{
qCDebug
(
Log
);
if
(
data
.
size
()
<
4
)
{
...
...
@@ -356,7 +355,36 @@ void ApplicationController::importData(const QByteArray &data)
importBundle
(
data
);
}
}
else
{
importReservationOrHealthCertificate
(
data
);
using
namespace
KItinerary
;
ExtractorEngine
engine
;
engine
.
setContextDate
(
QDateTime
(
QDate
::
currentDate
(),
QTime
(
0
,
0
)));
engine
.
setData
(
data
,
fileName
);
const
auto
resIds
=
m_resMgr
->
importReservations
(
JsonLdDocument
::
fromJson
(
engine
.
extract
()));
if
(
!
resIds
.
isEmpty
())
{
// check if there is a document we want to attach here
QMimeDatabase
db
;
const
auto
mt
=
db
.
mimeTypeForFileNameAndData
(
fileName
,
data
);
if
(
mt
.
name
()
==
QLatin1String
(
"application/pdf"
))
{
// TODO support more file types (however we certainly want to exclude pkpass and json here)
DigitalDocument
docInfo
;
docInfo
.
setName
(
fileName
);
docInfo
.
setEncodingFormat
(
mt
.
name
());
const
auto
docId
=
DocumentUtil
::
idForContent
(
data
);
m_docMgr
->
addDocument
(
docId
,
docInfo
,
data
);
for
(
const
auto
&
resId
:
resIds
)
{
auto
res
=
m_resMgr
->
reservation
(
resId
);
if
(
DocumentUtil
::
addDocumentId
(
res
,
docId
))
{
m_resMgr
->
updateReservation
(
resId
,
res
);
}
}
}
Q_EMIT
infoMessage
(
i18np
(
"One reservation imported."
,
"%1 reservations imported."
,
resIds
.
size
()));
return
;
}
// look for health certificate barcodes instead
importHealthCertificateRecursive
(
engine
.
rootDocumentNode
());
}
}
...
...
@@ -486,42 +514,6 @@ bool ApplicationController::importBundle(KItinerary::File *file)
return
count
>
0
;
}
QVector
<
QString
>
ApplicationController
::
importReservationOrHealthCertificate
(
const
QByteArray
&
data
,
const
QString
&
fileName
)
{
using
namespace
KItinerary
;
ExtractorEngine
engine
;
engine
.
setContextDate
(
QDateTime
(
QDate
::
currentDate
(),
QTime
(
0
,
0
)));
engine
.
setData
(
data
,
fileName
);
const
auto
resIds
=
m_resMgr
->
importReservations
(
JsonLdDocument
::
fromJson
(
engine
.
extract
()));
if
(
!
resIds
.
isEmpty
())
{
// check if there is a document we want to attach here
QMimeDatabase
db
;
const
auto
mt
=
db
.
mimeTypeForFileNameAndData
(
fileName
,
data
);
if
(
mt
.
name
()
==
QLatin1String
(
"application/pdf"
))
{
// TODO support more file types (however we certainly want to exclude pkpass and json here)
DigitalDocument
docInfo
;
docInfo
.
setName
(
fileName
);
docInfo
.
setEncodingFormat
(
mt
.
name
());
const
auto
docId
=
DocumentUtil
::
idForContent
(
data
);
m_docMgr
->
addDocument
(
docId
,
docInfo
,
data
);
for
(
const
auto
&
resId
:
resIds
)
{
auto
res
=
m_resMgr
->
reservation
(
resId
);
if
(
DocumentUtil
::
addDocumentId
(
res
,
docId
))
{
m_resMgr
->
updateReservation
(
resId
,
res
);
}
}
}
Q_EMIT
infoMessage
(
i18np
(
"One reservation imported."
,
"%1 reservations imported."
,
resIds
.
size
()));
return
resIds
;
}
// look for health certificate barcodes instead
importHealthCertificateRecursive
(
engine
.
rootDocumentNode
());
return
{};
}
bool
ApplicationController
::
importHealthCertificateRecursive
(
const
ExtractorDocumentNode
&
node
)
{
if
(
node
.
childNodes
().
size
()
==
1
&&
node
.
mimeType
()
==
QLatin1String
(
"internal/qimage"
))
{
...
...
src/app/applicationcontroller.h
View file @
e77c04e7
...
...
@@ -53,7 +53,7 @@ public:
void
importFromIntent
(
const
KAndroidExtras
::
Intent
&
intent
);
Q_INVOKABLE
void
importFromClipboard
();
Q_INVOKABLE
void
importFromUrl
(
const
QUrl
&
url
);
void
importData
(
const
QByteArray
&
data
);
void
importData
(
const
QByteArray
&
data
,
const
QString
&
fileName
=
{}
);
Q_INVOKABLE
void
checkCalendar
();
...
...
@@ -86,7 +86,6 @@ private:
bool
importBundle
(
const
QUrl
&
url
);
bool
importBundle
(
const
QByteArray
&
data
);
bool
importBundle
(
KItinerary
::
File
*
file
);
QVector
<
QString
>
importReservationOrHealthCertificate
(
const
QByteArray
&
data
,
const
QString
&
fileName
=
{});
bool
importHealthCertificateRecursive
(
const
KItinerary
::
ExtractorDocumentNode
&
node
);
void
importPass
(
const
QString
&
passId
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment