ratchet 0.3.0

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.
Files changed (49) hide show
  1. data/gem_bin/ratchet +23 -0
  2. data/lib/ratchet.rb +613 -0
  3. data/lib/ratchet/aliases.rb +106 -0
  4. data/lib/ratchet/bufferparser.rb +409 -0
  5. data/lib/ratchet/commandbuffer.rb +66 -0
  6. data/lib/ratchet/commandparser.rb +668 -0
  7. data/lib/ratchet/configuration.rb +278 -0
  8. data/lib/ratchet/connections.rb +403 -0
  9. data/lib/ratchet/constants.rb +111 -0
  10. data/lib/ratchet/contrib/instance_exec.rb +21 -0
  11. data/lib/ratchet/eventparser.rb +486 -0
  12. data/lib/ratchet/gtk/bufferlistview.rb +514 -0
  13. data/lib/ratchet/gtk/bufferview.rb +167 -0
  14. data/lib/ratchet/gtk/configwindow.rb +229 -0
  15. data/lib/ratchet/gtk/connectionwindow.rb +218 -0
  16. data/lib/ratchet/gtk/keybinding.rb +356 -0
  17. data/lib/ratchet/gtk/linkwindow.rb +137 -0
  18. data/lib/ratchet/gtk/mainwindow.rb +504 -0
  19. data/lib/ratchet/gtk/networkpresenceconf.rb +567 -0
  20. data/lib/ratchet/gtk/pluginconfig.rb +94 -0
  21. data/lib/ratchet/gtk/pluginwindow.rb +146 -0
  22. data/lib/ratchet/gtk/userlistview.rb +161 -0
  23. data/lib/ratchet/help.rb +64 -0
  24. data/lib/ratchet/items.rb +271 -0
  25. data/lib/ratchet/lines.rb +63 -0
  26. data/lib/ratchet/networks.rb +652 -0
  27. data/lib/ratchet/plugins.rb +616 -0
  28. data/lib/ratchet/queue.rb +47 -0
  29. data/lib/ratchet/ratchet-version.rb +21 -0
  30. data/lib/ratchet/replies.rb +134 -0
  31. data/lib/ratchet/replyparser.rb +441 -0
  32. data/lib/ratchet/tabcomplete.rb +98 -0
  33. data/lib/ratchet/users.rb +237 -0
  34. data/lib/ratchet/utils.rb +178 -0
  35. data/share/defaults.yaml +169 -0
  36. data/share/glade/config.glade +2634 -0
  37. data/share/glade/connect.glade +950 -0
  38. data/share/glade/keybindings.glade +109 -0
  39. data/share/glade/linkwindow.glade +188 -0
  40. data/share/glade/mainwindow.glade +335 -0
  41. data/share/glade/network-presences.glade +1373 -0
  42. data/share/glade/pluginconf.glade +97 -0
  43. data/share/glade/plugins.glade +360 -0
  44. data/share/plugins/colorewrite.rb +193 -0
  45. data/share/plugins/highlighter.rb +115 -0
  46. data/share/plugins/mpdplay.rb +123 -0
  47. data/share/plugins/numberswitcher.rb +30 -0
  48. data/share/plugins/sysinfo.rb +82 -0
  49. metadata +96 -0
@@ -0,0 +1,356 @@
1
+ =begin
2
+ This file is part of the Ratchet project, a client for Icecap.
3
+ Copyright (C) 2005-6 Andrew Thompson
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the Free Software
17
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ =end
19
+
20
+ #### keybinding.rb
21
+ # The Keybinding window and a mixin to allow converting GTK key events to strings
22
+ ####
23
+
24
+
25
+ module Ratchet
26
+ module KeyBind
27
+ def event_to_string(event)
28
+ mods = []
29
+ if (event.state & Gdk::Window::MOD1_MASK) != 0
30
+ mods.push('Alt')
31
+ end
32
+ if (event.state & Gdk::Window::CONTROL_MASK) != 0
33
+ mods.push('Ctrl')
34
+ end
35
+ if (event.state & Gdk::Window::SHIFT_MASK) != 0
36
+ mods.push('Shift')
37
+ end
38
+
39
+ return false if mods.empty?
40
+
41
+ key = Gdk::Keyval.to_name(event.keyval)
42
+
43
+ x = (mods.push(key)).join('-')
44
+
45
+ return x
46
+ end
47
+ end
48
+
49
+ class KeyBindingWindow < SingleWindow
50
+ include KeyBind
51
+ attr_accessor :sizegroups
52
+ def initialize(main, bindings, methods)
53
+ @main = main
54
+ @config = @main.config
55
+ @glade = GladeXML.new("#{DATADIR}/glade/keybindings.glade") {|handler| method(handler)}
56
+ @window = @glade['keywindow']
57
+ @grabkeys = false
58
+ @keybox = @glade['keybox']
59
+ @tooltips = Gtk::Tooltips.new
60
+ @meths = methods
61
+ @rows = []
62
+ @sizegroups = []
63
+ 5.times do
64
+ @sizegroups.push(Gtk::SizeGroup.new(Gtk::SizeGroup::HORIZONTAL))
65
+ end
66
+
67
+ @fakerow = FakeKeyBindingRow.new(self, @meths)
68
+
69
+ @title = Gtk::HBox.new
70
+
71
+ ['', 'Key Combo', 'Action', 'Arguments'].each_with_index do |x, i|
72
+ w = Gtk::Label.new(x)
73
+ @title.add(w)
74
+ @sizegroups[i].add_widget(w)
75
+ end
76
+
77
+ @keybox.pack_start(@title, false, false)
78
+ @keybox.pack_start(@fakerow, false, false, 2)
79
+
80
+ load_bindings(bindings)
81
+
82
+ @open = true
83
+
84
+ @window.signal_connect('key_release_event') { |widget, event| window_buttons(widget, event)}
85
+
86
+ @window.show_all
87
+ end
88
+
89
+ def action2index(action)
90
+ x = 0
91
+ @meths.each_with_index do |m, i|
92
+ if m['name'] == action
93
+ x = i+1
94
+ end
95
+ end
96
+
97
+ return x
98
+ end
99
+
100
+ def load_bindings(bindings)
101
+ bindings.each do |k, v|
102
+ puts k, v unless v and k
103
+ next unless v and k
104
+ command, args = v.split('(', 2)
105
+ args.chomp!(')') if args
106
+ x = KeyBindingRow.new(self, @meths)
107
+ x.set_binding(k)
108
+ y = action2index(command)
109
+ next unless y > 0
110
+ x.set_action(y)
111
+ x.set_arguments(args) if args
112
+ @rows.push(x)
113
+ end
114
+
115
+ #do a sort here, probably by action name
116
+ @rows.sort!{|x, y| x.get_action <=> y.get_action}
117
+ @rows.sort!{|x, y| x.get_arguments <=> y.get_arguments}
118
+ @rows.each_with_index do |row, i|
119
+ @keybox.pack_start(row, false, false, 2)
120
+ @keybox.reorder_child(row, i+1)
121
+ row.show_all
122
+ end
123
+ end
124
+
125
+ def save_bindings
126
+ result = {}
127
+ @rows.each do |row|
128
+ if row.get_binding != '' and row.get_action != ''
129
+ result[row.get_binding] = "#{row.get_action}(#{row.get_arguments})".chomp('()')
130
+ end
131
+ end
132
+
133
+ #~ result.each do |k, v|
134
+ #~ puts k+' => '+v
135
+ #~ end
136
+ return result
137
+ end
138
+
139
+ def grab_keys(listener)
140
+ @rows.each do |row|
141
+ if row != listener
142
+ row.inactivate
143
+ end
144
+ end
145
+
146
+ if listener != @fakerow
147
+ @fakerow.inactivate
148
+ end
149
+
150
+ listener.partially_inactivate
151
+
152
+ if @grabkeys
153
+ if listener != @listener
154
+ listener.ignore_binding_request
155
+ return
156
+ else
157
+ @rows.each {|row| row.activate}
158
+ @fakerow.activate
159
+ @listener.set_binding('')
160
+ return
161
+ end
162
+ end
163
+ @grabkeys = true
164
+ @listener = listener
165
+ end
166
+
167
+ def add_row
168
+ x = KeyBindingRow.new(self, @meths)
169
+ @rows.push(x)
170
+ @keybox.pack_start(x, false, false, 2)
171
+ @keybox.reorder_child(x, @rows.length)
172
+ x.show_all
173
+ return x
174
+ end
175
+
176
+ def remove_row(row)
177
+ @rows.delete(row)
178
+ @keybox.remove(row)
179
+ end
180
+
181
+ def window_buttons(widget, event)
182
+ return unless @grabkeys
183
+ x = event_to_string(event)
184
+ if x
185
+ @grabkeys = false
186
+ @rows.each {|row| row.activate}
187
+ @fakerow.activate
188
+ dup = false
189
+ @rows.each do |row|
190
+ if row != @listener and row.get_binding == x
191
+ dup = true
192
+ end
193
+ end
194
+ if dup
195
+ @listener.set_binding(nil)
196
+ else
197
+ @listener.set_binding(x)
198
+ end
199
+ end
200
+ end
201
+
202
+ def set_tooltip(widget, tip)
203
+ @tooltips.set_tip(widget, tip, '')
204
+ end
205
+
206
+ def ok_clicked
207
+ @config['keybindings'] = save_bindings
208
+ destroy
209
+ end
210
+
211
+ def destroy
212
+ @window.destroy
213
+ self.class.destroy
214
+ end
215
+
216
+ end
217
+
218
+ class KeyBindingRow < Gtk::HBox
219
+ def initialize(window, commands)
220
+ super()
221
+ spacing = 2
222
+ @window = window
223
+ homogenous = true
224
+ @bindbutton = Gtk::ToggleButton.new('Set Keybinding')
225
+ @sig = @bindbutton.signal_connect('pressed') {|| @window.grab_keys(self)}
226
+ @keybind = Gtk::Label.new
227
+ @actioncombo = Gtk::ComboBox.new
228
+ @actioncombo.signal_connect('changed') {|| action_changed}
229
+ @commands = commands
230
+ @arguments = Gtk::Entry.new
231
+ @arguments.sensitive = false
232
+ @arguments.width_chars = 10
233
+ @handlers = {}
234
+ [@bindbutton, @keybind, @actioncombo, @arguments].each_with_index do |w, i|
235
+ pack_start(w, true, false)
236
+ @window.sizegroups[i].add_widget(w)
237
+ end
238
+ fill_combos
239
+ end
240
+
241
+ def inactivate
242
+ @bindbutton.sensitive = false
243
+ @actioncombo.sensitive = false
244
+ end
245
+
246
+ def partially_inactivate
247
+ @actioncombo.sensitive = false
248
+ end
249
+
250
+ def activate
251
+ @bindbutton.sensitive = true
252
+ @actioncombo.sensitive = true
253
+ end
254
+
255
+ def set_binding(binding)
256
+ if binding
257
+ @binding = binding
258
+ @keybind.text = binding
259
+ @bindbutton.active = false
260
+ check_row
261
+ else
262
+ @bindbutton.active = false
263
+ end
264
+ end
265
+
266
+ def get_binding
267
+ return @keybind.text
268
+ end
269
+
270
+ def ignore_binding_request
271
+ @bindbutton.toggled
272
+ end
273
+
274
+ def fill_combos
275
+ @actioncombo.append_text('')
276
+ @commands.each do |cmd|
277
+ @actioncombo.append_text(cmd['name'])
278
+ end
279
+ end
280
+
281
+ def action_changed
282
+ if @actioncombo.active != -1
283
+ selection = @actioncombo.active_iter[0]
284
+ @commands.each do |cmd|
285
+ if cmd['name'] == selection
286
+ args = cmd['arguments']
287
+ if args == 0
288
+ @arguments.text = ''
289
+ @arguments.sensitive = false
290
+ tip = 'No Arguments'
291
+ else
292
+ @arguments.sensitive = true
293
+ if args > 0
294
+ tip = args.to_s+' required arguments'
295
+ elsif args < -1
296
+ tip = ((args*-1)+1).to_s+' required arguments, additional optional arguments'
297
+ elsif args == -1
298
+ tip = 'Optional arguments'
299
+ end
300
+ end
301
+ @window.set_tooltip(@arguments, tip)
302
+ elsif selection == ''
303
+ @arguments.sensitive = false
304
+ @window.set_tooltip(@arguments, '')
305
+ end
306
+ end
307
+ check_row
308
+ end
309
+ end
310
+
311
+ def get_action
312
+ return @actioncombo.active_iter[0]
313
+ end
314
+
315
+ def set_action(index)
316
+ @actioncombo.active=index
317
+ end
318
+
319
+ def set_arguments(args)
320
+ @arguments.text = args if @arguments.sensitive?
321
+ end
322
+
323
+ def get_arguments
324
+ @arguments.text
325
+ end
326
+
327
+ def check_row
328
+ if @keybind.text == '' and @actioncombo.active <= 0
329
+ puts 'empty row'
330
+ @window.remove_row(self)
331
+ end
332
+ end
333
+ end
334
+
335
+ class FakeKeyBindingRow < KeyBindingRow
336
+ def initialize(window, commands)
337
+ super
338
+ @bindbutton.label ='Add Keybinding'
339
+ end
340
+
341
+ def set_binding(binding)
342
+ @bindbutton.active = false
343
+ return if binding == '' or binding == nil
344
+ row = @window.add_row
345
+ row.set_binding(binding)
346
+ end
347
+
348
+ def action_changed
349
+ if @actioncombo.active > 0
350
+ row = @window.add_row
351
+ row.set_action(@actioncombo.active)
352
+ @actioncombo.active = -1
353
+ end
354
+ end
355
+ end
356
+ end
@@ -0,0 +1,137 @@
1
+ =begin
2
+ This file is part of the Ratchet project, a client for Icecap.
3
+ Copyright (C) 2005-6 Andrew Thompson
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the Free Software
17
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ =end
19
+
20
+ #### linkwindow.rb
21
+ # The Link grabber window
22
+ ####
23
+
24
+ #TODO: fix this so it works again
25
+
26
+ module Ratchet
27
+ class LinkWindow
28
+ def initialize(links)
29
+ @glade = GladeXML.new("#{DATADIR}/glade/linkwindow.glade") {|handler| method(handler)}
30
+ @linkstore = Gtk::ListStore.new(String, String, String)
31
+ @linklist = @glade['linklist']
32
+ @linklist.model = @linkstore
33
+ renderer = Gtk::CellRendererText.new
34
+
35
+ col = Gtk::TreeViewColumn.new("Time", renderer, :text => 0)
36
+ @linklist.append_column(col)
37
+ col = Gtk::TreeViewColumn.new("User", renderer, :text => 1)
38
+ @linklist.append_column(col)
39
+ @linklist.search_column=1
40
+ col = Gtk::TreeViewColumn.new("Link", renderer, :text => 2)
41
+ @linklist.append_column(col)
42
+
43
+ @links = links
44
+
45
+ @links.each do |v|
46
+ iter = @linkstore.append
47
+ iter[2] = v['link']
48
+ iter[0] = v['time']
49
+ iter[1] = v['name']
50
+ end
51
+
52
+ @columns = @linklist.columns
53
+
54
+ @columnselect = @glade['columnselect']
55
+
56
+ @columns.each do |column|
57
+ @columnselect.insert_text(0, column.title)
58
+ end
59
+ @columnselect.active = 2
60
+ @filtertext = ''
61
+
62
+ #~ col.set_cell_data_func(renderer) do |col, renderer, model, iter|
63
+ #~ index = nil
64
+ #~ @columns.each_with_index do |col, i|
65
+ #~ if col.title == @columnselect.active_iter[0]
66
+ #~ index = i
67
+ #~ end
68
+ #~ end
69
+
70
+ #~ if index
71
+ #~ if iter[index][0...@filtertext.length] == @filtertext or @filtertext == ''
72
+ #~ else
73
+ #~ #puts ' I\'d love to remove '+iter.to_s
74
+ #~ #model.remove(iter)
75
+ #~ @ditchables.push(iter)
76
+ #~ end
77
+ #~ end
78
+ #~ end
79
+
80
+ @window = @glade['linkwindow']
81
+
82
+ @linklist.selection.signal_connect('changed') do |widget|
83
+ selection = widget.selected
84
+ if selection
85
+ @glade['link_open'].sensitive = true
86
+ else
87
+ @glade['link_open'].sensitive = true
88
+ end
89
+ end
90
+ end
91
+
92
+ def filter_changed(widget)
93
+ @filtertext = widget.text
94
+ @linkstore.clear
95
+
96
+ index = nil
97
+ @columns.each_with_index do |col, i|
98
+ if col.title == @columnselect.active_iter[0]
99
+ index = i
100
+ end
101
+ end
102
+ @links.each do |v|
103
+ iter = @linkstore.append
104
+ iter[2] = v['link']
105
+ iter[0] = v['time']
106
+ iter[1] = v['name']
107
+ if iter[index][0...@filtertext.length] == @filtertext or @filtertext == ''
108
+ else
109
+ @linkstore.remove(iter)
110
+ end
111
+ end
112
+ #@linklist.signal_emit('changed')
113
+ end
114
+
115
+ def open_link
116
+ selection = @linklist.selection.selected
117
+ if selection
118
+ go_link(selection[2])
119
+ end
120
+ end
121
+
122
+ def link_activated(treeview, path, column)
123
+ iter = @linklist.model.get_iter(path)
124
+ if iter
125
+ go_link(iter[2])
126
+ end
127
+ end
128
+
129
+ def go_link(link)
130
+ system($config['linkclickaction'].sub('%s', $main.window.to_uri(link)))
131
+ end
132
+
133
+ def destroy
134
+ @window.destroy
135
+ end
136
+ end
137
+ end