yubioath-flutter/yubioath/gui/main.py

164 lines
5.3 KiB
Python
Raw Normal View History

2015-04-24 17:01:36 +03:00
# Copyright (c) 2014 Yubico AB
# All rights reserved.
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Additional permission under GNU GPL version 3 section 7
#
# If you modify this program, or any covered work, by linking or
# combining it with the OpenSSL project's OpenSSL library (or a
# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, We grant you additional
# permission to convey the resulting work. Corresponding Source for a
# non-source form of such a combination shall include the source code
# for the parts of OpenSSL used as well as that of the covered work.
2015-04-27 16:18:16 +03:00
import sys
import argparse
from PySide import QtGui, QtCore
from yubioath import __version__ as version
2015-05-19 11:02:39 +03:00
from yubioath.yubicommon import qt
2015-04-27 16:18:16 +03:00
from yubioath.gui import messages as m
2015-05-19 13:13:55 +03:00
from yubioath.gui.controller import GuiController
2015-05-19 11:02:39 +03:00
# from yubioath.core.ykpers import libversion as ykpers_version
ykpers_version = 'None'
from yubioath.gui.view.codes import CodesWidget
2015-04-27 16:18:16 +03:00
2015-05-19 11:02:39 +03:00
ABOUT_TEXT = """
<h2>%s</h2>
%s<br>
%s
<h4>%s</h4>
%%s
<br><br>
""" % (m.app_name, m.copyright, m.version_1, m.libraries)
2015-04-27 16:18:16 +03:00
2015-05-19 11:02:39 +03:00
class MainWidget(QtGui.QStackedWidget):
2015-04-27 16:18:16 +03:00
2015-05-19 13:13:55 +03:00
def __init__(self, controller):
2015-05-19 11:02:39 +03:00
super(MainWidget, self).__init__()
2015-04-27 16:18:16 +03:00
2015-05-19 13:13:55 +03:00
self._controller = controller
2015-05-19 11:02:39 +03:00
self._build_ui()
2015-05-19 13:13:55 +03:00
controller.refreshed.connect(self._refresh)
2015-04-27 16:18:16 +03:00
2015-05-19 11:02:39 +03:00
def showEvent(self, event):
event.accept()
def _build_ui(self):
2015-05-19 13:13:55 +03:00
self.codes_widget = CodesWidget(self._controller)
self.no_key_widget = QtGui.QLabel(m.no_key)
self.addWidget(self.codes_widget)
self.addWidget(self.no_key_widget)
def _refresh(self):
if self._controller.credentials is None:
self.setCurrentIndex(1)
else:
self.setCurrentIndex(0)
2015-05-19 11:02:39 +03:00
class YubiOathApplication(qt.Application):
def __init__(self):
super(YubiOathApplication, self).__init__(m)
2015-04-27 16:18:16 +03:00
QtCore.QCoreApplication.setOrganizationName(m.organization)
QtCore.QCoreApplication.setOrganizationDomain(m.domain)
QtCore.QCoreApplication.setApplicationName(m.app_name)
2015-05-19 11:02:39 +03:00
self._widget = None
self._settings = {} # TODO get_store('window')
2015-04-27 16:18:16 +03:00
2015-05-19 13:13:55 +03:00
reader = self._settings.get('reader', 'Yubikey')
self._controller = GuiController(reader, 6, 6)
2015-05-19 11:02:39 +03:00
self._init_window()
def _init_window(self):
self.window.setWindowTitle(m.win_title_1 % version)
self.window.setWindowIcon(QtGui.QIcon(':/yubioath.png'))
self.window.resize(self._settings.get('size', QtCore.QSize(320, 340)))
2015-05-19 11:02:39 +03:00
pos = self._settings.get('pos')
if pos:
self.window.move(pos)
self._build_menu_bar()
2015-04-27 16:18:16 +03:00
args = self._parse_args()
if args.tray:
pass
2015-05-19 11:02:39 +03:00
self.window.shown.connect(self._on_shown)
self.window.closed.connect(self._on_closed)
2015-04-27 16:18:16 +03:00
self.window.show()
self.window.raise_()
def _parse_args(self):
parser = argparse.ArgumentParser(description='Yubico Authenticator',
add_help=True)
parser.add_argument('-t', '--tray', action='store_true')
return parser.parse_args()
2015-05-19 11:02:39 +03:00
def _build_menu_bar(self):
file_menu = self.window.menuBar().addMenu(m.menu_file)
add_action = QtGui.QAction(m.action_add, file_menu)
add_action.triggered.connect(self._add_credential)
file_menu.addAction(add_action)
password_action = QtGui.QAction(m.action_password, file_menu)
password_action.triggered.connect(self._change_password)
file_menu.addAction(password_action)
settings_action = QtGui.QAction(m.action_settings, file_menu)
settings_action.triggered.connect(self._show_settings)
file_menu.addAction(settings_action)
help_menu = self.window.menuBar().addMenu(m.menu_help)
about_action = QtGui.QAction(m.action_about, help_menu)
about_action.triggered.connect(self._about)
help_menu.addAction(about_action)
def _on_shown(self):
if not self._widget:
2015-05-19 13:13:55 +03:00
self._widget = MainWidget(self._controller)
2015-05-19 11:02:39 +03:00
self.window.setCentralWidget(self._widget)
def _on_closed(self):
self._settings['pos'] = self.window.pos()
self._settings['size'] = self.window.size()
def _libversions(self):
return 'ykpers: %s' % ykpers_version
def _about(self):
QtGui.QMessageBox.about(self.window, m.about_1 % m.app_name,
ABOUT_TEXT % (version, self._libversions()))
def _add_credential(self):
print "TODO"
def _change_password(self):
print "TODO"
2015-04-27 16:18:16 +03:00
2015-05-19 11:02:39 +03:00
def _show_settings(self):
print "TODO"
2015-04-27 16:18:16 +03:00
2015-04-24 17:01:36 +03:00
def main():
2015-05-19 11:02:39 +03:00
app = YubiOathApplication()
sys.exit(app.exec_())