2010-05-07 04:47:10 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Pier Luigi Fiorini. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
|
|
|
*/
|
|
|
|
|
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 <MenuField.h>
|
|
|
|
#include <MenuItem.h>
|
|
|
|
#include <PopUpMenu.h>
|
2012-05-15 11:48:53 -05:00
|
|
|
#include <StringView.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
#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>
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
#include "AccountManager.h"
|
2021-07-13 14:43:48 -05:00
|
|
|
#include "ImageCache.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "NicknameTextControl.h"
|
|
|
|
#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
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
const int32 kSetNickname = 'stnk';
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
StatusView::StatusView(const char* name)
|
2010-05-30 03:51:19 -05:00
|
|
|
:
|
|
|
|
BView(name, B_WILL_DRAW)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
// Nick name
|
2012-09-25 16:45:29 -05:00
|
|
|
fNickname = new NicknameTextControl("Nickname",
|
2012-05-15 11:48:53 -05:00
|
|
|
new BMessage(kSetNickname));
|
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
|
|
|
|
|
|
|
// Set layout
|
2021-05-29 15:47:54 -05:00
|
|
|
BLayoutBuilder::Group<>(this, B_HORIZONTAL)
|
2010-05-07 04:47:10 -05:00
|
|
|
.AddGroup(B_VERTICAL)
|
|
|
|
.Add(statusField)
|
2012-05-15 11:48:53 -05:00
|
|
|
.AddGroup(B_HORIZONTAL)
|
2012-09-25 16:45:29 -05:00
|
|
|
.Add(fNickname)
|
2021-05-30 12:30:26 -05:00
|
|
|
.Add(fAvatar)
|
2012-05-15 11:48:53 -05:00
|
|
|
.End()
|
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) {
|
2012-09-25 16:45:29 -05:00
|
|
|
case kSetNickname:
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
AccountManager* accountManager = AccountManager::Get();
|
|
|
|
accountManager->SetNickname(fNickname->Text());
|
|
|
|
break;
|
2012-09-25 16:45:29 -05:00
|
|
|
}
|
2010-05-07 04:47:10 -05:00
|
|
|
case kSetStatus:
|
|
|
|
{
|
|
|
|
int32 status;
|
|
|
|
|
|
|
|
if (msg->FindInt32("status", &status) != B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AccountManager* accountManager = AccountManager::Get();
|
2021-06-20 12:44:20 -05:00
|
|
|
accountManager->SetStatus((UserStatus)status, "");
|
2010-05-07 04:47:10 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
BView::MessageReceived(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusView::SetName(BString name)
|
|
|
|
{
|
2012-09-25 16:45:29 -05:00
|
|
|
fNickname->SetText(name.String());
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-20 12:44:20 -05:00
|
|
|
StatusView::SetStatus(UserStatus status)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-06-22 14:02:42 -05:00
|
|
|
StatusView::SetAvatarIcon(const BBitmap* bitmap)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2021-07-13 14:43:48 -05:00
|
|
|
// We don't want the default avatar to override a real one
|
|
|
|
if (bitmap != ImageCache::Get()->GetImage("kPersonIcon"))
|
|
|
|
fAvatar->SetBitmap(bitmap);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|