diff options
author | Tobias Markmann <tm@ayena.de> | 2012-03-14 21:36:10 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-03-20 18:15:37 (GMT) |
commit | 3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9 (patch) | |
tree | cae0589a1826560668683d2129fe024148d4e43d /Swift/QtUI | |
parent | 138223ab9ca917420d107d95a113e7628c27bac5 (diff) | |
download | swift-contrib-3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9.zip swift-contrib-3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9.tar.bz2 |
Naming suggestion for 'Add Contact'-dialog and "Edit Contact"-dialog based on vCards.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtContactEditWidget.cpp | 71 | ||||
-rw-r--r-- | Swift/QtUI/QtContactEditWidget.h | 10 | ||||
-rw-r--r-- | Swift/QtUI/QtContactEditWindow.cpp | 13 | ||||
-rw-r--r-- | Swift/QtUI/QtContactEditWindow.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp | 18 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h | 14 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.cpp | 71 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.h | 5 |
8 files changed, 161 insertions, 44 deletions
diff --git a/Swift/QtUI/QtContactEditWidget.cpp b/Swift/QtUI/QtContactEditWidget.cpp index a5134e4..a80eb38 100644 --- a/Swift/QtUI/QtContactEditWidget.cpp +++ b/Swift/QtUI/QtContactEditWidget.cpp @@ -2,40 +2,48 @@ * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "QtContactEditWidget.h" #include <algorithm> -#include <QScrollArea> #include <QBoxLayout> -#include <QLabel> #include <QCheckBox> +#include <QLabel> #include <QLineEdit> +#include <QMovie> +#include <QScrollArea> +#include <QRadioButton> #include "Swift/QtUI/QtSwiftUtil.h" namespace Swift { -QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent) : QWidget(parent), groups_(NULL) { +QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent) : QWidget(parent), nameRadioButton_(NULL), groups_(NULL) { QBoxLayout* layout = new QVBoxLayout(this); setContentsMargins(0,0,0,0); layout->setContentsMargins(0,0,0,0); - QHBoxLayout* nameLayout = new QHBoxLayout(); - - QLabel* label = new QLabel(tr("Name:"), this); - nameLayout->addWidget(label); + nameLayout_ = new QHBoxLayout(); + suggestionsLayout_ = new QHBoxLayout(); + nameLayout_->addLayout(suggestionsLayout_); + name_ = new QLineEdit(this); - nameLayout->addWidget(name_); - layout->addLayout(nameLayout); + nameLayout_->addWidget(name_); + + throbberLabel_ = new QLabel(this); + throbberLabel_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this)); + throbberLabel_->movie()->start(); + nameLayout_->addWidget(throbberLabel_); + + layout->addLayout(nameLayout_); layout->addWidget(new QLabel(tr("Groups:"), this)); QScrollArea* groupsArea = new QScrollArea(this); layout->addWidget(groupsArea); groupsArea->setWidgetResizable(true); groupsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); groupsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); @@ -62,19 +70,31 @@ QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups, scrollLayout->addItem(new QSpacerItem(20, 73, QSizePolicy::Minimum, QSizePolicy::Expanding)); } void QtContactEditWidget::setName(const std::string& name) { name_->setText(P2QSTRING(name)); } std::string QtContactEditWidget::getName() const { - return Q2PSTRING(name_->text()); + std::string name; + QList<QRadioButton*> buttons = findChildren<QRadioButton*>(); + foreach(const QRadioButton* button, buttons) { + if (button->isChecked()) { + if (button == nameRadioButton_) { + name = Q2PSTRING(name_->text()); + } else { + name = Q2PSTRING(button->text()); + } + break; + } + } + return name; } void QtContactEditWidget::setSelectedGroups(const std::vector<std::string>& groups) { foreach (std::string group, groups) { checkBoxes_[group]->setCheckState(Qt::Checked); } } std::set<std::string> QtContactEditWidget::getSelectedGroups() const { @@ -84,17 +104,48 @@ std::set<std::string> QtContactEditWidget::getSelectedGroups() const { groups.insert(group.first); } } if (newGroup_->checkState() == Qt::Checked && !newGroupName_->text().isEmpty()) { groups.insert(Q2PSTRING(newGroupName_->text())); } return groups; } +void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& suggestions) { + throbberLabel_->movie()->stop(); + throbberLabel_->hide(); + + foreach(const std::string& name, suggestions) { + suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(P2QSTRING(name), this)); + } + + nameRadioButton_ = new QRadioButton(tr("Name:"), this); + suggestionsLayout_->insertWidget(nameLayout_->count(), nameRadioButton_); + + if (name_->text().isEmpty()) { + QRadioButton* suggestedRadioButton = dynamic_cast<QRadioButton*>(suggestionsLayout_->itemAt(0)->widget()); + if (suggestedRadioButton) { + suggestedRadioButton->setChecked(true); + } + } else { + nameRadioButton_->setChecked(true); + } +} + void QtContactEditWidget::clear() { name_->clear(); setSelectedGroups(std::vector<std::string>()); newGroup_->setChecked(false); newGroupName_->clear(); + throbberLabel_->movie()->start(); + throbberLabel_->show(); + + // clear suggestions + while(suggestionsLayout_->count() != 0) { + QLayoutItem *layoutItem = suggestionsLayout_->takeAt(0); + delete layoutItem->widget(); + delete layoutItem; + } + nameRadioButton_ = NULL; } } diff --git a/Swift/QtUI/QtContactEditWidget.h b/Swift/QtUI/QtContactEditWidget.h index 8ff267d..5350762 100644 --- a/Swift/QtUI/QtContactEditWidget.h +++ b/Swift/QtUI/QtContactEditWidget.h @@ -6,39 +6,49 @@ #pragma once #include <map> #include <set> #include <boost/shared_ptr.hpp> #include <QWidget> +#include <vector> #include <string> +class QLabel; class QLineEdit; class QCheckBox; +class QHBoxLayout; +class QRadioButton; namespace Swift { class QtContactEditWidget : public QWidget { Q_OBJECT public: QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent); void setName(const std::string&); std::string getName() const; void setSelectedGroups(const std::vector<std::string>& groups); std::set<std::string> getSelectedGroups() const; + void setNameSuggestions(const std::vector<std::string>& suggestions); + void clear(); private: typedef std::map<std::string, QCheckBox*> CheckBoxMap; CheckBoxMap checkBoxes_; + QHBoxLayout* nameLayout_; + QHBoxLayout* suggestionsLayout_; + QRadioButton* nameRadioButton_; QLineEdit* name_; QWidget* groups_; QCheckBox* newGroup_; QLineEdit* newGroupName_; + QLabel* throbberLabel_; }; } diff --git a/Swift/QtUI/QtContactEditWindow.cpp b/Swift/QtUI/QtContactEditWindow.cpp index 9b24b23..6520c0a 100644 --- a/Swift/QtUI/QtContactEditWindow.cpp +++ b/Swift/QtUI/QtContactEditWindow.cpp @@ -2,33 +2,35 @@ * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "QtContactEditWindow.h" #include <algorithm> +#include <boost/bind.hpp> + #include <QScrollArea> #include <QBoxLayout> #include <QLabel> #include <QCheckBox> #include <QLineEdit> #include <QMessageBox> #include <QPushButton> #include "Swift/QtUI/QtSwiftUtil.h" #include "QtContactEditWidget.h" namespace Swift { QtContactEditWindow::QtContactEditWindow() : contactEditWidget_(NULL) { - resize(300,300); + resize(400,300); setWindowTitle(tr("Edit contact")); setContentsMargins(0,0,0,0); QBoxLayout* layout = new QVBoxLayout(this); jidLabel_ = new QLabel(this); jidLabel_->setAlignment(Qt::AlignHCenter); layout->addWidget(jidLabel_); @@ -42,18 +44,27 @@ QtContactEditWindow::QtContactEditWindow() : contactEditWidget_(NULL) { connect(removeButton, SIGNAL(clicked()), this, SLOT(handleRemoveContact())); buttonLayout->addWidget(removeButton); QPushButton* okButton = new QPushButton(tr("OK"), this); okButton->setDefault( true ); connect(okButton, SIGNAL(clicked()), this, SLOT(handleUpdateContact())); buttonLayout->addStretch(); buttonLayout->addWidget(okButton); } +QtContactEditWindow::~QtContactEditWindow() { +} + +void QtContactEditWindow::setNameSuggestions(const std::vector<std::string>& nameSuggestions) { + if (contactEditWidget_) { + contactEditWidget_->setNameSuggestions(nameSuggestions); + } +} + void QtContactEditWindow::setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups) { delete contactEditWidget_; jid_ = jid; jidLabel_->setText("<b>" + P2QSTRING(jid.toString()) + "</b>"); contactEditWidget_ = new QtContactEditWidget(allGroups, this); groupsLayout_->addWidget(contactEditWidget_); contactEditWidget_->setName(name); contactEditWidget_->setSelectedGroups(groups); diff --git a/Swift/QtUI/QtContactEditWindow.h b/Swift/QtUI/QtContactEditWindow.h index b25e8b9..5392b10 100644 --- a/Swift/QtUI/QtContactEditWindow.h +++ b/Swift/QtUI/QtContactEditWindow.h @@ -5,31 +5,34 @@ */ #pragma once #include <QWidget> #include <Swift/Controllers/UIInterfaces/ContactEditWindow.h> #include <string> #include <Swiften/JID/JID.h> +#include <Swiften/Elements/VCard.h> class QLabel; class QVBoxLayout; namespace Swift { class QtContactEditWidget; class QtContactEditWindow : public QWidget, public ContactEditWindow { Q_OBJECT public: QtContactEditWindow(); + virtual ~QtContactEditWindow(); + virtual void setNameSuggestions(const std::vector<std::string>& nameSuggestions); virtual void setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups); void setEnabled(bool); void show(); void hide(); static bool confirmContactDeletion(const JID& jid); private slots: diff --git a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp index 779e547..da89a8d 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp +++ b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp @@ -2,34 +2,50 @@ * Copyright (c) 2011 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h" #include <QVBoxLayout> +#include <boost/bind.hpp> + +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/JID/JID.h> + #include <Swift/QtUI/QtContactEditWidget.h> namespace Swift { QtUserSearchDetailsPage::QtUserSearchDetailsPage(const std::set<std::string>& groups) { QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(new QLabel(tr("Please choose a name for the contact, and select the groups you want to add the contact to."))); editWidget = new QtContactEditWidget(groups, this); layout->addWidget(editWidget); } +QtUserSearchDetailsPage::~QtUserSearchDetailsPage() { + +} + +void QtUserSearchDetailsPage::setJID(const JID& jid) { + contactJID = jid; +} + +void QtUserSearchDetailsPage::setNameSuggestions(const std::vector<std::string>& nameSuggestions) { + editWidget->setNameSuggestions(nameSuggestions); +} + std::set<std::string> QtUserSearchDetailsPage::getSelectedGroups() { return editWidget->getSelectedGroups(); } std::string QtUserSearchDetailsPage::getName() { return editWidget->getName(); } void QtUserSearchDetailsPage::clear() { editWidget->clear(); } - } diff --git a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h index 70afcba..9409493 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h +++ b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h @@ -1,33 +1,43 @@ /* * Copyright (c) 2011 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <QWizardPage> + #include <set> +#include <string> +#include <vector> +#include <Swiften/Elements/VCard.h> +#include <Swiften/JID/JID.h> #include <Swift/QtUI/UserSearch/ui_QtUserSearchFieldsPage.h> namespace Swift { class QtContactEditWidget; class QtUserSearchDetailsPage : public QWizardPage { Q_OBJECT public: QtUserSearchDetailsPage(const std::set<std::string>& availableGroups); + virtual ~QtUserSearchDetailsPage(); + + void setJID(const JID& jid); + void setNameSuggestions(const std::vector<std::string>& nameSuggestions); std::set<std::string> getSelectedGroups(); std::string getName(); void clear(); signals: - void onUserTriggersFinish(); + void onUserTriggersFinish(); private: - QtContactEditWidget* editWidget; + QtContactEditWidget* editWidget; + JID contactJID; }; } diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp index 933612c..53eac07 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp @@ -84,56 +84,30 @@ void QtUserSearchWindow::handleCurrentChanged(int page) { JID server = getServerToSearch(); clearForm(); onFormRequested(server); } else if (page == 3 && lastPage_ == 2) { handleSearch(); } else if (page == 4) { detailsPage_->clear(); + detailsPage_->setJID(getContactJID()); + onNameSuggestionRequested(getContactJID()); } lastPage_ = page; } JID QtUserSearchWindow::getServerToSearch() { return firstPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstPage_->service_->currentText())) : myServer_; } void QtUserSearchWindow::handleAccepted() { - JID jid; - if (!firstPage_->byJID_->isChecked()) { - if (dynamic_cast<UserSearchModel*>(model_)) { - UserSearchResult* userItem = static_cast<UserSearchResult*>(resultsPage_->results_->currentIndex().internalPointer()); - if (userItem) { /* Remember to leave this if we change to dynamic cast */ - jid = userItem->getJID(); - } - } else { - int row = resultsPage_->results_->currentIndex().row(); - - Form::FormItem item = dynamic_cast<QtFormResultItemModel*>(model_)->getForm()->getItems().at(row); - JID fallbackJid; - foreach(FormField::ref field, item) { - if (boost::dynamic_pointer_cast<JIDSingleFormField>(field)) { - jid = JID(field->getRawValues().at(0)); - break; - } - if (field->getName() == "jid") { - fallbackJid = field->getRawValues().at(0); - } - } - if (!jid.isValid()) { - jid = fallbackJid; - } - } - } - else { - jid = JID(Q2PSTRING(firstPage_->jid_->text())); - } + JID jid = getContactJID(); if (type_ == AddContact) { eventStream_->send(boost::make_shared<AddContactUIEvent>(jid, detailsPage_->getName(), detailsPage_->getSelectedGroups())); } else { boost::shared_ptr<UIEvent> event(new RequestChatUIEvent(jid)); eventStream_->send(event); } } @@ -184,18 +158,51 @@ void QtUserSearchWindow::handleSearch() { search->setLast(Q2PSTRING(fieldsPage_->lastInput_->text())); } if (fieldsPage_->emailInput_->isEnabled()) { search->setEMail(Q2PSTRING(fieldsPage_->emailInput_->text())); } } onSearchRequested(search, getServerToSearch()); } +JID QtUserSearchWindow::getContactJID() const { + JID jid; + if (!firstPage_->byJID_->isChecked()) { + if (dynamic_cast<UserSearchModel*>(model_)) { + UserSearchResult* userItem = static_cast<UserSearchResult*>(resultsPage_->results_->currentIndex().internalPointer()); + if (userItem) { /* Remember to leave this if we change to dynamic cast */ + jid = userItem->getJID(); + } + } else { + int row = resultsPage_->results_->currentIndex().row(); + + Form::FormItem item = dynamic_cast<QtFormResultItemModel*>(model_)->getForm()->getItems().at(row); + JID fallbackJid; + foreach(FormField::ref field, item) { + if (boost::dynamic_pointer_cast<JIDSingleFormField>(field)) { + jid = JID(field->getRawValues().at(0)); + break; + } + if (field->getName() == "jid") { + fallbackJid = field->getRawValues().at(0); + } + } + if (!jid.isValid()) { + jid = fallbackJid; + } + } + } + else { + jid = JID(Q2PSTRING(firstPage_->jid_->text())); + } + return jid; +} + void QtUserSearchWindow::show() { clear(); QWidget::show(); } void QtUserSearchWindow::addSavedServices(const std::vector<JID>& services) { firstPage_->service_->clear(); foreach (JID jid, services) { firstPage_->service_->addItem(P2QSTRING(jid.toString())); @@ -217,18 +224,24 @@ void QtUserSearchWindow::setSearchFields(boost::shared_ptr<SearchPayload> fields QWidget* legacySearchWidgets[8] = {fieldsPage_->nickInputLabel_, fieldsPage_->nickInput_, fieldsPage_->firstInputLabel_, fieldsPage_->firstInput_, fieldsPage_->lastInputLabel_, fieldsPage_->lastInput_, fieldsPage_->emailInputLabel_, fieldsPage_->emailInput_}; for (int i = 0; i < 8; i++) { legacySearchWidgets[i]->setVisible(enabled[i]); legacySearchWidgets[i]->setEnabled(enabled[i]); } } fieldsPage_->emitCompletenessCheck(); } +void QtUserSearchWindow::setNameSuggestions(const std::vector<std::string>& suggestions) { + if (detailsPage_) { + detailsPage_->setNameSuggestions(suggestions); + } +} + void QtUserSearchWindow::setResults(const std::vector<UserSearchResult>& results) { UserSearchModel *newModel = new UserSearchModel(); newModel->setResults(results); resultsPage_->results_->setModel(newModel); resultsPage_->results_->setItemDelegate(delegate_); resultsPage_->results_->setHeaderHidden(true); delete model_; model_ = newModel; } diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.h b/Swift/QtUI/UserSearch/QtUserSearchWindow.h index 4cfe93f..9173ba9 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.h +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.h @@ -32,30 +32,33 @@ namespace Swift { virtual void addSavedServices(const std::vector<JID>& services); virtual void clear(); virtual void show(); virtual void setResults(const std::vector<UserSearchResult>& results); virtual void setResultsForm(Form::ref results); virtual void setSelectedService(const JID& jid); virtual void setServerSupportsSearch(bool error); virtual void setSearchError(bool error); - virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields) ; + virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields); + virtual void setNameSuggestions(const std::vector<std::string>& suggestions); + protected: virtual int nextId() const; private slots: void handleFirstPageRadioChange(); virtual void handleCurrentChanged(int); virtual void handleAccepted(); private: void clearForm(); void setError(const QString& error); JID getServerToSearch(); void handleSearch(); + JID getContactJID() const; private: UIEventStream* eventStream_; UserSearchWindow::Type type_; QAbstractItemModel* model_; UserSearchDelegate* delegate_; QtUserSearchFirstPage* firstPage_; QtUserSearchFieldsPage* fieldsPage_; QtUserSearchResultsPage* resultsPage_; |