Class: Snarl

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

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

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

Instance Method Summary collapse

Methods included from SnarlAPI

send, to_cha

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



77
78
79
80
# File 'lib/snarl.rb', line 77

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



84
85
86
# File 'lib/snarl.rb', line 84

def self.show_message(title, msg=" ", icon=nil, timeout=DEFAULT_TIMEOUT)
  Snarl.new(title, msg, icon, timeout)
end

.versionObject

Return the current version of snarl (not the snarl gem) as a character string “1.0” format



114
115
116
117
118
119
# File 'lib/snarl.rb', line 114

def self.version
  ss = SnarlAPI::SnarlStruct.malloc
  ss.cmd = SNARL_GET_VERSION
  version = SnarlAPI.send(ss)
  "#{version >> 16}.#{version & 0xffff}"
end

Instance Method Details

#hideObject

Hide you message – this is the same as dismissing it



101
102
103
104
# File 'lib/snarl.rb', line 101

def hide
  @ss.cmd = SNARL_HIDE
  send?
end

#update(title, msg = " ", icon = nil) ⇒ 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)



91
92
93
94
95
96
97
98
# File 'lib/snarl.rb', line 91

def update(title,msg=" ",icon=nil)
  @ss.cmd = SNARL_UPDATE
  @ss.title = SnarlAPI.to_cha(title)
  @ss.text = SnarlAPI.to_cha(msg)
  icon = File.expand_path(icon)
  @ss.icon = SnarlAPI.to_cha(icon) if icon && File.exist?(icon)
  send?    
end

#visible?Boolean

Check to see if the message is still being displayed

Returns:

  • (Boolean)


107
108
109
110
# File 'lib/snarl.rb', line 107

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