File: wrapperapp.cpp

package info (click to toggle)
fcitx-qt5 1.2.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 940 kB
  • sloc: cpp: 6,202; xml: 340; makefile: 12; sh: 4
file content (73 lines) | stat: -rw-r--r-- 3,092 bytes parent folder | download | duplicates (4)
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
/***************************************************************************
 *   Copyright (C) 2012~2012 by CSSlayer                                   *
 *   wengxt@gmail.com                                                      *
 *   Copyright (C) 2017~2017 by xzhao                                      *
 *   i@xuzhao.net                                                          *
 *                                                                         *
 *  This program is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU General Public License as published by   *
 *  the Free Software Foundation, either version 3 of the License, or      *
 *  (at your option) any later version.                                    *
 *                                                                         *
 *  This program is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *  You should have received a copy of the GNU General Public License      *
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 *                                                                         *
 ***************************************************************************/

#include <libintl.h>
#include <locale.h>

#include <QDebug>

#include "fcitx-utils/utils.h"
#include "fcitxqtconfiguifactory.h"
#include "fcitxqtconnection.h"
#include "mainwindow.h"
#include "wrapperapp.h"

WrapperApp::WrapperApp(int &argc, char **argv)
    : QApplication(argc, argv), m_factory(new FcitxQtConfigUIFactory(this)),
      m_mainWindow(0) {
    char *localedir = fcitx_utils_get_fcitx_path("localedir");
    setlocale(LC_ALL, "");
    bindtextdomain("fcitx", localedir);
    bindtextdomain("fcitx-qt5", localedir);
    free(localedir);
    bind_textdomain_codeset("fcitx", "UTF-8");
    bind_textdomain_codeset("fcitx-qt5", "UTF-8");
    textdomain("fcitx");

    FcitxQtConfigUIWidget *widget = 0;

    if (argc == 3 && strcmp(argv[1], "--test") == 0) {
        if (m_factory->test(QString::fromLocal8Bit(argv[2]))) {
            QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
        } else {
            QMetaObject::invokeMethod(this, "errorExit", Qt::QueuedConnection);
        }
    } else {
        if (argc == 2) {
            widget = m_factory->create(QString::fromLocal8Bit(argv[1]));
        }
        if (!widget) {
            qWarning("Could not find plugin for file.");
            QMetaObject::invokeMethod(this, "errorExit", Qt::QueuedConnection);
        } else {
            m_mainWindow = new MainWindow(widget);
            m_mainWindow->show();
        }
    }
}

WrapperApp::~WrapperApp() {
    if (m_mainWindow) {
        delete m_mainWindow;
    }
}

void WrapperApp::errorExit() { exit(1); }