1 #include "mainwindow.h"
2 #include "tmeditorwidget.h"
5 #include "httpserver.h"
8 #include "tmdatabase.h"
12 #include <QApplication>
13 #include <QStandardPaths>
15 #include <QDesktopServices>
18 #include <QLinkedList>
28 #define TM_DATABASE_VERSION 1
30 int main(int argc, char *argv[])
32 //SetDebugMemoryLeaks();
34 QApplication a(argc, argv);
36 a.setOrganizationName("wordring");
37 a.setApplicationName("tm");
39 QString path = QStandardPaths::writableLocation(
40 QStandardPaths::ConfigLocation) + "/settings.ini";
41 Settings settings(path, QSettings::IniFormat);
42 QString app_path = QCoreApplication::applicationDirPath();
50 remove = true; // 設定評価法が実装されるまで設定を常に消す。
52 // 設定ファイルのバージョンと違う場合、必要に応じてファイルや設定を消去する。
53 if(settings.value("Main/version", 0) != TM_VERSION)
55 settings.setValue("Main/version", TM_VERSION);
58 // DEBUG/RELEASEの違いで、必要に応じてファイルや設定を消去する。
59 if(debug != settings.value("Main/debug", false).toBool()) remove = true;
60 settings.setValue("Main/debug", debug);
65 QString mecab = QString(PROXYSRCDIR);
66 mecab += "/../third-party/lib/ipadic";
68 settings.setValue("Japanese/mecabdic", dir.absolutePath());
70 if(remove) settings.remove("Japanese/mecabdic");
71 if(!settings.contains("Japanese/mecabdic"))
73 QString mecabdic = app_path + "\\ipadic";
75 mecabdic = dir.absolutePath();
76 settings.setValue("Japanese/mecabdic", mecabdic);
82 if(remove) settings.remove("HttpServer/port");
83 if(!settings.contains("HttpServer/port"))
84 settings.setValue("HttpServer/port", 8080);
87 if(remove) settings.remove("SocketServer/port");
88 if(!settings.contains("SocketServer/port"))
89 settings.setValue("SocketServer/port", 8081);
92 if(remove) settings.remove("ProxyModule/prefix");
93 if(!settings.contains("ProxyModule/prefix"))
94 settings.setValue("ProxyModule/prefix", "/?u=");
98 settings.setValue("ProxyHandler/js_file", QString(PROXYSRCDIR) + "/tm-default.js");
99 settings.setValue("ProxyHandler/css_file", QString(PROXYSRCDIR) + "/tm-default.css");
101 if(remove) settings.remove("ProxyHandler/js_file");
102 if(!settings.contains("ProxyHandler/js_file"))
103 settings.setValue("ProxyHandler/js_file", app_path + "/tm-default.js");
104 if(remove) settings.remove("ProxyHandler/css_file");
105 if(!settings.contains("ProxyHandler/css_file"))
106 settings.setValue("ProxyHandler/css_file", app_path + "/tm-default.css");
110 settings.setValue("DefaultHtmlModule/file", QString(PROXYSRCDIR) + "/index.html");
112 if(remove) settings.remove("DefaultHtmlModule/file");
113 if(!settings.contains("DefaultHtmlModule/file"))
114 settings.setValue("DefaultHtmlModule/file", app_path + "/index.html");
117 if(remove) settings.remove("Database/root");
118 if(!settings.contains("Database/root"))
120 QString path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
122 path += QString::number(TM_DATABASE_VERSION);
123 settings.setValue("Database/root", path);
126 settings.setValue("WordringConnection/url", "ws://wordring.net/ws");
128 if(remove) settings.remove("WordringConnection/url");
129 if(!settings.contains("WordringConnection/url"))
130 settings.setValue("WordringConnection/url", "ws://wordring.net/ws");
132 TM::Service *service = new TM::Service(&settings, &a);
135 MainWindow w(&settings, service);
136 w.setFont(QFont("Meiryo"));
138 service->load_languages(QApplication::applicationDirPath() + "/plugins");
140 HttpServer *server = new HttpServer(&settings, &w);
141 w.set_http_port(server->port());
143 TM::SocketServer *socket = new TM::SocketServer(&settings, service, &w);
145 server->install(new TM::DefaultHtmlModule(&settings, server->port(), server));
146 server->install(new TM::ProxyModule(
147 &settings, server->port(), socket->port(), server));
149 QObject::connect(&w, SIGNAL(closing()), socket, SLOT(abort()));
151 int result = a.exec();