2010-05-07 04:47:10 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Pier Luigi Fiorini. All rights reserved.
|
2021-08-03 13:19:25 -05:00
|
|
|
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
2010-05-07 04:47:10 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
2021-08-03 13:19:25 -05:00
|
|
|
* Jaidyn Levesque, jadedctrl@teknik.io
|
2010-05-07 04:47:10 -05:00
|
|
|
*/
|
|
|
|
|
2021-05-19 16:12:19 -05:00
|
|
|
#include "StatusView.h"
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
#include <Bitmap.h>
|
2021-05-29 15:47:54 -05:00
|
|
|
#include <LayoutBuilder.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
#include <Message.h>
|
|
|
|
#include <PopUpMenu.h>
|
|
|
|
|
|
|
|
#include <libinterface/BitmapMenuItem.h>
|
2010-05-08 11:21:36 -05:00
|
|
|
#include <libinterface/BitmapUtils.h>
|
2021-05-19 16:12:19 -05:00
|
|
|
#include <libinterface/BitmapView.h>
|
2021-08-03 13:19:25 -05:00
|
|
|
#include <libinterface/EnterTextView.h>
|
2021-08-02 21:59:44 -05:00
|
|
|
#include <libinterface/MenuButton.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-08-03 13:19:25 -05:00
|
|
|
#include "AccountsMenu.h"
|
2021-08-02 21:59:44 -05:00
|
|
|
#include "ChatProtocolMessages.h"
|
2021-08-03 13:19:25 -05:00
|
|
|
#include "Contact.h"
|
2021-07-13 14:43:48 -05:00
|
|
|
#include "ImageCache.h"
|
2021-08-03 13:19:25 -05:00
|
|
|
#include "NotifyMessage.h"
|
2021-08-02 21:59:44 -05:00
|
|
|
#include "Server.h"
|
2021-08-16 10:40:18 -05:00
|
|
|
#include "StatusManager.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "StatusMenuItem.h"
|
2021-06-20 12:44:20 -05:00
|
|
|
#include "Utils.h"
|
2021-05-19 16:12:19 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-08-02 21:59:44 -05:00
|
|
|
const int32 kSelectAccount = 'SVsa';
|
2021-08-03 13:19:25 -05:00
|
|
|
const int32 kSetNick = 'SVsn';
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
|
2022-02-23 15:42:46 -06:00
|
|
|
StatusView::StatusView(const char* name)
|
2010-05-30 03:51:19 -05:00
|
|
|
:
|
2021-08-02 21:59:44 -05:00
|
|
|
BView(name, B_WILL_DRAW),
|
2021-08-03 13:19:25 -05:00
|
|
|
fAccount(-1)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
// Nick name
|
2021-08-03 16:05:57 -05:00
|
|
|
fNickname = new EnterTextView("nicknameTextView", be_bold_font, NULL);
|
2021-08-03 13:19:25 -05:00
|
|
|
fNickname->MakeEditable(true);
|
|
|
|
fNickname->MakeResizable(true);
|
|
|
|
fNickname->SetTarget(this);
|
|
|
|
fNickname->SetMessage(BMessage(kSetNick), "nick");
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
// Status menu
|
|
|
|
fStatusMenu = new BPopUpMenu("-");
|
|
|
|
|
|
|
|
// Add status menu items
|
2021-06-20 12:44:20 -05:00
|
|
|
int32 s = STATUS_ONLINE;
|
|
|
|
while (s >= STATUS_ONLINE && s < STATUS_STATUSES) {
|
|
|
|
StatusMenuItem* item = new StatusMenuItem(UserStatusToString(
|
|
|
|
(UserStatus)s), (UserStatus)s);
|
2010-05-07 04:47:10 -05:00
|
|
|
fStatusMenu->AddItem(item);
|
|
|
|
|
2012-05-15 11:48:53 -05:00
|
|
|
/*// Add items for custom messages
|
2021-06-20 12:44:20 -05:00
|
|
|
if (s == STATUS_ONLINE || s == STATUS_DO_NOT_DISTURB) {
|
|
|
|
item = new StatusMenuItem("Custom...", (UserStatus)s, true);
|
2010-05-07 04:47:10 -05:00
|
|
|
fStatusMenu->AddItem(item);
|
|
|
|
fStatusMenu->AddItem(new BSeparatorItem());
|
2012-05-15 11:48:53 -05:00
|
|
|
}*/
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
// Mark offline status by default
|
2021-06-20 12:44:20 -05:00
|
|
|
if (s == STATUS_OFFLINE)
|
2010-05-07 04:47:10 -05:00
|
|
|
item->SetMarked(true);
|
|
|
|
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Menu field
|
2010-05-30 03:51:19 -05:00
|
|
|
BMenuField* statusField = new BMenuField("StatusField", NULL,
|
2012-02-24 20:46:55 -06:00
|
|
|
fStatusMenu);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
// Icon
|
2010-05-30 03:51:19 -05:00
|
|
|
fAvatar = new BitmapView("AvatarIcon");
|
2010-05-20 13:11:32 -05:00
|
|
|
fAvatar->SetExplicitMaxSize(BSize(50, 50));
|
|
|
|
fAvatar->SetExplicitPreferredSize(BSize(50, 50));
|
2021-07-13 14:43:48 -05:00
|
|
|
fAvatar->SetBitmap(ImageCache::Get()->GetImage("kPersonIcon"));
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-08-02 21:59:44 -05:00
|
|
|
// Changing the account used
|
2021-08-03 13:19:25 -05:00
|
|
|
fAccountsMenu = new AccountsMenu("statusAccountsMenu",
|
2022-02-23 15:42:46 -06:00
|
|
|
BMessage(kSelectAccount), new BMessage(kSelectAccount));
|
2021-08-02 21:59:44 -05:00
|
|
|
fAccountsButton = new MenuButton("statusAccountsButton", "", new BMessage());
|
|
|
|
fAccountsButton->SetMenu(fAccountsMenu);
|
|
|
|
|
2021-08-03 13:19:25 -05:00
|
|
|
BMessage selected(kSelectAccount);
|
2021-08-02 21:59:44 -05:00
|
|
|
MessageReceived(&selected);
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
// Set layout
|
2021-08-02 21:59:44 -05:00
|
|
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
|
|
|
.AddGroup(B_HORIZONTAL)
|
|
|
|
.SetInsets(0)
|
2010-05-07 04:47:10 -05:00
|
|
|
.Add(statusField)
|
2021-08-02 21:59:44 -05:00
|
|
|
.Add(fAccountsButton)
|
|
|
|
.End()
|
|
|
|
.AddGroup(B_HORIZONTAL)
|
|
|
|
.Add(fNickname)
|
|
|
|
.Add(fAvatar)
|
2010-05-07 04:47:10 -05:00
|
|
|
.End()
|
2021-05-29 15:47:54 -05:00
|
|
|
.End();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusView::AttachedToWindow()
|
|
|
|
{
|
2012-05-15 11:48:53 -05:00
|
|
|
//fNickname->SetTarget(this);
|
2010-05-07 04:47:10 -05:00
|
|
|
fStatusMenu->SetTargetForItems(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusView::MessageReceived(BMessage* msg)
|
|
|
|
{
|
|
|
|
switch (msg->what) {
|
2021-08-03 13:19:25 -05:00
|
|
|
case kSetNick:
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2021-08-03 13:19:25 -05:00
|
|
|
BString nick;
|
|
|
|
if (msg->FindString("nick", &nick) == B_OK)
|
2021-08-16 10:40:18 -05:00
|
|
|
StatusManager::Get()->SetNickname(nick, fAccount);
|
2021-08-03 13:19:25 -05:00
|
|
|
_SetToAccount();
|
2010-05-07 04:47:10 -05:00
|
|
|
break;
|
2012-09-25 16:45:29 -05:00
|
|
|
}
|
2010-05-07 04:47:10 -05:00
|
|
|
case kSetStatus:
|
|
|
|
{
|
|
|
|
int32 status;
|
2021-08-03 13:19:25 -05:00
|
|
|
if (msg->FindInt32("status", &status) == B_OK)
|
2021-08-16 10:40:18 -05:00
|
|
|
StatusManager::Get()->SetStatus((UserStatus)status, "",
|
2021-08-03 13:19:25 -05:00
|
|
|
fAccount);
|
|
|
|
_SetToAccount();
|
2010-05-07 04:47:10 -05:00
|
|
|
break;
|
|
|
|
}
|
2021-08-02 21:59:44 -05:00
|
|
|
case kSelectAccount:
|
|
|
|
{
|
2021-08-03 13:19:25 -05:00
|
|
|
int32 index = msg->GetInt32("index", 0);
|
2021-08-02 21:59:44 -05:00
|
|
|
BitmapMenuItem* item = (BitmapMenuItem*)fAccountsMenu->ItemAt(index);
|
2021-08-03 13:19:25 -05:00
|
|
|
|
|
|
|
// Set button icon/label
|
|
|
|
fAccountsButton->SetLabel("");
|
2021-08-02 21:59:44 -05:00
|
|
|
BBitmap* bitmap = item->Bitmap();
|
|
|
|
fAccountsButton->SetIcon(bitmap);
|
2021-08-03 13:19:25 -05:00
|
|
|
if (bitmap == NULL) {
|
|
|
|
char label[2] = { item->Label()[0], '\0' };
|
|
|
|
fAccountsButton->SetLabel(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
fAccount = msg->GetInt64("instance", -1);
|
|
|
|
_SetToAccount();
|
2021-08-02 21:59:44 -05:00
|
|
|
break;
|
|
|
|
}
|
2021-08-03 13:19:25 -05:00
|
|
|
case IM_MESSAGE: {
|
2021-08-02 21:59:44 -05:00
|
|
|
int32 im_what = msg->GetInt32("im_what", 0);
|
2021-08-03 13:19:25 -05:00
|
|
|
if (im_what == IM_PROTOCOL_READY || im_what == IM_PROTOCOL_DISABLE)
|
|
|
|
fAccountsMenu->SetTargetForItems(this);
|
2021-08-02 21:59:44 -05:00
|
|
|
break;
|
|
|
|
}
|
2010-05-07 04:47:10 -05:00
|
|
|
default:
|
|
|
|
BView::MessageReceived(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-03 13:19:25 -05:00
|
|
|
void
|
|
|
|
StatusView::ObserveString(int32 what, BString str)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2021-08-03 13:19:25 -05:00
|
|
|
if (what == STR_CONTACT_NAME || what == STR_PERSONAL_STATUS)
|
|
|
|
_SetToAccount();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-08-03 13:19:25 -05:00
|
|
|
StatusView::ObserveInteger(int32 what, int32 value)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2021-08-03 13:19:25 -05:00
|
|
|
if (what == INT_ACCOUNT_STATUS || what == INT_CONTACT_STATUS)
|
|
|
|
_SetToAccount();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-08-03 13:19:25 -05:00
|
|
|
StatusView::ObservePointer(int32 what, void* ptr)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2021-08-03 13:19:25 -05:00
|
|
|
if (what == PTR_AVATAR_BITMAP)
|
|
|
|
_SetToAccount();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
2021-08-02 21:59:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-08-03 13:19:25 -05:00
|
|
|
StatusView::_SetToAccount()
|
2021-08-02 21:59:44 -05:00
|
|
|
{
|
2021-08-03 13:19:25 -05:00
|
|
|
int64 instance = fAccount;
|
|
|
|
if (instance == -1)
|
2022-02-23 15:42:46 -06:00
|
|
|
instance = Server::Get()->GetActiveAccounts().ValueAt(0);
|
2021-08-03 13:19:25 -05:00
|
|
|
|
2022-02-23 15:42:46 -06:00
|
|
|
ProtocolLooper* looper = Server::Get()->GetProtocolLooper(instance);
|
2021-08-03 13:19:25 -05:00
|
|
|
if (looper == NULL || looper->GetOwnContact() == NULL)
|
|
|
|
return;
|
|
|
|
Contact* contact = looper->GetOwnContact();
|
|
|
|
|
|
|
|
_SetAvatarIcon(contact->AvatarBitmap());
|
|
|
|
_SetName(contact->GetName());
|
|
|
|
_SetStatus(contact->GetNotifyStatus());
|
|
|
|
}
|
2021-08-02 21:59:44 -05:00
|
|
|
|
|
|
|
|
2021-08-03 13:19:25 -05:00
|
|
|
void
|
|
|
|
StatusView::_SetName(BString name)
|
|
|
|
{
|
2021-08-03 16:05:57 -05:00
|
|
|
fNickname->SetText(name.String());
|
2021-08-03 13:19:25 -05:00
|
|
|
}
|
2021-08-02 21:59:44 -05:00
|
|
|
|
|
|
|
|
2021-08-03 13:19:25 -05:00
|
|
|
void
|
|
|
|
StatusView::_SetStatus(UserStatus status)
|
|
|
|
{
|
|
|
|
for (int32 i = 0; i < fStatusMenu->CountItems(); i++) {
|
|
|
|
StatusMenuItem* item
|
|
|
|
= reinterpret_cast<StatusMenuItem*>(fStatusMenu->ItemAt(i));
|
|
|
|
if (item && item->Status() == status && !item->IsCustom())
|
|
|
|
item->SetMarked(true);
|
2021-08-02 21:59:44 -05:00
|
|
|
}
|
2021-08-03 13:19:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusView::_SetAvatarIcon(const BBitmap* bitmap)
|
|
|
|
{
|
|
|
|
fAvatar->SetBitmap(bitmap);
|
2021-08-02 21:59:44 -05:00
|
|
|
}
|