Class: SyslogRefWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/gui/syslog_ref_window.rb

Instance Method Summary collapse

Constructor Details

#initializeSyslogRefWindow

Returns a new instance of SyslogRefWindow.



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
# File 'lib/gui/syslog_ref_window.rb', line 15

def initialize()
		#save syslogref hash
		@syslogrefs_backup=$syslog_refs.dup

		@window=Gtk::Window.new

	@window.set_title("Syslog Ref configuration")
	@window.set_size_request(300, 200)

   @window.signal_connect("key_press_event") {|w,e|
     if e.keyval == Gdk::Keyval::GDK_Escape
  @window.destroy
     end
	}

		frame = Gtk::Frame::new
		frame.border_width=5
		frame.show
		vbox_root=Gtk::VBox::new
		vbox_root.show
		@window.add vbox_root
		vbox_root.add frame

		vbox = Gtk::VBox.new(false,0)
		vbox.show
		frame.add vbox

 @syslog_ref_ls = Gtk::ListStore.new(String, String)
   @syslog_ref_view = Gtk::TreeView.new(@syslog_ref_ls)
		@syslog_ref_view.show
column1 = Gtk::TreeViewColumn.new("Name",
		Gtk::CellRendererText.new, {:text => 0})
	column1.set_sort_column_id(0)
	column2 = Gtk::TreeViewColumn.new("Description",
		Gtk::CellRendererText.new, {:text => 1})
	column2.set_sort_column_id(1)

	@syslog_ref_view.append_column(column1)
	@syslog_ref_view.append_column(column2)
	
		scroll = Gtk::ScrolledWindow.new(nil, nil)
		scroll.border_width=2
		scroll.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC)  
		scroll.add @syslog_ref_view
		scroll.show

		# Create a menu
		menu = Gtk::Menu.new

		item_add = Gtk::ImageMenuItem.new("Add Syslog Ref")
image_item_add = Gtk::Image.new() 
image_item_add.set_stock(Gtk::Stock::ADD) 
		item_add.set_image(image_item_add)
		item_add.signal_connect("activate") { add_gui_syslog_ref() }
		menu.append(item_add)
		item_del = Gtk::ImageMenuItem.new("Delete selected Syslog Ref")
image_item_del = Gtk::Image.new() 
image_item_del.set_stock(Gtk::Stock::REMOVE) 
		item_del.set_image(image_item_del)
		item_del.signal_connect("activate") {
if @syslog_ref_view.selection.selected!=nil
	if SyslogRef::del_syslog_ref(@syslog_ref_view.selection.selected[0])
		@syslog_ref_view.model.remove(@syslog_ref_view.selection.selected)
	else
				dialog = Gtk::MessageDialog.new(@window, Gtk::Dialog::DESTROY_WITH_PARENT,
                          Gtk::MessageDialog::ERROR,
                          Gtk::MessageDialog::BUTTONS_OK,
                          "You can't delete! Syslog Ref in use")
		dialog.run
		dialog.destroy
	end
end
		}
		menu.append(item_del)
		item_edit = Gtk::ImageMenuItem.new("Edit Syslog Ref")
image_item_edit = Gtk::Image.new() 
image_item_edit.set_stock(Gtk::Stock::EDIT) 
		item_edit.set_image(image_item_edit)
		item_edit.signal_connect("activate") { 
if @syslog_ref_view.selection.selected != nil
	edit_syslog_ref(@syslog_ref_view.selection.selected[0])
end
		}
		menu.append(item_edit)

		menu.show_all

		@syslog_ref_view.signal_connect("button_press_event") do |widget, event|
 if event.kind_of? Gdk::EventButton and event.button == 3
 if @syslog_ref_view.selection.selected == nil
	 item_del.set_sensitive(false)
	 item_edit.set_sensitive(false)
 else
	 item_del.set_sensitive(true)
	 item_edit.set_sensitive(true)
 end
		 menu.popup(nil, nil, event.button, event.time)
 elsif (@syslog_ref_view.selection.selected != nil) && (event.event_type == Gdk::Event::BUTTON2_PRESS)
	edit_syslog_ref(@syslog_ref_view.selection.selected[0])	
 end
		end

		populate_ls()
		vbox.add(scroll)

		bbox = Gtk::HBox::new(FALSE, 10)
		bbox.border_width=10
		bbox.show

		ok_button = Gtk::Button.new(Gtk::Stock::OK)
		ok_button.show
		ok_button.signal_connect("clicked") {
SyslogRef::write_db_syslogref()
@window.destroy
		}

		cancel_button = Gtk::Button.new(Gtk::Stock::CANCEL)
		cancel_button.show
		cancel_button.signal_connect("clicked") {
 $syslog_refs=@syslogrefs_backup
	  @window.destroy
		}
		ok_button.set_flags(Gtk::Widget::CAN_DEFAULT)
		bbox.pack_start(ok_button, TRUE, TRUE, 0)
		cancel_button.set_flags(Gtk::Widget::CAN_DEFAULT)
		bbox.pack_start(cancel_button, TRUE, TRUE, 0)

		separator = Gtk::HSeparator::new()
		separator.show
		vbox_root.pack_start(separator, FALSE, TRUE, 0)
		vbox_root.pack_start(bbox, FALSE, TRUE, 0)

		@window.show
end

Instance Method Details

#add_gui_syslog_refObject



150
151
152
# File 'lib/gui/syslog_ref_window.rb', line 150

def add_gui_syslog_ref()
	add_modify_syslog_ref(true)
end

#add_modify_syslog_ref(add_boolean, syslog_ref_name = nil) ⇒ Object



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
# File 'lib/gui/syslog_ref_window.rb', line 158

def add_modify_syslog_ref(add_boolean, syslog_ref_name=nil)
	window=Gtk::Window.new
	window.set_modal(true)
	lbl="Edit Syslog Ref"
	if add_boolean
		lbl="Add Syslog Ref"
	end
	
  	window.set_title(lbl)
  	window.set_size_request(460, 160)

     window.signal_connect("key_press_event") {|w,e|
       if e.keyval == Gdk::Keyval::GDK_Escape
		  window.destroy
       end
  	}

	frame = Gtk::Frame::new
	frame.border_width=10
	frame.show
	vbox_root=Gtk::VBox::new
	vbox_root.show
	window.add vbox_root
	vbox_root.add frame

	vbox = Gtk::VBox.new
	vbox.show
	frame.add vbox

	table = Gtk::Table.new(3,2,false)
	table.show

	label_name = Gtk::Label.new "Name"
	label_name.show
	if add_boolean
		entry_name = Gtk::Entry.new			
	else
		entry_name = Gtk::Entry.new	
		entry_name.set_editable false
		entry_name.set_text(syslog_ref_name)
	end
	entry_name.show

	table.attach(label_name,0,1,0,1)
	table.attach(entry_name,1,2,0,1)

	entry_description = Gtk::Entry.new
	if !add_boolean
		entry_description.set_text($syslog_refs[entry_name.text()].description) unless entry_name.text() == ""
	end
	entry_description.show
	label_description = Gtk::Label.new "Description"
	label_description.show

	table.attach(label_description,0,1,1,2)
	table.attach(entry_description,1,2,1,2)

	entry_value = Gtk::Entry.new
	if !add_boolean
		entry_value.set_text($syslog_refs[entry_name.text()].value.source) unless entry_name.text() == ""
	end
	entry_value.show
	label_value = Gtk::Label.new "Value"
	label_value.show

	table.attach(label_value,0,1,2,3)
	table.attach(entry_value,1,2,2,3)
	if !add_boolean
   	  entry_name.signal_connect("changed") {|e|
     	  if e.text() != ""
			  entry_description.set_text($syslog_refs[e.text()].description)
			  entry_value.set_text($syslog_refs[e.text()].value)
		  end
   	  }
	end
	bbox =Gtk::HBox::new(FALSE, 10)
	bbox.border_width=10
	bbox.show

	ok_button = Gtk::Button.new(Gtk::Stock::OK)
	ok_button.show
	ok_button.signal_connect("clicked") {
		if add_boolean
			#new entry!
			if $syslog_refs[entry_name.text()] == nil
				SyslogRef::add_syslog_ref(entry_name.text(),entry_description.text(),entry_value.text())
			   iter = @syslog_ref_ls.append
			   iter[0] = entry_name.text()
			   iter[1] = entry_description.text()
				window.destroy 
			else
  				dialog = Gtk::MessageDialog.new(window, Gtk::Dialog::DESTROY_WITH_PARENT,
                            Gtk::MessageDialog::ERROR,
                            Gtk::MessageDialog::BUTTONS_OK,
                            "Syslog Ref '#{entry_name.text()}' already exists!")
				dialog.run
				dialog.destroy
			end
		else
			#modify existing entry
			$syslog_refs[entry_name.text()].description=entry_description.text()
			$syslog_refs[entry_name.text()].set_value(entry_value.text())
		   @syslog_ref_ls.each do |model,path,iter|
				if iter[0] == entry_name.text()
					iter[1]=entry_description.text()
					break
				end
			end
			window.destroy 
		end
	}

	cancel_button = Gtk::Button.new(Gtk::Stock::CANCEL)
	cancel_button.show
	cancel_button.signal_connect("clicked") {
  	  window.destroy
	}

	ok_button.set_flags(Gtk::Widget::CAN_DEFAULT)
	bbox.pack_start(ok_button, TRUE, TRUE, 0)
	cancel_button.set_flags(Gtk::Widget::CAN_DEFAULT)
	bbox.pack_start(cancel_button, TRUE, TRUE, 0)

	vbox.add(table)
	separator = Gtk::HSeparator::new()
	separator.show
	vbox_root.pack_start(separator, FALSE, TRUE, 0)
	vbox_root.pack_start(bbox, FALSE, TRUE, 0)
	window.show
end

#clear_lsObject



3
4
5
# File 'lib/gui/syslog_ref_window.rb', line 3

def clear_ls()
	@syslog_ref_ls.clear()
end

#edit_syslog_ref(syslog_ref_name) ⇒ Object



154
155
156
# File 'lib/gui/syslog_ref_window.rb', line 154

def edit_syslog_ref(syslog_ref_name)
	add_modify_syslog_ref(false, syslog_ref_name)
end

#populate_lsObject

populate listview with saved values



7
8
9
10
11
12
13
# File 'lib/gui/syslog_ref_window.rb', line 7

def populate_ls()
  	$syslog_refs.each_key do |name|
	  iter = @syslog_ref_ls.append
	  iter[0] = name
	  iter[1] = $syslog_refs[name].description
	end
end