void ChatDlg::chatEditCreated() { chatView()->setDialog(this); chatEdit()->setDialog(this); if (highlightersInstalled_) { connect(chatEdit(), SIGNAL(textChanged()), this, SLOT(setComposing())); } }
void ChatDlg::doneSend() { appendMessage(m_, true); disconnect(chatEdit(), SIGNAL(textChanged()), this, SLOT(setComposing())); chatEdit()->clear(); // Reset composing timer connect(chatEdit(), SIGNAL(textChanged()), this, SLOT(setComposing())); // Reset composing timer resetComposing(); }
/** * Runs all the gumph necessary before hiding a chat. * (checking new messages, setting the autodelete, cancelling composing etc) * \return ChatDlg is ready to be hidden. */ bool ChatDlg::readyToHide() { // really lame way of checking if we are encrypting if (!chatEdit()->isEnabled()) { return false; } if (keepOpen_) { QMessageBox mb(QMessageBox::Information, tr("Warning"), tr("A new chat message was just received.\nDo you still want to close the window?"), QMessageBox::Cancel, this); mb.addButton(tr("Close"), QMessageBox::AcceptRole); if (mb.exec() == QMessageBox::Cancel) { return false; } } // destroy the dialog if delChats is dcClose if (PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "instant") { setAttribute(Qt::WA_DeleteOnClose); } else { if (PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "hour") { setSelfDestruct(60); } else if (PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "day") { setSelfDestruct(60 * 24); } } // Reset 'contact is composing' & cancel own composing event resetComposing(); setChatState(StateGone); if (contactChatState_ == StateComposing || contactChatState_ == StateInactive) { setContactChatState(StatePaused); } if (pending_ > 0) { pending_ = 0; messagesRead(jid()); invalidateTab(); } doFlash(false); chatEdit()->setFocus(); return true; }
void ChatDlg::encryptedMessageSent(int x, bool b, int e, const QString &dtext) { if (transid_ == -1 || transid_ != x) { return; } transid_ = -1; if (b) { doneSend(); } else { PGPUtil::showDiagnosticText(static_cast<QCA::SecureMessage::Error>(e), dtext); } chatEdit()->setEnabled(true); chatEdit()->setFocus(); }
void ChatDlg::addEmoticon(QString text) { if (!isActiveTab()) return; chatEdit()->insert(text + " "); }
void ChatDlg::init() { initUi(); initActions(); setShortcuts(); // TODO: this have to be moved to chatEditCreated() chatView()->setDialog(this); chatEdit()->setDialog(this); chatEdit()->installEventFilter(this); connect(chatView(), SIGNAL(selectionChanged()), SLOT(logSelectionChanged())); // SyntaxHighlighters modify the QTextEdit in a QTimer::singleShot(0, ...) call // so we need to install our hooks after it fired for the first time QTimer::singleShot(10, this, SLOT(initComposing())); connect(this, SIGNAL(composing(bool)), SLOT(updateIsComposing(bool))); setAcceptDrops(TRUE); updateContact(jid(), true); X11WM_CLASS("chat"); setLooks(); updatePGP(); connect(account(), SIGNAL(pgpKeyChanged()), SLOT(updatePGP())); connect(account(), SIGNAL(encryptedMessageSent(int, bool, int, const QString &)), SLOT(encryptedMessageSent(int, bool, int, const QString &))); account()->dialogRegister(this, jid()); chatView()->setFocusPolicy(Qt::NoFocus); chatEdit()->setFocus(); // TODO: port to restoreSavedSize() (and adapt it from restoreSavedGeometry()) QSize size = PsiOptions::instance()->getOption("options.ui.chat.size").toSize(); if (!size.isEmpty()) { resize(size); } else { resize(defaultSize()); } }
void ChatDlg::logSelectionChanged() { #ifdef Q_WS_MAC // A hack to only give the message log focus when text is selected if (chatView()->hasSelectedText()) { chatView()->setFocus(); } else { chatEdit()->setFocus(); } #endif }
bool ChatDlg::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::KeyPress) { keyPressEvent(static_cast<QKeyEvent*>(event)); if (event->isAccepted()) return true; } if (chatView()->handleCopyEvent(obj, event, chatEdit())) return true; return QWidget::eventFilter(obj, event); }
void ChatDlg::activated() { TabbableWidget::activated(); if (pending_ > 0) { pending_ = 0; messagesRead(jid()); invalidateTab(); } doFlash(false); chatEdit()->setFocus(); }
void ChatDlg::setLooks() { // update the font QFont f; f.fromString(PsiOptions::instance()->getOption("options.ui.look.font.chat").toString()); chatView()->setFont(f); chatEdit()->setFont(f); // update contact info status_ = -2; // sick way of making it redraw the status updateContact(jid(), false); // update the widget icon #ifndef Q_WS_MAC setWindowIcon(IconsetFactory::icon("psi/start-chat").icon()); #endif /*QBrush brush; brush.setPixmap( QPixmap( LEGOPTS.chatBgImage ) ); chatView()->setPaper(brush); chatView()->setStaticBackground(true);*/ setWindowOpacity(double(qMax(MINIMUM_OPACITY, PsiOptions::instance()->getOption("options.ui.chat.opacity").toInt())) / 100); }
QSize YaChatEdit::minimumSizeHint() const { return chatEdit()->minimumSizeHint(); }
void ChatDlg::doSend() { if (!chatEdit()->isEnabled()) { return; } if (chatEdit()->text().isEmpty()) { return; } if (chatEdit()->text() == "/clear") { chatEdit()->clear(); doClear(); return; } if (!account()->loggedIn()) { return; } if (warnSend_) { warnSend_ = false; int n = QMessageBox::information(this, tr("Warning"), tr( "<p>Encryption was recently disabled by the remote contact. " "Are you sure you want to send this message without encryption?</p>" ), tr("&Yes"), tr("&No")); if (n != 0) { return; } } Message m(jid()); m.setType("chat"); m.setBody(chatEdit()->text()); m.setTimeStamp(QDateTime::currentDateTime()); if (isEncryptionEnabled()) { m.setWasEncrypted(true); } m_ = m; // Request events if (PsiOptions::instance()->getOption("options.messages.send-composing-events").toBool()) { // Only request more events when really necessary if (sendComposingEvents_) { m.addEvent(ComposingEvent); } m.setChatState(XMPP::StateActive); } // Update current state setChatState(XMPP::StateActive); if (isEncryptionEnabled()) { chatEdit()->setEnabled(false); transid_ = account()->sendMessageEncrypted(m); if (transid_ == -1) { chatEdit()->setEnabled(true); chatEdit()->setFocus(); return; } } else { aSend(m); doneSend(); } chatEdit()->setFocus(); }