profile lock

This commit is contained in:
ingvar1995 2016-07-02 15:40:06 +03:00
parent 18935c5b10
commit a6f47c6248
6 changed files with 81 additions and 25 deletions

View file

@ -62,7 +62,7 @@ def friend_status(tox, friend_num, new_status, user_data):
""" """
Check friend's status (none, busy, away) Check friend's status (none, busy, away)
""" """
print("Friend's #{} status changed! New status: {}".format(friend_num, new_status)) print("Friend's #{} status changed!".format(friend_num))
profile = Profile.get_instance() profile = Profile.get_instance()
friend = profile.get_friend_by_number(friend_num) friend = profile.get_friend_by_number(friend_num)
if friend.status is None and Settings.get_instance()['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']: if friend.status is None and Settings.get_instance()['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
@ -94,7 +94,7 @@ def friend_name(tox, friend_num, name, size, user_data):
Friend changed his name Friend changed his name
""" """
profile = Profile.get_instance() profile = Profile.get_instance()
print('New name: ', friend_num, name) print('New name friend #' + str(friend_num))
invoke_in_main_thread(profile.new_name, friend_num, name) invoke_in_main_thread(profile.new_name, friend_num, name)
@ -106,7 +106,7 @@ def friend_status_message(tox, friend_num, status_message, size, user_data):
profile = Profile.get_instance() profile = Profile.get_instance()
friend = profile.get_friend_by_number(friend_num) friend = profile.get_friend_by_number(friend_num)
invoke_in_main_thread(friend.set_status_message, status_message) invoke_in_main_thread(friend.set_status_message, status_message)
print('User #{} has new status: {}'.format(friend_num, status_message)) print('User #{} has new status'.format(friend_num))
invoke_in_main_thread(profile.send_messages, friend_num) invoke_in_main_thread(profile.send_messages, friend_num)
if profile.get_active_number() == friend_num: if profile.get_active_number() == friend_num:
invoke_in_main_thread(profile.set_active) invoke_in_main_thread(profile.set_active)
@ -123,7 +123,7 @@ def friend_message(window, tray):
invoke_in_main_thread(profile.new_message, friend_number, message_type, message) invoke_in_main_thread(profile.new_message, friend_number, message_type, message)
if not window.isActiveWindow(): if not window.isActiveWindow():
friend = profile.get_friend_by_number(friend_number) friend = profile.get_friend_by_number(friend_number)
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY']: if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
invoke_in_main_thread(tray_notification, friend.name, message, tray, window) invoke_in_main_thread(tray_notification, friend.name, message, tray, window)
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']: if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
sound_notification(SOUND_NOTIFICATION['MESSAGE']) sound_notification(SOUND_NOTIFICATION['MESSAGE'])
@ -178,14 +178,14 @@ def tox_file_recv(window, tray):
file_name) file_name)
if not window.isActiveWindow(): if not window.isActiveWindow():
friend = profile.get_friend_by_number(friend_number) friend = profile.get_friend_by_number(friend_number)
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY']: if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
file_from = QtGui.QApplication.translate("Callback", "File from", None, QtGui.QApplication.UnicodeUTF8) file_from = QtGui.QApplication.translate("Callback", "File from", None, QtGui.QApplication.UnicodeUTF8)
invoke_in_main_thread(tray_notification, file_from + ' ' + friend.name, file_name, tray, window) invoke_in_main_thread(tray_notification, file_from + ' ' + friend.name, file_name, tray, window)
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']: if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER']) sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(curr_directory() + '/images/icon_new_messages.png')) invoke_in_main_thread(tray.setIcon, QtGui.QIcon(curr_directory() + '/images/icon_new_messages.png'))
else: # AVATAR else: # AVATAR
print ('Avatar') print('Avatar')
invoke_in_main_thread(profile.incoming_avatar, invoke_in_main_thread(profile.incoming_avatar,
friend_number, friend_number,
file_number, file_number,

View file

@ -12,7 +12,7 @@ from callbacks import init_callbacks
from util import curr_directory from util import curr_directory
import styles.style import styles.style
import toxencryptsave import toxencryptsave
from passwordscreen import PasswordScreen from passwordscreen import PasswordScreen, UnlockAppScreen
import profile import profile
from plugin_support import PluginLoader from plugin_support import PluginLoader
@ -151,7 +151,7 @@ class Toxygen:
def aboutToShow(self): def aboutToShow(self):
status = profile.Profile.get_instance().status status = profile.Profile.get_instance().status
act = self.act act = self.act
if status is None: if status is None or Settings.get_instance().locked:
self.actions()[1].setVisible(False) self.actions()[1].setVisible(False)
else: else:
self.actions()[1].setVisible(True) self.actions()[1].setVisible(True)
@ -159,6 +159,7 @@ class Toxygen:
act.actions()[1].setChecked(False) act.actions()[1].setChecked(False)
act.actions()[2].setChecked(False) act.actions()[2].setChecked(False)
act.actions()[status].setChecked(True) act.actions()[status].setChecked(True)
self.actions()[2].setVisible(not Settings.get_instance().locked)
def languageChange(self, *args, **kwargs): def languageChange(self, *args, **kwargs):
self.actions()[0].setText(QtGui.QApplication.translate('tray', 'Open Toxygen', None, QtGui.QApplication.UnicodeUTF8)) self.actions()[0].setText(QtGui.QApplication.translate('tray', 'Open Toxygen', None, QtGui.QApplication.UnicodeUTF8))
@ -181,10 +182,19 @@ class Toxygen:
exit = m.addAction(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8)) exit = m.addAction(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8))
def show_window(): def show_window():
if not self.ms.isActiveWindow(): def show():
self.ms.setWindowState(self.ms.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) if not self.ms.isActiveWindow():
self.ms.activateWindow() self.ms.setWindowState(self.ms.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
self.ms.show() self.ms.activateWindow()
self.ms.show()
if not Settings.get_instance().locked:
show()
else:
def correct_pass():
show()
Settings.get_instance().locked = False
self.p = UnlockAppScreen(toxencryptsave.ToxEncryptSave.get_instance(), correct_pass)
self.p.show()
m.connect(show, QtCore.SIGNAL("triggered()"), show_window) m.connect(show, QtCore.SIGNAL("triggered()"), show_window)
m.connect(exit, QtCore.SIGNAL("triggered()"), lambda: app.exit()) m.connect(exit, QtCore.SIGNAL("triggered()"), lambda: app.exit())

View file

@ -52,8 +52,10 @@ class MainWindow(QtGui.QMainWindow):
self.actionSettings.setObjectName("actionSettings") self.actionSettings.setObjectName("actionSettings")
self.audioSettings = QtGui.QAction(MainWindow) self.audioSettings = QtGui.QAction(MainWindow)
self.pluginData = QtGui.QAction(MainWindow) self.pluginData = QtGui.QAction(MainWindow)
self.lockApp = QtGui.QAction(MainWindow)
self.menuProfile.addAction(self.actionAdd_friend) self.menuProfile.addAction(self.actionAdd_friend)
self.menuProfile.addAction(self.actionSettings) self.menuProfile.addAction(self.actionSettings)
self.menuProfile.addAction(self.lockApp)
self.menuSettings.addAction(self.actionPrivacy_settings) self.menuSettings.addAction(self.actionPrivacy_settings)
self.menuSettings.addAction(self.actionInterface_settings) self.menuSettings.addAction(self.actionInterface_settings)
self.menuSettings.addAction(self.actionNotifications) self.menuSettings.addAction(self.actionNotifications)
@ -75,6 +77,7 @@ class MainWindow(QtGui.QMainWindow):
self.actionNotifications.triggered.connect(self.notification_settings) self.actionNotifications.triggered.connect(self.notification_settings)
self.audioSettings.triggered.connect(self.audio_settings) self.audioSettings.triggered.connect(self.audio_settings)
self.pluginData.triggered.connect(self.plugins_menu) self.pluginData.triggered.connect(self.plugins_menu)
self.lockApp.triggered.connect(self.lock_app)
QtCore.QMetaObject.connectSlotsByName(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def languageChange(self, *args, **kwargs): def languageChange(self, *args, **kwargs):
@ -86,6 +89,7 @@ class MainWindow(QtGui.QMainWindow):
return super(MainWindow, self).event(event) return super(MainWindow, self).event(event)
def retranslateUi(self): def retranslateUi(self):
self.lockApp.setText(QtGui.QApplication.translate("MainWindow", "Lock", None, QtGui.QApplication.UnicodeUTF8))
self.menuPlugins.setTitle(QtGui.QApplication.translate("MainWindow", "Plugins", None, QtGui.QApplication.UnicodeUTF8)) self.menuPlugins.setTitle(QtGui.QApplication.translate("MainWindow", "Plugins", None, QtGui.QApplication.UnicodeUTF8))
self.pluginData.setText(QtGui.QApplication.translate("MainWindow", "List of plugins", None, QtGui.QApplication.UnicodeUTF8)) self.pluginData.setText(QtGui.QApplication.translate("MainWindow", "List of plugins", None, QtGui.QApplication.UnicodeUTF8))
self.menuProfile.setTitle(QtGui.QApplication.translate("MainWindow", "Profile", None, QtGui.QApplication.UnicodeUTF8)) self.menuProfile.setTitle(QtGui.QApplication.translate("MainWindow", "Profile", None, QtGui.QApplication.UnicodeUTF8))
@ -387,6 +391,19 @@ class MainWindow(QtGui.QMainWindow):
self.audio_s = AudioSettings() self.audio_s = AudioSettings()
self.audio_s.show() self.audio_s.show()
def lock_app(self):
if toxencryptsave.ToxEncryptSave.get_instance().has_password():
Settings.get_instance().locked = True
self.hide()
else:
msgBox = QtGui.QMessageBox()
msgBox.setWindowTitle(
QtGui.QApplication.translate("MainWindow", "Cannot lock app", None, QtGui.QApplication.UnicodeUTF8))
msgBox.setText(
QtGui.QApplication.translate("MainWindow", 'Error. Profile password is not set.', None,
QtGui.QApplication.UnicodeUTF8))
msgBox.exec_()
def show_menu(self): def show_menu(self):
if not hasattr(self, 'menu'): if not hasattr(self, 'menu'):
self.menu = DropdownMenu(self) self.menu = DropdownMenu(self)

View file

@ -19,12 +19,11 @@ class PasswordArea(LineEdit):
super(PasswordArea, self).keyPressEvent(event) super(PasswordArea, self).keyPressEvent(event)
class PasswordScreen(CenteredWidget): class PasswordScreenBase(CenteredWidget):
def __init__(self, encrypt, data): def __init__(self, encrypt):
super(PasswordScreen, self).__init__() super(PasswordScreenBase, self).__init__()
self._encrypt = encrypt self._encrypt = encrypt
self._data = data
self.initUI() self.initUI()
def initUI(self): def initUI(self):
@ -52,6 +51,27 @@ class PasswordScreen(CenteredWidget):
self.center() self.center()
QtCore.QMetaObject.connectSlotsByName(self) QtCore.QMetaObject.connectSlotsByName(self)
def button_click(self):
pass
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Enter:
self.button_click()
else:
super(PasswordScreenBase, self).keyPressEvent(event)
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))
self.warning.setText(QtGui.QApplication.translate("pass", "Incorrect password", None, QtGui.QApplication.UnicodeUTF8))
class PasswordScreen(PasswordScreenBase):
def __init__(self, encrypt, data):
super(PasswordScreen, self).__init__(encrypt)
self._data = data
def button_click(self): def button_click(self):
if self.password.text(): if self.password.text():
try: try:
@ -64,14 +84,19 @@ class PasswordScreen(CenteredWidget):
self._data[0] = new_data self._data[0] = new_data
self.close() self.close()
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Enter:
self.button_click()
else:
super(PasswordScreen, self).keyPressEvent(event)
def retranslateUi(self): class UnlockAppScreen(PasswordScreenBase):
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))
self.warning.setText(QtGui.QApplication.translate("pass", "Incorrect password", None, QtGui.QApplication.UnicodeUTF8))
def __init__(self, encrypt, callback):
super(UnlockAppScreen, self).__init__(encrypt)
self._callback = callback
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
def button_click(self):
if self.password.text():
if self._encrypt.is_password(self.password.text()):
self._callback()
self.close()
else:
self.warning.setVisible(True)
print('Wrong password!')

View file

@ -35,6 +35,7 @@ class Settings(dict, Singleton):
self.save() self.save()
smileys.SmileyLoader(self) smileys.SmileyLoader(self)
p = pyaudio.PyAudio() p = pyaudio.PyAudio()
self.locked = False
self.audio = {'input': p.get_default_input_device_info()['index'], self.audio = {'input': p.get_default_input_device_info()['index'],
'output': p.get_default_output_device_info()['index']} 'output': p.get_default_output_device_info()['index']}

View file

@ -48,6 +48,9 @@ class ToxEncryptSave(util.Singleton):
def has_password(self): def has_password(self):
return bool(self._passphrase) return bool(self._passphrase)
def is_password(self, password):
return self._passphrase == password
def is_data_encrypted(self, data): def is_data_encrypted(self, data):
func = self.libtoxencryptsave.tox_is_data_encrypted func = self.libtoxencryptsave.tox_is_data_encrypted
func.restype = c_bool func.restype = c_bool