Class: Libnotify::API

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

Overview

API for Libnotify

See Also:

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, #method_missing

Constructor Details

#initialize(options = {}, &block) ⇒ API

Creates a notification object.

See Also:



27
28
29
30
# File 'lib/libnotify/api.rb', line 27

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

.icon_dirsObject

List of globs to icons



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

def icon_dirs
  @icon_dirs
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



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

def app_name
  @app_name
end

#appendObject

Returns the value of attribute append.



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

def append
  @append
end

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#icon_pathObject

Returns the value of attribute icon_path.



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

def icon_path
  @icon_path
end

#summaryObject

Returns the value of attribute summary.



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

def summary
  @summary
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

#transientObject

Returns the value of attribute transient.



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

def transient
  @transient
end

#urgencyObject

Returns the value of attribute urgency.



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

def urgency
  @urgency
end

Class Method Details

.show(options = {}, &block) ⇒ Object

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



124
125
126
# File 'lib/libnotify/api.rb', line 124

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

Instance Method Details

#closeObject

Close a previously shown notification.



80
81
82
# File 'lib/libnotify/api.rb', line 80

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

#showObject

Shows an existing notification.



59
60
61
62
63
64
65
66
# File 'lib/libnotify/api.rb', line 59

def show
  notify_notification_set_urgency(@notification, urgency)
  notify_notification_set_timeout(@notification, timeout || -1)
  set_hints
  notify_notification_show(@notification, nil)
ensure
  clear_hints
end

#show!Object

Shows a new notification.

See Also:



51
52
53
54
55
56
# File 'lib/libnotify/api.rb', line 51

def show!
  notify_init(app_name) or raise "notify_init failed"
  raw_ptr = notify_notification_new(summary, body, icon_path, nil)
  @notification = ::FFI::AutoPointer.new(raw_ptr, method(:g_object_unref))
  show
end

#update(options = {}, &block) ⇒ Object

Updates a previously shown notification or creates a new one.



69
70
71
72
73
74
75
76
77
# File 'lib/libnotify/api.rb', line 69

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