transmission-rss 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -2
- data/bin/transmission-rss +92 -88
- data/lib/transmission-rss.rb +4 -4
- data/lib/transmission-rss/aggregator.rb +111 -109
- data/lib/transmission-rss/client.rb +70 -70
- data/lib/transmission-rss/config-editor.rb +6 -6
- data/lib/transmission-rss/config-editor/listbox.rb +67 -67
- data/lib/transmission-rss/config-editor/main.rb +316 -316
- data/lib/transmission-rss/config.rb +24 -24
- data/lib/transmission-rss/hash.rb +10 -10
- data/lib/transmission-rss/log.rb +21 -41
- metadata +9 -9
@@ -1,88 +1,88 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'timeout'
|
4
4
|
|
5
5
|
# TODO
|
6
6
|
# * Why the hell do timeouts in getSessionID and addTorrent not work?!
|
7
7
|
|
8
8
|
# Class for communication with transmission utilizing the RPC web interface.
|
9
9
|
class TransmissionRSS::Client
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def initialize(host, port)
|
11
|
+
@host = host
|
12
|
+
@port = port
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
@log = Log.instance
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
# Get transmission session id by simple GET.
|
18
|
+
def getSessionID
|
19
|
+
get = Net::HTTP::Get.new(
|
20
|
+
'/transmission/rpc'
|
21
|
+
)
|
22
22
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
23
|
+
# retries = 3
|
24
|
+
# begin
|
25
|
+
# Timeout::timeout(5) do
|
26
|
+
response = Net::HTTP.new(@host, @port).start do |http|
|
27
|
+
http.request(get)
|
28
|
+
end
|
29
|
+
# end
|
30
|
+
# rescue Timeout::Error
|
31
|
+
# puts('timeout error exception') if($verbose)
|
32
|
+
# if(retries > 0)
|
33
|
+
# retries -= 1
|
34
|
+
# puts('getSessionID timeout. retry..') if($verbose)
|
35
|
+
# retry
|
36
|
+
# else
|
37
|
+
# $stderr << "timeout http://#{@host}:#{@port}/transmission/rpc"
|
38
|
+
# end
|
39
|
+
# end
|
40
40
|
|
41
|
-
|
41
|
+
id = response.header['x-transmission-session-id']
|
42
42
|
|
43
|
-
|
43
|
+
@log.debug('got session id ' + id)
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
id
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
# POST json packed torrent add command.
|
49
|
+
def addTorrent(torrentFile, paused = false)
|
50
|
+
post = Net::HTTP::Post.new(
|
51
|
+
'/transmission/rpc',
|
52
|
+
initheader = {
|
53
|
+
'Content-Type' => 'application/json',
|
54
|
+
'X-Transmission-Session-Id' => getSessionID
|
55
|
+
}
|
56
|
+
)
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
post.body = {
|
59
|
+
"method" => "torrent-add",
|
60
|
+
"arguments" => {
|
61
|
+
"paused" => paused,
|
62
|
+
"filename" => torrentFile
|
63
|
+
}
|
64
|
+
}.to_json
|
65
65
|
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
66
|
+
# retries = 3
|
67
|
+
# begin
|
68
|
+
# Timeout::timeout(5) do
|
69
|
+
response = Net::HTTP.new(@host, @port).start do |http|
|
70
|
+
http.request(post)
|
71
|
+
end
|
72
|
+
# end
|
73
|
+
# rescue Timeout::Error
|
74
|
+
# puts('timeout error exception') if($verbose)
|
75
|
+
# if(retries > 0)
|
76
|
+
# retries -= 1
|
77
|
+
# puts('addTorrent timeout. retry..') if($verbose)
|
78
|
+
# retry
|
79
|
+
# else
|
80
|
+
# $stderr << "timeout http://#{@host}:#{@port}/transmission/rpc"
|
81
|
+
# end
|
82
|
+
# end
|
83
83
|
|
84
|
-
|
84
|
+
result = JSON.parse(response.body).result
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
@log.debug('addTorrent result: ' + result)
|
87
|
+
end
|
88
88
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
$:.unshift(
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'libglade2'
|
4
4
|
|
5
5
|
dir = 'config-editor'
|
6
6
|
|
7
7
|
blacklist = %w(
|
8
|
-
|
8
|
+
listbox-original
|
9
9
|
)
|
10
10
|
|
11
11
|
blacklist.map! do |name|
|
12
|
-
|
12
|
+
$:.first + '/' + dir + '/' + name + '.rb'
|
13
13
|
end
|
14
14
|
|
15
|
-
(
|
16
|
-
|
15
|
+
(Dir.glob($:.first + '/' + dir + '/*.rb') - blacklist).each do |lib|
|
16
|
+
require lib
|
17
17
|
end
|
@@ -1,93 +1,93 @@
|
|
1
1
|
# http://www.lakeinfoworks.com/blog/wp-content/listbox.rb
|
2
2
|
class TransmissionRSS::ListBox < Gtk::ScrolledWindow
|
3
|
-
|
4
|
-
|
3
|
+
def initialize
|
4
|
+
super
|
5
5
|
|
6
|
-
|
6
|
+
tbl = Gtk::Table.new(2, 2, false)
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
self.hscrollbar_policy = Gtk::PolicyType::AUTOMATIC
|
9
|
+
self.vscrollbar_policy = Gtk::PolicyType::AUTOMATIC
|
10
|
+
self.shadow_type = Gtk::ShadowType::NONE
|
11
|
+
self.window_placement= Gtk::CornerType::TOP_LEFT
|
12
12
|
|
13
|
-
|
13
|
+
@renderer = Gtk::CellRendererText.new
|
14
14
|
|
15
|
-
#
|
16
|
-
|
17
|
-
|
15
|
+
# @renderer.set_property('background', 'lavender')
|
16
|
+
@renderer.set_property('background', 'white')
|
17
|
+
@renderer.set_property('foreground', 'black')
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
@list_store = Gtk::ListStore.new(String)
|
20
|
+
@tree_view = Gtk::TreeView.new(@list_store)
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
@tree_view_col1 = Gtk::TreeViewColumn.new('', @renderer, { :text => 0 })
|
23
|
+
@tree_view_col1.sizing = Gtk::TreeViewColumn::AUTOSIZE
|
24
24
|
|
25
|
-
|
25
|
+
@text_col = 0
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
@tree_view.append_column(@tree_view_col1)
|
28
|
+
@tree_view.headers_visible = false
|
29
|
+
@tree_view.selection.mode = Gtk::SELECTION_SINGLE
|
30
30
|
|
31
|
-
|
31
|
+
tbl.attach_defaults(@tree_view, 0, 2, 0, 2)
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
self.add_with_viewport(tbl)
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def add(*args)
|
37
|
+
args.flatten.each do |arg|
|
38
|
+
iter = @list_store.append
|
39
|
+
iter.set_value(0, arg.to_s)
|
40
|
+
end
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
def button_release(widget, event, type = 'text')
|
44
|
+
path, column, cell_x, cell_y = @tree_view.get_path_at_pos(event.x, event.y)
|
45
45
|
|
46
|
-
|
46
|
+
return('') if(column.nil?)
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
entry = case(type)
|
49
|
+
when 'line_nbr'
|
50
|
+
path
|
51
|
+
when 'text'
|
52
|
+
@tree_view.selection.selected[@tree_view.columns.index(column)]
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
return(entry)
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
def clear
|
59
|
+
@list_store.clear
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
def header=(string)
|
63
|
+
@tree_view.headers_visible = true
|
64
|
+
@tree_view_col1.title = string
|
65
|
+
end
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
# TODO produces Gtk-CRITICAL
|
68
|
+
def remove(*args)
|
69
|
+
args.each do |arg|
|
70
|
+
iter = @list_store.iter_first
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
begin
|
73
|
+
if(iter.get_value(0) == arg)
|
74
|
+
@list_store.remove(iter)
|
75
|
+
end
|
76
|
+
end while(iter.next!)
|
77
|
+
end
|
78
|
+
end
|
79
79
|
|
80
|
-
|
81
|
-
|
80
|
+
def items
|
81
|
+
array = []
|
82
82
|
|
83
|
-
|
83
|
+
iter = @list_store.iter_first
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
if(not iter.nil?)
|
86
|
+
begin
|
87
|
+
array << iter.get_value(0)
|
88
|
+
end while(iter.next!)
|
89
|
+
end
|
90
90
|
|
91
|
-
|
92
|
-
|
91
|
+
array
|
92
|
+
end
|
93
93
|
end
|
@@ -1,319 +1,319 @@
|
|
1
1
|
# Represents the config editor window.
|
2
2
|
class TransmissionRSS::ConfigEditor
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
3
|
+
TITLE = 'transmission-rss config editor'
|
4
|
+
NAME = 'config-editor'
|
5
|
+
|
6
|
+
DEFAULT_CONFIG = {
|
7
|
+
'feeds' => [],
|
8
|
+
'update_interval' => 600,
|
9
|
+
'add_paused' => false,
|
10
|
+
'server' => {
|
11
|
+
'host' => 'localhost',
|
12
|
+
'port' => 9091
|
13
|
+
},
|
14
|
+
'log_target' => $stderr,
|
15
|
+
'privileges' => {}
|
16
|
+
}
|
17
|
+
|
18
|
+
# Loads glade file and initializes dynamic GUI elements.
|
19
|
+
def initialize(configFile, config)
|
20
|
+
@configFile = configFile
|
21
|
+
@config = config
|
22
|
+
|
23
|
+
path = File.join(File.dirname(__FILE__), 'main.glade')
|
24
|
+
|
25
|
+
# Load glade file and connect to handler method. Dubious.
|
26
|
+
@glade = GladeXML.new(path) do |handler|
|
27
|
+
method(handler)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Connect every widget to an instance variable.
|
31
|
+
@glade.widget_names.each do |name|
|
32
|
+
name.gsub!(/-/, '_')
|
33
|
+
instance_variable_set("@#{name}".intern, @glade[name])
|
34
|
+
end
|
35
|
+
|
36
|
+
# Quit program, when it is closed by the WM.
|
37
|
+
@window1.signal_connect('destroy') do
|
38
|
+
Gtk.main_quit
|
39
|
+
end
|
40
|
+
|
41
|
+
# Initialize the ListBox widget.
|
42
|
+
initialize_listbox
|
43
|
+
|
44
|
+
# Reflect the current config on the GUI.
|
45
|
+
initialize_config
|
46
|
+
end
|
47
|
+
|
48
|
+
# Reflects the current config on the GUI.
|
49
|
+
def initialize_config
|
50
|
+
@entry_server_host.text = @config.server.host
|
51
|
+
@entry_server_port.text = @config.server.port.to_s
|
52
|
+
|
53
|
+
@entry_update_interval.text = @config.update_interval.to_s
|
54
|
+
|
55
|
+
@checkbutton_add_paused.active = @config.add_paused
|
56
|
+
|
57
|
+
@listbox.clear
|
58
|
+
@listbox.add(@config.feeds)
|
59
|
+
|
60
|
+
# If log target is STDERR.
|
61
|
+
if(@config.log_target.class == IO)
|
62
|
+
# Deactivate log path entry.
|
63
|
+
@label10.sensitive = false
|
64
|
+
@entry_log_filepath.sensitive = false
|
65
|
+
|
66
|
+
@combobox_logtype.active = 0
|
67
|
+
else
|
68
|
+
# Activate log path entry.
|
69
|
+
@label10.sensitive = true
|
70
|
+
@entry_log_filepath.sensitive = true
|
71
|
+
|
72
|
+
# Set entry text accordingly.
|
73
|
+
@entry_log_filepath.text = @config.log_target
|
74
|
+
|
75
|
+
@combobox_logtype.active = 1
|
76
|
+
end
|
77
|
+
|
78
|
+
# If privilege section is given in config.
|
79
|
+
if(@config.privileges.empty?)
|
80
|
+
# Deactivate user entry.
|
81
|
+
@label15.sensitive = false
|
82
|
+
@entry_drop_privileges_user.sensitive = false
|
83
|
+
|
84
|
+
# Deactivate group entry.
|
85
|
+
@label16.sensitive = false
|
86
|
+
@entry_drop_privileges_group.sensitive = false
|
87
|
+
|
88
|
+
@checkbutton_drop_privileges.active = false
|
89
|
+
else
|
90
|
+
# Activate user entry.
|
91
|
+
@label15.sensitive = true
|
92
|
+
@entry_drop_privileges_user.sensitive = true
|
93
|
+
|
94
|
+
# Activate group entry.
|
95
|
+
@label16.sensitive = true
|
96
|
+
@entry_drop_privileges_group.sensitive = true
|
97
|
+
|
98
|
+
# Set entry texts accordingly.
|
99
|
+
@entry_drop_privileges_user.text = @config.privileges.user
|
100
|
+
@entry_drop_privileges_group.text = @config.privileges.group
|
101
|
+
|
102
|
+
@checkbutton_drop_privileges.active = true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Initializes the ListBox widget.
|
107
|
+
def initialize_listbox
|
108
|
+
@listbox = ListBox.new
|
109
|
+
@listbox.header = 'Feeds'
|
110
|
+
|
111
|
+
@vbox2.pack_start(@listbox)
|
112
|
+
|
113
|
+
@window1.show_all
|
114
|
+
|
115
|
+
@listbox.signal_connect('button_release_event') do |widget, event|
|
116
|
+
@entry_feed_url.text = @listbox.button_release(widget, event)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Add a feed to the ListBox if the Add-feed-button is pressed.
|
121
|
+
def on_button_add_feed(widget)
|
122
|
+
if(not @entry_feed_url.text.empty?)
|
123
|
+
@listbox.add(@entry_feed_url.text)
|
124
|
+
@entry_feed_url.text = ''
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Remove a feed from the ListBox if the Remove-feed-button is pressed.
|
129
|
+
def on_button_remove_feed(widget)
|
130
|
+
@listbox.remove(@entry_feed_url.text)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Activate or deactivate entry widgets if drop privileges checkbutton is
|
134
|
+
# toggled.
|
135
|
+
def on_checkbutton_drop_privileges_toggled(widget)
|
136
|
+
if(@checkbutton_drop_privileges.active?)
|
137
|
+
# Activate user entry.
|
138
|
+
@label15.sensitive = true
|
139
|
+
@entry_drop_privileges_user.sensitive = true
|
140
|
+
|
141
|
+
# Activate group entry.
|
142
|
+
@label16.sensitive = true
|
143
|
+
@entry_drop_privileges_group.sensitive = true
|
144
|
+
else
|
145
|
+
# Deactivate user entry.
|
146
|
+
@label15.sensitive = false
|
147
|
+
@entry_drop_privileges_user.sensitive = false
|
148
|
+
|
149
|
+
# Deactivate group entry.
|
150
|
+
@label16.sensitive = false
|
151
|
+
@entry_drop_privileges_group.sensitive = false
|
152
|
+
|
153
|
+
# Delete entry texts.
|
154
|
+
@entry_drop_privileges_user.text = ''
|
155
|
+
@entry_drop_privileges_group.text = ''
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Is called when a value in the log type ComboBox is selected.
|
160
|
+
def on_combobox_logtype_changed(widget)
|
161
|
+
# If STDERR is selected.
|
162
|
+
if(@combobox_logtype.active == 0)
|
163
|
+
# Deactivate the log file path entry.
|
164
|
+
@label10.sensitive = false
|
165
|
+
@entry_log_filepath.sensitive = false
|
166
|
+
|
167
|
+
# Delete entry text.
|
168
|
+
@entry_log_filepath.text = ''
|
169
|
+
else
|
170
|
+
# Activate the log file path entry.
|
171
|
+
@label10.sensitive = true
|
172
|
+
@entry_log_filepath.sensitive = true
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# Is called when the Help-About menu is selected.
|
177
|
+
def on_menu_about(widget)
|
178
|
+
Gnome::About.new(
|
179
|
+
TITLE,
|
180
|
+
VERSION,
|
181
|
+
'Copyright (C) 2010 henning mueller',
|
182
|
+
'Easy transmission-rss config editing. Devoted to Ann.',
|
183
|
+
['henning mueller'],
|
184
|
+
['henning mueller'],
|
185
|
+
nil
|
186
|
+
).show
|
187
|
+
end
|
188
|
+
|
189
|
+
# Is called when the File-New menu is selected.
|
190
|
+
def on_menu_new(widget)
|
191
|
+
dialog = Gtk::MessageDialog.new(
|
192
|
+
@window1,
|
193
|
+
Gtk::Dialog::DESTROY_WITH_PARENT,
|
194
|
+
Gtk::MessageDialog::WARNING,
|
195
|
+
Gtk::MessageDialog::BUTTONS_YES_NO,
|
196
|
+
"Unsaved configuration will be lost!\nProceed?"
|
197
|
+
)
|
198
|
+
|
199
|
+
if(dialog.run == Gtk::Dialog::RESPONSE_YES)
|
200
|
+
@configFile = nil
|
201
|
+
|
202
|
+
@config.clear
|
203
|
+
@config.load(DEFAULT_CONFIG)
|
204
|
+
|
205
|
+
initialize_config
|
206
|
+
end
|
207
|
+
|
208
|
+
dialog.destroy
|
209
|
+
end
|
210
|
+
|
211
|
+
# Is called when the File-Open menu is selected.
|
212
|
+
def on_menu_open(widget)
|
213
|
+
dialog = Gtk::FileChooserDialog.new(
|
214
|
+
'Open',
|
215
|
+
@window1,
|
216
|
+
Gtk::FileChooser::ACTION_OPEN,
|
217
|
+
nil,
|
218
|
+
[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
|
219
|
+
[Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT]
|
220
|
+
)
|
221
|
+
|
222
|
+
if(dialog.run == Gtk::Dialog::RESPONSE_ACCEPT)
|
223
|
+
@configFile = dialog.filename
|
224
|
+
|
225
|
+
@config.clear
|
226
|
+
@config.load(DEFAULT_CONFIG)
|
227
|
+
@config.load(@configFile)
|
228
|
+
|
229
|
+
initialize_config
|
230
|
+
end
|
231
|
+
|
232
|
+
dialog.destroy
|
233
|
+
end
|
234
|
+
|
235
|
+
# Is called when the File-Save menu is selected.
|
236
|
+
def on_menu_save(widget)
|
237
|
+
if(not @configFile.nil?)
|
238
|
+
save!
|
239
|
+
else
|
240
|
+
on_menu_save_as(nil)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
# Is called when the File-SaveAs menu is selected.
|
245
|
+
def on_menu_save_as(widget)
|
246
|
+
dialog = Gtk::FileChooserDialog.new(
|
247
|
+
'Save As..',
|
248
|
+
@window1,
|
249
|
+
Gtk::FileChooser::ACTION_SAVE,
|
250
|
+
nil,
|
251
|
+
[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
|
252
|
+
[Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]
|
253
|
+
)
|
254
|
+
|
255
|
+
if(dialog.run == Gtk::Dialog::RESPONSE_ACCEPT)
|
256
|
+
@configFile = dialog.filename
|
257
|
+
save!
|
258
|
+
end
|
259
|
+
|
260
|
+
dialog.destroy
|
261
|
+
end
|
262
|
+
|
263
|
+
# Is called when the File-Quit menu is selected.
|
264
|
+
def on_menu_quit(widget)
|
265
|
+
Gtk.main_quit
|
266
|
+
end
|
267
|
+
|
268
|
+
# Convert GUI config to +Config+, open the config file and write a YAML
|
269
|
+
# version of the Hash.
|
270
|
+
def save!
|
271
|
+
@config.server.host = @entry_server_host.text
|
272
|
+
@config.server.port = @entry_server_port.text.to_i
|
273
|
+
|
274
|
+
@config.update_interval = @entry_update_interval.text.to_i
|
275
|
+
|
276
|
+
@config.add_paused = @checkbutton_add_paused.active?
|
277
|
+
|
278
|
+
@config.feeds = @listbox.items
|
279
|
+
|
280
|
+
# If STDERR is selected.
|
281
|
+
if(@combobox_logtype.active == 0)
|
282
|
+
# Delete log_target from config hash, so $stderr is chosen on load.
|
283
|
+
@config.delete('log_target')
|
284
|
+
else
|
285
|
+
# Set log_target to entry text.
|
286
|
+
@config.log_target = @entry_log_filepath.text
|
287
|
+
end
|
288
|
+
|
289
|
+
# If checkbutton drop privileges is activated.
|
290
|
+
if(@checkbutton_drop_privileges.active?)
|
291
|
+
# Set user and group to entry texts.
|
292
|
+
@config.privileges.user = @entry_drop_privileges_user.text
|
293
|
+
@config.privileges.group = @entry_drop_privileges_group.text
|
294
|
+
else
|
295
|
+
# Delete privilege section from config hash.
|
296
|
+
@config.delete('privileges')
|
297
|
+
end
|
298
|
+
|
299
|
+
# Try writing to file; dialog on permission error.
|
300
|
+
begin
|
301
|
+
File.open(@configFile, 'w') do |f|
|
302
|
+
f.write(@config.to_yaml)
|
303
|
+
end
|
304
|
+
rescue Errno::EACCES
|
305
|
+
dialog = Gtk::MessageDialog.new(
|
306
|
+
@window1,
|
307
|
+
Gtk::Dialog::DESTROY_WITH_PARENT,
|
308
|
+
Gtk::MessageDialog::ERROR,
|
309
|
+
Gtk::MessageDialog::BUTTONS_CLOSE,
|
310
|
+
"Permission denied:\n" + @configFile
|
311
|
+
)
|
312
|
+
|
313
|
+
dialog.run
|
314
|
+
dialog.destroy
|
315
|
+
|
316
|
+
on_menu_save_as(nil)
|
317
|
+
end
|
318
|
+
end
|
319
319
|
end
|