Show protocol icons in notifications

CayaProtocolAddOn now has the convenience functions ProtoIcon(),
ProtoSignature(), and ProtoFriendlySignature(), for getting info from
its default protocol.
This commit is contained in:
Jaidyn Ann 2021-05-22 12:05:44 -05:00
parent 6ca134f9f6
commit 4705d586f9
5 changed files with 40 additions and 19 deletions

View File

@ -78,8 +78,15 @@ CayaProtocolAddOn::FriendlySignature() const
}
BBitmap*
CayaProtocolAddOn::Icon() const
{
return ReadNodeIcon(fPath, B_LARGE_ICON, true);
}
const char*
CayaProtocolAddOn::SubSignature() const
CayaProtocolAddOn::ProtoSignature() const
{
CayaProtocol* proto = Protocol();
const char* signature = proto->Signature();
@ -88,17 +95,30 @@ CayaProtocolAddOn::SubSignature() const
}
uint32
CayaProtocolAddOn::Version() const
const char*
CayaProtocolAddOn::ProtoFriendlySignature() const
{
return fVersion;
CayaProtocol* proto = Protocol();
const char* signature = proto->FriendlySignature();
delete proto;
return signature;
}
BBitmap*
CayaProtocolAddOn::Icon() const
CayaProtocolAddOn::ProtoIcon() const
{
return ReadNodeIcon(fPath, B_LARGE_ICON, true);
CayaProtocol* proto = Protocol();
BBitmap* icon = proto->Icon();
delete proto;
return icon;
}
uint32
CayaProtocolAddOn::Version() const
{
return fVersion;
}

View File

@ -29,11 +29,14 @@ public:
const char* Signature() const;
const char* FriendlySignature() const;
const char* SubSignature() const;
uint32 Version() const;
BBitmap* Icon() const;
const char* ProtoSignature() const;
const char* ProtoFriendlySignature() const;
BBitmap* ProtoIcon() const;
uint32 Version() const;
private:
image_id fImage;
BString fPath;

View File

@ -75,7 +75,7 @@ ProtocolSettings::Accounts() const
{
BObjectList<BString> list(true);
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->SubSignature()));
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()));
if (path.InitCheck() != B_OK)
return list;
@ -361,7 +361,7 @@ ProtocolSettings::Rename(const char* from, const char* to)
status_t ret = B_ERROR;
// Find user's settings path
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->SubSignature()));
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()));
if ((ret = path.InitCheck()) != B_OK)
return ret;
@ -382,7 +382,7 @@ ProtocolSettings::Delete(const char* account)
status_t ret = B_ERROR;
// Find user's settings path
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->SubSignature()));
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()));
if ((ret = path.InitCheck()) != B_OK)
return ret;
@ -417,7 +417,7 @@ ProtocolSettings::_Load(const char* account, BMessage** settings)
status_t ret = B_ERROR;
// Find user's settings path
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->SubSignature()));
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()));
if ((ret = path.InitCheck()) != B_OK)
return ret;
@ -440,7 +440,7 @@ ProtocolSettings::_Save(const char* account, BMessage* settings)
status_t ret = B_ERROR;
// Find user's settings path
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->SubSignature()));
BPath path(CayaAccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()));
if ((ret = path.InitCheck()) != B_OK)
return ret;

View File

@ -369,7 +369,7 @@ Server::ImMessage(BMessage* msg)
BNotification notification(B_PROGRESS_NOTIFICATION);
notification.SetGroup(BString("Caya"));
notification.SetTitle(title);
notification.SetIcon(addOn->Icon());
notification.SetIcon(addOn->ProtoIcon());
notification.SetContent(message);
notification.SetProgress(progress);
notification.Send();
@ -402,7 +402,7 @@ Server::ImMessage(BMessage* msg)
BNotification notification((notification_type)type);
notification.SetGroup(BString("Caya"));
notification.SetTitle(title);
notification.SetIcon(addOn->Icon());
notification.SetIcon(addOn->ProtoIcon());
notification.SetContent(message);
notification.Send();

View File

@ -57,7 +57,6 @@ PreferencesAccounts::PreferencesAccounts()
fProtosMenu = new BPopUpMenu(NULL, true);
for (uint32 i = 0; i < pm->CountProtocolAddOns(); i++) {
CayaProtocolAddOn* addOn = pm->ProtocolAddOnAt(i);
CayaProtocol* proto = addOn->Protocol();
ProtocolSettings* settings = new ProtocolSettings(addOn);
// Add accounts to list view
@ -68,9 +67,8 @@ PreferencesAccounts::PreferencesAccounts()
msg->AddPointer("settings", settings);
BitmapMenuItem* item = new BitmapMenuItem(
proto->FriendlySignature(), msg, proto->Icon());
addOn->ProtoFriendlySignature(), msg, addOn->ProtoIcon());
fProtosMenu->AddItem(item);
delete proto;
}
ToolButton* proto = new ToolButton("Add", NULL);