1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/OpenSecurity/client/opensecurity_dialog.py Mon Dec 02 14:02:05 2013 +0100
1.3 @@ -0,0 +1,93 @@
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 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 credentials import Credentials
1.47 +from environment import Environment
1.48 +from password import Password
1.49 +
1.50 +
1.51 +# ------------------------------------------------------------
1.52 +# code
1.53 +
1.54 +
1.55 +def main():
1.56 +
1.57 + # parse command line
1.58 + parser = argparse.ArgumentParser(description = 'OpenSecurity Dialog.')
1.59 + parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\' or \'credentials\'')
1.60 + parser.add_argument('text', metavar='TEXT', help='text to show')
1.61 + args = parser.parse_args()
1.62 +
1.63 + app = QtGui.QApplication(sys.argv)
1.64 +
1.65 + # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
1.66 + data_path = Environment("OpenSecurity").data_path
1.67 + image_path = os.path.join(data_path, '..', 'gfx')
1.68 + for file in os.listdir(image_path):
1.69 + if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
1.70 + QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
1.71 +
1.72 + # we should have now our application icon
1.73 + app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
1.74 +
1.75 + if args.mode == 'password':
1.76 + dlg = Password(args.text)
1.77 +
1.78 + if args.mode == 'credentials':
1.79 + dlg = Credentials(args.text)
1.80 +
1.81 + # pop up the dialog
1.82 + dlg.show()
1.83 + app.exec_()
1.84 +
1.85 + # give proper result code
1.86 + if dlg.result() == QtGui.QDialog.Accepted:
1.87 + res = 0
1.88 + else:
1.89 + res = 1
1.90 + sys.exit(res)
1.91 +
1.92 +
1.93 +# start
1.94 +if __name__ == "__main__":
1.95 + main()
1.96 +