/[gli]/branches/overhaul/src/fe/gtk/Networking.py
Gentoo

Contents of /branches/overhaul/src/fe/gtk/Networking.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1623 - (show annotations) (download) (as text)
Fri Jan 19 10:19:38 2007 UTC (7 years, 7 months ago) by agaffney
File MIME type: text/x-python
File size: 31630 byte(s)
remove Help button
rearrange Stage screen
1 # Copyright 1999-2005 Gentoo Foundation
2 # This source code is distributed under the terms of version 2 of the GNU
3 # General Public License as published by the Free Software Foundation, a copy
4 # of which can be found in the main directory of this project.
5
6 import gtk,gobject
7 import os
8 import re
9 import GLIScreen
10 import GLIUtility
11 import commands, string
12 import copy
13 #import subprocess
14 from Widgets import Widgets
15
16 class Panel(GLIScreen.GLIScreen):
17 """
18 The Networking section of the installer.
19
20 @author: John N. Laliberte <allanonjl@gentoo.org>
21 @license: GPL
22 """
23 # Attributes:
24 title="Networking Settings"
25 _helptext = """
26 <b><u>Networking</u></b>
27
28 If you previously set up a network interface in the Pre-install Configuration
29 screen, it should show up configured again in the Device list.
30
31 All detected interfaces should show up in the list, but you also have the option
32 to type in your own interface. Once you select an interface, select DHCP or
33 Static Configuration. Then once you have set your network settings make sure to
34 click Save to add the interface to the list.
35
36 Wireless support currently is unavailable, but coming soon! We even have the
37 boxes for it all ready to go.
38
39 Don't forget to set a hostname and domain name in the
40 "Hostname / Proxy Information / Other" tab!
41 """
42
43 # Operations
44 def __init__(self, controller):
45 GLIScreen.GLIScreen.__init__(self, controller)
46
47 vert = gtk.VBox(False, 0)
48 vert.set_border_width(10)
49 self.gateway = ["",""] # device, ip
50 self.gateway_is_set = False
51 self.first_run = False
52
53 # Treestore that holds the currently setup devices
54 # -----------------------------------------------
55 treedata = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING,
56 gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
57 columns = []
58 treedatasort = gtk.TreeModelSort(treedata)
59 treeview = gtk.TreeView(treedatasort)
60 #self.treeview.connect("cursor-changed", self.selection_changed)
61 columns.append(gtk.TreeViewColumn("Device ", gtk.CellRendererText(), text=1))
62 columns.append(gtk.TreeViewColumn("IP Address", gtk.CellRendererText(), text=2))
63 columns.append(gtk.TreeViewColumn("Broadcast ", gtk.CellRendererText(), text=3))
64 columns.append(gtk.TreeViewColumn("Netmask ", gtk.CellRendererText(), text=4))
65 columns.append(gtk.TreeViewColumn("DHCP Options ", gtk.CellRendererText(), text=5))
66 columns.append(gtk.TreeViewColumn("Gateway ", gtk.CellRendererText(), text=6))
67 col_num = 0
68 for column in columns:
69 column.set_resizable(True)
70 column.set_sort_column_id(col_num)
71 treeview.append_column(column)
72 col_num += 1
73 treewindow = gtk.ScrolledWindow()
74 treewindow.set_size_request(-1, 125)
75 treewindow.set_shadow_type(gtk.SHADOW_IN)
76 treewindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
77 treewindow.add(treeview)
78 # -----------------------------------------------
79
80
81 # Interface frame where you select the device
82 # -----------------------------------------------
83 #create the outside box for the ethernet device
84 frame = gtk.Frame()
85 # create the ethernet dropdown
86 ethernet_select_combo = gtk.combo_box_entry_new_text()
87 # pack it all into a box
88 ethernet_and_label = gtk.HBox(False,0)
89 label = gtk.Label(" _Interface: ")
90 label.set_use_underline(True)
91 save_button = gtk.Button("Save")
92 save_button.set_size_request(100,-1)
93 delete_button = gtk.Button("Delete")
94 delete_button.set_size_request(100,-1)
95 ethernet_and_label.pack_start(label, expand=False, fill=False, padding=5)
96 ethernet_and_label.pack_start(ethernet_select_combo, expand=False, fill=False, padding=5)
97 ethernet_and_label.pack_start(save_button, expand=False, fill=False, padding=5)
98 ethernet_and_label.pack_start(delete_button, expand=False, fill=False, padding=5)
99 # set the new widget to be the label plus the ethernet dropdown
100 frame.set_label_widget(ethernet_and_label)
101 # align it to the top left of the frame
102 frame.set_label_align(0.0, .5)
103 # -----------------------------------------------
104
105 # Type Frame where you select static or dhcp
106 # -----------------------------------------------
107 # create the type of ethernet frame
108 ethernet_type_frame_hbox = gtk.HBox(False, 0)
109 ethernet_type_frame = gtk.Frame()
110 ethernet_type_frame.set_border_width(5)
111 # create the combo that holds the different types of interfaces
112 ethernet_type_select_combo = gtk.combo_box_new_text()
113 ethernet_type_select_combo.append_text("DHCP")
114 ethernet_type_select_combo.append_text("Static")
115 self.dhcp = 0
116 self.static = 1
117 # pack it into a box
118 ethernet_type_and_label = gtk.HBox(False,0)
119 label = gtk.Label(" _Configuration: ")
120 label.set_use_underline(True)
121 ethernet_type_and_label.pack_start(label, expand=False, fill=False, padding=5)
122 ethernet_type_and_label.pack_start(ethernet_type_select_combo, expand=False, fill=False, padding=5)
123 # set the new widget to be the label plus the ethernet dropdown
124 ethernet_type_frame.set_label_widget(ethernet_type_and_label)
125 # align it to the top left of the frame
126 ethernet_type_frame.set_label_align(0.0, .5)
127 # -----------------------------------------------
128
129 # Create the gtk.Notebook to hold the static and dhcp configurations
130 # -----------------------------------------------
131 static_and_dhcp_notebook = gtk.Notebook()
132 static_and_dhcp_notebook.set_show_tabs(False) # hide the tabs
133 static_and_dhcp_notebook.set_show_border(False) # hide the border
134 #------------------------------------------------
135
136 # Static configuration frame of the gtk.Notebook ( page 1 )
137 # -----------------------------------------------
138 # create the static configuration frame
139 ethernet_static_frame_hbox = gtk.HBox(False, 0)
140 ethernet_static_frame = gtk.Frame()
141 ethernet_static_frame.set_border_width(5)
142 ethernet_static_frame.set_shadow_type(gtk.SHADOW_NONE)
143 #ethernet_static_frame.set_label("Static Configuration")
144 #ethernet_static_frame.set_label_align(0.0, .5)
145 # the hbox to pack the entry boxes into
146 static_entry_table = gtk.Table(rows=4, columns=2, homogeneous=False)
147 static_entry_table.set_row_spacings(5)
148
149 # create the static ip box
150 staticip_entry = gtk.Entry()
151 staticip_entry.set_max_length(15)
152 # pack it all into a box
153 label = gtk.Label(" _IP Address: ")
154 label.set_size_request(50,-1)
155 label.set_use_underline(True)
156 label.set_alignment(0.0, 0.5)
157 #label.set_size_request(150, -1)
158 static_entry_table.attach(label,0,1,0,1)
159 static_entry_table.attach(staticip_entry,1,2,0,1)
160
161 # create the broadcast box
162 broadcastip_entry = gtk.Entry()
163 broadcastip_entry.set_max_length(15)
164 # pack it all into a box
165 label = gtk.Label(" _Broadcast: ")
166 label.set_use_underline(True)
167 label.set_alignment(0.0, 0.5)
168 static_entry_table.attach(label,0,1,1,2)
169 static_entry_table.attach(broadcastip_entry,1,2,1,2)
170
171 # create the netmask box
172 netmaskip_entry = gtk.Entry()
173 netmaskip_entry.set_max_length(15)
174 # pack it all into a box
175 label = gtk.Label(" _Netmask: ")
176 label.set_use_underline(True)
177 label.set_alignment(0.0, 0.5)
178 static_entry_table.attach(label,0,1,2,3)
179 static_entry_table.attach(netmaskip_entry,1,2,2,3)
180
181 # create the gateway box
182 gatewayip_entry = gtk.Entry()
183 gatewayip_entry.set_max_length(15)
184 # pack it all into a box
185 label = gtk.Label(" _Gateway: ")
186 label.set_use_underline(True)
187 label.set_alignment(0.0, 0.5)
188 static_entry_table.attach(label,0,1,3,4)
189 static_entry_table.attach(gatewayip_entry,1,2,3,4)
190
191 # now add the 1 table to the ethernet_static_frame
192 static_entry_hbox = gtk.HBox(False,0)
193 static_entry_hbox.set_border_width(5)
194 static_entry_hbox.pack_start(static_entry_table, expand=False, fill=False, padding=5)
195 ethernet_static_frame.add(static_entry_hbox)
196 static_and_dhcp_notebook.append_page(ethernet_static_frame, gtk.Label("static"))
197 #------------------------------------------------
198
199 # Create the DHCP page of the gtk.Notebook ( page 2 )
200 # -----------------------------------------------
201 # create the dhcp configuration frame
202 ethernet_dhcp_frame_hbox = gtk.HBox(False, 0)
203 ethernet_dhcp_frame = gtk.Frame()
204 ethernet_dhcp_frame.set_border_width(5)
205 ethernet_dhcp_frame.set_shadow_type(gtk.SHADOW_NONE)
206 #ethernet_dhcp_frame.set_label("DHCP Configuration")
207 #ethernet_dhcp_frame.set_label_align(0.0, .5)
208 # the hbox to pack the entry boxes into
209 dhcp_entry_table = gtk.Table(rows=3, columns=2, homogeneous=False)
210 dhcp_entry_table.set_row_spacings(5)
211
212 # create the dhcp box
213 dhcp_options_entry = gtk.Entry()
214 dhcp_options_entry.set_max_length(15)
215 # pack it all into a box
216 label = gtk.Label(" _DHCP Options: ")
217 label.set_size_request(50,-1)
218 label.set_use_underline(True)
219 label.set_alignment(0.0, 0.5)
220 #label.set_size_request(150, -1)
221 dhcp_entry_table.attach(label,0,1,0,1)
222 dhcp_entry_table.attach(dhcp_options_entry,0,1,1,2)
223
224 # now add the 1 table to the ethernet_static_frame
225 dhcp_entry_hbox = gtk.HBox(False,0)
226 dhcp_entry_hbox.set_border_width(50)
227 dhcp_entry_hbox.pack_start(dhcp_entry_table, expand=False, fill=False, padding=5)
228 ethernet_dhcp_frame.add(dhcp_entry_hbox)
229
230 static_and_dhcp_notebook.append_page(ethernet_dhcp_frame, gtk.Label("dhcp"))
231 # -----------------------------------------------
232
233 # Create the wireless frame to hold wireless information
234 # -----------------------------------------------
235 # create the wireless frame
236 wireless_frame_hbox = gtk.HBox(False, 0)
237 wireless_frame = gtk.Frame()
238 #wireless_frame.set_border_width(5)
239 # align it to the top left of the frame
240 wireless_frame.set_label_align(0.0, .5)
241 # create the checkbox that will determine if you have wireless or not
242 wireless_checkbox = gtk.CheckButton("Wireless")
243 # pack it all into a box
244 wireless_and_label = gtk.HBox(False,0)
245 wireless_and_label.pack_start(wireless_checkbox, expand=False, fill=False, padding=5)
246 # set the new widget to be the checkbox
247 wireless_frame.set_label_widget(wireless_and_label)
248 # create the wireless input boxes
249 wireless_entry_table = gtk.Table(rows=2, columns=2, homogeneous=False)
250 wireless_entry_table.set_row_spacings(5)
251 # create the ESSID box
252 essid_entry = gtk.Entry()
253 essid_entry.set_max_length(30)
254 # pack it all into a box
255 essid_and_label = gtk.HBox(False,0)
256 label = gtk.Label(" _ESSID: ")
257 label.set_use_underline(True)
258 label.set_alignment(0.0, 0.5)
259 label.set_size_request(50,-1)
260 wireless_entry_table.attach(label,0,1,0,1)
261 wireless_entry_table.attach(essid_entry,1,2,0,1)
262 # create the Key box
263 key_entry = gtk.Entry()
264 key_entry.set_max_length(15)
265 # pack it all into a box
266 key_and_label = gtk.HBox(False,0)
267 label = gtk.Label(" _Key: ")
268 label.set_use_underline(True)
269 label.set_alignment(0.0, 0.5)
270 wireless_entry_table.attach(label,0,1,1,2)
271 wireless_entry_table.attach(key_entry,1,2,1,2)
272
273 # add it to the wireless frame
274 wireless_entry_hbox = gtk.HBox(False,0)
275 wireless_entry_hbox.set_border_width(5)
276 wireless_entry_hbox.pack_start(wireless_entry_table, expand=False, fill=False, padding=5)
277 wireless_frame.add(wireless_entry_hbox)
278 # -----------------------------------------------
279
280 # Ethernet hardware information frame
281 # -----------------------------------------------
282 hardware_frame = gtk.Frame()
283 #hardware_frame.set_border_width(5)
284 # align it to the top left of the frame
285 hardware_frame.set_label_align(0.0, .5)
286 hardware_frame.set_label("Hardware Information")
287 # create the textview to hold the hardware information
288 #textview = gtk.TextView(buffer=None)
289 #textview.set_editable(False)
290 #textbuffer = textview.get_buffer()
291 hardware_label = gtk.Label("No Device Selected")
292 hardware_label.set_size_request(250,75)
293 hardware_label.set_line_wrap(True)
294 #textbuffer.set_text(string)
295 hardware_frame.add(hardware_label)
296 # -----------------------------------------------
297
298 # add the configuration ethernet frame and wireless frame to the hbox.
299 configuration_and_wireless_hbox = gtk.HBox(False, 0)
300 wireless_and_hardware_vbox = gtk.VBox(False,0)
301 wireless_and_hardware_vbox.pack_start(wireless_frame, expand=True, fill=True, padding=5)
302 wireless_and_hardware_vbox.pack_start(hardware_frame, expand=True, fill=True, padding=5)
303 configuration_and_wireless_hbox.pack_start(ethernet_type_frame, expand=True, fill=True, padding=5)
304 configuration_and_wireless_hbox.pack_start(wireless_and_hardware_vbox, expand=True, fill=True, padding=5)
305
306 # add wireless and configuration to interface frame
307 frame.add(configuration_and_wireless_hbox)
308
309 # add the 1 hbox to the ethernet_type frame
310 #ethernet_type_frame.add(ethernet_static_frame)
311
312 # add the gtk.Notebook to the ethernet_type frame.
313 ethernet_type_frame.add(static_and_dhcp_notebook)
314
315 # finally show the frames ( after everything has been added )
316 ethernet_static_frame.show()
317 wireless_frame.show()
318 ethernet_type_frame.show()
319 frame.show()
320
321 # add hostname
322 bottom_hbox = gtk.VBox(False,0)
323 hostname_entry = gtk.Entry()
324 hostname_entry.set_max_length(50) # only as long as ipv4 addresses
325 hostname_entry.set_size_request(150,-1)
326
327 hostname_and_label = gtk.HBox(False,0)
328 label = gtk.Label(" _Hostname: ")
329 label.set_use_underline(True)
330 label.set_size_request(150,-1)
331 hostname_and_label.pack_start(label, expand=False, fill=False, padding=5)
332 hostname_and_label.pack_start(hostname_entry, expand=False, fill=False, padding=5)
333
334 # add dnsdomainname
335 dnsdomainname_entry = gtk.Entry()
336 dnsdomainname_entry.set_max_length(50) # only as long as ipv4 addresses
337 dnsdomainname_entry.set_size_request(150,-1)
338
339 dnsdomainname_and_label = gtk.HBox(False,0)
340 label = gtk.Label(" _DNS Domain Name: ")
341 label.set_use_underline(True)
342 label.set_size_request(150,-1)
343 dnsdomainname_and_label.pack_start(label, expand=False, fill=False, padding=5)
344 dnsdomainname_and_label.pack_start(dnsdomainname_entry, expand=False, fill=False, padding=5)
345
346 # pack the treewindow and overall options into an hbox
347 top_window_hbox = gtk.HBox(False, 0)
348 #static_options_vbox = gtk.VBox(False,0)
349 #static_options_vbox.pack_start(hostname_and_label, expand=False, fill=False, padding=5)
350 #static_options_vbox.pack_start(dnsdomainname_and_label, expand=False, fill=False, padding=5)
351 #static_options_vbox.pack_start(gateway_and_label, expand=False, fill=False, padding=5)
352 treeview_vbox = gtk.VBox(False,0)
353 #treeview_vbox.pack_start(gtk.Label("Currently Saved Devices:"), expand=False, fill=False, padding=5)
354 treeview_vbox.pack_start(treewindow, expand=False, fill=False, padding=5)
355 top_window_hbox.pack_start(treeview_vbox, expand=True, fill=True, padding=5)
356 #top_window_hbox.pack_end(static_options_vbox, expand=False, fill=False, padding=5)
357
358 bottom_hbox.pack_start(hostname_and_label, expand=False, fill=False, padding=5)
359 bottom_hbox.pack_start(dnsdomainname_and_label, expand=False, fill=False, padding=5)
360
361 # pack the topmost frame
362 vert.pack_start(top_window_hbox, expand=False, fill=False, padding=0)
363 vert.pack_start(frame, expand=True, fill=True, padding=10)
364 #vert.pack_start(bottom_hbox, expand=True, fill=True, padding=5)
365
366 notebook = gtk.Notebook()
367 #notebook.set_show_tabs(False)
368 #self.add_content(vert)
369 notebook.set_show_border(False)
370 notebook.append_page(vert, gtk.Label("Device Information"))
371 notebook.append_page(bottom_hbox, gtk.Label("Hostname / Proxy Information / Other"))
372 self.add_content(notebook)
373
374 # connect to widget events
375 treeview.connect("cursor-changed", self.selection_changed)
376 wireless_checkbox.connect("toggled", self.wireless_clicked)
377 ethernet_type_select_combo.connect("changed", self.ethernet_type_changed)
378 ethernet_select_combo.connect("changed", self.ethernet_device_selected)
379 ethernet_select_combo.child.connect("activate", self.ethernet_device_added)
380 static_and_dhcp_notebook.connect("switch-page", self.switch)
381 save_button.connect("clicked", self.save_clicked)
382 delete_button.connect("clicked", self.delete_clicked)
383
384 # add all the boxes that we access later to a dictionary
385 self.widgets = {"essid":essid_entry, "key":key_entry,
386 "ipaddress":staticip_entry, "broadcast":broadcastip_entry, "netmask":netmaskip_entry,
387 "ethernet_type":ethernet_type_select_combo, "wireless_checkbox":wireless_checkbox,
388 "ethernet_device":ethernet_select_combo, "hardware_info":hardware_label,
389 "static_dhcp_notebook":static_and_dhcp_notebook, "dhcp_options":dhcp_options_entry,
390 "treedata":treedata, "treeview":treeview, "gateway":gatewayip_entry,
391 "hostname":hostname_entry, "domainname":dnsdomainname_entry
392 }
393
394 # sets the initial default condition of the frame
395 def set_initial_conditions(self):
396
397 # populate the ethernet devices
398 self.populate_ethernet_device_widget()
399
400 # disable the static entries
401 self.set_static_entries(False)
402
403 # set DHCP to be the default selected
404 self.widgets["ethernet_type"].set_active(self.dhcp)
405
406 # disable the wireless entries
407 self.set_wireless_entries(False)
408
409 # disable the ethernet type dropdown, and wireless checkbox
410 self.set_overall_widgets(False)
411
412 # set variable for the "first run" through
413 self.first_run = True
414
415 def set_wireless_entries(self, value):
416 # always clear the entries
417 self.widgets["essid"].set_text("")
418 self.widgets["key"].set_text("")
419
420 # they checked the box so enable the boxes for input
421 self.widgets["essid"].set_sensitive(value)
422 self.widgets["key"].set_sensitive(value)
423
424 def set_static_entries(self,value):
425 # always clear the entries
426 self.widgets["ipaddress"].set_text("")
427 self.widgets["broadcast"].set_text("")
428 self.widgets["netmask"].set_text("")
429
430 self.widgets["ipaddress"].set_sensitive(value)
431 self.widgets["broadcast"].set_sensitive(value)
432 self.widgets["netmask"].set_sensitive(value)
433
434 def set_overall_widgets(self, value):
435 self.widgets["ethernet_type"].set_sensitive(value)
436 self.widgets["wireless_checkbox"].set_sensitive(value)
437
438 def populate_ethernet_device_widget(self):
439 device_list = self.get_ethernet_devices()
440 for device in device_list:
441 self.widgets["ethernet_device"].append_text(device)
442
443 # below here are the events connected to widgets
444 def wireless_clicked(self, widget):
445
446 if widget.get_active():
447 self.set_wireless_entries(True)
448 else:
449 self.set_wireless_entries(False)
450
451 def ethernet_type_changed(self, widget):
452 selected_text = self.get_active_text(widget)
453 if selected_text == "DHCP":
454 # disable 3 input boxes and set ip address to dhcp
455 self.set_static_entries(False)
456 self.widgets["dhcp_options"].set_text("")
457 self.widgets["ipaddress"].set_text("dhcp")
458
459 # flip the gtk.Notebook to allow input of dhcp options
460 self.widgets["static_dhcp_notebook"].set_current_page(1)
461
462 elif selected_text == "Static":
463 self.set_static_entries(True)
464 self.widgets["static_dhcp_notebook"].set_current_page(0)
465
466 def ethernet_device_selected(self, widget):
467 # enable the selection of wireless and static configurations
468 self.set_overall_widgets(True)
469
470 # clear the boxes so things aren't dragged over
471 #self.set_static_entries(True)
472 self.widgets["dhcp_options"].set_text("")
473
474 # get the hardware information about the device and set it
475 info = self.get_ethernet_device_info(widget.get_child().get_text())
476 self.widgets["hardware_info"].set_text(info)
477
478 # if the gateway is not set, or if its the ethernet device it should be set for, enable it.
479 if self.gateway_is_set == False or self.gateway[0] == self.widgets["ethernet_device"].get_child().get_text():
480 self.widgets["gateway"].set_sensitive(True)
481 self.widgets["gateway"].set_text(self.gateway[1])
482 else:
483 self.widgets["gateway"].set_text("")
484 self.widgets["gateway"].set_sensitive(False)
485
486 # figure out if its in the list, and if so, flip to the right page
487 # and display ( get ) the info.
488 device = self.widgets["ethernet_device"].get_child().get_text()
489 row_number = self.device_in_treeview(device)
490 if self.device_in_treeview(device) != None:
491 # select it
492 sel = self.widgets["treeview"].get_selection()
493 sel.select_path(row_number)
494 # force the click event so it selects the correct
495 # things.
496 self.selection_changed(self.widgets["treeview"])
497
498 def ethernet_device_added(self, widget):
499 self.widgets["ethernet_device"].append_text(widget.get_text())
500
501 def save_clicked(self, widget, data=None):
502 # retrieve the data
503 data = self.get_information()
504
505 # only proceed if the ethernet device isn't blank
506 if data["ethernet_device"] != "":
507
508 # save the gateway if its not set
509 # the user must unset the gateway to change it to a different device.
510 if self.widgets["gateway"].get_text() != "":
511 self.gateway[0] = self.widgets["ethernet_device"].get_child().get_text()
512 self.gateway[1] = self.widgets["gateway"].get_text()
513 self.gateway_is_set = True
514
515 # this will occur when the gateway is unset!
516 if self.widgets["gateway"].get_text() == "" and self.gateway_is_set == True and \
517 self.widgets["ethernet_device"].get_child().get_text() == self.gateway[0]:
518 self.gateway[0] = ""
519 self.gateway[1] = ""
520 self.gateway_is_set = False
521
522 if self.gateway_is_set == True and self.widgets["ethernet_device"].get_child().get_text() == self.gateway[0]:
523 gateway = self.gateway[1]
524 else:
525 gateway = ""
526
527 # store it in the top box.
528 self.add_to_treedata([0, data["ethernet_device"], data["ipaddress"], data["broadcast"],
529 data["netmask"], data["dhcp_options"],gateway])
530
531 else:
532 msgdialog = Widgets().error_Box("No Ethernet Device","Please enter a device!")
533 result = msgdialog.run()
534 msgdialog.destroy()
535
536 def delete_clicked(self, widget, data=None):
537 # gets which one is currently selected
538 treeselection = self.widgets["treeview"].get_selection()
539 treemodel, treeiter = treeselection.get_selected()
540 #selected_row = gtk.TreeRowReference(treemodel, treemodel.get_path(treeiter))
541 #print str(treemodel.get_value(treeiter, 1))
542 device = treemodel.get_value(treeiter, 1) # this is the number that identifies the row
543 #if treeiter != None:
544 # self.widgets["treedata"].remove(treeiter)
545
546 # iterate over the liststore to find the row, and then delete it
547 store = self.widgets["treedata"]
548 model = self.widgets["treeview"].get_model()
549 #iter = model.get_iter_root()
550 iter = store.get_iter_first()
551
552 while(iter != None):
553 dev = store.get_value(iter, 1)
554 print dev + " " + device
555 #print model.get_path(iter)
556 #temp_row_ref = gtk.TreeRowReference(model, model.get_path(iter))
557 #if selected_row.get_path() == temp_row_ref.get_path():
558 #store.remove(iter)
559 #break
560
561 if dev == device:
562 store.remove(iter)
563 break
564 # necessary b/c w/o it, iter error
565 else:
566 iter = store.iter_next(iter)
567
568 def switch(self, widget, page, page_num, data=None):
569 # debug only
570 pass
571 #print "page num: "+str(page_num)
572 #print self.widgets["static_dhcp_notebook"].get_current_page()
573 #print "current page: "+str(widget.get_current_page())
574
575 def selection_changed(self, widget, data=None):
576 # gets which one is currently selected
577 treeselection = self.widgets["treeview"].get_selection()
578 treemodel, treeiter = treeselection.get_selected()
579 row = treemodel.get_value(treeiter, 1) # this is the device that identifies the row
580
581 # iterate over the liststore to find the row
582 store = self.widgets["treedata"]
583 iter = store.get_iter_first()
584
585 while(iter != None):
586 dev = store.get_value(iter, 1)
587 if dev == row:
588 number, device, ip, broadcast, netmask, options = store.get(iter, 0, 1, 2, 3, 4, 5)
589 break
590 # necessary b/c w/o it, iter error
591 else:
592 iter = store.iter_next(iter)
593
594 # is it dhcp or static? ( to set the type selected )
595 if ip == "dhcp":
596 self.widgets["ethernet_type"].set_active(self.dhcp)
597 else:
598 # its static
599 self.widgets["ethernet_type"].set_active(self.static)
600
601 # load them all, because they will just be blank if not set.
602 self.widgets["ethernet_device"].get_child().set_text(device)
603 self.widgets["ipaddress"].set_text(ip)
604 self.widgets["broadcast"].set_text(broadcast)
605 self.widgets["netmask"].set_text(netmask)
606 self.widgets["dhcp_options"].set_text(options)
607
608 # only set if it is the gateway
609 if device == self.gateway[0]:
610 self.widgets["gateway"].set_text(self.gateway[1])
611
612
613
614
615 # helper functions
616 def get_active_text(self,combobox):
617 model = combobox.get_model()
618 active = combobox.get_active()
619 if active < 0:
620 return None
621 return model[active][0]
622
623 def get_ethernet_devices(self):
624 put, get = os.popen4("ifconfig -a | egrep -e '^[^ ]'|sed -e 's/ .\+$//'")
625 devices=[]
626 for device in get.readlines():
627 device=device.strip()
628 if device!="lo":
629 devices.append(device)
630 return devices
631
632 def get_ethernet_device_info(self, device):
633 # grab the first line from dmesg for the detected device..
634 # this may change later.
635 try:
636 put, get = os.popen4("dmesg | grep " + device + " | head -n 1")
637
638 info = get.readlines()
639 if len(info) != 1:
640 if len(info) != 0:
641 info = "An error occurred retrieving hardware information"
642 else:
643 info = "No information was found in dmesg about your device."
644 else:
645 info = info[0]
646
647 except:
648 print "Error"
649 return info
650
651 def get_information(self):
652 # retrieve all the information from the input boxes.
653 #self.widgets = {"essid":essid_entry, "key":key_entry,
654 #"ipaddress":staticip_entry, "broadcast":broadcastip_entry, "netmask":netmaskip_entry,
655 #"ethernet_type":ethernet_type_select_combo, "wireless_checkbox":wireless_checkbox,
656 #"ethernet_device":ethernet_select_combo, "hardware_info":hardware_label,
657 #"static_dhcp_notebook":static_and_dhcp_notebook
658 #}
659 data ={}
660 data["ipaddress"]=self.widgets["ipaddress"].get_text()
661 data["broadcast"] = self.widgets["broadcast"].get_text()
662 data["netmask"] = self.widgets["netmask"].get_text()
663 data["eth_type"] = self.get_active_text(self.widgets["ethernet_type"])
664 data["ethernet_device"] = self.widgets["ethernet_device"].get_child().get_text()
665 data["dhcp_options"] = self.widgets["dhcp_options"].get_text()
666
667 # add in wireless support when supported in the backend
668
669 return data
670
671 def add_to_treedata(self, data ):
672 # need to figure out if this already exists in the treeview,
673 # and if not, add it as a new entry. If it does already exist,
674 # modify the entry. need to modify data[0]
675
676 store = self.widgets["treedata"]
677 iter = store.get_iter_first()
678 new_item = True
679 #count = 0
680 # if the value of ethernet_device = value in any of
681 # the treeviews ethernet column, we need to edit that column.
682 # if not, its a new entry.
683 while ( iter != None ):
684 values = store.get(iter, 0, 1, 2, 3, 4, 5, 6)
685
686 if values[1] == data[1]:
687 # modify this entry!
688 store.set(iter, 0, 0, 1, data[1], 2, data[2],
689 3, data[3], 4, data[4], 5, data[5], 6, data[6])
690
691 # and set to False
692 new_item = False
693
694 #count+=1
695 iter = store.iter_next(iter)
696
697 if new_item == True:
698 # this is a new entry
699 #data[0] = count+1
700 store.append(data)
701
702 def device_in_treeview(self, device):
703 return_val = None
704
705 store = self.widgets["treedata"]
706 iter = store.get_iter_first()
707
708 row_num=0
709 while(iter != None):
710 dev = store.get_value(iter, 1)
711 if dev == device:
712 return_val = row_num
713 break
714 # necessary b/c w/o it, iter error
715 else:
716 iter = store.iter_next(iter)
717 row_num=row_num+1
718 return return_val
719
720 ###
721 def activate(self):
722 if self.first_run == False:
723 self.set_initial_conditions()
724
725 # load everything
726 interfaces = self.controller.install_profile.get_network_interfaces()
727
728 # Preload networking info from CC...stolen from gli-dialog
729 CC_iface = self.controller.client_profile.get_network_interface()
730 if CC_iface and (CC_iface not in interfaces):
731 #The CC has a network config that's not already there. Preload it.
732 CC_net_type = self.controller.client_profile.get_network_type()
733 if CC_net_type == 'dhcp':
734 interfaces[CC_iface] = ('dhcp', self.controller.client_profile.get_network_dhcp_options(), None)
735 elif CC_net_type == 'static':
736 interfaces[CC_iface] = (self.controller.client_profile.get_network_ip(), self.controller.client_profile.get_network_broadcast(), self.controller.client_profile.get_network_netmask())
737
738 try:
739 dev, gatewayip = self.controller.install_profile.get_default_gateway()
740 except:
741 dev = None
742
743 for interface in interfaces.keys():
744 if interfaces[interface][0] == "dhcp":
745 if interfaces[interface][1] == None:
746 options = ""
747 else:
748 options = interfaces[interface][1]
749
750 self.add_to_treedata( [0, interface, interfaces[interface][0], "",
751 "", options, ""] )
752 else:
753 gateway = ""
754 # if this is the device that is the gateway
755 if dev == interface:
756 gateway = gatewayip
757 self.gateway = [dev, gatewayip]
758 self.gateway_is_set = True
759
760 self.add_to_treedata( [0, interface, interfaces[interface][0], interfaces[interface][1],
761 interfaces[interface][2], "", gateway] )
762
763 self.widgets["hostname"].set_text(self.controller.install_profile.get_hostname())
764 self.widgets["domainname"].set_text(self.controller.install_profile.get_domainname())
765
766 self.controller.SHOW_BUTTON_EXIT = True
767 # self.controller.SHOW_BUTTON_HELP = True
768 self.controller.SHOW_BUTTON_BACK = True
769 self.controller.SHOW_BUTTON_FORWARD = True
770 self.controller.SHOW_BUTTON_FINISH = False
771
772 def deactivate(self):
773 return_value = False
774
775 # save everything to profile
776 interfaces={}
777 # iterate over the liststore
778 store = self.widgets["treedata"]
779 iter = store.get_iter_first()
780
781 while(iter != None):
782 number, device, ip, broadcast, netmask, options, gateway = store.get(iter, 0, 1, 2, 3, 4, 5, 6)
783
784 if ip != "dhcp":
785 interfaces[device] = (ip, broadcast, netmask)
786 else:
787 print options
788 interfaces[device]=(ip, options, None)
789
790 if gateway != "":
791 # store the gateway
792 try:
793 self.controller.install_profile.set_default_gateway(None,self.gateway[1], \
794 {'interface':self.gateway[0]})
795 except:
796 msgdialog=Widgets().error_Box("Malformed IP","Malformed IP address in your gateway!")
797 result = msgdialog.run()
798 msgdialog.destroy()
799 return False
800
801 iter = store.iter_next(iter)
802
803 # If there are no interfaces configured, confirm this is what the user actually wants
804 if not interfaces:
805 msgdlg = gtk.MessageDialog(parent=self.controller.window, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format="You have not configured any interfaces. Continue?")
806 resp = msgdlg.run()
807 msgdlg.destroy()
808 if resp == gtk.RESPONSE_NO:
809 return False
810
811 # store the stuff
812 try:
813 self.controller.install_profile.set_network_interfaces(interfaces)
814 except:
815 msgdialog=Widgets().error_Box("Malformed IP","Malformed IP address in one of your interfaces!")
816 result = msgdialog.run()
817 msgdialog.destroy()
818 return False
819
820 # store dnsdomainname and hostname
821 hostname = self.widgets["hostname"].get_text()
822 domainname = self.widgets["domainname"].get_text()
823 if( hostname != "" and domainname != ""):
824 self.controller.install_profile.set_hostname(None, hostname, None)
825 self.controller.install_profile.set_domainname(None, domainname, None)
826 return_value = True
827 elif( self.first_run == True):
828 msgdialog=Widgets().error_Box("Missing information","You didn't set your hostname and/or dnsdomainname!")
829 result = msgdialog.run()
830 msgdialog.destroy()
831 return_value = False
832 else:
833 return_value = True
834
835 return return_value

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20