Skip to content

Commit

Permalink
Convert own identity to v2 file struct and read it from there
Browse files Browse the repository at this point in the history
Fixes #245
  • Loading branch information
dragotin committed Oct 15, 2024
1 parent 82f1638 commit 3c3480d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
29 changes: 27 additions & 2 deletions src/dbtoxmlconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ QMap<QByteArray, int> DbToXMLConverter::convert(const QString& dBase)
// -- Convert the numbercycles
int nc_cnt = convertNumbercycles(dBase);
overallResults["numberCyclesOk"] = nc_cnt;
emit conversionOut(i18n("<br/>transformed %1 numbercycle(s) successfully.").arg(nc_cnt));
emit conversionOut(i18n("<br/>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("<br/>Converted manual created identity successfully"));
}

if (nc_cnt == 0) {
qDebug() << "Could not transform any numbercycles. Smell!";
}
Expand Down Expand Up @@ -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());
Expand All @@ -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;
}
1 change: 1 addition & 0 deletions src/dbtoxmlconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
Expand Down
1 change: 1 addition & 0 deletions src/defaultprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/defaultprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class KRAFTCAT_EXPORT DefaultProvider
Root,
XmlDocs,
PdfDocs,
NumberCycles
NumberCycles,
OwnIdentity
};

~DefaultProvider();
Expand Down
3 changes: 2 additions & 1 deletion src/myidentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "myidentity.h"
#include "kraftsettings.h"
#include "addressprovider.h"
#include "defaultprovider.h"

#include <KLocalizedString>
#include <QFile>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/t_defaultprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3c3480d

Please sign in to comment.