Fix sorting of library. Add basic search framework.
[dorian] / main.cpp
index c1b25ce..5977925 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,12 +1,13 @@
-#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
-#include <unistd.h>
-#endif
-
 #include <QtGui/QApplication>
 
 #include "mainwindow.h"
 #include "trace.h"
 #include "settings.h"
+#include "library.h"
+#include "settings.h"
+#include "bookdb.h"
+#include "search.h"
+#include "platform.h"
 
 static const char *DORIAN_VERSION =
 #include "pkg/version.txt"
@@ -23,6 +24,7 @@ static const QtMsgType DORIAN_DEFAULT_TRACE_LEVEL =
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
+    int ret;
 
     a.setApplicationName("Dorian");
     a.setApplicationVersion(DORIAN_VERSION);
@@ -33,22 +35,21 @@ int main(int argc, char *argv[])
         value("tracelevel", (int)DORIAN_DEFAULT_TRACE_LEVEL).toInt();
     qInstallMsgHandler(Trace::messageHandler);
 
-    MainWindow w;
-    w.show();
-
-#if 0 // FIXME #ifdef Q_OS_SYMBIAN
-    // Remove context menu from all widgets
-    foreach (QWidget *w, QApplication::allWidgets()) {
-        w->setContextMenuPolicy(Qt::NoContextMenu);
+    {
+        MainWindow w;
+        w.show();
+        ret = a.exec();
     }
-#endif // Q_OS_SYMBIAN
 
-    int ret = a.exec();
+    // Release singletons
+    Library::close();
+    BookDb::close();
+    Settings::close();
+    Search::close();
+
+    // Re-start application if event loop exit code was 1000
     if (ret == 1000) {
-#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
-        extern char **environ;
-        execve(argv[0], argv, environ);
-#endif
+        Platform::restart(argv);
     }
     return ret;
 }