OSDN Git Service

Editorのデータ構造変更前、一時保存。
[wordring-tm/wordring-tm.git] / proxy / main.cpp
1 #include "mainwindow.h"
2 #include "tmeditorwidget.h"
3
4 #include "tmsocket.h"
5 #include "httpserver.h"
6 #include "tmhttp.h"
7 #include "tmservice.h"
8 #include "tmdatabase.h"
9
10 #include "settings.h"
11
12 #include <QApplication>
13
14 #include <QDesktopServices>
15 #include <QSettings>
16
17 #include <QLinkedList>
18 #include <QFont>
19 #include <QDir>
20
21 #include "debug.h"
22
23 int main(int argc, char *argv[])
24 {
25         SetDebugMemoryLeaks();
26         QApplication a(argc, argv);
27
28         a.setOrganizationName("Wordring");
29         a.setApplicationName("TM");
30
31         QString path = QStandardPaths::writableLocation(
32                                         QStandardPaths::ConfigLocation) + "/settings.ini";
33         Settings settings(path, QSettings::IniFormat);
34         //QString apppath = QCoreApplication::applicationDirPath();
35
36         // Language
37         if(!settings.contains("Japanese/mecabdic"))
38         {
39                 QString mecabdic(PROXYSRCDIR);
40                 mecabdic.append("/../third-party/lib/ipadic");
41                 QDir dir(mecabdic);
42                 mecabdic = dir.absolutePath();
43                 settings.setValue("Japanese/mecabdic", mecabdic);
44         }
45
46         // HttpServer
47         if(!settings.contains("HttpServer/port")) settings.setValue("HttpServer/port", 8080);
48         // SocketServer
49         if(!settings.contains("SocketServer/port")) settings.setValue("SocketServer/port", 8081);
50         // ProxyModule
51         if(!settings.contains("ProxyModule/prefix")) settings.setValue("ProxyModule/prefix", "/?");
52         // ProxyHandler
53         if(!settings.contains("ProxyHandler/jscode"))
54                 settings.setValue("ProxyHandler/jscode", QString(PROXYSRCDIR) + "/tm.js");
55
56         // Database
57         if(!settings.contains("Database/root"))
58         {
59                 QString path = QStandardPaths::writableLocation(
60                                         QStandardPaths::CacheLocation);
61                 settings.setValue("Database/root", path);
62         }
63
64         TM::Service *service = new TM::Service(&settings, &a);
65         MainWindow w(&settings, service);
66         w.setFont(QFont("Meiryo", 10.5));
67         service->load_languages(QApplication::applicationDirPath() + "/plugins");
68
69         HttpServer *server = new HttpServer(&settings, &w);
70         w.set_http_port(server->port());
71
72         TM::SocketServer *socket = new TM::SocketServer(&settings, service, w.editor_widget(), &w);
73
74         server->install(new TM::ProxyModule(
75                                                 &settings, server->port(), socket->port(), server));
76
77         QObject::connect(&w, SIGNAL(closing()), socket, SLOT(abort()));
78         w.show();
79         int result = a.exec();
80
81         return result;
82 }