diff --git a/src/dbtoxmlconverter.cpp b/src/dbtoxmlconverter.cpp index 98171c4a..98341417 100644 --- a/src/dbtoxmlconverter.cpp +++ b/src/dbtoxmlconverter.cpp @@ -87,11 +87,16 @@ QMap DbToXMLConverter::convert(const QString& dBase) // -- Convert the numbercycles int nc_cnt = convertNumbercycles(dBase); overallResults["numberCyclesOk"] = nc_cnt; - emit conversionOut(i18n("
transformed %1 numbercycle(s) successfully.").arg(nc_cnt)); + emit conversionOut(i18n("
Transformed %1 numbercycle(s) successfully.").arg(nc_cnt)); for( const auto& k : overallResults.keys()) { qDebug() << "Tranformation result" << k << ":" << overallResults[k]; } + if (convertOwnIdentity(dBase)) { + qDebug() << "manual own Identity converted"; + emit conversionOut(i18n("
Converted manual created identity successfully")); + } + if (nc_cnt == 0) { qDebug() << "Could not transform any numbercycles. Smell!"; } @@ -282,7 +287,7 @@ int DbToXMLConverter::convertNumbercycles(const QString& baseDir) QDir dir(baseDir); dir.cd(DefaultProvider::self()->kraftV2Subdir(DefaultProvider::KraftV2Dir::NumberCycles)); - bool re; + bool re{false}; QSaveFile file(dir.absoluteFilePath("numbercycles.xml")); if ( file.open( QIODevice::WriteOnly | QIODevice::Text) ) { re = file.write(xml.toUtf8()); @@ -291,5 +296,25 @@ int DbToXMLConverter::convertNumbercycles(const QString& baseDir) re = file.commit(); } } + if (!re) cnt = 0; return cnt; } + +// copy a manually created own identity over to the new location +bool DbToXMLConverter::convertOwnIdentity(const QString& baseDir) +{ + // The Kraft 1.x file position is this: + QString v1file = QStandardPaths::writableLocation( QStandardPaths::AppDataLocation ); + v1file += "/myidentity.vcd"; + + QDir dir(baseDir); + dir.cd(DefaultProvider::self()->kraftV2Subdir(DefaultProvider::KraftV2Dir::OwnIdentity)); + QString v2File = dir.absoluteFilePath("myidentity.vcd"); + + QFile fi(v1file); + bool re{false}; + if (fi.exists()) { + re = fi.copy(v2File); + } + return re; +} diff --git a/src/dbtoxmlconverter.h b/src/dbtoxmlconverter.h index 5be41797..40cd15a0 100644 --- a/src/dbtoxmlconverter.h +++ b/src/dbtoxmlconverter.h @@ -38,6 +38,7 @@ class DbToXMLConverter : public QObject int amountOfDocsOfYear(int year); int convertNumbercycles(const QString &baseDir); + bool convertOwnIdentity(const QString& baseDir); signals: void conversionOut(const QString&); diff --git a/src/defaultprovider.cpp b/src/defaultprovider.cpp index c932ec31..e4fe44ba 100644 --- a/src/defaultprovider.cpp +++ b/src/defaultprovider.cpp @@ -442,6 +442,7 @@ QString DefaultProvider::kraftV2Subdir(KraftV2Dir dir) QString subdir; switch (dir) { case KraftV2Dir::Root: + case KraftV2Dir::OwnIdentity: break; // return the empty string case KraftV2Dir::NumberCycles: subdir = "numbercycles"; diff --git a/src/defaultprovider.h b/src/defaultprovider.h index 9bf7ae45..39a3554f 100644 --- a/src/defaultprovider.h +++ b/src/defaultprovider.h @@ -41,7 +41,8 @@ class KRAFTCAT_EXPORT DefaultProvider Root, XmlDocs, PdfDocs, - NumberCycles + NumberCycles, + OwnIdentity }; ~DefaultProvider(); diff --git a/src/myidentity.cpp b/src/myidentity.cpp index 1db4cf2b..9b34c74d 100644 --- a/src/myidentity.cpp +++ b/src/myidentity.cpp @@ -18,6 +18,7 @@ #include "myidentity.h" #include "kraftsettings.h" #include "addressprovider.h" +#include "defaultprovider.h" #include #include @@ -65,7 +66,7 @@ KContacts::Addressee MyIdentity::UIToAddressee(Ui::manualOwnIdentity ui) QString MyIdentity::identityFile() { - QString file = QStandardPaths::writableLocation( QStandardPaths::AppDataLocation ); + QString file = DefaultProvider::self()->kraftV2Dir(DefaultProvider::KraftV2Dir::OwnIdentity); file += "/myidentity.vcd"; return file; diff --git a/tests/t_defaultprovider.cpp b/tests/t_defaultprovider.cpp index 8b08d98c..ba347ede 100644 --- a/tests/t_defaultprovider.cpp +++ b/tests/t_defaultprovider.cpp @@ -164,6 +164,8 @@ private slots: QString pRoot = DefaultProvider::self()->kraftV2Dir(DefaultProvider::KraftV2Dir::Root); const QString pNumC = DefaultProvider::self()->kraftV2Dir(DefaultProvider::KraftV2Dir::NumberCycles); const QString pXmlD = DefaultProvider::self()->kraftV2Dir(DefaultProvider::KraftV2Dir::XmlDocs); + const QString pOwnI = DefaultProvider::self()->kraftV2Dir(DefaultProvider::KraftV2Dir::OwnIdentity); + QCOMPARE(base, pOwnI); QCOMPARE(base, pRoot); QCOMPARE(base + "/numbercycles", pNumC); QCOMPARE(base + "/xmldoc", pXmlD);