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.
- data/gem_bin/ratchet +23 -0
- data/lib/ratchet.rb +613 -0
- data/lib/ratchet/aliases.rb +106 -0
- data/lib/ratchet/bufferparser.rb +409 -0
- data/lib/ratchet/commandbuffer.rb +66 -0
- data/lib/ratchet/commandparser.rb +668 -0
- data/lib/ratchet/configuration.rb +278 -0
- data/lib/ratchet/connections.rb +403 -0
- data/lib/ratchet/constants.rb +111 -0
- data/lib/ratchet/contrib/instance_exec.rb +21 -0
- data/lib/ratchet/eventparser.rb +486 -0
- data/lib/ratchet/gtk/bufferlistview.rb +514 -0
- data/lib/ratchet/gtk/bufferview.rb +167 -0
- data/lib/ratchet/gtk/configwindow.rb +229 -0
- data/lib/ratchet/gtk/connectionwindow.rb +218 -0
- data/lib/ratchet/gtk/keybinding.rb +356 -0
- data/lib/ratchet/gtk/linkwindow.rb +137 -0
- data/lib/ratchet/gtk/mainwindow.rb +504 -0
- data/lib/ratchet/gtk/networkpresenceconf.rb +567 -0
- data/lib/ratchet/gtk/pluginconfig.rb +94 -0
- data/lib/ratchet/gtk/pluginwindow.rb +146 -0
- data/lib/ratchet/gtk/userlistview.rb +161 -0
- data/lib/ratchet/help.rb +64 -0
- data/lib/ratchet/items.rb +271 -0
- data/lib/ratchet/lines.rb +63 -0
- data/lib/ratchet/networks.rb +652 -0
- data/lib/ratchet/plugins.rb +616 -0
- data/lib/ratchet/queue.rb +47 -0
- data/lib/ratchet/ratchet-version.rb +21 -0
- data/lib/ratchet/replies.rb +134 -0
- data/lib/ratchet/replyparser.rb +441 -0
- data/lib/ratchet/tabcomplete.rb +98 -0
- data/lib/ratchet/users.rb +237 -0
- data/lib/ratchet/utils.rb +178 -0
- data/share/defaults.yaml +169 -0
- data/share/glade/config.glade +2634 -0
- data/share/glade/connect.glade +950 -0
- data/share/glade/keybindings.glade +109 -0
- data/share/glade/linkwindow.glade +188 -0
- data/share/glade/mainwindow.glade +335 -0
- data/share/glade/network-presences.glade +1373 -0
- data/share/glade/pluginconf.glade +97 -0
- data/share/glade/plugins.glade +360 -0
- data/share/plugins/colorewrite.rb +193 -0
- data/share/plugins/highlighter.rb +115 -0
- data/share/plugins/mpdplay.rb +123 -0
- data/share/plugins/numberswitcher.rb +30 -0
- data/share/plugins/sysinfo.rb +82 -0
- metadata +96 -0
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
#### bufferview.rb ####
|
|
21
|
+
# Class that wraps a scwview to show the contents of a buffer
|
|
22
|
+
####
|
|
23
|
+
|
|
24
|
+
module Ratchet
|
|
25
|
+
class BufferView
|
|
26
|
+
attr_reader :lines, :view
|
|
27
|
+
def initialize(config)
|
|
28
|
+
@config = config
|
|
29
|
+
@view = Scw::View.new
|
|
30
|
+
@liststore = Gtk::ListStore.new(Scw::Timestamp, Scw::Presence, String, Scw::RowColor)
|
|
31
|
+
@view.model = @liststore
|
|
32
|
+
#~ @view.align_presences = @config['scw_align_presences']
|
|
33
|
+
@view.scroll_on_append = true
|
|
34
|
+
#~ @view.modify_font(Pango::FontDescription.new(@config['main_font']))
|
|
35
|
+
#~ @view.modify_text(Gtk::STATE_NORMAL, Gdk::Color.new(*@config['foregroundcolor']))
|
|
36
|
+
#~ @view.modify_text(Gtk::STATE_SELECTED, Gdk::Color.new(*@config['selectedforegroundcolor'].to_a))
|
|
37
|
+
#~ @view.modify_base(Gtk::STATE_SELECTED, Gdk::Color.new(*@config['selectedbackgroundcolor']))
|
|
38
|
+
#~ @view.modify_text(Gtk::STATE_ACTIVE, Gdk::Color.new(*@config['selectedforegroundcolor']))
|
|
39
|
+
#~ @view.modify_base(Gtk::STATE_ACTIVE, Gdk::Color.new(*@config['selectedbackgroundcolor']))
|
|
40
|
+
#~ @view.modify_text(Gtk::STATE_PRELIGHT, Gdk::Color.new(*@config['scw_prelight']))
|
|
41
|
+
redraw
|
|
42
|
+
@lines = []
|
|
43
|
+
@lastread = nil
|
|
44
|
+
|
|
45
|
+
@view.signal_connect("activate") do |view,id,data, event|
|
|
46
|
+
# puts "Activated #{id} with #{data}"
|
|
47
|
+
if id == 'url'
|
|
48
|
+
link = to_uri(data)
|
|
49
|
+
system(@config['linkclickaction'].sub('%s', link))
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
@view.signal_connect('context_request') do |view, id, data, x, y|
|
|
54
|
+
#TODO - connect up the menus
|
|
55
|
+
if id == 'user'
|
|
56
|
+
# puts data
|
|
57
|
+
# menu = $main.window.create_user_popup(data)
|
|
58
|
+
# menu.show_all
|
|
59
|
+
# menu.popup(nil, nil, 3, Gdk::Event::CURRENT_TIME)# {[x, y]}
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def redraw
|
|
65
|
+
|
|
66
|
+
@font = Pango::FontDescription.new(@config['main_font'])
|
|
67
|
+
@view.reset_rc_styles
|
|
68
|
+
@view.align_presences = @config['scw_align_presences']
|
|
69
|
+
@view.modify_text(Gtk::STATE_NORMAL, Gdk::Color.new(*@config['foregroundcolor'].to_a))
|
|
70
|
+
@view.modify_text(Gtk::STATE_SELECTED, Gdk::Color.new(*@config['selectedforegroundcolor'].to_a))
|
|
71
|
+
@view.modify_base(Gtk::STATE_SELECTED, Gdk::Color.new(*@config['selectedbackgroundcolor'].to_a))
|
|
72
|
+
@view.modify_text(Gtk::STATE_ACTIVE, Gdk::Color.new(*@config['selectedforegroundcolor'].to_a))
|
|
73
|
+
@view.modify_base(Gtk::STATE_ACTIVE, Gdk::Color.new(*@config['selectedbackgroundcolor'].to_a))
|
|
74
|
+
|
|
75
|
+
@view.modify_text(Gtk::STATE_PRELIGHT, Gdk::Color.new(*@config['scw_prelight']))
|
|
76
|
+
@view.modify_font(@font)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def append(line, id)
|
|
80
|
+
#puts 'appending'+line[2]
|
|
81
|
+
iter = @liststore.append
|
|
82
|
+
line.each_with_index do |item, i|
|
|
83
|
+
iter[i] = item
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
lineref = Gtk::TreeRowReference.new(@liststore, iter.path)
|
|
87
|
+
@lines.push([id, lineref])
|
|
88
|
+
trim
|
|
89
|
+
#puts 'done'
|
|
90
|
+
marklastread unless @lastread
|
|
91
|
+
return lineref
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def update_line(lineref, text)
|
|
95
|
+
item = @lines.detect{|x| x[1] == lineref}
|
|
96
|
+
# puts item
|
|
97
|
+
if item and item[1]
|
|
98
|
+
iter = @liststore.get_iter(item[1].path)
|
|
99
|
+
@liststore.set_value(iter, 2, text)
|
|
100
|
+
else
|
|
101
|
+
puts 'invalid'
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def get_line(lineref)
|
|
106
|
+
item = @lines.detect{|x| x[1] == lineref}
|
|
107
|
+
if item and item[1]
|
|
108
|
+
iter = @liststore.get_iter(item[1].path)
|
|
109
|
+
return iter
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def prepend(line, id)
|
|
114
|
+
iter = @liststore.prepend
|
|
115
|
+
line.each_with_index do |item, i|
|
|
116
|
+
iter[i] = item
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
lineref = Gtk::TreeRowReference.new(@liststore, iter.path)
|
|
120
|
+
@lines.unshift([id, lineref])
|
|
121
|
+
trim
|
|
122
|
+
return lineref
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def remove_id(id)
|
|
126
|
+
item = @lines.detect{|x| x[0] == id}
|
|
127
|
+
@liststore.remove(@liststore.get_iter(item[1].path))
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def remove_path(path)
|
|
131
|
+
item = @lines.detect{|x| x[1].path == path}
|
|
132
|
+
@liststore.remove(@liststore.get_iter(item[1].path))
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def has_id?(id)
|
|
136
|
+
return @lines.detect{|x| x[0] == id}
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def trim
|
|
140
|
+
#@lines = @lines.select{|x| x[1].valid?}
|
|
141
|
+
if @lines.length > 100
|
|
142
|
+
#puts 'trimming'
|
|
143
|
+
(@lines.length-100).times do |x|
|
|
144
|
+
id, iter = @lines.shift
|
|
145
|
+
#puts iter.class
|
|
146
|
+
@liststore.remove(@liststore.get_iter(iter.path))
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
#puts @lines.length
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def marklastread
|
|
153
|
+
id, iter = @lines[-1]
|
|
154
|
+
return unless iter
|
|
155
|
+
|
|
156
|
+
iter3 = @liststore.get_iter(iter.path)
|
|
157
|
+
|
|
158
|
+
if @lastread and @lastread.valid?
|
|
159
|
+
iter2 = @liststore.get_iter(@lastread.path)
|
|
160
|
+
iter2[3] = ''
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
iter3[3] = @config['scw_lastread'].to_hex
|
|
164
|
+
@lastread = iter
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -0,0 +1,229 @@
|
|
|
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
|
+
#### configwindow.rb ####
|
|
21
|
+
# The Config window
|
|
22
|
+
####
|
|
23
|
+
|
|
24
|
+
module Ratchet
|
|
25
|
+
class ConfigWindow
|
|
26
|
+
def initialize(main)
|
|
27
|
+
@main = main
|
|
28
|
+
@config = @main.config
|
|
29
|
+
@glade = GladeXML.new("#{DATADIR}/glade/config.glade") {|handler| method(handler)}
|
|
30
|
+
@window = @glade['config']
|
|
31
|
+
@preferencesbar = @glade['preferencesbar']
|
|
32
|
+
@configarea = @glade['configarea']
|
|
33
|
+
@treestore = Gtk::TreeStore.new(String)
|
|
34
|
+
@preferencesbar.model = @treestore
|
|
35
|
+
@treeselection = @preferencesbar.selection
|
|
36
|
+
@treeselection.signal_connect('changed') do |widget|
|
|
37
|
+
switch_category(widget.selected)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
@channellistposition = @glade['tablistposition']
|
|
41
|
+
@options = {}
|
|
42
|
+
@options['tablistposition'] = ['Top', 'Bottom', 'Left', 'Right', 'UnderUserList']
|
|
43
|
+
@options['canonicaltime'] = ['Server', 'Client']
|
|
44
|
+
@options['tabcompletesort'] = ['Alphabetical', 'Activity']
|
|
45
|
+
@options['tablisttype'] = ['Button', 'TreeView']
|
|
46
|
+
@options['tabstructure'] = ['Hierarchical', 'Flat']
|
|
47
|
+
@options['tabsort'] = ['Case Insensitive', 'Case Sensitive', 'Case Insensitive No Hash', 'Case Sensitive No Hash']
|
|
48
|
+
|
|
49
|
+
parent = @treestore.append(nil)
|
|
50
|
+
parent[0] = "Interface"
|
|
51
|
+
child2 = @treestore.append(parent)
|
|
52
|
+
child2[0] = "Miscallenous"
|
|
53
|
+
child = @treestore.append(parent)
|
|
54
|
+
child[0] = "Templates"
|
|
55
|
+
child = @treestore.append(parent)
|
|
56
|
+
child[0] = "Colors"
|
|
57
|
+
|
|
58
|
+
@glade['temp2'].remove(@glade['miscconfig'])
|
|
59
|
+
@glade['temp1'].remove(@glade['colorconfig'])
|
|
60
|
+
|
|
61
|
+
@glade['temp1'].destroy
|
|
62
|
+
@glade['temp2'].destroy
|
|
63
|
+
|
|
64
|
+
@categories = {'Miscallenous' => @glade['miscconfig'], 'Templates'=>@glade['promptconfig'], 'Colors' => @glade['colorconfig']}
|
|
65
|
+
renderer = Gtk::CellRendererText.new
|
|
66
|
+
|
|
67
|
+
col = Gtk::TreeViewColumn.new("", renderer, :text => 0)
|
|
68
|
+
@preferencesbar.append_column(col)
|
|
69
|
+
@preferencesbar.expand_all
|
|
70
|
+
@treeselection.select_iter(child2)
|
|
71
|
+
@currentcategory = @configarea.child
|
|
72
|
+
draw_category(@categories['Miscallenous'])
|
|
73
|
+
@configarray = {}
|
|
74
|
+
@configbackup = {}
|
|
75
|
+
|
|
76
|
+
fill_values
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def fill_values(values = @config.values)
|
|
80
|
+
#values = $config.get_all_values
|
|
81
|
+
|
|
82
|
+
values.each do | key, value|
|
|
83
|
+
if @glade[key]
|
|
84
|
+
if @glade[key].class == Gtk::Entry
|
|
85
|
+
@glade[key].text = value
|
|
86
|
+
@glade[key].signal_connect('changed') do |widget|
|
|
87
|
+
change_setting(widget, widget.text)
|
|
88
|
+
end
|
|
89
|
+
@configarray[@glade[key]] = {'name' => key, 'value' => value}
|
|
90
|
+
@configbackup[key] ||= value
|
|
91
|
+
elsif @glade[key].class == Gtk::ComboBox
|
|
92
|
+
i = 0
|
|
93
|
+
match = false
|
|
94
|
+
#fill the combobox
|
|
95
|
+
@configarray[@glade[key]] = {'name' => key, 'value' => value}
|
|
96
|
+
@configbackup[key] ||= value
|
|
97
|
+
# puts key, @options[key]
|
|
98
|
+
next unless @options[key]
|
|
99
|
+
@options[key].each do |v|
|
|
100
|
+
@glade[key].append_text(v)
|
|
101
|
+
if value == v.downcase
|
|
102
|
+
@glade[key].active = i
|
|
103
|
+
match = true
|
|
104
|
+
end
|
|
105
|
+
i += 1
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
unless match
|
|
109
|
+
@glade[key].active == 0
|
|
110
|
+
end
|
|
111
|
+
# @glade[key].active = 1
|
|
112
|
+
#end
|
|
113
|
+
elsif @glade[key].class == Gtk::ColorButton and value.class == Color
|
|
114
|
+
#color_button(@glade[key], Gdk::Color.new(*value))
|
|
115
|
+
@configarray[@glade[key]] = {'name' => key, 'value' => value}
|
|
116
|
+
@configbackup[key] ||= value
|
|
117
|
+
@glade[key].color = Gdk::Color.new(*value)
|
|
118
|
+
elsif @glade[key].class == Gtk::CheckButton
|
|
119
|
+
@configarray[@glade[key]] = {'name' => key, 'value' => value}
|
|
120
|
+
@configbackup[key] ||= value
|
|
121
|
+
if value
|
|
122
|
+
@glade[key].active = true
|
|
123
|
+
else
|
|
124
|
+
@glade[key].active = false
|
|
125
|
+
end
|
|
126
|
+
elsif @glade[key].class == Gtk::FontButton
|
|
127
|
+
@configarray[@glade[key]] = {'name' => key, 'value' => value}
|
|
128
|
+
@configbackup[key] ||= value
|
|
129
|
+
@glade[key].font_name = value
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
#@glade['message'].text = @config['message']
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def color_button(button, color)
|
|
137
|
+
button.modify_bg(Gtk::STATE_NORMAL, color)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def switch_category(selection)
|
|
141
|
+
draw_category(@categories[selection[0]]) if selection and @categories[selection[0]]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def draw_category(category)
|
|
145
|
+
@configarea.remove(@currentcategory)
|
|
146
|
+
@configarea.add(category)
|
|
147
|
+
@currentcategory = category
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def change_setting(widget, setting)
|
|
151
|
+
puts 'changed setting of '+widget.name+' to '+setting.to_s
|
|
152
|
+
@configarray[widget] = {'name' => widget.name, 'value' => setting}# unless @configbackup[widget.name] == setting
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def color_changed(widget)
|
|
156
|
+
change_setting(widget, Color.new(*widget.color.to_a))
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# def change_color(widget, color)
|
|
160
|
+
# color_button(widget, color)
|
|
161
|
+
# change_setting(widget, Color.new(*color.to_a))
|
|
162
|
+
# #$config.set_value(widget.name, color)
|
|
163
|
+
# end
|
|
164
|
+
#
|
|
165
|
+
# def select_color(widget)
|
|
166
|
+
# button = widget
|
|
167
|
+
# @configarray[widget] = {'name' => widget.name} unless @configarray[widget]
|
|
168
|
+
# color = nil
|
|
169
|
+
# color = Gdk::Color.new(*@configarray[widget]['value']) if @configarray[widget]['value']
|
|
170
|
+
# selectordialog = Gtk::ColorSelectionDialog.new
|
|
171
|
+
# selectordialog.modal = true
|
|
172
|
+
# selector = selectordialog.colorsel
|
|
173
|
+
# if color
|
|
174
|
+
# selector.current_color = color
|
|
175
|
+
# selector.previous_color = color
|
|
176
|
+
# end
|
|
177
|
+
# selectordialog.run do |response|
|
|
178
|
+
# case response
|
|
179
|
+
# when Gtk::Dialog::RESPONSE_OK
|
|
180
|
+
# change_color(button, selector.current_color)
|
|
181
|
+
# #else
|
|
182
|
+
# #do_nothing_since_dialog_was_cancelled()
|
|
183
|
+
# end
|
|
184
|
+
# selectordialog.destroy
|
|
185
|
+
# end
|
|
186
|
+
# end
|
|
187
|
+
|
|
188
|
+
def combobox_changed(widget)
|
|
189
|
+
change_setting(widget, @options[widget.name][widget.active].downcase)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def tickbox_changed(widget)
|
|
193
|
+
change_setting(widget, widget.active?)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def font_changed(widget)
|
|
197
|
+
#puts 'changed font'+widget.font_name
|
|
198
|
+
change_setting(widget, widget.font_name)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def revert_config
|
|
202
|
+
#$config.revert_to_defaults
|
|
203
|
+
fill_values(@config.defaults)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def update_config
|
|
207
|
+
#$config.create_config_snapshot
|
|
208
|
+
@config.update_snapshot(@configbackup)
|
|
209
|
+
#pass all the values back to $config
|
|
210
|
+
@configarray.each do |k, v|
|
|
211
|
+
@config[v['name']] = v['value']
|
|
212
|
+
end
|
|
213
|
+
destroy
|
|
214
|
+
@main.windows.each{|window| window.draw_from_config}
|
|
215
|
+
@main.buffers.values.select{|x| x.buffer}.each{|x| x.buffer.redraw}
|
|
216
|
+
changes = @config.changes
|
|
217
|
+
@main.send_command('sendconfig', changes) if changes
|
|
218
|
+
@main.restyle
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def show_all
|
|
222
|
+
@window.show_all
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def destroy
|
|
226
|
+
@window.destroy
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
#### connectionwindow.rb ####
|
|
21
|
+
# The Connection Window
|
|
22
|
+
####
|
|
23
|
+
|
|
24
|
+
module Ratchet
|
|
25
|
+
class ConnectionWindow < SingleWindow
|
|
26
|
+
attr_reader :autoconnect
|
|
27
|
+
def initialize(main)
|
|
28
|
+
@main = main
|
|
29
|
+
require 'yaml'
|
|
30
|
+
@glade = GladeXML.new("#{DATADIR}/glade/connect.glade") {|handler| method(handler)}
|
|
31
|
+
@window = @glade['window1']
|
|
32
|
+
|
|
33
|
+
@connection_log = @glade['connection_log']
|
|
34
|
+
|
|
35
|
+
@local_button = @glade['local']
|
|
36
|
+
@ssh_button = @glade['ssh']
|
|
37
|
+
@socket_button = @glade['socket']
|
|
38
|
+
@net_ssh_button = @glade['net_ssh']
|
|
39
|
+
@inetd_button = @glade['inetd']
|
|
40
|
+
@net_ssh_button.visible = false
|
|
41
|
+
@socket_button.visible = false
|
|
42
|
+
@net_ssh_button.visible= false# = $netssh
|
|
43
|
+
if $platform == 'win32'
|
|
44
|
+
@local_button.visible = false
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#@ssh_button.active = true
|
|
48
|
+
@config = {}
|
|
49
|
+
|
|
50
|
+
@config['default_method'] = 'local'
|
|
51
|
+
|
|
52
|
+
@config[@ssh_button] = {}
|
|
53
|
+
@config[@ssh_button]['host'] = 'localhost'
|
|
54
|
+
if $platform == 'linux'
|
|
55
|
+
@config[@ssh_button]['username'] = `whoami`.chomp
|
|
56
|
+
else
|
|
57
|
+
@config[@ssh_button]['username'] = 'icecapd'
|
|
58
|
+
end
|
|
59
|
+
@config[@ssh_button]['binpath'] = '/usr/bin/icecapd'
|
|
60
|
+
@config[@ssh_button]['port'] = '22'
|
|
61
|
+
|
|
62
|
+
@config[@local_button] = {}
|
|
63
|
+
icecapdpath = ENV['PATH'].split(File::PATH_SEPARATOR).detect{|path| File.exist?(File.join(path, 'icecapd'))}
|
|
64
|
+
icecapdpath ||= '/usr/local/bin'
|
|
65
|
+
@config[@local_button] ['binpath'] = File.join(icecapdpath, 'icecapd')
|
|
66
|
+
|
|
67
|
+
@config[@socket_button] = {}
|
|
68
|
+
if $platform == 'linux'
|
|
69
|
+
@config[@socket_button]['location'] = ENV['HOME']+'/.icecapd/client-listener'
|
|
70
|
+
elsif $platform == 'win32'
|
|
71
|
+
@config[@socket_button]['location'] = ''
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
@config[@inetd_button] = {}
|
|
75
|
+
@config[@inetd_button]['host'] = 'localhost'
|
|
76
|
+
@config[@inetd_button]['port'] = '1027'
|
|
77
|
+
|
|
78
|
+
@config[@net_ssh_button] = {}
|
|
79
|
+
@config[@net_ssh_button] ['host'] = 'localhost'
|
|
80
|
+
@config[@net_ssh_button] ['port'] = '22'
|
|
81
|
+
@config[@net_ssh_button] ['binpath'] = '/usr/bin/icecapd'
|
|
82
|
+
if $platform == 'linux'
|
|
83
|
+
@config[@net_ssh_button]['username'] = `whoami`.chomp
|
|
84
|
+
else
|
|
85
|
+
@config[@net_ssh_button]['username'] = 'icecapd'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
@option_frame = @glade['option_frame']
|
|
89
|
+
|
|
90
|
+
@option = {}
|
|
91
|
+
@option[@ssh_button] = @glade['ssh_table']
|
|
92
|
+
@option[@socket_button] = @glade['socket_table']
|
|
93
|
+
@option[@net_ssh_button] = @glade['net_ssh_table']
|
|
94
|
+
@option[@local_button] = @glade['local_table']
|
|
95
|
+
@option[@inetd_button] = @glade['inetd_table']
|
|
96
|
+
|
|
97
|
+
@open = true
|
|
98
|
+
|
|
99
|
+
load_settings
|
|
100
|
+
@glade[@config['default_method']].active = true
|
|
101
|
+
fill_entries
|
|
102
|
+
redraw_options
|
|
103
|
+
|
|
104
|
+
@autoconnect = @config['autoconnect']
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def save_settings
|
|
108
|
+
get_config
|
|
109
|
+
settings = { 'default_method' => get_active.name,
|
|
110
|
+
'autoconnect' => @glade['autoconnect'].active?}
|
|
111
|
+
|
|
112
|
+
group = @glade['ssh'].group
|
|
113
|
+
|
|
114
|
+
group.each do |button|
|
|
115
|
+
@config[button].each do |k, v|
|
|
116
|
+
if v.length > 0
|
|
117
|
+
settings[button.name] = {} if !settings[button.name]
|
|
118
|
+
settings[button.name][k] = v
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
unless File.directory?($ratchetfolder)
|
|
124
|
+
Dir.mkdir($ratchetfolder)
|
|
125
|
+
end
|
|
126
|
+
File.open($ratchetfolder+'/settings.yaml', "w") {|f| YAML.dump(settings, f)}
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def load_settings
|
|
130
|
+
return if !File.exists?($ratchetfolder+'/settings.yaml')
|
|
131
|
+
settings = YAML.load_file($ratchetfolder+'/settings.yaml')
|
|
132
|
+
|
|
133
|
+
group = @glade['ssh'].group
|
|
134
|
+
group.each do |button|
|
|
135
|
+
if settings[button.name]
|
|
136
|
+
@config[button].merge!(settings[button.name])
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
settings.each do |k, v|
|
|
141
|
+
if v.class != Hash
|
|
142
|
+
@config[k] = v
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def get_config
|
|
148
|
+
group = @glade['ssh'].group
|
|
149
|
+
|
|
150
|
+
group.each do |button|
|
|
151
|
+
@config[button].each do |k, v|
|
|
152
|
+
@config[button][k] = @glade[button.name+'_'+k].text if @glade[button.name+'_'+k]
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def send_text(text)
|
|
158
|
+
@connection_log.buffer.insert(@connection_log.buffer.end_iter, text+"\n")
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def fill_entries
|
|
162
|
+
group = @glade['ssh'].group
|
|
163
|
+
|
|
164
|
+
group.each do |button|
|
|
165
|
+
@config[button].each do |k, v|
|
|
166
|
+
@glade[button.name+'_'+k].text = v if @glade[button.name+'_'+k]
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
@glade['autoconnect'].active = @config['autoconnect']
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def get_active
|
|
174
|
+
group = @glade['ssh'].group
|
|
175
|
+
active = nil
|
|
176
|
+
|
|
177
|
+
group.each do |button|
|
|
178
|
+
if button.active?
|
|
179
|
+
active = button
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
return active
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def redraw_options
|
|
187
|
+
return if !@option_frame
|
|
188
|
+
child = @option_frame.child
|
|
189
|
+
@option_frame.remove(child)
|
|
190
|
+
@option_frame.add(@option[get_active]) if @option
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def start_connect
|
|
194
|
+
settings = {}
|
|
195
|
+
|
|
196
|
+
button = get_active
|
|
197
|
+
@config[button].each do |k, v|
|
|
198
|
+
settings[k] = @glade[button.name+'_'+k].text if @glade[button.name+'_'+k].text.length > 0
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
method = button.name
|
|
202
|
+
save_settings
|
|
203
|
+
Thread.new{@main.connect(method, settings)}
|
|
204
|
+
#destroy
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def destroy
|
|
208
|
+
@open = false
|
|
209
|
+
@window.destroy
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def quit
|
|
213
|
+
destroy
|
|
214
|
+
@main.quit
|
|
215
|
+
false
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|