class ChannelsManagementWindow(ChannelsManagementWindowMeta, ISearchHandler):

    def __init__(self, _ = None):
        super(ChannelsManagementWindow, self).__init__()
        self._searchDP = SearchChannelsDataProvider(self.proto.messages.getSearchUserRoomsProcessor())

    def destroy(self):
        super(ChannelsManagementWindow, self).destroy()

    @proto_getter(PROTO_TYPE.MIGRATION)
    def proto(self):
        return None

    def onWindowClose(self):
        self.destroy()

    def getSearchLimitLabel(self):
        return i18n.makeString(MESSENGER.DIALOGS_SEARCHCHANNEL_LABELS_RESULT, self._searchDP.processor.getSearchResultLimit())

    def searchToken(self, token):
        self.as_freezSearchButtonS(True)
        self._searchDP.find(token.strip())

    def joinToChannel(self, index):
        item = self._searchDP.requestItemAtHandler(int(index))
        if item is not None:
            self.proto.messages.joinToUserRoom(item['id'], item['name'])
        else:
            LOG_ERROR('Channel data not found', int(index))
        return

    def createChannel(self, name, usePassword, password, retype):
        validator = self.proto.messages.getUserRoomValidator()
        name, error = validator.validateUserRoomName(name)
        if error is not None:
            g_messengerEvents.onErrorReceived(error)
            return
        else:
            if usePassword:
                pwd, error = validator.validateUserRoomPwdPair(password, retype)
                if error is not None:
                    g_messengerEvents.onErrorReceived(error)
                    return
            result = self.proto.messages.createUserRoom(name, password)
            if result:
                self.destroy()
            return

    def onSearchComplete(self, _):
        self.as_freezSearchButtonS(False)

    def onSearchFailed(self, _):
        self.as_freezSearchButtonS(False)

    def _populate(self):
        super(ChannelsManagementWindow, self)._populate()
        self._searchDP.init(self.as_getDataProviderS(), (self,))

    def _dispose(self):
        if self._searchDP is not None:
            self._searchDP.fini()
            self._searchDP = None
        super(ChannelsManagementWindow, self)._dispose()
        return
class ChannelsManagementWindow(View, WindowViewMeta,
                               ChannelsManagementWindowMeta, ISearchHandler):
    def __init__(self):
        super(ChannelsManagementWindow, self).__init__()
        self._searchDP = SearchChannelsDataProvider()

    def destroy(self):
        super(ChannelsManagementWindow, self).destroy()

    def _populate(self):
        super(ChannelsManagementWindow, self)._populate()
        self._searchDP.init(self.as_getDataProviderS(), [self])

    def _dispose(self):
        if self._searchDP is not None:
            self._searchDP.fini()
            self._searchDP = None
        super(ChannelsManagementWindow, self)._dispose()
        return

    @proto_getter(PROTO_TYPE.BW)
    def proto(self):
        return None

    def onWindowClose(self):
        self.destroy()

    def getSearchLimitLabel(self):
        return i18n.makeString(MESSENGER.DIALOGS_SEARCHCHANNEL_LABELS_RESULT,
                               self._searchDP.processor.getSearchResultLimit())

    def searchToken(self, token):
        self.as_freezSearchButtonS(True)
        self._searchDP.find(token.strip())

    def joinToChannel(self, index):
        item = self._searchDP.requestItemAtHandler(int(index))
        if item is not None:
            self.proto.channels.joinToChannel(item['id'])
        else:
            LOG_ERROR('Channel data not found', int(index))
        return

    def createChannel(self, name, userPassword, password, retype):
        name = name.strip()
        if name is None or len(name) not in xrange(
                CHANNEL_NAME_MIN_LENGTH, CHANNEL_NAME_MAX_LENGTH + 1):
            SystemMessages.pushI18nMessage(
                MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDNAME_MESSAGE,
                CHANNEL_NAME_MIN_LENGTH,
                CHANNEL_NAME_MAX_LENGTH,
                type=SystemMessages.SM_TYPE.Error)
            return
        else:
            if userPassword:
                pwdRange = xrange(CHANNEL_PWD_MIN_LENGTH,
                                  CHANNEL_PWD_MAX_LENGTH + 1)
                if password is None or len(password) not in pwdRange:
                    SystemMessages.pushI18nMessage(
                        MESSENGER.
                        DIALOGS_CREATECHANNEL_ERRORS_INVALIDPASSWORD_MESSAGE,
                        CHANNEL_PWD_MIN_LENGTH,
                        CHANNEL_PWD_MAX_LENGTH,
                        type=SystemMessages.SM_TYPE.Error)
                    return
                if retype is None or len(retype) not in pwdRange:
                    SystemMessages.pushI18nMessage(
                        MESSENGER.
                        DIALOGS_CREATECHANNEL_ERRORS_INVALIDRETYPEPASSWORD_MESSAGE,
                        CHANNEL_PWD_MIN_LENGTH,
                        CHANNEL_PWD_MAX_LENGTH,
                        type=SystemMessages.SM_TYPE.Error)
                    return
                if password != retype:
                    SystemMessages.pushI18nMessage(
                        MESSENGER.
                        DIALOGS_CREATECHANNEL_ERRORS_NOTEQUALSPASSWORDS_MESSAGE
                    )
                    return
            else:
                password = None
            self.proto.channels.createChannel(name, password)
            self.destroy()
            return

    def onSearchComplete(self, _):
        self.as_freezSearchButtonS(False)

    def onSearchFailed(self, _):
        self.as_freezSearchButtonS(False)
示例#3
0
class ChannelsManagementWindow(View, AbstractWindowView, ChannelsManagementWindowMeta, ISearchHandler):

    def __init__(self, ctx = None):
        super(ChannelsManagementWindow, self).__init__()
        self._searchDP = SearchChannelsDataProvider()

    def destroy(self):
        super(ChannelsManagementWindow, self).destroy()

    def _populate(self):
        super(ChannelsManagementWindow, self)._populate()
        self._searchDP.init(self.as_getDataProviderS(), [self])

    def _dispose(self):
        if self._searchDP is not None:
            self._searchDP.fini()
            self._searchDP = None
        super(ChannelsManagementWindow, self)._dispose()
        return

    @proto_getter(PROTO_TYPE.BW)
    def proto(self):
        return None

    def onWindowClose(self):
        self.destroy()

    def getSearchLimitLabel(self):
        return i18n.makeString(MESSENGER.DIALOGS_SEARCHCHANNEL_LABELS_RESULT, self._searchDP.processor.getSearchResultLimit())

    def searchToken(self, token):
        self.as_freezSearchButtonS(True)
        self._searchDP.find(token.strip())

    def joinToChannel(self, index):
        item = self._searchDP.requestItemAtHandler(int(index))
        if item is not None:
            self.proto.channels.joinToChannel(item['id'])
        else:
            LOG_ERROR('Channel data not found', int(index))
        return

    def createChannel(self, name, userPassword, password, retype):
        name = name.strip()
        if name is None or len(unicode_from_utf8(name)[0]) not in xrange(CHANNEL_NAME_MIN_LENGTH, CHANNEL_NAME_MAX_LENGTH + 1):
            SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDNAME_MESSAGE, CHANNEL_NAME_MIN_LENGTH, CHANNEL_NAME_MAX_LENGTH, type=SystemMessages.SM_TYPE.Error)
            return
        else:
            if userPassword:
                pwdRange = xrange(CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH + 1)
                if password is None or len(unicode_from_utf8(password)[0]) not in pwdRange:
                    SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDPASSWORD_MESSAGE, CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH, type=SystemMessages.SM_TYPE.Error)
                    return
                if retype is None or len(unicode_from_utf8(retype)[0]) not in pwdRange:
                    SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDRETYPEPASSWORD_MESSAGE, CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH, type=SystemMessages.SM_TYPE.Error)
                    return
                if password != retype:
                    SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_NOTEQUALSPASSWORDS_MESSAGE, type=SystemMessages.SM_TYPE.Error)
                    return
            else:
                password = None
            result = self.proto.channels.createChannel(name, password)
            if result == CREATE_CHANNEL_RESULT.activeChannelLimitReached:
                SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_ACTIVECHANNELLIMITREACHED_MESSAGE, type=SystemMessages.SM_TYPE.Error)
            self.destroy()
            return

    def onSearchComplete(self, _):
        self.as_freezSearchButtonS(False)

    def onSearchFailed(self, _):
        self.as_freezSearchButtonS(False)
class ChannelsManagementWindow(ChannelsManagementWindowMeta, ISearchHandler):
    def __init__(self, _=None):
        super(ChannelsManagementWindow, self).__init__()
        self._searchDP = SearchChannelsDataProvider(
            self.proto.messages.getSearchUserRoomsProcessor())

    @proto_getter(PROTO_TYPE.MIGRATION)
    def proto(self):
        return None

    def onWindowClose(self):
        self.destroy()

    def getSearchLimitLabel(self):
        return i18n.makeString(MESSENGER.DIALOGS_SEARCHCHANNEL_LABELS_RESULT,
                               self._searchDP.processor.getSearchResultLimit())

    def searchToken(self, token):
        self.as_freezSearchButtonS(True)
        self._searchDP.find(token.strip())

    def joinToChannel(self, index):
        item = self._searchDP.requestItemAtHandler(int(index))
        if item is not None:
            self.proto.messages.joinToUserRoom(item['id'], item['name'])
        else:
            LOG_ERROR('Channel data not found', int(index))
        return

    def createChannel(self, name, usePassword, password, retype):
        validator = self.proto.messages.getUserRoomValidator()
        if not IS_CHINA:
            name, error = validator.validateUserRoomName(name)
            if error is not None:
                g_messengerEvents.onErrorReceived(error)
                return
        else:
            name, error = ('', None)
        if usePassword:
            _, error = validator.validateUserRoomPwdPair(password, retype)
            if error is not None:
                g_messengerEvents.onErrorReceived(error)
                return
        result = self.proto.messages.createUserRoom(name, password)
        if result:
            self.destroy()
        return

    def onSearchComplete(self, _):
        self.as_freezSearchButtonS(False)

    def onSearchFailed(self, _):
        self.as_freezSearchButtonS(False)

    def _populate(self):
        super(ChannelsManagementWindow, self)._populate()
        self._searchDP.init(self.as_getDataProviderS(), (self, ))
        self.as_hideChannelNameInputS(IS_CHINA)

    def _dispose(self):
        if self._searchDP is not None:
            self._searchDP.fini()
            self._searchDP = None
        super(ChannelsManagementWindow, self)._dispose()
        return