history improvements, ui for creation finished, some updates
This commit is contained in:
parent
3aba7dffd2
commit
3ad7d20827
@ -1,11 +1,12 @@
|
|||||||
import contact
|
import contact
|
||||||
|
|
||||||
|
|
||||||
class Groupchat(contact.Contact):
|
class GroupChat(contact.Contact):
|
||||||
|
|
||||||
def __init__(self, group_id, *args):
|
def __init__(self, group_id, tox, *args):
|
||||||
super().__init__(*args)
|
super().__init__(*args)
|
||||||
self._id = group_id
|
self._id = group_id
|
||||||
|
self._tox = tox
|
||||||
|
|
||||||
def load_avatar(self, default_path='group.png'):
|
def load_avatar(self, default_path='group.png'):
|
||||||
super().load_avatar(default_path)
|
super().load_avatar(default_path)
|
||||||
|
@ -87,9 +87,18 @@ class Contact(basecontact.BaseContact):
|
|||||||
if hasattr(self, '_message_getter'):
|
if hasattr(self, '_message_getter'):
|
||||||
del self._message_getter
|
del self._message_getter
|
||||||
# don't delete data about active file transfer
|
# don't delete data about active file transfer
|
||||||
self._corr = list(filter(lambda x: x.get_type() in (2, 3) and x.get_status() >= 2, self._corr))
|
self._corr = list(filter(lambda x: x.get_type() in (2, 3) and (x.get_status() >= 2 or x.get_status() is None),
|
||||||
|
self._corr))
|
||||||
self._unsaved_messages = 0
|
self._unsaved_messages = 0
|
||||||
|
|
||||||
|
def delete_old_messages(self):
|
||||||
|
old = filter(lambda x: x.get_type() in (2, 3) and (x.get_status() >= 2 or x.get_status() is None),
|
||||||
|
self._corr[:-SAVE_MESSAGES])
|
||||||
|
old = list(old)
|
||||||
|
l = max(len(self._corr) - SAVE_MESSAGES, 0) - len(old)
|
||||||
|
self._unsaved_messages -= l
|
||||||
|
self._corr = old + self._corr[-SAVE_MESSAGES:]
|
||||||
|
|
||||||
def get_curr_text(self):
|
def get_curr_text(self):
|
||||||
return self._curr_text
|
return self._curr_text
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ from toxencryptsave import ToxEncryptSave
|
|||||||
|
|
||||||
PAGE_SIZE = 42
|
PAGE_SIZE = 42
|
||||||
|
|
||||||
|
SAVE_MESSAGES = 150
|
||||||
|
|
||||||
MESSAGE_OWNER = {
|
MESSAGE_OWNER = {
|
||||||
'ME': 0,
|
'ME': 0,
|
||||||
'FRIEND': 1,
|
'FRIEND': 1,
|
||||||
|
@ -11,27 +11,35 @@ import toxencryptsave
|
|||||||
import plugin_support
|
import plugin_support
|
||||||
|
|
||||||
|
|
||||||
class AddGroupchat(QtGui.QWidget):
|
class AddGroupchat(CenteredWidget):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self):
|
||||||
super().__init__(parent)
|
super().__init__()
|
||||||
self.initUI()
|
self.initUI()
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
|
self.center()
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setObjectName('AddGC')
|
self.setObjectName('AddGC')
|
||||||
self.resize(570, 320)
|
self.resize(570, 240)
|
||||||
|
self.setMaximumSize(QtCore.QSize(570, 240))
|
||||||
|
self.setMinimumSize(QtCore.QSize(570, 240))
|
||||||
self.label = QtGui.QLabel(self)
|
self.label = QtGui.QLabel(self)
|
||||||
self.label.setGeometry(QtCore.QRect(50, 20, 470, 20))
|
self.label.setGeometry(QtCore.QRect(50, 20, 470, 20))
|
||||||
self.createGCButton = QtGui.QPushButton(self)
|
self.createGCButton = QtGui.QPushButton(self)
|
||||||
self.createGCButton.setGeometry(QtCore.QRect(50, 280, 470, 30))
|
self.createGCButton.setGeometry(QtCore.QRect(50, 190, 470, 30))
|
||||||
self.name = LineEdit(self)
|
self.name = LineEdit(self)
|
||||||
self.name.setGeometry(QtCore.QRect(50, 40, 470, 27))
|
self.name.setGeometry(QtCore.QRect(50, 40, 470, 27))
|
||||||
self.privacy_type = QtGui.QLabel(self)
|
self.privacy_type = QtGui.QLabel(self)
|
||||||
self.privacy_type.setGeometry(QtCore.QRect(50, 70, 470, 20))
|
self.privacy_type.setGeometry(QtCore.QRect(50, 70, 470, 20))
|
||||||
self.privacy_combobox = QtGui.QComboBox(self)
|
self.privacy_combobox = QtGui.QComboBox(self)
|
||||||
self.privacy_combobox.setGeometry(QtCore.QRect(50, 100, 470, 30))
|
self.privacy_combobox.setGeometry(QtCore.QRect(50, 90, 470, 30))
|
||||||
|
self.pass_label = QtGui.QLabel(self)
|
||||||
|
self.pass_label.setGeometry(QtCore.QRect(50, 130, 470, 20))
|
||||||
|
self.password = LineEdit(self)
|
||||||
|
self.password.setGeometry(QtCore.QRect(50, 150, 470, 27))
|
||||||
|
|
||||||
|
self.createGCButton.clicked.connect(self.button_click)
|
||||||
QtCore.QMetaObject.connectSlotsByName(self)
|
QtCore.QMetaObject.connectSlotsByName(self)
|
||||||
|
|
||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
@ -41,6 +49,16 @@ class AddGroupchat(QtGui.QWidget):
|
|||||||
self.privacy_type.setText(QtGui.QApplication.translate('AddGC', "Privacy type:", None, QtGui.QApplication.UnicodeUTF8))
|
self.privacy_type.setText(QtGui.QApplication.translate('AddGC', "Privacy type:", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.privacy_combobox.addItem(QtGui.QApplication.translate('AddGC', "Public", None, QtGui.QApplication.UnicodeUTF8))
|
self.privacy_combobox.addItem(QtGui.QApplication.translate('AddGC', "Public", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.privacy_combobox.addItem(QtGui.QApplication.translate('AddGC', "Private", None, QtGui.QApplication.UnicodeUTF8))
|
self.privacy_combobox.addItem(QtGui.QApplication.translate('AddGC', "Private", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.name.setPlaceholderText(QtGui.QApplication.translate('AddGC', "Not empty group name", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.password.setPlaceholderText(QtGui.QApplication.translate('AddGC', "Optional password", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.pass_label.setText(QtGui.QApplication.translate('AddGC', "Password:", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
|
def button_click(self):
|
||||||
|
if self.name.text():
|
||||||
|
Profile.get_instance().create_gc(self.name.text(),
|
||||||
|
self.privacy_combobox.currentIndex() == 0,
|
||||||
|
self.password.text())
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
class AddContact(CenteredWidget):
|
class AddContact(CenteredWidget):
|
||||||
|
@ -83,6 +83,7 @@ class TransferMessage(Message):
|
|||||||
|
|
||||||
|
|
||||||
class UnsentFile(Message):
|
class UnsentFile(Message):
|
||||||
|
|
||||||
def __init__(self, path, data, time):
|
def __init__(self, path, data, time):
|
||||||
super(UnsentFile, self).__init__(MESSAGE_TYPE['FILE_TRANSFER'], 0, time)
|
super(UnsentFile, self).__init__(MESSAGE_TYPE['FILE_TRANSFER'], 0, time)
|
||||||
self._data, self._path = data, path
|
self._data, self._path = data, path
|
||||||
|
@ -16,6 +16,7 @@ import calls
|
|||||||
import avwidgets
|
import avwidgets
|
||||||
import plugin_support
|
import plugin_support
|
||||||
import basecontact
|
import basecontact
|
||||||
|
from groupchat import *
|
||||||
|
|
||||||
|
|
||||||
class Profile(basecontact.BaseContact, Singleton):
|
class Profile(basecontact.BaseContact, Singleton):
|
||||||
@ -175,7 +176,8 @@ class Profile(basecontact.BaseContact, Singleton):
|
|||||||
pass
|
pass
|
||||||
self._active_friend_or_gc = value
|
self._active_friend_or_gc = value
|
||||||
friend_or_gc = self._friends_and_gc[value]
|
friend_or_gc = self._friends_and_gc[value]
|
||||||
self._friends_and_gc[value].reset_messages()
|
friend_or_gc.reset_messages()
|
||||||
|
friend_or_gc.delete_old_messages()
|
||||||
self._screen.messageEdit.setPlainText(friend_or_gc.curr_text)
|
self._screen.messageEdit.setPlainText(friend_or_gc.curr_text)
|
||||||
self._messages.clear()
|
self._messages.clear()
|
||||||
friend.load_corr()
|
friend.load_corr()
|
||||||
@ -1195,6 +1197,17 @@ class Profile(basecontact.BaseContact, Singleton):
|
|||||||
self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
# Group chats support
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def create_gc(self, name, is_public, password):
|
||||||
|
privacy_state = TOX_GROUP_PRIVACY_STATE['TOX_GROUP_PRIVACY_STATE_PUBLIC'] if is_public else TOX_GROUP_PRIVACY_STATE['TOX_GROUP_PRIVACY_STATE_PRIVATE']
|
||||||
|
num = self._tox.group_new(privacy_state, bytes(name, 'utf-8'))
|
||||||
|
if password:
|
||||||
|
self._tox.group_founder_set_password(num, password)
|
||||||
|
# self._friends_and_gc.append(Groupchat(num, self._tox, ))
|
||||||
|
|
||||||
|
|
||||||
def tox_factory(data=None, settings=None):
|
def tox_factory(data=None, settings=None):
|
||||||
"""
|
"""
|
||||||
|
@ -1549,7 +1549,9 @@ class Tox:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
error = c_int()
|
error = c_int()
|
||||||
result = Tox.libtoxcore.tox_group_new(self._tox_pointer, privacy_state, group_name,
|
func = Tox.libtoxcore.tox_group_new
|
||||||
|
func.restype = c_uint32
|
||||||
|
result = func(self._tox_pointer, privacy_state, group_name,
|
||||||
len(group_name), byref(error))
|
len(group_name), byref(error))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user