diff --git a/application/Account.cpp b/application/Account.cpp index 952137f..2286362 100644 --- a/application/Account.cpp +++ b/application/Account.cpp @@ -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); } - - diff --git a/application/Account.h b/application/Account.h index 9e11965..fe39038 100644 --- a/application/Account.h +++ b/application/Account.h @@ -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; }; diff --git a/application/AppMessages.h b/application/AppMessages.h index 36b08dd..fbe0d48 100644 --- a/application/AppMessages.h +++ b/application/AppMessages.h @@ -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'; diff --git a/application/ProtocolManager.cpp b/application/ProtocolManager.cpp index d0ac873..86f04c0 100644 --- a/application/ProtocolManager.cpp +++ b/application/ProtocolManager.cpp @@ -9,11 +9,13 @@ #include #include +#include #include #include #include #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(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(be_app); theApp->GetMainWindow()->GetServer()->AddProtocolLooper( instanceId, cayap); } diff --git a/application/Server.cpp b/application/Server.cpp index ae1d108..c9e7192 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -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; }