File: main.cpp

package info (click to toggle)
fcitx5-configtool 5.1.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,512 kB
  • sloc: cpp: 9,083; javascript: 31; makefile: 3; sh: 2
file content (69 lines) | stat: -rw-r--r-- 2,014 bytes parent folder | download
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
/*
 * SPDX-FileCopyrightText: 2011~2011 CSSlayer <wengxt@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 */

#include "config.h"
#include "keyboardlayoutwidget.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QMainWindow>
#include <QMessageBox>
#include <fcitx-utils/i18n.h>

int main(int argc, char *argv[]) {
    qputenv("QT_QPA_PLATFORM", "xcb");

    QApplication app(argc, argv);
    app.setApplicationName(QLatin1String("kbd-layout-viewer"));
    app.setApplicationVersion(QLatin1String(PROJECT_VERSION));

    if (app.platformName() != "xcb") {
        QMessageBox msgBox(QMessageBox::Critical, _("Error"),
                           _("This program only works on X11."));
        msgBox.exec();
        return 1;
    }

    QCommandLineParser parser;
    parser.setApplicationDescription(_("A general keyboard layout viewer"));
    parser.addHelpOption();
    parser.addOptions(
        {{{"g", "group"}, _("Keyboard layout <group> (0-3)"), _("group")},
         {{"l", "layout"}, _("Keyboard <layout>"), _("layout")},
         {{"v", "variant"}, _("Keyboard layout <variant>"), _("variant")}});

    parser.process(app);

    int group = -1;
    QString variant, layout;
    if (parser.isSet("group")) {
        group = parser.value("group").toInt();
    }
    if (parser.isSet("layout")) {
        layout = parser.value("layout");
    }
    if (parser.isSet("variant")) {
        variant = parser.value("variant");
    }

    QMainWindow mainWindow;
    mainWindow.setWindowIcon(QIcon::fromTheme("input-keyboard"));
    mainWindow.setWindowTitle(_("Keyboard Layout viewer"));
    mainWindow.setMinimumSize(QSize(900, 400));
    fcitx::kcm::KeyboardLayoutWidget widget;
    if (group > 0 || layout.isNull()) {
        if (group < 0)
            group = 0;
        widget.setGroup(group);
    } else if (!layout.isNull()) {
        widget.setKeyboardLayout(layout, variant);
    }

    mainWindow.setCentralWidget(&widget);
    mainWindow.show();

    return app.exec();
}