Debian Codegraph @

qt5/guiwrapper/wrapperapp.cpp

raw
1 /***************************************************************************
2 * Copyright (C) 2012~2012 by CSSlayer *
3 * [email protected] *
4 * Copyright (C) 2017~2017 by xzhao *
5 * [email protected] *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21
22 #include <libintl.h>
23 #include <locale.h>
24
25 #include <QDebug>
26
27 #include "fcitx-utils/utils.h"
28 #include "fcitxqtconfiguifactory.h"
29 #include "fcitxqtconnection.h"
30 #include "mainwindow.h"
31 #include "wrapperapp.h"
32
33 WrapperApp::WrapperApp(int &argc, char **argv)
34 : QApplication(argc, argv), m_factory(new FcitxQtConfigUIFactory(this)),
35 m_mainWindow(0) {
36 char *localedir = fcitx_utils_get_fcitx_path("localedir");
37 setlocale(LC_ALL, "");
38 bindtextdomain("fcitx", localedir);
39 bindtextdomain("fcitx-qt5", localedir);
40 free(localedir);
41 bind_textdomain_codeset("fcitx", "UTF-8");
42 bind_textdomain_codeset("fcitx-qt5", "UTF-8");
43 textdomain("fcitx");
44
45 FcitxQtConfigUIWidget *widget = 0;
46
47 if (argc == 3 && strcmp(argv[1], "--test") == 0) {
48 if (m_factory->test(QString::fromLocal8Bit(argv[2]))) {
49 QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
50 } else {
51 QMetaObject::invokeMethod(this, "errorExit", Qt::QueuedConnection);
52 }
53 } else {
54 if (argc == 2) {
55 widget = m_factory->create(QString::fromLocal8Bit(argv[1]));
56 }
57 if (!widget) {
58 qWarning("Could not find plugin for file.");
59 QMetaObject::invokeMethod(this, "errorExit", Qt::QueuedConnection);
60 } else {
61 m_mainWindow = new MainWindow(widget);
62 m_mainWindow->show();
63 }
64 }
65 }
66
67 WrapperApp::~WrapperApp() {
68 if (m_mainWindow) {
69 delete m_mainWindow;
70 }
71 }
72
73 void WrapperApp::errorExit() { exit(1); }