OpenSecurity/bin/opensecurity_tray.pyw
changeset 207 ae931a692b54
parent 199 26b9a95b0da1
child 213 2e0b94e12bfc
     1.1 --- a/OpenSecurity/bin/opensecurity_tray.pyw	Wed Jun 25 19:21:04 2014 +0200
     1.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw	Wed Jun 25 22:26:34 2014 +0200
     1.3 @@ -91,7 +91,14 @@
     1.4          
     1.5          super(OpenSecurityTrayIcon, self).__init__(icon, parent)
     1.6          self.setup_ui()
     1.7 -        
     1.8 +        self.activated.connect(self.activated_)
     1.9 +       
    1.10 +
    1.11 +    def activated_(self, reason):
    1.12 +
    1.13 +        """the system tray icon was activated"""
    1.14 +        self.refresh_format_menu()
    1.15 +
    1.16          
    1.17      def clicked_about(self):
    1.18          """clicked about"""
    1.19 @@ -170,7 +177,54 @@
    1.20          elif sys.platform == 'win32' or sys.platform == 'cygwin':
    1.21              mail_url = 'mailto:' + urllib.quote(address, '@') + '?' + urllib.quote('subject=' + subject)
    1.22              subprocess.Popen(['cmd', '/C', 'start', mail_url])
    1.23 -    
    1.24 +   
    1.25 +
    1.26 +    def format_drive(self):
    1.27 +
    1.28 +        """format drive clicked (the sender should a QAction created with refresh_format_menu)"""
    1.29 +        try:
    1.30 +
    1.31 +            # fiddle the IP of the VM controlling the VM
    1.32 +            s = self.sender()
    1.33 +            ip = str(s.text().split('\\\\')[1])
    1.34 +
    1.35 +            # invoke the format drive dialog
    1.36 +            dlg_format_drive = os.path.join(sys.path[0], 'ui', 'format_drive_dialog.py')
    1.37 +            process_command = [sys.executable, dlg_format_drive, ip]
    1.38 +            process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)        
    1.39 +
    1.40 +            stdout = process.communicate()[0]
    1.41 +
    1.42 +        except:
    1.43 +            pass
    1.44 +
    1.45 +
    1.46 +    def refresh_format_menu(self):
    1.47 +
    1.48 +        """create a new list of format 'drives'"""
    1.49 +        self._menu_format.clear()
    1.50 +        a = self._menu_format.addAction('<No Drive given>')
    1.51 +        a.setEnabled(False)
    1.52 +
    1.53 +        try:
    1.54 +
    1.55 +            # get machines
    1.56 +            machines = json.load(urllib2.urlopen('http://127.0.0.1:8080/sdvms'))
    1.57 +            if len(machines) == 0:
    1.58 +                return
    1.59 +
    1.60 +            self._icon_network = QtGui.QIcon()
    1.61 +            self._icon_network.addPixmap(QtGui.QPixmap(":/opensecurity/gfx/network-workgroup.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    1.62 +
    1.63 +            self._menu_format.clear()
    1.64 +            for m in machines:
    1.65 +                a = self._menu_format.addAction(m + '\\\\' + machines[m])
    1.66 +                a.setIcon(self._icon_network)
    1.67 +                a.triggered.connect(self.format_drive)
    1.68 +
    1.69 +        except:
    1.70 +            pass
    1.71 +
    1.72  
    1.73      def setup_ui(self):
    1.74          """create the user interface
    1.75 @@ -202,6 +256,9 @@
    1.76          menu.addAction(self.acConfigure)
    1.77          menu.addSeparator()
    1.78  
    1.79 +        self._menu_format = menu.addMenu('Format')
    1.80 +        menu.addSeparator()
    1.81 +
    1.82          self.acMail = menu.addAction('Send feedback mail')
    1.83          icon = QtGui.QIcon()
    1.84          icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_mail_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)