Chat-O-Matic/application/views/StatusMenuItem.cpp

89 lines
1.4 KiB
C++
Raw Normal View History

/*
* Copyright 2009, Pier Luigi Fiorini. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
*/
#include <string.h>
#include <Bitmap.h>
#include <Menu.h>
#include <libinterface/BitmapUtils.h>
2021-06-20 12:44:20 -05:00
#include "AppResources.h"
#include "StatusMenuItem.h"
2021-06-20 12:44:20 -05:00
#include "Utils.h"
2010-05-20 16:31:55 -05:00
const float kSize = 16;
const float kCircle = 12;
2021-06-20 12:44:20 -05:00
StatusMenuItem::StatusMenuItem(const char* label, UserStatus status,
2010-05-20 16:31:55 -05:00
bool custom, char shortcut, uint32 modifiers)
:
BitmapMenuItem(label, NULL, NULL, shortcut, modifiers),
fStatus(status),
fCustom(custom)
{
BMessage* msg = new BMessage(kSetStatus);
msg->AddInt32("status", fStatus);
msg->AddBool("custom", fCustom);
SetMessage(msg);
SetIcon();
}
2021-06-20 12:44:20 -05:00
UserStatus
StatusMenuItem::Status() const
{
return fStatus;
}
bool
StatusMenuItem::IsCustom() const
{
return fCustom;
}
void
StatusMenuItem::SetIcon()
{
2021-06-20 12:44:20 -05:00
BResources* res = ChatResources();
if (!res)
return;
int32 num = 0;
switch (fStatus) {
2021-06-20 12:44:20 -05:00
case STATUS_ONLINE:
num = kOnlineReplicant;
break;
2021-06-20 12:44:20 -05:00
case STATUS_AWAY:
num = kAwayReplicant;
break;
2021-06-20 12:44:20 -05:00
case STATUS_DO_NOT_DISTURB:
num = kBusyReplicant;
break;
2021-06-20 12:44:20 -05:00
case STATUS_CUSTOM_STATUS:
num = kIconReplicant;
break;
2021-06-20 12:44:20 -05:00
case STATUS_INVISIBLE:
case STATUS_OFFLINE:
num = kOfflineReplicant;
break;
default:
break;
}
BBitmap* bitmap = IconFromResources(res, num, B_MINI_ICON);
SetBitmap(bitmap);
delete res;
}