public
Created

Modem tray notifier

  • Download Gist
prctl.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
require 'fiddle'
 
def set_process_name name
RUBY_PLATFORM =~ /linux/ or return
Fiddle::Function.new(
DL::Handle['prctl'], [
Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP,
Fiddle::TYPE_LONG, Fiddle::TYPE_LONG,
Fiddle::TYPE_LONG
], Fiddle::TYPE_INT
).call(15, name.to_s, 0, 0, 0)
end
trayicon.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/env ruby
# encoding: utf-8
trap ("HUP") { puts "Hupped!"; }
require 'Qt4'
require 'open-uri'
#require './prctl'
class HuaweiTrayIcon < Qt::SystemTrayIcon
def initialize()
super(Qt::Icon.new("smallhua.gif"))
@@me = self
menu = Qt::Menu.new("Huawei E5830 Status")
setContextMenu(menu)
ma = Qt::Action.new("&Quit", nil)
Qt::Object::connect(ma, SIGNAL('triggered()'), $qApp, SLOT('quit()'))
menu.addAction(ma)
 
timer = Qt::Timer.new(self) do
connect(SIGNAL :timeout) { @@me.show_notification }
end
 
timer.start 20_000
end
 
def event(e)
super
show_notification true
end
 
def show_notification(force=false)
network_types = ["No network available", "GSM","GPRS","EDGE","WCDMA","HSDPA","HSUPA","HSPA"]
begin
open("http://195.198.1.1/en/conn.asp").read.lines do |line|
if /^var sysinfo = \[\d,\d,\d,\d,\d,\d,(?<network_index>\d)\];$/ =~ line
@@network = network_types[network_index.to_i]
end
if /^var ppp_state = (?<ppp_state>\d);$/ =~ line
@@ppp = ppp_state == "1"
end
end
rescue Exception => exc
@@network = "No response from Huawei E5830: " + exc.message.force_encoding("UTF-8")
@@ppp = false
end
 
if force || @@network != @@old_network || @@ppp != @@old_ppp
message = @@network + (@@ppp ? ": <font color=green>✔" : ": <font color=red>✘")
%x{notify-send -i 'dialog-information' 'Huawei E5830 Status' '#{message}'}
@@old_ppp = @@ppp
@@old_network = @@network
end
end
end
 
a = Qt::Application.new(ARGV)
icon = HuaweiTrayIcon.new
icon.show
 
a.exec()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.