summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtChatWindow.cpp44
-rw-r--r--Swift/QtUI/QtChatWindow.h2
2 files changed, 37 insertions, 9 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index d58393b..abbfae5 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -595,11 +595,33 @@ void QtChatWindow::dragEnterEvent(QDragEnterEvent *event) {
595 event->acceptProposedAction(); 595 event->acceptProposedAction();
596 } 596 }
597 } 597 }
598 else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) { 598 else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
599 if (isMUC_ || supportsImpromptuChat_) { 599 if (isMUC_ || supportsImpromptuChat_) {
600 event->acceptProposedAction(); 600 // Prevent invitations or impromptu initializations for contacts that you are already chatting to.
601 std::vector<JID> droppedJIDs =jidListFromQByteArray(event->mimeData()->data("application/vnd.swift.contact-jid-list"));
602 std::set<JID> conversationJIDs;
603 if (isMUC_) {
604 conversationJIDs = treeWidget_->getRoster()->getJIDs();
605 }
606
607 for (std::vector<JID>::iterator i = droppedJIDs.begin(); i != droppedJIDs.end(); ) {
608 const JID& droppedJID = *i;
609 if (conversationJIDs.find(droppedJID) != conversationJIDs.end()) {
610 i = droppedJIDs.erase(i);
611 }
612 else {
613 ++i;
614 }
615 }
616
617 if (droppedJIDs.empty()) {
618 event->ignore();
619 }
620 else {
621 event->acceptProposedAction();
622 }
601 } 623 }
602 } 624 }
603 } 625 }
604} 626}
605 627
@@ -614,22 +636,26 @@ void QtChatWindow::dropEvent(QDropEvent *event) {
614 message.append(boost::make_shared<ChatTextMessagePart>(messageText)); 636 message.append(boost::make_shared<ChatTextMessagePart>(messageText));
615 addSystemMessage(message, DefaultDirection); 637 addSystemMessage(message, DefaultDirection);
616 } 638 }
617 } 639 }
618 else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) { 640 else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
619 QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list"); 641 std::vector<JID> invites = jidListFromQByteArray(event->mimeData()->data("application/vnd.swift.contact-jid-list"));
620 QDataStream dataStream(&dataBytes, QIODevice::ReadOnly);
621 std::vector<JID> invites;
622 while (!dataStream.atEnd()) {
623 QString jidString;
624 dataStream >> jidString;
625 invites.push_back(Q2PSTRING(jidString));
626 }
627 onInviteToChat(invites); 642 onInviteToChat(invites);
628 } 643 }
629} 644}
630 645
646std::vector<JID> QtChatWindow::jidListFromQByteArray(const QByteArray& dataBytes) {
647 QDataStream dataStream(dataBytes);
648 std::vector<JID> invites;
649 while (!dataStream.atEnd()) {
650 QString jidString;
651 dataStream >> jidString;
652 invites.push_back(Q2PSTRING(jidString));
653 }
654 return invites;
655}
656
631void QtChatWindow::setAvailableOccupantActions(const std::vector<OccupantAction>& actions) { 657void QtChatWindow::setAvailableOccupantActions(const std::vector<OccupantAction>& actions) {
632 treeWidget_->setAvailableOccupantActions(actions); 658 treeWidget_->setAvailableOccupantActions(actions);
633} 659}
634 660
635void QtChatWindow::setSubject(const std::string& subject) { 661void QtChatWindow::setSubject(const std::string& subject) {
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 8d7db59..bbcdee7 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -183,10 +183,12 @@ namespace Swift {
183 void handleSettingChanged(const std::string& setting); 183 void handleSettingChanged(const std::string& setting);
184 184
185 void handleOccupantSelectionChanged(RosterItem* item); 185 void handleOccupantSelectionChanged(RosterItem* item);
186 void handleAppendedToLog(); 186 void handleAppendedToLog();
187 187
188 static std::vector<JID> jidListFromQByteArray(const QByteArray& dataBytes);
189
188 private: 190 private:
189 int unreadCount_; 191 int unreadCount_;
190 bool contactIsTyping_; 192 bool contactIsTyping_;
191 LastLineTracker lastLineTracker_; 193 LastLineTracker lastLineTracker_;
192 std::string id_; 194 std::string id_;