OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/input_method/ibus_engine_controller.h" | 5 #include "chrome/browser/chromeos/input_method/ibus_engine_controller.h" |
6 | 6 |
7 #if defined(HAVE_IBUS) | 7 #if defined(HAVE_IBUS) |
8 #include <ibus.h> | 8 #include <ibus.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 LOG(ERROR) << "ibus_bus_new() failed"; | 122 LOG(ERROR) << "ibus_bus_new() failed"; |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 (*g_connections_)[engine_id_] = this; | 126 (*g_connections_)[engine_id_] = this; |
127 VLOG(1) << "Adding engine: " << engine_id_; | 127 VLOG(1) << "Adding engine: " << engine_id_; |
128 | 128 |
129 // Check the IBus connection status. | 129 // Check the IBus connection status. |
130 bool result = true; | 130 bool result = true; |
131 if (ibus_bus_is_connected(ibus_)) { | 131 if (ibus_bus_is_connected(ibus_)) { |
132 LOG(INFO) << "ibus_bus_is_connected(). IBus connection is ready."; | 132 if (!g_factory_) { |
| 133 g_factory_ = ibus_factory_new(ibus_bus_get_connection(ibus_)); |
| 134 } |
| 135 |
| 136 VLOG(1) << "ibus_bus_is_connected(). IBus connection is ready."; |
133 result = MaybeCreateComponent(); | 137 result = MaybeCreateComponent(); |
134 } | 138 } |
135 | 139 |
136 // Start listening the gobject signals regardless of the bus connection | 140 // Start listening the gobject signals regardless of the bus connection |
137 // status. | 141 // status. |
138 ConnectIBusSignals(); | 142 ConnectIBusSignals(); |
139 return result; | 143 return result; |
140 } | 144 } |
141 | 145 |
142 virtual void SetPreeditText(const char* text, int cursor) { | 146 virtual void SetPreeditText(const char* text, int cursor) { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 reinterpret_cast<gpointer>(G_CALLBACK(IBusBusDisconnectedCallback)), | 617 reinterpret_cast<gpointer>(G_CALLBACK(IBusBusDisconnectedCallback)), |
614 this); | 618 this); |
615 } | 619 } |
616 | 620 |
617 // Handles "connected" signal from ibus-daemon. | 621 // Handles "connected" signal from ibus-daemon. |
618 static void IBusBusConnectedCallback(IBusBus* bus, gpointer user_data) { | 622 static void IBusBusConnectedCallback(IBusBus* bus, gpointer user_data) { |
619 LOG(WARNING) << "IBus connection is recovered."; | 623 LOG(WARNING) << "IBus connection is recovered."; |
620 g_return_if_fail(user_data); | 624 g_return_if_fail(user_data); |
621 IBusEngineControllerImpl* self | 625 IBusEngineControllerImpl* self |
622 = static_cast<IBusEngineControllerImpl*>(user_data); | 626 = static_cast<IBusEngineControllerImpl*>(user_data); |
| 627 if (!g_factory_) { |
| 628 g_factory_ = ibus_factory_new(ibus_bus_get_connection(bus)); |
| 629 } |
| 630 |
623 if (!self->MaybeCreateComponent()) { | 631 if (!self->MaybeCreateComponent()) { |
624 LOG(ERROR) << "MaybeCreateComponent() failed"; | 632 LOG(ERROR) << "MaybeCreateComponent() failed"; |
625 return; | 633 return; |
626 } | 634 } |
627 } | 635 } |
628 | 636 |
629 // Handles "disconnected" signal from ibus-daemon. | 637 // Handles "disconnected" signal from ibus-daemon. |
630 static void IBusBusDisconnectedCallback(IBusBus* bus, gpointer user_data) { | 638 static void IBusBusDisconnectedCallback(IBusBus* bus, gpointer user_data) { |
631 LOG(WARNING) << "IBus connection is terminated."; | 639 LOG(WARNING) << "IBus connection is terminated."; |
| 640 g_factory_ = NULL; |
632 } | 641 } |
633 | 642 |
634 bool MaybeCreateComponent() { | 643 bool MaybeCreateComponent() { |
635 if (!ibus_ || !ibus_bus_is_connected(ibus_)) { | 644 if (!ibus_ || !ibus_bus_is_connected(ibus_) || !g_factory_) { |
636 return false; | 645 return false; |
637 } | 646 } |
638 | 647 |
639 VLOG(1) << "MaybeCreateComponent"; | 648 VLOG(1) << "MaybeCreateComponent"; |
640 IBusComponent* component = ibus_component_new(bus_name_.c_str(), | 649 IBusComponent* component = ibus_component_new(bus_name_.c_str(), |
641 description_.c_str(), | 650 description_.c_str(), |
642 "", | 651 "", |
643 "", | 652 "", |
644 engine_name_.c_str(), | 653 engine_name_.c_str(), |
645 "", | 654 "", |
646 "", | 655 "", |
647 ""); | 656 ""); |
648 ibus_component_add_engine(component, | 657 ibus_component_add_engine(component, |
649 ibus_engine_desc_new(engine_id_.c_str(), | 658 ibus_engine_desc_new(engine_id_.c_str(), |
650 description_.c_str(), | 659 description_.c_str(), |
651 description_.c_str(), | 660 description_.c_str(), |
652 language_.c_str(), | 661 language_.c_str(), |
653 "", | 662 "", |
654 engine_name_.c_str(), | 663 engine_name_.c_str(), |
655 "", | 664 "", |
656 layout_.c_str())); | 665 layout_.c_str())); |
657 | 666 |
658 IBusFactory* factory = ibus_factory_new(ibus_bus_get_connection(ibus_)); | 667 ibus_factory_add_engine(g_factory_, engine_id_.c_str(), |
659 ibus_factory_add_engine(factory, engine_id_.c_str(), | |
660 IBUS_TYPE_CHROMEOS_ENGINE); | 668 IBUS_TYPE_CHROMEOS_ENGINE); |
661 ibus_bus_register_component(ibus_, component); | 669 ibus_bus_register_component(ibus_, component); |
662 g_object_unref(component); | 670 g_object_unref(component); |
663 | 671 |
664 return true; | 672 return true; |
665 } | 673 } |
666 | 674 |
667 static void OnServiceMethodCall(IBusService* service, | 675 static void OnServiceMethodCall(IBusService* service, |
668 GDBusConnection* connection, | 676 GDBusConnection* connection, |
669 const gchar* sender, | 677 const gchar* sender, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 unsigned int page_size_; | 872 unsigned int page_size_; |
865 unsigned int cursor_position_; | 873 unsigned int cursor_position_; |
866 std::string aux_text_; | 874 std::string aux_text_; |
867 bool aux_text_visible_; | 875 bool aux_text_visible_; |
868 std::vector<EngineProperty*> properties_; | 876 std::vector<EngineProperty*> properties_; |
869 std::map<std::string, EngineProperty*> property_map_; | 877 std::map<std::string, EngineProperty*> property_map_; |
870 | 878 |
871 std::set<IBusChromeOSEngine*> engine_instances_; | 879 std::set<IBusChromeOSEngine*> engine_instances_; |
872 | 880 |
873 static ConnectionMap* g_connections_; | 881 static ConnectionMap* g_connections_; |
| 882 static IBusFactory* g_factory_; |
874 }; | 883 }; |
875 | 884 |
876 IBusEngineControllerImpl::ConnectionMap* | 885 IBusEngineControllerImpl::ConnectionMap* |
877 IBusEngineControllerImpl::g_connections_ = NULL; | 886 IBusEngineControllerImpl::g_connections_ = NULL; |
878 | 887 |
| 888 IBusFactory* IBusEngineControllerImpl::g_factory_ = NULL; |
| 889 |
879 void ibus_chromeos_engine_class_init(IBusChromeOSEngineClass *klass) { | 890 void ibus_chromeos_engine_class_init(IBusChromeOSEngineClass *klass) { |
880 IBusEngineControllerImpl::InitEngineClass(klass); | 891 IBusEngineControllerImpl::InitEngineClass(klass); |
881 } | 892 } |
882 | 893 |
883 void ibus_chromeos_engine_init(IBusChromeOSEngine* engine) { | 894 void ibus_chromeos_engine_init(IBusChromeOSEngine* engine) { |
884 IBusEngineControllerImpl::InitEngine(engine); | 895 IBusEngineControllerImpl::InitEngine(engine); |
885 } | 896 } |
886 | 897 |
887 #endif // HAVE_IBUS | 898 #endif // HAVE_IBUS |
888 | 899 |
(...skipping 17 matching lines...) Expand all Loading... |
906 #else | 917 #else |
907 return NULL; | 918 return NULL; |
908 #endif | 919 #endif |
909 } | 920 } |
910 | 921 |
911 IBusEngineController::~IBusEngineController() { | 922 IBusEngineController::~IBusEngineController() { |
912 } | 923 } |
913 | 924 |
914 } // namespace input_method | 925 } // namespace input_method |
915 } // namespace chromeos | 926 } // namespace chromeos |
OLD | NEW |