1
# -*- coding: utf-8; Mode: Python; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2006, 2007, 2009 Canonical Ltd.
4
# Written by Colin Watson <cjwatson@ubuntu.com>.
5
# Copyright (C) 2007-2010 Mario Limonciello
7
# This file is part of Ubiquity.
9
# Ubiquity is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 2 of the License, or
12
# (at your option) any later version.
14
# Ubiquity is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with Ubiquity. If not, see <http://www.gnu.org/licenses/>.
22
from ubiquity.plugin import *
23
from ubiquity import osextras
24
from mythbuntu_common.installer import *
25
from mythbuntu_common.lirc import LircHandler
26
from ubiquity import install_misc
32
AFTER = 'myth-services'
35
class PageGtk(MythPageGtk):
36
def __init__(self, controller, *args, **kwargs):
37
self.ui_file = 'tab_remote_control'
38
MythPageGtk.__init__(self, controller, *args, **kwargs)
40
self.remote_control_support.hide()
42
def populate_lirc(self):
43
"""Fills the lirc pages with the appropriate data"""
45
self.transmitter_count = 0
46
lirchandler=LircHandler()
47
for item in lirchandler.get_possible_devices("remote"):
48
if "Custom" not in item and "Blaster" not in item:
49
self.remote_list.append_text(item)
50
self.remote_count = self.remote_count + 1
51
for item in lirchandler.get_possible_devices("transmitter"):
52
if "Custom" not in item:
53
self.transmitter_list.append_text(item)
54
self.transmitter_count = self.transmitter_count + 1
55
self.remote_list.set_active(0)
56
self.transmitter_list.set_active(0)
58
def toggle_ir(self,widget):
59
"""Called whenever a request to enable/disable remote is called"""
60
if widget is not None:
61
#turn on/off IR remote
62
if widget.get_name() == 'remotecontrol':
63
self.remote_hbox.set_sensitive(widget.get_active())
64
self.generate_lircrc_checkbox.set_sensitive(widget.get_active())
65
if widget.get_active() and self.remote_list.get_active() == 0:
66
self.remote_list.set_active(1)
68
self.remote_list.set_active(0)
69
#turn on/off IR transmitter
70
elif widget.get_name() == "transmittercontrol":
71
self.transmitter_hbox.set_sensitive(widget.get_active())
72
if widget.get_active():
73
if self.transmitter_list.get_active() == 0:
74
self.transmitter_list.set_active(1)
76
self.transmitter_list.set_active(0)
77
#if our selected remote itself changed
78
elif widget.get_name() == 'remote_list':
79
self.generate_lircrc_checkbox.set_active(True)
80
if self.remote_list.get_active() == 0:
81
self.remotecontrol.set_active(False)
82
self.generate_lircrc_checkbox.set_active(False)
83
#if our selected transmitter itself changed
84
elif widget.get_name() == 'transmitter_list':
85
if self.transmitter_list.get_active() == 0:
86
self.transmittercontrol.set_active(False)
88
def set_lirc(self,question,answer):
89
"""Preseeds a lirc configuration item"""
90
if question == "remote":
91
for i in range(0,self.remote_count):
92
self.remote_list.set_active(i)
94
if self.remote_list.get_active_text() == answer:
98
self.remote_list.set_active(0)
99
if question == "transmitter":
100
for i in range(0,self.transmitter_count):
101
self.transmitter_list.set_active(i)
103
if self.transmitter_list.get_active_text() == answer:
107
self.transmitter_list.set_active(0)
109
def get_lirc(self,type):
110
item = {"modules":"","device":"","driver":"","lircd_conf":""}
112
item["remote"]=self.remote_list.get_active_text()
113
elif type == "transmitter":
114
item["transmitter"]=self.transmitter_list.get_active_text()
119
self.top = ['remote', 'transmitter']
121
for question in self.top:
122
answer = self.db.get('lirc/' + question)
124
self.ui.set_lirc(question,answer)
125
questions.append('^lirc/' + question)
126
return (['/usr/share/ubiquity/ask-mythbuntu','ir'], questions)
128
def ok_handler(self):
129
for question in self.top:
130
device = self.ui.get_lirc(question)
131
self.preseed('lirc/' + question,device[question])
132
Plugin.ok_handler(self)
134
class Install(InstallPlugin):
135
def install(self, target, progress, *args, **kwargs):
136
progress.info('ubiquity/install/ir')
138
lirchandler = LircHandler()
140
#configure lircd for remote and transmitter
141
ir_device = {"modules":"","driver":"","device":"","lircd_conf":"","remote":"","transmitter":""}
142
install_misc.chroot_setup(target)
143
install_misc.chrex(target,'dpkg-divert', '--package', 'ubiquity', '--rename',
144
'--quiet', '--add', '/sbin/udevd')
146
os.symlink('/bin/true', '/target/sbin/udevd')
151
ir_device["remote"] = progress.get('lirc/remote')
152
install_misc.set_debconf(target, 'lirc/remote',ir_device["remote"])
153
ir_device["modules"] = ""
154
ir_device["driver"] = ""
155
ir_device["device"] = ""
156
ir_device["lircd_conf"] = ""
157
lirchandler.set_device(ir_device,"remote")
158
except debconf.DebconfError:
162
ir_device["transmitter"] = progress.get('lirc/transmitter')
163
install_misc.set_debconf(target, 'lirc/transmitter',ir_device["transmitter"])
164
ir_device["modules"] = ""
165
ir_device["driver"] = ""
166
ir_device["device"] = ""
167
ir_device["lircd_conf"] = ""
168
lirchandler.set_device(ir_device,"transmitter")
169
except debconf.DebconfError:
172
lirchandler.write_hardware_conf(target + '/etc/lirc/hardware.conf')
175
install_misc.reconfigure(target, 'lirc')
177
osextras.unlink_force('/target/sbin/udevd')
178
install_misc.chrex(target,'dpkg-divert', '--package', 'ubiquity', '--rename',
179
'--quiet', '--remove', '/sbin/udevd')
180
install_misc.chroot_cleanup(target)
183
home = '/target/home/' + progress.get('passwd/username')
184
os.putenv('HOME',home)
185
if not os.path.isdir(home):
187
lirchandler.create_lircrc(os.path.join(target,"etc/lirc/lircd.conf"),False)
189
return InstallPlugin.install(self, target, progress, *args, **kwargs)