~happyaron/ubiquity/lp-1465530

« back to all changes in this revision

Viewing changes to ubiquity/components/myth-remote.py

  • Committer: Mario Limonciello
  • Date: 2010-02-22 02:34:45 UTC
  • Revision ID: superm1@ubuntu.com-20100222023445-bpgiucj9kh2p0419
Remove all of the mythbuntu frontend from ubiquity.  Now that it's fully
stable, it's being moved to the mythbuntu-live-autostart package so that
it can benefit from being maintained by anyone in ~mythbuntu-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8; Mode: Python; indent-tabs-mode: nil; tab-width: 4 -*-
2
 
#
3
 
# Copyright (C) 2006, 2007, 2009 Canonical Ltd.
4
 
# Written by Colin Watson <cjwatson@ubuntu.com>.
5
 
# Copyright (C) 2007-2010 Mario Limonciello
6
 
#
7
 
# This file is part of Ubiquity.
8
 
#
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.
13
 
#
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.
18
 
#
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/>.
21
 
 
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
27
 
import os
28
 
import debconf
29
 
 
30
 
 
31
 
NAME = 'myth-remote'
32
 
AFTER = 'myth-services'
33
 
WEIGHT = 10
34
 
 
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)
39
 
        self.populate_lirc()
40
 
        self.remote_control_support.hide()
41
 
 
42
 
    def populate_lirc(self):
43
 
        """Fills the lirc pages with the appropriate data"""
44
 
        self.remote_count = 0
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)
57
 
 
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)
67
 
                else:
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)
75
 
                else:
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)
87
 
 
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)
93
 
                found=False
94
 
                if self.remote_list.get_active_text() == answer:
95
 
                    found = True
96
 
                    break
97
 
                if not found:
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)
102
 
                found=False
103
 
                if self.transmitter_list.get_active_text() == answer:
104
 
                    found = True
105
 
                    break
106
 
                if not found:
107
 
                    self.transmitter_list.set_active(0)
108
 
 
109
 
    def get_lirc(self,type):
110
 
        item = {"modules":"","device":"","driver":"","lircd_conf":""}
111
 
        if type == "remote":
112
 
            item["remote"]=self.remote_list.get_active_text()
113
 
        elif type == "transmitter":
114
 
            item["transmitter"]=self.transmitter_list.get_active_text()
115
 
        return item
116
 
 
117
 
class Page(Plugin):
118
 
    def prepare(self):
119
 
        self.top = ['remote', 'transmitter']
120
 
        questions = []
121
 
        for question in self.top:
122
 
            answer = self.db.get('lirc/' + question)
123
 
            if answer != '':
124
 
                self.ui.set_lirc(question,answer)
125
 
            questions.append('^lirc/' + question)
126
 
        return (['/usr/share/ubiquity/ask-mythbuntu','ir'], questions)
127
 
 
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)
133
 
 
134
 
class Install(InstallPlugin):
135
 
    def install(self, target, progress, *args, **kwargs):
136
 
        progress.info('ubiquity/install/ir')
137
 
 
138
 
        lirchandler = LircHandler()
139
 
 
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')
145
 
        try:
146
 
            os.symlink('/bin/true', '/target/sbin/udevd')
147
 
        except OSError:
148
 
            pass
149
 
 
150
 
        try:
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:
159
 
            pass
160
 
 
161
 
        try:
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:
170
 
            pass
171
 
 
172
 
        lirchandler.write_hardware_conf(target + '/etc/lirc/hardware.conf')
173
 
 
174
 
        try:
175
 
            install_misc.reconfigure(target, 'lirc')
176
 
        finally:
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)
181
 
 
182
 
        #configure lircrc
183
 
        home = '/target/home/' + progress.get('passwd/username')
184
 
        os.putenv('HOME',home)
185
 
        if not os.path.isdir(home):
186
 
            os.makedirs(home)
187
 
        lirchandler.create_lircrc(os.path.join(target,"etc/lirc/lircd.conf"),False)
188
 
 
189
 
        return InstallPlugin.install(self, target, progress, *args, **kwargs)