Merge pull request #899 from gontofe/WifiMenuToggle

Adding Touch Menu Wifi Status icon/Toggler for Kobo and Kindle.
pull/902/merge
Huang Xin 10 years ago
commit 786d300953

@ -72,11 +72,15 @@ function NetworkMgr:promptWifiOff()
end
function NetworkMgr:getWifiStatus()
if os.execute("ping -c3 8.8.8.8") == 0 then
return true
else
return false
end
local default_string = io.popen("ip r | grep default")
local result = default_string:read()
if result ~= nil then
local gateway = string.match(result,"%d+.%d+.%d+.%d+")
if os.execute("ping -q -c1 "..gateway) == 0 then
return true
end -- ping to gateway
end -- test for empty string
return false
end
return NetworkMgr

@ -20,6 +20,7 @@ local Geom = require("ui/geometry")
local Font = require("ui/font")
local DEBUG = require("dbg")
local _ = require("gettext")
local NetworkMgr = require("ui/networkmgr")
--[[
TouchMenuItem widget
@ -314,10 +315,28 @@ function TouchMenu:init()
self.page_info_text,
self.page_info_right_chev
}
--group for device info
self.time_info = TextWidget:new{
text = "",
face = self.fface,
}
if Device:isKindle() or Device:isKobo() then
self.net_info = Button:new{
icon = "resources/icons/appbar.wifi.png",
callback = function() self:netToggle() end,
bordersize = 0,
show_parent = self,
}
self.net_info.label_widget.dim = not NetworkMgr:getWifiStatus()
self.device_info = HorizontalGroup:new{
self.time_info,
self.net_info,
}
else
self.device_info = HorizontalGroup:new{
self.time_info,
}
end
local footer_width = self.width - self.padding*2 - self.bordersize*2
self.footer = HorizontalGroup:new{
LeftContainer:new{
@ -337,7 +356,7 @@ function TouchMenu:init()
},
RightContainer:new{
dimen = Geom:new{ w = footer_width*0.33, h = self.footer_height},
self.time_info,
self.device_info,
}
}
@ -435,6 +454,15 @@ function TouchMenu:updateItems()
UIManager.repaint_all = true
end
function TouchMenu:netToggle()
if NetworkMgr:getWifiStatus() == true then
NetworkMgr:promptWifiOff()
else
NetworkMgr:promptWifiOn()
end
self:closeMenu()
end
function TouchMenu:switchMenuTab(tab_num)
if self.tab_item_table[tab_num].callback then
self.tab_item_table[tab_num].callback()

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

Loading…
Cancel
Save