Misc. tweaks, no functional change

This commit is contained in:
Jaidyn Ann 2021-08-01 06:37:25 -05:00
parent 803a2f20bd
commit 9f05ce1136
15 changed files with 46 additions and 52 deletions

View File

@ -59,6 +59,4 @@ private:
typedef KeyMap<BString, ChatCommand*> CommandMap; typedef KeyMap<BString, ChatCommand*> CommandMap;
#endif // CHAT_COMMAND_H #endif // CHAT_COMMAND_H

View File

@ -52,9 +52,8 @@ ImageCache::~ImageCache()
ImageCache* ImageCache*
ImageCache::Get() ImageCache::Get()
{ {
if (fInstance == NULL) { if (fInstance == NULL)
fInstance = new ImageCache(); fInstance = new ImageCache();
}
return fInstance; return fInstance;
} }
@ -103,8 +102,10 @@ ImageCache::Release()
void void
ImageCache::_LoadResource(int identifier, const char* key) ImageCache::_LoadResource(int identifier, const char* key)
{ {
BResources* res = ChatResources(); BResources res = ChatResources();
BBitmap* bitmap = IconFromResources(res, identifier, B_LARGE_ICON); if (res.InitCheck() != B_OK)
return;
BBitmap* bitmap = IconFromResources(&res, identifier, B_LARGE_ICON);
if (bitmap != NULL && bitmap->IsValid() == true) if (bitmap != NULL && bitmap->IsValid() == true)
fBitmaps.AddItem(BString(key), bitmap); fBitmaps.AddItem(BString(key), bitmap);
} }

View File

@ -89,6 +89,7 @@ ProtocolLooper::ConversationById(BString id)
void void
ProtocolLooper::AddConversation(Conversation* chat) ProtocolLooper::AddConversation(Conversation* chat)
{ {
if (chat != NULL)
fChatMap.AddItem(chat->GetId(), chat); fChatMap.AddItem(chat->GetId(), chat);
} }
@ -96,6 +97,7 @@ ProtocolLooper::AddConversation(Conversation* chat)
void void
ProtocolLooper::RemoveConversation(Conversation* chat) ProtocolLooper::RemoveConversation(Conversation* chat)
{ {
if (chat != NULL)
fChatMap.RemoveItemFor(chat->GetId()); fChatMap.RemoveItemFor(chat->GetId());
} }
@ -118,6 +120,7 @@ ProtocolLooper::ContactById(BString id)
void void
ProtocolLooper::AddContact(Contact* contact) ProtocolLooper::AddContact(Contact* contact)
{ {
if (contact != NULL)
fRosterMap.AddItem(contact->GetId(), contact); fRosterMap.AddItem(contact->GetId(), contact);
} }
@ -125,6 +128,8 @@ ProtocolLooper::AddContact(Contact* contact)
void void
ProtocolLooper::RemoveContact(Contact* contact) ProtocolLooper::RemoveContact(Contact* contact)
{ {
if (contact == NULL)
return;
fRosterMap.RemoveItemFor(contact->GetId()); fRosterMap.RemoveItemFor(contact->GetId());
fUserMap.AddItem(contact->GetId(), (User*)contact); fUserMap.AddItem(contact->GetId(), (User*)contact);
} }
@ -159,6 +164,7 @@ ProtocolLooper::UserById(BString id)
void void
ProtocolLooper::AddUser(User* user) ProtocolLooper::AddUser(User* user)
{ {
if (user != NULL)
fUserMap.AddItem(user->GetId(), user); fUserMap.AddItem(user->GetId(), user);
} }
@ -187,6 +193,7 @@ ProtocolLooper::GetOwnContact()
void void
ProtocolLooper::SetOwnContact(Contact* contact) ProtocolLooper::SetOwnContact(Contact* contact)
{ {
if (contact != NULL)
fMySelf = contact; fMySelf = contact;
} }

View File

@ -42,7 +42,7 @@ ProtocolTemplate::ProtocolTemplate(ChatProtocol* protocol, const char* type)
if (settingsTemplate.IsEmpty() == true) { if (settingsTemplate.IsEmpty() == true) {
size_t size; size_t size;
const void* buff = const void* buff =
ChatResources()->LoadResource(B_MESSAGE_TYPE, type, &size); ChatResources().LoadResource(B_MESSAGE_TYPE, type, &size);
if (buff != NULL) if (buff != NULL)
settingsTemplate.Unflatten((const char*)buff); settingsTemplate.Unflatten((const char*)buff);

View File

@ -29,7 +29,7 @@ public:
{ {
} }
BString fTitle; const char* fTitle;
int32 fPerms; // Permissions afforded to role, as described above. int32 fPerms; // Permissions afforded to role, as described above.
int32 fPriority; // 'Rank' of role, with higher being greater priority. int32 fPriority; // 'Rank' of role, with higher being greater priority.
// I.E., a user with a priority of 11 can't kick a user // I.E., a user with a priority of 11 can't kick a user

View File

@ -55,13 +55,15 @@ Server::Server()
|| fCommands.CountItems() > 0) || fCommands.CountItems() > 0)
return; return;
BResources* res = ChatResources(); BResources res = ChatResources();
if (res.InitCheck() != B_OK)
return;
// Loading user pop-up items // Loading user pop-up items
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
size_t size; size_t size;
BMessage temp; BMessage temp;
const void* buff = res->LoadResource(B_MESSAGE_TYPE, 1100 + i, &size); const void* buff = res.LoadResource(B_MESSAGE_TYPE, 1100 + i, &size);
temp.Unflatten((const char*)buff); temp.Unflatten((const char*)buff);
fUserItems.AddItem(new BMessage(temp)); fUserItems.AddItem(new BMessage(temp));
} }
@ -69,7 +71,7 @@ Server::Server()
// Loading room pop-up items // Loading room pop-up items
BMessage leave; BMessage leave;
size_t leaveSize; size_t leaveSize;
const void* leaveBuff = res->LoadResource(B_MESSAGE_TYPE, 1120, &leaveSize); const void* leaveBuff = res.LoadResource(B_MESSAGE_TYPE, 1120, &leaveSize);
leave.Unflatten((const char*)leaveBuff); leave.Unflatten((const char*)leaveBuff);
fChatItems.AddItem(new BMessage(leave)); fChatItems.AddItem(new BMessage(leave));
@ -77,7 +79,7 @@ Server::Server()
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
size_t size; size_t size;
BMessage temp; BMessage temp;
const void* buff = res->LoadResource(B_MESSAGE_TYPE, 1140 + i, &size); const void* buff = res.LoadResource(B_MESSAGE_TYPE, 1140 + i, &size);
temp.Unflatten((const char*)buff); temp.Unflatten((const char*)buff);
ChatCommand* cmd = new ChatCommand(&temp); ChatCommand* cmd = new ChatCommand(&temp);
fCommands.AddItem(cmd->GetName(), cmd); fCommands.AddItem(cmd->GetName(), cmd);

View File

@ -95,7 +95,6 @@ TheApp::ReadyToRun()
return; return;
} }
} }
fMainWin->Start(); fMainWin->Start();
fMainWin->Show(); fMainWin->Show();
} }

View File

@ -264,18 +264,18 @@ User::_SetCachedAvatar(BBitmap* bitmap)
{ {
_EnsureCachePath(); _EnsureCachePath();
BFile cacheFile(fCachePath.Path(), B_WRITE_ONLY | B_CREATE_FILE); BFile cacheFile(fCachePath.Path(), B_WRITE_ONLY | B_CREATE_FILE);
if (cacheFile.InitCheck() != B_OK)
return;
BBitmapStream* stream = new BBitmapStream(bitmap); BBitmapStream stream(bitmap);
BTranslatorRoster* roster = BTranslatorRoster::Default(); BTranslatorRoster* roster = BTranslatorRoster::Default();
int32 format_count; int32 format_count;
translator_info info; translator_info info;
const translation_format* formats = NULL; const translation_format* formats = NULL;
roster->Identify(stream, new BMessage(), &info, 0, "image"); roster->Identify(&stream, new BMessage(), &info, 0, "image");
roster->GetOutputFormats(info.translator, &formats, &format_count); roster->GetOutputFormats(info.translator, &formats, &format_count);
roster->Translate(info.translator, stream, new BMessage(), &cacheFile, roster->Translate(info.translator, &stream, NULL, &cacheFile,
formats[0].type); formats[0].type);
} }

View File

@ -79,7 +79,6 @@ protected:
UserItem* fListItem; UserItem* fListItem;
BString fID; BString fID;
bigtime_t fInstance;
BString fName; BString fName;
BString fPersonalStatus; BString fPersonalStatus;
BBitmap* fAvatarBitmap; BBitmap* fAvatarBitmap;

View File

@ -91,23 +91,16 @@ CommandArgs(BString line)
} }
BResources* BResources
ChatResources() ChatResources()
{ {
BResources res;
image_info info; image_info info;
if (our_image(info) != B_OK) if (our_image(info) == B_OK) {
return NULL;
BFile file(info.name, B_READ_ONLY); BFile file(info.name, B_READ_ONLY);
if (file.InitCheck() != B_OK) if (file.InitCheck() == B_OK)
return NULL; res.SetTo(&file);
BResources* res = new BResources(&file);
if (res->InitCheck() != B_OK) {
delete res;
return NULL;
} }
return res; return res;
} }

View File

@ -29,7 +29,7 @@ bool IsCommand(BString line);
BString CommandName(BString line); BString CommandName(BString line);
BString CommandArgs(BString line); BString CommandArgs(BString line);
BResources* ChatResources(); BResources ChatResources();
const char* SettingsPath(); const char* SettingsPath();

View File

@ -57,8 +57,8 @@ ReplicantMenuItem::IsCustom() const
void void
ReplicantMenuItem::SetIcon() ReplicantMenuItem::SetIcon()
{ {
BResources* res = ChatResources(); BResources res = ChatResources();
if (!res) if (res.InitCheck() != B_OK)
return; return;
int32 num = 0; int32 num = 0;
@ -84,8 +84,6 @@ ReplicantMenuItem::SetIcon()
break; break;
} }
BBitmap* bitmap = IconFromResources(res, num, B_MINI_ICON); BBitmap* bitmap = IconFromResources(&res, num, B_MINI_ICON);
SetBitmap(bitmap); SetBitmap(bitmap);
delete res;
} }

View File

@ -97,7 +97,6 @@ ReplicantStatusView::ReplicantStatusView(BMessage* archive)
ReplicantStatusView::~ReplicantStatusView() ReplicantStatusView::~ReplicantStatusView()
{ {
delete fResources;
delete fCayaMsg; delete fCayaMsg;
delete fReplicantHandler; delete fReplicantHandler;
delete fReplicantMenu; delete fReplicantMenu;
@ -300,7 +299,7 @@ ReplicantStatusView::_Init()
BBitmap* BBitmap*
ReplicantStatusView::_GetIcon(const uint32 id) ReplicantStatusView::_GetIcon(const uint32 id)
{ {
BBitmap* icon = IconFromResources(fResources, id, B_MINI_ICON); BBitmap* icon = IconFromResources(&fResources, id, B_MINI_ICON);
return icon; return icon;
} }

View File

@ -63,7 +63,7 @@ private:
BBitmap* fExitMenuIcon; BBitmap* fExitMenuIcon;
BBitmap* fPreferencesIcon; BBitmap* fPreferencesIcon;
BResources* fResources; BResources fResources;
BPopUpMenu* fReplicantMenu; BPopUpMenu* fReplicantMenu;

View File

@ -54,8 +54,8 @@ StatusMenuItem::IsCustom() const
void void
StatusMenuItem::SetIcon() StatusMenuItem::SetIcon()
{ {
BResources* res = ChatResources(); BResources res = ChatResources();
if (!res) if (res.InitCheck() != B_OK)
return; return;
int32 num = 0; int32 num = 0;
@ -81,8 +81,6 @@ StatusMenuItem::SetIcon()
break; break;
} }
BBitmap* bitmap = IconFromResources(res, num, B_MINI_ICON); BBitmap* bitmap = IconFromResources(&res, num, B_MINI_ICON);
SetBitmap(bitmap); SetBitmap(bitmap);
delete res;
} }