Class: Knj::Notify

Inherits:
Object show all
Defined in:
lib/knj/notify.rb

Overview

This class can be used to send notify-messages through the notify-binary (notify-send or kdialog).

Class Method Summary collapse

Class Method Details

.send(args) ⇒ Object

Call this method to show notifications.

Examples

Knj::Notify.send(“msg” => “Hello world!”, “time” => 5)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/knj/notify.rb', line 6

def self.send(args)
  begin
    toolkit = Knj::Os.toolkit
  rescue
    toolkit = ""
  end
  
  if toolkit == "kde"
    cmd = "kdialog --passivepopup #{Knj::Strings.unixsafe(args["msg"])}"
    
    if args["title"]
      cmd << " --title #{Knj::Strings.unixsafe(args["msg"])}"
    end
    
    if args["time"]
      cmd << " #{Knj::Strings.unixsafe(args["time"])}"
    end
    
    system(cmd)
  else
    cmd = "notify-send"
    
    if args["time"]
      raise "Time is not numeric." if !(Float(args["time"]) rescue false)
      cmd << " -t #{args["time"]}"
    end
    
    cmd << " #{Knj::Strings.unixsafe(args["title"])} #{Knj::Strings.unixsafe(args["msg"])}"
    system(cmd)
  end
end