Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/fcitx/fcitxqtinputmethoditem.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2011~2012 by CSSlayer * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program; if not, write to the * | ||||
16 | * Free Software Foundation, Inc., * | ||||
17 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * | ||||
18 | ***************************************************************************/ | ||||
19 | | ||||
20 | // Qt | ||||
21 | #include <QDBusArgument> | ||||
22 | #include <QDBusMetaType> | ||||
23 | | ||||
24 | // self | ||||
25 | #include "fcitxqtinputmethoditem.h" | ||||
26 | | ||||
27 | bool FcitxQtInputMethodItem::enabled() const | ||||
28 | { | ||||
29 | return m_enabled; | ||||
30 | } | ||||
31 | | ||||
32 | QString FcitxQtInputMethodItem::saveName(QString uniqueName) | ||||
33 | { | ||||
34 | QString prefix = "fcitx-keyboard-"; | ||||
35 | if (uniqueName.startsWith(prefix)) { | ||||
36 | QString layoutName = uniqueName.right(uniqueName.size() - prefix.size()); | ||||
37 | QString layout = layoutName.section("-", 0, 0); | ||||
38 | QString variant = layoutName.section("-", 1); | ||||
39 | if (variant.isEmpty()) { | ||||
40 | return layout; | ||||
41 | } | ||||
42 | else { | ||||
43 | return QString("%1(%2)").arg(layout, variant); | ||||
44 | } | ||||
45 | } | ||||
46 | return "fcitx:" + uniqueName; | ||||
47 | } | ||||
48 | | ||||
49 | const QString& FcitxQtInputMethodItem::langCode() const | ||||
50 | { | ||||
51 | return m_langCode; | ||||
52 | } | ||||
53 | const QString& FcitxQtInputMethodItem::name() const | ||||
54 | { | ||||
55 | return m_name; | ||||
56 | } | ||||
57 | const QString& FcitxQtInputMethodItem::uniqueName() const | ||||
58 | { | ||||
59 | return m_uniqueName; | ||||
60 | } | ||||
61 | void FcitxQtInputMethodItem::setEnabled(bool enable) | ||||
62 | { | ||||
63 | m_enabled = enable; | ||||
64 | } | ||||
65 | void FcitxQtInputMethodItem::setLangCode(const QString& lang) | ||||
66 | { | ||||
67 | m_langCode = lang; | ||||
68 | } | ||||
69 | void FcitxQtInputMethodItem::setName(const QString& name) | ||||
70 | { | ||||
71 | m_name = name; | ||||
72 | } | ||||
73 | void FcitxQtInputMethodItem::setUniqueName(const QString& name) | ||||
74 | { | ||||
75 | m_uniqueName = name; | ||||
76 | } | ||||
77 | | ||||
78 | void FcitxQtInputMethodItem::registerMetaType() | ||||
79 | { | ||||
80 | qRegisterMetaType<FcitxQtInputMethodItem>("FcitxQtInputMethodItem"); | ||||
81 | qDBusRegisterMetaType<FcitxQtInputMethodItem>(); | ||||
82 | qRegisterMetaType<FcitxQtInputMethodItemList>("FcitxQtInputMethodItemList"); | ||||
83 | qDBusRegisterMetaType<FcitxQtInputMethodItemList>(); | ||||
84 | } | ||||
85 | | ||||
86 | FCITXQTDBUSADDONS_EXPORT | ||||
87 | QDBusArgument& operator<<(QDBusArgument& argument, const FcitxQtInputMethodItem& im) | ||||
88 | { | ||||
89 | argument.beginStructure(); | ||||
90 | argument << im.name(); | ||||
91 | argument << im.uniqueName(); | ||||
92 | argument << im.langCode(); | ||||
93 | argument << im.enabled(); | ||||
94 | argument.endStructure(); | ||||
95 | return argument; | ||||
96 | } | ||||
97 | | ||||
98 | FCITXQTDBUSADDONS_EXPORT | ||||
99 | const QDBusArgument& operator>>(const QDBusArgument& argument, FcitxQtInputMethodItem& im) | ||||
100 | { | ||||
101 | QString name; | ||||
102 | QString uniqueName; | ||||
103 | QString langCode; | ||||
104 | bool enabled; | ||||
105 | argument.beginStructure(); | ||||
106 | argument >> name >> uniqueName >> langCode >> enabled; | ||||
107 | argument.endStructure(); | ||||
108 | im.setName(name); | ||||
109 | im.setUniqueName(uniqueName); | ||||
110 | im.setLangCode(langCode); | ||||
111 | im.setEnabled(enabled); | ||||
112 | return argument; | ||||
113 | } |