diff -r 000000000000 -r c9bf2537109a ait/os/bin/opensecurityd/opensecurity-dialog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ait/os/bin/opensecurityd/opensecurity-dialog.py Tue Nov 12 11:31:34 2013 +0100 @@ -0,0 +1,92 @@ +#!/bin/env python +# -*- coding: utf-8 -*- + +# ------------------------------------------------------------ +# opensecurity-dialog +# +# an opensecurity dialog +# +# Autor: Oliver Maurhart, +# +# Copyright (C) 2013 AIT Austrian Institute of Technology +# AIT Austrian Institute of Technology GmbH +# Donau-City-Strasse 1 | 1220 Vienna | Austria +# http://www.ait.ac.at +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation version 2. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# ------------------------------------------------------------ + + +# ------------------------------------------------------------ +# imports + +import argparse +import os +import sys + +from PyQt4 import QtCore +from PyQt4 import QtGui + +# local +from credentials import Credentials +from environment import Environment +from password import Password + + +# ------------------------------------------------------------ +# code + + +def main(): + + # parse command line + parser = argparse.ArgumentParser(description = 'OpenSecuirty Dialog.') + parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\' or \'credentials\'') + parser.add_argument('text', metavar='TEXT', help='text to show') + args = parser.parse_args() + + app = QtGui.QApplication(sys.argv) + + # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them + data_path = Environment("opensecurity").image_path + for file in os.listdir(data_path): + if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'): + QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(data_path, file))) + + # we should have now our application icon + app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64'))) + + if args.mode == 'password': + dlg = Password(args.text) + + if args.mode == 'credentials': + dlg = Credentials(args.text) + + # pop up the dialog + dlg.show() + app.exec_() + + # give proper result code + if dlg.result() == QtGui.QDialog.Accepted: + res = 0 + else: + res = 1 + sys.exit(res) + + +# start +if __name__ == "__main__": + main() +