clipboard_manager 0.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53024fd293247de67210024d61edc496a1f1ea7e
4
- data.tar.gz: e55402d00cfdbc6af25f522d3401ec0ffc9ec5a7
3
+ metadata.gz: b2e1ccd8a935cab8bb3288575e366ff8e98c4686
4
+ data.tar.gz: f2f35c43e9e62421cf189f7c472c39f4a4becf75
5
5
  SHA512:
6
- metadata.gz: ef8b740ce48668df19173deec7a232d165bad64d27f9aa5d67f66f645aa20fe07d15143f63c554be5b157034a6f7978451417660940e6a1a49082eca71b2e289
7
- data.tar.gz: 9a8be19c9b0088c72fbc353862ff229e655bb77721f66b14606d4d06667f04d0c68ff242704b7af7840f83f3be156c7809ccd2194d7801bdb20f986e2655699e
6
+ metadata.gz: e209e97dee8d3e2a85e94d920a8ae6dbcdb8aa7b3d7c4e5e92d705b70b0180861684bcb2e92e94ac799cd3e66a558c39713bc8a09a970dfef54e52ff6cfcd032
7
+ data.tar.gz: a9173364649a49516196775f7941f278f646af0c4a9d07a89c379072d477719b036a2b7c91c734019d47d71f724c3a16e7e5cc71a7721fa658349df6b961a727
data/README.rdoc CHANGED
@@ -15,6 +15,10 @@ Ruby Gtk3App Clipboard Manager.
15
15
  * espeak
16
16
  * history
17
17
 
18
+ Currently needs zenity for confirmations...
19
+ Zenity is easy to install if it's not already in your linux system.
20
+ Was just lazy on adding my own dialog for this, will fix soon.
21
+
18
22
  == INSTALL:
19
23
 
20
24
  $ sudo gem install clipboard_manager
@@ -47,9 +51,9 @@ It will run the given system command "wget.. youtube_dl... '$0' | mplayer ...",
47
51
  where $0 will be replaced by the match.
48
52
 
49
53
  The _firefox_ task will run when the clipboard text matches an amazon link.
50
- It will open the link with firfox.
54
+ It will open the link with firefox.
51
55
 
52
- The _espeak_ task will run the the clipboard text is at least 80 characters long.
56
+ The _espeak_ task will run when the clipboard text is at least 80 characters long.
53
57
  It will have espeak read the text.
54
58
 
55
59
  Currently, clipboard_manager has three tasks methods: bashit(system), firefox, and espeak.
data/config/config.yml ADDED
@@ -0,0 +1,124 @@
1
+ ---
2
+ :Help: |
3
+ Usage: gtk3app clipboardmanager [options]
4
+ Options:
5
+ --ask Ask for confirmation.
6
+ --running Start in active mode.
7
+ Default for options is true,
8
+ use no-ask and no-running for false.
9
+ :StatusTimeOut: 3
10
+ :Sleep: 750
11
+ :MaxHistory: 13
12
+ :MaxString: 60
13
+ :QrcTimeOut: 3
14
+ :QrcCommand: zbarcam --nodisplay --raw --prescale=800x800
15
+ :IsPwd: |-
16
+ \A
17
+ (?!\w+:\/\/) # not like url
18
+ (?!\/[a-z]+\/[a-z]) # not like linux path
19
+ (?![a-z]+\/[a-z]+\/) # not like relative path
20
+ (?=.*\d) # at least on diget
21
+ (?=.*[a-z]) # at least one lower case letter
22
+ (?=.*[A-Z]) # at least one upper case letter
23
+ (?=.*[^\w\s]) # at least one special character
24
+ .{4,43}$ # 4 to 43 in length
25
+ \Z
26
+ :Working: "/home/fox/.local/share/gtk3app/clipboardmanager/working.png"
27
+ :Ok: "/home/fox/.local/share/gtk3app/clipboardmanager/ok.png"
28
+ :Nope: "/home/fox/.local/share/gtk3app/clipboardmanager/nope.png"
29
+ :Ready: "/home/fox/.local/share/gtk3app/clipboardmanager/ready.png"
30
+ :Off: "/home/fox/.local/share/gtk3app/clipboardmanager/off.png"
31
+ :thing:
32
+ :HelpFile: https://github.com/carlosjhr64/clipboard_manager
33
+ :Logo: "/home/fox/.local/share/gtk3app/clipboardmanager/logo.png"
34
+ :about_dialog:
35
+ :set_program_name: Clipboard Manager
36
+ :set_version: 1.0.1
37
+ :set_copyright: "(c) 2014 CarlosJHR64"
38
+ :set_comments: 'A Ruby Gtk3App Clipboard Manager '
39
+ :set_website: https://github.com/carlosjhr64/clipboard_manager
40
+ :set_website_label: See it at GitHub!
41
+ :DO_TOGGLE:
42
+ - Toggle On/Off
43
+ :do_toggle!:
44
+ - :DO_TOGGLE
45
+ - activate
46
+ :DO_HISTORY:
47
+ - History
48
+ :do_history!:
49
+ - :DO_HISTORY
50
+ - activate
51
+ :DO_QRCODE:
52
+ - QR-Code
53
+ :do_qrcode!:
54
+ - :DO_QRCODE
55
+ - activate
56
+ :window:
57
+ :set_title: Clipboard Manager
58
+ :set_window_position: :center
59
+ :VBOX:
60
+ - :vertical
61
+ :vbox: &1 {}
62
+ :vbox!:
63
+ - :VBOX
64
+ - :vbox
65
+ :ASK:
66
+ - Ask For Confirmation
67
+ :ask: *1
68
+ :ask!:
69
+ - :ASK
70
+ - :ask
71
+ :RUNNING:
72
+ - On/Off
73
+ :running: *1
74
+ :running!:
75
+ - :RUNNING
76
+ - :running
77
+ :TASKS:
78
+ - 'Tasks:'
79
+ :tasks: *1
80
+ :tasks!:
81
+ - :TASKS
82
+ - :tasks
83
+ :HISTORY_BUTTON:
84
+ - :label: History
85
+ :history_button: *1
86
+ :history_button!:
87
+ - :HISTORY_BUTTON
88
+ - :history_button
89
+ :HISTORY_DIALOG: &2 []
90
+ :history_dialog:
91
+ :set_window_position: :center
92
+ :history_dialog!:
93
+ - :HISTORY_DIALOG
94
+ - :history_dialog
95
+ :HISTORY_COMBO: *2
96
+ :history_combo: *1
97
+ :history_combo!:
98
+ - :HISTORY_COMBO
99
+ - :history_combo
100
+ :QRCODE_BUTTON:
101
+ - :label: QR-Code
102
+ :qrcode_button: *1
103
+ :qrcode_button!:
104
+ - :QRCODE_BUTTON
105
+ - :qrcode_button
106
+ :QUESTION_DIALOG: *2
107
+ :question_dialog:
108
+ :set_window_position: :center
109
+ :set_keep_above: true
110
+ :question_dialog!:
111
+ - :question_dialog
112
+ - :QUESTION_DIALOG
113
+ :tasks:
114
+ :mplayer:
115
+ - "(https?://www\\.youtube\\.com/watch\\?v=[\\w\\-]+)"
116
+ - :bashit
117
+ - wget --quiet -O - $(youtube-dl -f 5/36/17/18 -g '$1') | mplayer -really-quiet
118
+ -cache 8192 -cache-min 1 -
119
+ :firefox:
120
+ - "^https?://www.amazon.com/"
121
+ - :firefox
122
+ :espeak:
123
+ - ".{80,}"
124
+ - :espeak
data/data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 1.0.1
@@ -1,5 +1,17 @@
1
+ # Standard Libraries
2
+ require 'timeout'
3
+
4
+ # Work gems
5
+ require 'gtk3app'
6
+
7
+ # This Gem
1
8
  require_relative 'clipboard_manager/version.rb'
2
9
  require_relative 'clipboard_manager/config.rb'
3
10
  require_relative 'clipboard_manager/clipboard_manager.rb'
11
+
4
12
  # Requires:
5
13
  #`ruby`
14
+ #`zbarcam`
15
+ #`firefox`
16
+ #`espeak`
17
+ #`system`
@@ -1,9 +1,26 @@
1
1
  module ClipboardManager
2
2
  using Rafini::Exception
3
3
 
4
+ class Dialog < Such::Dialog
5
+ def initialize(*par)
6
+ super
7
+ add_button(Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL)
8
+ add_button(Gtk::Stock::OK, Gtk::ResponseType::OK)
9
+ end
10
+
11
+ def runs
12
+ show_all
13
+ response = run
14
+ response = yield(response)
15
+ destroy
16
+ return response
17
+ end
18
+ end
19
+
4
20
  def self.options=(opts)
5
21
  @@options=opts
6
22
  end
23
+
7
24
  def self.options
8
25
  @@options
9
26
  end
@@ -16,7 +33,6 @@ class ClipboardManager
16
33
  CLIPBOARD = Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD)
17
34
 
18
35
  def initialize(program)
19
- @program = program
20
36
  @image = program.mini.children.first
21
37
  @timer = nil
22
38
 
@@ -28,28 +44,15 @@ class ClipboardManager
28
44
 
29
45
  @is_pwd = Regexp.new(CONFIG[:IsPwd], Regexp::EXTENDED)
30
46
 
31
-
32
- program.mini_menu.append_menu_item(:toggle!){toggle}
33
- status(@ready)
34
-
35
- @history, @previous = [], nil
36
- request_text do |text|
37
- if text
38
- add_history text
39
- @previous = text
40
- end
41
- Rafini.thread_bang!{cycle}
42
- end
43
-
44
47
  window = program.window
45
48
  vbox = Such::Box.new window, :vbox!
46
49
 
47
- @ask = Such::CheckButton.new vbox, :ask!
48
- @ask.active = ::ClipboardManager.options[:ask, true]
49
-
50
50
  @running = Such::CheckButton.new(vbox, :running!, 'toggled'){toggled}
51
51
  @running.active = ::ClipboardManager.options[:running, true]
52
52
 
53
+ @ask = Such::CheckButton.new vbox, :ask!
54
+ @ask.active = ::ClipboardManager.options[:ask, true]
55
+
53
56
  Such::Label.new vbox, :tasks!
54
57
 
55
58
  @checks = {}
@@ -57,16 +60,33 @@ class ClipboardManager
57
60
  @checks[key] = Such::CheckButton.new(vbox, [key.to_s.capitalize], {set_active: true})
58
61
  end
59
62
 
60
- Such::Button.new(vbox, :history_button!){do_history}
63
+ Such::Button.new(vbox, :history_button!){do_history!}
64
+ Such::Button.new(vbox, :qrcode_button!){do_qrcode!}
65
+
66
+ mm = program.mini_menu
67
+ mm.append_menu_item(:do_toggle!){do_toggle!}
68
+ mm.append_menu_item(:do_history!){do_history!}
69
+ mm.append_menu_item(:do_qrcode!){do_qrcode!}
61
70
 
71
+ @history, @previous = [], nil
72
+ request_text do |text|
73
+ if text
74
+ add_history text
75
+ @previous = text
76
+ end
77
+ GLib::Timeout.add(CONFIG[:Sleep]) do
78
+ step if @running.active?
79
+ true # repeat
80
+ end
81
+ end
82
+
83
+ status(@ready)
62
84
  window.show_all
63
85
  end
64
86
 
65
87
  # https://github.com/ruby-gnome2/ruby-gnome2/blob/master/gtk3/sample/misc/dialog.rb
66
- def do_history
67
- dialog = Such::Dialog.new :history_dialog!
68
- dialog.add_button(Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL)
69
- dialog.add_button(Gtk::Stock::OK, Gtk::ResponseType::OK)
88
+ def do_history!
89
+ dialog = Dialog.new :history_dialog!
70
90
  combo = Such::ComboBoxText.new dialog.child, :history_combo!
71
91
  @history.each do |str|
72
92
  if str.length > CONFIG[:MaxString]
@@ -75,19 +95,48 @@ class ClipboardManager
75
95
  end
76
96
  combo.append_text(str)
77
97
  end
78
- dialog.show_all
79
- if dialog.run==Gtk::ResponseType::OK and combo.active_text
80
- @previous = nil
81
- CLIPBOARD.text = @history[combo.active]
98
+ dialog.runs do |response|
99
+ if response==Gtk::ResponseType::OK and combo.active_text
100
+ @previous = nil
101
+ CLIPBOARD.text = @history[combo.active]
102
+ end
103
+ end
104
+ end
105
+
106
+ def do_qrcode!
107
+ qrcode = nil
108
+ IO.popen(CONFIG[:QrcCommand], 'r') do |io|
109
+ begin
110
+ Timeout.timeout(CONFIG[:QrcTimeOut]) do
111
+ qrcode = io.gets.strip
112
+ end
113
+ rescue Timeout::Error
114
+ $!.puts 'QrcTimeOut'
115
+ ensure
116
+ Process.kill('INT', io.pid)
117
+ end
118
+ end
119
+ if qrcode.nil?
120
+ CLIPBOARD.clear
121
+ status(@nope)
122
+ else
123
+ CLIPBOARD.text = qrcode
124
+ status(@ok)
82
125
  end
83
- dialog.destroy
126
+ end
127
+
128
+ def question?(name)
129
+ return true unless @ask.active?
130
+ dialog = Dialog.new :question_dialog!
131
+ Such::Label.new dialog.child, ["Run #{name}?"]
132
+ dialog.runs{|response| (response==Gtk::ResponseType::OK)}
84
133
  end
85
134
 
86
135
  def toggled
87
136
  @running.active? ? status(@ready) : status(@off)
88
137
  end
89
138
 
90
- def toggle
139
+ def do_toggle!
91
140
  request_text do |text|
92
141
  @previous = text
93
142
  @running.active = !@running.active?
@@ -106,15 +155,8 @@ class ClipboardManager
106
155
  @timer = Time.now
107
156
  end
108
157
 
109
- def cycle
110
- while true
111
- step if @running.active?
112
- sleep CONFIG[:Sleep]
113
- end
114
- end
115
-
116
158
  def step
117
- if @timer and Time.now - @timer > CONFIG[:TimeOut]
159
+ if @timer and Time.now - @timer > CONFIG[:StatusTimeOut]
118
160
  @timer = nil
119
161
  status @ready
120
162
  end
@@ -122,7 +164,10 @@ class ClipboardManager
122
164
  unless text.nil? or @previous == text
123
165
  @previous = text
124
166
  status @working
125
- Rafini.thread_bang!{manage(text)}
167
+ GLib::Timeout.add(0) do
168
+ manage(text)
169
+ false # don't repeat
170
+ end
126
171
  end
127
172
  end
128
173
  end
@@ -147,7 +192,7 @@ class ClipboardManager
147
192
  espeak(text)
148
193
  when :firefox
149
194
  firefox(text)
150
- when :system
195
+ when :bashit
151
196
  bashit(md, str)
152
197
  else
153
198
  raise "Method #{mth} not implemented."
@@ -155,7 +200,7 @@ class ClipboardManager
155
200
  status(@ok)
156
201
  rescue RuntimeError
157
202
  $!.puts
158
- status(@nope) # TODO it's not just nope!
203
+ status(@nope)
159
204
  end
160
205
  return
161
206
  end
@@ -163,26 +208,21 @@ class ClipboardManager
163
208
  status(@nope)
164
209
  end
165
210
 
166
- def question?(wut)
167
- @ask.active? ? system("zenity --question --text='#{wut}'") : true
168
- end
169
-
170
211
  def espeak(text)
171
- IO.popen('espeak --stdin', 'w'){|e|e.puts text.strip}
212
+ Rafini.thread_bang!{IO.popen('espeak --stdin', 'w'){|e|e.puts text.strip}}
172
213
  end
173
214
 
174
215
  def firefox(text)
175
- raise "not a url" unless text =~ /^https?:\/\/\S+$/
176
216
  raise "quote not allowed in url" if text =~ /'/
177
- system("firefox '#{text}' &")
217
+ Process.detach spawn "firefox '#{text}'"
178
218
  end
179
219
 
180
220
  def bashit(md, str)
181
221
  (md.length-1).downto(0) do |i|
182
222
  str = str.gsub(/\$#{i}/, md[i])
183
- $stderr.puts str if $VERBOSE
184
- system str
185
223
  end
224
+ $stderr.puts str
225
+ Process.detach spawn str
186
226
  end
187
227
 
188
228
  end
@@ -1,6 +1,6 @@
1
1
  module ClipboardManager
2
2
 
3
- help = <<-HELP # TODO
3
+ help = <<-HELP
4
4
  Usage: gtk3app clipboardmanager [options]
5
5
  Options:
6
6
  --ask Ask for confirmation.
@@ -30,11 +30,14 @@ use no-ask and no-running for false.
30
30
  CONFIG = {
31
31
  Help: help,
32
32
 
33
- TimeOut: 3,
34
- Sleep: 0.5,
33
+ StatusTimeOut: 3,
34
+ Sleep: 750,
35
35
  MaxHistory: 13,
36
36
  MaxString: 60,
37
37
 
38
+ QrcTimeOut: 3,
39
+ QrcCommand: 'zbarcam --nodisplay --raw --prescale=800x800',
40
+
38
41
  IsPwd: is_pwd,
39
42
 
40
43
  Working: "#{XDG['DATA']}/gtk3app/clipboardmanager/working.png",
@@ -57,8 +60,14 @@ use no-ask and no-running for false.
57
60
  set_website_label: 'See it at GitHub!',
58
61
  },
59
62
 
60
- TOGGLE: ['Toggle On/Off'],
61
- toggle!: [:TOGGLE, 'activate'],
63
+ DO_TOGGLE: ['Toggle On/Off'],
64
+ do_toggle!: [:DO_TOGGLE, 'activate'],
65
+
66
+ DO_HISTORY: ['History'],
67
+ do_history!: [:DO_HISTORY, 'activate'],
68
+
69
+ DO_QRCODE: ['QR-Code'],
70
+ do_qrcode!: [:DO_QRCODE, 'activate'],
62
71
 
63
72
  window: {
64
73
  set_title: "Clipboard Manager",
@@ -85,21 +94,34 @@ use no-ask and no-running for false.
85
94
  history_button: h0,
86
95
  history_button!: [:HISTORY_BUTTON, :history_button],
87
96
 
88
- HISTORY_DIALOG: [],
89
- history_dialog: {},
97
+ HISTORY_DIALOG: a0,
98
+ history_dialog: {
99
+ set_window_position: :center,
100
+ },
90
101
  history_dialog!: [:HISTORY_DIALOG, :history_dialog],
91
102
 
92
- HISTORY_COMBO: [],
93
- history_combo: {},
103
+ HISTORY_COMBO: a0,
104
+ history_combo: h0,
94
105
  history_combo!: [:HISTORY_COMBO, :history_combo],
106
+
107
+ QRCODE_BUTTON: [label: 'QR-Code'],
108
+ qrcode_button: h0,
109
+ qrcode_button!: [:QRCODE_BUTTON, :qrcode_button],
110
+
111
+ QUESTION_DIALOG: a0,
112
+ question_dialog: {
113
+ set_window_position: :center,
114
+ set_keep_above: true,
115
+ },
116
+ question_dialog!: [:question_dialog, :QUESTION_DIALOG],
95
117
  },
96
118
 
97
119
  # Note that Ruby 2 hashes preserves order, and order here is important.
98
120
  tasks: {
99
121
  mplayer: [
100
- 'https?://www\.youtube\.com/\S+',
101
- :system,
102
- "wget -O - $(youtube-dl -f 5/36/17/18 -g '$0') | mplayer -really-quiet -cache 8192 -cache-min 1 - &",
122
+ '(https?://www\.youtube\.com/watch\?v=[\w\-]+)',
123
+ :bashit,
124
+ "wget --quiet -O - $(youtube-dl -f 5/36/17/18 -g '$1') | mplayer -really-quiet -cache 8192 -cache-min 1 -",
103
125
  ],
104
126
  firefox: ['^https?://www.amazon.com/', :firefox],
105
127
  espeak: ['.{80,}', :espeak],
@@ -1,3 +1,3 @@
1
1
  module ClipboardManager
2
- VERSION = '0.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipboard_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - carlosjhr64
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-29 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gtk3app
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
13
33
  description: |
14
34
  Ruby Gtk3App Clipboard Manager.
15
35
  email: carlosjhr64@gmail.com
@@ -19,6 +39,7 @@ extra_rdoc_files:
19
39
  - README.rdoc
20
40
  files:
21
41
  - README.rdoc
42
+ - config/config.yml
22
43
  - data/VERSION
23
44
  - data/logo.png
24
45
  - data/nope.png
@@ -52,8 +73,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
73
  version: '0'
53
74
  requirements:
54
75
  - 'ruby: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]'
55
- - 'zenity: 3.8.0'
76
+ - 'zbarcam: 0.10'
56
77
  - 'firefox: Mozilla Firefox 33.1'
78
+ - 'espeak: eSpeak text-to-speech: 1.47.11 03.May.13 Data at: /usr/share/espeak-data'
57
79
  - 'system: linux/bash'
58
80
  rubyforge_project:
59
81
  rubygems_version: 2.4.1