knjrbfw 0.0.38 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.38
1
+ 0.0.39
data/knjrbfw.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjrbfw}
8
- s.version = "0.0.38"
8
+ s.version = "0.0.39"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
data/lib/knj/datet.rb CHANGED
@@ -512,10 +512,25 @@ class Knj::Datet
512
512
  end
513
513
 
514
514
  #Returns the day of the year (0-365) as an integer.
515
+ #===Examples
516
+ # Knj::Datet.new.day_of_year #=> 123
515
517
  def day_of_year
516
518
  return @time.strftime("%j").to_i
517
519
  end
518
520
 
521
+ #Returns the day as a localized string.
522
+ #===Examples
523
+ # Knj::Datet.new.day_str #=> "Monday"
524
+ # Knj::Datet.new.day_str(:short => true) #=> "Mon"
525
+ def day_str(args = nil)
526
+ ret = Knj::Datet.days_arr[@time.strftime("%w").to_i]
527
+ if args.is_a?(Hash) and args[:short]
528
+ ret = ret.slice(0, 3)
529
+ end
530
+
531
+ return ret
532
+ end
533
+
519
534
  #Returns how many days there is between the two timestamps given as an integer.
520
535
  #===Examples
521
536
  # d1 = Knj::Datet.new #=> 2012-05-03 18:04:12 +0200
data/lib/knj/gtk2_cb.rb CHANGED
@@ -11,7 +11,7 @@ end
11
11
  class Gtk::ComboBox
12
12
  def init(items)
13
13
  @knj = {
14
- "items" => []
14
+ :items => []
15
15
  }
16
16
 
17
17
  ls = Gtk::ListStore.new(String, String)
@@ -25,30 +25,29 @@ class Gtk::ComboBox
25
25
 
26
26
  if appendob.is_a?(String)
27
27
  iter[0] = appendob
28
- elsif appendob.respond_to?("is_knj?")
28
+ elsif appendob.respond_to?(:is_knj?)
29
29
  iter[0] = appendob.title
30
- @knj["items"] << {
31
- "iter" => iter,
32
- "object" => appendob
30
+ @knj[:items] << {
31
+ :iter => iter,
32
+ :object => appendob
33
33
  }
34
34
  end
35
35
  end
36
36
  else
37
- raise "Unsupported type: " + items.class.to_s
37
+ raise "Unsupported type: '#{items.class.name}'."
38
38
  end
39
39
 
40
40
  self.model = ls
41
-
42
41
  self.active = 0
43
42
  end
44
43
 
45
44
  def sel
46
45
  iter = self.active_iter
47
46
 
48
- if @knj["items"].length > 0
49
- @knj["items"].each do |item|
50
- if item["iter"] == iter
51
- return item["object"]
47
+ if @knj[:items].length > 0
48
+ @knj[:items].each do |item|
49
+ if item[:iter] == iter
50
+ return item[:object]
52
51
  end
53
52
  end
54
53
 
@@ -62,10 +61,10 @@ class Gtk::ComboBox
62
61
  end
63
62
 
64
63
  def sel=(actob)
65
- if actob.respond_to?("is_knj?")
66
- @knj["items"].each do |item|
67
- if item["object"].id == actob.id
68
- self.active_iter = item["iter"]
64
+ if actob.respond_to?(:is_knj?)
65
+ @knj[:items].each do |item|
66
+ if item[:object].id == actob.id
67
+ self.active_iter = item[:iter]
69
68
  return nil
70
69
  end
71
70
  end
@@ -80,6 +79,6 @@ class Gtk::ComboBox
80
79
  end
81
80
  end
82
81
 
83
- raise "Could not find such a row: " + textval
82
+ raise "Could not find such a row: '#{actob}'."
84
83
  end
85
84
  end
data/lib/knj/notify.rb CHANGED
@@ -1,13 +1,37 @@
1
+ #This class can be used to send notify-messages through the notify-binary (notify-send or kdialog).
1
2
  class Knj::Notify
3
+ #Call this method to show notifications.
4
+ #===Examples
5
+ # Knj::Notify.send("msg" => "Hello world!", "time" => 5)
2
6
  def self.send(args)
3
- cmd = "notify-send"
4
-
5
- if args["time"]
6
- raise "Time is not numeric." if !Php.is_numeric(args["time"])
7
- cmd << " -t " + args["time"].to_s
7
+ begin
8
+ toolkit = Knj::Os.toolkit
9
+ rescue
10
+ toolkit = ""
8
11
  end
9
12
 
10
- cmd << " " + Strings.UnixSafe(args["title"]) + " " + Strings.UnixSafe(args["msg"])
11
- system(cmd)
13
+ if toolkit == "kde"
14
+ cmd = "kdialog --passivepopup #{Knj::Strings.unixsafe(args["msg"])}"
15
+
16
+ if args["title"]
17
+ cmd << " --title #{Knj::Strings.unixsafe(args["msg"])}"
18
+ end
19
+
20
+ if args["time"]
21
+ cmd << " #{Knj::Strings.unixsafe(args["time"])}"
22
+ end
23
+
24
+ system(cmd)
25
+ else
26
+ cmd = "notify-send"
27
+
28
+ if args["time"]
29
+ raise "Time is not numeric." if !Knj::Php.is_numeric(args["time"])
30
+ cmd << " -t #{args["time"]}"
31
+ end
32
+
33
+ cmd << " #{Knj::Strings.unixsafe(args["title"])} #{Knj::Strings.unixsafe(args["msg"])}"
34
+ system(cmd)
35
+ end
12
36
  end
13
37
  end
data/lib/knj/os.rb CHANGED
@@ -68,8 +68,17 @@ module Knj::Os
68
68
  end
69
69
  end
70
70
 
71
- def self.mode
72
- raise "stub!"
71
+ #Returns the current graphical toolkit running.
72
+ #===Examples
73
+ # Knj::Os.toolkit #=> 'kde'
74
+ def self.toolkit
75
+ if self.os == "linux"
76
+ if ENV["DESKTOP_SESSION"].index("plasma") != nil
77
+ return "kde"
78
+ end
79
+ end
80
+
81
+ raise "Could not figure out the toolkit."
73
82
  end
74
83
 
75
84
  def self.class_exist(classstr)
data/lib/knj/thread.rb CHANGED
@@ -2,9 +2,9 @@
2
2
  class Knj::Thread < Thread
3
3
  attr_accessor :data
4
4
 
5
+ #Initializes the thread and passes any given arguments to the thread-block.
5
6
  def initialize(*args)
6
- @data = {}
7
- raise "No block was given." if !block_given?
7
+ raise "No block was given." unless block_given?
8
8
 
9
9
  super(*args) do
10
10
  begin
@@ -12,15 +12,19 @@ class Knj::Thread < Thread
12
12
  rescue SystemExit
13
13
  exit
14
14
  rescue Exception => e
15
- print Knj::Errors.error_str(e)
15
+ print "#{Knj::Errors.error_str(e)}\n\n"
16
16
  end
17
17
  end
18
+
19
+ @data = {}
18
20
  end
19
21
 
22
+ #Returns a key from the data-hash.
20
23
  def [](key)
21
24
  return @data[key]
22
25
  end
23
26
 
27
+ #Sets a key on the data-hash.
24
28
  def []=(key, value)
25
29
  return @data[key] = value
26
30
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjrbfw
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.38
5
+ version: 0.0.39
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -374,7 +374,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
374
374
  requirements:
375
375
  - - ">="
376
376
  - !ruby/object:Gem::Version
377
- hash: 2653248264753354168
377
+ hash: -4326648523750519043
378
378
  segments:
379
379
  - 0
380
380
  version: "0"