Exemple #1
0
void ChatWindow::sendLine()
{
    QColor oldColor = edtChat->color();
    QString s = edtChat->text();
    s.replace(QRegExp("<br>"), "");
    s.replace(QRegExp("</?p>"), "");
    QCString sLineSend = s.local8Bit();
    chat->chat->sendLine(sLineSend);
    QString clientString;
    QString br;
    if (bClientMode){
        int n = txtChat->paragraphs();
        clientString = txtChat->text(n-1);
        txtChat->removeParagraph(n-1);
        br = "<br>";
        int pos = clientString.find("&gt;");
        clientString = chatHeader(chat->getUin()) + clientString.mid(pos+4);
    }
    QString line = chatHeader(0) + ParseText(sLineSend) + "<br>\n";
    txtChat->insertParagraph(br + line, -1);
    if (bClientMode)
        txtChat->insertParagraph(clientString, -1);
    txtChat->scrollToBottom();
    txtChat->moveCursor(QTextEdit::MoveEnd, false);
    edtChat->setText("");
    edtChat->setBold(btnBold->isOn());
    edtChat->setItalic(btnItalic->isOn());
    edtChat->setUnderline(btnUnderline->isOn());
    if (logFile){
        QCString s = line.local8Bit();
        logFile->writeBlock(s, s.length());
        logFile->flush();
    }
    edtChat->setColor(oldColor);
}
Exemple #2
0
void ChatWindow::openLog()
{
    QString fname;
    if (logFile){
        fname = logFile->name();
    }else{
        string name;
        pMain->buildFileName(name, "ChatLog/");
        fname = QString::fromLocal8Bit(name.c_str());
    }
#ifdef WIN32
    fname.replace(QRegExp("\\\\"), "/");
#endif
    fname = QFileDialog::getSaveFileName(fname, QString::null, this);
#ifdef WIN32
    fname.replace(QRegExp("/"), "\\");
#endif
    if (fname.length() == 0) return;
    if (logFile && (logFile->name() == fname)) return;
    QFile *newFile = new QFile(fname);
    if (!newFile->open(IO_Append)){
        BalloonMsg::message(i18n("Can't create %1") .arg(fname), btnSave);
        delete newFile;
        return;
    }
    if (logFile == NULL){
        logFile = newFile;
        return;
    }
    delete logFile;
    QString clientString;
    if (bClientMode){
        int n = txtChat->paragraphs();
        clientString = txtChat->text(n-1);
        txtChat->removeParagraph(n-1);
        int pos = clientString.find("&gt;");
        clientString = chatHeader(chat->getUin()) + clientString.mid(pos+4);
    }
    QString t = txtChat->text();
    QCString s = t.local8Bit();
    logFile->writeBlock(s, s.length());
    logFile->flush();
    if (bClientMode)
        txtChat->insertParagraph(clientString, -1);
    txtChat->scrollToBottom();
    txtChat->moveCursor(QTextEdit::MoveEnd, false);
    logFile = newFile;
}
Exemple #3
0
void ChatWindow::processEvent(ICQEvent *e)
{
    if (e->message() != chat) return;
    chat->bDelete = false;
    if (e->state == ICQEvent::Fail){
        if (bInit) close();
        return;
    }
    if (e->type() != EVENT_CHAT) return;
    switch (e->subType()){
    case CHAT_CONNECT:{
            CUser u(e->Uin());
            new ChatUserItem(lstUsers, u.name(), e->Uin());
            QString line = chatHeader(e->Uin()) +
                           txtChat->quoteText(i18n("Enter to chat").local8Bit()) + "<br>\n";
            txtChat->insertParagraph(line, -1);
            txtChat->scrollToBottom();
            txtChat->moveCursor(QTextEdit::MoveEnd, false);
            if (logFile){
                QCString s = line.local8Bit();
                logFile->writeBlock(s, s.length());
                logFile->flush();
            }
            bConnected = true;
            break;
        }
    case CHAT_FONT_FACE:
        if (bClientMode){
            txtChat->setBold(chat->chat->fontFace & FONT_BOLD);
            txtChat->setItalic(chat->chat->fontFace & FONT_ITALIC);
            txtChat->setUnderline(chat->chat->fontFace & FONT_UNDERLINE);
        }
        break;
    case CHAT_COLORxFG:
        if (bClientMode)
            txtChat->setColor(chatColor(chat->chat->fgColor));
        break;
    case CHAT_TEXT:
        if (!bClientMode){
            txtChat->insertParagraph(chatHeader(e->Uin()), -1);
            txtChat->scrollToBottom();
            txtChat->moveCursor(QTextEdit::MoveEnd, false);
            txtChat->setBold(chat->chat->fontFace & FONT_BOLD);
            txtChat->setItalic(chat->chat->fontFace & FONT_ITALIC);
            txtChat->setUnderline(chat->chat->fontFace & FONT_UNDERLINE);
            txtChat->setColor(chatColor(chat->chat->fgColor));
            bClientMode = true;
        }
        txtChat->insert(QString::fromLocal8Bit(e->text.c_str()), false, false);
        break;
    case CHAT_BACKSPACE:
        if (bClientMode)
            txtChat->doKeyboardAction(QTextEdit::ActionBackspace);
        break;
    case CHAT_NEWLINE:{
            QString clientString;
            if (bClientMode){
                int n = txtChat->paragraphs();
                clientString = txtChat->text(n-1);
                txtChat->removeParagraph(n-1);
                int pos = clientString.find("&gt;");
                clientString = clientString.mid(pos+4);
            }
            txtChat->insertParagraph("<br>", -1);
            txtChat->moveCursor(QTextEdit::MoveEnd, false);
            QString line = chatHeader(chat->getUin()) + MainWindow::ParseText(clientString.local8Bit(), false) + "<br>\n";
            txtChat->append(line);
            txtChat->scrollToBottom();
            txtChat->moveCursor(QTextEdit::MoveEnd, false);
            bClientMode = false;
            if (logFile){
                QCString s = line.local8Bit();
                logFile->writeBlock(s, s.size());
                logFile->flush();
            }
            break;
        }
    }
}