2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2011-12-03 16:38:03 -06:00
|
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
2010-05-07 04:47:10 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
2010-05-16 16:02:50 -05:00
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
2010-05-07 04:47:10 -05:00
|
|
|
*/
|
|
|
|
|
2010-05-24 22:19:09 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
#include <File.h>
|
|
|
|
#include <Message.h>
|
|
|
|
#include <Path.h>
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "Account.h"
|
2021-06-20 12:44:20 -05:00
|
|
|
#include "Utils.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
Account::Account(bigtime_t instanceId, ChatProtocol* cayap,
|
2021-05-21 15:52:33 -05:00
|
|
|
const char* name, const char* addOnSignature, BHandler* target)
|
2010-05-19 17:28:26 -05:00
|
|
|
:
|
|
|
|
fIdentifier(instanceId),
|
2010-05-16 16:02:50 -05:00
|
|
|
fName(name),
|
|
|
|
fProtocol(cayap),
|
|
|
|
fMessenger(target),
|
|
|
|
fSettings(new BMessage())
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-05-16 16:02:50 -05:00
|
|
|
fProtocol->Init(this);
|
|
|
|
|
|
|
|
// Find user's settings path
|
2021-06-20 12:44:20 -05:00
|
|
|
BPath path(AccountPath(addOnSignature, fProtocol->Signature()));
|
2010-05-16 16:02:50 -05:00
|
|
|
if (path.InitCheck() == B_OK) {
|
|
|
|
path.Append(name);
|
|
|
|
|
2021-06-01 21:43:19 -05:00
|
|
|
fProtocol->SetName(name);
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
// Load settings file
|
|
|
|
BFile file(path.Path(), B_READ_ONLY);
|
|
|
|
if (fSettings->Unflatten(&file) == B_OK)
|
|
|
|
fProtocol->UpdateSettings(fSettings);
|
|
|
|
}
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Account::~Account()
|
|
|
|
{
|
2010-05-16 16:02:50 -05:00
|
|
|
delete fSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bigtime_t
|
|
|
|
Account::Identifier() const
|
|
|
|
{
|
|
|
|
return fIdentifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
Account::Name() const
|
|
|
|
{
|
|
|
|
return fName.String();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 17:28:26 -05:00
|
|
|
status_t
|
2010-05-07 04:47:10 -05:00
|
|
|
Account::SendMessage(BMessage* message)
|
|
|
|
{
|
2010-05-20 16:31:55 -05:00
|
|
|
message->AddInt64("instance", fIdentifier);
|
|
|
|
return fMessenger.SendMessage(message);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
2021-05-21 15:52:33 -05:00
|
|
|
|
|
|
|
|