#!/usr/bin/env ruby
# encoding: UTF-8
=begin
Copyright 2010 Guillermo Gómez Savino
you can redistribute this example and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
=end
require 'rubygems'
require 'cgi'
require 'restclient'
require 'json'
require 'sequel'
if !File.exist?("updates.sqlite")
# Si la DB no existe, entonces debo crear el esquema
require 'schema.rb'
else
# Si ya existe, sólo establezco la conexión
DB = Sequel.connect('sqlite://updates.sqlite')
end
require 'update.rb'
require 'uqlog.rb'
require 'gtk2'
require 'RNotify'
si=Gtk::StatusIcon.new
si.stock=Gtk::Stock::DIALOG_INFO
th0 = Thread.new {
loop do
puts "comencé a las #{Time.now.to_s}"
Update.query_source
si.tooltip=Update.count.to_s + " packages for testing"
puts "terminé a las #{Time.now.to_s}"
sleep(3600)
#end
}
###**************************###
## Handle left click on icon
###**************************###
si.signal_connect('activate'){|icon| icon.blinking=!(icon.blinking?)
#th0.run
}
###**************************###
## Pop up menu on rigth click
###**************************###
##Build a menu
info=Gtk::ImageMenuItem.new(Gtk::Stock::INFO)
info.signal_connect('activate'){p "Embedded: #{si.embedded?}"
p "Visible: #{si.visible?}"
p "Blinking: #{si.blinking?}"}
quit=Gtk::ImageMenuItem.new(Gtk::Stock::QUIT)
quit.signal_connect('activate'){Gtk.main_quit}
#menu=Gtk::Menu.new
#menu.append(info)
#menu.append(Gtk::SeparatorMenuItem.new)
#menu.append(quit)
#menu.show_all
##Show menu on rigth click
si.signal_connect('popup-menu'){|tray, button, time| menu.popup(nil, nil, button, time)}
###**************************###
## Handle scroll events
#* Need a recent gtk version (>=2.16 ?)
###**************************###
si.signal_connect('scroll-event'){|icon, event|
modifier=event.state#A GdkModifierType indicating the state of modifier keys and mouse buttons
##Handle only control and shift key
ctrl_shift=(Gdk::Window::CONTROL_MASK|Gdk::Window::SHIFT_MASK)
mod=modifier&ctrl_shift
case mod
when 0
print "(None)"
when Gdk::Window::CONTROL_MASK
print "Control+"
when Gdk::Window::SHIFT_MASK
print "Shift+"
when (Gdk::Window::CONTROL_MASK|Gdk::Window::SHIFT_MASK)
print "Control+Shift+"
end
##Check for direction
case event.direction
when Gdk::EventScroll::UP
print "up\n"
when Gdk::EventScroll::DOWN
print "down\n"
end
}
if not(Update.empty?)
Notify.init("newupdate")
update = Update.dataset.order(:date_pushed).last
test = Notify::Notification.new(update[:title], "Nuevo updates-testing", nil, nil)
test.timeout= Notify::Notification::EXPIRES_NEVER
test.signal_connect("closed") { Gtk.main_quit }
test.add_action("Click Me action", "Instalar", "bye!!") do |action, data|
puts "#{action} - #{data}"
Gtk.main_quit
end
test.add_action("Click Me action2", "Karma +1", "bye!!") do |action, data|
puts "#{action} - #{data}"
Gtk.main_quit
end
test.add_action("Click Me action2", "Karma -1", "bye!!") do |action, data|
puts "#{action} - #{data}"
Gtk.main_quit
end
icon = Gdk::Pixbuf.new(File.dirname(__FILE__) + "/icon.png")
#st = Gtk::StatusIcon.new
#st.pixbuf=icon
test.pixbuf_icon=icon
test.show
end
###**************************###
## Main loop
###**************************###
#require 'scheduler.rb'
#
Gtk.main
test.clear_actions
test.close
Notify.uninit