Class: Snarl
Defined Under Namespace
Modules: SnarlAPI
Constant Summary collapse
- DEFAULT_TIMEOUT =
3
- NO_TIMEOUT =
0
Constants included from SnarlAPI
SnarlAPI::BASE, SnarlAPI::CreateWindow, SnarlAPI::DestroyWindow, SnarlAPI::HWND_MESSAGE, SnarlAPI::SNARL_ASK_APPLET_VER, SnarlAPI::SNARL_EX_SHOW, SnarlAPI::SNARL_GET_VERSION, SnarlAPI::SNARL_GET_VERSION_EX, SnarlAPI::SNARL_GLOBAL_MSG, SnarlAPI::SNARL_HIDE, SnarlAPI::SNARL_IS_VISIBLE, SnarlAPI::SNARL_LAUNCHED, SnarlAPI::SNARL_NOTIFICATION_ACK, SnarlAPI::SNARL_NOTIFICATION_CANCLED, SnarlAPI::SNARL_NOTIFICATION_CLICKED, SnarlAPI::SNARL_NOTIFICATION_TIMED_OUT, SnarlAPI::SNARL_QUIT, SnarlAPI::SNARL_REGISTER_ALERT, SnarlAPI::SNARL_REGISTER_CONFIG_WINDOW, SnarlAPI::SNARL_REGISTER_CONFIG_WINDOW_2, SnarlAPI::SNARL_REVOKE_ALERT, SnarlAPI::SNARL_REVOKE_CONFIG_WINDOW, SnarlAPI::SNARL_SET_TIMEOUT, SnarlAPI::SNARL_SHOW, SnarlAPI::SNARL_SHOW_APP_UP, SnarlAPI::SNARL_TEXT_LENGTH, SnarlAPI::SNARL_UPDATE, SnarlAPI::WM_COPYDATA, SnarlAPI::WM_USER
Class Method Summary collapse
-
.show_message(title, options = {:snarl_class => nil, :msg => " ", :timeout => DEFAULT_TIMEOUT, :icon => nil, :extra => nil}) ⇒ 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.
-
.versionex ⇒ Object
Return the current build number of snarl (not the snarl gem) If zero will call the original version.
Instance Method Summary collapse
-
#hide ⇒ Object
Hide you message – this is the same as dismissing it.
-
#initialize(title, *options) ⇒ 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, *options) ⇒ 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.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/snarl.rb', line 173 def initialize(title, *) # allow both ways of calling it... if && ![0].is_a?(Hash) = {} [:msg] = .shift [:timeout] = .shift [:icon] = .shift raise unless .empty? = else = [0] || {} end = {:snarl_class => nil, :msg => " ", :timeout => DEFAULT_TIMEOUT, :icon => nil, :extra => nil}.merge() if [:extra] && [:snarl_class].nil? then raise ArgumentError.new("Must specificy a snarl_class to use sound notifications") end if [:snarl_class].nil? then @ss = SnarlStruct.new show(title, ) else @ss = SnarlStructEx.new show(title, ) end end |
Class Method Details
.show_message(title, options = {:snarl_class => nil, :msg => " ", :timeout => DEFAULT_TIMEOUT, :icon => nil, :extra => nil}) ⇒ 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.
204 205 206 |
# File 'lib/snarl.rb', line 204 def self.(title, = {:snarl_class => nil, :msg => " ", :timeout => DEFAULT_TIMEOUT, :icon => nil, :extra => nil}) Snarl.new(title, ) end |
.version ⇒ Object
Return the current version of snarl (not the snarl gem) as a character string “1.0” format
241 242 243 244 245 246 |
# File 'lib/snarl.rb', line 241 def self.version ss = SnarlAPI::SnarlStruct.new ss.cmd = SNARL_GET_VERSION version = SnarlAPI.send(ss) "#{version >> 16}.#{version & 0xffff}" end |
.versionex ⇒ Object
Return the current build number of snarl (not the snarl gem) If zero will call the original version.
250 251 252 253 254 255 256 257 258 259 |
# File 'lib/snarl.rb', line 250 def self.versionex ssx = SnarlAPI::SnarlStructEx.new ssx.cmd = SNARL_GET_VERSION_EX versionex = SnarlAPI.send(ssx); if versionex == 0 then self.version else "#{versionex}" end end |
Instance Method Details
#hide ⇒ Object
Hide you message – this is the same as dismissing it
228 229 230 231 |
# File 'lib/snarl.rb', line 228 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.
215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/snarl.rb', line 215 def update(title,msg=" ",icon=nil, timeout=DEFAULT_TIMEOUT) @ss.cmd = SNARL_UPDATE @ss.set_title(title) @ss.set_text(msg) if icon icon = File.(icon) @ss.set_icon(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
234 235 236 237 |
# File 'lib/snarl.rb', line 234 def visible? @ss.cmd = SNARL_IS_VISIBLE send? end |