-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.cpp
executable file
·135 lines (121 loc) · 4.96 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <QtGui/QApplication>
#include <QtDeclarative>
#include "qmlapplicationviewer.h"
#include "backend/trace.h"
#include "backend/preferences.h"
#include "backend/contentitem.h"
#include "backend/book.h"
#include "backend/bookmark.h"
#include "backend/bookdb.h"
#include "backend/library.h"
#include "backend/coverprovider.h"
#include "backend/bookfinder.h"
#include "backend/platform.h"
#include "backend/mediakey.h"
#include "backend/qdeclarativewebview_p.h"
#if defined(Q_OS_SYMBIAN)
#include "backend/iap.h"
#endif
int main(int argc, char *argv[]) {
// Set up application
QScopedPointer<QApplication> app(createApplication(argc, argv));
app->setApplicationName("Ionic");
app->setApplicationVersion(Platform::instance()->version());
app->setOrganizationDomain("pipacs.com");
app->setOrganizationName("pipacs.com");
// Set up tracing
Preferences *settings = Preferences::instance();
Trace::level = (QtMsgType)settings->value("tracelevel", (int)QtDebugMsg).toInt();
Trace::setFileName(settings->value("tracefilename").toString());
qInstallMsgHandler(Trace::messageHandler);
qDebug() << "Ionic version " << Platform::instance()->version();
// Register QML types
qmlRegisterType<Bookmark>("com.pipacs.ionic.Bookmark", 1, 0, "Bookmark");
qmlRegisterType<Book>("com.pipacs.ionic.Book", 1, 0, "Book");
qmlRegisterType<Library>("com.pipacs.ionic.Library", 1, 0, "Library");
qmlRegisterType<Preferences>("com.pipacs.ionic.Preferences", 1, 0, "Preferences");
#if defined(Q_OS_SYMBIAN)
qmlRegisterType<IapItem>("com.pipacs.ionic.IapItem", 1, 0, "IapItem");
#endif
qmlRegisterType<QDeclarativeWebSettings>();
qmlRegisterType<QDeclarativeWebView>("com.pipacs.ionic.IWebView", 1, 0, "IWebView");
// Do book database management in a separate thread
QThread *bookDbWorkerThread = new QThread;
BookDb::instance()->worker()->moveToThread(bookDbWorkerThread);
bookDbWorkerThread->start(QThread::LowestPriority);
// Initialize library, load book from command line, or the last book, or the default book
Library *library = Library::instance();
library->load();
Book *current;
if (argc > 1) {
qDebug() << argv[1];
current = library->find(argv[1]);
if (!current) {
current = library->add(argv[1]);
}
if (current) {
library->setNowReading(current);
}
}
current = library->nowReading();
if (!current->isValid()) {
if (!library->bookCount()) {
library->add(":/books/2BR02B.epub");
}
library->setNowReading(library->book(0));
}
// Do book import in a separate thread
BookFinder *bookFinder = new BookFinder;
BookFinderWorker *bookFinderWorker = new BookFinderWorker;
QThread *bookFinderWorkerThread = new QThread;
bookFinderWorker->moveToThread(bookFinderWorkerThread);
bookFinder->connect(bookFinder, SIGNAL(findRequested()), bookFinderWorker, SLOT(doFind()));
bookFinderWorker->connect(bookFinderWorker, SIGNAL(begin(int)), bookFinder, SIGNAL(begin(int)));
bookFinderWorker->connect(bookFinderWorker, SIGNAL(add(QString)), bookFinder, SIGNAL(add(QString)));
bookFinderWorker->connect(bookFinderWorker, SIGNAL(done(int)), bookFinder, SIGNAL(done(int)));
bookFinderWorkerThread->start(QThread::LowestPriority);
// Set up and show QML widget with main.qml
QmlApplicationViewer *viewer = new QmlApplicationViewer;
MediaKey *mediaKey = new MediaKey(viewer);
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer->engine()->addImageProvider(QString("covers"), new CoverProvider);
viewer->rootContext()->setContextProperty("library", library);
viewer->rootContext()->setContextProperty("prefs", settings);
Book *emptyBook = new Book();
viewer->rootContext()->setContextProperty("emptyBook", emptyBook);
viewer->rootContext()->setContextProperty("bookFinder", bookFinder);
viewer->rootContext()->setContextProperty("platform", Platform::instance());
viewer->rootContext()->setContextProperty("mediaKey", mediaKey);
#if defined(Q_OS_SYMBIAN)
Iap *iap = new Iap(viewer);
viewer->rootContext()->setContextProperty("iap", iap);
#endif
#if defined(Q_OS_SYMBIAN)
viewer->setSource(QUrl("qrc:/qml/main-symbian.qml"));
#else
viewer->setSource(QUrl("qrc:/qml/main.qml"));
#endif
viewer->showExpanded();
#if defined(MEEGO_EDITION_HARMATTAN)
// Install event filter to capture/release volume keys
viewer->installEventFilter(mediaKey);
#endif
// Run application
int ret = app->exec();
// Delete singletons
delete viewer;
bookFinderWorkerThread->quit();
bookFinderWorkerThread->wait();
delete bookFinderWorkerThread;
delete bookFinderWorker;
delete bookFinder;
delete emptyBook;
Library::close();
bookDbWorkerThread->quit();
bookDbWorkerThread->wait();
delete bookDbWorkerThread;
BookDb::close();
Preferences::close();
Platform::close();
return ret;
}