ruby_do_plugin_execute_application 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -1,6 +1,38 @@
1
1
  class Ruby_do_plugin_execute_application < Ruby_do::Plugin::Base
2
- def initialize(*args, &block)
3
- super(*args, &block)
2
+ def start
3
+ #Scan XDG-dirs for .desktop application files.
4
+ dirs_scanned = []
5
+ @results_found = []
6
+ @debug = false
7
+
8
+ #Do this in thread to avoid locking app.
9
+ Thread.new do
10
+ begin
11
+ ENV["XDG_DATA_DIRS"].split(":").each do |val|
12
+ val = val.to_s.gsub("//", "/").gsub(/\/$/, "")
13
+
14
+ next if dirs_scanned.index(val) != nil
15
+ dirs_scanned << val
16
+
17
+ path = "#{val}/applications"
18
+ self.scan_dir(path) if File.exists?(path)
19
+ end
20
+
21
+ #Delete static results which were not found after scanning.
22
+ self.rdo_plugin_args[:rdo].ob.list(:Static_result, "plugin_id" => self.model.id, "id_not" => @results_found) do |sres|
23
+ print "Deleting result because it not longer exists: '#{sres[:id_str]}'.\n" if @debug
24
+ self.rdo_plugin_args[:rdo].ob.delete(sres)
25
+ end
26
+ rescue => e
27
+ $stderr.puts "Error when updating 'execute_application'-plugin."
28
+ $stderr.puts e.inspect
29
+ $stderr.puts e.backtrace
30
+ end
31
+ end
32
+ end
33
+
34
+ def load_icons
35
+ print "Loading icons.\n" if @debug
4
36
 
5
37
  #Find icon-paths to scan for icons.
6
38
  @icon_paths = []
@@ -9,14 +41,6 @@ class Ruby_do_plugin_execute_application < Ruby_do::Plugin::Base
9
41
  self.scan_icon_dir("/usr/share/icons")
10
42
 
11
43
  @icon_exts = ["png", "xpm", "svg"]
12
-
13
-
14
- #Scan XDG-dirs for .desktop application files.
15
- @apps = []
16
- ENV["XDG_DATA_DIRS"].split(":").each do |val|
17
- path = "#{val}/applications"
18
- self.scan_dir(path) if File.exists?(path)
19
- end
20
44
  end
21
45
 
22
46
  def scan_icon_dir(path)
@@ -53,13 +77,21 @@ class Ruby_do_plugin_execute_application < Ruby_do::Plugin::Base
53
77
  end
54
78
 
55
79
  def scan_dir(path)
80
+ print "Path: #{path}\n" if @debug
81
+
56
82
  Dir.foreach(path) do |file|
57
83
  next if file[0, 1] == "."
58
- fp = "#{path}/#{file}"
84
+ fp = "#{path}/#{file}".gsub("//", "/")
59
85
 
60
86
  if File.directory?(fp)
61
87
  self.scan_dir(fp)
62
88
  else
89
+ if sres = self.static_result_get(fp) and fp.to_s.downcase.index("poedit") == nil
90
+ @results_found << sres.id
91
+ print "Skipping because exists: #{fp}\n" if @debug
92
+ next
93
+ end
94
+
63
95
  cont = File.read(fp)
64
96
 
65
97
  data = {}
@@ -67,19 +99,28 @@ class Ruby_do_plugin_execute_application < Ruby_do::Plugin::Base
67
99
  data[match[0].to_s.downcase] = match[1]
68
100
  end
69
101
 
102
+ if !data["name"] or !data["exec"]
103
+ print "Skipping because no name or no exec: #{fp}\n" if @debug
104
+ next
105
+ end
106
+
70
107
  icon_paths = []
71
108
  icon_path = nil
72
109
 
73
- if icon = data["icon"]
74
- if File.exists?(icon)
75
- icon_path = icon
76
- else
110
+ [data["icon"], data["name"]].each do |icon|
111
+ next if icon.to_s.strip.empty?
112
+
113
+ if icon
114
+ icon_paths << icon if File.exists?(icon)
115
+
116
+ self.load_icons if !@icon_paths
77
117
  @icon_paths.each do |path|
118
+ icon_fp = "#{path}/#{icon}"
119
+ icon_paths << icon_fp if File.exists?(icon_fp)
120
+
78
121
  @icon_exts.each do |ext|
79
- fp = "#{path}/#{icon}.#{ext}"
80
- if File.exists?(fp)
81
- icon_paths << fp
82
- end
122
+ icon_fp = "#{path}/#{icon}.#{ext}"
123
+ icon_paths << icon_fp if File.exists?(icon_fp)
83
124
  end
84
125
  end
85
126
  end
@@ -90,15 +131,19 @@ class Ruby_do_plugin_execute_application < Ruby_do::Plugin::Base
90
131
  icon_path = icon_paths.first
91
132
  end
92
133
 
93
- if data["name"] and data["exec"]
94
- @apps << {
95
- :name => data["name"],
96
- :namel => data["name"].to_s.downcase,
97
- :exec => data["exec"],
98
- :icon => icon,
99
- :icon_path => icon_path
134
+ print "Registering: #{fp}\n" if @debug
135
+ exec_data = data["exec"].gsub("%U", "").gsub("%F", "").strip
136
+ res = self.register_static_result(
137
+ :id_str => fp,
138
+ :title => data["name"],
139
+ :descr => sprintf(_("Open the application: '%1$s' with the command '%2$s'."), data["name"], exec_data),
140
+ :icon_path => icon_path,
141
+ :data => {
142
+ :exec => exec_data
100
143
  }
101
- end
144
+ )
145
+
146
+ @results_found << res[:sres].id
102
147
  end
103
148
  end
104
149
  end
@@ -109,33 +154,8 @@ class Ruby_do_plugin_execute_application < Ruby_do::Plugin::Base
109
154
  }
110
155
  end
111
156
 
112
- def on_search(args)
113
- return Enumerator.new do |yielder|
114
- @apps.each do |app|
115
- found_all = true
116
- args[:words].each do |word|
117
- if app[:namel].index(word) == nil
118
- found_all = false
119
- break
120
- end
121
- end
122
-
123
- if found_all
124
- yielder << Ruby_do::Plugin::Result.new(
125
- :plugin => self,
126
- :title => app[:name],
127
- :title_html => "<b>#{Knj::Web.html(app[:name])}</b>",
128
- :descr => sprintf(_("Open the application: '%1$s' with the command '%2$s'."), app[:name], app[:exec]),
129
- :exec => app[:exec],
130
- :icon => app[:icon_path]
131
- )
132
- end
133
- end
134
- end
135
- end
136
-
137
- def execute_result(args)
138
- Knj::Os.subproc(args[:res].args[:exec])
157
+ def execute_static_result(args)
158
+ Knj::Os.subproc(args[:sres].data[:exec])
139
159
  return :close_win_main
140
160
  end
141
161
  end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ruby_do_plugin_execute_application}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kasper Johansen"]
12
+ s.date = %q{2012-07-11}
13
+ s.description = %q{A plugin for Ruby-Do that executes installed applications.}
14
+ s.email = %q{k@spernj.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/ruby_do_plugin_execute_application.rb",
29
+ "ruby_do_plugin_execute_application.gemspec",
30
+ "spec/ruby_do_plugin_execute_application_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/kaspernj/ruby_do_plugin_execute_application}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.6.2}
37
+ s.summary = %q{A plugin for Ruby-Do that executes installed applications.}
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<ruby_do>, [">= 0"])
44
+ s.add_runtime_dependency(%q<knjrbfw>, [">= 0"])
45
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
46
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
49
+ else
50
+ s.add_dependency(%q<ruby_do>, [">= 0"])
51
+ s.add_dependency(%q<knjrbfw>, [">= 0"])
52
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<ruby_do>, [">= 0"])
59
+ s.add_dependency(%q<knjrbfw>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
61
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
62
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
64
+ end
65
+ end
66
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ruby_do_plugin_execute_application
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.0
5
+ version: 0.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-07-09 00:00:00 +02:00
13
+ date: 2012-07-11 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -98,6 +98,7 @@ files:
98
98
  - Rakefile
99
99
  - VERSION
100
100
  - lib/ruby_do_plugin_execute_application.rb
101
+ - ruby_do_plugin_execute_application.gemspec
101
102
  - spec/ruby_do_plugin_execute_application_spec.rb
102
103
  - spec/spec_helper.rb
103
104
  has_rdoc: true
@@ -114,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
116
  - - ">="
116
117
  - !ruby/object:Gem::Version
117
- hash: 2764426103137546546
118
+ hash: 802253384185664232
118
119
  segments:
119
120
  - 0
120
121
  version: "0"