Class: Snarl
Overview
Snarl (www.fullphat.net/snarl.html) is a simple notification system, similar to Growl under OSX. This is a simple pure Ruby wrapper to the native API (using DL).
Defined Under Namespace
Modules: SnarlAPI
Constant Summary collapse
- DEFAULT_TIMEOUT =
3
- NO_TIMEOUT =
0
Constants included from SnarlAPI
SnarlAPI::CopyDataStruct, SnarlAPI::SNARL_GET_VERSION, SnarlAPI::SNARL_HIDE, SnarlAPI::SNARL_IS_VISIBLE, SnarlAPI::SNARL_REGISTER_CONFIG_WINDOW, SnarlAPI::SNARL_REVOKE_CONFIG_WINDOW, SnarlAPI::SNARL_SHOW, SnarlAPI::SNARL_TEXT_LENGTH, SnarlAPI::SNARL_UPDATE, SnarlAPI::SnarlStruct, SnarlAPI::WM_COPYDATA
Class Method Summary collapse
-
.show_message(title, msg = " ", icon = nil, timeout = DEFAULT_TIMEOUT) ⇒ Object
a quick and easy method to create a new message, when you don’t care to access it again.
-
.version ⇒ Object
Return the current version of snarl (not the snarl gem) as a character string “1.0” format.
Instance Method Summary collapse
-
#hide ⇒ Object
Hide you message – this is the same as dismissing it.
-
#initialize(title, msg = " ", icon = nil, timeout = DEFAULT_TIMEOUT) ⇒ Snarl
constructor
Create a new snarl message, the only thing you need to send is a title note that if you decide to send an icon, you must provide the complete path.
-
#update(title, msg = " ", icon = nil, timeout = DEFAULT_TIMEOUT) ⇒ Object
Update an existing message, it will return true/false depending upon success (it will fail if the message has already timed out or been dismissed) Note that if you decide to send an icon, you must provide the complete path.
-
#visible? ⇒ Boolean
Check to see if the message is still being displayed.
Methods included from SnarlAPI
Constructor Details
#initialize(title, msg = " ", icon = nil, timeout = DEFAULT_TIMEOUT) ⇒ Snarl
Create a new snarl message, the only thing you need to send is a title note that if you decide to send an icon, you must provide the complete path. The timeout file has a default value (DEFAULT_TIMEOUT -> 3 seconds) but can be set to Snarl::NO_TIMEOUT, to force a manual acknowledgement of the notification.
80 81 82 83 |
# File 'lib/snarl.rb', line 80 def initialize(title, msg=" ", icon=nil, timeout=DEFAULT_TIMEOUT) @ss = SnarlStruct.malloc show(title, msg, icon, timeout) end |
Class Method Details
.show_message(title, msg = " ", icon = nil, timeout = DEFAULT_TIMEOUT) ⇒ Object
a quick and easy method to create a new message, when you don’t care to access it again. Note that if you decide to send an icon, you must provide the complete path. The timeout file has a default value (DEFAULT_TIMEOUT -> 3 seconds) but can be set to Snarl::NO_TIMEOUT, to force a manual acknowledgement of the notification.
91 92 93 |
# File 'lib/snarl.rb', line 91 def self.(title, msg=" ", icon=nil, timeout=DEFAULT_TIMEOUT) Snarl.new(title, msg, icon, timeout) end |
.version ⇒ Object
Return the current version of snarl (not the snarl gem) as a character string “1.0” format
128 129 130 131 132 133 |
# File 'lib/snarl.rb', line 128 def self.version ss = SnarlAPI::SnarlStruct.malloc ss.cmd = SNARL_GET_VERSION version = SnarlAPI.send(ss) "#{version >> 16}.#{version & 0xffff}" end |
Instance Method Details
#hide ⇒ Object
Hide you message – this is the same as dismissing it
115 116 117 118 |
# File 'lib/snarl.rb', line 115 def hide @ss.cmd = SNARL_HIDE send? end |
#update(title, msg = " ", icon = nil, timeout = DEFAULT_TIMEOUT) ⇒ Object
Update an existing message, it will return true/false depending upon success (it will fail if the message has already timed out or been dismissed) Note that if you decide to send an icon, you must provide the complete path. The timeout file has a default value (DEFAULT_TIMEOUT -> 3 seconds) but can be set to Snarl::NO_TIMEOUT, to force a manual acknowledgement of the notification.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/snarl.rb', line 102 def update(title,msg=" ",icon=nil, timeout=DEFAULT_TIMEOUT) @ss.cmd = SNARL_UPDATE @ss.title = SnarlAPI.to_cha(title) @ss.text = SnarlAPI.to_cha(msg) if icon icon = File.(icon) @ss.icon = SnarlAPI.to_cha(icon) if File.exist?(icon.to_s) end @ss.timeout = timeout send? end |
#visible? ⇒ Boolean
Check to see if the message is still being displayed
121 122 123 124 |
# File 'lib/snarl.rb', line 121 def visible? @ss.cmd = SNARL_IS_VISIBLE send? end |