1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROMEOS_DBUS_IBUS_IBUS_PROPERTY_H_ 6 #define CHROMEOS_DBUS_IBUS_IBUS_PROPERTY_H_ 7 8 #include <string> 9 #include "base/basictypes.h" 10 #include "base/memory/scoped_vector.h" 11 #include "chromeos/chromeos_export.h" 12 13 namespace dbus { 14 class MessageWriter; 15 class MessageReader; 16 } // namespace dbus 17 18 namespace chromeos { 19 20 class IBusProperty; 21 typedef ScopedVector<IBusProperty> IBusPropertyList; 22 23 // Pops a IBusProperty from |reader|. 24 // Returns false if an error occurs. 25 bool CHROMEOS_EXPORT PopIBusProperty(dbus::MessageReader* reader, 26 IBusProperty* property); 27 // Pops a IBusPropertyList from |reader|. 28 // Returns false if an error occurs. 29 bool CHROMEOS_EXPORT PopIBusPropertyList(dbus::MessageReader* reader, 30 IBusPropertyList* property_list); 31 32 // Appends a IBusProperty to |writer|. 33 void CHROMEOS_EXPORT AppendIBusProperty(const IBusProperty& property, 34 dbus::MessageWriter* writer); 35 // Appends a IBusPropertyList to |writer|. 36 void CHROMEOS_EXPORT AppendIBusPropertyList( 37 const IBusPropertyList& property_list, 38 dbus::MessageWriter* writer); 39 40 // The IBusPropList is one of IBusObjects and it contains array of IBusProperty. 41 // The IBusProperty contains IBusTexts but only plain string is used in Chrome. 42 // We treat IBusPropList as scoped_vector of IBusProperty. 43 // 44 // DATA STRUCTURE OVERVIEW: 45 // variant struct { 46 // string "IBusProperty" 47 // array [] 48 // string "CompositionMode" // Key 49 // uint32 3 // Type 50 // variant struct { // Label 51 // string "IBusText" 52 // array [] 53 // string "" 54 // variant struct { 55 // string "IBusAttrList" 56 // array [] 57 // array [] 58 // } 59 // } 60 // string "/usr/share/ibus-mozc/hiragana.png" // icon 61 // variant struct { // Tooltip 62 // string "IBusText" 63 // array [] 64 // string "" 65 // variant struct { 66 // string "IBusAttrList" 67 // array [] 68 // array [] 69 // } 70 // } 71 // boolean true // sensitive 72 // boolean true // visible 73 // uint32 0 // state 74 // variant struct { // sub properties 75 // string "IBusPropList" 76 // array [] 77 // array [ 78 // ... More IBusPropertys 79 // ] 80 // } 81 // } 82 class CHROMEOS_EXPORT IBusProperty { 83 public: 84 enum IBusPropertyType { 85 IBUS_PROPERTY_TYPE_NORMAL = 0, 86 IBUS_PROPERTY_TYPE_TOGGLE, 87 IBUS_PROPERTY_TYPE_RADIO, 88 IBUS_PROPERTY_TYPE_MENU, 89 IBUS_PROPERTY_TYPE_SEPARATOR, 90 }; 91 IBusProperty(); 92 virtual ~IBusProperty(); 93 94 void CopyFrom(const IBusProperty& obj); 95 96 // The identity for the IBusProperty. 97 std::string key() const { return key_; } 98 void set_key(const std::string& key) { key_ = key; } 99 100 // The type of property: 101 IBusPropertyType type() const { return type_; } 102 void set_type(IBusPropertyType type) { type_ = type; } 103 104 // The string to be shown in UI. 105 std::string label() const { return label_; } 106 void set_label(const std::string& label) { label_ = label; } 107 108 // The string to be shown in UI as tooltip. 109 std::string tooltip() const { return tooltip_; } 110 void set_tooltip(const std::string& tooltip) { tooltip_ = tooltip; } 111 112 // True if the property is visible. 113 bool visible() const { return visible_; } 114 void set_visible(bool visible) { visible_ = visible; } 115 116 // True if the property is checked. 117 bool checked() const { return checked_; } 118 void set_checked(bool checked) { checked_ = checked; } 119 120 const IBusPropertyList& sub_properties() const { return sub_properties_; } 121 IBusPropertyList* mutable_sub_properties() { return &sub_properties_; } 122 123 private: 124 std::string key_; 125 IBusPropertyType type_; 126 std::string label_; 127 std::string tooltip_; 128 bool visible_; 129 bool checked_; 130 IBusPropertyList sub_properties_; 131 132 DISALLOW_COPY_AND_ASSIGN(IBusProperty); 133 }; 134 135 } // namespace chromeos 136 137 #endif // CHROMEOS_DBUS_IBUS_IBUS_PROPERTY_H_ 138