password screen and main.py update

This commit is contained in:
ingvar1995 2016-05-15 17:39:49 +03:00
parent 284311a91c
commit 010c15a498
3 changed files with 58 additions and 3 deletions

View File

@ -9,6 +9,7 @@ from callbacks import init_callbacks
from util import curr_directory, get_style from util import curr_directory, get_style
import styles.style import styles.style
import locale import locale
import toxencryptsave
class Toxygen(object): class Toxygen(object):
@ -18,6 +19,13 @@ class Toxygen(object):
self.tox = self.ms = self.init = self.mainloop = self.avloop = None self.tox = self.ms = self.init = self.mainloop = self.avloop = None
self.path = path self.path = path
def enter_pass(self, old_data):
"""
Show password screen
"""
# TODO: show password screen and decrypt data
raise NotImplementedError()
def main(self): def main(self):
""" """
Main function of app. loads login screen if needed and starts main screen 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: with open(curr_directory() + '/styles/style.qss') as fl:
dark_style = fl.read() dark_style = fl.read()
app.setStyleSheet(dark_style) app.setStyleSheet(dark_style)
encrypt_save = toxencryptsave.LibToxEncryptSave()
if self.path is not None: if self.path is not None:
path = os.path.dirname(self.path.encode(locale.getpreferredencoding())) + '/' path = os.path.dirname(self.path.encode(locale.getpreferredencoding())) + '/'
name = os.path.basename(self.path.encode(locale.getpreferredencoding()))[:-4] name = os.path.basename(self.path.encode(locale.getpreferredencoding()))[:-4]
data = ProfileHelper(path, name).open_profile() data = ProfileHelper(path, name).open_profile()
if encrypt_save.is_data_encrypted(data):
data = self.enter_pass(data)
settings = Settings(name) settings = Settings(name)
self.tox = tox_factory(data, settings) self.tox = tox_factory(data, settings)
else: else:
@ -72,12 +85,16 @@ class Toxygen(object):
if _login.default: if _login.default:
Settings.set_auto_profile(path, name) Settings.set_auto_profile(path, name)
data = ProfileHelper(path, name).open_profile() data = ProfileHelper(path, name).open_profile()
if encrypt_save.is_data_encrypted(data):
data = self.enter_pass(data)
settings = Settings(name) settings = Settings(name)
self.tox = tox_factory(data, settings) self.tox = tox_factory(data, settings)
else: else:
path, name = auto_profile path, name = auto_profile
path = path.encode(locale.getpreferredencoding()) path = path.encode(locale.getpreferredencoding())
data = ProfileHelper(path, name).open_profile() data = ProfileHelper(path, name).open_profile()
if encrypt_save.is_data_encrypted(data):
data = self.enter_pass(data)
settings = Settings(name) settings = Settings(name)
self.tox = tox_factory(data, settings) self.tox = tox_factory(data, settings)

36
src/passwordscreen.py Normal file
View File

@ -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))

View File

@ -1,6 +1,6 @@
import libtox import libtox
import util 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 = { TOX_ERR_ENCRYPTION = {
@ -48,8 +48,10 @@ class LibToxEncryptSave(util.Singleton):
return bool(self._passphrase) return bool(self._passphrase)
def is_data_encrypted(self, data): def is_data_encrypted(self, data):
result = self.libtoxencryptsave.tox_is_data_encrypted(c_char_p(data)) func = self.libtoxencryptsave.tox_is_data_encrypted
return bool(result) func.restype = c_bool
result = func(c_char_p(data))
return result
def pass_encrypt(self, data): def pass_encrypt(self, data):
""" """