uwa_download 0.1 → 0.2

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.
@@ -6,7 +6,7 @@ module UWA
6
6
  module Widget
7
7
  class Download < UWA::Handler
8
8
  NAME = 'uwa_download'
9
- VERSION = '0.1'
9
+ VERSION = '0.2'
10
10
  COPYRIGHT = 'Copyright (C) 2007 Florent Solt'
11
11
  DESC = 'UWA Download widget'
12
12
  AUTHOR = 'Florent Solt'
@@ -16,23 +16,27 @@ class Download
16
16
  end
17
17
 
18
18
  def download
19
- start(@query['uri'].strip)
19
+ start(query['uri'].strip) if bin?
20
20
  monitor
21
21
  end
22
22
 
23
23
  def monitor
24
- @threads.delete_if { |t| !t.status }
25
- self << JSON.unparse(@threads.collect do |t|
26
- [
27
- t[:download][:name],
28
- t[:download][:percent] || 0,
29
- t[:download][:speed] || 0
30
- ]
31
- end)
24
+ if bin?
25
+ @threads.delete_if { |t| !t.status }
26
+ self << JSON.unparse(@threads.collect do |t|
27
+ t[:download].values_at(:name, :percent, :speed)
28
+ end)
29
+ else
30
+ self << JSON.unparse([["You have to install #{@bin.inspect} !"]])
31
+ end
32
32
  end
33
33
 
34
34
  private
35
35
 
36
+ def bin?
37
+ system("which #{@bin} > /dev/null 2>&1")
38
+ end
39
+
36
40
  def start(uri)
37
41
  FileUtils.mkdir_p @destination
38
42
  @threads << Thread.start do
@@ -30,7 +30,9 @@ widget.onMonitor = function(values) {
30
30
  }
31
31
  for (var i=0; i<values.length; i++) {
32
32
  var li = widget.createElement('li');
33
- li.appendText(values[i][0] + ' - ' + values[i][1] + '% - ' + values[i][2]);
33
+ li.appendText(values[i][0]);
34
+ if (values[i][1]) li.appendText(' - ' + values[i][1] + '%');
35
+ if (values[i][2]) li.appendText(' - ' + values[i][2]);
34
36
  widget.monitor.appendChild(li);
35
37
  }
36
38
  }
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: uwa_download
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2007-04-06 00:00:00 +02:00
6
+ version: "0.2"
7
+ date: 2007-04-12 00:00:00 +02:00
8
8
  summary: UWA Download widget
9
9
  require_paths:
10
10
  - lib