Add field for institution's website URL
ClosedPublic

Authored by tbaumgart on Jun 24 2018, 4:26 PM.

Details

Summary

This change adds an edit field for the URL of a bank's website to the
institution dialog. For security reasons, allow the https protocol is
used. The protocol does not need to be entered as part of the URL and in
case it is, it will be removed from the URL part. A button right to the
edit field allows to open the URL entered in the browser.

Whenever the URL text changes, a check will be started to verify that
the URL entered accesses a web server. In case it does, the button is
enabled otherwise disabled. In case a favicon is found at the URL it is
placed on the button otherwise, the standard KMyMoney icon for
institutions is used. In case of an invalid URL the icon will be removed
from the button.

No check is performed that it is really your bank's website that opens
when pressing the button.


Button with a favicon drawn from the website.


Same area with an account that is not managed by an institution.


And an institution that does not provide a favicon, so we use our own.

Test Plan

Added false URLs, URLs that do not provide a favicon and ones that
provide a favicon. Saved data to file and checked that the KVP
entries are filled.

Diff Detail

Repository
R261 KMyMoney
Branch
bankurl
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 281
Build 281: arc lint + arc unit
tbaumgart requested review of this revision.Jun 24 2018, 4:26 PM
tbaumgart created this revision.

In a second step I want to add a widget to the ledger that allows to access the bank's website. This change is just so that one can maintain the URL and store it.

tbaumgart updated this revision to Diff 36613.Jun 24 2018, 5:02 PM
  • Added missing library include
wojnilowicz added inline comments.Jun 25 2018, 7:14 PM
kmymoney/CMakeLists.txt
77

Why here?
It should be linked as PRIVATE module in dialogs target.

kmymoney/dialogs/knewbankdlg.cpp
28

What is it here for?

39

Why not?

#include <KIOGui/KIO/FavIconRequestJob>
66

Is using temporary file as per this example is too much to write? I think this method is unjustified and based on Qt docs probably returns invalid filename.

69

According to this source,
"Auto-remove is on by default." . Why setting it explicitly then?

74

Did you know this and this? I think it's better to adhere to guidelines of libraries we are using.

77

Where is this used?

101

It's static function so you can save on QByteArray construction by using it as follows

QByteArray::fromPercentEncoding
118

Would it break if you would capture by reference i.e. [&] ?

168

Why using constData() here? Isn't QString overloaded on QByteArray returned from toPercentEncoding?

168

You store here whole QIcon as a QString and that's big (especially in case of Icons::Icon::ViewBank). I'm not against it but haven't you thought about storing path to icon only?

203

Isn't it better to use static QTimer::singleShot? No data member and no signal connect needed then.

kmymoney/dialogs/knewbankdlg.h
50

I know it's not related to this patch but maybe it's worth to change it to

private Q_SLOTS:
tbaumgart updated this revision to Diff 36654.Jun 25 2018, 9:15 PM
tbaumgart marked 12 inline comments as done.
  • Added missing library include
  • Changes according to the review
tbaumgart marked an inline comment as done.Jun 25 2018, 9:16 PM
tbaumgart added inline comments.
kmymoney/dialogs/knewbankdlg.cpp
28

A leftover, removed.

39

Also a leftover trying to solve another problem.

66

Method is unused and a leftover from a previous version.

74

Yes, but I adhere to the style used throughout the whole KMyMoney code base.

77

Removed, more leftover.

101

Right, I have overlooked the static quantifier.

118

Yes, it crashes.

168

Fixed the toPercentEncoding conversion into a QString. You're right, no need to use constData().

Yes, but I want to have access to the icon w/o downloading it from the internet. And in fact, it is pretty short, the one downloaded from my bank is much bigger (factor of 10). And the path might disappear without notice as it is just a cache.

203

No, because you cannot re-trigger it. This is why I have chosen this implementation.

kmymoney/dialogs/knewbankdlg.h
50

True.

All in all it works very well.

kmymoney/dialogs/knewbankdlg.cpp
28

Hmm... I still can see it.

74

That style is not compatible with any of the mentioned styles. Is there any reason why you stick explicitly with it?

168

Oh. And I thought you download it from the internet each time. I'm not big fan of storing encoded data in kmy file because of this. I thought your opinion was the same. If not then we should also accept D10614.

203

Don't you need to call

d->m_iconLoadTimer.start(200);

to re-trigger it? In that case QTimer::singleShot still has advantages.

Besides you're setting

m_iconLoadTimer.setSingleShot(true);

to not re-trigger it automatically.

For sure, there is something that I do not understand.

tbaumgart marked an inline comment as done.Jun 27 2018, 6:04 AM
tbaumgart added inline comments.
kmymoney/dialogs/knewbankdlg.cpp
28

Now gone for good.

168

D10614 is a bit different I think. There an already local file is added which does not make sense in my eyes. Here we load the icon from the internet and don't have control over it's presence in the favicon cache. Since I plan to display it everytime someone opens a ledger for the account, the user might not have access to the internet at that time. Or it is slow. I also don't want to check upon opening of the ledger if the internet is present but do that only in case the user selects to open the bank's web-site. In fact, this is performed by the browser.

203

That last sentence is the key here :-) I might have to write a blog entry.

tbaumgart updated this revision to Diff 36741.Jun 27 2018, 6:05 AM
tbaumgart marked an inline comment as done.
  • Added missing library include
  • Changes according to the review
  • Removed some more leftover trial code
wojnilowicz added inline comments.Jun 27 2018, 2:48 PM
kmymoney/dialogs/knewbankdlg.cpp
168

The only difference I see is that in your case the icon is downloaded automatically instead of pointed manually. Both icon types are meant to be FavIcons. The end effect is equal i.e. obfuscated storage.

I would establish our own cache with icons (FavIcons and icons from D10614) and point all links there but I leave it up to you.

203

Now I see. Thanks for the explanation.

tbaumgart updated this revision to Diff 36950.Jun 30 2018, 1:59 PM
  • Improve favicon storage for institutions
tbaumgart updated this revision to Diff 36960.Jun 30 2018, 4:54 PM
  • Add a button with an icon to open the banks website
tbaumgart edited the summary of this revision. (Show Details)Jun 30 2018, 4:59 PM

Just a random thought - will any of this code be useful for adding a URL to a Payee? It could be useful there as well.

Additional thought - I have some accounts (store credit cards, for example) which I currently do NOT have under any institution. Would it be reasonable to add the URL at the account level, or should I just create an institution for each of them? I suppose it might be worth thinking of a future expansion of this to have a URL for each account, separate from the generic URL for the institution. Not necessarily important, but might save a few mouse clicks to go straight to the account.

I did not test it this time but it looks better with icons in cache.

kmymoney/dialogs/knewbankdlg.cpp
217

Why don't you check this URL in KNewBankDlg::slotUrlChanged? That way you could start KNewBankDlg::slotLoadIcon only after url check passes and not every time url changes. Maybe I don't see something in your code but it seems logical to me that way.

kmymoney/icons/icons.cpp
27 ↗(On Diff #36960)

Is that needed?

416 ↗(On Diff #36960)

Why did you not use QStandardPaths::CacheLocation? Then no need for #include QDir or for this function at all.

425 ↗(On Diff #36960)

It's a bit unclear what are you searching here for, so maybe a one line comment would be good.

428 ↗(On Diff #36960)

QString::compare is overloaded with QLatin1String so no need for a heavy QStringLiteral.

433 ↗(On Diff #36960)

It's better to write

QString::fromLatin1("%1/%2-%3")

Applies to similar strings as well.

kmymoney/icons/icons.h
106 ↗(On Diff #36960)

Those new function names are a little bit ambigious with "get" function in backgound.
What would you say for:
loadIconFromCache
storeIconInCache

tbaumgart updated this revision to Diff 36970.Jun 30 2018, 9:05 PM
tbaumgart marked 5 inline comments as done.
  • Added changes request by review
tbaumgart added inline comments.Jun 30 2018, 9:05 PM
kmymoney/dialogs/knewbankdlg.cpp
217

You sure remember that slotLoadIcon() is only called when that single shot timer elapses after the last change of the URL. So it is not checked on every change.

kmymoney/icons/icons.cpp
416 ↗(On Diff #36960)

QDir is still needed for QDir::mkpath() due to this note in Qt docs:

The storage location returned can be a directory that does not exist; i.e., it may need to be created by the system or the user.

kmymoney/icons/icons.h
106 ↗(On Diff #36960)

Good point. Will change it.

wojnilowicz accepted this revision.Jul 1 2018, 4:14 AM
wojnilowicz added inline comments.
kmymoney/icons/icons.cpp
435 ↗(On Diff #36970)

QRegularExpressionMatch::captured is not overloaded with QLatin1String.

461 ↗(On Diff #36970)

You don't check if the requested icon really exist in cache.

This revision is now accepted and ready to land.Jul 1 2018, 4:14 AM
tbaumgart marked 2 inline comments as done.Jul 1 2018, 6:52 AM
This revision was automatically updated to reflect the committed changes.