diff --git a/html/enmlformatter.cpp b/html/enmlformatter.cpp
index 7abcc063..dcde4e97 100644
--- a/html/enmlformatter.cpp
+++ b/html/enmlformatter.cpp
@@ -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();
@@ -263,6 +264,7 @@ QByteArray EnmlFormatter::rebuildNoteEnml() {
}
}
+ QLOG_DEBUG() << "After tidy";
content.clear();
content.append(tidyProcess.readAllStandardOutput());
tidyProcess.close();
diff --git a/main.cpp b/main.cpp
index 508acad0..ca7e350d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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
@@ -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())
diff --git a/nixnote.cpp b/nixnote.cpp
index ca98a416..d1c00f33 100644
--- a/nixnote.cpp
+++ b/nixnote.cpp
@@ -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());
@@ -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";
}
diff --git a/nixnote.h b/nixnote.h
index deae4207..dd697729 100644
--- a/nixnote.h
+++ b/nixnote.h
@@ -305,6 +305,7 @@ public slots:
void indexFinished(bool finished);
void exportAsPdf();
void exportAsPdfReady(bool);
+ void saveOnExit();
signals:
void syncRequested();