Class: Libnotify::API

Inherits:
Object
  • Object
show all
Includes:
FFI
Defined in:
lib/libnotify/api.rb

Overview

API for Libnotify

See Also:

Constant Summary

ICON_REGEX =

TODO refactor & test!

/(\d+)x\d/
ICON_SORTER =
proc do |a, b|
  ma = a.scan ICON_REGEX
  mb = b.scan ICON_REGEX

  if ma.first && mb.first
    mb.first.first.to_i <=> ma.first.first.to_i
  elsif ma.first && !mb.first
    1
  elsif !ma.first && ma.first
    -1
  else
    a <=> b
  end
end

Constants included from FFI

FFI::URGENCY

Class Attribute Summary (collapse)

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from FFI

attach_functions!, included, load_libs, #lookup_urgency, #method_missing

Constructor Details

- (API) initialize(options = {}, &block)

Creates a notification object.

See Also:



43
44
45
46
# File 'lib/libnotify/api.rb', line 43

def initialize(options={}, &block)
  set_defaults
  apply_options(options, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Libnotify::FFI

Class Attribute Details

+ (Object) icon_dirs

List of globs to icons



15
16
17
# File 'lib/libnotify/api.rb', line 15

def icon_dirs
  @icon_dirs
end

Instance Attribute Details

- (Object) append

Returns the value of attribute append



11
12
13
# File 'lib/libnotify/api.rb', line 11

def append
  @append
end

- (Object) body

Returns the value of attribute body



11
12
13
# File 'lib/libnotify/api.rb', line 11

def body
  @body
end

- (Object) icon_path

Returns the value of attribute icon_path



10
11
12
# File 'lib/libnotify/api.rb', line 10

def icon_path
  @icon_path
end

- (Object) summary

Returns the value of attribute summary



11
12
13
# File 'lib/libnotify/api.rb', line 11

def summary
  @summary
end

- (Object) timeout

Returns the value of attribute timeout



10
11
12
# File 'lib/libnotify/api.rb', line 10

def timeout
  @timeout
end

- (Object) transient

Returns the value of attribute transient



11
12
13
# File 'lib/libnotify/api.rb', line 11

def transient
  @transient
end

- (Object) urgency

Returns the value of attribute urgency



11
12
13
# File 'lib/libnotify/api.rb', line 11

def urgency
  @urgency
end

Class Method Details

+ (Object) show(options = {}, &block)

Creates and shows a notification. It's a shortcut for Libnotify.new(options).show!.



141
142
143
# File 'lib/libnotify/api.rb', line 141

def self.show(options={}, &block)
  new(options, &block).show!
end

Instance Method Details

- (Object) close

Close a previously shown notification.



95
96
97
# File 'lib/libnotify/api.rb', line 95

def close
  notify_notification_close(@notification, nil) if @notification
end

- (Object) show!

Shows a notification.

See Also:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/libnotify/api.rb', line 66

def show!
  notify_init(self.class.to_s) or raise "notify_init failed"
  @notification = notify_notification_new(summary, body, icon_path, nil)
  notify_notification_set_urgency(@notification, lookup_urgency(urgency))
  notify_notification_set_timeout(@notification, timeout || -1)
  if append
    notify_notification_set_hint_string(@notification, "x-canonical-append", "")
    notify_notification_set_hint_string(@notification, "append", "")
  end
  if transient
    notify_notification_set_hint_uint32(@notification, "transient", 1)
  end
  notify_notification_show(@notification, nil)
ensure
  notify_notification_clear_hints(@notification) if (append || transient)
end

- (Object) update(options = {}, &block)

Updates a previously shown notification.



84
85
86
87
88
89
90
91
92
# File 'lib/libnotify/api.rb', line 84

def update(options={}, &block)
  apply_options(options, &block)
  if @notification
    notify_notification_update(@notification, summary, body, icon_path, nil)
    notify_notification_show(@notification, nil)
  else
    show!
  end
end