From 0e97af6891a00c41cd43705f9fb0d91f21cbe947 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Tue, 16 Jun 2009 18:38:11 +0200 Subject: [PATCH] Implement notification. --- lib/board/example.rb | 7 ++---- lib/board/notify.rb | 12 +++++++++ lib/board/user.rb | 4 ++- lib/ics/driver.rb | 8 +++--- lib/kaya.notifyrc | 19 ++++++++++++++ lib/themes/shogi/shogi.rb | 64 +++++++++++++++++++++++------------------------ 6 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 lib/board/notify.rb create mode 100644 lib/kaya.notifyrc rewrite lib/themes/shogi/shogi.rb (100%) diff --git a/lib/board/example.rb b/lib/board/example.rb index bc2ebce..841f82f 100644 --- a/lib/board/example.rb +++ b/lib/board/example.rb @@ -8,11 +8,8 @@ require 'history' description = "KDE Board Game Suite" version = "1.5" -about = KDE::AboutData.new("tagua", "Tagua", KDE.ki18n("Tagua"), - version, KDE.ki18n(description),KDE::AboutData::License_GPL,KDE.ki18n("(C) 2003 whoever the author is")) - -about.addAuthor(KDE.ki18n("author1"), KDE.ki18n("whatever they did"), "email@somedomain") -about.addAuthor(KDE.ki18n("author2"), KDE.ki18n("they did something else"), "another@email.address") +about = KDE::AboutData.new("kaya", "Kaya", KDE.ki18n("Kaya"), + version, KDE.ki18n(description), KDE::AboutData::License_GPL, KDE.ki18n("(C) 2009 Paolo Capriotti")) KDE::CmdLineArgs.init(ARGV, about) diff --git a/lib/board/notify.rb b/lib/board/notify.rb new file mode 100644 index 0000000..689d7e9 --- /dev/null +++ b/lib/board/notify.rb @@ -0,0 +1,12 @@ +class Notify + def initialize(window) + @window = window + end + + def [](events) + events.each do |event, text| + KDE::Notification.event(event.to_s, text, + Qt::Pixmap.new, @window) + end + end +end \ No newline at end of file diff --git a/lib/board/user.rb b/lib/board/user.rb index 89c4259..06464ca 100644 --- a/lib/board/user.rb +++ b/lib/board/user.rb @@ -7,9 +7,10 @@ class User attr_accessor :color - def initialize(color, board) + def initialize(color, board, notify) @color = color @board = board + @notify = notify end def reset(match) @@ -26,5 +27,6 @@ class User def on_move(data) @board.forward(data[:state], data[:move]) + @notify[:move => "A new move has been played"] end end diff --git a/lib/ics/driver.rb b/lib/ics/driver.rb index 81c1ff4..2693383 100644 --- a/lib/ics/driver.rb +++ b/lib/ics/driver.rb @@ -9,6 +9,7 @@ require 'ics/connection' require 'ics/protocol' require 'console' require 'board/user' +require 'board/notify' require 'ics/match_handler' protocol = ICS::Protocol.new(:debug) @@ -20,8 +21,8 @@ protocol.link_to c description = "KDE Board Game Suite" version = "1.5" -about = KDE::AboutData.new("tagua", "Tagua", KDE.ki18n("Tagua"), - version, KDE.ki18n(description),KDE::AboutData::License_GPL,KDE.ki18n("(C) 2003 whoever the author is")) +about = KDE::AboutData.new("kaya", "Kaya", KDE.ki18n("Kaya"), + version, KDE.ki18n(description),KDE::AboutData::License_GPL,KDE.ki18n("(C) 2009 Paolo Capriotti")) KDE::CmdLineArgs.init(ARGV, about) @@ -77,7 +78,8 @@ end # c.send_text m # end -user = User.new(:white, board) +notify = Notify.new(table) +user = User.new(:white, board, notify) handler = ICS::MatchHandler.new(user, protocol) protocol.observe :creating_game do |data| diff --git a/lib/kaya.notifyrc b/lib/kaya.notifyrc new file mode 100644 index 0000000..b81c490 --- /dev/null +++ b/lib/kaya.notifyrc @@ -0,0 +1,19 @@ +[Global] +IconName=kaya +Comment=Kaya + +[Context/game] +Name=game +Comment=A game played on a server + +[Event/newGame] +Name=New Game +Comment=A new game has started +Contexts=game +Action=Sound|Taskbar + +[Event/move] +Name=New Move +Comment=A new move has been played +Contexts=game +Action=Taskbar diff --git a/lib/themes/shogi/shogi.rb b/lib/themes/shogi/shogi.rb dissimilarity index 100% index 5102068..e5ed2bc 100644 --- a/lib/themes/shogi/shogi.rb +++ b/lib/themes/shogi/shogi.rb @@ -1,32 +1,32 @@ -# require 'qtutils' -# require 'themes/theme' -# -# class FantasyTheme -# include Theme -# BASE_DIR = File.dirname(__FILE__) -# TYPES = { :knight => 'n' } -# NUDE_TILE = File.join(BASE_DIR, 'nude_tile.svg') -# -# theme :name => 'Shogi' -# -# def pixmap(piece, size) -# tile = Qt::SvgRenderer.new(NUDE_TILE) -# kanji = Qt::SvgRenderer.new(filename(piece)) -# img = Qt::Image.painted(size) do |p| -# if piece.color == :white -# p.translate(size) -# p.rotate(180) -# end -# kanji.render(p) -# tile.render(p) -# end -# img.to_pix -# end -# -# def filename(piece) -# color = piece.color.to_s[0, 1] -# # type = TYPES[piece.type] || piece.type.to_s[0, 1] -# name = piece.type.to_s + ".svg" -# File.join(BASE_DIR, name) -# end -# end +require 'qtutils' +require 'themes/theme' + +class ShogiTheme + include Theme + BASE_DIR = File.dirname(__FILE__) + TYPES = { :knight => 'n' } + NUDE_TILE = File.join(BASE_DIR, 'nude_tile.svg') + + theme :name => 'Shogi' + + def pixmap(piece, size) + tile = Qt::SvgRenderer.new(NUDE_TILE) + kanji = Qt::SvgRenderer.new(filename(piece)) + img = Qt::Image.painted(size) do |p| + if piece.color == :white + p.translate(size) + p.rotate(180) + end + kanji.render(p) + tile.render(p) + end + img.to_pix + end + + def filename(piece) + color = piece.color.to_s[0, 1] +# type = TYPES[piece.type] || piece.type.to_s[0, 1] + name = piece.type.to_s + ".svg" + File.join(BASE_DIR, name) + end +end -- 2.11.4.GIT