diff options
author | Kevin Smith <git@kismith.co.uk> | 2009-06-26 19:34:11 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2009-06-26 19:34:41 (GMT) |
commit | e2d9f9e47056a41d5e5a67ea3130ccdd860a06ed (patch) | |
tree | 75651c66869903c9a34d013d3553b123768c35a3 /Swift | |
parent | 649fc1d12d7be943b5ab964b9dac0670797d9057 (diff) | |
download | swift-contrib-e2d9f9e47056a41d5e5a67ea3130ccdd860a06ed.zip swift-contrib-e2d9f9e47056a41d5e5a67ea3130ccdd860a06ed.tar.bz2 |
Use nicks in tab titles.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/ChatController.cpp | 1 | ||||
-rw-r--r-- | Swift/Controllers/ChatWindow.h | 1 | ||||
-rw-r--r-- | Swift/Controllers/NickResolver.cpp | 5 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/NickResolverTest.cpp | 35 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.h | 1 |
6 files changed, 33 insertions, 15 deletions
diff --git a/Swift/Controllers/ChatController.cpp b/Swift/Controllers/ChatController.cpp index 32fc0c2..90e5567 100644 --- a/Swift/Controllers/ChatController.cpp +++ b/Swift/Controllers/ChatController.cpp @@ -16,6 +16,7 @@ ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQ : ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager) { nickResolver_ = nickResolver; presenceOracle_->onPresenceChange.connect(boost::bind(&ChatController::handlePresenceChange, this, _1, _2)); + chatWindow_->setName(nickResolver_->jidToNick(toJID_)); } bool ChatController::isIncomingMessageFromMe(boost::shared_ptr<Message>) { diff --git a/Swift/Controllers/ChatWindow.h b/Swift/Controllers/ChatWindow.h index dd71bf9..36788cf 100644 --- a/Swift/Controllers/ChatWindow.h +++ b/Swift/Controllers/ChatWindow.h @@ -22,6 +22,7 @@ namespace Swift { virtual void addSystemMessage(const String& message) = 0; virtual void addErrorMessage(const String& message) = 0; + virtual void setName(const String& name) = 0; virtual void show() = 0; virtual void setAvailableSecurityLabels(const std::vector<SecurityLabel>& labels) = 0; virtual void setSecurityLabelsEnabled(bool enabled) = 0; diff --git a/Swift/Controllers/NickResolver.cpp b/Swift/Controllers/NickResolver.cpp index db1d2b4..0886079 100644 --- a/Swift/Controllers/NickResolver.cpp +++ b/Swift/Controllers/NickResolver.cpp @@ -11,10 +11,11 @@ NickResolver::NickResolver(boost::shared_ptr<XMPPRoster> xmppRoster) { } String NickResolver::jidToNick(const JID& jid) { - if (xmppRoster_->containsJID(jid)) { + String nick; + if (xmppRoster_->containsJID(jid) && xmppRoster_->getNameForJID(jid) != "") { return xmppRoster_->getNameForJID(jid); } - std::map<JID, String>::iterator it = map_.find(jid); + std::map<JID, String>::const_iterator it = map_.find(jid); return (it == map_.end()) ? jid.toBare() : it->second; } diff --git a/Swift/Controllers/UnitTest/NickResolverTest.cpp b/Swift/Controllers/UnitTest/NickResolverTest.cpp index 947d3d8..e3123f9 100644 --- a/Swift/Controllers/UnitTest/NickResolverTest.cpp +++ b/Swift/Controllers/UnitTest/NickResolverTest.cpp @@ -10,6 +10,7 @@ class NickResolverTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(NickResolverTest); CPPUNIT_TEST(testNoMatch); + CPPUNIT_TEST(testZeroLengthMatch); CPPUNIT_TEST(testMatch); CPPUNIT_TEST(testOverwrittenMatch); CPPUNIT_TEST(testRemovedMatch); @@ -23,37 +24,45 @@ class NickResolverTest : public CppUnit::TestFixture void testNoMatch() { boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster()); NickResolver resolver(xmppRoster); - JID testling("foo@bar/baz"); + JID testJID("foo@bar/baz"); - CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testling)); + CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testJID)); + } + + void testZeroLengthMatch() { + boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster()); + NickResolver resolver(xmppRoster); + JID testJID("foo@bar/baz"); + xmppRoster->addContact(testJID, "", groups_); + CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testJID)); } void testMatch() { boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster()); NickResolver resolver(xmppRoster); - JID testling("foo@bar/baz"); - xmppRoster->addContact(testling, "Test", groups_); + JID testJID("foo@bar/baz"); + xmppRoster->addContact(testJID, "Test", groups_); - CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testling)); + CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testJID)); } void testOverwrittenMatch() { boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster()); NickResolver resolver(xmppRoster); - JID testling("foo@bar/baz"); - xmppRoster->addContact(testling, "FailTest", groups_); - xmppRoster->addContact(testling, "Test", groups_); + JID testJID("foo@bar/baz"); + xmppRoster->addContact(testJID, "FailTest", groups_); + xmppRoster->addContact(testJID, "Test", groups_); - CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testling)); + CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testJID)); } void testRemovedMatch() { boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster()); NickResolver resolver(xmppRoster); - JID testling("foo@bar/baz"); - xmppRoster->addContact(testling, "FailTest", groups_); - xmppRoster->removeContact(testling); - CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testling)); + JID testJID("foo@bar/baz"); + xmppRoster->addContact(testJID, "FailTest", groups_); + xmppRoster->removeContact(testJID); + CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testJID)); } }; diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 8e916c3..f4e0b0b 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -121,6 +121,11 @@ void QtChatWindow::setUnreadMessageCount(int count) { updateTitleWithUnreadCount(); } +void QtChatWindow::setName(const String& name) { + contact_ = P2QSTRING(name); + updateTitleWithUnreadCount(); +} + void QtChatWindow::updateTitleWithUnreadCount() { setWindowTitle(unreadCount_ > 0 ? QString("(%1) %2)").arg(unreadCount_).arg(contact_) : contact_); emit titleUpdated(); diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 20a53b9..6e45d34 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -29,6 +29,7 @@ namespace Swift { void setSecurityLabelsEnabled(bool enabled); void setSecurityLabelsError(); SecurityLabel getSelectedSecurityLabel(); + void setName(const String& name); protected slots: void qAppFocusChanged(QWidget* old, QWidget* now); |