1
# -*- coding: utf-8 -*-
2
#####################################################################
3
# Rafael Proença <cypherbios@ubuntu.com>
4
# Laudeci Oliveira <laudeci@gmail.com>
6
# Copyright 2006 APTonCD DevTeam.
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published
10
# by the Free Software Foundation; version 2 only.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#####################################################################
23
from APTonCD.core import *
24
from APTonCD.core import gui
25
from APTonCD.core import constants
26
import APTonCD.core.utils
27
from APTonCD.core.utils import get_icon
28
from APTonCD.widgets import *
30
WINDOW_NAME = 'dlgRestoreFrom'
32
class RestoreFrom(controller.IController):
34
This class will handle cd properties for APTonCD media creation.
36
def __init__(self, controller = None, drive_list = []):
40
self.controller = controller
41
self.drivers = drive_list
42
self.glade = gui.get_glade(constants.RESTORE_GUI, WINDOW_NAME)
45
self.window = gui.get_widget(self.glade, WINDOW_NAME)
46
self.window.set_icon_name(constants.APP_ICON_NAME)
48
self.cmbLocation = gui.get_widget(self.glade, 'cboMountedDevices')
49
self.optMedia = gui.get_widget(self.glade, 'optMedia')
50
self.optIso = gui.get_widget(self.glade, 'optIso')
51
self.filechooserIsoImage = gui.get_widget(self.glade, 'filechooserIsoImage')
53
#set filter to allow iso file only
54
filter = gtk.FileFilter()
55
#TODO: make a constant string for this file title
56
filter.set_name(constants.MESSAGE_0068)
57
filter.add_mime_type('application/x-cd-image')
58
filter.add_pattern("*.iso")
59
self.filechooserIsoImage.add_filter(filter)
60
self.filechooserIsoImage.set_action(gtk.FILE_CHOOSER_ACTION_OPEN)
64
self.window.set_transient_for(self.controller.get_main_window())
65
self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
69
self.connect_signals()
70
self.optMedia.set_active(True)
71
if len(self.cmbLocation.get_model()) <= 0:
72
self.optMedia.set_sensitive(False)
73
self.optIso.set_active(True)
75
self.filechooserIsoImage.set_sensitive(False)
76
self.cmbLocation.set_active_iter(self.cmbLocation.get_model().get_iter_first())
78
self.window.set_modal(True)
81
result = self.window.run()
82
if result == gtk.RESPONSE_OK:
83
if self.optMedia.get_active():
84
model = self.cmbLocation.get_model()
85
return True, constants.RESTORE_TYPE.RESTORE_FROM_MEDIA, model[self.cmbLocation.get_active_iter()][1]
87
if len(self.filechooserIsoImage.get_filenames()) > 0:
88
return True, constants.RESTORE_TYPE.RESTORE_FROM_ISO, self.filechooserIsoImage.get_filenames()[0]
90
return True, constants.RESTORE_TYPE.RESTORE_FROM_NONE, None
92
return False, constants.RESTORE_TYPE.RESTORE_FROM_NONE, None
97
def get_main_window(self):
99
implements IController interface method.
100
for access the class windows object.
103
return self.controller.get_main_window()
107
def get_parent_widget(self):
109
implements IController interface method.
113
self.controller.get_parent_widget()
115
return self.window.get_children()[0]
117
def connect_signals(self):
119
This procedure will connect widgets to its signal handler.
121
#gui.connect(self.cmbLocation, 'selection_changed', self.on_cmbLocation_change)
122
gui.connect(self.optIso, 'toggled', self.on_option_toggle)
123
gui.connect(self.optMedia, 'toggled', self.on_option_toggle)
125
def on_option_toggle(self, widget):
126
if widget == self.optMedia:
127
self.cmbLocation.set_sensitive(True)
128
self.filechooserIsoImage.set_sensitive(False)
130
self.cmbLocation.set_sensitive(False)
131
self.filechooserIsoImage.set_sensitive(True)
133
def load_media(self):
134
self.cmbLocation.set_model(gtk.ListStore(*[gobject.TYPE_STRING] * 3))
135
model = self.cmbLocation.get_model()
136
cell = gtk.CellRendererText()
137
self.cmbLocation.pack_start(cell, True)
138
self.cmbLocation.add_attribute(cell, 'text', 0)
140
for n in self.drivers: