Forwarding messages to ChatWindow

Added stringview as status feedback
This commit is contained in:
urnenfeld 2010-05-28 22:38:16 +00:00
parent ff80897441
commit 3a8af7c9f9
3 changed files with 34 additions and 18 deletions

View File

@ -45,18 +45,21 @@ ChatWindow::ChatWindow(ContactLinker* cl)
fSendView = new BTextView("fReceiveView"); fSendView = new BTextView("fReceiveView");
BScrollView* scrollViewSend = new BScrollView("scrollviewS", fSendView, BScrollView* scrollViewSend = new BScrollView("scrollviewS", fSendView,
B_WILL_DRAW, false, true); B_WILL_DRAW, false, true);
fSendView->SetWordWrap(true); fSendView->SetWordWrap(true);
AddCommonFilter(new EditingFilter(fSendView)); AddCommonFilter(new EditingFilter(fSendView));
fSendView->MakeFocus(true); fSendView->MakeFocus(true);
fStatus = new BStringView("status", "");
SetLayout(new BGroupLayout(B_HORIZONTAL)); SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
.Add(scrollViewReceive, 2) .Add(scrollViewReceive, 2)
.Add(scrollViewSend) .Add(scrollViewSend)
.Add(fStatus)
.SetInsets(5, 5, 5, 5) .SetInsets(5, 5, 5, 5)
); );
MoveTo(BAlert::AlertPosition(Bounds().Width(), Bounds().Height() / 2)); MoveTo(BAlert::AlertPosition(Bounds().Width(), Bounds().Height() / 2));
@ -101,7 +104,7 @@ ChatWindow::MessageReceived(BMessage* message)
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
} }
} }
@ -115,7 +118,15 @@ ChatWindow::ImMessage(BMessage* msg)
BString message = msg->FindString("body"); BString message = msg->FindString("body");
fReceiveView->AppendOtherMessage(message.String()); fReceiveView->AppendOtherMessage(message.String());
break; break;
} }
case IM_CONTACT_STARTED_TYPING:
fStatus->SetText("Buddy is typing ...");
break;
case IM_CONTACT_STOPPED_TYPING:
fStatus->SetText("");
break;
default: default:
break; break;
} }
@ -143,7 +154,7 @@ void
ChatWindow::ObservePointer(int32 what, void* ptr) ChatWindow::ObservePointer(int32 what, void* ptr)
{ {
switch (what) { switch (what) {
case PTR_AVATAR_BITMAP: case PTR_AVATAR_BITMAP:
break; break;
} }
} }
@ -163,9 +174,9 @@ ChatWindow::ObserveInteger(int32 what, int32 val)
} }
void void
ChatWindow::AppendStatus(CayaStatus status) ChatWindow::AppendStatus(CayaStatus status)
{ {
BString message(fContactLinker->GetName()); BString message(fContactLinker->GetName());
switch (status) { switch (status) {
@ -180,7 +191,7 @@ ChatWindow::AppendStatus(CayaStatus status)
message << " is busy, please do not disturb!"; message << " is busy, please do not disturb!";
break; break;
case CAYA_OFFLINE: case CAYA_OFFLINE:
message << " is offline"; message << " is offline";
break; break;
default: default:
break; break;

View File

@ -4,9 +4,10 @@
*/ */
#ifndef _CHAT_WINDOW_H #ifndef _CHAT_WINDOW_H
#define _CHAT_WINDOW_H #define _CHAT_WINDOW_H
#include <Window.h> #include <Window.h>
#include <TextView.h> #include <TextView.h>
#include <StringView.h>
#include "Observer.h" #include "Observer.h"
#include "CayaConstants.h" #include "CayaConstants.h"
@ -30,8 +31,10 @@ public:
private: private:
BTextView* fSendView; BTextView* fSendView;
ContactLinker* fContactLinker; ContactLinker* fContactLinker;
CayaRenderView* fReceiveView; CayaRenderView* fReceiveView;
BStringView* fStatus;
}; };
#endif // _CHAT_WINDOW_H #endif // _CHAT_WINDOW_H

View File

@ -37,7 +37,7 @@ Server::Server()
void void
Server::Quit() Server::Quit()
{ {
ContactLinker* linker = NULL; ContactLinker* linker = NULL;
while ((linker = fRosterMap.ValueAt(0))) { while ((linker = fRosterMap.ValueAt(0))) {
linker->DeleteWindow(); linker->DeleteWindow();
@ -139,7 +139,7 @@ Server::Filter(BMessage* message, BHandler **target)
ContactLinker* item = fRosterMap.ValueFor(id, &found); ContactLinker* item = fRosterMap.ValueFor(id, &found);
if (found) if (found)
item->HideWindow(); item->HideWindow();
} }
result = B_SKIP_MESSAGE; result = B_SKIP_MESSAGE;
break; break;
@ -152,7 +152,7 @@ Server::Filter(BMessage* message, BHandler **target)
break; break;
} }
return result; return result;
} }
@ -163,18 +163,18 @@ Server::RosterItems() const
} }
RosterItem* RosterItem*
Server::RosterItemForId(BString id) Server::RosterItemForId(BString id)
{ {
bool found = false; bool found = false;
ContactLinker* item = fRosterMap.ValueFor(id, &found); ContactLinker* item = fRosterMap.ValueFor(id, &found);
return item ? item->GetRosterItem() : NULL; return item ? item->GetRosterItem() : NULL;
} }
filter_result filter_result
Server::ImMessage(BMessage* msg) Server::ImMessage(BMessage* msg)
{ {
filter_result result = B_DISPATCH_MESSAGE; filter_result result = B_DISPATCH_MESSAGE;
int32 im_what = msg->FindInt32("im_what"); int32 im_what = msg->FindInt32("im_what");
@ -274,6 +274,8 @@ Server::ImMessage(BMessage* msg)
break; break;
} }
case IM_MESSAGE_RECEIVED: case IM_MESSAGE_RECEIVED:
case IM_CONTACT_STARTED_TYPING:
case IM_CONTACT_STOPPED_TYPING:
{ {
BString id = msg->FindString("id"); BString id = msg->FindString("id");
if (id.Length() > 0) { if (id.Length() > 0) {
@ -296,7 +298,7 @@ Server::ImMessage(BMessage* msg)
} }
ContactLinker* ContactLinker*
Server::GetOwnContact() Server::GetOwnContact()
{ {
return fMySelf; return fMySelf;
@ -323,7 +325,7 @@ Server::_LooperFromMessage(BMessage* message)
} }
ContactLinker* ContactLinker*
Server::_EnsureContactLinker(BMessage* message) Server::_EnsureContactLinker(BMessage* message)
{ {
if (!message) if (!message)