| 47 | |
| 48 | |
| 49 | void ExportData::backupData(QString filename) { |
| 50 | quitNow = false; |
| 51 | QFile xmlFile(filename); |
| 52 | if (!xmlFile.open(QIODevice::WriteOnly)) { |
| 53 | lastError = 16; |
| 54 | errorMessage = tr("Cannot open file."); |
| 55 | return; |
| 56 | } |
| 57 | if (!cmdLine) { |
| 58 | progress = new QProgressDialog(); |
| 59 | progress->setAutoClose(false); |
| 60 | progress->setWindowModality(Qt::ApplicationModal); |
| 61 | connect(progress, SIGNAL(canceled()), this, SLOT(abortBackup())); |
| 62 | progress->setWindowTitle(tr("Export")); |
| 63 | } |
| 64 | writer = new QXmlStreamWriter(&xmlFile); |
| 65 | writer->setAutoFormatting(true); |
| 66 | writer->setCodec("UTF-8"); |
| 67 | writer->writeStartDocument(); |
| 68 | writer->writeDTD("<!DOCTYPE NixNote-Export>"); |
| 69 | writer->writeStartElement("nixnote-export"); |
| 70 | writer->writeAttribute("version", "2"); |
| 71 | if (backup) |
| 72 | writer->writeAttribute("exportType", "backup"); |
| 73 | else |
| 74 | writer->writeAttribute("exportType", "export"); |
| 75 | writer->writeAttribute("application", "NixNote"); |
| 76 | writer->writeAttribute("applicationVersion", "2.x"); |
| 77 | if (backup) { |
| 78 | NoteTable noteTable(global.db); |
| 79 | noteTable.getAll(this->lids); |
| 80 | if (!cmdLine) |
| 81 | progress->setWindowTitle(tr("Backup")); |
| 82 | writer->writeStartElement("Synchronization"); |
| 83 | UserTable userTable(global.db); |
| 84 | qlonglong lastSyncDate = userTable.getLastSyncDate(); |
| 85 | qint32 number = userTable.getLastSyncNumber(); |
| 86 | createNode("UpdateSequenceNumber", QString::number(number)); |
| 87 | createNode("LastSequenceDate", QString::number(lastSyncDate)); |
| 88 | writer->writeEndElement(); |
| 89 | |
| 90 | writeNotebooks(); |
| 91 | writeTags(); |
| 92 | writeSavedSearches(); |
| 93 | writeLinkedNotebooks(); |
| 94 | writeSharedNotebooks(); |
| 95 | } |
| 96 | writeNotes(); |
| 97 | writer->writeEndElement(); |
| 98 | writer->writeEndDocument(); |
| 99 | if (!cmdLine) |
| 100 | progress->hide(); |
| 101 | xmlFile.close(); |
| 102 | } |
| 103 | |
| 104 | |
| 105 |
no test coverage detected