Notify on account disabling, more detailed alerts
Like the notification sent when accounts are ready (IM_PROTOCOL_READY), one's been added for when accounds have disconnected/are disabled: IM_PROTOCOL_DISABLED. Also, error BAlerts (created with IM_ERROR messages) are now more detailed, showing the associated accounts' name in the header.
This commit is contained in:
parent
8d47983c47
commit
6dcb6f4405
|
@ -119,7 +119,9 @@ Server::Filter(BMessage* message, BHandler **target)
|
||||||
case IM_MESSAGE:
|
case IM_MESSAGE:
|
||||||
result = ImMessage(message);
|
result = ImMessage(message);
|
||||||
break;
|
break;
|
||||||
|
case IM_ERROR:
|
||||||
|
ImError(message);
|
||||||
|
break;
|
||||||
case APP_REPLICANT_MESSENGER:
|
case APP_REPLICANT_MESSENGER:
|
||||||
{
|
{
|
||||||
BMessenger* messenger = new BMessenger();
|
BMessenger* messenger = new BMessenger();
|
||||||
|
@ -526,12 +528,13 @@ Server::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
case IM_PROGRESS:
|
case IM_PROGRESS:
|
||||||
{
|
{
|
||||||
|
ProtocolLooper* looper = _LooperFromMessage(msg);
|
||||||
const char* protocol = NULL;
|
const char* protocol = NULL;
|
||||||
const char* title = NULL;
|
const char* title = NULL;
|
||||||
const char* message = NULL;
|
const char* message = NULL;
|
||||||
float progress = 0.0f;
|
float progress = 0.0f;
|
||||||
|
|
||||||
if (msg->FindString("protocol", &protocol) != B_OK)
|
if (looper == NULL)
|
||||||
return result;
|
return result;
|
||||||
if (msg->FindString("title", &title) != B_OK)
|
if (msg->FindString("title", &title) != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
@ -543,48 +546,20 @@ Server::ImMessage(BMessage* msg)
|
||||||
if (!AppPreferences::Item()->NotifyProtocolStatus)
|
if (!AppPreferences::Item()->NotifyProtocolStatus)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ChatProtocolAddOn* addOn
|
|
||||||
= ProtocolManager::Get()->ProtocolAddOn(protocol);
|
|
||||||
|
|
||||||
BNotification notification(B_PROGRESS_NOTIFICATION);
|
BNotification notification(B_PROGRESS_NOTIFICATION);
|
||||||
notification.SetGroup(BString(APP_NAME));
|
notification.SetGroup(BString(APP_NAME));
|
||||||
notification.SetTitle(title);
|
notification.SetTitle(title);
|
||||||
notification.SetIcon(addOn->ProtoIcon());
|
notification.SetIcon(looper->Protocol()->Icon());
|
||||||
notification.SetContent(message);
|
notification.SetContent(message);
|
||||||
notification.SetProgress(progress);
|
notification.SetProgress(progress);
|
||||||
notification.Send();
|
notification.Send();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IM_NOTIFICATION:
|
case IM_NOTIFICATION: {
|
||||||
{
|
_ProtocolNotification(_LooperFromMessage(msg),
|
||||||
int32 type = (int32)B_INFORMATION_NOTIFICATION;
|
msg->FindString("title"), msg->FindString("message"),
|
||||||
const char* protocol = NULL;
|
(notification_type)msg->GetInt32("type",
|
||||||
const char* title = NULL;
|
B_INFORMATION_NOTIFICATION));
|
||||||
const char* message = NULL;
|
|
||||||
|
|
||||||
if (msg->FindString("protocol", &protocol) != B_OK)
|
|
||||||
return result;
|
|
||||||
if (msg->FindInt32("type", &type) != B_OK)
|
|
||||||
return result;
|
|
||||||
if (msg->FindString("title", &title) != B_OK)
|
|
||||||
return result;
|
|
||||||
if (msg->FindString("message", &message) != B_OK)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
if (!AppPreferences::Item()->NotifyProtocolStatus)
|
|
||||||
break;
|
|
||||||
|
|
||||||
ChatProtocolAddOn* addOn
|
|
||||||
= ProtocolManager::Get()->ProtocolAddOn(protocol);
|
|
||||||
|
|
||||||
BNotification notification((notification_type)type);
|
|
||||||
notification.SetGroup(BString(APP_NAME));
|
|
||||||
notification.SetTitle(title);
|
|
||||||
notification.SetIcon(addOn->ProtoIcon());
|
|
||||||
notification.SetContent(message);
|
|
||||||
notification.Send();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IM_PROTOCOL_RELOAD_COMMANDS:
|
case IM_PROTOCOL_RELOAD_COMMANDS:
|
||||||
|
@ -596,25 +571,18 @@ Server::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
case IM_PROTOCOL_READY:
|
case IM_PROTOCOL_READY:
|
||||||
{
|
{
|
||||||
// Ready notification
|
|
||||||
ProtocolLooper* looper = _LooperFromMessage(msg);
|
ProtocolLooper* looper = _LooperFromMessage(msg);
|
||||||
if (looper == NULL) break;
|
if (looper == NULL) break;
|
||||||
ChatProtocol* proto = looper->Protocol();
|
|
||||||
|
|
||||||
BString content("%user% has connected!");
|
// Ready notification
|
||||||
content.ReplaceAll("%user%", looper->Protocol()->GetName());
|
if (AppPreferences::Item()->NotifyProtocolStatus == true)
|
||||||
|
_ProtocolNotification(looper, BString("Connected"),
|
||||||
BNotification notification(B_INFORMATION_NOTIFICATION);
|
BString("%user% has connected!"));
|
||||||
notification.SetGroup(BString(APP_NAME));
|
|
||||||
notification.SetTitle("Connected");
|
|
||||||
notification.SetContent(content);
|
|
||||||
notification.SetIcon(proto->Icon());
|
|
||||||
notification.Send();
|
|
||||||
|
|
||||||
// Join cached rooms
|
// Join cached rooms
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
char fileName[B_FILE_NAME_LENGTH] = {'\0'};
|
char fileName[B_FILE_NAME_LENGTH] = {'\0'};
|
||||||
BDirectory dir(RoomsCachePath(proto->GetName()));
|
BDirectory dir(RoomsCachePath(looper->Protocol()->GetName()));
|
||||||
|
|
||||||
while (dir.GetNextEntry(&entry, true) == B_OK)
|
while (dir.GetNextEntry(&entry, true) == B_OK)
|
||||||
if (entry.GetName(fileName) == B_OK) {
|
if (entry.GetName(fileName) == B_OK) {
|
||||||
|
@ -642,7 +610,14 @@ Server::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case IM_PROTOCOL_DISABLED:
|
||||||
|
{
|
||||||
|
// "Whoops" notification
|
||||||
|
if (AppPreferences::Item()->NotifyProtocolStatus == true)
|
||||||
|
_ProtocolNotification(_LooperFromMessage(msg),
|
||||||
|
BString("Disabled"), BString("%user% has been disabled!"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -651,6 +626,28 @@ Server::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Server::ImError(BMessage* msg)
|
||||||
|
{
|
||||||
|
const char* error = NULL;
|
||||||
|
const char* detail = msg->FindString("detail");
|
||||||
|
ProtocolLooper* looper = _LooperFromMessage(msg);
|
||||||
|
|
||||||
|
if (msg->FindString("error", &error) != B_OK || looper == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Format error message
|
||||||
|
BString errMsg(looper->Protocol()->GetName());
|
||||||
|
errMsg << " ― " << error;
|
||||||
|
if (detail)
|
||||||
|
errMsg << "\n\n" << detail;
|
||||||
|
|
||||||
|
BAlert* alert = new BAlert("Error", errMsg.String(), "OK", NULL, NULL,
|
||||||
|
B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||||
|
alert->Go();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::AddProtocolLooper(bigtime_t instanceId, ChatProtocol* cayap)
|
Server::AddProtocolLooper(bigtime_t instanceId, ChatProtocol* cayap)
|
||||||
{
|
{
|
||||||
|
@ -977,3 +974,21 @@ Server::_GetRole(BMessage* msg)
|
||||||
|
|
||||||
return new Role(title, perms, priority);
|
return new Role(title, perms, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Server::_ProtocolNotification(ProtocolLooper* looper, BString title,
|
||||||
|
BString desc, notification_type type)
|
||||||
|
{
|
||||||
|
if (looper == NULL || title.IsEmpty() == true) return;
|
||||||
|
title.ReplaceAll("%user%", looper->Protocol()->GetName());
|
||||||
|
desc.ReplaceAll("%user%", looper->Protocol()->GetName());
|
||||||
|
|
||||||
|
BNotification notification(type);
|
||||||
|
notification.SetGroup(BString(APP_NAME));
|
||||||
|
notification.SetTitle(title);
|
||||||
|
if (desc.IsEmpty() == false)
|
||||||
|
notification.SetContent(desc);
|
||||||
|
notification.SetIcon(looper->Protocol()->Icon());
|
||||||
|
notification.Send();
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <MessageFilter.h>
|
#include <MessageFilter.h>
|
||||||
|
#include <Notification.h>
|
||||||
|
|
||||||
#include <libsupport/KeyMap.h>
|
#include <libsupport/KeyMap.h>
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ public:
|
||||||
|
|
||||||
virtual filter_result Filter(BMessage* message, BHandler** target);
|
virtual filter_result Filter(BMessage* message, BHandler** target);
|
||||||
filter_result ImMessage(BMessage* msg);
|
filter_result ImMessage(BMessage* msg);
|
||||||
|
void ImError(BMessage* msg);
|
||||||
|
|
||||||
void AddProtocolLooper(bigtime_t instanceId,
|
void AddProtocolLooper(bigtime_t instanceId,
|
||||||
ChatProtocol* cayap);
|
ChatProtocol* cayap);
|
||||||
|
@ -75,12 +77,15 @@ private:
|
||||||
|
|
||||||
Role* _GetRole(BMessage* msg);
|
Role* _GetRole(BMessage* msg);
|
||||||
|
|
||||||
|
void _ProtocolNotification(ProtocolLooper* looper,
|
||||||
|
BString title, BString desc,
|
||||||
|
notification_type type=B_INFORMATION_NOTIFICATION);
|
||||||
|
|
||||||
void _ReplicantStatusNotify(UserStatus status);
|
void _ReplicantStatusNotify(UserStatus status);
|
||||||
|
|
||||||
ProtocolLoopers fLoopers;
|
ProtocolLoopers fLoopers;
|
||||||
AccountInstances
|
AccountInstances
|
||||||
fAccounts;
|
fAccounts;
|
||||||
BString fMySelf;
|
|
||||||
|
|
||||||
CommandMap fCommands;
|
CommandMap fCommands;
|
||||||
BObjectList<BMessage>
|
BObjectList<BMessage>
|
||||||
|
|
|
@ -211,9 +211,6 @@ MainWindow::MessageReceived(BMessage* message)
|
||||||
case IM_MESSAGE:
|
case IM_MESSAGE:
|
||||||
ImMessage(message);
|
ImMessage(message);
|
||||||
break;
|
break;
|
||||||
case IM_ERROR:
|
|
||||||
ImError(message);
|
|
||||||
break;
|
|
||||||
case B_ABOUT_REQUESTED:
|
case B_ABOUT_REQUESTED:
|
||||||
be_app->PostMessage(message);
|
be_app->PostMessage(message);
|
||||||
break;
|
break;
|
||||||
|
@ -282,26 +279,6 @@ MainWindow::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
MainWindow::ImError(BMessage* msg)
|
|
||||||
{
|
|
||||||
const char* error = NULL;
|
|
||||||
const char* detail = msg->FindString("detail");
|
|
||||||
|
|
||||||
if (msg->FindString("error", &error) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Format error message
|
|
||||||
BString errMsg(error);
|
|
||||||
if (detail)
|
|
||||||
errMsg << "\n" << detail;
|
|
||||||
|
|
||||||
BAlert* alert = new BAlert("Error", errMsg.String(), "OK", NULL, NULL,
|
|
||||||
B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
|
||||||
alert->Go();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWindow::ObserveInteger(int32 what, int32 val)
|
MainWindow::ObserveInteger(int32 what, int32 val)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,7 +35,6 @@ public:
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
void ImMessage(BMessage* msg);
|
void ImMessage(BMessage* msg);
|
||||||
void ImError(BMessage* msg);
|
|
||||||
|
|
||||||
// Observer inheritance
|
// Observer inheritance
|
||||||
void ObserveInteger(int32 what, int32 val);
|
void ObserveInteger(int32 what, int32 val);
|
||||||
|
|
Ŝarĝante…
Reference in New Issue