示例#1
0
    def timeUpdate(self, handle, cmd):
        window = self.mainwindow
        chum = PesterProfile(handle)
        systemColor = QtGui.QColor(window.theme["memos/systemMsgColor"])
        close = None
        # old TC command?
        try:
            secs = int(cmd)
            time = datetime.fromtimestamp(secs)
            timed = time - datetime.now()
            s = (timed.seconds // 60)*60
            timed = timedelta(timed.days, s)
        except ValueError:
            if cmd == "i":
                timed = timedelta(0)
            else:
                if cmd[len(cmd)-1] == 'c':
                    close = timeProtocol(cmd)
                    timed = None
                else:
                    timed = timeProtocol(cmd)

        if self.times.has_key(handle):
            if close is not None:
                if close in self.times[handle]:
                    self.times[handle].setCurrent(close)
                    grammar = self.times[handle].getGrammar()
                    self.times[handle].removeTime(close)
                    msg = chum.memoclosemsg(systemColor, grammar, window.theme["convo/text/closememo"])
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
            elif timed not in self.times[handle]:
                self.times[handle].addTime(timed)
            else:
                self.times[handle].setCurrent(timed)
        else:
            if timed is not None:
                ttracker = TimeTracker(timed)
                self.times[handle] = ttracker
示例#2
0
    def userPresentChange(self, handle, channel, update):
        h = unicode(handle)
        c = unicode(channel)
        update = unicode(update)
        if update[0:4] == "kick": # yeah, i'm lazy.
            l = update.split(":")
            update = l[0]
            op = l[1]
        if update == "nick":
            l = h.split(":")
            oldnick = l[0]
            newnick = l[1]
            h = oldnick
        if (update in ["join","left", "kick", "+o"]) \
                and channel != self.channel:
            return
        chums = self.userlist.findItems(h, QtCore.Qt.MatchFlags(0))
        systemColor = QtGui.QColor(self.mainwindow.theme["memos/systemMsgColor"])
        # print exit
        if update == "quit" or update == "left" or update == "nick":
            for c in chums:
                chum = PesterProfile(h)
                self.userlist.takeItem(self.userlist.row(c))
                if not self.times.has_key(h):
                    self.times[h] = TimeTracker(timedelta(0))
                while self.times[h].getTime() is not None:
                    t = self.times[h]
                    grammar = t.getGrammar()
                    msg = chum.memoclosemsg(systemColor, grammar, self.mainwindow.theme["convo/text/closememo"])
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
                    self.times[h].removeTime(t.getTime())
                if update == "nick":
                    self.addUser(newnick)
        elif update == "kick":
            if len(chums) == 0:
                return
            c = chums[0]
            chum = PesterProfile(h)
            if h == self.mainwindow.profile().handle:
                chum = self.mainwindow.profile()
                ttracker = self.time
                curtime = self.time.getTime()
            elif self.times.has_key(h):
                ttracker = self.times[h]
            else:
                ttracker = TimeTracker(timedelta(0))
            while ttracker.getTime() is not None:
                grammar = ttracker.getGrammar()
                opchum = PesterProfile(op)
                if self.times.has_key(op):
                    opgrammar = self.times[op].getGrammar()
                elif op == self.mainwindow.profile().handle:
                    opgrammar = self.time.getGrammar()
                else:
                    opgrammar = TimeGrammar("CURRENT", "C", "RIGHT NOW")
                msg = chum.memobanmsg(opchum, opgrammar, systemColor, grammar)
                self.textArea.append(convertTags(msg))
                self.mainwindow.chatlog.log(self.channel, msg)
                ttracker.removeTime(ttracker.getTime())

            if chum is self.mainwindow.profile():
                # are you next?
                msgbox = QtGui.QMessageBox()
                msgbox.setText(self.mainwindow.theme["convo/text/kickedmemo"])
                msgbox.setInformativeText("press 0k to rec0nnect or cancel to absc0nd")
                msgbox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
                ret = msgbox.exec_()
                if ret == QtGui.QMessageBox.Ok:
                    self.userlist.clear()
                    self.time = TimeTracker(curtime)
                    self.resetSlider(curtime)
                    self.mainwindow.joinChannel.emit(self.channel)
                    me = self.mainwindow.profile()
                    self.time.openCurrentTime()
                    msg = me.memoopenmsg(systemColor, self.time.getTime(), self.time.getGrammar(), self.mainwindow.theme["convo/text/openmemo"], self.channel)
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
                elif ret == QtGui.QMessageBox.Cancel:
                    if self.parent():
                        i = self.parent().tabIndices[self.channel]
                        self.parent().tabClose(i)
                    else:
                        self.close()
            else:
                # i warned you about those stairs bro
                self.userlist.takeItem(self.userlist.row(c))
        elif update == "join":
            self.addUser(h)
            time = self.time.getTime()
            serverText = "PESTERCHUM:TIME>"+delta2txt(time, "server")
            self.messageSent.emit(serverText, self.title())
        elif update == "+o":
            chums = self.userlist.findItems(h, QtCore.Qt.MatchFlags(0))
            for c in chums:
                icon = PesterIcon(self.mainwindow.theme["memos/op/icon"])
                c.setIcon(icon)
                if unicode(c.text()) == self.mainwindow.profile().handle:
                    self.userlist.optionsMenu.addAction(self.opAction)
                    self.userlist.optionsMenu.addAction(self.banuserAction)