~ubuntu-branches/ubuntu/trusty/aptoncd/trusty

« back to all changes in this revision

Viewing changes to APTonCD/restore/restoreFromDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-19 21:41:06 UTC
  • mfrom: (3 sid) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20090819214106-7g72fpzgvl722w6k
* New maintainer (Closes: #542459, #484637, #542501)
* New upstream release
  - Fix the executable flag on non executable files. This fix last lintian
    warnings
* debian/rules: prepared for python2.6 (include of python.mk and use of 
  $(py_setup_install_args) )

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#####################################################################
 
3
#  Rafael Proença <cypherbios@ubuntu.com>
 
4
#  Laudeci Oliveira <laudeci@gmail.com> 
 
5
#
 
6
#  Copyright 2006 APTonCD DevTeam.
 
7
#
 
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.
 
11
#
 
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
#####################################################################
 
17
import gtk
 
18
import re
 
19
import os
 
20
import datetime
 
21
import gobject
 
22
 
 
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 *
 
29
 
 
30
WINDOW_NAME = 'dlgRestoreFrom'
 
31
 
 
32
class RestoreFrom(controller.IController):
 
33
        """
 
34
                This class will handle cd properties for APTonCD media creation.
 
35
        """
 
36
        def __init__(self, controller = None, drive_list = []):
 
37
                """
 
38
                        Constructor
 
39
                """
 
40
                self.controller = controller
 
41
                self.drivers = drive_list
 
42
                self.glade = gui.get_glade(constants.RESTORE_GUI, WINDOW_NAME)
 
43
        
 
44
                #Main widget
 
45
                self.window = gui.get_widget(self.glade, WINDOW_NAME)
 
46
                self.window.set_icon_name(constants.APP_ICON_NAME)
 
47
                
 
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')
 
52
                
 
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)
 
61
                
 
62
                
 
63
                if self.controller:
 
64
                        self.window.set_transient_for(self.controller.get_main_window())
 
65
                        self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
 
66
                                # connect signals
 
67
                self.load_media()
 
68
                
 
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)
 
74
                else:   
 
75
                        self.filechooserIsoImage.set_sensitive(False)
 
76
                        self.cmbLocation.set_active_iter(self.cmbLocation.get_model().get_iter_first())
 
77
        
 
78
                self.window.set_modal(True)
 
79
 
 
80
        def run(self):
 
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]
 
86
                        else:
 
87
                                if len(self.filechooserIsoImage.get_filenames()) > 0:
 
88
                                        return True, constants.RESTORE_TYPE.RESTORE_FROM_ISO, self.filechooserIsoImage.get_filenames()[0]
 
89
                                else:
 
90
                                        return True, constants.RESTORE_TYPE.RESTORE_FROM_NONE, None
 
91
                else:
 
92
                        return False, constants.RESTORE_TYPE.RESTORE_FROM_NONE, None
 
93
 
 
94
        def destroy(self):
 
95
                self.window.destroy()
 
96
 
 
97
        def get_main_window(self):
 
98
                """
 
99
                        implements IController interface method.
 
100
                        for access the class windows object.
 
101
                """
 
102
                if self.controller:
 
103
                        return self.controller.get_main_window()
 
104
                else:
 
105
                        return self.window
 
106
 
 
107
        def get_parent_widget(self):
 
108
                """
 
109
                        implements IController interface method.
 
110
                        for container widget
 
111
                """
 
112
                if self.controller:
 
113
                        self.controller.get_parent_widget()
 
114
                else:
 
115
                        return self.window.get_children()[0]
 
116
 
 
117
        def connect_signals(self):
 
118
                """
 
119
                        This procedure will connect widgets to its signal handler.
 
120
                """
 
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)
 
124
                
 
125
        def on_option_toggle(self, widget):
 
126
                if widget == self.optMedia:
 
127
                        self.cmbLocation.set_sensitive(True)
 
128
                        self.filechooserIsoImage.set_sensitive(False)
 
129
                else:
 
130
                        self.cmbLocation.set_sensitive(False)
 
131
                        self.filechooserIsoImage.set_sensitive(True)
 
132
                        
 
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)
 
139
                
 
140
                for n in self.drivers:
 
141
                        model.append(n)