Skip to content

Commit

Permalink
Add the ability to export/backup notes. Not fully tested yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
baumgarr committed Mar 30, 2014
1 parent 97e889d commit f18f1f0
Show file tree
Hide file tree
Showing 16 changed files with 979 additions and 14 deletions.
24 changes: 19 additions & 5 deletions Makefile

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions NixNote2.pro
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ SOURCES += main.cpp\
gui/externalbrowse.cpp \
sql/nsqlquery.cpp \
dialog/aboutdialog.cpp \
xml/importenex.cpp
xml/importenex.cpp \
xml/exportdata.cpp



Expand Down Expand Up @@ -318,7 +319,8 @@ HEADERS += nixnote.h \
gui/externalbrowse.h \
sql/nsqlquery.h \
dialog/aboutdialog.h \
xml/importenex.h
xml/importenex.h \
xml/exportdata.h


INCLUDEPATH += /usr/local/include/thrift \
Expand Down
19 changes: 17 additions & 2 deletions gui/nmainmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,36 @@ void NMainMenuBar::setupFileMenu() {

fileMenu->addSeparator();

backupDatabaseAction = new QAction(tr("Backup Database"), this);
backupDatabaseAction->setToolTip(tr("Backup database to a file"));
backupDatabaseAction->setFont(f);
connect(backupDatabaseAction, SIGNAL(triggered()), parent, SLOT(databaseBackup()));
setupShortcut(backupDatabaseAction, QString("File_Backup_Database"));
fileMenu->addAction(backupDatabaseAction);

restoreDatabaseAction = new QAction(tr("Restore Database"), this);
restoreDatabaseAction->setToolTip(tr("Restore from a backup"));
restoreDatabaseAction->setFont(f);
connect(restoreDatabaseAction, SIGNAL(triggered()), parent, SLOT(databaseRestore()));
setupShortcut(restoreDatabaseAction, QString("File_Restore_Database"));
fileMenu->addAction(restoreDatabaseAction);

importNoteAction = new QAction(tr("Import from Export File"), this);
fileMenu->addSeparator();

exportNoteAction = new QAction(tr("Export Notes"), this);
exportNoteAction->setToolTip(tr("Export selected notes to a file"));
exportNoteAction->setFont(f);
connect(exportNoteAction, SIGNAL(triggered()), parent, SLOT(noteExport()));
setupShortcut(exportNoteAction, QString("File_Note_Export"));
fileMenu->addAction(exportNoteAction);

importNoteAction = new QAction(tr("Import Notes"), this);
importNoteAction->setToolTip(tr("Import notes from an export file"));
importNoteAction->setFont(f);
connect(importNoteAction, SIGNAL(triggered()), parent, SLOT(noteImport()));
setupShortcut(importNoteAction, QString("File_Note_Import"));
fileMenu->addAction(importNoteAction);


fileMenu->addSeparator();
// Start adding the user accounts
QList<QString> names = global.accountsManager->nameList();
Expand Down
2 changes: 2 additions & 0 deletions gui/nmainmenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class NMainMenuBar : public QMenuBar
QAction *databaseStatusDialogAction;
QAction *reindexDatabaseAction;
QAction *restoreDatabaseAction;
QAction *backupDatabaseAction;
QAction *exportNoteAction;
QAction *importNoteAction;
QAction *accountDialogAction;
QAction *pauseIndexingAction;
Expand Down
83 changes: 81 additions & 2 deletions nixnote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "dialog/logindialog.h"
#include "xml/importdata.h"
#include "xml/importenex.h"
#include "xml/exportdata.h"
#include "dialog/aboutdialog.h"

extern Global global;
Expand Down Expand Up @@ -1232,6 +1233,85 @@ void NixNote::leftButtonTriggered() {
}


//**************************************************
// Import notes menu option chosen
//**************************************************
void NixNote::noteExport() {
databaseBackup(false);
}



//**************************************************
//* Backup (or export) notes
//**************************************************
void NixNote::databaseBackup(bool backup) {
QLOG_TRACE() << "Entering databaseBackup()";
ExportData noteReader(backup);

if (!backup) {
noteTableView->getSelectedLids(noteReader.lids);
if (noteReader.lids.size() == 0) {
QMessageBox::critical(this, tr("Error"), tr("No notes selected."));
return;
}
}

QFileDialog fd;
fd.setFileMode(QFileDialog::AnyFile);
fd.setConfirmOverwrite(true);
if (backup)
fd.setWindowTitle(tr("Backup Database"));
else
fd.setWindowTitle(tr("Export Notes"));
fd.setFilter(tr("NixNote Export (*.nnex);;All Files (*.*)"));
fd.setAcceptMode(QFileDialog::AcceptSave);
if (saveLastPath == "")
fd.setDirectory(QDir::homePath());
else
fd.setDirectory(saveLastPath);
if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
QLOG_DEBUG() << "Database restore canceled in file dialog.";
return;
}

waitCursor(true);
QStringList fileNames;
fileNames = fd.selectedFiles();
saveLastPath = fileNames[0];
int pos = saveLastPath.lastIndexOf("/");
if (pos > 0)
saveLastPath.truncate(pos);

if (backup)
setMessage(tr("Performing backup"));
else
setMessage(tr("Performing export"));

if (!fileNames[0].endsWith(".nnex")) {
fileNames[0].append(".nnex");
}
noteReader.backupData(fileNames[0]);

if (noteReader.lastError != 0) {
setMessage(noteReader.errorMessage);
QLOG_ERROR() << "Restore problem: " << noteReader.errorMessage;
QMessageBox::critical(this, tr("Error"), noteReader.errorMessage);
waitCursor(false);
return;
}


if (backup)
setMessage(tr("Database backup complete."));
else
setMessage(tr("Note extract complete."));

waitCursor(false);

}


//**************************************************
// Import notes menu option chosen
//**************************************************
Expand All @@ -1242,9 +1322,8 @@ void NixNote::noteImport() {


//**************************************************
//* Restore (or import) notest
//* Restore (or import) notes
//**************************************************

void NixNote::databaseRestore(bool fullRestore) {
QLOG_TRACE() << "Entering databaseRestore()";

Expand Down
2 changes: 2 additions & 0 deletions nixnote.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ public slots:
void rightButtonTriggered();
void openNote(bool newWindow);
void noteImport();
void noteExport();
void databaseRestore(bool fullRestore=true);
void databaseBackup(bool backup=true);
void resetView();
void newNote();
void newExternalNote();
Expand Down
14 changes: 14 additions & 0 deletions sql/notetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1988,3 +1988,17 @@ void NoteTable::pinNote(string guid, bool value) {
QString g(QString::fromStdString(guid));
pinNote(g, value);
}


// Get all lids
void NoteTable::getAll(QList<qint32> &lids) {
NSqlQuery query(*db);
lids.empty();
query.prepare("Select lid from DataStore where key=:guid");
query.bindValue(":guid", NOTE_GUID);
query.exec();
while(query.next()) {
lids.append(query.value(0).toInt());

}
}
1 change: 1 addition & 0 deletions sql/notetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class NoteTable
void getAllReminders(QList< QPair<qint32, qlonglong>* > *reminders); // Get all notes with un-completed reminders
qint32 getThumbnailsNeededCount();
qint32 addStub(QString noteGuid); // Add a stub. Used if a resource appears before the owning note
void getAll(QList<qint32> &lids);
};


Expand Down
13 changes: 12 additions & 1 deletion sql/searchtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ SearchTable::SearchTable(QSqlDatabase *db)



void SearchTable::getAll(QList<qint32> &lids) {
lids.empty();
NSqlQuery query(*db);
query.prepare("Select lid from datastore where key=:key");
query.bindValue(":key", SEARCH_GUID);
query.exec();
while (query.next()) {
lids.append(query.value(0).toInt());
}
}

// Given a record's name as a std::string, we return the lid
qint32 SearchTable::findByName(string &name) {
QLOG_TRACE() << "Entering SearchTable::findByName()";
Expand Down Expand Up @@ -382,7 +393,7 @@ bool SearchTable::isDeleted(qint32 lid) {
qint32 SearchTable::getAllDirty(QList<qint32> &lids) {
NSqlQuery query(*db);
lids.clear();
query.prepare("Select lid from DataStore where key=:key");
query.prepare("Select lid from DataStore where key=:key and data='true'");
query.bindValue(":key", SEARCH_ISDIRTY);
query.exec();
while(query.next()) {
Expand Down
1 change: 1 addition & 0 deletions sql/searchtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class SearchTable
bool isDeleted(qint32 lid);
void setUpdateSequenceNumber(qint32 lid, qint32 usn);
string getGuid(qint32 lid);
void getAll(QList<qint32> &lids);
};

#endif // SEARCHTABLE_H
2 changes: 1 addition & 1 deletion sql/tagtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ qint32 TagTable::findChildren(QList<qint32> &list, QString parentGuid) {
qint32 TagTable::getAllDirty(QList<qint32> &lids) {
NSqlQuery query(*db);
lids.clear();
query.prepare("Select lid from DataStore where key=:key");
query.prepare("Select lid from DataStore where key=:key and data='true'");
query.bindValue(":key", TAG_ISDIRTY);
query.exec();
while(query.next()) {
Expand Down
1 change: 0 additions & 1 deletion threads/indexrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ void IndexRunner::index() {
// Start indexing resources
if (keepRunning && resourceTable.getIndexNeeded(lids) > 0 && !pauseIndexing) {
endMsgNeeded = true;
QLOG_DEBUG() << "Unindexed Resources found: " << lids.size();

// Index each resource that is needed.
for (int i=0; i<lids.size() && keepRunning && !pauseIndexing; i++) {
Expand Down
Loading

0 comments on commit f18f1f0

Please sign in to comment.