self peer screen added

This commit is contained in:
ingvar1995 2018-07-24 23:40:29 +03:00
parent 27d24ecaf4
commit 850c3b1ca3
4 changed files with 84 additions and 2 deletions

View File

@ -28,7 +28,7 @@ class GroupFactory(ToxSave):
name = alias or self._tox.group_get_name(group_number) or tox_id
status_message = self._tox.group_get_topic(group_number)
message_getter = self._db.messages_getter(tox_id)
is_private = self._tox.group_get_privacy_state() == constants.TOX_GROUP_PRIVACY_STATE['PRIVATE']
is_private = self._tox.group_get_privacy_state(group_number) == constants.TOX_GROUP_PRIVACY_STATE['PRIVATE']
group = GroupChat(self._tox, self._profile_manager, message_getter, group_number, name, status_message,
item, tox_id, is_private)
group.set_alias(alias)

View File

@ -106,7 +106,11 @@ class GroupsService(tox_save.ToxSave):
def peer_selected(self, chat_id, peer_id):
widgets_factory = self._widgets_factory_provider.get_item()
group = self._get_group_by_public_key(chat_id)
self_peer = group.get_self_peer()
if self_peer.id != peer_id:
self._peer_screen = widgets_factory.create_peer_screen_window(group, peer_id)
else:
self._peer_screen = widgets_factory.create_self_peer_screen_window(group)
self._peer_screen.show()
# -----------------------------------------------------------------------------------------------------------------
@ -122,6 +126,13 @@ class GroupsService(tox_save.ToxSave):
self._tox.group_toggle_ignore(group.number, peer.id, ignore)
peer.is_muted = ignore
def set_self_info(self, group, name, status):
self._tox.group_self_set_name(group.number, name)
self._tox.group_self_set_status(group.number, status)
self_peer = group.get_self_peer()
self_peer.name = name
self_peer.status = status
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,67 @@
from ui.widgets import CenteredWidget, LineEdit
from PyQt5 import QtCore, QtWidgets, uic
import utils.util as util
import utils.ui as util_ui
from ui.contact_items import *
class SelfPeerScreen(CenteredWidget):
def __init__(self, contacts_manager, groups_service, group):
super().__init__()
self._contacts_manager = contacts_manager
self._groups_service = groups_service
self._group = group
self._peer = group.get_self_peer()
self._roles = {
TOX_GROUP_ROLE['FOUNDER']: util_ui.tr('Administrator'),
TOX_GROUP_ROLE['MODERATOR']: util_ui.tr('Moderator'),
TOX_GROUP_ROLE['USER']: util_ui.tr('User'),
TOX_GROUP_ROLE['OBSERVER']: util_ui.tr('Observer')
}
uic.loadUi(util.get_views_path('self_peer_screen'), self)
self._update_ui()
def _update_ui(self):
self.lineEdit = LineEdit(self)
self.lineEdit.setGeometry(140, 40, 400, 30)
self.lineEdit.setText(self._peer.name)
self.lineEdit.textChanged.connect(self._nick_changed)
self.savePushButton.clicked.connect(self._save)
self.copyPublicKeyPushButton.clicked.connect(self._copy_public_key)
self._retranslate_ui()
self.statusComboBox.setCurrentIndex(self._peer.status)
def _retranslate_ui(self):
self.setWindowTitle(util_ui.tr('Change credentials in group'))
self.lineEdit.setPlaceholderText(util_ui.tr('Your nickname in group'))
self.nameLabel.setText(util_ui.tr('Name:'))
self.roleLabel.setText(util_ui.tr('Role:'))
self.statusLabel.setText(util_ui.tr('Status:'))
self.copyPublicKeyPushButton.setText(util_ui.tr('Copy public key'))
self.savePushButton.setText(util_ui.tr('Save'))
self.roleNameLabel.setText(self._get_role_name())
self.statusComboBox.addItem(util_ui.tr('Online'))
self.statusComboBox.addItem(util_ui.tr('Away'))
self.statusComboBox.addItem(util_ui.tr('Busy'))
def _get_role_name(self):
return self._roles[self._peer.role]
def _nick_changed(self):
nick = self.lineEdit.text()
self.savePushButton.setEnabled(bool(nick))
def _save(self):
nick = self.lineEdit.text()
status = self.statusComboBox.currentIndex()
self._groups_service.set_self_info(self._group, nick, status)
self.close()
def _copy_public_key(self):
clipboard = QtWidgets.QApplication.clipboard()
clipboard.setText(self._peer.public_key)

View File

@ -2,6 +2,7 @@ from ui.main_screen_widgets import *
from ui.menu import *
from ui.groups_widgets import *
from ui.peer_screen import *
from ui.self_peer_screen import *
class WidgetsFactory:
@ -73,3 +74,6 @@ class WidgetsFactory:
def create_peer_screen_window(self, group, peer_id):
return PeerScreen(self._contacts_manager, self._groups_service, group, peer_id)
def create_self_peer_screen_window(self, group):
return SelfPeerScreen(self._contacts_manager, self._groups_service, group)