From 0ee8a0ec21ae09a5cd3e6c25dcdc009449a26fa9 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 22 Aug 2018 12:08:00 +0300 Subject: [PATCH] gc settings screen added --- toxygen/bootstrap/nodes.json | 2 +- toxygen/contacts/contact_menu.py | 3 + toxygen/groups/groups_service.py | 5 ++ ...nt_screen.py => group_settings_widgets.py} | 35 +++++++- toxygen/ui/main_screen.py | 3 +- toxygen/ui/peer_screen.py | 3 +- toxygen/ui/self_peer_screen.py | 5 +- toxygen/ui/views/gc_settings_screen.ui | 83 +++++++++++++++++++ toxygen/ui/widgets_factory.py | 6 +- toxygen/utils/ui.py | 5 ++ 10 files changed, 139 insertions(+), 11 deletions(-) rename toxygen/ui/{group_management_screen.py => group_settings_widgets.py} (55%) create mode 100644 toxygen/ui/views/gc_settings_screen.ui diff --git a/toxygen/bootstrap/nodes.json b/toxygen/bootstrap/nodes.json index 382e000..4f4f011 100644 --- a/toxygen/bootstrap/nodes.json +++ b/toxygen/bootstrap/nodes.json @@ -1 +1 @@ -{"nodes":[{"ipv4":"80.211.19.83","ipv6":"-","port":33445,"public_key":"C78997BEA65096B09EAD41F850116D798A0D4A14D2D8652FCD2495ADDE006523","status_udp":true,"status_tcp":true}]} \ No newline at end of file +{"nodes":[{"ipv4":"80.211.19.83","ipv6":"-","port":33445,"public_key":"A05AFD9C7B785ADBB93DCD55FC8992177A2BA50413AAD7AD8D3442EE5E7ADA21","status_udp":true,"status_tcp":true}]} \ No newline at end of file diff --git a/toxygen/contacts/contact_menu.py b/toxygen/contacts/contact_menu.py index 7330b35..da1cddb 100644 --- a/toxygen/contacts/contact_menu.py +++ b/toxygen/contacts/contact_menu.py @@ -184,6 +184,9 @@ class GroupMenuGenerator(BaseContactMenuGenerator): .with_optional_action(util_ui.tr('Manage group'), lambda: groups_service.show_group_management_screen(self._contact), self._contact.is_self_founder()) + .with_optional_action(util_ui.tr('Group settings'), + lambda: groups_service.show_group_settings_screen(self._contact), + not self._contact.is_self_founder()) .with_optional_action(util_ui.tr('Set topic'), lambda: groups_service.set_group_topic(self._contact), self._contact.is_self_moderator_or_founder()) diff --git a/toxygen/groups/groups_service.py b/toxygen/groups/groups_service.py index 941ee1b..058e7ea 100644 --- a/toxygen/groups/groups_service.py +++ b/toxygen/groups/groups_service.py @@ -118,6 +118,11 @@ class GroupsService(tox_save.ToxSave): self._screen = widgets_factory.create_group_management_screen(group) self._screen.show() + def show_group_settings_screen(self, group): + widgets_factory = self._get_widgets_factory() + self._screen = widgets_factory.create_group_settings_screen(group) + self._screen.show() + def set_group_password(self, group, password): if group.password == password: return diff --git a/toxygen/ui/group_management_screen.py b/toxygen/ui/group_settings_widgets.py similarity index 55% rename from toxygen/ui/group_management_screen.py rename to toxygen/ui/group_settings_widgets.py index bbc2629..c32168b 100644 --- a/toxygen/ui/group_management_screen.py +++ b/toxygen/ui/group_settings_widgets.py @@ -25,9 +25,9 @@ class GroupManagementScreen(CenteredWidget): def _retranslate_ui(self): self.setWindowTitle(util_ui.tr('Group "{}"').format(self._group.name)) - self.passwordLabel.setText(util_ui.tr('Password')) + self.passwordLabel.setText(util_ui.tr('Password:')) self.peerLimitLabel.setText(util_ui.tr('Peer limit:')) - self.privacyStateLabel.setText(util_ui.tr('Privacy state')) + self.privacyStateLabel.setText(util_ui.tr('Privacy state:')) self.savePushButton.setText(util_ui.tr('Save')) self.privacyStateComboBox.clear() @@ -44,3 +44,34 @@ class GroupManagementScreen(CenteredWidget): self._groups_service.set_group_peers_limit(self._group, peers_limit) self.close() + + +class GroupSettingsScreen(CenteredWidget): + + def __init__(self, group): + super().__init__() + self._group = group + + uic.loadUi(util.get_views_path('gc_settings_screen'), self) + self._update_ui() + + def _update_ui(self): + self._retranslate_ui() + + self.copyPasswordPushButton.clicked.connect(self._copy_password) + self.copyPasswordPushButton.setEnabled(bool(self._group.password)) + + def _retranslate_ui(self): + self.setWindowTitle(util_ui.tr('Group "{}"').format(self._group.name)) + if self._group.password: + password_label_text = '{} {}'.format(util_ui.tr('Password:'), self._group.password) + else: + password_label_text = util_ui.tr('Password is not set') + self.passwordLabel.setText(password_label_text) + self.peerLimitLabel.setText('{} {}'.format(util_ui.tr('Peer limit:'), self._group.peers_limit)) + privacy_state = util_ui.tr('Private') if self._group.is_private else util_ui.tr('Public') + self.privacyStateLabel.setText('{} {}'.format(util_ui.tr('Privacy state:'), privacy_state)) + self.copyPasswordPushButton.setText(util_ui.tr('Copy password')) + + def _copy_password(self): + util_ui.copy_to_clipboard(self._group.password) diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index 3df3162..afb3ef9 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -650,8 +650,7 @@ class MainWindow(QtWidgets.QMainWindow): @staticmethod def copy_text(text): - clipboard = QtWidgets.QApplication.clipboard() - clipboard.setText(text) + util_ui.copy_to_clipboard(text) def clear_history(self, num): self._history_loader.clear_history(num) diff --git a/toxygen/ui/peer_screen.py b/toxygen/ui/peer_screen.py index acc93ee..f366aad 100644 --- a/toxygen/ui/peer_screen.py +++ b/toxygen/ui/peer_screen.py @@ -92,8 +92,7 @@ class PeerScreen(CenteredWidget): self.close() def _copy_public_key(self): - clipboard = QtWidgets.QApplication.clipboard() - clipboard.setText(self._peer.public_key) + util_ui.copy_to_clipboard(self._peer.public_key) def _ban_peer(self): ban_type = self._get_ban_type() diff --git a/toxygen/ui/self_peer_screen.py b/toxygen/ui/self_peer_screen.py index ebc1426..cf252d3 100644 --- a/toxygen/ui/self_peer_screen.py +++ b/toxygen/ui/self_peer_screen.py @@ -1,5 +1,5 @@ from ui.widgets import CenteredWidget, LineEdit -from PyQt5 import QtCore, QtWidgets, uic +from PyQt5 import uic import utils.util as util import utils.ui as util_ui from ui.contact_items import * @@ -63,5 +63,4 @@ class SelfPeerScreen(CenteredWidget): self.close() def _copy_public_key(self): - clipboard = QtWidgets.QApplication.clipboard() - clipboard.setText(self._peer.public_key) + util_ui.copy_to_clipboard(self._peer.public_key) diff --git a/toxygen/ui/views/gc_settings_screen.ui b/toxygen/ui/views/gc_settings_screen.ui new file mode 100644 index 0000000..526c156 --- /dev/null +++ b/toxygen/ui/views/gc_settings_screen.ui @@ -0,0 +1,83 @@ + + + Form + + + + 0 + 0 + 400 + 220 + + + + + 400 + 220 + + + + + 400 + 220 + + + + Form + + + + + 10 + 20 + 380 + 20 + + + + TextLabel + + + + + + 10 + 60 + 380 + 40 + + + + PushButton + + + + + + 10 + 120 + 380 + 20 + + + + TextLabel + + + + + + 10 + 160 + 380 + 20 + + + + TextLabel + + + + + + diff --git a/toxygen/ui/widgets_factory.py b/toxygen/ui/widgets_factory.py index b146088..aa70861 100644 --- a/toxygen/ui/widgets_factory.py +++ b/toxygen/ui/widgets_factory.py @@ -4,7 +4,7 @@ from ui.groups_widgets import * from ui.peer_screen import * from ui.self_peer_screen import * from ui.group_invites_widgets import * -from ui.group_management_screen import * +from ui.group_settings_widgets import * from ui.group_bans_widgets import * @@ -88,5 +88,9 @@ class WidgetsFactory: def create_group_management_screen(self, group): return GroupManagementScreen(self._groups_service, group) + @staticmethod + def create_group_settings_screen(group): + return GroupSettingsScreen(group) + def create_groups_bans_screen(self, group): return GroupBansScreen(self._groups_service, group) diff --git a/toxygen/utils/ui.py b/toxygen/utils/ui.py index cdb5f9a..d2d7122 100644 --- a/toxygen/utils/ui.py +++ b/toxygen/utils/ui.py @@ -46,4 +46,9 @@ def close_all_windows(): QtWidgets.QApplication.closeAllWindows() +def copy_to_clipboard(text): + clipboard = QtWidgets.QApplication.clipboard() + clipboard.setText(text) + + # TODO: all dialogs