Merge lp:~unity-api-team/indicator-network/krillin-wifi into lp:indicator-network/14.10

Proposed by Antti Kaijanmäki
Status: Merged
Approved by: Antti Kaijanmäki
Approved revision: 433
Merged at revision: 435
Proposed branch: lp:~unity-api-team/indicator-network/krillin-wifi
Merge into: lp:indicator-network/14.10
Diff against target: 691 lines (+236/-87)
16 files modified
src/connectivity-cpp/dbus-cpp/services/urfkill.h (+3/-3)
src/connectivity-cpp/include/connectivity/networking/manager.h (+5/-0)
src/connectivity-cpp/src/platform/nmofono/kill-switch.cpp (+2/-0)
src/connectivity-cpp/src/platform/nmofono/kill-switch.h (+1/-0)
src/connectivity-cpp/src/platform/nmofono/manager.cpp (+89/-4)
src/connectivity-cpp/src/platform/nmofono/manager.h (+6/-0)
src/connectivity-cpp/src/platform/nmofono/wifi/link.cpp (+5/-2)
src/indicator/quick-access-section.cpp (+13/-4)
src/indicator/wifi-link-item.h (+0/-37)
src/indicator/wifi-section.cpp (+53/-11)
src/menumodel-cpp/action-group-exporter.h (+7/-5)
src/menumodel-cpp/action.cpp (+3/-1)
src/menumodel-cpp/gio-helpers/util.cpp (+7/-2)
src/menumodel-cpp/gio-helpers/util.h (+3/-2)
src/menumodel-cpp/menu-merger.h (+17/-9)
src/menumodel-cpp/menu.h (+22/-7)
To merge this branch: bzr merge lp:~unity-api-team/indicator-network/krillin-wifi
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Charles Kerr (community) Approve
Review via email: mp+235879@code.launchpad.net

Commit message

Fix wifi toggle on krillin.

Description of the change

fix wifi toggle on krillin.

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Nice thread fixes. :)

There are a couple of warts here that I've talked with Antti about offline, but they don't block this Critical and can wait until the next MP.

review: Approve
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

just a simple timeout increase.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/connectivity-cpp/dbus-cpp/services/urfkill.h'
--- src/connectivity-cpp/dbus-cpp/services/urfkill.h 2014-08-19 19:55:15 +0000
+++ src/connectivity-cpp/dbus-cpp/services/urfkill.h 2014-09-26 13:07:38 +0000
@@ -162,7 +162,7 @@
162162
163 static std::chrono::milliseconds default_timeout()163 static std::chrono::milliseconds default_timeout()
164 {164 {
165 return std::chrono::seconds{5};165 return std::chrono::seconds{15};
166 }166 }
167 };167 };
168168
@@ -179,7 +179,7 @@
179179
180 static std::chrono::milliseconds default_timeout()180 static std::chrono::milliseconds default_timeout()
181 {181 {
182 return std::chrono::seconds{5};182 return std::chrono::seconds{15};
183 }183 }
184 };184 };
185185
@@ -196,7 +196,7 @@
196196
197 static std::chrono::milliseconds default_timeout()197 static std::chrono::milliseconds default_timeout()
198 {198 {
199 return std::chrono::seconds{1};199 return std::chrono::seconds{5};
200 }200 }
201 };201 };
202 };202 };
203203
=== modified file 'src/connectivity-cpp/include/connectivity/networking/manager.h'
--- src/connectivity-cpp/include/connectivity/networking/manager.h 2014-08-19 19:55:15 +0000
+++ src/connectivity-cpp/include/connectivity/networking/manager.h 2014-09-26 13:07:38 +0000
@@ -128,6 +128,11 @@
128 */128 */
129 virtual const core::Property<std::uint32_t>& characteristics() const = 0;129 virtual const core::Property<std::uint32_t>& characteristics() const = 0;
130130
131 virtual const core::Property<bool>& hasWifi() const = 0;
132 virtual const core::Property<bool>& wifiEnabled() const = 0;
133 virtual bool enableWifi() = 0;
134 virtual bool disableWifi() = 0;
135
131protected:136protected:
132 /**137 /**
133 * @brief The default constructor is protected.138 * @brief The default constructor is protected.
134139
=== modified file 'src/connectivity-cpp/src/platform/nmofono/kill-switch.cpp'
--- src/connectivity-cpp/src/platform/nmofono/kill-switch.cpp 2014-08-19 19:55:15 +0000
+++ src/connectivity-cpp/src/platform/nmofono/kill-switch.cpp 2014-09-26 13:07:38 +0000
@@ -38,6 +38,8 @@
38 {38 {
39 switch(value) {39 switch(value) {
40 case URfkill::Interface::Killswitch::State::not_available:40 case URfkill::Interface::Killswitch::State::not_available:
41 state.set(KillSwitch::State::not_available);
42 break;
41 case URfkill::Interface::Killswitch::State::unblocked:43 case URfkill::Interface::Killswitch::State::unblocked:
42 state.set(KillSwitch::State::unblocked);44 state.set(KillSwitch::State::unblocked);
43 break;45 break;
4446
=== modified file 'src/connectivity-cpp/src/platform/nmofono/kill-switch.h'
--- src/connectivity-cpp/src/platform/nmofono/kill-switch.h 2014-08-19 19:55:15 +0000
+++ src/connectivity-cpp/src/platform/nmofono/kill-switch.h 2014-09-26 13:07:38 +0000
@@ -61,6 +61,7 @@
6161
62 enum class State62 enum class State
63 {63 {
64 not_available,
64 unblocked,65 unblocked,
65 soft_blocked,66 soft_blocked,
66 hard_blocked67 hard_blocked
6768
=== modified file 'src/connectivity-cpp/src/platform/nmofono/manager.cpp'
--- src/connectivity-cpp/src/platform/nmofono/manager.cpp 2014-08-28 12:13:29 +0000
+++ src/connectivity-cpp/src/platform/nmofono/manager.cpp 2014-09-26 13:07:38 +0000
@@ -55,6 +55,31 @@
55 core::Property<connectivity::networking::Manager::NetworkingStatus> m_status;55 core::Property<connectivity::networking::Manager::NetworkingStatus> m_status;
56 core::Property<std::uint32_t> m_characteristics;56 core::Property<std::uint32_t> m_characteristics;
57 std::unique_ptr<State> m_state;57 std::unique_ptr<State> m_state;
58
59 core::Property<bool> m_hasWifi;
60 core::Property<bool> m_wifiEnabled ;
61 std::shared_ptr<KillSwitch> m_wifiKillSwitch;
62
63 void updateHasWifi()
64 {
65 if (m_wifiKillSwitch->state().get() != KillSwitch::State::not_available) {
66 m_hasWifi.set(true);
67 if (m_wifiKillSwitch->state().get() == KillSwitch::State::unblocked)
68 m_wifiEnabled.set(true);
69 else
70 m_wifiEnabled.set(false);
71 return;
72 }
73
74 // ok, killswitch not supported, but we still might have wifi devices
75 bool haswifi = false;
76 for (auto link : m_links.get()) {
77 if (link->type() == networking::Link::Type::wifi)
78 haswifi = true;
79 }
80 m_hasWifi.set(haswifi);
81 m_wifiEnabled.set(haswifi);
82 }
58};83};
59}84}
60}85}
@@ -143,6 +168,10 @@
143 /// @todo offload the initialization to a thread or something168 /// @todo offload the initialization to a thread or something
144 /// @todo those Id() thingies169 /// @todo those Id() thingies
145170
171 p->m_wifiKillSwitch = std::make_shared<KillSwitch>(p->urfkill,
172 p->urfkill->switches[fdo::URfkill::Interface::Killswitch::Type::wlan]);
173 p->m_wifiKillSwitch->state().changed().connect(std::bind(&Private::updateHasWifi, p.get()));
174
146 p->nm->device_added->connect([this](const dbus::types::ObjectPath &path){175 p->nm->device_added->connect([this](const dbus::types::ObjectPath &path){
147 std::cout << "Device Added:" << path.as_string() << std::endl;176 std::cout << "Device Added:" << path.as_string() << std::endl;
148 auto links = p->m_links.get();177 auto links = p->m_links.get();
@@ -158,10 +187,11 @@
158 if (dev.type() == NM::Interface::Device::Type::wifi) {187 if (dev.type() == NM::Interface::Device::Type::wifi) {
159 links.insert(std::make_shared<wifi::Link>(dev,188 links.insert(std::make_shared<wifi::Link>(dev,
160 *p->nm.get(),189 *p->nm.get(),
161 std::make_shared<KillSwitch>(p->urfkill,190 p->m_wifiKillSwitch));
162 p->urfkill->switches[fdo::URfkill::Interface::Killswitch::Type::wlan])));
163 p->m_links.set(links);191 p->m_links.set(links);
164 }192 }
193
194 p->updateHasWifi();
165 });195 });
166 p->nm->device_removed->connect([this](const dbus::types::ObjectPath &path){196 p->nm->device_removed->connect([this](const dbus::types::ObjectPath &path){
167 std::cout << "Device Removed:" << path.as_string() << std::endl;197 std::cout << "Device Removed:" << path.as_string() << std::endl;
@@ -173,6 +203,8 @@
173 }203 }
174 }204 }
175 p->m_links.set(links);205 p->m_links.set(links);
206
207 p->updateHasWifi();
176 });208 });
177 std::set<std::shared_ptr<networking::Link> > links;209 std::set<std::shared_ptr<networking::Link> > links;
178 for(auto dev : p->nm->get_devices()) {210 for(auto dev : p->nm->get_devices()) {
@@ -182,8 +214,7 @@
182 std::shared_ptr<networking::Link> link;214 std::shared_ptr<networking::Link> link;
183 link.reset(new wifi::Link(dev,215 link.reset(new wifi::Link(dev,
184 *p->nm.get(),216 *p->nm.get(),
185 std::make_shared<KillSwitch>(p->urfkill,217 p->m_wifiKillSwitch));
186 p->urfkill->switches[fdo::URfkill::Interface::Killswitch::Type::wlan])));
187 links.insert(link);218 links.insert(link);
188 break;219 break;
189 }220 }
@@ -219,6 +250,8 @@
219250
220 /// @todo set by the default connections.251 /// @todo set by the default connections.
221 p->m_characteristics.set(networking::Link::Characteristics::empty);252 p->m_characteristics.set(networking::Link::Characteristics::empty);
253
254 p->updateHasWifi();
222}255}
223256
224void257void
@@ -269,3 +302,55 @@
269{302{
270 return p->m_characteristics;303 return p->m_characteristics;
271}304}
305
306const core::Property<bool>&
307Manager::hasWifi() const
308{
309 return p->m_hasWifi;
310}
311
312const core::Property<bool>&
313Manager::wifiEnabled() const
314{
315 return p->m_wifiEnabled;
316}
317
318
319bool
320Manager::enableWifi()
321{
322 if (!p->m_hasWifi.get())
323 return false;
324
325 try {
326 if (p->m_wifiKillSwitch->state() == KillSwitch::State::soft_blocked) {
327 // try to unblock. throws if fails.
328 p->m_wifiKillSwitch->unblock();
329 }
330 p->nm->wireless_enabled->set(true);
331 } catch(std::runtime_error &e) {
332 std::cerr << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl;
333 return false;
334 }
335 return true;
336}
337
338bool
339Manager::disableWifi()
340{
341 if (!p->m_hasWifi.get())
342 return false;
343
344 try {
345 if (p->m_wifiKillSwitch->state() == KillSwitch::State::unblocked) {
346 // block the device. that will disable it also
347 p->m_wifiKillSwitch->block();
348 }
349 p->nm->wireless_enabled->set(false);
350 } catch(std::runtime_error &e) {
351 std::cerr << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl;
352 return false;
353 }
354 return true;
355}
356
272357
=== modified file 'src/connectivity-cpp/src/platform/nmofono/manager.h'
--- src/connectivity-cpp/src/platform/nmofono/manager.h 2014-08-19 19:55:15 +0000
+++ src/connectivity-cpp/src/platform/nmofono/manager.h 2014-09-26 13:07:38 +0000
@@ -51,6 +51,12 @@
51 void disableFlightMode() override;51 void disableFlightMode() override;
52 const core::Property<connectivity::networking::Manager::FlightModeStatus>& flightMode() const override;52 const core::Property<connectivity::networking::Manager::FlightModeStatus>& flightMode() const override;
5353
54 const core::Property<bool>& hasWifi() const override;
55 const core::Property<bool>& wifiEnabled() const override;
56
57 bool enableWifi() override;
58 bool disableWifi() override;
59
54 const core::Property<std::set<std::shared_ptr<connectivity::networking::Link>>>& links() const;60 const core::Property<std::set<std::shared_ptr<connectivity::networking::Link>>>& links() const;
55 const core::Property<std::set<std::shared_ptr<connectivity::networking::Service>>>&services() const override;61 const core::Property<std::set<std::shared_ptr<connectivity::networking::Service>>>&services() const override;
56 const core::Property<connectivity::networking::Manager::NetworkingStatus> & status() const override;62 const core::Property<connectivity::networking::Manager::NetworkingStatus> & status() const override;
5763
=== modified file 'src/connectivity-cpp/src/platform/nmofono/wifi/link.cpp'
--- src/connectivity-cpp/src/platform/nmofono/wifi/link.cpp 2014-09-04 07:48:13 +0000
+++ src/connectivity-cpp/src/platform/nmofono/wifi/link.cpp 2014-09-26 13:07:38 +0000
@@ -100,6 +100,8 @@
100 org::freedesktop::NetworkManager::Interface::NetworkManager nm;100 org::freedesktop::NetworkManager::Interface::NetworkManager nm;
101101
102 KillSwitch::Ptr killSwitch;102 KillSwitch::Ptr killSwitch;
103 // hack hack
104 std::vector<core::ScopedConnection> switchConnection;
103105
104 std::map<AccessPointKey, std::shared_ptr<GroupedAccessPoint>> grouper;106 std::map<AccessPointKey, std::shared_ptr<GroupedAccessPoint>> grouper;
105 bool disabled;107 bool disabled;
@@ -146,9 +148,9 @@
146 // std::uint32_t reason = std::get<2>(args);148 // std::uint32_t reason = std::get<2>(args);
147 updateDeviceState(new_state);149 updateDeviceState(new_state);
148 });150 });
149 p->killSwitch->state().changed().connect([this](platform::nmofono::KillSwitch::State){151 p->switchConnection.emplace_back(p->killSwitch->state().changed().connect([this](platform::nmofono::KillSwitch::State){
150 updateDeviceState(p->lastState);152 updateDeviceState(p->lastState);
151 });153 }));
152}154}
153155
154Link::~Link()156Link::~Link()
@@ -428,6 +430,7 @@
428 case KillSwitch::State::soft_blocked:430 case KillSwitch::State::soft_blocked:
429 p->status_.set(Status::disabled);431 p->status_.set(Status::disabled);
430 break;432 break;
433 case KillSwitch::State::not_available:
431 case KillSwitch::State::unblocked:434 case KillSwitch::State::unblocked:
432 p->status_.set(Status::offline);435 p->status_.set(Status::offline);
433 }436 }
434437
=== modified file 'src/indicator/quick-access-section.cpp'
--- src/indicator/quick-access-section.cpp 2014-05-27 16:06:14 +0000
+++ src/indicator/quick-access-section.cpp 2014-09-26 13:07:38 +0000
@@ -65,10 +65,19 @@
65 }65 }
66 });66 });
67 m_flightModeSwitch->activated().connect([this](){67 m_flightModeSwitch->activated().connect([this](){
68 if (m_flightModeSwitch->state().get())68 if (m_flightModeSwitch->state().get()) {
69 m_manager->enableFlightMode();69 try {
70 else70 m_manager->enableFlightMode();
71 m_manager->disableFlightMode();71 } catch (const std::exception &e) {
72 std::cout << e.what() << std::endl;
73 }
74 } else {
75 try {
76 m_manager->disableFlightMode();
77 } catch (const std::exception &e) {
78 std::cout << e.what() << std::endl;
79 }
80 }
72 });81 });
7382
74 m_actionGroupMerger->add(*m_flightModeSwitch);83 m_actionGroupMerger->add(*m_flightModeSwitch);
7584
=== modified file 'src/indicator/wifi-link-item.h'
--- src/indicator/wifi-link-item.h 2014-08-15 11:49:44 +0000
+++ src/indicator/wifi-link-item.h 2014-09-26 13:07:38 +0000
@@ -42,8 +42,6 @@
42 /// @todo do something with me...42 /// @todo do something with me...
43 Action::Ptr m_actionBusy;43 Action::Ptr m_actionBusy;
4444
45 SwitchItem::Ptr m_switch;
46
47 networking::wifi::AccessPoint::Ptr m_activeAccessPoint;45 networking::wifi::AccessPoint::Ptr m_activeAccessPoint;
48 std::map<networking::wifi::AccessPoint::Ptr, AccessPointItem::Ptr> m_accessPoints;46 std::map<networking::wifi::AccessPoint::Ptr, AccessPointItem::Ptr> m_accessPoints;
4947
@@ -85,40 +83,6 @@
8583
86 m_rootMerger = std::make_shared<MenuMerger>();84 m_rootMerger = std::make_shared<MenuMerger>();
8785
88 m_switch = std::make_shared<SwitchItem>(_("Wi-Fi"), "wifi", "enable");
89 m_actionGroupMerger->add(*m_switch);
90 switch (m_link->status().get()) {
91 case networking::Link::Status::disabled:
92 m_switch->state().set(false);
93 break;
94 case networking::Link::Status::offline:
95 case networking::Link::Status::connecting:
96 case networking::Link::Status::connected:
97 case networking::Link::Status::online:
98 m_switch->state().set(true);
99 break;
100 }
101 m_link->status().changed().connect([this](networking::Link::Status value){
102 switch (value) {
103 case networking::Link::Status::disabled:
104 m_switch->state().set(false);
105 break;
106 case networking::Link::Status::offline:
107 case networking::Link::Status::connecting:
108 case networking::Link::Status::connected:
109 case networking::Link::Status::online:
110 m_switch->state().set(true);
111 break;
112 }
113 });
114 m_switch->activated().connect([this](){
115 if (m_switch->state().get()) {
116 m_link->enable();
117 } else {
118 m_link->disable();
119 }
120 });
121
122 m_accessPointCompare = [](MenuItem::Ptr a, MenuItem::Ptr b){86 m_accessPointCompare = [](MenuItem::Ptr a, MenuItem::Ptr b){
123 // order alphabetically by SSID87 // order alphabetically by SSID
12488
@@ -152,7 +116,6 @@
152 m_otherNetwork = std::make_shared<TextItem>(_("Other network…"), "wifi", "othernetwork");116 m_otherNetwork = std::make_shared<TextItem>(_("Other network…"), "wifi", "othernetwork");
153 //m_actionGroupMerger->add(*m_otherNetwork);117 //m_actionGroupMerger->add(*m_otherNetwork);
154118
155 m_topMenu->append(*m_switch);
156 m_rootMerger->append(m_topMenu);119 m_rootMerger->append(m_topMenu);
157120
158 m_apsMerger->append(m_connectedBeforeApsMenu);121 m_apsMerger->append(m_connectedBeforeApsMenu);
159122
=== modified file 'src/indicator/wifi-section.cpp'
--- src/indicator/wifi-section.cpp 2014-05-12 11:36:59 +0000
+++ src/indicator/wifi-section.cpp 2014-09-26 13:07:38 +0000
@@ -32,6 +32,8 @@
32 Menu::Ptr m_menu;32 Menu::Ptr m_menu;
33 Menu::Ptr m_settingsMenu;33 Menu::Ptr m_settingsMenu;
3434
35 SwitchItem::Ptr m_switch;
36
35 WifiLinkItem::Ptr m_wifiLink;37 WifiLinkItem::Ptr m_wifiLink;
36 TextItem::Ptr m_openWifiSettings;38 TextItem::Ptr m_openWifiSettings;
3739
@@ -44,19 +46,36 @@
44 m_settingsMenu = std::make_shared<Menu>();46 m_settingsMenu = std::make_shared<Menu>();
4547
4648
47 for (auto link : m_manager->links().get()) {49 m_switch = std::make_shared<SwitchItem>(_("Wi-Fi"), "wifi", "enable");
48 auto wifi_link = std::dynamic_pointer_cast<networking::wifi::Link>(link);50
49 m_wifiLink = std::make_shared<WifiLinkItem>(wifi_link);51 /// @todo don't now really care about actully being able to detach the whole
5052 /// wifi chipset. on touch devices we always have wifi.
51 m_actionGroupMerger->add(*m_wifiLink);53 if (m_manager->hasWifi().get()) {
52 m_menu->append(*m_wifiLink);54 m_actionGroupMerger->add(*m_switch);
53 m_settingsMenu->append(*m_wifiLink);55 m_menu->append(*m_switch);
5456 m_settingsMenu->append(*m_switch);
55 // just take the first one now.
56 /// @todo multiple links and links()->changed()
57 break;
58 }57 }
5958
59 m_switch->state().set(m_manager->wifiEnabled().get());
60 m_manager->wifiEnabled().changed().connect([this](bool value) {
61 m_switch->state().set(value);
62 });
63 m_switch->activated().connect([this](){
64 if (m_switch->state().get()) {
65 if (!m_manager->enableWifi()) {
66 /// try to work around the switch getting out of state on unity8 side
67 m_switch->state().set(false);
68 }
69 } else {
70 if (!m_manager->disableWifi())
71 m_switch->state().set(true);
72 }
73 });
74
75
76 m_manager->links().changed().connect(std::bind(&Private::updateLinks, this));
77 updateLinks();
78
60 m_openWifiSettings = std::make_shared<TextItem>(_("Wi-Fi settings…"), "wifi", "settings");79 m_openWifiSettings = std::make_shared<TextItem>(_("Wi-Fi settings…"), "wifi", "settings");
61 m_openWifiSettings->activated().connect([](){80 m_openWifiSettings->activated().connect([](){
62 UrlDispatcher::send("settings:///system/wifi", [](std::string url, bool success){81 UrlDispatcher::send("settings:///system/wifi", [](std::string url, bool success){
@@ -69,6 +88,29 @@
69 m_menu->append(*m_openWifiSettings);88 m_menu->append(*m_openWifiSettings);
70 }89 }
7190
91 void updateLinks()
92 {
93 // remove all and recreate. we have top 1 now anyway
94 if (m_wifiLink) {
95 m_actionGroupMerger->remove(*m_wifiLink);
96 m_menu->removeAll(*m_wifiLink);
97 m_settingsMenu->removeAll(*m_wifiLink);
98 m_wifiLink.reset();
99 }
100
101 for (auto link : m_manager->links().get()) {
102 auto wifi_link = std::dynamic_pointer_cast<networking::wifi::Link>(link);
103 m_wifiLink = std::make_shared<WifiLinkItem>(wifi_link);
104
105 m_actionGroupMerger->add(*m_wifiLink);
106 m_menu->append(*m_wifiLink);
107 m_settingsMenu->append(*m_wifiLink);
108
109 // just take the first one
110 break;
111 }
112 }
113
72public:114public:
73};115};
74116
75117
=== modified file 'src/menumodel-cpp/action-group-exporter.h'
--- src/menumodel-cpp/action-group-exporter.h 2014-08-14 23:23:06 +0000
+++ src/menumodel-cpp/action-group-exporter.h 2014-09-26 13:07:38 +0000
@@ -63,19 +63,21 @@
63 return;63 return;
64 }64 }
6565
66
67 auto group = m_gSimpleActionGroup;
66 GMainLoopDispatch([=](){68 GMainLoopDispatch([=](){
67 for (auto action : actionGroup->actions()) {69 for (auto action : actionGroup->actions()) {
68 g_action_map_add_action(G_ACTION_MAP(m_gSimpleActionGroup.get()), action->gaction().get());70 g_action_map_add_action(G_ACTION_MAP(group.get()), action->gaction().get());
69 }71 }
70 });72 });
71 actionGroup->actionAdded().connect([this](Action::Ptr action){73 actionGroup->actionAdded().connect([=](Action::Ptr action){
72 GMainLoopDispatch([=](){74 GMainLoopDispatch([=](){
73 g_action_map_add_action(G_ACTION_MAP(m_gSimpleActionGroup.get()), action->gaction().get());75 g_action_map_add_action(G_ACTION_MAP(group.get()), action->gaction().get());
74 });76 });
75 });77 });
76 actionGroup->actionRemoved().connect([this](Action::Ptr action){78 actionGroup->actionRemoved().connect([=](Action::Ptr action){
77 GMainLoopDispatch([=](){79 GMainLoopDispatch([=](){
78 g_action_map_remove_action(G_ACTION_MAP(m_gSimpleActionGroup.get()),80 g_action_map_remove_action(G_ACTION_MAP(group.get()),
79 action->name().c_str());81 action->name().c_str());
80 });82 });
81 });83 });
8284
=== modified file 'src/menumodel-cpp/action.cpp'
--- src/menumodel-cpp/action.cpp 2014-08-14 23:23:06 +0000
+++ src/menumodel-cpp/action.cpp 2014-09-26 13:07:38 +0000
@@ -85,6 +85,7 @@
85 g_signal_handler_disconnect(m_gaction.get(), m_activateHandlerId);85 g_signal_handler_disconnect(m_gaction.get(), m_activateHandlerId);
86 if (m_changeStateHandlerId)86 if (m_changeStateHandlerId)
87 g_signal_handler_disconnect(m_gaction.get(), m_changeStateHandlerId);87 g_signal_handler_disconnect(m_gaction.get(), m_changeStateHandlerId);
88 GMainLoopSync([]{});
88}89}
8990
90std::string91std::string
@@ -99,8 +100,9 @@
99{100{
100 std::lock_guard<std::recursive_mutex> lg(m_mutex);101 std::lock_guard<std::recursive_mutex> lg(m_mutex);
101 m_state = value;102 m_state = value;
103 auto action = m_gaction;
102 GMainLoopDispatch([=](){104 GMainLoopDispatch([=](){
103 g_simple_action_set_state(G_SIMPLE_ACTION(m_gaction.get()), value);105 g_simple_action_set_state(G_SIMPLE_ACTION(action.get()), value);
104 });106 });
105 /// @todo state changes don't work properly. We probably need to make the107 /// @todo state changes don't work properly. We probably need to make the
106 /// state a Property to be able to get signals on change.108 /// state a Property to be able to get signals on change.
107109
=== modified file 'src/menumodel-cpp/gio-helpers/util.cpp'
--- src/menumodel-cpp/gio-helpers/util.cpp 2014-08-14 23:23:06 +0000
+++ src/menumodel-cpp/gio-helpers/util.cpp 2014-09-26 13:07:38 +0000
@@ -20,7 +20,7 @@
20#include "util.h"20#include "util.h"
2121
22std::mutex GMainLoopDispatch::_lock;22std::mutex GMainLoopDispatch::_lock;
23std::vector<GMainLoopDispatch::Func *> GMainLoopDispatch::_funcs;23std::list<GMainLoopDispatch::Func *> GMainLoopDispatch::_funcs;
2424
25gboolean25gboolean
26GMainLoopDispatch::dispatch_cb(gpointer)26GMainLoopDispatch::dispatch_cb(gpointer)
@@ -37,7 +37,12 @@
37GMainLoopDispatch::GMainLoopDispatch(std::function<void()> func)37GMainLoopDispatch::GMainLoopDispatch(std::function<void()> func)
38{38{
39 if (g_main_context_acquire(g_main_context_default())) {39 if (g_main_context_acquire(g_main_context_default())) {
40 func();40 if (_funcs.empty())
41 func();
42 else {
43 std::function<void()> *funcPtr = new std::function<void()>(func);
44 _funcs.push_back(funcPtr);
45 }
41 g_main_context_release(g_main_context_default());46 g_main_context_release(g_main_context_default());
42 } else {47 } else {
43 std::lock_guard<std::mutex> lock(_lock);48 std::lock_guard<std::mutex> lock(_lock);
4449
=== modified file 'src/menumodel-cpp/gio-helpers/util.h'
--- src/menumodel-cpp/gio-helpers/util.h 2014-08-15 11:59:20 +0000
+++ src/menumodel-cpp/gio-helpers/util.h 2014-09-26 13:07:38 +0000
@@ -28,6 +28,7 @@
28#include <condition_variable>28#include <condition_variable>
29#include <iostream>29#include <iostream>
30#include <vector>30#include <vector>
31#include <list>
3132
32struct GMainLoopSync33struct GMainLoopSync
33{34{
@@ -72,8 +73,8 @@
72public:73public:
73 typedef std::function<void()> Func;74 typedef std::function<void()> Func;
74 static std::mutex _lock;75 static std::mutex _lock;
75 // vector keeps the order of the functions76 // list keeps the order of the functions
76 static std::vector<Func *> _funcs;77 static std::list<Func *> _funcs;
7778
78 //GMainLoopDispatch() = delete;79 //GMainLoopDispatch() = delete;
79 GMainLoopDispatch(std::function<void()> func);80 GMainLoopDispatch(std::function<void()> func);
8081
=== modified file 'src/menumodel-cpp/menu-merger.h'
--- src/menumodel-cpp/menu-merger.h 2014-08-14 23:23:06 +0000
+++ src/menumodel-cpp/menu-merger.h 2014-09-26 13:07:38 +0000
@@ -56,15 +56,18 @@
56 gint added)56 gint added)
57 {57 {
58 int offset = m_startPositions[model] + position;58 int offset = m_startPositions[model] + position;
59 auto menu = m_gmenu;
5960
60 for (int i = 0; i < removed; ++i) {61 GMainLoopDispatch([=](){
61 g_menu_remove(m_gmenu.get(), offset);62 for (int i = 0; i < removed; ++i) {
62 }63 g_menu_remove(menu.get(), offset);
63 for (int i = added-1; i >= 0; --i) {64 }
64 auto item = g_menu_item_new_from_model(model, position + i);65 for (int i = added-1; i >= 0; --i) {
65 g_menu_insert_item(m_gmenu.get(), offset, item);66 auto item = g_menu_item_new_from_model(model, position + i);
66 g_object_unref(item);67 g_menu_insert_item(menu.get(), offset, item);
67 }68 g_object_unref(item);
69 }
70 });
6871
69 int delta = added - removed;72 int delta = added - removed;
70 bool update = false;73 bool update = false;
@@ -89,6 +92,12 @@
89 m_gmenu = make_gmenu_ptr();92 m_gmenu = make_gmenu_ptr();
90 }93 }
9194
95 ~MenuMerger()
96 {
97 clear();
98 GMainLoopSync([]{});
99 }
100
92 void append(MenuModel::Ptr menu)101 void append(MenuModel::Ptr menu)
93 {102 {
94 // calculate the start position for the items for the new menu103 // calculate the start position for the items for the new menu
@@ -106,7 +115,6 @@
106115
107 // add all items116 // add all items
108 itemsChanged(*menu, 0, 0, g_menu_model_get_n_items(*menu));117 itemsChanged(*menu, 0, 0, g_menu_model_get_n_items(*menu));
109
110 m_handlerId[*menu] = g_signal_connect(menu->operator GMenuModel *(),118 m_handlerId[*menu] = g_signal_connect(menu->operator GMenuModel *(),
111 "items-changed",119 "items-changed",
112 G_CALLBACK(MenuMerger::items_changed_cb),120 G_CALLBACK(MenuMerger::items_changed_cb),
113121
=== modified file 'src/menumodel-cpp/menu.h'
--- src/menumodel-cpp/menu.h 2014-08-14 23:23:06 +0000
+++ src/menumodel-cpp/menu.h 2014-09-26 13:07:38 +0000
@@ -51,14 +51,18 @@
51 virtual ~Menu()51 virtual ~Menu()
52 {52 {
53 std::lock_guard<std::recursive_mutex> lg(m_mutex);53 std::lock_guard<std::recursive_mutex> lg(m_mutex);
54 clear();
55 GMainLoopSync([]{});
54 }56 }
5557
56 void append(MenuItem::Ptr item)58 void append(MenuItem::Ptr item)
57 {59 {
58 std::lock_guard<std::recursive_mutex> lg(m_mutex);60 std::lock_guard<std::recursive_mutex> lg(m_mutex);
59 m_items.push_back(item);61 m_items.push_back(item);
62 // prevent this-> from being captured
63 auto menu = m_gmenu;
60 GMainLoopDispatch([=](){64 GMainLoopDispatch([=](){
61 g_menu_append_item(m_gmenu.get(), item->gmenuitem());65 g_menu_append_item(menu.get(), item->gmenuitem());
62 });66 });
63 if (std::count(m_items.begin(), m_items.end(), item) == 1) {67 if (std::count(m_items.begin(), m_items.end(), item) == 1) {
64 /// @todo disconenct68 /// @todo disconenct
@@ -66,9 +70,11 @@
66 int index = 0;70 int index = 0;
67 for (auto iter = m_items.begin(); iter != m_items.end(); ++iter) {71 for (auto iter = m_items.begin(); iter != m_items.end(); ++iter) {
68 if (*iter == item) {72 if (*iter == item) {
73 // prevent this-> from being captured
74 auto menu = m_gmenu;
69 GMainLoopDispatch([=](){75 GMainLoopDispatch([=](){
70 g_menu_remove(m_gmenu.get(), index);76 g_menu_remove(menu.get(), index);
71 g_menu_insert_item(m_gmenu.get(), index, item->gmenuitem());77 g_menu_insert_item(menu.get(), index, item->gmenuitem());
72 });78 });
73 }79 }
74 ++index;80 ++index;
@@ -88,8 +94,11 @@
88 ++index;94 ++index;
89 ++iter;95 ++iter;
90 }96 }
97
98 // prevent this-> from being captured
99 auto menu = m_gmenu;
91 GMainLoopDispatch([=](){100 GMainLoopDispatch([=](){
92 g_menu_insert_item(m_gmenu.get(), index, item->gmenuitem());101 g_menu_insert_item(menu.get(), index, item->gmenuitem());
93 });102 });
94 m_items.insert(position, item);103 m_items.insert(position, item);
95 }104 }
@@ -132,8 +141,10 @@
132 if (iter == m_items.end())141 if (iter == m_items.end())
133 return;142 return;
134143
144 // prevent this-> from being captured
145 auto menu = m_gmenu;
135 GMainLoopDispatch([=](){146 GMainLoopDispatch([=](){
136 g_menu_remove(m_gmenu.get(), index);147 g_menu_remove(menu.get(), index);
137 });148 });
138 m_items.erase(item);149 m_items.erase(item);
139 }150 }
@@ -147,9 +158,11 @@
147 // work reversed so that GMenu positions match tbe m_items positions158 // work reversed so that GMenu positions match tbe m_items positions
148 int index = m_items.size()-1;159 int index = m_items.size()-1;
149 for (auto iter = m_items.rbegin(); iter != m_items.rend(); ++iter) {160 for (auto iter = m_items.rbegin(); iter != m_items.rend(); ++iter) {
161 // prevent this-> from being captured
162 auto menu = m_gmenu;
150 if (*iter == item) {163 if (*iter == item) {
151 GMainLoopDispatch([=](){164 GMainLoopDispatch([=](){
152 g_menu_remove(m_gmenu.get(), index);165 g_menu_remove(menu.get(), index);
153 });166 });
154 }167 }
155 --index;168 --index;
@@ -201,8 +214,10 @@
201 void clear()214 void clear()
202 {215 {
203 std::lock_guard<std::recursive_mutex> lg(m_mutex);216 std::lock_guard<std::recursive_mutex> lg(m_mutex);
217 // prevent this-> from being captured
218 auto menu = m_gmenu;
204 GMainLoopDispatch([=](){219 GMainLoopDispatch([=](){
205 g_menu_remove_all(m_gmenu.get());220 g_menu_remove_all(menu.get());
206 });221 });
207 m_items.clear();222 m_items.clear();
208 }223 }

Subscribers

People subscribed via source and target branches