2021-06-22 14:42:07 -05:00
|
|
|
/*
|
2021-06-23 23:57:27 -05:00
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2021-06-24 12:22:34 -05:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
2021-06-23 23:57:27 -05:00
|
|
|
*/
|
2021-06-22 14:42:07 -05:00
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
#include "PurpleProtocol.h"
|
2021-06-22 14:42:07 -05:00
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
#include <Application.h>
|
|
|
|
#include <Roster.h>
|
2021-06-22 14:42:07 -05:00
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
#include <ChatProtocolMessages.h>
|
2021-06-22 14:42:07 -05:00
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
#include "PurpleMessages.h"
|
2021-06-22 14:42:07 -05:00
|
|
|
|
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
BMessenger* kAppMessenger = NULL;
|
2021-06-22 14:42:07 -05:00
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
|
|
|
|
ChatProtocol*
|
|
|
|
protocol_at(int32 i)
|
|
|
|
{
|
|
|
|
BMessenger* msgr = ensure_app_messenger();
|
|
|
|
|
|
|
|
BMessage* msg = new BMessage(PURPLE_REQUEST_PROTOCOL_INFO);
|
|
|
|
msg->AddInt64("thread_id", find_thread(NULL));
|
|
|
|
msg->AddInt32("index", i);
|
|
|
|
msgr->SendMessage(msg);
|
|
|
|
|
|
|
|
thread_id sender;
|
|
|
|
|
2021-06-24 12:22:34 -05:00
|
|
|
int32 size = receive_data(&sender, NULL, 0);
|
|
|
|
char buffer[size];
|
|
|
|
receive_data(&sender, buffer, size);
|
|
|
|
BMessage temp;
|
|
|
|
temp.Unflatten(buffer);
|
2021-06-23 23:57:27 -05:00
|
|
|
|
2021-06-24 12:22:34 -05:00
|
|
|
BString name = temp.FindString("name");
|
|
|
|
BString id = temp.FindString("id");
|
|
|
|
|
|
|
|
return (ChatProtocol*)new PurpleProtocol(name, id, temp);
|
2021-06-23 23:57:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32
|
|
|
|
protocol_count()
|
|
|
|
{
|
|
|
|
BMessage* msg = new BMessage(PURPLE_REQUEST_PROTOCOL_COUNT);
|
|
|
|
msg->AddInt64("thread_id", find_thread(NULL));
|
|
|
|
ensure_app_messenger()->SendMessage(msg);
|
|
|
|
|
|
|
|
thread_id sender;
|
2021-06-26 20:40:39 -05:00
|
|
|
return receive_data(&sender, NULL, 0);
|
2021-06-23 23:57:27 -05:00
|
|
|
}
|
2021-06-22 14:42:07 -05:00
|
|
|
|
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
const char*
|
|
|
|
signature()
|
|
|
|
{
|
|
|
|
return "purple";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
friendly_signature()
|
|
|
|
{
|
|
|
|
return "Purple";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32
|
|
|
|
version()
|
|
|
|
{
|
|
|
|
return APP_VERSION_1_PRE_ALPHA_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BMessenger*
|
|
|
|
ensure_app_messenger()
|
|
|
|
{
|
|
|
|
if (kAppMessenger == NULL || kAppMessenger->IsValid() == false) {
|
|
|
|
ensure_app();
|
|
|
|
kAppMessenger = new BMessenger("application/x-vnd.cardie.purple");
|
|
|
|
}
|
|
|
|
return kAppMessenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ensure_app()
|
|
|
|
{
|
|
|
|
BRoster roster;
|
|
|
|
if (roster.IsRunning("application/x-vnd.cardie.purple") == true)
|
|
|
|
return;
|
|
|
|
|
|
|
|
app_info aInfo;
|
|
|
|
be_app->GetAppInfo(&aInfo);
|
|
|
|
BPath protoPath(&aInfo.ref);
|
|
|
|
protoPath.GetParent(&protoPath);
|
|
|
|
protoPath.Append("protocols/purple");
|
|
|
|
|
|
|
|
entry_ref protoRef;
|
|
|
|
BEntry(protoPath.Path()).GetRef(&protoRef);
|
|
|
|
roster.Launch(&protoRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
connect_thread(void* data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-24 12:22:34 -05:00
|
|
|
PurpleProtocol::PurpleProtocol(BString name, BString id, BMessage settings)
|
2021-06-23 23:57:27 -05:00
|
|
|
:
|
|
|
|
fSignature(id),
|
2021-06-24 12:22:34 -05:00
|
|
|
fFriendlySignature(name),
|
|
|
|
fSettingsTemplate(settings)
|
2021-06-22 14:42:07 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
PurpleProtocol::Init(ChatProtocolMessengerInterface* interface)
|
|
|
|
{
|
|
|
|
fMessenger = interface;
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
PurpleProtocol::Shutdown()
|
|
|
|
{
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
PurpleProtocol::Process(BMessage* msg)
|
|
|
|
{
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
PurpleProtocol::UpdateSettings(BMessage* msg)
|
|
|
|
{
|
2021-06-26 20:40:39 -05:00
|
|
|
ensure_app();
|
|
|
|
fPrplMessenger = new BMessenger("application/x-vnd.cardie.purple");
|
|
|
|
msg->what = PURPLE_LOAD_ACCOUNT;
|
|
|
|
_SendPrplMessage(msg);
|
|
|
|
// thread_id thread = spawn_thread(connect_thread, "connect_thread",
|
|
|
|
// B_NORMAL_PRIORITY, (void*)this);
|
2021-06-23 23:57:27 -05:00
|
|
|
|
2021-06-26 20:40:39 -05:00
|
|
|
// if (thread < B_OK)
|
|
|
|
// return B_ERROR;
|
2021-06-23 23:57:27 -05:00
|
|
|
|
2021-06-26 20:40:39 -05:00
|
|
|
// resume_thread(thread);
|
2021-06-22 14:42:07 -05:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BMessage
|
|
|
|
PurpleProtocol::SettingsTemplate(const char* name)
|
|
|
|
{
|
2021-06-24 12:22:34 -05:00
|
|
|
return fSettingsTemplate;
|
2021-06-22 14:42:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BObjectList<BMessage>
|
|
|
|
PurpleProtocol::Commands()
|
|
|
|
{
|
|
|
|
return BObjectList<BMessage>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BObjectList<BMessage>
|
|
|
|
PurpleProtocol::UserPopUpItems()
|
|
|
|
{
|
|
|
|
return BObjectList<BMessage>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BObjectList<BMessage>
|
|
|
|
PurpleProtocol::ChatPopUpItems()
|
|
|
|
{
|
|
|
|
return BObjectList<BMessage>();
|
|
|
|
}
|
|
|
|
|
|
|
|
BObjectList<BMessage>
|
|
|
|
PurpleProtocol::MenuBarItems()
|
|
|
|
{
|
|
|
|
return BObjectList<BMessage>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
PurpleProtocol::Signature() const
|
|
|
|
{
|
2021-06-23 23:57:27 -05:00
|
|
|
return fSignature.String();
|
2021-06-22 14:42:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
PurpleProtocol::FriendlySignature() const
|
|
|
|
{
|
2021-06-23 23:57:27 -05:00
|
|
|
return fFriendlySignature.String();
|
2021-06-22 14:42:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BBitmap*
|
|
|
|
PurpleProtocol::Icon() const
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PurpleProtocol::SetAddOnPath(BPath path)
|
|
|
|
{
|
|
|
|
fAddOnPath = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BPath
|
|
|
|
PurpleProtocol::AddOnPath()
|
|
|
|
{
|
|
|
|
return fAddOnPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
PurpleProtocol::GetName()
|
|
|
|
{
|
|
|
|
return fName.String();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PurpleProtocol::SetName(const char* name)
|
|
|
|
{
|
|
|
|
fName.SetTo(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32
|
|
|
|
PurpleProtocol::GetEncoding()
|
|
|
|
{
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ChatProtocolMessengerInterface*
|
|
|
|
PurpleProtocol::MessengerInterface() const
|
|
|
|
{
|
|
|
|
return fMessenger;
|
|
|
|
}
|
2021-06-26 20:40:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PurpleProtocol::_SendPrplMessage(BMessage* msg)
|
|
|
|
{
|
|
|
|
msg->AddString("account_name", fName);
|
|
|
|
msg->AddString("signature", fSignature);
|
|
|
|
if (fPrplMessenger->IsValid())
|
|
|
|
fPrplMessenger->SendMessage(msg);
|
|
|
|
}
|