summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtChatWindow.cpp')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp88
1 files changed, 62 insertions, 26 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index ed79dcc..68104b4 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -256,28 +256,33 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
}
event->accept();
int key = event->key();
if (key == Qt::Key_Tab) {
tabComplete();
- } else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) {
+ }
+ else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) {
beginCorrection();
- } else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) {
+ }
+ else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) {
cancelCorrection();
- } else if (key == Qt::Key_Down || key == Qt::Key_Up) {
+ }
+ else if (key == Qt::Key_Down || key == Qt::Key_Up) {
/* Drop */
- } else {
+ }
+ else {
messageLog_->handleKeyPressEvent(event);
}
}
void QtChatWindow::beginCorrection() {
boost::optional<AlertID> newCorrectingAlert;
if (correctionEnabled_ == ChatWindow::Maybe) {
newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message")));
- } else if (correctionEnabled_ == ChatWindow::No) {
+ }
+ else if (correctionEnabled_ == ChatWindow::No) {
newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message")));
}
if (newCorrectingAlert) {
if (correctingAlert_) {
removeAlert(*correctingAlert_);
@@ -327,13 +332,14 @@ void QtChatWindow::tabComplete() {
return;
}
QTextCursor cursor;
if (tabCompleteCursor_.hasSelection()) {
cursor = tabCompleteCursor_;
- } else {
+ }
+ else {
cursor = input_->textCursor();
while(cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor) && cursor.document()->characterAt(cursor.position() - 1) != ' ') { }
}
QString root = cursor.selectedText();
if (root.isEmpty()) {
return;
@@ -403,13 +409,14 @@ void QtChatWindow::setSecurityLabelsError() {
}
void QtChatWindow::setSecurityLabelsEnabled(bool enabled) {
if (enabled) {
labelsWidget_->setEnabled(true);
labelsWidget_->show();
- } else {
+ }
+ else {
labelsWidget_->hide();
}
}
void QtChatWindow::setCorrectionEnabled(Tristate enabled) {
correctionEnabled_ = enabled;
@@ -495,13 +502,14 @@ void QtChatWindow::setName(const std::string& name) {
updateTitleWithUnreadCount();
}
void QtChatWindow::updateTitleWithUnreadCount() {
if (isWindow()) {
setWindowTitle(unreadCount_ > 0 ? QString("(%1) %2").arg(unreadCount_).arg(contact_) : contact_);
- } else {
+ }
+ else {
setWindowTitle(contact_);
}
emit titleUpdated();
}
@@ -531,13 +539,14 @@ void QtChatWindow::returnPressed() {
void QtChatWindow::handleInputChanged() {
if (inputClearing_) {
return;
}
if (input_->toPlainText().isEmpty()) {
onUserCancelsTyping();
- } else {
+ }
+ else {
onUserTyping();
}
}
void QtChatWindow::handleCursorPositionChanged() {
if (tabCompletion_) {
@@ -571,35 +580,40 @@ void QtChatWindow::resizeEvent(QResizeEvent*) {
void QtChatWindow::moveEvent(QMoveEvent*) {
emit geometryChanged();
}
void QtChatWindow::dragEnterEvent(QDragEnterEvent *event) {
- if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
- // TODO: check whether contact actually supports file transfer
- if (!isMUC_) {
- event->acceptProposedAction();
+ if (inputEnabled_) {
+ if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
+ // TODO: check whether contact actually supports file transfer
+ if (!isMUC_) {
+ event->acceptProposedAction();
+ }
}
- } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
- if (isMUC_ || supportsImpromptuChat_) {
- event->acceptProposedAction();
+ else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
+ if (isMUC_ || supportsImpromptuChat_) {
+ event->acceptProposedAction();
+ }
}
}
}
void QtChatWindow::dropEvent(QDropEvent *event) {
if (fileTransferEnabled_ == ChatWindow::Yes && event->mimeData()->hasUrls()) {
if (event->mimeData()->urls().size() == 1) {
onSendFileRequest(Q2PSTRING(event->mimeData()->urls().at(0).toLocalFile()));
- } else {
+ }
+ else {
std::string messageText(Q2PSTRING(tr("Sending of multiple files at once isn't supported at this time.")));
ChatMessage message;
message.append(boost::make_shared<ChatTextMessagePart>(messageText));
addSystemMessage(message, DefaultDirection);
}
- } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
+ }
+ else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list");
QDataStream dataStream(&dataBytes, QIODevice::ReadOnly);
std::vector<JID> invites;
while (!dataStream.atEnd()) {
QString jidString;
dataStream >> jidString;
@@ -631,21 +645,26 @@ void QtChatWindow::handleActionButtonClicked() {
QAction* block = NULL;
QAction* unblock = NULL;
if (availableRoomActions_.empty()) {
if (blockingState_ == IsBlocked) {
unblock = contextMenu.addAction(tr("Unblock"));
- } else if (blockingState_ == IsUnblocked) {
+ unblock->setEnabled(inputEnabled_);
+ }
+ else if (blockingState_ == IsUnblocked) {
block = contextMenu.addAction(tr("Block"));
+ block->setEnabled(inputEnabled_);
}
if (supportsImpromptuChat_) {
invite = contextMenu.addAction(tr("Invite person to this chat…"));
+ invite->setEnabled(inputEnabled_);
}
- } else {
+ }
+ else {
foreach(ChatWindow::RoomAction availableAction, availableRoomActions_)
{
if (impromptu_) {
// hide options we don't need in impromptu chats
if (availableAction == ChatWindow::ChangeSubject ||
availableAction == ChatWindow::Configure ||
@@ -653,22 +672,38 @@ void QtChatWindow::handleActionButtonClicked() {
availableAction == ChatWindow::Destroy) {
continue;
}
}
switch(availableAction)
{
- case ChatWindow::ChangeSubject: changeSubject = contextMenu.addAction(tr("Change subject…")); break;
- case ChatWindow::Configure: configure = contextMenu.addAction(tr("Configure room…")); break;
- case ChatWindow::Affiliations: affiliations = contextMenu.addAction(tr("Edit affiliations…")); break;
- case ChatWindow::Destroy: destroy = contextMenu.addAction(tr("Destroy room")); break;
- case ChatWindow::Invite: invite = contextMenu.addAction(tr("Invite person to this room…")); break;
+ case ChatWindow::ChangeSubject:
+ changeSubject = contextMenu.addAction(tr("Change subject…"));
+ changeSubject->setEnabled(inputEnabled_);
+ break;
+ case ChatWindow::Configure:
+ configure = contextMenu.addAction(tr("Configure room…"));
+ configure->setEnabled(inputEnabled_);
+ break;
+ case ChatWindow::Affiliations:
+ affiliations = contextMenu.addAction(tr("Edit affiliations…"));
+ affiliations->setEnabled(inputEnabled_);
+ break;
+ case ChatWindow::Destroy:
+ destroy = contextMenu.addAction(tr("Destroy room"));
+ destroy->setEnabled(inputEnabled_);
+ break;
+ case ChatWindow::Invite:
+ invite = contextMenu.addAction(tr("Invite person to this room…"));
+ invite->setEnabled(inputEnabled_);
+ break;
}
}
}
QAction* bookmark = contextMenu.addAction(tr("Add boomark..."));
+ bookmark->setEnabled(inputEnabled_);
QAction* result = contextMenu.exec(QCursor::pos());
if (result == NULL) {
/* Skip processing. Note that otherwise, because the actions could be null they could match */
}
else if (result == changeSubject) {
@@ -705,13 +740,14 @@ void QtChatWindow::handleActionButtonClicked() {
}
else if (result == block) {
onBlockUserRequest();
}
else if (result == unblock) {
onUnblockUserRequest();
- } else if (result == bookmark) {
+ }
+ else if (result == bookmark) {
onBookmarkRequest();
}
}
void QtChatWindow::handleAffiliationEditorAccepted() {
onChangeAffiliationsRequest(affiliationEditor_->getChanges());