aboutsummaryrefslogtreecommitdiff
blob: 00583b0e23c7570cf8a5193be4221f82d8e255bc (plain)
1
2
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
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
# Copyright 1999-2006 Gentoo Foundation
# This source code is distributed under the terms of version 2 of the GNU
# General Public License as published by the Free Software Foundation, a copy
# of which can be found in the main directory of this project.

import gtk
import os
from GLIScreen import *
import GLIUtility
from Widgets import Widgets

class Panel(GLIScreen):
	"""
	Other settings for an install.
	
	@author:    John N. Laliberte <allanonjl@gentoo.org>
	@license:   GPL
	"""
	# Attributes:
	#title="Other Settings"
	_helptext = """
<b><u>Other Settings</u></b>

Display Manager:
If you installed gnome, choose gdm. If you installed kde, choose kdm. If you \
installed anything else specified in XSession, choose xdm.

Console Font:
You probably don't want to mess with this.

Extended Keymaps:
You probably don't want to mess with this.

Windowkeys:
If installing on x86 you are safe with Yes, otherwise you'll probably want to \
say No.

Keymap:
This defaults to "us" if not set (recommended).  If you don't want an English \
keymap, choose it from the list.

XSession:
Choose this only if you didn't choose gdm or kdm from the Display Manager list.

Clock:
If you chose a local timezone, you'll want to choose "local" for the clock \
setting. Otherwise if you chose UTC in the Timezone screen, choose UTC here.

Default Editor:
Pick one.  Nano is the default and recommended.
"""
	
	# Operations
	def __init__(self, controller):
		GLIScreen.__init__(self, controller)

		vert    = gtk.VBox(False, 10) # This box is content so it should fill space to force title to top
		horiz   = gtk.HBox(False, 0)
		horiz2   = gtk.HBox(False, 0)
		horiz3   = gtk.HBox(False, 0)

		addme_to_vert = []
		
		# this code could be reduced, but would it make things any clearer?
		
		# create the CLOCK object
		self.clock = self.Option("Clock")
		self.clock.HelpText = "Should CLOCK be set to UTC or local? Unless you set your timezone to UTC you will want to choose local."
		self.clock.Options = ["UTC","local"]
		self.clock.Type = self.Option.OptionType.COMBO
		clock_gtk = self.clock.Generate_GTK()
		addme_to_vert.append(clock_gtk)
		
		# create the Windowkeys object
		self.windowkeys = self.Option("Windowkeys")
		self.windowkeys.HelpText = "Should we first load the 'windowkeys' console keymap?"
		self.windowkeys.Options = ["Yes","No"]
		self.windowkeys.Type = self.Option.OptionType.COMBO
		clock_gtk = self.windowkeys.Generate_GTK()
		addme_to_vert.append(clock_gtk)
		
		# create the Display Manager object
		self.displaymanager = self.Option("Display Manager")
		self.displaymanager.HelpText = "Choose your display manager for Xorg-x11 (note you must make sure that package also gets installed for it to work)"
		self.displaymanager.Options = ["xdm","kdm","gdm"]
		self.displaymanager.Type = self.Option.OptionType.COMBO_ENTRY
		clock_gtk = self.displaymanager.Generate_GTK()
		addme_to_vert.append(clock_gtk)
		
		# create the Default Editor object
		self.editor = self.Option("Default Editor")
		self.editor.HelpText = "Choose your default editor"
		self.editor.Options = ["/bin/nano","/usr/bin/vim","/usr/bin/emacs"]
		self.editor.Type = self.Option.OptionType.COMBO
		editor_gtk = self.editor.Generate_GTK()
		addme_to_vert.append(editor_gtk)

		# create the Keymap object
		self.keymap = self.Option("Keymap")
		self.keymap.HelpText = "Choose your desired keymap"
		self.keymap.Options = [""] + GLIUtility.generate_keymap_list()
		self.keymap.Type = self.Option.OptionType.COMBO
		editor_gtk = self.keymap.Generate_GTK()
		addme_to_vert.append(editor_gtk)

		# create the Console Font object
		self.font = self.Option("Console Font")
		self.font.HelpText = "Choose your default console font"
		self.font.Options = [""] + GLIUtility.generate_consolefont_list()
		self.font.Type = self.Option.OptionType.COMBO
		editor_gtk = self.font.Generate_GTK()
		addme_to_vert.append(editor_gtk)
		
		# create a last bogus one to make it look pretty.
		bogus = self.Option("")
		bogus.HelpText = ""
		bogus.Type = self.Option.OptionType.NONE
		bogus = bogus.Generate_GTK()
		addme_to_vert.append(bogus)
		
		# create the XSession object
		self.xsession = self.Option("XSession")
		self.xsession.HelpText = "Choose what window manager you want to start default with X if run with xdm, startx, or xinit. (common options are Gnome or Xsession)"
		self.xsession.Options = ["Gnome","Xsession","fluxbox"]
		self.xsession.Type = self.Option.OptionType.COMBO_ENTRY
		editor_gtk = self.xsession.Generate_GTK()
		addme_to_vert.append(editor_gtk)
		
		# create the Extended Keymaps object
		self.extkeymap = self.Option("Extended Keymaps")
		self.extkeymap.HelpText = "This sets the maps to load for extended keyboards. Most users will leave this as is."
		self.extkeymap.Type = self.Option.OptionType.TEXT
		editor_gtk = self.extkeymap.Generate_GTK()
		addme_to_vert.append(editor_gtk)
		
		addme_to_vert.reverse()
		for i,item in enumerate(addme_to_vert):
			if i< 3:
				horiz.pack_start(item, expand=True, fill=True, padding=10)
			elif i<6:
				horiz2.pack_start(item, expand=True, fill=True, padding=10)
			else:
				horiz3.pack_start(item, expand=True, fill=True, padding=10)
		
		self.add_content(horiz)
		self.add_content(horiz2)
		self.add_content(horiz3)
	
	def create_etc_files(self, etc_files):
		tmp_etc_files = ("conf.d/keymaps", "conf.d/clock", "rc.conf", "conf.d/xdm")
		for tmp_etc_file in tmp_etc_files:
			if not tmp_etc_file in etc_files: 
				etc_files[tmp_etc_file] = {}
			
		return etc_files
			
	def activate(self):
		
		etc_files = self.controller.install_profile.get_etc_files()
		etc_files = self.create_etc_files(etc_files)
		
		if 'conf.d/keymaps' in etc_files:
			if 'KEYMAP' in etc_files['conf.d/keymaps']:
				self.keymap.SetValue(etc_files['conf.d/keymaps']['KEYMAP'])
			if 'SET_WINDOWKEYS' in etc_files['conf.d/keymaps']:
				self.windowkeys.SetValue(etc_files['conf.d/keymaps']['SET_WINDOWKEYS'])
			if 'EXTENDED_KEYMAPS' in etc_files['conf.d/keymaps']:
				self.extkeymap.SetValue(etc_files['conf.d/keymaps']['EXTENDED_KEYMAPS'])
				
		if 'conf.d/consolefont' in etc_files:
			if 'CONSOLEFONT' in etc_files['conf.d/consolefont']:
				self.font.SetValue(etc_files['conf.d/consolefont']['CONSOLEFONT'])
			
		if 'conf.d/clock' in etc_files:
			if 'CLOCK' in etc_files['conf.d/clock']:
				self.clock.SetValue(etc_files['conf.d/clock']['CLOCK'])
				
		if 'rc.conf' in etc_files:
			if 'EDITOR' in etc_files['rc.conf']:
				self.editor.SetValue(etc_files['rc.conf']['EDITOR'])
			if 'DISPLAYMANAGER' in etc_files['rc.conf']:
				self.displaymanager.SetValue(etc_files['rc.conf']['DISPLAYMANAGER'])
			if 'XSESSION' in etc_files['rc.conf']:
				self.xsession.SetValue(etc_files['rc.conf']['XSESSION'])
	
		
		self.controller.SHOW_BUTTON_BACK    = True
		self.controller.SHOW_BUTTON_FORWARD = True
		
	def next(self):
		etc_files = self.controller.install_profile.get_etc_files()
		etc_files = self.create_etc_files(etc_files)

		if self.keymap.GetValue():
			etc_files['conf.d/keymaps']['KEYMAP'] = self.keymap.GetValue()
		etc_files['conf.d/keymaps']['SET_WINDOWKEYS'] = self.windowkeys.GetValue()
		if self.extkeymap.GetValue() != "":
			etc_files['conf.d/keymaps']['EXTENDED_KEYMAPS'] = self.extkeymap.GetValue()
		if self.font.GetValue():
			if not "conf.d/consolefont" in etc_files: 
				etc_files['conf.d/consolefont'] = {}
			etc_files['conf.d/consolefont']['CONSOLEFONT'] = self.font.GetValue()
		etc_files['conf.d/clock']['CLOCK'] = self.clock.GetValue()
		etc_files['rc.conf']['EDITOR'] = self.editor.GetValue()
		if self.displaymanager.GetValue() != "":
			etc_files['conf.d/xdm']['DISPLAYMANAGER'] = self.displaymanager.GetValue()
		if self.xsession.GetValue() != "":
			etc_files['rc.conf']['XSESSION'] = self.xsession.GetValue()
			
		try:
			self.controller.install_profile.set_etc_files(etc_files)
		except:
			msgbox=Widgets().error_Box("Error","An internal error occurred!")
			msgbox.run()
			msgbox.destroy()
			
		progress = ProgressDialog(self.controller, ("update_config_files", 'finishing_cleanup' ), self.progress_callback)
		progress.run()

	def progress_callback(self, result, data=None):
		if result == PROGRESS_DONE:
			self.controller.load_screen("InstallDone")
		else:
			GLIScreen.progress_callback(self, result, data)



	class Option:

		class Property(object):
			class __metaclass__(type):
				def __init__(cls, name, bases, dct):
					for fname in ['get', 'set', 'delete']:
						if fname in dct:
							setattr(cls, fname, staticmethod(dct[fname]))
				def __get__(cls, obj, objtype=None):
					if obj is None:
						return cls
					fget = getattr(cls, 'get')
					return fget(obj)
				def __set__(cls, obj, value):
					fset = getattr(cls, 'set')
					fset(obj, value)
				def __delete__(cls, obj):
					fdel = getattr(cls, 'delete')
					fdel(obj)
					
		class OptionType:
			NONE = 0
			TEXT = 1
			COMBO = 2
			COMBO_ENTRY = 3
			
		def __init__(self, name):
			self.Name = name
			self.HelpText = ""
			# by default we make a combo
			self.Type = self.OptionType.COMBO
			self.Options = []
		
		class Name(Property):
			""" Name property """
			def get(self):
				return self._name
			def set(self):
				self._name = val
		
		class HelpText(Property):
			""" HelpText property """
			def get(self):
				return self._helptext
			def set(self):
				self._helptext = val
		
		class Type(Property):
			""" Name property """
			def get(self):
				return self._type
			def set(self):
				self._type = val
		
		class Options(Property):
			""" Options property """
			def get(self):
				return self._options
			def set(self):
				self._name = self._options

		class GtkElement(Property):
			""" GtkElement Property """
			def get(self):
				return self._gtkelement
			def set(self):
				self._gtkelement = val
				
		def GetValue(self):
			if self.Type == self.OptionType.TEXT:
				return self.GtkElement.get_text()
			elif self.Type == self.OptionType.COMBO:
				model = self.GtkElement.get_model()
				active = self.GtkElement.get_active()
				return model[active][0]
			elif self.Type == self.OptionType.COMBO_ENTRY:
				return self.GtkElement.get_child().get_text()
		
		def SetValue(self, text):
			if self.Type == self.OptionType.TEXT:
				self.GtkElement.set_text(text)
			elif self.Type == self.OptionType.COMBO:
				# iterate through all the elements,
				# get the number and set it.
				model = self.GtkElement.get_model()

				for i,item in enumerate(model):
					if item[0] == text:
						self.GtkElement.set_active(i)
			elif self.Type == self.OptionType.COMBO_ENTRY:
				self.GtkElement.get_child().set_text(text)
			
		def Generate_GTK(self):
			
			box = gtk.VBox(False, 0)
			
			# the name of the setting
			hbox = gtk.HBox(False,0)
			label = gtk.Label("")
			label.set_markup('<span weight="bold">'+self.Name+'</span>')

			label.set_size_request(150, -1)
			hbox.pack_start(label, expand=False, fill=False, padding=0)
			box.pack_start(hbox, expand=False, fill=False, padding=5)
			
			# the description of the option
			hbox = gtk.HBox(False,0)
			label = gtk.Label(self.HelpText)
			label.set_size_request(200, -1)
			label.set_line_wrap(True)
			label.set_justify(gtk.JUSTIFY_FILL)
			hbox.pack_start(label, expand=False, fill=False, padding=0)
			box.pack_start(hbox, expand=False, fill=False, padding=5)
			
			# switch here based on type of gui element.
			if self.Type == self.OptionType.TEXT:
				gui_element = gtk.Entry()
			elif self.Type == self.OptionType.NONE:
				gui_element = gtk.Label("")
				# but we want to HIDE the entry so its not visible
				gui_element.hide()
			elif self.Type == self.OptionType.COMBO:
				gui_element = gtk.combo_box_new_text()
				#gui_element.set_wrap_width(5)
			elif self.Type == self.OptionType.COMBO_ENTRY:
				gui_element = gtk.combo_box_entry_new_text()

			# store it for later :)
			self.GtkElement = gui_element
			
			for option_text in self.Options:
				gui_element.append_text(option_text)
			
			gui_element.set_name(self.Name)
			gui_element.set_size_request(150, -1)
			
			# what we do by default
			if self.Type == self.OptionType.TEXT or self.Type == self.OptionType.NONE:
				#gui_element.set_text(()
				pass
			elif self.Type == self.OptionType.COMBO:
				gui_element.set_active(0)
			
			hbox = gtk.HBox(False,0)
			hbox.pack_start(gui_element, expand=False, fill=False, padding=0)
			box.pack_start(hbox, expand=False, fill=False, padding=5)
			return box