2010-05-16 16:02:50 -05:00
|
|
|
/*
|
2011-12-03 16:38:03 -06:00
|
|
|
* Copyright 2010-2011, Pier Luigi Fiorini. All rights reserved.
|
2010-05-16 16:02:50 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Bitmap.h>
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
#include <Path.h>
|
2010-05-16 16:02:50 -05:00
|
|
|
|
|
|
|
#include <libinterface/BitmapUtils.h>
|
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
#include "ChatProtocol.h"
|
|
|
|
#include "ChatProtocolAddOn.h"
|
2010-05-16 16:02:50 -05:00
|
|
|
|
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::ChatProtocolAddOn(image_id image, const char* path, int32 subProto)
|
2010-05-19 17:28:26 -05:00
|
|
|
:
|
|
|
|
fImage(image),
|
2010-05-16 16:02:50 -05:00
|
|
|
fPath(path),
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
fIcon(NULL),
|
|
|
|
fProtoIndex(subProto)
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
|
|
|
_Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-23 12:11:17 -06:00
|
|
|
ChatProtocolAddOn::~ChatProtocolAddOn()
|
|
|
|
{
|
|
|
|
delete fIcon;
|
|
|
|
unload_add_on(fImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
status_t
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::InitCheck() const
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
|
|
|
return fStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::Path() const
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
|
|
|
return fPath.String();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocol*
|
|
|
|
ChatProtocolAddOn::Protocol() const
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
return ProtocolAt(fProtoIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocol*
|
|
|
|
ChatProtocolAddOn::ProtocolAt(int32 i) const
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
{
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocol* proto = fGetProtocol(i);
|
2022-02-18 15:42:06 -06:00
|
|
|
proto->SetAddOnPath(fPath.String());
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::CountProtocols() const
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
{
|
|
|
|
return fCountProtocols();
|
2010-05-16 16:02:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::Signature() const
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
|
|
|
return fSignature.String();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::FriendlySignature() const
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
|
|
|
return fFriendlySignature.String();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-22 12:05:44 -05:00
|
|
|
BBitmap*
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::Icon() const
|
2021-05-22 12:05:44 -05:00
|
|
|
{
|
|
|
|
return ReadNodeIcon(fPath, B_LARGE_ICON, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-21 15:52:33 -05:00
|
|
|
const char*
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::ProtoSignature() const
|
2021-05-21 15:52:33 -05:00
|
|
|
{
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocol* proto = Protocol();
|
2021-05-21 15:52:33 -05:00
|
|
|
const char* signature = proto->Signature();
|
|
|
|
delete proto;
|
|
|
|
return signature;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-22 12:05:44 -05:00
|
|
|
const char*
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::ProtoFriendlySignature() const
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
{
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocol* proto = Protocol();
|
2021-05-22 12:05:44 -05:00
|
|
|
const char* signature = proto->FriendlySignature();
|
|
|
|
delete proto;
|
|
|
|
return signature;
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
BBitmap*
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::ProtoIcon() const
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocol* proto = Protocol();
|
2021-05-22 12:05:44 -05:00
|
|
|
BBitmap* icon = proto->Icon();
|
|
|
|
delete proto;
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::Version() const
|
2021-05-22 12:05:44 -05:00
|
|
|
{
|
|
|
|
return fVersion;
|
2010-05-16 16:02:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-20 12:44:20 -05:00
|
|
|
ChatProtocolAddOn::_Init()
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
|
|
|
const char* (*signature)();
|
|
|
|
const char* (*friendly_signature)();
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
uint32 (*version)();
|
2010-05-16 16:02:50 -05:00
|
|
|
|
|
|
|
fStatus = B_OK;
|
|
|
|
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
if (get_image_symbol(fImage, "protocol_at", B_SYMBOL_TYPE_TEXT,
|
2010-05-16 16:02:50 -05:00
|
|
|
(void**)&fGetProtocol) != B_OK) {
|
|
|
|
unload_add_on(fImage);
|
|
|
|
fStatus = B_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
if (get_image_symbol(fImage, "protocol_count", B_SYMBOL_TYPE_TEXT,
|
|
|
|
(void**)&fCountProtocols) != B_OK) {
|
|
|
|
unload_add_on(fImage);
|
|
|
|
fStatus = B_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
if (get_image_symbol(fImage, "signature", B_SYMBOL_TYPE_TEXT,
|
|
|
|
(void**)&signature) != B_OK) {
|
|
|
|
unload_add_on(fImage);
|
|
|
|
fStatus = B_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_image_symbol(fImage, "friendly_signature", B_SYMBOL_TYPE_TEXT,
|
|
|
|
(void**)&friendly_signature) != B_OK) {
|
|
|
|
unload_add_on(fImage);
|
|
|
|
fStatus = B_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
if (get_image_symbol(fImage, "version", B_SYMBOL_TYPE_TEXT,
|
|
|
|
(void**)&version) != B_OK) {
|
|
|
|
unload_add_on(fImage);
|
|
|
|
fStatus = B_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
fSignature = signature();
|
|
|
|
fFriendlySignature = friendly_signature();
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
fVersion = version();
|
2010-05-16 16:02:50 -05:00
|
|
|
}
|