From 96aa795618f3bd6969e4a91252e7a11c694c968b Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sun, 14 Sep 2014 15:05:28 +0100 Subject: [PATCH] Adding Touch Menu Wifi Status icon/Toggler for Kobo and Kindle. Change to NetworkMgr:getWifiStatus() to ping default gateway instead of 8.8.8.8. --- frontend/ui/networkmgr.lua | 14 +++++++++----- frontend/ui/widget/touchmenu.lua | 30 +++++++++++++++++++++++++++++- resources/icons/appbar.wifi.png | Bin 0 -> 484 bytes 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 resources/icons/appbar.wifi.png diff --git a/frontend/ui/networkmgr.lua b/frontend/ui/networkmgr.lua index e7bc98819..68a765eff 100644 --- a/frontend/ui/networkmgr.lua +++ b/frontend/ui/networkmgr.lua @@ -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 diff --git a/frontend/ui/widget/touchmenu.lua b/frontend/ui/widget/touchmenu.lua index 815c8fca0..7888324a9 100644 --- a/frontend/ui/widget/touchmenu.lua +++ b/frontend/ui/widget/touchmenu.lua @@ -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() diff --git a/resources/icons/appbar.wifi.png b/resources/icons/appbar.wifi.png new file mode 100644 index 0000000000000000000000000000000000000000..ce702a9bd01d1d18d969788496ad9328fa81a05e GIT binary patch literal 484 zcmV!Dd526g^WBLU@#Z zKs7`tp@irsL|0jbtU?GOvg!wvd_h*FloCQ#S+<*Q+EupQglH+Hg#1A{UA&q1X6D^_ z)m@`^HTT>(_q}`W+!;mu&JM8ugo23j6~Kv-W1dZ`cCtg7?OB;dk zkzec9C!GGI&Y44awnLpqlkL7^dD)Us_z9AeNq(RXtiO4Y_(r%eSGx|j& z_@bRV6TMCZsNW`-M%DypPRDP2bxfYvn-TFciqVNA=p>Gnp;Q8S24~B-sPr zoTD)cckNO-OSLrKUhc@{rN^;TaKfcp{ aknjywKGSX2xFUZ50000