reworking user interface ongoing
authorOliver Maurhart <oliver.maurhart@ait.ac.at>
Mon, 31 Mar 2014 15:26:56 +0200
changeset 104e30b476d23a0
parent 103 2eeee55363b8
child 105 9cc91074deb8
reworking user interface ongoing
OpenSecurity/bin/opensecurity_dialog.pyw
OpenSecurity/bin/opensecurity_tray.pyw
OpenSecurity/bin/ui/__init__.py
OpenSecurity/bin/ui/opensecurity_dialog.py
OpenSecurity/bin/ui/opensecurity_tray.pyw
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/OpenSecurity/bin/opensecurity_dialog.pyw	Mon Mar 31 15:26:56 2014 +0200
     1.3 @@ -0,0 +1,94 @@
     1.4 +#!/bin/env python
     1.5 +# -*- coding: utf-8 -*-
     1.6 +
     1.7 +# ------------------------------------------------------------
     1.8 +# opensecurity-dialog
     1.9 +# 
    1.10 +# an opensecurity dialog
    1.11 +#
    1.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    1.13 +#
    1.14 +# Copyright (C) 2013, 2014 AIT Austrian Institute of Technology
    1.15 +# AIT Austrian Institute of Technology GmbH
    1.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    1.17 +# http://www.ait.ac.at
    1.18 +#
    1.19 +# This program is free software; you can redistribute it and/or
    1.20 +# modify it under the terms of the GNU General Public License
    1.21 +# as published by the Free Software Foundation version 2.
    1.22 +# 
    1.23 +# This program is distributed in the hope that it will be useful,
    1.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.26 +# GNU General Public License for more details.
    1.27 +# 
    1.28 +# You should have received a copy of the GNU General Public License
    1.29 +# along with this program; if not, write to the Free Software
    1.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    1.31 +# Boston, MA  02110-1301, USA.
    1.32 +# ------------------------------------------------------------
    1.33 +
    1.34 +
    1.35 +# ------------------------------------------------------------
    1.36 +# imports
    1.37 +
    1.38 +import argparse
    1.39 +import os
    1.40 +import sys
    1.41 +
    1.42 +from PyQt4 import QtCore
    1.43 +from PyQt4 import QtGui
    1.44 +
    1.45 +# local
    1.46 +from ui import *
    1.47 +
    1.48 +
    1.49 +# ------------------------------------------------------------
    1.50 +# code
    1.51 +
    1.52 +
    1.53 +def main():
    1.54 +    
    1.55 +    # parse command line
    1.56 +    parser = argparse.ArgumentParser(description = 'OpenSecurity Dialog.')
    1.57 +    parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\', \'credentials\', \'notification-information\', \'notification-warning\' or \'notification-critical\'')
    1.58 +    parser.add_argument('text', metavar='TEXT', help='text to show')
    1.59 +    args = parser.parse_args()
    1.60 +    
    1.61 +    a = QtGui.QApplication(sys.argv)
    1.62 +    
    1.63 +    if args.mode == 'password':
    1.64 +        d = PasswordDialog(args.text)
    1.65 +    
    1.66 +    if args.mode == 'credentials':
    1.67 +        d = CredentialsDialog(args.text)
    1.68 +    
    1.69 +    if args.mode == 'notification-information':
    1.70 +        d = NotificationDialog('OpenSecurity Information', args.text)
    1.71 +    
    1.72 +    if args.mode == 'notification-warning':
    1.73 +        d = NotificationDialog('OpenSecurity Warning', args.text)
    1.74 +    
    1.75 +    if args.mode == 'notification-critical':
    1.76 +        d = NotificationDialog('OpenSecurity Criticali Message', args.text)
    1.77 +        
    1.78 +    if not 'd' in locals():
    1.79 +        sys.stderr.write('unknown mode. type --help for help\n')
    1.80 +        sys.exit(1)
    1.81 +    
    1.82 +    # pop up the dialog
    1.83 +    d.show()
    1.84 +    a.exec_()
    1.85 +    
    1.86 +    # give proper result code
    1.87 +    if d.result() == QtGui.QDialog.Accepted:
    1.88 +        res = 0
    1.89 +    else:
    1.90 +        res = 1
    1.91 +    sys.exit(res)
    1.92 +    
    1.93 +
    1.94 +# start
    1.95 +if __name__ == "__main__":
    1.96 +    main()
    1.97 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw	Mon Mar 31 15:26:56 2014 +0200
     2.3 @@ -0,0 +1,200 @@
     2.4 +#!/bin/env python
     2.5 +# -*- coding: utf-8 -*-
     2.6 +
     2.7 +# ------------------------------------------------------------
     2.8 +# opensecurity-dialog
     2.9 +# 
    2.10 +# an opensecurity dialog
    2.11 +#
    2.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    2.13 +#
    2.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    2.15 +# AIT Austrian Institute of Technology GmbH
    2.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    2.17 +# http://www.ait.ac.at
    2.18 +#
    2.19 +# This program is free software; you can redistribute it and/or
    2.20 +# modify it under the terms of the GNU General Public License
    2.21 +# as published by the Free Software Foundation version 2.
    2.22 +# 
    2.23 +# This program is distributed in the hope that it will be useful,
    2.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.26 +# GNU General Public License for more details.
    2.27 +# 
    2.28 +# You should have received a copy of the GNU General Public License
    2.29 +# along with this program; if not, write to the Free Software
    2.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    2.31 +# Boston, MA  02110-1301, USA.
    2.32 +# ------------------------------------------------------------
    2.33 +
    2.34 +
    2.35 +# ------------------------------------------------------------
    2.36 +# imports
    2.37 +
    2.38 +import argparse
    2.39 +import os
    2.40 +import subprocess
    2.41 +import sys
    2.42 +import urllib2
    2.43 +
    2.44 +from PyQt4 import QtCore
    2.45 +from PyQt4 import QtGui
    2.46 +
    2.47 +# local
    2.48 +if sys.platform == 'win32' or sys.platform == 'cygwin':
    2.49 +    from cygwin import Cygwin
    2.50 +
    2.51 +from ui import AboutDialog
    2.52 +from ui import opensecurity_rc
    2.53 +
    2.54 +
    2.55 +# ------------------------------------------------------------
    2.56 +# code
    2.57 +
    2.58 +
    2.59 +class OpenSecurityWait(QtGui.QDialog):
    2.60 +
    2.61 +    """OpenSecurity: please wait ..."""
    2.62 +    
    2.63 +    def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
    2.64 +        super(OpenSecurityWait, self).__init__(parent, flags)
    2.65 +        self.setWindowTitle('OpenSecurity')
    2.66 +        self.setup_ui()
    2.67 +        
    2.68 +        
    2.69 +    def setup_ui(self):
    2.70 +        """Create the widgets."""
    2.71 +        
    2.72 +        lyMain = QtGui.QVBoxLayout(self)
    2.73 +        lyMain.setContentsMargins(8, 8, 8, 8)
    2.74 +        
    2.75 +        # content area: left pixmap, right text
    2.76 +        lbTitle = QtGui.QLabel('Creating secure subsystem. Please stand by ...')
    2.77 +        lyMain.addWidget(lbTitle)
    2.78 +        
    2.79 +        self.setMinimumSize(400, 50)
    2.80 +        self.resize(lyMain.minimumSize())
    2.81 +
    2.82 +
    2.83 +class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
    2.84 +    
    2.85 +    """This is the OpenSecuirty Tray Icon"""
    2.86 +
    2.87 +    def __init__(self, icon, parent=None):
    2.88 +        
    2.89 +        super(OpenSecurityTrayIcon, self).__init__(icon, parent)
    2.90 +        self.setup_ui()
    2.91 +        
    2.92 +        
    2.93 +    def clicked_about(self):
    2.94 +        """clicked about"""
    2.95 +        d = AboutDialog()
    2.96 +        d.exec_()
    2.97 +    
    2.98 +
    2.99 +    def clicked_browser(self):
   2.100 +        """wish for safe internet browsing"""
   2.101 +        
   2.102 +        if not (sys.platform == 'win32' or sys.platform == 'cygwin'):
   2.103 +            QtGui.QMessageBox.critical(self.parent(), 'OpenSecurity Error', 'This action is not supported on this platform.\nSorry.')
   2.104 +            return
   2.105 +
   2.106 +        # TODO: HARDCODED ADDRESS OF OPENSECURITYD
   2.107 +        
   2.108 +        # tell the user to wait
   2.109 +        d = OpenSecurityWait()
   2.110 +        d.show()
   2.111 +        QtGui.QApplication.instance().processEvents()
   2.112 +        
   2.113 +        try:
   2.114 +        
   2.115 +            # get a proper browsing VM
   2.116 +            Cygwin.start_X11()
   2.117 +            browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline()
   2.118 +            #dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
   2.119 +            #process_command = [sys.executable, dlg_launch_image, browsing_vm, '/usr/bin/iceweasel']
   2.120 +            #process_command = [sys.executable, dlg_launch_image, browsing_vm, '/usr/bin/midori']
   2.121 +            #print(process_command)
   2.122 +            #process = subprocess.Popen(process_command, shell = False)
   2.123 +            
   2.124 +        except:
   2.125 +            d.hide()
   2.126 +            QtGui.QApplication.instance().processEvents()
   2.127 +            QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
   2.128 +            
   2.129 +        d.hide()
   2.130 +        QtGui.QApplication.instance().processEvents()
   2.131 +            
   2.132 +            
   2.133 +    def clicked_exit(self):
   2.134 +        """clicked exit"""
   2.135 +        sys.exit(0)
   2.136 +    
   2.137 +
   2.138 +    def clicked_launch_application(self):
   2.139 +        """clicked the launch an application"""
   2.140 +        dlg_launch_image = os.path.join(sys.path[0], 'ui', 'launch_dialog.py')
   2.141 +        process_command = [sys.executable, dlg_launch_image]
   2.142 +        print(process_command)
   2.143 +        process = subprocess.Popen(process_command, shell = False)
   2.144 +            
   2.145 +            
   2.146 +    def setup_ui(self):
   2.147 +        """create the user interface
   2.148 +        As for the system tray this is 'just' the context menu.
   2.149 +        """
   2.150 +    
   2.151 +        # define the tray icon menu
   2.152 +        menu = QtGui.QMenu(self.parent())
   2.153 +        self.setContextMenu(menu)
   2.154 +        
   2.155 +        # add known apps
   2.156 +        self.acBrowser = QtGui.QAction('Secure Browsing', self.parent())
   2.157 +        icon = QtGui.QIcon()
   2.158 +        icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_icon_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
   2.159 +        self.acBrowser.setIcon(icon)
   2.160 +        menu.addAction(self.acBrowser)
   2.161 +        menu.addSeparator()
   2.162 +        
   2.163 +        # add standard menu items
   2.164 +        self.acLaunch = QtGui.QAction('Launch Application', self.parent())
   2.165 +        icon = QtGui.QIcon()
   2.166 +        icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_icon_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
   2.167 +        self.acLaunch.setIcon(icon)
   2.168 +        menu.addAction(self.acLaunch)
   2.169 +        menu.addSeparator()
   2.170 +
   2.171 +        self.acAbout = menu.addAction('About')
   2.172 +        self.acExit = menu.addAction('Exit')
   2.173 +        
   2.174 +        self.acBrowser.triggered.connect(self.clicked_browser)
   2.175 +        self.acLaunch.triggered.connect(self.clicked_launch_application)
   2.176 +        self.acAbout.triggered.connect(self.clicked_about)
   2.177 +        self.acExit.triggered.connect(self.clicked_exit)
   2.178 +        
   2.179 +        
   2.180 +def main():
   2.181 +    
   2.182 +    a = QtGui.QApplication(sys.argv)
   2.183 +
   2.184 +#    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
   2.185 +#    image_path = os.path.join(Environment("OpenSecurity").data_path, 'gfx')
   2.186 +#    for file in os.listdir(image_path):
   2.187 +#        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
   2.188 +#            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
   2.189 +
   2.190 +    w = QtGui.QWidget()
   2.191 +    icon = QtGui.QIcon()
   2.192 +    icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(":/opensecurity/gfx/opensecurity_icon_64.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
   2.193 +    trayIcon = OpenSecurityTrayIcon(icon)
   2.194 +
   2.195 +    trayIcon.show()
   2.196 +    a.setQuitOnLastWindowClosed(False)
   2.197 +    sys.exit(a.exec_())
   2.198 +   
   2.199 +
   2.200 +# start
   2.201 +if __name__ == "__main__":
   2.202 +    main()
   2.203 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/OpenSecurity/bin/ui/__init__.py	Mon Mar 31 15:26:56 2014 +0200
     3.3 @@ -0,0 +1,51 @@
     3.4 +#!/bin/env python
     3.5 +# -*- coding: utf-8 -*-
     3.6 +
     3.7 +# ------------------------------------------------------------
     3.8 +# ui/__init__.py
     3.9 +# 
    3.10 +# python package file for ui
    3.11 +#
    3.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    3.13 +#
    3.14 +# Copyright (C) 2014 AIT Austrian Institute of Technology
    3.15 +# AIT Austrian Institute of Technology GmbH
    3.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    3.17 +# http://www.ait.ac.at
    3.18 +#
    3.19 +# This program is free software; you can redistribute it and/or
    3.20 +# modify it under the terms of the GNU General Public License
    3.21 +# as published by the Free Software Foundation version 2.
    3.22 +# 
    3.23 +# This program is distributed in the hope that it will be useful,
    3.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.26 +# GNU General Public License for more details.
    3.27 +# 
    3.28 +# You should have received a copy of the GNU General Public License
    3.29 +# along with this program; if not, write to the Free Software
    3.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    3.31 +# Boston, MA  02110-1301, USA.
    3.32 +# ------------------------------------------------------------
    3.33 +
    3.34 +
    3.35 +# ------------------------------------------------------------
    3.36 +# imports
    3.37 +
    3.38 +from about_dialog import AboutDialog
    3.39 +from configure_dialog import ConfigureDialog
    3.40 +from credentials_dialog import CredentialsDialog
    3.41 +from launch_dialog import LaunchDialog
    3.42 +from notification_dialog import NotificationDialog
    3.43 +from password_dialog import  PasswordDialog
    3.44 +
    3.45 +# ------------------------------------------------------------
    3.46 +# vars
    3.47 +__all__ = [
    3.48 +    'AboutDialog',
    3.49 +    'ConfigureDialog',
    3.50 +    'CredentialsDialog',
    3.51 +    'LaunchDialog',
    3.52 +    'NotificationDialog',
    3.53 +    'PasswordDialog'
    3.54 +    ]
     4.1 --- a/OpenSecurity/bin/ui/opensecurity_dialog.py	Mon Mar 31 13:27:50 2014 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,106 +0,0 @@
     4.4 -#!/bin/env python
     4.5 -# -*- coding: utf-8 -*-
     4.6 -
     4.7 -# ------------------------------------------------------------
     4.8 -# opensecurity-dialog
     4.9 -# 
    4.10 -# an opensecurity dialog
    4.11 -#
    4.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    4.13 -#
    4.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
    4.15 -# AIT Austrian Institute of Technology GmbH
    4.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
    4.17 -# http://www.ait.ac.at
    4.18 -#
    4.19 -# This program is free software; you can redistribute it and/or
    4.20 -# modify it under the terms of the GNU General Public License
    4.21 -# as published by the Free Software Foundation version 2.
    4.22 -# 
    4.23 -# This program is distributed in the hope that it will be useful,
    4.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.26 -# GNU General Public License for more details.
    4.27 -# 
    4.28 -# You should have received a copy of the GNU General Public License
    4.29 -# along with this program; if not, write to the Free Software
    4.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    4.31 -# Boston, MA  02110-1301, USA.
    4.32 -# ------------------------------------------------------------
    4.33 -
    4.34 -
    4.35 -# ------------------------------------------------------------
    4.36 -# imports
    4.37 -
    4.38 -import argparse
    4.39 -import os
    4.40 -import sys
    4.41 -
    4.42 -from PyQt4 import QtCore
    4.43 -from PyQt4 import QtGui
    4.44 -
    4.45 -# local
    4.46 -from credentials import Credentials
    4.47 -from environment import Environment
    4.48 -from notification import Notification
    4.49 -from password import Password
    4.50 -
    4.51 -
    4.52 -# ------------------------------------------------------------
    4.53 -# code
    4.54 -
    4.55 -
    4.56 -def main():
    4.57 -    
    4.58 -    # parse command line
    4.59 -    parser = argparse.ArgumentParser(description = 'OpenSecurity Dialog.')
    4.60 -    parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\', \'credentials\', \'notification-information\', \'notification-warning\' or \'notification-critical\'')
    4.61 -    parser.add_argument('text', metavar='TEXT', help='text to show')
    4.62 -    args = parser.parse_args()
    4.63 -    
    4.64 -    app = QtGui.QApplication(sys.argv)
    4.65 -    
    4.66 -    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
    4.67 -    data_path = Environment("OpenSecurity").data_path
    4.68 -    image_path = os.path.join(data_path, 'gfx')
    4.69 -    for file in os.listdir(image_path):
    4.70 -        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
    4.71 -            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
    4.72 -            
    4.73 -    # we should have now our application icon
    4.74 -    app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
    4.75 -    
    4.76 -    if args.mode == 'password':
    4.77 -        dlg = Password(args.text)
    4.78 -    
    4.79 -    if args.mode == 'credentials':
    4.80 -        dlg = Credentials(args.text)
    4.81 -    
    4.82 -    if args.mode == 'notification-information':
    4.83 -        dlg = Notification('information', args.text)
    4.84 -    
    4.85 -    if args.mode == 'notification-warning':
    4.86 -        dlg = Notification('warning', args.text)
    4.87 -    
    4.88 -    if args.mode == 'notification-critical':
    4.89 -        dlg = Notification('critical', args.text)
    4.90 -        
    4.91 -    if not 'dlg' in locals():
    4.92 -        raise ValueError('unknown mode. type --help for help')
    4.93 -    
    4.94 -    # pop up the dialog
    4.95 -    dlg.show()
    4.96 -    app.exec_()
    4.97 -    
    4.98 -    # give proper result code
    4.99 -    if dlg.result() == QtGui.QDialog.Accepted:
   4.100 -        res = 0
   4.101 -    else:
   4.102 -        res = 1
   4.103 -    sys.exit(res)
   4.104 -    
   4.105 -
   4.106 -# start
   4.107 -if __name__ == "__main__":
   4.108 -    main()
   4.109 -
     5.1 --- a/OpenSecurity/bin/ui/opensecurity_tray.pyw	Mon Mar 31 13:27:50 2014 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,182 +0,0 @@
     5.4 -#!/bin/env python
     5.5 -# -*- coding: utf-8 -*-
     5.6 -
     5.7 -# ------------------------------------------------------------
     5.8 -# opensecurity-dialog
     5.9 -# 
    5.10 -# an opensecurity dialog
    5.11 -#
    5.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    5.13 -#
    5.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
    5.15 -# AIT Austrian Institute of Technology GmbH
    5.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
    5.17 -# http://www.ait.ac.at
    5.18 -#
    5.19 -# This program is free software; you can redistribute it and/or
    5.20 -# modify it under the terms of the GNU General Public License
    5.21 -# as published by the Free Software Foundation version 2.
    5.22 -# 
    5.23 -# This program is distributed in the hope that it will be useful,
    5.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.26 -# GNU General Public License for more details.
    5.27 -# 
    5.28 -# You should have received a copy of the GNU General Public License
    5.29 -# along with this program; if not, write to the Free Software
    5.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    5.31 -# Boston, MA  02110-1301, USA.
    5.32 -# ------------------------------------------------------------
    5.33 -
    5.34 -
    5.35 -# ------------------------------------------------------------
    5.36 -# imports
    5.37 -
    5.38 -import argparse
    5.39 -import os
    5.40 -import subprocess
    5.41 -import sys
    5.42 -import urllib2
    5.43 -
    5.44 -from PyQt4 import QtCore
    5.45 -from PyQt4 import QtGui
    5.46 -
    5.47 -# local
    5.48 -from about import About
    5.49 -from environment import Environment
    5.50 -from cygwin import Cygwin
    5.51 -
    5.52 -# ------------------------------------------------------------
    5.53 -# code
    5.54 -
    5.55 -
    5.56 -class OpenSecurityWait(QtGui.QDialog):
    5.57 -
    5.58 -    """OpenSecurity: please wait ..."""
    5.59 -    
    5.60 -    def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
    5.61 -        super(OpenSecurityWait, self).__init__(parent, flags)
    5.62 -        self.setWindowTitle('OpenSecurity')
    5.63 -        self.setup_ui()
    5.64 -        
    5.65 -        
    5.66 -    def setup_ui(self):
    5.67 -        """Create the widgets."""
    5.68 -        
    5.69 -        lyMain = QtGui.QVBoxLayout(self)
    5.70 -        lyMain.setContentsMargins(8, 8, 8, 8)
    5.71 -        
    5.72 -        # content area: left pixmap, right text
    5.73 -        lbTitle = QtGui.QLabel('Creating secure subsystem. Please stand by ...')
    5.74 -        lyMain.addWidget(lbTitle)
    5.75 -        
    5.76 -        self.setMinimumSize(400, 50)
    5.77 -        self.resize(lyMain.minimumSize())
    5.78 -
    5.79 -
    5.80 -class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
    5.81 -    
    5.82 -    """This is the OpenSecuirty Tray Icon"""
    5.83 -
    5.84 -    def __init__(self, icon, parent=None):
    5.85 -        
    5.86 -        super(OpenSecurityTrayIcon, self).__init__(icon, parent)
    5.87 -        self.setup_ui()
    5.88 -        
    5.89 -        
    5.90 -    def clicked_about(self):
    5.91 -        """clicked about"""
    5.92 -        dlgAbout = About()
    5.93 -        dlgAbout.exec_()
    5.94 -    
    5.95 -
    5.96 -    def clicked_browser(self):
    5.97 -        """wish for safe internet browsing"""
    5.98 -        
    5.99 -        # TODO: HARDCODED ADDRESS OF OPENSECURITYD
   5.100 -        
   5.101 -        # tell the user to wait
   5.102 -        dlg = OpenSecurityWait()
   5.103 -        dlg.show()
   5.104 -        QtGui.QApplication.instance().processEvents()
   5.105 -        
   5.106 -        try:
   5.107 -        
   5.108 -            # get a proper browsing VM
   5.109 -            Cygwin.start_X11()
   5.110 -            browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline()
   5.111 -            #dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
   5.112 -            #process_command = [sys.executable, dlg_launch_image, browsing_vm, '/usr/bin/iceweasel']
   5.113 -            #process_command = [sys.executable, dlg_launch_image, browsing_vm, '/usr/bin/midori']
   5.114 -            #print(process_command)
   5.115 -            #process = subprocess.Popen(process_command, shell = False)
   5.116 -            
   5.117 -        except:
   5.118 -            dlg.hide()
   5.119 -            QtGui.QApplication.instance().processEvents()
   5.120 -            QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
   5.121 -            
   5.122 -        dlg.hide()
   5.123 -        QtGui.QApplication.instance().processEvents()
   5.124 -            
   5.125 -            
   5.126 -    def clicked_exit(self):
   5.127 -        """clicked exit"""
   5.128 -        sys.exit(0)
   5.129 -    
   5.130 -
   5.131 -    def clicked_launch_application(self):
   5.132 -        """clicked the launch an application"""
   5.133 -        dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
   5.134 -        process_command = [sys.executable, dlg_launch_image]
   5.135 -        print(process_command)
   5.136 -        process = subprocess.Popen(process_command, shell = False)
   5.137 -            
   5.138 -            
   5.139 -    def setup_ui(self):
   5.140 -        """create the user interface
   5.141 -        As for the system tray this is 'just' the context menu.
   5.142 -        """
   5.143 -    
   5.144 -        # define the tray icon menu
   5.145 -        menu = QtGui.QMenu(self.parent())
   5.146 -        self.setContextMenu(menu)
   5.147 -        
   5.148 -        # add known apps
   5.149 -        cAcBrowser = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Safe Internet Browsing')
   5.150 -        menu.addSeparator()
   5.151 -        
   5.152 -        # add standard menu items
   5.153 -        cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
   5.154 -        menu.addSeparator()
   5.155 -        cAcAbout = menu.addAction("About")
   5.156 -        cAcExit = menu.addAction("Exit")
   5.157 -        
   5.158 -        cAcBrowser.triggered.connect(self.clicked_browser)
   5.159 -        cAcLaunch.triggered.connect(self.clicked_launch_application)
   5.160 -        cAcAbout.triggered.connect(self.clicked_about)
   5.161 -        cAcExit.triggered.connect(self.clicked_exit)
   5.162 -        
   5.163 -        
   5.164 -def main():
   5.165 -    
   5.166 -    app = QtGui.QApplication(sys.argv)
   5.167 -
   5.168 -    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
   5.169 -    image_path = os.path.join(Environment("OpenSecurity").data_path, 'gfx')
   5.170 -    for file in os.listdir(image_path):
   5.171 -        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
   5.172 -            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
   5.173 -
   5.174 -    w = QtGui.QWidget()
   5.175 -    trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
   5.176 -
   5.177 -    trayIcon.show()
   5.178 -    app.setQuitOnLastWindowClosed(False)
   5.179 -    sys.exit(app.exec_())
   5.180 -   
   5.181 -
   5.182 -# start
   5.183 -if __name__ == "__main__":
   5.184 -    main()
   5.185 -