3 #include "export-firefox.h"
5 #include "attributeitem.h"
6 #include "mainwindow.h"
8 extern QString vymName;
9 extern Main *mainWindow;
11 ExportFirefox::ExportFirefox()
13 exportName = "Firefox";
14 filter = "JSON (*.json);;All (* *.*)";
15 caption = vymName + " -" + QObject::tr("Export as Firefox bookmarks");
18 QJsonObject ExportFirefox::buildList(BranchItem *bi)
20 // Loop over children branches
24 if (bi->branchCount() > 0 ) {
25 for (int i = 0; i < bi->branchCount(); i++)
26 jarray.append(buildList(bi->getBranchNum(i)));
28 jsobj["children"] = jarray;
33 for (int i = 0; i < bi->attributeCount(); i++) {
34 ai =bi->getAttributeNum(i);
37 // Rewrite some values, which maybe have been modified in map
39 ai->setValue(bi->num());
40 else if (key == "uri" && !bi->getURL().isEmpty())
41 ai->setValue(bi->getURL());
42 else if (key == "title" && !bi->getHeadingPlain().isEmpty())
43 ai->setValue(bi->getHeadingPlain());
46 if (key == "postData")
47 jsobj[key] = QJsonValue::Null;
48 else if (ai->getAttributeType() == AttributeItem::DateTime)
49 jsobj[key] = QJsonValue(ai->getValue().toDateTime().toMSecsSinceEpoch() * 1000);
50 else if (ai->getAttributeType() == AttributeItem::String)
51 jsobj[key] = ai->getValue().toString();
52 else if (ai->getAttributeType() == AttributeItem::Integer)
54 jsobj[key] = QJsonValue(ai->getValue().toInt());
57 qWarning() << "ExportFirefox Unknown attribute type in " << bi->getHeadingPlain() << "Key: " << key;
63 void ExportFirefox::doExport()
66 if (!file.open(QIODevice::WriteOnly)) {
67 QMessageBox::critical(
68 0, QObject::tr("Critical Export Error"),
69 QObject::tr("Could not export as Firefox bookmarks to %1").arg(filePath));
70 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
74 // Select bookmark main branch
75 model->select("mc:0,bo:0");
77 BranchItem *bi = model->getSelectedBranch();
80 // Loop over all branches
85 for (int i = 0; i < bi->branchCount(); i++)
86 jarray.append(buildList(bi->getBranchNum(i)));
88 jsobj["children"] = jarray;
90 jsobj = buildList(bi);
92 file.write(QJsonDocument(jsobj).toJson());
95 displayedDestination = filePath;
97 result = ExportBase::Success;