Class: App

Inherits:
Gtk::Window
  • Object
show all
Defined in:
lib/gui/base_window.rb

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ App

Returns a new instance of App.



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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/gui/base_window.rb', line 140

def initialize(title)

 super(title)
 @size_changed_from_menu=false
 @busy = 0

 pluginslist=[]
 create_plugins_list(pluginslist)

proc_map_window=Proc.new {|action, current|
	@size_changed_from_menu=true
	$config.map_display_view=current.name
	if current.name == "25% screen"
		map_window_activ_quart()
	elsif current.name == "50% screen"
		map_window_activ_half()
	elsif current.name == "100% screen"
		map_window_activ_full()
	elsif current.name == "Full screen"
		$canvas.toggle_fullscreen()
	end
}

proc_icon=Proc.new  {|action, current|
	if current.name.index("host")
if current.name == "host_type"
$config.host_icon_view="type"
	 host_icon()
else
$config.host_icon_view="os"
	 host_icon()
end
	else
		if current.name == "network_type"
$config.network_icon_view="type"
network_icon()
		else
$config.network_icon_view="os"
network_icon()
		end
	end
}

proc_label=Proc.new {|action, current|
	if current.name.index("host")
		if current.name == "host_dns_name"
 $config.host_label_view="dns_name"
 host_label()
elsif current.name == "host_netbios_name"
 $config.host_label_view="netbios_name"
 host_label()
elsif current.name == "host_ip"
 $config.host_label_view="ip"
 host_label()
elsif current.name == "host_osl"
   $config.host_label_view="os"
 host_label()
elsif current.name == "host_mac"
 $config.host_label_view="mac"
 host_label()
elsif current.name == "host_mac_manufacturer"
 $config.host_label_view="mac_manufacturer"
 host_label()
elsif current.name == "host_description"
 $config.host_label_view="description"
 host_label()
end
	else
		case current.name
		when "network_name"
$config.network_label_view="name"
network_label()
		when "network_dns_domain"
  $config.network_label_view="dns_domain"
network_label()
		when "network_netbios_domain"
   $config.network_label_view="netbios_domain"
network_label()
		when "network_ip"
 	$config.network_label_view="ip"
network_label()
		when "network_osl"
 		$config.network_label_view="os"
network_label()
		when "network_description"
$config.network_label_view="description"
network_label()
		end
	end
}

plugins_list_xml=""
pluginslist.each {|plugin_name_table|
	plugins_list_xml="#{plugins_list_xml}\n<menuitem action='#{plugin_name_table[0]}'/>"
}

main_menu = %Q[
<ui>
  <menubar name='MainBar'>
 <menu action='FileMenu'>
   <menuitem action='Open backup file'/>
   <menuitem action='Save log'/>
   <menuitem action='Save map'/>
   <menuitem action='Save map as XML'/>
   <menuitem action='Snapshot'/>
   <separator/>
   <menuitem action='Reset'/>
   <separator/>
   <menuitem action='Quit'/>
 </menu>
 <menu action='ViewMenu'>
		<menu action='LabelMenu'>
   	<menu action='LabelHostMenu'>
	<menuitem action='host_dns_name'/>
	<menuitem action='host_netbios_name'/>
	<menuitem action='host_ip'/>
	<menuitem action='host_osl'/>
	<menuitem action='host_mac'/>
	<menuitem action='host_mac_manufacturer'/>
	<menuitem action='host_description'/>
   	</menu>
   	<menu action='LabelNetworkMenu'>
	<menuitem action='network_name'/>
	<menuitem action='network_dns_domain'/>
	<menuitem action='network_netbios_domain'/>
	<menuitem action='network_ip'/>
	<menuitem action='network_osl'/>
	<menuitem action='network_description'/>
   	</menu>
		</menu>
		<menu action='IconMenu'>
   	<menu action='IconHostMenu'>
	<menuitem action='host_osi'/>
	<menuitem action='host_type'/>
   	</menu>
   	<menu action='IconNetworkMenu'>
	<menuitem action='network_osi'/>
	<menuitem action='network_type'/>
   	</menu>
		</menu>
   <separator/>
   <menuitem action='Select all nodes'/>
   <menuitem action='Switch selected nodes'/>
   <separator/>
   <menuitem action='Zoom in'/>
   <menuitem action='Zoom out'/>
    <menu action='MapWindowMenu'>
     <menuitem action='User defined'/>
     <menuitem action='25% screen'/>
     <menuitem action='50% screen'/>
     <menuitem action='100% screen'/>
     <menuitem action='Full screen'/>
    </menu>     
   </menu>
	 <menu action='ManageMenu'>
   <menu action='AddMenu'>
   	<menuitem action='Add host'/>
   	<menuitem action='Add host range'/>
   	<menuitem action='Add network'/>
   </menu>
   <menuitem action='Del node'/>
   <separator/>
   <menuitem action='Unwanted node'/>
 </menu>
 <menu action='OptionMenu'>
   <menuitem action='Preference'/>
   <menu action='EventConfMenu'>
   	<menuitem action='SNMP OID conf'/>
   	<menuitem action='SNMP Trap conf'/>
   	<menuitem action='WMI Request conf'/>
   	<menuitem action='JMX Ref conf'/>
   	<menuitem action='Syslog Ref conf'/>
   	<menuitem action='Custom conf'/>	
   </menu>
 </menu>
 <menu action='ToolsMenu'>
   <menuitem action='Node Tree'/>
   <menuitem action='Node Find'/>
   <menuitem action='Event browser'/>
   <menuitem action='MIB browser'/>
   <menuitem action='IP calculator'/>
 </menu>
 <menu action='PluginMenu'>
#{plugins_list_xml}
 </menu>
 <menu action='HelpMenu'>
   <menuitem action='Help'/>
   <menuitem action='Update'/>
   <menuitem action='About...'/>
 </menu>
  </menubar>
</ui>]

#we need to have an action_procs!
@action_procs=actions = [
  ["FileMenu", nil, "_File"],
  ["Open backup file", Gtk::Stock::OPEN, "_Open backup file", "<control>O", "Open backup file", proc{ open_file }],
  ["Save log", Gtk::Stock::SAVE, "Save _Log", "<control>L", "Save current log", proc{ $event_win.save_event() }],
  ["Save map", Gtk::Stock::SAVE, "_Save Map", "<control>S", "Save map", proc{ save }],
  ["Save map as XML", Gtk::Stock::SAVE, "Save Map As _XML", "<control>X", "Save map to a file", proc{ save_as }],
  ["Snapshot", Gtk::Stock::PRINT, "Snap Shot", nil, "Take a snapshot", proc{ snapshot }],
  ["Reset", Gtk::Stock::NEW, "_Reset", "<control>R", "Create a new map", proc{ new_map }],
  ["Quit", Gtk::Stock::QUIT, "_Quit", "<control>Q", "Quit", proc{ quit_now }],
  ["ViewMenu", nil, "View"],
  ["LabelMenu", nil, "Node label"],
  ["IconMenu", nil, "Node icon"],
  ["LabelHostMenu", nil, "Host as"],
  ["IconHostMenu", nil, "Host as"],
  ["LabelNetworkMenu", nil, "Network as"],
  ["IconNetworkMenu", nil, "Network as"],
  ["Select all nodes", nil, "Select _all nodes", "<control>A", "", proc { select_all_node() }],
  ["Switch selected nodes", nil, "Sw_itch selected nodes", "<control>I", "", proc { invert_selected_node() }],
  ["Zoom in", Gtk::Stock::ZOOM_IN, "Zoom in", "KP_Add", "", proc { $canvas.node_view_zoom_in() }],
  ["Zoom out", Gtk::Stock::ZOOM_OUT, "Zoom out", "KP_Subtract", "", proc { $canvas.node_view_zoom_out() }],
  ["MapWindowMenu", nil, "Map window"],
  ["ManageMenu", nil, "Manage"],
  ["AddMenu", Gtk::Stock::ADD, "Add node"],
  ["Add host", nil, "Host", nil, "", proc { addnodewin }],
  ["Add host range", nil, "Host range", nil, "", proc { add_host_range }],
  ["Add network", nil, "Network", nil, "", proc { addnetworkwin }],
  ["Del node", Gtk::Stock::REMOVE, "Del node", nil, "", proc { delnodewin }],
  ["Unwanted node", Gtk::Stock::PREFERENCES, "Unwanted node", nil, "", proc { unwantednodewin }],  
  ["OptionMenu", nil, "Option"],
  ["Preference", Gtk::Stock::PREFERENCES, "Preference", nil, "", proc { create_config_option } ],
  ["EventConfMenu", nil, "Monitoring conf"],
  ["SNMP OID conf", nil, "SNMP OID", "", "", proc { OIDRefWindow.new() }],
  ["WMI Request conf", nil, "WMI Request", "", "", proc { WMIRefWindow.new() }],
  ["Syslog Ref conf", nil, "Syslog Event", "", "", proc { SyslogRefWindow.new() }],
  ["SNMP Trap conf", nil, "SNMP Trap", "", "", proc { SnmpTrapRefWindow.new() }],
  ["JMX Ref conf", nil, "JMX Request", "", "", proc { JMXRefWindow.new() }],
  ["Custom conf", nil, "Custom Plugin", "", "", proc { CustomPluginWindow.new() }],  
  ["ToolsMenu", nil, "Tools"],
  ["Node Tree", nil, "Node _Tree", "<control>T", "", proc { $treenode_win.show() }],
  ["Node Find", Gtk::Stock::FIND, "Node _Find", "<control>F", "", proc { findnodewin }],
  ["Event browser", nil, "_Event browser", "<control>E", "", proc { $event_win.show() }],
  ["MIB browser", nil, "_MIB browser", "<control>M", "", proc { MibBrowser.new }],
  ["IP calculator", nil, "IP _calculator", "<control>C", "", proc { netmask_calculator} ],
  ["PluginMenu", nil, "Plugins"],
  ["HelpMenu", nil, "Help"],
  ["Help", Gtk::Stock::HELP, "Help", nil, "", proc{ create_help }],
  ["Update", Gtk::Stock::HOME, "Check update", nil, "", proc{ check_update }],
  ["About...", Gtk::Stock::ABOUT, "About", nil, "About", proc{ AboutWindow.new }]
]
$log.info("#{pluginslist.length()} plugin" + (pluginslist.length()>1?"s":"") + " loaded")
if pluginslist.length()
	actions=actions+pluginslist
end

map_window_radio_actions = [
  ["User defined", nil, "User defined", nil, "User defined", 0],
  ["25% screen", nil, "25% screen", nil, "25% screen", 1],
  ["50% screen", nil, "50% screen", nil, "50% screen", 2],
  ["100% screen", nil, "100% screen", nil, "100% screen", 3],
  ["Full screen", nil, "Full screen", nil, "Full screen", 4]
]

node_host_label_radio_actions = [
  ["host_dns_name", nil, "DNS Name", nil, "DNS Name", 0],
  ["host_netbios_name", nil, "Netbios Name", nil, "Netbios Name", 1],
  ["host_ip", nil, "IP", nil, "IP", 2],
  ["host_osl", nil, "OS", nil, "OS", 3],
  ["host_mac", nil, "MAC", nil, "MAC", 4],
  ["host_mac_manufacturer", nil, "MAC manufacturer", nil, "MAC manufacturer", 5],
  ["host_description", nil, "Description", nil, "Description", 6]
]

node_network_label_radio_actions = [
  ["network_name", nil, "Name", nil, "Name", 0],
  ["network_dns_domain", nil, "DNS Domain", nil, "DNS Domain", 1],
  ["network_netbios_domain", nil, "Netbios Domain", nil, "Netbios Domain", 2],
  ["network_ip", nil, "IP", nil, "IP", 3],
  ["network_osl", nil, "OS", nil, "OS", 4],
  ["network_description", nil, "Description", nil, "Description", 5]
]

node_host_icon_radio_actions = [
  ["host_osi", nil, "OS", nil, "OS", 0],
  ["host_type", nil, "Type", nil, "Type", 1]
]
node_network_icon_radio_actions=[
  ["network_osi", nil, "OS", nil, "OS", 0],
  ["network_type", nil, "Type", nil, "Type", 1]
]
  @ag=actiongroup = Gtk::ActionGroup.new("Actions")
  actiongroup.add_actions(actions)

  map_display=0
  map_window_radio_actions.each do |tab|
	if $config.map_display_view == tab[0]
		map_display=tab[5]
	end
  end
  actiongroup.add_radio_actions(map_window_radio_actions, map_display, proc_map_window )

  label_view_pos=0
  node_host_label_radio_actions.each do |tab|
		if ("host_#{$config.host_label_view}" == tab[0]) || ("host_#{$config.host_label_view}l" == tab[0])
break
		end
		label_view_pos+=1
  end
  actiongroup.add_radio_actions(node_host_label_radio_actions, label_view_pos, proc_label )

  label_view_pos=0
  node_network_label_radio_actions.each do |tab|
		if ("network_#{$config.network_label_view}" == tab[0]) || ("network_#{$config.network_label_view}l" == tab[0])
break
		end
		label_view_pos+=1
  end
  actiongroup.add_radio_actions(node_network_label_radio_actions, label_view_pos, proc_label )
  
  icon_view_pos=0
  node_host_icon_radio_actions.each do |tab|
		if ("host_#{$config.host_icon_view}" == tab[0]) || ("host_#{$config.host_icon_view}i" == tab[0])
break
		end
		icon_view_pos+=1
  end
  actiongroup.add_radio_actions(node_host_icon_radio_actions, icon_view_pos, proc_icon )

  icon_view_pos=0
  node_network_icon_radio_actions.each do |tab|
		if ("network_#{$config.network_icon_view}" == tab[0]) || ("network_#{$config.network_icon_view}i" == tab[0])
break
		end
		icon_view_pos+=1
  end
  actiongroup.add_radio_actions(node_network_icon_radio_actions, icon_view_pos, proc_icon )

  uimanager = Gtk::UIManager.new
  uimanager.insert_action_group(actiongroup, 0)
  add_accel_group(uimanager.accel_group)
  uimanager.add_ui(main_menu)
  @main_bar=uimanager.get_widget("/MainBar")
  #we set height size
  @main_bar.height_request=30

  $canvas=CanvasMap.new
  $canvas_root=$canvas.get_root()

  @main_vbox = Gtk::VBox.new()

  @main_vbox.pack_start(@main_bar, false)
  @main_vbox.pack_start($canvas, true, true) 

 @main_vbox.signal_connect('size-allocate') { |w,e|
		set_map_display_view_user_defined()
		height=e.height
		if !$canvas.fullscreen?()
height -= @main_bar.height_request
		else
#we need to store $win size!
$root_width=$win.window.geometry[2]
$root_height=$win.window.geometry[3]
		end
		$canvas.set_size(e.width, height)
	false
 }
 
  add(@main_vbox)
  show_all()
  $canvas.grab_focus()
  #on startup we hide some menu entries
  hide_menu_entry()

end

Instance Method Details

#busyObject



70
71
72
73
74
# File 'lib/gui/base_window.rb', line 70

def busy()
   @busy = 1
   self.disable_menu()
   self.window.cursor = Gdk::Cursor.new(Gdk::Cursor::WATCH) if self.window
end

#busy?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/gui/base_window.rb', line 82

def busy?()
   return @busy == 1
end

#check_updateObject



124
125
126
# File 'lib/gui/base_window.rb', line 124

def check_update()
	check_update_window()
end

#disable_menuObject



110
111
112
# File 'lib/gui/base_window.rb', line 110

def disable_menu()
	@main_bar.set_sensitive(false) if @main_bar
end

#enable_menuObject



114
115
116
# File 'lib/gui/base_window.rb', line 114

def enable_menu()
	@main_bar.set_sensitive(true) if @main_bar
end

#get_size_changed_from_menuObject



132
133
134
# File 'lib/gui/base_window.rb', line 132

def get_size_changed_from_menu()
	return @size_changed_from_menu
end

#hide_menuObject



106
107
108
# File 'lib/gui/base_window.rb', line 106

def hide_menu()
	@main_vbox.remove(@main_bar)
end

#hide_menu_entryObject



90
91
92
# File 'lib/gui/base_window.rb', line 90

def hide_menu_entry()
	@ag.get_action("AddMenu").sensitive=false
end

#hide_update_menu_entryObject



98
99
100
# File 'lib/gui/base_window.rb', line 98

def hide_update_menu_entry()
	@ag.get_action("Update").sensitive=false
end

#N_(text) ⇒ Object



66
67
68
# File 'lib/gui/base_window.rb', line 66

def N_ (text)
	return text
end

#proportional_node_position(wold, hold, w, h) ⇒ Object



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'lib/gui/base_window.rb', line 582

def proportional_node_position(wold, hold,w,h)

	tmp_table= [$host, $network]
	tmp_table.each {|hsh|
	  hsh.each_key {|ip|
	    xp=hsh[ip].x / wold.to_f
	    yp=hsh[ip].y / hold.to_f
	    
	    x = (xp*w).to_i
	    y = (yp*h).to_i
	    hsh[ip].node_view.hide_link()
	    hsh[ip].node_view.move(x-hsh[ip].x,y-hsh[ip].y)
	    hsh[ip].node_view.show_link()
	  }
	}
end

#set_display_view_menuObject



128
129
130
# File 'lib/gui/base_window.rb', line 128

def set_display_view_menu()
	@ag.get_action("User defined").activate
end

#set_map_display_view_user_definedObject



86
87
88
# File 'lib/gui/base_window.rb', line 86

def set_map_display_view_user_defined()
	$config.map_display_view="User defined"
end

#set_size_changed_from_menu(b) ⇒ Object



136
137
138
# File 'lib/gui/base_window.rb', line 136

def set_size_changed_from_menu(b)
	@size_changed_from_menu=b
end

#show_menuObject



118
119
120
121
122
# File 'lib/gui/base_window.rb', line 118

def show_menu()
	@main_bar.height_request=30
	@main_vbox.pack_start(@main_bar,false)
	@main_vbox.reorder_child(@main_bar,0)
end

#show_menu_entryObject



94
95
96
# File 'lib/gui/base_window.rb', line 94

def show_menu_entry()
	@ag.get_action("AddMenu").sensitive=true
end

#show_update_menu_entryObject



102
103
104
# File 'lib/gui/base_window.rb', line 102

def show_update_menu_entry()
	@ag.get_action("Update").sensitive=true
end

#snapshot_fileObject



749
750
751
752
753
754
755
# File 'lib/gui/base_window.rb', line 749

def snapshot_file()
  i=1
  while (FileTest.exist?("#{SNAPSHOT_DIR}/snapshot-#{i}.png"))
    i+=1
  end
  return "#{SNAPSHOT_DIR}/snapshot-#{i}.png"
end

#unbusyObject



76
77
78
79
80
# File 'lib/gui/base_window.rb', line 76

def unbusy()
   @busy = 0
   self.enable_menu()
   self.window.cursor = nil if self.window
end

#window_closeObject



667
668
669
# File 'lib/gui/base_window.rb', line 667

def window_close
  destroy
end