From 010c15a498c4ed5d7a76e1ad67224d78996ecdc6 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 15 May 2016 17:39:49 +0300 Subject: [PATCH] password screen and main.py update --- src/main.py | 17 +++++++++++++++++ src/passwordscreen.py | 36 ++++++++++++++++++++++++++++++++++++ src/toxencryptsave.py | 8 +++++--- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/passwordscreen.py diff --git a/src/main.py b/src/main.py index 804036e..6e09624 100644 --- a/src/main.py +++ b/src/main.py @@ -9,6 +9,7 @@ from callbacks import init_callbacks from util import curr_directory, get_style import styles.style import locale +import toxencryptsave class Toxygen(object): @@ -18,6 +19,13 @@ class Toxygen(object): self.tox = self.ms = self.init = self.mainloop = self.avloop = None self.path = path + def enter_pass(self, old_data): + """ + Show password screen + """ + # TODO: show password screen and decrypt data + raise NotImplementedError() + def main(self): """ Main function of app. loads login screen if needed and starts main screen @@ -29,10 +37,15 @@ class Toxygen(object): with open(curr_directory() + '/styles/style.qss') as fl: dark_style = fl.read() app.setStyleSheet(dark_style) + + encrypt_save = toxencryptsave.LibToxEncryptSave() + if self.path is not None: path = os.path.dirname(self.path.encode(locale.getpreferredencoding())) + '/' name = os.path.basename(self.path.encode(locale.getpreferredencoding()))[:-4] data = ProfileHelper(path, name).open_profile() + if encrypt_save.is_data_encrypted(data): + data = self.enter_pass(data) settings = Settings(name) self.tox = tox_factory(data, settings) else: @@ -72,12 +85,16 @@ class Toxygen(object): if _login.default: Settings.set_auto_profile(path, name) data = ProfileHelper(path, name).open_profile() + if encrypt_save.is_data_encrypted(data): + data = self.enter_pass(data) settings = Settings(name) self.tox = tox_factory(data, settings) else: path, name = auto_profile path = path.encode(locale.getpreferredencoding()) data = ProfileHelper(path, name).open_profile() + if encrypt_save.is_data_encrypted(data): + data = self.enter_pass(data) settings = Settings(name) self.tox = tox_factory(data, settings) diff --git a/src/passwordscreen.py b/src/passwordscreen.py new file mode 100644 index 0000000..4e4da53 --- /dev/null +++ b/src/passwordscreen.py @@ -0,0 +1,36 @@ +from widgets import CenteredWidget +from PySide import QtCore, QtGui + +# TODO: add onclick + + +class PasswordScreen(CenteredWidget): + + def __init__(self, encrypt): + super(PasswordScreen, self).__init__() + self._encrypt = encrypt + self.initUI() + + def initUI(self): + self.resize(360, 200) + self.setMinimumSize(QtCore.QSize(360, 200)) + self.setMaximumSize(QtCore.QSize(360, 200)) + + self.enter_pass = QtGui.QLabel(self) + self.enter_pass.setGeometry(QtCore.QRect(30, 10, 300, 30)) + + self.password = QtGui.QLineEdit(self) + self.password.setGeometry(QtCore.QRect(30, 80, 300, 30)) + self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) + + self.button = QtGui.QPushButton(self) + self.button.setGeometry(QtCore.QRect(30, 120, 300, 30)) + self.button.setText('OK') + + self.retranslateUi() + QtCore.QMetaObject.connectSlotsByName(self) + + def retranslateUi(self): + self.setWindowTitle(QtGui.QApplication.translate("pass", "Enter password", None, QtGui.QApplication.UnicodeUTF8)) + self.enter_pass.setText(QtGui.QApplication.translate("pass", "Password:", None, QtGui.QApplication.UnicodeUTF8)) + diff --git a/src/toxencryptsave.py b/src/toxencryptsave.py index c46b4d8..d8e1cc9 100644 --- a/src/toxencryptsave.py +++ b/src/toxencryptsave.py @@ -1,6 +1,6 @@ import libtox import util -from ctypes import c_size_t, create_string_buffer, byref, c_int, ArgumentError, c_char_p +from ctypes import c_size_t, create_string_buffer, byref, c_int, ArgumentError, c_char_p, c_bool TOX_ERR_ENCRYPTION = { @@ -48,8 +48,10 @@ class LibToxEncryptSave(util.Singleton): return bool(self._passphrase) def is_data_encrypted(self, data): - result = self.libtoxencryptsave.tox_is_data_encrypted(c_char_p(data)) - return bool(result) + func = self.libtoxencryptsave.tox_is_data_encrypted + func.restype = c_bool + result = func(c_char_p(data)) + return result def pass_encrypt(self, data): """