Created
September 25, 2012 22:15
-
-
Save Pipeliner/3784802 to your computer and use it in GitHub Desktop.
Modem tray notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment