Switch the pkpass formatter plugin to use KPkPass
ClosedPublic

Authored by vkrause on Mar 31 2018, 8:33 AM.

Details

Summary

This brings no functional change, but it makes the pkpass handling code
reusable in other places too.

Diff Detail

Repository
R81 KDE PIM Addons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
vkrause created this revision.Mar 31 2018, 8:33 AM
Restricted Application added a project: KDE PIM. · View Herald TranscriptMar 31 2018, 8:33 AM
vkrause requested review of this revision.Mar 31 2018, 8:33 AM
knauss added a subscriber: knauss.Mar 31 2018, 10:35 AM
knauss added inline comments.
plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp
105

why not give grantlee the ability to understand QColor? I mean we already have special lookups and it make sense to have the feature for complete kdepim.

vkrause added inline comments.Mar 31 2018, 11:38 AM
plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp
105

How? I did not find a way to add string conversions for custom types externally. And I can't do this in Grantlee itself, as it would add a dependency on QtGui which it currently does not have.

knauss added inline comments.Mar 31 2018, 9:28 PM
plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp
105

use something like this:
GRANTLEE_BEGIN_LOOKUP(QColor)
if ( property == "name" )
return object.name();
else if ( property == "age" )
return object.age();
else
return object.name()
GRANTLEE_END_LOOKUP

http://www.grantlee.org/apidox/generic_types_and_templates.html

and see messagelib/messageviewer/src/messagepartthemes/default/messagepartrenderermanager.cpp for more examples...

knauss added inline comments.Mar 31 2018, 9:33 PM
CMakeLists.txt
124

the naming is also a little bit wired as we dont used this KPk before.

plugins/messageviewer/bodypartformatter/pkpass/CMakeLists.txt
15

I think if i now enters KDE Pim it should exist in in KPim namespace.

vkrause added inline comments.Apr 1 2018, 8:38 AM
CMakeLists.txt
124

"KPk" is not the namespace here, "K" is. "PkPass" is the name of the file format (and Apple came up with that one, hard to change for me ;-) ).

plugins/messageviewer/bodypartformatter/pkpass/CMakeLists.txt
15

That doesn't seem to be widely used, but I can of course change the library accordingly (it will need to be done there first though).

plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp
105

That's for property access to custom types, not for turning a custom type into a string (and it's in use in this file even). This is usable in theory by adding a dummy property such as "name" to QColor, but that is just as clunky as the current solution. What we would want is turning a QColor directly into a string, without any such indirection, and that's the part I haven't found a solution for yet.

knauss added inline comments.Apr 1 2018, 8:48 AM
CMakeLists.txt
124

A okay- well I parsed the KP as shorthand for kde pim. What about KPimPkPass?

plugins/messageviewer/bodypartformatter/pkpass/CMakeLists.txt
15

that is right - because everyone thought that we need to use the KF5:: namespace. And we didn't wanted to move everything to KPIm:: later on, that's why only new libs using this namespace.

plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp
105

can't you can return a default value, if no property is given. In messagelib/messageviewer/src/messagepartthemes/default/messagepartrenderermanager.cpp i needed to write my own lookup functions, maybe the macros are not working for this anymore.

vkrause added inline comments.Apr 1 2018, 8:57 AM
CMakeLists.txt
124

And KPim::PkPass in CMake, yes. Also makes a possible future migration to KF5 easier, "KPim" is easier to search/replace than "K".

plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp
105

I don't think this works, as Grantlee seems to use the lookup functions only when encountering a "." followed by a string, for a type with a custom lookup function registered.

A custom string conversion function is possible in theory via QMetaType::registerConverter, but that does not accept a conversion between two built-in types, so that also does not help in the case of QColor.

vkrause updated this revision to Diff 31150.Apr 2 2018, 2:07 PM

Move KPkPass library to KPim namespace

knauss added inline comments.Apr 2 2018, 11:50 PM
CMakeLists.txt
93

update the name here too

plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp
27

either <PkPass or <KPimPkPass to be consitent

50

also rename the classes PkPass::Barcode, PkPass::Field ?

105

I still think that having the .name inside the template is the more clean solution, but well this is only minor personal syntax style.

mlaurent requested changes to this revision.Apr 3 2018, 4:43 AM
mlaurent added a subscriber: mlaurent.
mlaurent added inline comments.
plugins/messageviewer/bodypartformatter/pkpass/CMakeLists.txt
21

you can remove this line too as we don't call update this macro
find_package(SharedMimeInfo ${SharedMimeInfo_MINIMUM_VERSION} REQUIRED)

This revision now requires changes to proceed.Apr 3 2018, 4:43 AM
vkrause added inline comments.Apr 3 2018, 6:49 AM
plugins/messageviewer/bodypartformatter/pkpass/CMakeLists.txt
21

Indeed, I'll fix that.

plugins/messageviewer/bodypartformatter/pkpass/pkpass_plugin.cpp
27

This now follows the KF5 naming patterns, ie. namespacing the library with "KF5" (or "KPim" here), and namespacing the C++ namespace with "K". I used the pattern you suggest initially in KF5::SyntaxHighlighting, and had to change it to the KSyntaxHighlighting namespace in review. So for consistency I'd follow KF5 here.

vkrause updated this revision to Diff 31196.Apr 3 2018, 6:51 AM

Remove no longer needed sharedmimeinfo dependency.

mlaurent accepted this revision.Apr 4 2018, 8:32 AM
This revision is now accepted and ready to land.Apr 4 2018, 8:32 AM
knauss accepted this revision.Apr 4 2018, 9:27 AM
This revision was automatically updated to reflect the committed changes.