2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2011-12-03 16:38:03 -06:00
|
|
|
* 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:
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <memory.h>
|
|
|
|
|
|
|
|
#include <Bitmap.h>
|
2010-05-09 04:38:30 -05:00
|
|
|
#include <Directory.h>
|
|
|
|
#include <FindDirectory.h>
|
2015-06-24 11:23:04 -05:00
|
|
|
#include <IconUtils.h>
|
2010-05-09 04:38:30 -05:00
|
|
|
#include <Path.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
#include "CayaUtils.h"
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
CayaStatusToString(CayaStatus status)
|
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case CAYA_ONLINE:
|
|
|
|
return "Available";
|
|
|
|
case CAYA_AWAY:
|
|
|
|
return "Away";
|
|
|
|
case CAYA_DO_NOT_DISTURB:
|
|
|
|
return "Busy";
|
2012-05-15 12:20:11 -05:00
|
|
|
case CAYA_CUSTOM_STATUS:
|
|
|
|
return "Custom Status";
|
|
|
|
case CAYA_INVISIBLE:
|
|
|
|
return "Invisible";
|
|
|
|
case CAYA_OFFLINE:
|
|
|
|
return "Offline";
|
2010-05-07 04:47:10 -05:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-09 03:23:53 -05:00
|
|
|
|
|
|
|
BResources*
|
|
|
|
CayaResources()
|
|
|
|
{
|
|
|
|
image_info info;
|
|
|
|
if (our_image(info) != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BFile file(info.name, B_READ_ONLY);
|
|
|
|
if (file.InitCheck() != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BResources* res = new BResources(&file);
|
|
|
|
if (res->InitCheck() != B_OK) {
|
|
|
|
delete res;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-05-09 04:38:30 -05:00
|
|
|
|
|
|
|
const char*
|
|
|
|
CayaAccountsPath()
|
|
|
|
{
|
|
|
|
BPath path;
|
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
path.Append("Caya/Protocols");
|
|
|
|
if (create_directory(path.Path(), 0755) != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return path.Path();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
CayaAccountPath(const char* signature)
|
|
|
|
{
|
|
|
|
if (!signature)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BPath path(CayaAccountsPath());
|
|
|
|
if (path.InitCheck() != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
path.Append(signature);
|
|
|
|
if (create_directory(path.Path(), 0755) != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return path.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
|
|
|
const char*
|
|
|
|
CayaAccountPath(const char* signature, const char* subsignature)
|
|
|
|
{
|
|
|
|
if (BString(signature) == BString(subsignature)
|
|
|
|
|| BString(subsignature).IsEmpty() == true)
|
|
|
|
return CayaAccountPath(signature);
|
|
|
|
|
|
|
|
BPath path(CayaAccountPath(signature));
|
|
|
|
|
|
|
|
path.Append(subsignature);
|
|
|
|
if (create_directory(path.Path(), 0755) != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return path.Path();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-24 14:20:57 -05:00
|
|
|
const char*
|
|
|
|
CayaCachePath()
|
|
|
|
{
|
|
|
|
BPath path;
|
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
path.Append("Caya/Cache");
|
|
|
|
if (create_directory(path.Path(), 0755) != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return path.Path();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
CayaLogPath(const char* signature, const char* subsignature)
|
|
|
|
{
|
|
|
|
BPath path(CayaCachePath());
|
|
|
|
path.Append("Logs");
|
|
|
|
path.Append(signature);
|
|
|
|
|
|
|
|
if (BString(signature) != BString(subsignature)
|
|
|
|
|| BString(subsignature).IsEmpty() == false)
|
|
|
|
{
|
|
|
|
path.Append(subsignature);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create_directory(path.Path(), 0755) != B_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return path.Path();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
status_t
|
|
|
|
our_image(image_info& image)
|
|
|
|
{
|
|
|
|
team_id team = B_CURRENT_TEAM;
|
|
|
|
|
|
|
|
int32 cookie = 0;
|
|
|
|
while (get_next_image_info(team, &cookie, &image) == B_OK) {
|
2010-05-20 16:31:55 -05:00
|
|
|
if ((char*)our_image >= (char*)image.text
|
|
|
|
&& (char*)our_image <= (char*)image.text + image.text_size)
|
2010-05-07 04:47:10 -05:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|