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