| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2012~2017 CSSlayer <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <QDBusMetaType> |
| 9 |
|
| 10 |
#include "fcitxqtdbustypes.h" |
| 11 |
|
| 12 |
namespace fcitx { |
| 13 |
|
| 14 |
#define FCITX5_QT_DEFINE_DBUS_TYPE(TYPE) \ |
| 15 |
qRegisterMetaType<TYPE>(#TYPE); \ |
| 16 |
qDBusRegisterMetaType<TYPE>(); \ |
| 17 |
qRegisterMetaType<TYPE##List>(#TYPE "List"); \ |
| 18 |
qDBusRegisterMetaType<TYPE##List>(); |
| 19 |
|
| 20 |
void registerFcitxQtDBusTypes() { |
| 21 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtFormattedPreedit); |
| 22 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtStringKeyValue); |
| 23 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtInputMethodEntry); |
| 24 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtLayoutInfo); |
| 25 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtVariantInfo); |
| 26 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtConfigOption); |
| 27 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtConfigType); |
| 28 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtAddonInfo); |
| 29 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtAddonState); |
| 30 |
FCITX5_QT_DEFINE_DBUS_TYPE(FcitxQtAddonInfoV2); |
| 31 |
} |
| 32 |
|
| 33 |
bool FcitxQtFormattedPreedit::operator==( |
| 34 |
const FcitxQtFormattedPreedit &preedit) const { |
| 35 |
return (preedit.format_ == format_) && (preedit.string_ == string_); |
| 36 |
} |
| 37 |
|
| 38 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 39 |
const FcitxQtFormattedPreedit &preedit) { |
| 40 |
argument.beginStructure(); |
| 41 |
argument << preedit.string(); |
| 42 |
argument << preedit.format(); |
| 43 |
argument.endStructure(); |
| 44 |
return argument; |
| 45 |
} |
| 46 |
|
| 47 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 48 |
FcitxQtFormattedPreedit &preedit) { |
| 49 |
QString str; |
| 50 |
qint32 format; |
| 51 |
argument.beginStructure(); |
| 52 |
argument >> str >> format; |
| 53 |
argument.endStructure(); |
| 54 |
preedit.setString(str); |
| 55 |
preedit.setFormat(format); |
| 56 |
return argument; |
| 57 |
} |
| 58 |
|
| 59 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 60 |
const FcitxQtStringKeyValue &arg) { |
| 61 |
argument.beginStructure(); |
| 62 |
argument << arg.key(); |
| 63 |
argument << arg.value(); |
| 64 |
argument.endStructure(); |
| 65 |
return argument; |
| 66 |
} |
| 67 |
|
| 68 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 69 |
FcitxQtStringKeyValue &arg) { |
| 70 |
QString key, value; |
| 71 |
argument.beginStructure(); |
| 72 |
argument >> key >> value; |
| 73 |
argument.endStructure(); |
| 74 |
arg.setKey(key); |
| 75 |
arg.setValue(value); |
| 76 |
return argument; |
| 77 |
} |
| 78 |
|
| 79 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 80 |
const FcitxQtInputMethodEntry &arg) { |
| 81 |
argument.beginStructure(); |
| 82 |
argument << arg.uniqueName(); |
| 83 |
argument << arg.name(); |
| 84 |
argument << arg.nativeName(); |
| 85 |
argument << arg.icon(); |
| 86 |
argument << arg.label(); |
| 87 |
argument << arg.languageCode(); |
| 88 |
argument << arg.configurable(); |
| 89 |
argument.endStructure(); |
| 90 |
return argument; |
| 91 |
} |
| 92 |
|
| 93 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 94 |
FcitxQtInputMethodEntry &arg) { |
| 95 |
QString uniqueName, name, nativeName, icon, label, languageCode; |
| 96 |
bool configurable; |
| 97 |
argument.beginStructure(); |
| 98 |
argument >> uniqueName >> name >> nativeName >> icon >> label >> |
| 99 |
languageCode >> configurable; |
| 100 |
argument.endStructure(); |
| 101 |
arg.setUniqueName(uniqueName); |
| 102 |
arg.setName(name); |
| 103 |
arg.setNativeName(nativeName); |
| 104 |
arg.setIcon(icon); |
| 105 |
arg.setLabel(label); |
| 106 |
arg.setLanguageCode(languageCode); |
| 107 |
arg.setConfigurable(configurable); |
| 108 |
return argument; |
| 109 |
} |
| 110 |
|
| 111 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 112 |
const FcitxQtVariantInfo &arg) { |
| 113 |
argument.beginStructure(); |
| 114 |
argument << arg.variant(); |
| 115 |
argument << arg.description(); |
| 116 |
argument << arg.languages(); |
| 117 |
argument.endStructure(); |
| 118 |
return argument; |
| 119 |
} |
| 120 |
|
| 121 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 122 |
FcitxQtVariantInfo &arg) { |
| 123 |
QString variant, description; |
| 124 |
QStringList languages; |
| 125 |
argument.beginStructure(); |
| 126 |
argument >> variant >> description >> languages; |
| 127 |
argument.endStructure(); |
| 128 |
arg.setVariant(variant); |
| 129 |
arg.setDescription(description); |
| 130 |
arg.setLanguages(languages); |
| 131 |
return argument; |
| 132 |
} |
| 133 |
|
| 134 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 135 |
const FcitxQtLayoutInfo &arg) { |
| 136 |
argument.beginStructure(); |
| 137 |
argument << arg.layout(); |
| 138 |
argument << arg.description(); |
| 139 |
argument << arg.languages(); |
| 140 |
argument << arg.variants(); |
| 141 |
argument.endStructure(); |
| 142 |
return argument; |
| 143 |
} |
| 144 |
|
| 145 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 146 |
FcitxQtLayoutInfo &arg) { |
| 147 |
QString layout, description; |
| 148 |
QStringList languages; |
| 149 |
FcitxQtVariantInfoList variants; |
| 150 |
argument.beginStructure(); |
| 151 |
argument >> layout >> description >> languages >> variants; |
| 152 |
argument.endStructure(); |
| 153 |
arg.setLayout(layout); |
| 154 |
arg.setDescription(description); |
| 155 |
arg.setLanguages(languages); |
| 156 |
arg.setVariants(variants); |
| 157 |
return argument; |
| 158 |
} |
| 159 |
|
| 160 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 161 |
const FcitxQtConfigOption &arg) { |
| 162 |
argument.beginStructure(); |
| 163 |
argument << arg.name(); |
| 164 |
argument << arg.type(); |
| 165 |
argument << arg.description(); |
| 166 |
argument << arg.defaultValue(); |
| 167 |
argument << arg.properties(); |
| 168 |
argument.endStructure(); |
| 169 |
return argument; |
| 170 |
} |
| 171 |
|
| 172 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 173 |
FcitxQtConfigOption &arg) { |
| 174 |
QString name, description, type; |
| 175 |
QDBusVariant defaultValue; |
| 176 |
QVariantMap properties; |
| 177 |
argument.beginStructure(); |
| 178 |
argument >> name >> type >> description >> defaultValue >> properties; |
| 179 |
argument.endStructure(); |
| 180 |
arg.setName(name); |
| 181 |
arg.setType(type); |
| 182 |
arg.setDescription(description); |
| 183 |
arg.setDefaultValue(defaultValue); |
| 184 |
arg.setProperties(properties); |
| 185 |
return argument; |
| 186 |
} |
| 187 |
|
| 188 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 189 |
const FcitxQtConfigType &arg) { |
| 190 |
argument.beginStructure(); |
| 191 |
argument << arg.name(); |
| 192 |
argument << arg.options(); |
| 193 |
argument.endStructure(); |
| 194 |
return argument; |
| 195 |
} |
| 196 |
|
| 197 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 198 |
FcitxQtConfigType &arg) { |
| 199 |
QString name; |
| 200 |
FcitxQtConfigOptionList options; |
| 201 |
argument.beginStructure(); |
| 202 |
argument >> name >> options; |
| 203 |
argument.endStructure(); |
| 204 |
arg.setName(name); |
| 205 |
arg.setOptions(options); |
| 206 |
return argument; |
| 207 |
} |
| 208 |
|
| 209 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 210 |
const FcitxQtAddonInfo &arg) { |
| 211 |
argument.beginStructure(); |
| 212 |
argument << arg.uniqueName(); |
| 213 |
argument << arg.name(); |
| 214 |
argument << arg.comment(); |
| 215 |
argument << arg.category(); |
| 216 |
argument << arg.configurable(); |
| 217 |
argument << arg.enabled(); |
| 218 |
argument.endStructure(); |
| 219 |
return argument; |
| 220 |
} |
| 221 |
|
| 222 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 223 |
FcitxQtAddonInfo &arg) { |
| 224 |
QString uniqueName, name, comment; |
| 225 |
int category; |
| 226 |
bool configurable, enabled; |
| 227 |
argument.beginStructure(); |
| 228 |
argument >> uniqueName >> name >> comment >> category >> configurable >> |
| 229 |
enabled; |
| 230 |
argument.endStructure(); |
| 231 |
arg.setUniqueName(uniqueName); |
| 232 |
arg.setName(name); |
| 233 |
arg.setComment(comment); |
| 234 |
arg.setCategory(category); |
| 235 |
arg.setConfigurable(configurable); |
| 236 |
arg.setEnabled(enabled); |
| 237 |
return argument; |
| 238 |
} |
| 239 |
|
| 240 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 241 |
const FcitxQtAddonInfoV2 &arg) { |
| 242 |
argument.beginStructure(); |
| 243 |
argument << arg.uniqueName(); |
| 244 |
argument << arg.name(); |
| 245 |
argument << arg.comment(); |
| 246 |
argument << arg.category(); |
| 247 |
argument << arg.configurable(); |
| 248 |
argument << arg.enabled(); |
| 249 |
argument << arg.onDemand(); |
| 250 |
argument << arg.dependencies(); |
| 251 |
argument << arg.optionalDependencies(); |
| 252 |
argument.endStructure(); |
| 253 |
return argument; |
| 254 |
} |
| 255 |
|
| 256 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 257 |
FcitxQtAddonInfoV2 &arg) { |
| 258 |
QString uniqueName, name, comment; |
| 259 |
int category; |
| 260 |
bool configurable, enabled, onDemand; |
| 261 |
QStringList dependencies, optionalDependencies; |
| 262 |
argument.beginStructure(); |
| 263 |
argument >> uniqueName >> name >> comment >> category >> configurable >> |
| 264 |
enabled >> onDemand >> dependencies >> optionalDependencies; |
| 265 |
argument.endStructure(); |
| 266 |
arg.setUniqueName(uniqueName); |
| 267 |
arg.setName(name); |
| 268 |
arg.setComment(comment); |
| 269 |
arg.setCategory(category); |
| 270 |
arg.setConfigurable(configurable); |
| 271 |
arg.setEnabled(enabled); |
| 272 |
arg.setOnDemand(onDemand); |
| 273 |
arg.setDependencies(dependencies); |
| 274 |
arg.setOptionalDependencies(optionalDependencies); |
| 275 |
return argument; |
| 276 |
} |
| 277 |
|
| 278 |
QDBusArgument &operator<<(QDBusArgument &argument, |
| 279 |
const FcitxQtAddonState &arg) { |
| 280 |
argument.beginStructure(); |
| 281 |
argument << arg.uniqueName(); |
| 282 |
argument << arg.enabled(); |
| 283 |
argument.endStructure(); |
| 284 |
return argument; |
| 285 |
} |
| 286 |
|
| 287 |
const QDBusArgument &operator>>(const QDBusArgument &argument, |
| 288 |
FcitxQtAddonState &arg) { |
| 289 |
QString uniqueName; |
| 290 |
bool enabled; |
| 291 |
argument.beginStructure(); |
| 292 |
argument >> uniqueName >> enabled; |
| 293 |
argument.endStructure(); |
| 294 |
arg.setUniqueName(uniqueName); |
| 295 |
arg.setEnabled(enabled); |
| 296 |
return argument; |
| 297 |
} |
| 298 |
} // namespace fcitx |