OpenSecurity/bin/opensecurity_tray.pyw
changeset 111 a2c7f29d3683
parent 110 490a78181935
parent 106 c5101320b46c
child 136 ac117cd7bab1
     1.1 --- a/OpenSecurity/bin/opensecurity_tray.pyw	Wed Apr 02 10:41:00 2014 +0100
     1.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw	Wed Apr 02 10:45:58 2014 +0100
     1.3 @@ -42,11 +42,14 @@
     1.4  from PyQt4 import QtGui
     1.5  
     1.6  # local
     1.7 -from about import About
     1.8 -from environment import Environment
     1.9 -from cygwin import Cygwin
    1.10 -import threading
    1.11 -import time
    1.12 +if sys.platform == 'win32' or sys.platform == 'cygwin':
    1.13 +    from cygwin import Cygwin
    1.14 +
    1.15 +from ui import AboutDialog
    1.16 +from ui import ConfigureDialog
    1.17 +from ui import opensecurity_rc
    1.18 +
    1.19 +
    1.20  # ------------------------------------------------------------
    1.21  # code
    1.22  
    1.23 @@ -87,18 +90,22 @@
    1.24          
    1.25      def clicked_about(self):
    1.26          """clicked about"""
    1.27 -        dlgAbout = About()
    1.28 -        dlgAbout.exec_()
    1.29 +        d = AboutDialog()
    1.30 +        d.exec_()
    1.31      
    1.32  
    1.33      def clicked_browser(self):
    1.34          """wish for safe internet browsing"""
    1.35          
    1.36 +        if not (sys.platform == 'win32' or sys.platform == 'cygwin'):
    1.37 +            QtGui.QMessageBox.critical(self.parent(), 'OpenSecurity Error', 'This action is not supported on this platform.\nSorry.')
    1.38 +            return
    1.39 +
    1.40          # TODO: HARDCODED ADDRESS OF OPENSECURITYD
    1.41          
    1.42          # tell the user to wait
    1.43 -        dlg = OpenSecurityWait()
    1.44 -        dlg.show()
    1.45 +        d = OpenSecurityWait()
    1.46 +        d.show()
    1.47          QtGui.QApplication.instance().processEvents()
    1.48          
    1.49          try:
    1.50 @@ -113,14 +120,20 @@
    1.51              #process = subprocess.Popen(process_command, shell = False)
    1.52              
    1.53          except:
    1.54 -            dlg.hide()
    1.55 +            d.hide()
    1.56              QtGui.QApplication.instance().processEvents()
    1.57              QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
    1.58              
    1.59 -        dlg.hide()
    1.60 +        d.hide()
    1.61          QtGui.QApplication.instance().processEvents()
    1.62              
    1.63              
    1.64 +    def clicked_configure(self):
    1.65 +        """clicked configure"""
    1.66 +        d = ConfigureDialog()
    1.67 +        d.exec_()
    1.68 +    
    1.69 +
    1.70      def clicked_exit(self):
    1.71          """clicked exit"""
    1.72          sys.exit(0)
    1.73 @@ -128,7 +141,7 @@
    1.74  
    1.75      def clicked_launch_application(self):
    1.76          """clicked the launch an application"""
    1.77 -        dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
    1.78 +        dlg_launch_image = os.path.join(sys.path[0], 'ui', 'launch_dialog.py')
    1.79          process_command = [sys.executable, dlg_launch_image]
    1.80          print(process_command)
    1.81          process = subprocess.Popen(process_command, shell = False)
    1.82 @@ -144,35 +157,48 @@
    1.83          self.setContextMenu(menu)
    1.84          
    1.85          # add known apps
    1.86 -        cAcBrowser = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Safe Internet Browsing')
    1.87 +        self.acBrowser = QtGui.QAction('Secure Browsing', self.parent())
    1.88 +        icon = QtGui.QIcon()
    1.89 +        icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_browsing_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    1.90 +        self.acBrowser.setIcon(icon)
    1.91 +        menu.addAction(self.acBrowser)
    1.92          menu.addSeparator()
    1.93          
    1.94          # add standard menu items
    1.95 -        cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
    1.96 +        self.acLaunch = QtGui.QAction('Launch Application', self.parent())
    1.97 +        icon = QtGui.QIcon()
    1.98 +        icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_launch_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    1.99 +        self.acLaunch.setIcon(icon)
   1.100 +        menu.addAction(self.acLaunch)
   1.101 +        self.acConfigure = QtGui.QAction('Configuration', self.parent())
   1.102 +        icon = QtGui.QIcon()
   1.103 +        icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_configure_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
   1.104 +        self.acConfigure.setIcon(icon)
   1.105 +        menu.addAction(self.acConfigure)
   1.106          menu.addSeparator()
   1.107 -        cAcAbout = menu.addAction("About")
   1.108 -        cAcExit = menu.addAction("Exit")
   1.109 +
   1.110 +        self.acAbout = menu.addAction('About')
   1.111 +        self.acExit = menu.addAction('Exit')
   1.112          
   1.113 -        cAcBrowser.triggered.connect(self.clicked_browser)
   1.114 -        cAcLaunch.triggered.connect(self.clicked_launch_application)
   1.115 -        cAcAbout.triggered.connect(self.clicked_about)
   1.116 -        cAcExit.triggered.connect(self.clicked_exit)
   1.117 -                           
   1.118 +        self.acBrowser.triggered.connect(self.clicked_browser)
   1.119 +        self.acLaunch.triggered.connect(self.clicked_launch_application)
   1.120 +        self.acConfigure.triggered.connect(self.clicked_configure)
   1.121 +        self.acAbout.triggered.connect(self.clicked_about)
   1.122 +        self.acExit.triggered.connect(self.clicked_exit)
   1.123 +        
   1.124 +        
   1.125  def main():
   1.126 -    app = QtGui.QApplication(sys.argv)
   1.127 -
   1.128 -    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
   1.129 -    image_path = os.path.join(Environment("OpenSecurity").data_path, 'gfx')
   1.130 -    for file in os.listdir(image_path):
   1.131 -        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
   1.132 -            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
   1.133 +    
   1.134 +    a = QtGui.QApplication(sys.argv)
   1.135  
   1.136      w = QtGui.QWidget()
   1.137 -    trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
   1.138 +    icon = QtGui.QIcon()
   1.139 +    icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(":/opensecurity/gfx/opensecurity_icon_64.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
   1.140 +    trayIcon = OpenSecurityTrayIcon(icon)
   1.141  
   1.142      trayIcon.show()
   1.143 -    app.setQuitOnLastWindowClosed(False)
   1.144 -    sys.exit(app.exec_())
   1.145 +    a.setQuitOnLastWindowClosed(False)
   1.146 +    sys.exit(a.exec_())
   1.147     
   1.148  
   1.149  # start