#!/usr/bin/ruby
require 'kconv'
require 'gtk'
require 'thread'
## constants.
Logdir = "/home/tshm/.madoka/log/" # dir path of the log needs "/" ending
CheckString = /> / # regex to look for in the last line of the log
Timer = 30 # sleep time until the next check
Hybernate = 60*60 # sleep time after the user has dismissed the window
Notify_command = 'system("wavp /usr/X11R6/lib/X11/qvwm/sounds/chimes.wav >/dev/null 2>&1")'
# font setting
Gtk::RC::parse_string <<EOS
style "default"
{
fontset = "-adobe-helvetica-medium-r-normal--14-*-*-*-*-*-*-*,-*-fixed-medium-r-normal--14-*"
}
widget_class "*" style "default"
EOS
class Notifier
def initialize
recently_checked = false
m = Mutex::new()
date = Time.now.strftime("%Y%m%d")
# interface creation
window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
window.set_title('Message!!')
window.signal_connect('destroy') {Gtk.main_quit}
window.border_width = 5
label = Gtk::Label.new('test')
button = Gtk::Button.new('Dismiss')
button.signal_connect('clicked') {
window.hide_all()
m.synchronize{recently_checked=true}
}
vbox = Gtk::VBox.new(false,5)
vbox.pack_start(label, true, true)
vbox.pack_start(button)
window.add(vbox)
button.grab_focus()
# main loop ("check and sleep" infinite cycle)
Thread.start do
while (true)
lastline = IO::readlines(Logdir+"log"+Time.now.strftime("%Y%m%d"))[-1]
if (lastline =~ CheckString)
label.set_text(Kconv::toeuc(lastline))
window.show_all()
window.queue_draw()
eval(Notify_command)
end
sleep(Timer)
if recently_checked
sleep(Hybernate)
m.synchronize{recently_checked=false}
end
end
end
end
end
Notifier.new
Gtk.main