Login screen converted, create profile screen fixed

This commit is contained in:
ingvar1995 2018-05-24 21:22:12 +03:00
parent c97fb6b467
commit 486c13a3d3
7 changed files with 261 additions and 116 deletions

View file

@ -31,6 +31,7 @@ from network.tox_dns import ToxDns
from history.history import History
from file_transfers.file_transfers_messages_service import FileTransfersMessagesService
from groups.groups_service import GroupsService
from ui.create_profile_screen import CreateProfileScreen
import styles.style # TODO: dynamic loading
@ -165,7 +166,8 @@ class App:
if result is None:
return False
if result.is_new_profile(): # create new profile
self._create_new_profile(result.profile_path)
if not self._create_new_profile(result.profile_path):
return False
else: # load existing profile
self._load_existing_profile(result.profile_path)
self._path = result.profile_path
@ -233,16 +235,25 @@ class App:
data = self._enter_pass(data)
self._tox = self._create_tox(data)
def _create_new_profile(self, profile_path):
name = util.get_profile_name_from_path(profile_path) or 'toxygen_user'
def _create_new_profile(self, profile_name):
result = self._get_create_profile_screen_result()
if result is None:
return False
if result.save_into_default_folder:
profile_path = util.join_path(Settings.get_default_path(), profile_name + '.tox')
else:
profile_path = util.join_path(util.curr_directory(__file__), profile_name + '.tox')
if os.path.isfile(profile_path):
util_ui.message_box(util_ui.tr('Profile with this name already exists'),
util_ui.tr('Error'))
return
return False
name = profile_name or 'toxygen_user'
self._tox = tox_factory()
self._tox.self_set_name(bytes(name, 'utf-8') if name else b'Toxygen User')
self._tox.self_set_status_message(b'Toxing on Toxygen')
# TODO: set profile password
self._path = profile_path
if result.password:
self._toxes.set_password(result.password)
self._settings = Settings(self._toxes, self._path.replace('.tox', '.json'))
self._profile_manager = ProfileManager(self._settings, self._toxes, profile_path)
try:
@ -252,12 +263,22 @@ class App:
util.log('Profile creation exception: ' + str(ex))
text = util_ui.tr('Profile saving error! Does Toxygen have permission to write to this directory?')
util_ui.message_box(text, util_ui.tr('Error'))
return
return False
current_language, supported_languages = self._get_languages()
if current_language in supported_languages:
self._settings['language'] = current_language
self._settings.save()
return True
def _get_create_profile_screen_result(self):
cps = CreateProfileScreen()
cps.show()
self._app.exec_()
return cps.result
def _save_profile(self, data=None):
data = data or self._tox.get_savedata()
self._profile_manager.save_profile(data)

View file

@ -29,15 +29,24 @@ class CreateProfileScreen(CenteredWidget, DialogWithResult):
uic.loadUi(util.get_views_path('create_profile_screen'), self)
self.center()
self.createProfile.clicked.connect(self._create_profile)
self.retranslateUi()
def retranslateUi(self):
self.defaultFolder.setPlaceholderText(util_ui.tr('Save in default folder'))
self.programFolder.setPlaceholderText(util_ui.tr('Save in program folder'))
self.setWindowTitle(util_ui.tr('New profile settings'))
self.defaultFolder.setText(util_ui.tr('Save in default folder'))
self.programFolder.setText(util_ui.tr('Save in program folder'))
self.password.setPlaceholderText(util_ui.tr('Password'))
self.confirmPassword.setPlaceholderText(util_ui.tr('Confirm password'))
self.createProfile.setText(util_ui.tr('Create profile'))
self.passwordLabel.setText(util_ui.tr('Password:'))
self.passwordLabel.setText(util_ui.tr('Password (at least 8 symbols):'))
def _create_profile(self):
if self.password.text() != self.confirmPassword.text():
return # TODO : error
result = CreateProfileScreenResult(self.defaultFolder.isChecked(), self.password.text())
password = self.password.text()
if password != self.confirmPassword.text():
self.errorLabel.setText(util_ui.tr('Passwords do not match'))
return
if 0 < len(password) < 8:
self.errorLabel.setText(util_ui.tr('Password must be at least 8 symbols'))
return
result = CreateProfileScreenResult(self.defaultFolder.isChecked(), password)
self.close_with_result(result)

View file

@ -1,20 +1,10 @@
from ui.widgets import *
from PyQt5 import uic
import utils.util as util
import utils.ui as util_ui
import os.path
class NickEdit(LineEdit):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Return:
self.parent.create_profile()
else:
super(NickEdit, self).keyPressEvent(event)
class LoginScreenResult:
def __init__(self, profile_path, load_as_default, password=None):
@ -46,75 +36,42 @@ class LoginScreen(CenteredWidget, DialogWithResult):
def __init__(self):
CenteredWidget.__init__(self)
DialogWithResult.__init__(self)
self.initUI()
uic.loadUi(util.get_views_path('login_screen'), self)
self.center()
self._profiles = []
def initUI(self):
self.resize(400, 200)
self.setMinimumSize(QtCore.QSize(400, 200))
self.setMaximumSize(QtCore.QSize(400, 200))
self.new_profile = QtWidgets.QPushButton(self)
self.new_profile.setGeometry(QtCore.QRect(20, 150, 171, 27))
self.new_profile.clicked.connect(self.create_profile)
self.label = QtWidgets.QLabel(self)
self.label.setGeometry(QtCore.QRect(20, 70, 101, 17))
self.new_name = NickEdit(self)
self.new_name.setGeometry(QtCore.QRect(20, 100, 171, 31))
self.load_profile = QtWidgets.QPushButton(self)
self.load_profile.setGeometry(QtCore.QRect(220, 150, 161, 27))
self.load_profile.clicked.connect(self.load_existing_profile)
self.default = QtWidgets.QCheckBox(self)
self.default.setGeometry(QtCore.QRect(220, 110, 131, 22))
self.groupBox = QtWidgets.QGroupBox(self)
self.groupBox.setGeometry(QtCore.QRect(210, 40, 181, 151))
self.comboBox = QtWidgets.QComboBox(self.groupBox)
self.comboBox.setGeometry(QtCore.QRect(10, 30, 161, 27))
self.groupBox_2 = QtWidgets.QGroupBox(self)
self.groupBox_2.setGeometry(QtCore.QRect(10, 40, 191, 151))
self.toxygen = QtWidgets.QLabel(self)
self.toxygen.setGeometry(QtCore.QRect(160, 8, 90, 25))
self.groupBox.raise_()
self.groupBox_2.raise_()
self.comboBox.raise_()
self.default.raise_()
self.load_profile.raise_()
self.new_name.raise_()
self.new_profile.raise_()
font = QtGui.QFont()
font.setFamily("Impact")
font.setPointSize(16)
self.toxygen.setFont(font)
self.toxygen.setObjectName("toxygen")
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
self._update_ui()
def retranslateUi(self):
self.new_name.setPlaceholderText(QtWidgets.QApplication.translate("login", "Profile name"))
self.setWindowTitle(QtWidgets.QApplication.translate("login", "Log in"))
self.new_profile.setText(QtWidgets.QApplication.translate("login", "Create"))
self.label.setText(QtWidgets.QApplication.translate("login", "Profile name:"))
self.load_profile.setText(QtWidgets.QApplication.translate("login", "Load profile"))
self.default.setText(QtWidgets.QApplication.translate("login", "Use as default"))
self.groupBox.setTitle(QtWidgets.QApplication.translate("login", "Load existing profile"))
self.groupBox_2.setTitle(QtWidgets.QApplication.translate("login", "Create new profile"))
self.toxygen.setText(QtWidgets.QApplication.translate("login", "toxygen"))
def create_profile(self):
self.type = 1
self.name = self.new_name.text()
self.close()
def load_existing_profile(self):
index = self.comboBox.currentIndex()
load_as_default = self.default.isChecked()
path = os.path.join(self._profiles[index][0], self._profiles[index][1] + '.tox')
result = LoginScreenResult(path, load_as_default)
self.close_with_result(result)
self.setWindowTitle(util_ui.tr('Log in'))
self.profileNameLineEdit.setPlaceholderText(util_ui.tr('Profile name'))
self.createProfilePushButton.setText(util_ui.tr('Create'))
self.loadProfilePushButton.setText(util_ui.tr('Load profile'))
self.defaultProfileCheckBox.setText(util_ui.tr('Use as default'))
self.existingProfileGroupBox.setTitle(util_ui.tr('Load existing profile'))
self.newProfileGroupBox.setTitle(util_ui.tr('Create new profile'))
def update_select(self, profiles):
profiles = sorted(profiles, key=lambda p: p[1])
self._profiles = list(profiles)
self.comboBox.addItems(list(map(lambda p: p[1], profiles)))
self.load_profile.setEnabled(len(profiles) > 0)
self.profilesComboBox.addItems(list(map(lambda p: p[1], profiles)))
self.loadProfilePushButton.setEnabled(len(profiles) > 0)
def _update_ui(self):
self.profileNameLineEdit = LineEditWithEnterSupport(self._create_profile, self)
self.profileNameLineEdit.setGeometry(QtCore.QRect(20, 100, 170, 30))
self.retranslateUi()
self.createProfilePushButton.clicked.connect(self._create_profile)
self.loadProfilePushButton.clicked.connect(self._load_existing_profile)
def _create_profile(self):
path = self.profileNameLineEdit.text()
load_as_default = self.defaultProfileCheckBox.isChecked()
result = LoginScreenResult(path, load_as_default)
self.close_with_result(result)
def _load_existing_profile(self):
index = self.profilesComboBox.currentIndex()
load_as_default = self.defaultProfileCheckBox.isChecked()
path = util.join_path(self._profiles[index][0], self._profiles[index][1] + '.tox')
result = LoginScreenResult(path, load_as_default)
self.close_with_result(result)

View file

@ -1,19 +1,20 @@
from ui.widgets import CenteredWidget, LineEdit, DialogWithResult
from PyQt5 import QtCore, QtWidgets
import utils.ui as util_ui
class PasswordArea(LineEdit):
def __init__(self, parent):
super(PasswordArea, self).__init__(parent)
self.parent = parent
super().__init__(parent)
self._parent = parent
self.setEchoMode(QtWidgets.QLineEdit.Password)
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Return:
self.parent.button_click()
self._parent.button_click()
else:
super(PasswordArea, self).keyPressEvent(event)
super().keyPressEvent(event)
class PasswordScreenBase(CenteredWidget, DialogWithResult):
@ -37,7 +38,7 @@ class PasswordScreenBase(CenteredWidget, DialogWithResult):
self.button = QtWidgets.QPushButton(self)
self.button.setGeometry(QtCore.QRect(30, 90, 300, 30))
self.button.setText('OK')
self.button.setText(util_ui.tr('OK'))
self.button.clicked.connect(self.button_click)
self.warning = QtWidgets.QLabel(self)
@ -59,15 +60,15 @@ class PasswordScreenBase(CenteredWidget, DialogWithResult):
super(PasswordScreenBase, self).keyPressEvent(event)
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("pass", "Enter password"))
self.enter_pass.setText(QtWidgets.QApplication.translate("pass", "Password:"))
self.warning.setText(QtWidgets.QApplication.translate("pass", "Incorrect password"))
self.setWindowTitle(util_ui.tr('Enter password'))
self.enter_pass.setText(util_ui.tr('Password:'))
self.warning.setText(util_ui.tr('Incorrect password'))
class PasswordScreen(PasswordScreenBase):
def __init__(self, encrypt, data):
super(PasswordScreen, self).__init__(encrypt)
super().__init__(encrypt)
self._data = data
def button_click(self):
@ -129,16 +130,15 @@ class SetProfilePasswordScreen(CenteredWidget):
self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("PasswordScreen", "Profile password"))
self.setWindowTitle(util_ui.tr('Profile password'))
self.password.setPlaceholderText(
QtWidgets.QApplication.translate("PasswordScreen", "Password (at least 8 symbols)"))
util_ui.tr('Password (at least 8 symbols)'))
self.confirm_password.setPlaceholderText(
QtWidgets.QApplication.translate("PasswordScreen", "Confirm password"))
util_ui.tr('Confirm password'))
self.set_password.setText(
QtWidgets.QApplication.translate("PasswordScreen", "Set password"))
self.not_match.setText(QtWidgets.QApplication.translate("PasswordScreen", "Passwords do not match"))
self.warning.setText(
QtWidgets.QApplication.translate("PasswordScreen", "There is no way to recover lost passwords"))
util_ui.tr('Set password'))
self.not_match.setText(util_ui.tr('Passwords do not match'))
self.warning.setText(util_ui.tr('There is no way to recover lost passwords'))
def new_password(self):
if self.password.text() == self.confirm_password.text():
@ -146,9 +146,8 @@ class SetProfilePasswordScreen(CenteredWidget):
self._encrypt.set_password(self.password.text())
self.close()
else:
self.not_match.setText(
QtWidgets.QApplication.translate("PasswordScreen", "Password must be at least 8 symbols"))
self.not_match.setText(util_ui.tr('Password must be at least 8 symbols'))
self.not_match.setVisible(True)
else:
self.not_match.setText(QtWidgets.QApplication.translate("PasswordScreen", "Passwords do not match"))
self.not_match.setText(util_ui.tr('Passwords do not match'))
self.not_match.setVisible(True)

View file

@ -7,19 +7,19 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>380</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>300</height>
<height>380</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>300</height>
<height>380</height>
</size>
</property>
<property name="windowTitle">
@ -29,7 +29,7 @@
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<y>290</y>
<width>341</width>
<height>51</height>
</rect>
@ -47,6 +47,9 @@
<height>41</height>
</rect>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
<widget class="QLineEdit" name="password">
<property name="geometry">
@ -57,14 +60,17 @@
<height>41</height>
</rect>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
<widget class="QLabel" name="passwordLabel">
<property name="geometry">
<rect>
<x>30</x>
<y>100</y>
<width>67</width>
<height>17</height>
<width>330</width>
<height>20</height>
</rect>
</property>
<property name="text">
@ -76,7 +82,7 @@
<rect>
<x>30</x>
<y>10</y>
<width>112</width>
<width>330</width>
<height>23</height>
</rect>
</property>
@ -92,7 +98,7 @@
<rect>
<x>30</x>
<y>50</y>
<width>112</width>
<width>330</width>
<height>23</height>
</rect>
</property>
@ -100,6 +106,22 @@
<string>RadioButton</string>
</property>
</widget>
<widget class="QLabel" name="errorLabel">
<property name="geometry">
<rect>
<x>30</x>
<y>250</y>
<width>341</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
<resources/>
<connections/>

View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>loginScreen</class>
<widget class="QWidget" name="loginScreen">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="toxygenLabel">
<property name="geometry">
<rect>
<x>0</x>
<y>5</y>
<width>401</width>
<height>30</height>
</rect>
</property>
<property name="font">
<font>
<family>Garuda</family>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Toxygen</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QGroupBox" name="newProfileGroupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>180</width>
<height>150</height>
</rect>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QPushButton" name="createProfilePushButton">
<property name="geometry">
<rect>
<x>20</x>
<y>110</y>
<width>150</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="existingProfileGroupBox">
<property name="geometry">
<rect>
<x>210</x>
<y>40</y>
<width>180</width>
<height>150</height>
</rect>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QComboBox" name="profilesComboBox">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>160</width>
<height>27</height>
</rect>
</property>
</widget>
<widget class="QCheckBox" name="defaultProfileCheckBox">
<property name="geometry">
<rect>
<x>10</x>
<y>75</y>
<width>160</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>CheckBox</string>
</property>
</widget>
<widget class="QPushButton" name="loadProfilePushButton">
<property name="geometry">
<rect>
<x>20</x>
<y>110</y>
<width>150</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -52,7 +52,7 @@ class DialogWithResult(QtWidgets.QWidget):
class LineEdit(QtWidgets.QLineEdit):
def __init__(self, parent=None):
super(LineEdit, self).__init__(parent)
super().__init__(parent)
def contextMenuEvent(self, event):
menu = create_menu(self.createStandardContextMenu())
@ -181,3 +181,16 @@ class MultilineEdit(CenteredWidget):
def button_click(self):
self.save(self.edit.toPlainText())
self.close()
class LineEditWithEnterSupport(LineEdit):
def __init__(self, enter_action, parent=None):
super().__init__(parent)
self._action = enter_action
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Return:
self._action()
else:
super().keyPressEvent(event)