From 3a8af7c9f9980485ebe5a8994b500eb860d0a232 Mon Sep 17 00:00:00 2001 From: urnenfeld Date: Fri, 28 May 2010 22:38:16 +0000 Subject: [PATCH] Forwarding messages to ChatWindow Added stringview as status feedback --- application/ChatWindow.cpp | 27 +++++++++++++++++++-------- application/ChatWindow.h | 7 +++++-- application/Server.cpp | 18 ++++++++++-------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/application/ChatWindow.cpp b/application/ChatWindow.cpp index abe58e6..211c619 100644 --- a/application/ChatWindow.cpp +++ b/application/ChatWindow.cpp @@ -45,18 +45,21 @@ ChatWindow::ChatWindow(ContactLinker* cl) fSendView = new BTextView("fReceiveView"); BScrollView* scrollViewSend = new BScrollView("scrollviewS", fSendView, - B_WILL_DRAW, false, true); + B_WILL_DRAW, false, true); fSendView->SetWordWrap(true); AddCommonFilter(new EditingFilter(fSendView)); fSendView->MakeFocus(true); + fStatus = new BStringView("status", ""); + SetLayout(new BGroupLayout(B_HORIZONTAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) .Add(scrollViewReceive, 2) .Add(scrollViewSend) + .Add(fStatus) .SetInsets(5, 5, 5, 5) - ); + ); MoveTo(BAlert::AlertPosition(Bounds().Width(), Bounds().Height() / 2)); @@ -101,7 +104,7 @@ ChatWindow::MessageReceived(BMessage* message) default: BWindow::MessageReceived(message); break; - } + } } @@ -115,7 +118,15 @@ ChatWindow::ImMessage(BMessage* msg) BString message = msg->FindString("body"); fReceiveView->AppendOtherMessage(message.String()); break; - } + } + case IM_CONTACT_STARTED_TYPING: + fStatus->SetText("Buddy is typing ..."); + break; + + case IM_CONTACT_STOPPED_TYPING: + fStatus->SetText(""); + break; + default: break; } @@ -143,7 +154,7 @@ void ChatWindow::ObservePointer(int32 what, void* ptr) { switch (what) { - case PTR_AVATAR_BITMAP: + case PTR_AVATAR_BITMAP: break; } } @@ -163,9 +174,9 @@ ChatWindow::ObserveInteger(int32 what, int32 val) } -void +void ChatWindow::AppendStatus(CayaStatus status) -{ +{ BString message(fContactLinker->GetName()); switch (status) { @@ -180,7 +191,7 @@ ChatWindow::AppendStatus(CayaStatus status) message << " is busy, please do not disturb!"; break; case CAYA_OFFLINE: - message << " is offline"; + message << " is offline"; break; default: break; diff --git a/application/ChatWindow.h b/application/ChatWindow.h index d8e2f95..8648bc2 100644 --- a/application/ChatWindow.h +++ b/application/ChatWindow.h @@ -4,9 +4,10 @@ */ #ifndef _CHAT_WINDOW_H #define _CHAT_WINDOW_H - + #include #include +#include #include "Observer.h" #include "CayaConstants.h" @@ -30,8 +31,10 @@ public: private: BTextView* fSendView; - ContactLinker* fContactLinker; + ContactLinker* fContactLinker; CayaRenderView* fReceiveView; + BStringView* fStatus; + }; #endif // _CHAT_WINDOW_H diff --git a/application/Server.cpp b/application/Server.cpp index 8561f33..a33279e 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -37,7 +37,7 @@ Server::Server() void Server::Quit() { - ContactLinker* linker = NULL; + ContactLinker* linker = NULL; while ((linker = fRosterMap.ValueAt(0))) { linker->DeleteWindow(); @@ -139,7 +139,7 @@ Server::Filter(BMessage* message, BHandler **target) ContactLinker* item = fRosterMap.ValueFor(id, &found); if (found) - item->HideWindow(); + item->HideWindow(); } result = B_SKIP_MESSAGE; break; @@ -152,7 +152,7 @@ Server::Filter(BMessage* message, BHandler **target) break; } - return result; + return result; } @@ -163,18 +163,18 @@ Server::RosterItems() const } -RosterItem* +RosterItem* Server::RosterItemForId(BString id) { bool found = false; ContactLinker* item = fRosterMap.ValueFor(id, &found); - return item ? item->GetRosterItem() : NULL; + return item ? item->GetRosterItem() : NULL; } filter_result Server::ImMessage(BMessage* msg) -{ +{ filter_result result = B_DISPATCH_MESSAGE; int32 im_what = msg->FindInt32("im_what"); @@ -274,6 +274,8 @@ Server::ImMessage(BMessage* msg) break; } case IM_MESSAGE_RECEIVED: + case IM_CONTACT_STARTED_TYPING: + case IM_CONTACT_STOPPED_TYPING: { BString id = msg->FindString("id"); if (id.Length() > 0) { @@ -296,7 +298,7 @@ Server::ImMessage(BMessage* msg) } -ContactLinker* +ContactLinker* Server::GetOwnContact() { return fMySelf; @@ -323,7 +325,7 @@ Server::_LooperFromMessage(BMessage* message) } -ContactLinker* +ContactLinker* Server::_EnsureContactLinker(BMessage* message) { if (!message)