diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-07-14 13:10:43 (GMT) |
|---|---|---|
| committer | Richard Maudsley <richard.maudsley@isode.com> | 2014-07-14 13:25:11 (GMT) |
| commit | 4386fa0e6fa8c361d51ec085aefa2d15a61d399a (patch) | |
| tree | c21ba329bd28610eda23f2d2cc023d08d0c7b4e0 | |
| parent | d949d1638c0778a6262c3afa13b55059a85b0499 (diff) | |
| download | swift-contrib-4386fa0e6fa8c361d51ec085aefa2d15a61d399a.zip swift-contrib-4386fa0e6fa8c361d51ec085aefa2d15a61d399a.tar.bz2 | |
Show status message instead of empty VCard dialog when receiving VCard or when an empty VCard is received.
Test-Information:
Request VCard from a user in a MUC that is configured to NOT allow VCards from anonymous users and observe that "empty vcard" status message is displayed instead of an empty dialog. Check that VCard is displayed properly when a VCard is available and that the throbber is still functioning as before.
Change-Id: I098b3ad9495b06b4efbca1547021311f5205cbf2
| -rw-r--r-- | Swift/QtUI/QtProfileWindow.cpp | 41 | ||||
| -rw-r--r-- | Swift/QtUI/QtProfileWindow.h | 1 | ||||
| -rw-r--r-- | Swift/QtUI/QtProfileWindow.ui | 48 | ||||
| -rw-r--r-- | Swiften/Elements/VCard.h | 10 |
4 files changed, 86 insertions, 14 deletions
diff --git a/Swift/QtUI/QtProfileWindow.cpp b/Swift/QtUI/QtProfileWindow.cpp index d0d1414..e643627 100644 --- a/Swift/QtUI/QtProfileWindow.cpp +++ b/Swift/QtUI/QtProfileWindow.cpp @@ -1,114 +1,155 @@ /* * Copyright (c) 2011 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ /* * Copyright (c) 2012 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include "QtProfileWindow.h" #include "ui_QtProfileWindow.h" #include <QCloseEvent> #include <QMovie> #include <QShortcut> #include <QTextDocument> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtUtilities.h> namespace Swift { QtProfileWindow::QtProfileWindow() : QWidget(), ui(new Ui::QtProfileWindow) { ui->setupUi(this); + + ui->statusLabel->setText(tr("Retrieving profile information for this user.")); + ui->statusLabel->setVisible(false); + + ui->emptyLabel->setText(tr("No profile information is available for this user.")); + ui->emptyLabel->setVisible(false); + new QShortcut(QKeySequence::Close, this, SLOT(close())); ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this)); connect(ui->savePushButton, SIGNAL(clicked()), SLOT(handleSave())); setEditable(false); setAttribute(Qt::WA_DeleteOnClose); } QtProfileWindow::~QtProfileWindow() { delete ui; } void QtProfileWindow::setJID(const JID& jid) { this->jid = jid; updateTitle(); } void QtProfileWindow::setVCard(VCard::ref vcard) { ui->vcard->setVCard(vcard); + if (vcard->isEmpty()) { + ui->vcard->setVisible(false); + ui->emptyLabel->setVisible(true); + } else { + ui->vcard->setVisible(true); + ui->emptyLabel->setVisible(false); + } + + updateWindowSize(); } void QtProfileWindow::setEnabled(bool b) { ui->vcard->setEnabled(b); ui->savePushButton->setEnabled(b); } void QtProfileWindow::setEditable(bool b) { ui->throbberLabel->setVisible(b); ui->errorLabel->setVisible(b); ui->savePushButton->setVisible(b); ui->vcard->setEditable(b); updateTitle(); } void QtProfileWindow::setProcessing(bool processing) { if (processing) { ui->throbberLabel->movie()->start(); ui->throbberLabel->show(); + ui->statusLabel->setVisible(true); + ui->vcard->setVisible(false); } else { ui->throbberLabel->hide(); ui->throbberLabel->movie()->stop(); + ui->statusLabel->setVisible(false); + ui->vcard->setVisible(true); } + + updateWindowSize(); } void QtProfileWindow::setError(const std::string& error) { if (!error.empty()) { ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>"); } else { ui->errorLabel->setText(""); } } void QtProfileWindow::show() { QWidget::show(); QWidget::activateWindow(); } void QtProfileWindow::hide() { QWidget::hide(); } void QtProfileWindow::updateTitle() { QString jidString; if (jid.isValid()) { jidString = QString(" ( %1 )").arg(P2QSTRING(jid.toString())); } if (ui->vcard->isEditable()) { setWindowTitle(tr("Edit Profile") + jidString); } else { setWindowTitle(tr("Show Profile") + jidString); } } +void QtProfileWindow::updateWindowSize() { + int width = 0; + int height = 0; + + QSize size = ui->statusLabel->size(); + width = std::max(width, size.width()); + height = std::max(height, size.height() * 3); + + size = ui->emptyLabel->size(); + width = std::max(width, size.width()); + height = std::max(height, size.height() * 3); + + size = ui->vcard->size(); + width = std::max(width, size.width()); + height = std::max(height, size.height()); + + resize(width, height); +} + void QtProfileWindow::closeEvent(QCloseEvent* event) { event->accept(); onWindowAboutToBeClosed(jid); } void QtProfileWindow::handleSave() { onVCardChangeRequest(ui->vcard->getVCard()); } } diff --git a/Swift/QtUI/QtProfileWindow.h b/Swift/QtUI/QtProfileWindow.h index a2af63a..57cc2df 100644 --- a/Swift/QtUI/QtProfileWindow.h +++ b/Swift/QtUI/QtProfileWindow.h @@ -12,46 +12,47 @@ #pragma once #include <Swiften/JID/JID.h> #include <Swift/Controllers/UIInterfaces/ProfileWindow.h> #include <QWidget> namespace Ui { class QtProfileWindow; } namespace Swift { class QtProfileWindow : public QWidget, public ProfileWindow { Q_OBJECT public: QtProfileWindow(); virtual ~QtProfileWindow(); virtual void setJID(const JID& jid); virtual void setVCard(VCard::ref vcard); virtual void setEnabled(bool b); virtual void setProcessing(bool processing); virtual void setError(const std::string& error); virtual void setEditable(bool b); virtual void show(); virtual void hide(); private: void updateTitle(); + void updateWindowSize(); virtual void closeEvent(QCloseEvent* event); private slots: void handleSave(); private: Ui::QtProfileWindow* ui; JID jid; }; } diff --git a/Swift/QtUI/QtProfileWindow.ui b/Swift/QtUI/QtProfileWindow.ui index 9394dc5..ed2986d 100644 --- a/Swift/QtUI/QtProfileWindow.ui +++ b/Swift/QtUI/QtProfileWindow.ui @@ -1,85 +1,105 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>QtProfileWindow</class> <widget class="QWidget" name="QtProfileWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>334</width> <height>197</height> </rect> </property> <property name="windowTitle"> <string>Edit Profile</string> </property> - <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0"> + <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0,0"> <property name="margin"> <number>0</number> </property> <item> <widget class="Swift::QtVCardWidget" name="vcard" native="true"/> </item> <item> + <widget class="QLabel" name="statusLabel"> + <property name="text"> + <string>TextLabel</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="emptyLabel"> + <property name="text"> + <string>TextLabel</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="throbberLabel"> + <property name="text"> + <string/> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="textInteractionFlags"> + <set>Qt::NoTextInteraction</set> + </property> + </widget> + </item> + <item> <layout class="QHBoxLayout" name="horizontalLayout"> <property name="sizeConstraint"> <enum>QLayout::SetDefaultConstraint</enum> </property> <item> <spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>0</height> </size> </property> </spacer> </item> <item> <widget class="QLabel" name="errorLabel"> <property name="text"> <string/> </property> </widget> </item> <item> - <widget class="QLabel" name="throbberLabel"> - <property name="text"> - <string/> - </property> - <property name="alignment"> - <set>Qt::AlignCenter</set> - </property> - <property name="textInteractionFlags"> - <set>Qt::NoTextInteraction</set> - </property> - </widget> - </item> - <item> <widget class="QPushButton" name="savePushButton"> <property name="text"> <string>Save</string> </property> <property name="default"> <bool>true</bool> </property> </widget> </item> </layout> </item> </layout> </widget> <customwidgets> <customwidget> <class>Swift::QtVCardWidget</class> <extends>QWidget</extends> <header>Swift/QtUI/QtVCardWidget/QtVCardWidget.h</header> <container>1</container> </customwidget> </customwidgets> <resources/> <connections/> </ui> diff --git a/Swiften/Elements/VCard.h b/Swiften/Elements/VCard.h index 84b6cfe..409a8ab 100644 --- a/Swiften/Elements/VCard.h +++ b/Swiften/Elements/VCard.h @@ -231,61 +231,71 @@ namespace Swift { return titles_; } void addTitle(const std::string& title) { titles_.push_back(title); } void clearTitles() { titles_.clear(); } const std::vector<std::string>& getRoles() const { return roles_; } void addRole(const std::string& role) { roles_.push_back(role); } void clearRoles() { roles_.clear(); } const std::vector<std::string>& getURLs() const { return urls_; } void addURL(const std::string& url) { urls_.push_back(url); } void clearURLs() { urls_.clear(); } + bool isEmpty() const { + bool empty = version_.empty() && fullName_.empty() && familyName_.empty() && givenName_.empty() && middleName_.empty() && prefix_.empty() && suffix_.empty(); + empty &= photo_.empty() && photoType_.empty() && nick_.empty(); + empty &= birthday_.is_not_a_date_time(); + empty &= unknownContent_.empty(); + empty &= emailAddresses_.empty() && telephones_.empty() && addresses_.empty() && addressLabels_.empty() && jids_.empty(); + empty &= description_.empty() && organizations_.empty() && titles_.empty() && roles_.empty() && urls_.empty(); + return empty; + } + private: std::string version_; std::string fullName_; std::string familyName_; std::string givenName_; std::string middleName_; std::string prefix_; std::string suffix_; //std::string email_; ByteArray photo_; std::string photoType_; std::string nick_; boost::posix_time::ptime birthday_; std::string unknownContent_; std::vector<EMailAddress> emailAddresses_; std::vector<Telephone> telephones_; std::vector<Address> addresses_; std::vector<AddressLabel> addressLabels_; std::vector<JID> jids_; std::string description_; std::vector<Organization> organizations_; std::vector<std::string> titles_; std::vector<std::string> roles_; std::vector<std::string> urls_; }; } |
Swift