OSDN Git Service

1d90a0d647d32d4213b014af9fa958db42e64516
[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 #include <QStandardPaths>
14
15 #include <QDesktopServices>
16 #include <QSettings>
17
18 #include <QLinkedList>
19 #include <QFont>
20 #include <QDir>
21
22 #include "debug.h"
23
24 int main(int argc, char *argv[])
25 {
26         SetDebugMemoryLeaks();
27         QApplication a(argc, argv);
28
29         a.setOrganizationName("wordring");
30         a.setApplicationName("tm");
31
32         QString path = QStandardPaths::writableLocation(
33                                         QStandardPaths::ConfigLocation) + "/settings.ini";
34         Settings settings(path, QSettings::IniFormat);
35         QString app_path = QCoreApplication::applicationDirPath();
36
37         // Language
38 #ifdef QT_DEBUG
39         settings.setValue(
40                 "Japanese/mecabdic", QString(PROXYSRCDIR) + "/../third-party/lib/ipadic");
41 #else
42         if(!settings.contains("Japanese/mecabdic"))
43         {
44                 QString mecabdic = app_path + "/ipadic";
45                 QDir dir(mecabdic);
46                 mecabdic = dir.absolutePath();
47                 settings.setValue("Japanese/mecabdic", mecabdic);
48         }
49 #endif
50         // HttpServer
51         if(!settings.contains("HttpServer/port")) settings.setValue("HttpServer/port", 8080);
52         // SocketServer
53         if(!settings.contains("SocketServer/port")) settings.setValue("SocketServer/port", 8081);
54         // ProxyModule
55         if(!settings.contains("ProxyModule/prefix")) settings.setValue("ProxyModule/prefix", "/?");
56         // ProxyHandler
57 #ifdef QT_DEBUG
58         settings.setValue("ProxyHandler/jscode", QString(PROXYSRCDIR) + "/tm.js");
59 #else
60         if(!settings.contains("ProxyHandler/jscode"))
61                 settings.setValue("ProxyHandler/jscode", app_path + "/tm.js");
62 #endif
63         // DefaultHtmlModule
64 #ifdef QT_DEBUG
65         settings.setValue("DefaultHtmlModule/file", QString(PROXYSRCDIR) + "/index.html");
66 #else
67         if(!settings.contains("DefaultHtmlModule/file"))
68                 settings.setValue("DefaultHtmlModule/file", app_path + "/index.html");
69 #endif
70         // Database
71         if(!settings.contains("Database/root"))
72         {
73                 QString path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
74                 settings.setValue("Database/root", path);
75         }
76 //#ifdef QT_DEBUG
77         settings.setValue("WordringConnection/url", "ws://localhost:82/ws/tm");
78 //#else
79 //      if(!settings.contains("WordringConnection/url"))
80 //              settings.setValue("WordringConnection/url", "ws://tm.wordring.net:80/");
81 //#endif
82         TM::Service *service = new TM::Service(&settings, &a);
83         MainWindow w(&settings, service);
84         w.setFont(QFont("Meiryo", 10.5));
85         service->load_languages(QApplication::applicationDirPath() + "/plugins");
86
87         HttpServer *server = new HttpServer(&settings, &w);
88         w.set_http_port(server->port());
89
90         TM::SocketServer *socket = new TM::SocketServer(&settings, service, w.editor_widget(), &w);
91
92         server->install(new TM::DefaultHtmlModule(&settings, server->port(), server));
93         server->install(new TM::ProxyModule(
94                                                 &settings, server->port(), socket->port(), server));
95
96         QObject::connect(&w, SIGNAL(closing()), socket, SLOT(abort()));
97         w.show();
98         int result = a.exec();
99         delete service;
100
101         return result;
102 }