Menu

[efa3d9]: / src / export-firefox.cpp  Maximize  Restore  History

Download this file

102 lines (81 with data), 2.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
#include <QMessageBox>
#include "export-firefox.h"
#include "attributeitem.h"
#include "branchitem.h"
#include "mainwindow.h"
#include "vymmodel.h"
extern QString vymName;
extern Main *mainWindow;
ExportFirefox::ExportFirefox()
{
exportName = "Firefox";
filter = "JSON (*.json);;All (* *.*)";
caption = vymName + " -" + QObject::tr("Export as Firefox bookmarks");
}
QJsonObject ExportFirefox::buildList(BranchItem *bi)
{
// Loop over children branches
QJsonObject jsobj;
QJsonArray jarray;
if (bi->branchCount() > 0 ) {
for (int i = 0; i < bi->branchCount(); i++)
jarray.append(buildList(bi->getBranchNum(i)));
jsobj["children"] = jarray;
}
QString key;
AttributeItem *ai;
for (int i = 0; i < bi->attributeCount(); i++) {
ai =bi->getAttributeNum(i);
key = ai->key();
// Rewrite some values, which maybe have been modified in map
if (key == "index")
ai->setValue(bi->num());
else if (key == "uri" && bi->hasUrl())
ai->setValue(bi->url());
else if (key == "title" && !bi->headingPlain().isEmpty())
ai->setValue(bi->headingPlain());
// Export values
if (key == "postData")
jsobj[key] = QJsonValue::Null;
else if (ai->value().typeName() == "QDateTime")
jsobj[key] = QJsonValue(ai->value().toDateTime().toMSecsSinceEpoch() * 1000);
else if (ai->value().typeName() == "QString")
jsobj[key] = ai->value().toString();
else if (ai->value().typeName() == "Integer")
{
jsobj[key] = QJsonValue(ai->value().toInt());
}
else
qWarning() << "ExportFirefox Unknown attribute type in " << bi->headingPlain() << "Key: " << key;
}
return jsobj;
}
void ExportFirefox::doExport()
{
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::critical(
0, QObject::tr("Critical Export Error"),
QObject::tr("Could not export as Firefox bookmarks to %1").arg(filePath));
mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
return;
}
// Select bookmark main branch
model->select("mc:0,bo:0");
BranchItem *bi = model->getSelectedBranch();
if (!bi) return;
// Loop over all branches
QJsonObject jsobj;
QJsonArray jarray;
/*
for (int i = 0; i < bi->branchCount(); i++)
jarray.append(buildList(bi->getBranchNum(i)));
jsobj["children"] = jarray;
*/
jsobj = buildList(bi);
file.write(QJsonDocument(jsobj).toJson());
file.close();
displayedDestination = filePath;
result = ExportBase::Success;
completeExport();
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.