Только у меня нотификации нет? (в консоль вывод падает) Причём раньше работало в таком виде. KDE: 4.4.5, Qt: 4.6.3, ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux].
#!/usr/bin/env ruby
# encoding: UTF-8
if RUBY_VERSION < '1.9'
$KCODE = 'u'
end
require 'Qt4'
class Main_window < Qt::MainWindow
def initialize(parent = nil)
super
init_dbus!
init_tray_icon!
show_message('Some test message here.')
self
end
private
def init_dbus!
@bus = Qt::DBusConnection::session_bus
unless @bus.connected?
$stderr.puts 'No session bus found. Stopped.'
exit(1)
end
@notify = Qt::DBusInterface.new(
'org.freedesktop.Notifications',
'/org/freedesktop/Notifications',
'org.freedesktop.Notifications',
@bus
)
unless @notify.valid?
$stderr.puts 'Unable to found required D-Bus service. Stopped.'
exit(2)
end
self
end
def init_tray_icon!
@tray = Qt::SystemTrayIcon.new(self.style.standard_icon(Qt::Style::SP_MediaPlay), self)
@tray.tool_tip = 'XMMS2 song change notifier'
@menu = Qt::Menu.new(self)
@action_quit = Qt::Action.new(self.style.standard_icon(Qt::Style::SP_DialogCloseButton), 'Quit', @menu)
Qt::Object.connect(@action_quit, SIGNAL(:activated), self, SLOT(:close))
@menu.add_action(@action_quit)
@tray.context_menu = @menu
@tray.visible = true
self
end
def show_message(message)
unless message.empty?
$stdout.puts message
@notify.call_with_argument_list(
Qt::DBus::NoBlock,
'Notify',
[
'XMMS2 notify', Qt::Variant.fromValue(0, 'uint'),
'media-playback-start',
'Now playing', message,
[], {}, 5000
]
)
end
self
end
end
application = Qt::Application.new(ARGV)
main_window = Main_window.new
application.exec