2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2010-05-16 16:02:50 -05:00
|
|
|
* Copyright 2009-2010, Andrea Anzani. All rights reserved.
|
|
|
|
* Copyright 2009-2010, 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-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"
|
2010-05-16 16:02:50 -05:00
|
|
|
#include "CayaUtils.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
Account::Account(bigtime_t instanceId, CayaProtocol* cayap,
|
2010-05-20 16:31:55 -05:00
|
|
|
const char* name, 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
|
|
|
|
BPath path(CayaAccountPath(fProtocol->Signature()));
|
|
|
|
if (path.InitCheck() == B_OK) {
|
|
|
|
path.Append(name);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|