summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/QtUI/QtMainWindow.cpp10
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp3
2 files changed, 9 insertions, 4 deletions
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index 611fc80..0c1dd97 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -1,41 +1,42 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtMainWindow.h>
+#include <memory>
+
#include <boost/bind.hpp>
#include <boost/optional.hpp>
-#include <memory>
#include <QAction>
#include <QBoxLayout>
#include <QComboBox>
#include <QLineEdit>
#include <QListWidget>
#include <QListWidgetItem>
#include <QMenuBar>
#include <QPushButton>
#include <QTabWidget>
#include <QToolBar>
#include <Swiften/Base/Platform.h>
#include <Swift/Controllers/SettingConstants.h>
#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestBlockListDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h>
#include <Swift/QtUI/QtAdHocCommandWithJIDWindow.h>
#include <Swift/QtUI/QtLoginWindow.h>
#include <Swift/QtUI/QtSettingsProvider.h>
#include <Swift/QtUI/QtSwiftUtil.h>
#include <Swift/QtUI/QtTabWidget.h>
#include <Swift/QtUI/QtUISettingConstants.h>
@@ -330,96 +331,97 @@ void QtMainWindow::handleShowOfflineToggled(bool state) {
settings_->storeSetting(SettingConstants::SHOW_OFFLINE, state);
showOfflineAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
}
void QtMainWindow::handleShowEmoticonsToggled(bool state) {
settings_->storeSetting(QtUISettingConstants::SHOW_EMOTICONS, state);
showEmoticonsAction_->setChecked(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
}
void QtMainWindow::setMyNick(const std::string& nick) {
meView_->setNick(P2QSTRING(nick));
}
void QtMainWindow::setMyJID(const JID& jid) {
meView_->setJID(P2QSTRING(jid.toBare().toString()));
}
void QtMainWindow::setMyAvatarPath(const std::string& path) {
meView_->setAvatar(P2QSTRING(path));
}
void QtMainWindow::setMyStatusText(const std::string& status) {
meView_->setStatusText(P2QSTRING(status));
}
void QtMainWindow::setMyStatusType(StatusShow::Type type) {
meView_->setStatusType(type);
const bool online = (type != StatusShow::None);
treeWidget_->setOnline(online);
chatListWindow_->setOnline(online);
- foreach (QAction *action, onlineOnlyActions_) {
+ for (auto action : onlineOnlyActions_) {
action->setEnabled(online);
}
serverAdHocMenu_->setEnabled(online);
}
void QtMainWindow::setMyContactRosterItem(std::shared_ptr<ContactRosterItem> contact) {
meView_->setContactRosterItem(contact);
}
void QtMainWindow::setConnecting() {
meView_->setConnecting();
}
void QtMainWindow::setStreamEncryptionStatus(bool tlsInPlaceAndValid) {
meView_->setStreamEncryptionStatus(tlsInPlaceAndValid);
}
void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain) {
openCertificateDialog(chain, this);
}
void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent) {
#if defined(SWIFTEN_PLATFORM_MACOSX)
CocoaUIHelpers::displayCertificateChainAsSheet(parent, chain);
#elif defined(SWIFTEN_PLATFORM_WINDOWS)
WinUIHelpers::displayCertificateChainAsSheet(parent, chain);
#else
QtCertificateViewerDialog::displayCertificateChainAsSheet(parent, chain);
#endif
}
void QtMainWindow::handleAdHocActionTriggered(bool /*checked*/) {
QAction* action = qobject_cast<QAction*>(sender());
assert(action);
+ assert(serverAdHocCommandActions_.indexOf(action) >= 0);
DiscoItems::Item command = serverAdHocCommands_[serverAdHocCommandActions_.indexOf(action)];
uiEventStream_->send(std::make_shared<RequestAdHocUIEvent>(command));
}
void QtMainWindow::setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands) {
serverAdHocCommands_ = commands;
- foreach (QAction* action, serverAdHocCommandActions_) {
+ for (auto action : serverAdHocCommandActions_) {
delete action;
}
serverAdHocMenu_->clear();
serverAdHocCommandActions_.clear();
- foreach (DiscoItems::Item command, commands) {
+ for (const auto& command : commands) {
QAction* action = new QAction(P2QSTRING(command.getName()), this);
connect(action, SIGNAL(triggered(bool)), this, SLOT(handleAdHocActionTriggered(bool)));
serverAdHocMenu_->addAction(action);
serverAdHocCommandActions_.append(action);
}
if (serverAdHocCommandActions_.isEmpty()) {
QAction* action = new QAction(tr("No Available Commands"), this);
action->setEnabled(false);
serverAdHocMenu_->addAction(action);
serverAdHocCommandActions_.append(action);
}
}
void QtMainWindow::setBlockingCommandAvailable(bool isAvailable) {
openBlockingListEditor_->setVisible(isAvailable);
}
}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
index ace6bcb..610c4f3 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
@@ -6,92 +6,94 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/Elements/Form.h>
#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
using namespace Swift;
class FormParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(FormParserTest);
CPPUNIT_TEST(testParse_FormInformation);
CPPUNIT_TEST(testParse_FormLayout);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testParse_FormItems);
CPPUNIT_TEST_SUITE_END();
public:
void testParse_FormInformation() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<x type=\"submit\" xmlns=\"jabber:x:data\">"
"<title>Bot Configuration</title>"
"<instructions>Hello!</instructions>"
"<instructions>Fill out this form to configure your new bot!</instructions>"
"</x>"
));
Form* payload = dynamic_cast<Form*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getTitle());
CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), payload->getInstructions());
CPPUNIT_ASSERT_EQUAL(Form::SubmitType, payload->getType());
}
void testParse_FormLayout() {
PayloadsParserTester parser;
// P1 = page one, S1 = section one, F1 = field one, T1 = text one
CPPUNIT_ASSERT(parser.parse(
"<x type=\"form\" xmlns=\"jabber:x:data\">"
"<page label=\"P1\" xmlns=\"http://jabber.org/protocol/xdata-layout\">"
"<reportedref/>"
"<text>P1T1</text>"
"<fieldref var=\"P1F1\"/>"
"<section label=\"P1S1\">"
"<text>P1S1T1</text>"
"<fieldref var=\"P1S1F1\"/>"
"</section>"
"</page>"
"<page label=\"P2\" xmlns=\"http://jabber.org/protocol/xdata-layout\">"
"<section label=\"P2S1\">"
"<section label=\"P2S2\">"
"<section label=\"P2S3\"/>"
"</section>"
"</section>"
"</page>"
"<field label=\"field one\" type=\"text-single\" var=\"P1F1\"/>"
"<field label=\"field two\" type=\"text-single\" var=\"P1S1F1\"/>"
"</x>"));
Form* payload = dynamic_cast<Form*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getFields().size()));
// PAGE ONE - parsing of element types
CPPUNIT_ASSERT_EQUAL(std::string("P1"), payload->getPages()[0]->getLabel());
CPPUNIT_ASSERT(payload->getPages()[0]->getReportedRefs()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("P1T1"), payload->getPages()[0]->getTextElements()[0]->getTextString());
CPPUNIT_ASSERT_EQUAL(std::string("P1F1"), payload->getPages()[0]->getFields()[0]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("P1S1"), payload->getPages()[0]->getChildSections()[0]->getLabel());
CPPUNIT_ASSERT_EQUAL(std::string("P1S1T1"), payload->getPages()[0]->getChildSections()[0]->getTextElements()[0]->getTextString());
CPPUNIT_ASSERT_EQUAL(std::string("P1S1F1"), payload->getPages()[0]->getChildSections()[0]->getFields()[0]->getName());
// PAGE TWO - parsing of nested elements
CPPUNIT_ASSERT_EQUAL(std::string("P2"), payload->getPages()[1]->getLabel());
CPPUNIT_ASSERT_EQUAL(std::string("P2S1"), payload->getPages()[1]->getChildSections()[0]->getLabel());
CPPUNIT_ASSERT_EQUAL(std::string("P2S2"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getLabel());
CPPUNIT_ASSERT_EQUAL(std::string("P2S3"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getChildSections()[0]->getLabel());
}
void testParse() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
"<x type=\"form\" xmlns=\"jabber:x:data\">"
"<field type=\"hidden\" var=\"FORM_TYPE\">"
"<value>jabber:bot</value>"
"</field>"
"<field type=\"fixed\"><value>Section 1: Bot Info</value></field>"
"<field label=\"The name of your bot\" type=\"text-single\" var=\"botname\"/>"
"<field label=\"Helpful description of your bot\" type=\"text-multi\" var=\"description\"><value>This is a bot.</value><value>A quite good one actually</value></field>"
"<field label=\"Public bot?\" type=\"boolean\" var=\"public\">"
"<required/>"
"<value>1</value>"
@@ -99,60 +101,61 @@ class FormParserTest : public CppUnit::TestFixture {
"<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>"
"<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">"
"<option label=\"Contests\"><value>contests</value></option>"
"<option label=\"News\"><value>news</value></option>"
"<option label=\"Polls\"><value>polls</value></option>"
"<option label=\"Reminders\"><value>reminders</value></option>"
"<option label=\"Search\"><value>search</value></option>"
"<value>news</value>"
"<value>search</value>"
"</field>"
"<field label=\"Maximum number of subscribers\" type=\"list-single\" var=\"maxsubs\">"
"<value>20</value>"
"<option label=\"10\"><value>10</value></option>"
"<option label=\"20\"><value>20</value></option>"
"<option label=\"30\"><value>30</value></option>"
"<option label=\"50\"><value>50</value></option>"
"<option label=\"100\"><value>100</value></option>"
"<option label=\"None\"><value>none</value></option>"
"</field>"
"<field label=\"People to invite\" type=\"jid-multi\" var=\"invitelist\">"
"<desc>Tell all your friends about your new bot!</desc>"
"<value>foo@bar.com</value>"
"<value>baz@fum.org</value>"
"</field>"
"<field var=\"untyped\">"
"<value>foo</value>"
"</field>"
"</x>"));
Form* payload = dynamic_cast<Form*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
CPPUNIT_ASSERT_EQUAL(10, static_cast<int>(payload->getFields().size()));
CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), payload->getFields()[0]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("FORM_TYPE"), payload->getFields()[0]->getName());
CPPUNIT_ASSERT(!payload->getFields()[0]->getRequired());
CPPUNIT_ASSERT_EQUAL(std::string("Section 1: Bot Info"), payload->getFields()[1]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("The name of your bot"), payload->getFields()[2]->getLabel());
CPPUNIT_ASSERT_EQUAL(std::string("This is a bot.\nA quite good one actually"), payload->getFields()[3]->getTextMultiValue());
CPPUNIT_ASSERT_EQUAL(true, payload->getFields()[4]->getBoolValue());
CPPUNIT_ASSERT(payload->getFields()[4]->getRequired());
CPPUNIT_ASSERT_EQUAL(std::string("1"), payload->getFields()[4]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFields()[6]->getValues().size()));
CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("search"), payload->getFields()[6]->getValues()[1]);
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(payload->getFields()[6]->getOptions().size()));
CPPUNIT_ASSERT_EQUAL(std::string("Contests"), payload->getFields()[6]->getOptions()[0].label);
CPPUNIT_ASSERT_EQUAL(std::string("contests"), payload->getFields()[6]->getOptions()[0].value);
CPPUNIT_ASSERT_EQUAL(std::string("News"), payload->getFields()[6]->getOptions()[1].label);
CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getOptions()[1].value);
CPPUNIT_ASSERT_EQUAL(std::string("20"), payload->getFields()[7]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), payload->getFields()[8]->getJIDMultiValue(0));
CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), payload->getFields()[8]->getJIDMultiValue(1));
CPPUNIT_ASSERT_EQUAL(std::string("Tell all your friends about your new bot!"), payload->getFields()[8]->getDescription());