Improved the behaviour to don't get focus when a message is received or the user is typing, from that rev the chat window will appear on the screen without leaving the focus of your current application. But there are two exeptions...when a window is created the first time or the user open it from the contacts list it will get focus. Other little fixes, changed variable names and style.

This commit is contained in:
barrett 2012-06-07 16:46:07 +00:00
parent d661379bc4
commit 92f2ee4547
10 changed files with 97 additions and 53 deletions

View File

@ -96,6 +96,20 @@ ChatWindow::ChatWindow(ContactLinker* cl)
} }
void
ChatWindow::ShowWindow()
{
if (IsHidden())
Show();
if (IsMinimized())
Minimize(false);
if (!IsActive())
Activate(true);
}
bool bool
ChatWindow::QuitRequested() ChatWindow::QuitRequested()
{ {
@ -153,6 +167,7 @@ ChatWindow::MessageReceived(BMessage* message)
case IM_MESSAGE: case IM_MESSAGE:
ImMessage(message); ImMessage(message);
break; break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@ -265,3 +280,16 @@ ChatWindow::AppendStatus(CayaStatus status)
fReceiveView->Append("\n", COL_TEXT, COL_TEXT, R_TEXT); fReceiveView->Append("\n", COL_TEXT, COL_TEXT, R_TEXT);
fReceiveView->ScrollToSelection(); fReceiveView->ScrollToSelection();
} }
void
ChatWindow::AvoidFocus(bool avoid)
{
// This is needed to avoid the window focus when
// a new message is received, since it could be a lot annoying
// for the user
if (avoid)
SetFlags(B_AVOID_FOCUS);
else
SetFlags(Flags() &~ B_AVOID_FOCUS);
}

View File

@ -20,6 +20,8 @@ class ChatWindow : public BWindow, public Observer {
public: public:
ChatWindow(ContactLinker* cl); ChatWindow(ContactLinker* cl);
virtual void ShowWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested(); virtual bool QuitRequested();
@ -32,6 +34,7 @@ public:
void ObserveInteger(int32 what, int32 val); void ObserveInteger(int32 what, int32 val);
void AppendStatus(CayaStatus status); void AppendStatus(CayaStatus status);
void AvoidFocus(bool avoid);
private: private:
BTextView* fSendView; BTextView* fSendView;
ContactLinker* fContactLinker; ContactLinker* fContactLinker;

View File

@ -34,7 +34,8 @@ ContactLinker::ContactLinker(BString id, BMessenger msgn)
fMessenger(msgn), fMessenger(msgn),
fLooper(NULL), fLooper(NULL),
fStatus(CAYA_OFFLINE), fStatus(CAYA_OFFLINE),
fPopUp(NULL) fPopUp(NULL),
fNewWindow(true)
{ {
// Create the roster item and register it as observer // Create the roster item and register it as observer
fRosterItem = new RosterItem(id.String(), this); fRosterItem = new RosterItem(id.String(), this);
@ -59,29 +60,38 @@ ContactLinker::DeleteWindow()
UnregisterObserver(fChatWindow); UnregisterObserver(fChatWindow);
fChatWindow->Quit(); fChatWindow->Quit();
fChatWindow = NULL; fChatWindow = NULL;
fNewWindow = true;
} }
} }
} }
void void
ContactLinker::ShowWindow() ContactLinker::ShowWindow(bool typing, bool userAction)
{ {
if (fChatWindow == NULL) if (fChatWindow == NULL)
CreateChatWindow(); CreateChatWindow();
fChatWindow->AvoidFocus(true);
if (CayaPreferences::Item()->MoveToCurrentWorkspace) if (CayaPreferences::Item()->MoveToCurrentWorkspace)
fChatWindow->SetWorkspaces(B_CURRENT_WORKSPACE); fChatWindow->SetWorkspaces(B_CURRENT_WORKSPACE);
if (fChatWindow->IsHidden()) if (fNewWindow || userAction) {
fChatWindow->Show(); fChatWindow->AvoidFocus(false);
fChatWindow->ShowWindow();
if (fChatWindow->IsMinimized()) fNewWindow = false;
fChatWindow->Minimize(false); } else {
if (typing) {
if (CayaPreferences::Item()->FocusOnMessageReceived == true if (CayaPreferences::Item()->RaiseUserIsTyping)
|| CayaPreferences::Item()->FocusUserIsTyping == true) fChatWindow->ShowWindow();
fChatWindow->Activate(true); } else {
if (CayaPreferences::Item()->RaiseOnMessageReceived
|| fChatWindow->IsHidden())
fChatWindow->ShowWindow();
}
}
fChatWindow->AvoidFocus(false);
} }

View File

@ -27,7 +27,7 @@ public:
ChatWindow* GetChatWindow(); ChatWindow* GetChatWindow();
void DeleteWindow(); void DeleteWindow();
void ShowWindow(); void ShowWindow(bool typing = false, bool userAction = false);
void HideWindow(); void HideWindow();
void ShowPopUp(BPoint where); void ShowPopUp(BPoint where);
@ -70,6 +70,8 @@ private:
BBitmap* fAvatarBitmap; BBitmap* fAvatarBitmap;
CayaStatus fStatus; CayaStatus fStatus;
ContactPopUp* fPopUp; ContactPopUp* fPopUp;
bool fNewWindow;
}; };
#endif // _CONTACT_LINKER_H_ #endif // _CONTACT_LINKER_H_

View File

@ -137,7 +137,8 @@ void
MainWindow::MessageReceived(BMessage* message) MainWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kSearchContact: { case kSearchContact:
{
void* control = NULL; void* control = NULL;
if (message->FindPointer("source", &control) != B_OK) if (message->FindPointer("source", &control) != B_OK)
return; return;
@ -165,16 +166,18 @@ MainWindow::MessageReceived(BMessage* message)
} }
break; break;
} }
case CAYA_SHOW_SETTINGS: { case CAYA_SHOW_SETTINGS:
{
PreferencesDialog* dialog = new PreferencesDialog(); PreferencesDialog* dialog = new PreferencesDialog();
dialog->Show(); dialog->Show();
break; break;
} }
case CAYA_OPEN_CHAT_WINDOW: { case CAYA_OPEN_CHAT_WINDOW:
{
int index = message->FindInt32("index"); int index = message->FindInt32("index");
RosterItem* ritem = ItemAt(index); RosterItem* ritem = ItemAt(index);
if (ritem != NULL) if (ritem != NULL)
ritem->GetContactLinker()->ShowWindow(); ritem->GetContactLinker()->ShowWindow(false, true);
break; break;
} }

View File

@ -321,8 +321,7 @@ Server::ImMessage(BMessage* msg)
ContactLinker* item = fRosterMap.ValueFor(id, &found); ContactLinker* item = fRosterMap.ValueFor(id, &found);
if (found) { if (found) {
ChatWindow* win = item->GetChatWindow(); ChatWindow* win = item->GetChatWindow();
if (CayaPreferences::Item()->FocusOnMessageReceived) item->ShowWindow();
item->ShowWindow();
win->PostMessage(msg); win->PostMessage(msg);
} }
} }
@ -338,8 +337,7 @@ Server::ImMessage(BMessage* msg)
ContactLinker* item = fRosterMap.ValueFor(id, &found); ContactLinker* item = fRosterMap.ValueFor(id, &found);
if (found) { if (found) {
ChatWindow* win = item->GetChatWindow(); ChatWindow* win = item->GetChatWindow();
if (CayaPreferences::Item()->FocusUserIsTyping) item->ShowWindow(true);
item->ShowWindow();
win->PostMessage(msg); win->PostMessage(msg);
} }
} }

View File

@ -14,8 +14,8 @@ template<> const char* CayaPreferences::fFilename = "preferences";
CayaPreferencesData::CayaPreferencesData() CayaPreferencesData::CayaPreferencesData()
: :
MoveToCurrentWorkspace(true), MoveToCurrentWorkspace(true),
FocusOnMessageReceived(false), RaiseOnMessageReceived(false),
FocusUserIsTyping(false), RaiseUserIsTyping(false),
HideCayaDeskbar(false), HideCayaDeskbar(false),
DisableReplicant(true), DisableReplicant(true),
IgnoreEmoticons(false), IgnoreEmoticons(false),
@ -78,8 +78,8 @@ CayaPreferencesData::Flatten(BPositionIO* flatData) const
// Behaviour // Behaviour
_AddBool(flatData, MoveToCurrentWorkspace); _AddBool(flatData, MoveToCurrentWorkspace);
_AddBool(flatData, FocusOnMessageReceived); _AddBool(flatData, RaiseOnMessageReceived);
_AddBool(flatData, FocusUserIsTyping); _AddBool(flatData, RaiseUserIsTyping);
_AddBool(flatData, NotifyProtocolStatus); _AddBool(flatData, NotifyProtocolStatus);
_AddBool(flatData, NotifyContactStatus); _AddBool(flatData, NotifyContactStatus);
@ -142,8 +142,8 @@ CayaPreferencesData::Unflatten(type_code code, BPositionIO* flatData)
// Behaviour // Behaviour
MoveToCurrentWorkspace = _ReadBool(flatData); MoveToCurrentWorkspace = _ReadBool(flatData);
FocusOnMessageReceived = _ReadBool(flatData); RaiseOnMessageReceived = _ReadBool(flatData);
FocusUserIsTyping = _ReadBool(flatData); RaiseUserIsTyping = _ReadBool(flatData);
NotifyProtocolStatus = _ReadBool(flatData); NotifyProtocolStatus = _ReadBool(flatData);
NotifyContactStatus = _ReadBool(flatData); NotifyContactStatus = _ReadBool(flatData);

View File

@ -26,8 +26,8 @@ public:
status_t Unflatten(type_code code, BPositionIO* flatData); status_t Unflatten(type_code code, BPositionIO* flatData);
bool MoveToCurrentWorkspace; bool MoveToCurrentWorkspace;
bool FocusOnMessageReceived; bool RaiseOnMessageReceived;
bool FocusUserIsTyping; bool RaiseUserIsTyping;
bool NotifyProtocolStatus; bool NotifyProtocolStatus;
bool NotifyContactStatus; bool NotifyContactStatus;

View File

@ -24,8 +24,8 @@
#include "TheApp.h" #include "TheApp.h"
const uint32 kToCurrentWorkspace = 'CBcw'; const uint32 kToCurrentWorkspace = 'CBcw';
const uint32 kFocusOnMessageReceived= 'FCmr'; const uint32 kRaiseOnMessageReceived = 'FCmr';
const uint32 kFocusUserIsTyping = 'FCit'; const uint32 kRaiseUserIsTyping = 'FCit';
const uint32 kNotifyProtocolsLogin = 'NTpl'; const uint32 kNotifyProtocolsLogin = 'NTpl';
const uint32 kNotifyContactStatus = 'NTcl'; const uint32 kNotifyContactStatus = 'NTcl';
@ -42,13 +42,13 @@ PreferencesBehavior::PreferencesBehavior()
"Move window to current workspace", "Move window to current workspace",
new BMessage(kToCurrentWorkspace)); new BMessage(kToCurrentWorkspace));
fFocusOnMessageReceived = new BCheckBox("FocusOnMessageReceived", fRaiseOnMessageReceived = new BCheckBox("FocusOnMessageReceived",
"Get focus when a message is received", "Auto-raise when a message is received",
new BMessage(kFocusOnMessageReceived)); new BMessage(kRaiseOnMessageReceived));
fFocusUserIsTyping = new BCheckBox("FocusUserIsTyping", fRaiseUserIsTyping = new BCheckBox("FocusUserIsTyping",
"Get focus when user is typing", "Auto-raise when user is typing",
new BMessage(kFocusUserIsTyping)); new BMessage(kRaiseUserIsTyping));
fPlaySoundOnMessageReceived = new BCheckBox("PlaySoundOnMessageReceived", fPlaySoundOnMessageReceived = new BCheckBox("PlaySoundOnMessageReceived",
"Play sound event", NULL); "Play sound event", NULL);
@ -82,8 +82,8 @@ PreferencesBehavior::PreferencesBehavior()
.Add(fOnIncoming) .Add(fOnIncoming)
.AddGroup(B_VERTICAL, spacing) .AddGroup(B_VERTICAL, spacing)
.Add(fToCurrentWorkspace) .Add(fToCurrentWorkspace)
.Add(fFocusOnMessageReceived) .Add(fRaiseOnMessageReceived)
.Add(fFocusUserIsTyping) .Add(fRaiseUserIsTyping)
.Add(fMarkUnreadWindow) .Add(fMarkUnreadWindow)
.Add(fMarkUnreadReplicant) .Add(fMarkUnreadReplicant)
.Add(fPlaySoundOnMessageReceived) .Add(fPlaySoundOnMessageReceived)
@ -106,17 +106,17 @@ void
PreferencesBehavior::AttachedToWindow() PreferencesBehavior::AttachedToWindow()
{ {
fToCurrentWorkspace->SetTarget(this); fToCurrentWorkspace->SetTarget(this);
fFocusUserIsTyping->SetTarget(this); fRaiseUserIsTyping->SetTarget(this);
fFocusOnMessageReceived->SetTarget(this); fRaiseOnMessageReceived->SetTarget(this);
fNotifyProtocols->SetTarget(this); fNotifyProtocols->SetTarget(this);
fNotifyContactStatus->SetTarget(this); fNotifyContactStatus->SetTarget(this);
fToCurrentWorkspace->SetValue( fToCurrentWorkspace->SetValue(
CayaPreferences::Item()->MoveToCurrentWorkspace); CayaPreferences::Item()->MoveToCurrentWorkspace);
fFocusUserIsTyping->SetValue( fRaiseUserIsTyping->SetValue(
CayaPreferences::Item()->FocusUserIsTyping); CayaPreferences::Item()->RaiseUserIsTyping);
fFocusOnMessageReceived->SetValue( fRaiseOnMessageReceived->SetValue(
CayaPreferences::Item()->FocusOnMessageReceived); CayaPreferences::Item()->RaiseOnMessageReceived);
fNotifyProtocols->SetValue( fNotifyProtocols->SetValue(
CayaPreferences::Item()->NotifyProtocolStatus); CayaPreferences::Item()->NotifyProtocolStatus);
fNotifyContactStatus->SetValue( fNotifyContactStatus->SetValue(
@ -132,13 +132,13 @@ PreferencesBehavior::MessageReceived(BMessage* message)
CayaPreferences::Item()->MoveToCurrentWorkspace CayaPreferences::Item()->MoveToCurrentWorkspace
= fToCurrentWorkspace->Value(); = fToCurrentWorkspace->Value();
break; break;
case kFocusOnMessageReceived: case kRaiseOnMessageReceived:
CayaPreferences::Item()->FocusOnMessageReceived CayaPreferences::Item()->RaiseOnMessageReceived
= fFocusOnMessageReceived->Value(); = fRaiseOnMessageReceived->Value();
break; break;
case kFocusUserIsTyping: case kRaiseUserIsTyping:
CayaPreferences::Item()->FocusUserIsTyping CayaPreferences::Item()->RaiseUserIsTyping
= fFocusUserIsTyping->Value(); = fRaiseUserIsTyping->Value();
break; break;
case kNotifyProtocolsLogin: case kNotifyProtocolsLogin:
CayaPreferences::Item()->NotifyProtocolStatus CayaPreferences::Item()->NotifyProtocolStatus

View File

@ -22,8 +22,8 @@ private:
BStringView* fOnIncoming; BStringView* fOnIncoming;
BCheckBox* fToCurrentWorkspace; BCheckBox* fToCurrentWorkspace;
BCheckBox* fFocusOnMessageReceived; BCheckBox* fRaiseOnMessageReceived;
BCheckBox* fFocusUserIsTyping; BCheckBox* fRaiseUserIsTyping;
BCheckBox* fPlaySoundOnMessageReceived; BCheckBox* fPlaySoundOnMessageReceived;
BCheckBox* fMarkUnreadWindow; BCheckBox* fMarkUnreadWindow;
BCheckBox* fMarkUnreadReplicant; BCheckBox* fMarkUnreadReplicant;