File indexing completed on 2024-11-24 05:00:24
0001 /* 0002 SPDX-FileCopyrightText: 2014 Weng Xuetian <wengxt@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 #include "propertymanager.h" 0007 0008 PropertyManager::PropertyManager() 0009 : m_props(nullptr) 0010 { 0011 } 0012 0013 PropertyManager::~PropertyManager() 0014 { 0015 if (m_props) 0016 g_object_unref(m_props); 0017 } 0018 0019 void PropertyManager::setProperties(IBusPropList *props) 0020 { 0021 if (m_props) 0022 g_object_unref(m_props); 0023 m_props = props; 0024 if (m_props) 0025 g_object_ref(m_props); 0026 } 0027 0028 IBusProperty *PropertyManager::property(const QByteArray &key) 0029 { 0030 if (!m_props) 0031 return nullptr; 0032 0033 return searchList(key, m_props); 0034 } 0035 0036 IBusProperty *PropertyManager::searchList(const QByteArray &key, IBusPropList *props) 0037 { 0038 if (!props) 0039 return nullptr; 0040 0041 int i = 0; 0042 while (true) { 0043 IBusProperty *prop = ibus_prop_list_get(props, i); 0044 if (!prop) 0045 break; 0046 if (ibus_property_get_key(prop) == key) 0047 return prop; 0048 if (ibus_property_get_prop_type(prop) == PROP_TYPE_MENU) { 0049 IBusProperty *p = searchList(key, ibus_property_get_sub_props(prop)); 0050 if (p) 0051 return p; 0052 } 0053 i++; 0054 } 0055 return nullptr; 0056 } 0057 0058 void PropertyManager::updateProperty(IBusProperty *prop) 0059 { 0060 if (m_props) 0061 ibus_prop_list_update_property(m_props, prop); 0062 }