Class: Snarl

Inherits:
Object
  • Object
show all
Includes:
SnarlAPI
Defined in:
lib/snarl.rb

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

Instance Method Summary collapse

Methods included from SnarlAPI

send, to_cha

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, *options)
  # allow both ways of calling it...
	if options && !options[0].is_a?(Hash)
	  options2 = {}
	  options2[:msg] = options.shift
	  options2[:timeout] = options.shift
	  options2[:icon] = options.shift
	  raise unless options.empty?
	 options = options2
else
  options = options[0] || {}
end
options = {:snarl_class => nil, :msg => " ", :timeout => DEFAULT_TIMEOUT, :icon => nil, :extra => nil}.merge(options)

if options[:extra] && options[:snarl_class].nil? then raise ArgumentError.new("Must specificy a snarl_class to use sound notifications") end
	
if options[:snarl_class].nil? then
  	@ss = SnarlStruct.new
  	show(title, options)
	else
@ss = SnarlStructEx.new
show(title, options)
	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.show_message(title, options = {:snarl_class => nil, :msg => " ", :timeout => DEFAULT_TIMEOUT, :icon => nil, :extra => nil})
  Snarl.new(title, options)
end

.versionObject

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

.versionexObject

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

#hideObject

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.expand_path(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

Returns:

  • (Boolean)


234
235
236
237
# File 'lib/snarl.rb', line 234

def visible?
  @ss.cmd = SNARL_IS_VISIBLE
  send?
end