Skip to content

Commit

Permalink
Add aboutToQuit() listener to try and catch people who don't shut dow…
Browse files Browse the repository at this point in the history
…n cleanly.
  • Loading branch information
baumgarr committed Feb 22, 2017
1 parent 00027b3 commit 711ab3e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 24 deletions.
2 changes: 2 additions & 0 deletions html/enmlformatter.cpp
Expand Up @@ -240,6 +240,7 @@ QByteArray EnmlFormatter::rebuildNoteEnml() {
// Run it through "tidy". It is a program which will fix any invalid HTML
// and give us the results back through stdout. In a perfect world this
// wouldn't be needed, but WebKit doesn't always give back good HTML.
QLOG_DEBUG() << "Calling tidy";
QProcess tidyProcess;
tidyProcess.start("tidy -raw -asxhtml -q -m -u -utf8 ", QIODevice::ReadWrite|QIODevice::Unbuffered);
QLOG_DEBUG() << "Starting tidy " << tidyProcess.waitForStarted();
Expand All @@ -263,6 +264,7 @@ QByteArray EnmlFormatter::rebuildNoteEnml() {
}
}

QLOG_DEBUG() << "After tidy";
content.clear();
content.append(tidyProcess.readAllStandardOutput());
tidyProcess.close();
Expand Down
19 changes: 19 additions & 0 deletions main.cpp
Expand Up @@ -71,6 +71,21 @@ void fault_handler(int sig) {
exit(1);
}



void shutdown_handler(int sig) {
void *array[30];
size_t size;

// get void*'s for all entries on the stack
size = backtrace(array, 30);

// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, 2);
return;
}

#endif // End Windows check


Expand Down Expand Up @@ -265,6 +280,10 @@ int main(int argc, char *argv[])
QNetworkProxy::setApplicationProxy(proxy);
}

QLOG_DEBUG() << "Setting up exit signal";

QObject::connect(a, SIGNAL(aboutToQuit()), w, SLOT(saveOnExit()));

QLOG_DEBUG() << "Launching";
int rc = a->exec();
if (global.sharedMemory->isAttached())
Expand Down
64 changes: 40 additions & 24 deletions nixnote.cpp
Expand Up @@ -1119,39 +1119,23 @@ void NixNote::closeShortcut() {
}



//*****************************************************************************
//* Close the program
//*****************************************************************************
void NixNote::closeEvent(QCloseEvent *event) {
// if (closeToTray && !closeFlag) {
// event->ignore();
// hide();
// return;
// }
//* Save program contents on exit
//******************************************************************************
void NixNote::saveOnExit() {
QLOG_DEBUG() << "saveOnExit called";

QLOG_DEBUG() << "Saving contents";
saveContents();

QLOG_DEBUG() << "Shutting down threads";
indexRunner.keepRunning = false;
counterRunner.keepRunning = false;
indexThread.quit();
counterThread.quit();

global.settings->beginGroup("Sync");
bool syncOnShutdown = global.settings->value("syncOnShutdown", false).toBool();
global.settings->endGroup();
if (syncOnShutdown && !finalSync && global.accountsManager->oauthTokenFound()) {
finalSync = true;
syncRunner.finalSync = true;
hide();
connect(&syncRunner, SIGNAL(syncComplete()), this, SLOT(close()));
synchronize();
event->ignore();
return;
}

syncRunner.keepRunning = false;
syncThread.quit();

QLOG_DEBUG() << "Saving window states";
ConfigStore config(global.db);
config.saveSetting(CONFIG_STORE_WINDOW_STATE, saveState());
config.saveSetting(CONFIG_STORE_WINDOW_GEOMETRY, saveGeometry());
Expand Down Expand Up @@ -1260,10 +1244,42 @@ void NixNote::closeEvent(QCloseEvent *event) {
saveNoteColumnWidths();
saveNoteColumnPositions();
noteTableView->saveColumnsVisible();
QLOG_DEBUG() << "Exitng saveOnExit()";
}

//*****************************************************************************
//* Close the program
//*****************************************************************************
void NixNote::closeEvent(QCloseEvent *event) {
// if (closeToTray && !closeFlag) {
// event->ignore();
// hide();
// return;
// }

saveOnExit();

global.settings->beginGroup("Sync");
bool syncOnShutdown = global.settings->value("syncOnShutdown", false).toBool();
global.settings->endGroup();
if (syncOnShutdown && !finalSync && global.accountsManager->oauthTokenFound()) {
finalSync = true;
syncRunner.finalSync = true;
hide();
connect(&syncRunner, SIGNAL(syncComplete()), this, SLOT(close()));
synchronize();
event->ignore();
return;
}

syncRunner.keepRunning = false;
syncThread.quit();

if (trayIcon->isVisible())
trayIcon->hide();
if (trayIcon != NULL)
delete trayIcon;

QMainWindow::closeEvent(event);
QLOG_DEBUG() << "Quitting";
}
Expand Down
1 change: 1 addition & 0 deletions nixnote.h
Expand Up @@ -305,6 +305,7 @@ public slots:
void indexFinished(bool finished);
void exportAsPdf();
void exportAsPdfReady(bool);
void saveOnExit();

signals:
void syncRequested();
Expand Down

0 comments on commit 711ab3e

Please sign in to comment.