summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/UserSearch')
-rw-r--r--Swift/QtUI/UserSearch/ContactListModel.cpp43
-rw-r--r--Swift/QtUI/UserSearch/ContactListModel.h7
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.cpp23
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.h9
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp40
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h11
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp25
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.h3
8 files changed, 99 insertions, 62 deletions
diff --git a/Swift/QtUI/UserSearch/ContactListModel.cpp b/Swift/QtUI/UserSearch/ContactListModel.cpp
index 4c4a3ea..907142f 100644
--- a/Swift/QtUI/UserSearch/ContactListModel.cpp
+++ b/Swift/QtUI/UserSearch/ContactListModel.cpp
@@ -5,4 +5,10 @@
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include <Swift/QtUI/UserSearch/ContactListModel.h>
@@ -83,41 +89,4 @@ QVariant ContactListModel::data(const QModelIndex& index, int role) const {
}
-bool ContactListModel::dropMimeData(const QMimeData* data, Qt::DropAction /*action*/, int /*row*/, int /*column*/, const QModelIndex& /*parent*/) {
- if (!data->hasFormat("application/vnd.swift.contact-jid")) {
- return false;
- }
-
- QByteArray dataBytes = data->data("application/vnd.swift.contact-jid");
- QDataStream dataStream(&dataBytes, QIODevice::ReadOnly);
- QString jidString;
- QString displayName;
- QString statusText;
- StatusShow::Type statusType;
- QString avatarPath;
-
- dataStream >> jidString;
- dataStream >> displayName;
- dataStream >> statusText;
- dataStream >> statusType;
- dataStream >> avatarPath;
-
- JID jid = JID(Q2PSTRING(jidString));
-
- foreach(const Contact& contact, contacts_) {
- if (contact.jid == jid) {
- return false;
- }
- }
-
- emit layoutAboutToBeChanged();
- contacts_.push_back(Contact(Q2PSTRING(displayName), jid, statusType, Q2PSTRING(avatarPath)));
- emit layoutChanged();
-
- onJIDsDropped(std::vector<JID>(1, jid));
- onListChanged(getList());
-
- return true;
-}
-
QModelIndex ContactListModel::index(int row, int column, const QModelIndex& parent) const {
if (!hasIndex(row, column, parent)) {
diff --git a/Swift/QtUI/UserSearch/ContactListModel.h b/Swift/QtUI/UserSearch/ContactListModel.h
index e7f4a0b..6ca505e 100644
--- a/Swift/QtUI/UserSearch/ContactListModel.h
+++ b/Swift/QtUI/UserSearch/ContactListModel.h
@@ -5,4 +5,10 @@
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#pragma once
@@ -37,5 +43,4 @@ namespace Swift {
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex& index) const;
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.cpp b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
index 90adc11..6ad1169 100644
--- a/Swift/QtUI/UserSearch/QtContactListWidget.cpp
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
@@ -5,4 +5,10 @@
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include <Swift/QtUI/UserSearch/QtContactListWidget.h>
@@ -21,5 +27,4 @@ QtContactListWidget::QtContactListWidget(QWidget* parent, SettingsProvider* sett
setModel(contactListModel_);
- connect(contactListModel_, SIGNAL(onListChanged(std::vector<Contact>)), this, SLOT(handleListChanged(std::vector<Contact>)));
connect(contactListModel_, SIGNAL(onListChanged(std::vector<Contact>)), this, SIGNAL(onListChanged(std::vector<Contact>)));
connect(contactListModel_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SIGNAL(onJIDsAdded(std::vector<JID>)));
@@ -27,7 +32,4 @@ QtContactListWidget::QtContactListWidget(QWidget* parent, SettingsProvider* sett
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
- setDragEnabled(true);
- setAcceptDrops(true);
- setDropIndicatorShown(true);
setUniformRowHeights(true);
@@ -70,10 +72,4 @@ std::vector<Contact> QtContactListWidget::getList() const {
void QtContactListWidget::setMaximumNoOfContactsToOne(bool limited) {
limited_ = limited;
- if (limited) {
- handleListChanged(getList());
- } else {
- setAcceptDrops(true);
- setDropIndicatorShown(true);
- }
}
@@ -91,11 +87,4 @@ void QtContactListWidget::updateContacts(const std::vector<Contact>& contactUpda
}
-void QtContactListWidget::handleListChanged(std::vector<Contact> list) {
- if (limited_) {
- setAcceptDrops(list.size() <= 1);
- setDropIndicatorShown(list.size() <= 1);
- }
-}
-
void QtContactListWidget::handleSettingsChanged(const std::string&) {
contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.h b/Swift/QtUI/UserSearch/QtContactListWidget.h
index f360a91..a83b47a 100644
--- a/Swift/QtUI/UserSearch/QtContactListWidget.h
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.h
@@ -5,4 +5,10 @@
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#pragma once
@@ -42,7 +48,4 @@ signals:
void onJIDsAdded(const std::vector<JID>& jids);
-private slots:
- void handleListChanged(std::vector<Contact> list);
-
private:
void handleSettingsChanged(const std::string&);
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
index b1e9a12..360ce0a 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
@@ -5,9 +5,19 @@
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include "Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h"
+#include <QMessageBox>
+#include <QMimeData>
+#include <QUrl>
+
#include "Swift/QtUI/QtSwiftUtil.h"
-#include <Swift/QtUI/UserSearch/QtContactListWidget.h>
#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/QtUI/UserSearch/QtContactListWidget.h>
#include <Swift/QtUI/UserSearch/QtSuggestingJIDInput.h>
@@ -40,4 +50,6 @@ QtUserSearchFirstMultiJIDPage::QtUserSearchFirstMultiJIDPage(UserSearchWindow::T
connect(contactList_, SIGNAL(onListChanged(std::vector<Contact>)), this, SLOT(emitCompletenessCheck()));
connect(jid_, SIGNAL(editingDone()), this, SLOT(handleEditingDone()));
+
+ setAcceptDrops(true);
}
@@ -54,3 +66,29 @@ void QtUserSearchFirstMultiJIDPage::handleEditingDone() {
}
+void QtUserSearchFirstMultiJIDPage::dragEnterEvent(QDragEnterEvent *event) {
+ if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")
+ || event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
+ event->acceptProposedAction();
+ }
+}
+
+void QtUserSearchFirstMultiJIDPage::dropEvent(QDropEvent *event) {
+ 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> jids;
+ while (!dataStream.atEnd()) {
+ QString jidString;
+ dataStream >> jidString;
+ jids.push_back(Q2PSTRING(jidString));
+ }
+ onJIDsDropped(jids);
+ } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
+ QMessageBox* messageBox = new QMessageBox(this);
+ messageBox->setText(tr("You can't invite a room to chat."));
+ messageBox->setWindowTitle(tr("Error inviting room to chat"));
+ messageBox->show();
+ }
+}
+
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h
index 427995e..9905f21 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h
@@ -5,4 +5,10 @@
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#pragma once
@@ -30,7 +36,12 @@ namespace Swift {
virtual bool isComplete() const;
+ signals:
+ void onJIDsDropped(std::vector<JID> jid);
+
public slots:
void emitCompletenessCheck();
void handleEditingDone();
+ virtual void dragEnterEvent(QDragEnterEvent *event);
+ virtual void dropEvent(QDropEvent *event);
public:
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
index c0c7972..ec5dd39 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2013 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -378,4 +378,24 @@ void QtUserSearchWindow::updateContacts(const std::vector<Contact>& contacts) {
}
+void QtUserSearchWindow::addContacts(const std::vector<Contact>& contacts) {
+ if (type_ != AddContact) {
+ /* prevent duplicate JIDs from appearing in the contact list */
+ foreach (const Contact& newContact, contacts) {
+ bool found = false;
+ foreach (const Contact& oldContact, contactVector_) {
+ if (newContact.jid == oldContact.jid) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ contactVector_.push_back(newContact);
+ }
+ }
+ firstMultiJIDPage_->contactList_->setList(contactVector_);
+ firstMultiJIDPage_->emitCompletenessCheck();
+ }
+}
+
void QtUserSearchWindow::handleAddViaSearch() {
searchNext_ = true;
@@ -391,5 +411,5 @@ void QtUserSearchWindow::handleListChanged(std::vector<Contact> list) {
void QtUserSearchWindow::handleJIDsAdded(std::vector<JID> jids) {
- onJIDUpdateRequested(jids);
+ onJIDAddRequested(jids);
}
@@ -450,4 +470,5 @@ void QtUserSearchWindow::setFirstPage(QString title) {
connect(firstMultiJIDPage_->contactList_, SIGNAL(onListChanged(std::vector<Contact>)), this, SLOT(handleListChanged(std::vector<Contact>)));
connect(firstMultiJIDPage_->contactList_, SIGNAL(onJIDsAdded(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>)));
+ connect(firstMultiJIDPage_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>)));
setPage(1, firstMultiJIDPage_);
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.h b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
index e5a9f80..941e455 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -51,4 +51,5 @@ namespace Swift {
virtual void setCanStartImpromptuChats(bool supportsImpromptu);
virtual void updateContacts(const std::vector<Contact> &contacts);
+ virtual void addContacts(const std::vector<Contact>& contacts);
protected: