Error notification if applying protocol settings fails
This commit is contained in:
parent
a49e957b16
commit
e8e1ce0b05
|
@ -23,6 +23,7 @@ Account::Account(bigtime_t instanceId, ChatProtocol* cayap,
|
||||||
:
|
:
|
||||||
fIdentifier(instanceId),
|
fIdentifier(instanceId),
|
||||||
fName(name),
|
fName(name),
|
||||||
|
fStatus(B_ERROR),
|
||||||
fProtocol(cayap),
|
fProtocol(cayap),
|
||||||
fMessenger(target),
|
fMessenger(target),
|
||||||
fSettings(new BMessage())
|
fSettings(new BMessage())
|
||||||
|
@ -39,7 +40,7 @@ Account::Account(bigtime_t instanceId, ChatProtocol* cayap,
|
||||||
// Load settings file
|
// Load settings file
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
BFile file(path.Path(), B_READ_ONLY);
|
||||||
if (fSettings->Unflatten(&file) == B_OK)
|
if (fSettings->Unflatten(&file) == B_OK)
|
||||||
fProtocol->UpdateSettings(fSettings);
|
fStatus = fProtocol->UpdateSettings(fSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +51,13 @@ Account::~Account()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Account::InitCheck()
|
||||||
|
{
|
||||||
|
return fStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bigtime_t
|
bigtime_t
|
||||||
Account::Identifier() const
|
Account::Identifier() const
|
||||||
{
|
{
|
||||||
|
@ -70,5 +78,3 @@ Account::SendMessage(BMessage* message)
|
||||||
message->AddInt64("instance", fIdentifier);
|
message->AddInt64("instance", fIdentifier);
|
||||||
return fMessenger.SendMessage(message);
|
return fMessenger.SendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ public:
|
||||||
BHandler* target);
|
BHandler* target);
|
||||||
virtual ~Account();
|
virtual ~Account();
|
||||||
|
|
||||||
|
status_t InitCheck();
|
||||||
|
|
||||||
bigtime_t Identifier() const;
|
bigtime_t Identifier() const;
|
||||||
const char* Name() const;
|
const char* Name() const;
|
||||||
|
|
||||||
|
@ -28,6 +30,7 @@ private:
|
||||||
bigtime_t fIdentifier;
|
bigtime_t fIdentifier;
|
||||||
ChatProtocol* fProtocol;
|
ChatProtocol* fProtocol;
|
||||||
BString fName;
|
BString fName;
|
||||||
|
status_t fStatus;
|
||||||
BMessenger fMessenger;
|
BMessenger fMessenger;
|
||||||
BMessage* fSettings;
|
BMessage* fSettings;
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,8 +47,11 @@ const uint32 APP_MOVE_UP = 'CYmu';
|
||||||
//! Select the downward conversation
|
//! Select the downward conversation
|
||||||
const uint32 APP_MOVE_DOWN = 'CYmd';
|
const uint32 APP_MOVE_DOWN = 'CYmd';
|
||||||
|
|
||||||
//! Disable a given account
|
//! An account has been disabled
|
||||||
const uint32 APP_ACCOUNT_DISABLED = 'CYda';
|
const uint32 APP_ACCOUNT_DISABLED = 'Axwo';
|
||||||
|
|
||||||
|
//! An account's initial connection failed
|
||||||
|
const uint32 APP_ACCOUNT_FAILED = 'Axwx';
|
||||||
|
|
||||||
//! Request a "help" message
|
//! Request a "help" message
|
||||||
const uint32 APP_REQUEST_HELP = 'CYhm';
|
const uint32 APP_REQUEST_HELP = 'CYhm';
|
||||||
|
|
|
@ -9,11 +9,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <image.h>
|
#include <image.h>
|
||||||
|
|
||||||
|
#include <Bitmap.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <Handler.h>
|
#include <Handler.h>
|
||||||
|
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
|
#include "AppMessages.h"
|
||||||
#include "ProtocolManager.h"
|
#include "ProtocolManager.h"
|
||||||
#include "ChatProtocol.h"
|
#include "ChatProtocol.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
@ -121,12 +123,23 @@ void
|
||||||
ProtocolManager::AddAccount(ChatProtocolAddOn* addOn, const char* account,
|
ProtocolManager::AddAccount(ChatProtocolAddOn* addOn, const char* account,
|
||||||
BHandler* target)
|
BHandler* target)
|
||||||
{
|
{
|
||||||
|
TheApp* theApp = reinterpret_cast<TheApp*>(be_app);
|
||||||
bigtime_t instanceId = system_time();
|
bigtime_t instanceId = system_time();
|
||||||
ChatProtocol* cayap = addOn->Protocol();
|
ChatProtocol* cayap = addOn->Protocol();
|
||||||
(void)new Account(instanceId, cayap, account, addOn->Signature(), target);
|
Account* acc =
|
||||||
|
new Account(instanceId, cayap, account, addOn->Signature(), target);
|
||||||
|
|
||||||
|
// Send a "whoops" notification if hits a failure
|
||||||
|
if (acc->InitCheck() != B_OK) {
|
||||||
|
BMessage error(APP_ACCOUNT_FAILED);
|
||||||
|
cayap->Icon()->Archive(&error);
|
||||||
|
error.AddString("name", account);
|
||||||
|
theApp->GetMainWindow()->MessageReceived(&error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fProtocolMap.AddItem(instanceId, cayap);
|
fProtocolMap.AddItem(instanceId, cayap);
|
||||||
|
|
||||||
TheApp* theApp = reinterpret_cast<TheApp*>(be_app);
|
|
||||||
theApp->GetMainWindow()->GetServer()->AddProtocolLooper(
|
theApp->GetMainWindow()->GetServer()->AddProtocolLooper(
|
||||||
instanceId, cayap);
|
instanceId, cayap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,11 +146,6 @@ Server::Filter(BMessage* message, BHandler **target)
|
||||||
case APP_ACCOUNT_DISABLED:
|
case APP_ACCOUNT_DISABLED:
|
||||||
{
|
{
|
||||||
BString name;
|
BString name;
|
||||||
int64 instance;
|
|
||||||
if (message->FindInt64("instance", &instance) != B_OK)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
// "Whoops" notification
|
|
||||||
if (AppPreferences::Get()->NotifyProtocolStatus == true
|
if (AppPreferences::Get()->NotifyProtocolStatus == true
|
||||||
&& message->FindString("name", &name) == B_OK) {
|
&& message->FindString("name", &name) == B_OK) {
|
||||||
BBitmap* icon = new BBitmap(message);
|
BBitmap* icon = new BBitmap(message);
|
||||||
|
@ -161,6 +156,19 @@ Server::Filter(BMessage* message, BHandler **target)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case APP_ACCOUNT_FAILED:
|
||||||
|
{
|
||||||
|
BString name;
|
||||||
|
if (AppPreferences::Get()->NotifyProtocolStatus == true
|
||||||
|
&& message->FindString("name", &name) == B_OK) {
|
||||||
|
BBitmap* icon = new BBitmap(message);
|
||||||
|
BString content(B_TRANSLATE("%user% has been temporarily disabled."));
|
||||||
|
content.ReplaceAll("%user%", name);
|
||||||
|
|
||||||
|
_SendNotification(B_TRANSLATE("Connection failed"), content, icon);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case APP_REPLICANT_MESSENGER:
|
case APP_REPLICANT_MESSENGER:
|
||||||
{
|
{
|
||||||
BMessenger* messenger = new BMessenger();
|
BMessenger* messenger = new BMessenger();
|
||||||
|
@ -625,7 +633,6 @@ Server::ImMessage(BMessage* msg)
|
||||||
join.AddString("chat_id", fileName);
|
join.AddString("chat_id", fileName);
|
||||||
looper->PostMessage(&join);
|
looper->PostMessage(&join);
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyInteger(INT_ACCOUNTS_UPDATED, 0);
|
NotifyInteger(INT_ACCOUNTS_UPDATED, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue