Move opening files to KMyMoneyApp
ClosedPublic

Authored by wojnilowicz on Feb 24 2018, 8:19 AM.

Details

Summary

In my opinion opening file has little to do with views, so I moved it to KMyMoneyApp. KMyMoneyApp in many places already called KMyMoneyView in this regard, so the move around seems like a good choice.
It also serves as a one step forward in making KMyMoneyView independent of KMyMoneyApp.
The next step would be to reduce a rather long code to open a simple file.

Test Plan

I opened and saved: database, kmy file, gnc file.

Diff Detail

Repository
R261 KMyMoney
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
wojnilowicz requested review of this revision.Feb 24 2018, 8:19 AM
wojnilowicz created this revision.
wojnilowicz edited the test plan for this revision. (Show Details)

Code in KMyMoneyApp has been refactored in following way:

  1. no deep and long "if trees" to improve code readability,
  2. gnc file is opened like a normal kmy file,
  3. all file related methods were moved to pimpl,
  4. code path for opening database and nondatabase has been explicitly divided, as it differs too much right now,
  5. code for initializing storage has been divided into functional blocks, for better readability,
  6. opening nondatabase throws lot of exceptions for debugging purposes.

I have not yet tested to compile or run the patch but still have to do that before I can give a judgment.

kmymoney/kmymoney.cpp
468

Isn't

q->d->fixFile_0();

the same as

fixFile_0();

?

850

Ah, here's a nice one: can't we add a method to the plugin that takes care of the detection? We pass the qbaFileHeader and the plugin tells us, if it is capable of reading the file (no matter how). This way, we can eliminate the GNC stuff here and move it into the plugin.

996

Can't the

QString::fromLatin1("~")

be a

QLatin1String("~")

?

2515

Same here: the plugin should take care of adding it's own stuff that it supports. E.g.

const QString fileExtension = plugin->fileExtension();
if (!fileExtension.isEmpty()) {
  fileExtensions.append(fileExtension);
  fileExtensions.append(QLatin1String(";;"));
}

No break, because it could have multiple plugins which can read their data file.

wojnilowicz marked an inline comment as done.Feb 26 2018, 7:30 PM
wojnilowicz added inline comments.
kmymoney/kmymoney.cpp
850

I think it's a good idea to have all GNC stuff in GNC plugin.

I think, that instead of moulding every storage plugin to pReader we could only require MyMoneyStorageMgr filled up like in the case of SQL.

I think it's not good to pass qbaFileHeader, because database can be just a url to connect to and not a physical file you can read through.

I would like to divide that method further, shake off some more unneeded stuff and create XML storage plugin. Then we could have handlers of files in plugins which would be self contained units.

I think the change you request could go in follow-up patches.

996

QStringLiteral is more appropriate here. Please check header file of KBackup::numberedBackupFile.

2515

I think it could be arranged.

wojnilowicz marked an inline comment as done.
This revision was not accepted when it landed; it landed in state Needs Review.Mar 4 2018, 1:26 PM
This revision was automatically updated to reflect the committed changes.