MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / databaseBackup

Method databaseBackup

nixnote.cpp:1707–1773  ·  view source on GitHub ↗

Backup (or export) notes

Source from the content-addressed store, hash-verified

1705//* Backup (or export) notes
1706//**************************************************
1707void NixNote::databaseBackup(bool backup) {
1708 QLOG_TRACE() << "Entering databaseBackup()";
1709 ExportData noteReader(backup);
1710
1711 if (!backup) {
1712 noteTableView->getSelectedLids(noteReader.lids);
1713 if (noteReader.lids.size() == 0) {
1714 QMessageBox::critical(this, tr("Error"), tr("No notes selected."));
1715 return;
1716 }
1717 }
1718
1719 QString caption, directory;
1720 if (backup)
1721 caption = tr("Backup Database");
1722 else
1723 caption = tr("Export Notes");
1724 if (saveLastPath == "")
1725 directory = QDir::homePath();
1726 else
1727 directory = saveLastPath;
1728
1729 QFileDialog fd(0, caption, directory, tr("NixNote Export (*.nnex);;All Files (*.*)"));
1730 fd.setFileMode(QFileDialog::AnyFile);
1731 fd.setConfirmOverwrite(true);
1732 fd.setAcceptMode(QFileDialog::AcceptSave);
1733
1734 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
1735 QLOG_DEBUG() << "Database restore canceled in file dialog.";
1736 return;
1737 }
1738
1739 waitCursor(true);
1740 QStringList fileNames;
1741 fileNames = fd.selectedFiles();
1742 saveLastPath = fileNames[0];
1743 int pos = saveLastPath.lastIndexOf("/");
1744 if (pos != -1)
1745 saveLastPath.truncate(pos);
1746
1747 if (backup)
1748 setMessage(tr("Performing backup"));
1749 else
1750 setMessage(tr("Performing export"));
1751
1752 if (!fileNames[0].endsWith(".nnex")) {
1753 fileNames[0].append(".nnex");
1754 }
1755 noteReader.backupData(fileNames[0]);
1756
1757 if (noteReader.lastError != 0) {
1758 setMessage(noteReader.errorMessage);
1759 QLOG_ERROR() << "Backup problem: " << noteReader.errorMessage;
1760 QMessageBox::critical(this, tr("Error"), noteReader.errorMessage);
1761 waitCursor(false);
1762 return;
1763 }
1764

Callers

nothing calls this directly

Calls 3

getSelectedLidsMethod · 0.80
backupDataMethod · 0.80
execMethod · 0.45

Tested by

no test coverage detected