2010-05-07 04:47:10 -05:00
|
|
|
#include "Emoconfig.h"
|
|
|
|
|
|
|
|
#include <File.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <Bitmap.h>
|
|
|
|
#include <String.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#include <TranslationUtils.h>
|
|
|
|
#include "SmileTextRender.h"
|
|
|
|
|
|
|
|
//tmp
|
2010-07-10 08:58:15 -05:00
|
|
|
BMessage* faces = NULL;
|
|
|
|
bool valid = false;
|
|
|
|
bool fname = false;
|
|
|
|
bool svg = false;
|
|
|
|
bool size = true;
|
2010-05-07 04:47:10 -05:00
|
|
|
BString filename;
|
|
|
|
BString face;
|
|
|
|
BPath path;
|
|
|
|
BString gCharacters;
|
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
Emoconfig::Emoconfig(const char* xmlfile): BMessage()
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
fEmoticonSize = 16.0; //default
|
2010-07-10 08:58:15 -05:00
|
|
|
numfaces = 0;
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
fParser = XML_ParserCreate(NULL);
|
|
|
|
|
|
|
|
XML_SetUserData(fParser, this);
|
|
|
|
XML_SetElementHandler(fParser, StartElement, EndElement);
|
|
|
|
XML_SetCharacterDataHandler(fParser, Characters);
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
//path!
|
|
|
|
BPath p(xmlfile);
|
|
|
|
p.GetParent(&path);
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
// loading the config file..
|
2010-07-10 08:58:15 -05:00
|
|
|
BFile* settings = new BFile(xmlfile, B_READ_ONLY);
|
2010-05-07 04:47:10 -05:00
|
|
|
off_t size;
|
|
|
|
settings->GetSize(&size);
|
2010-07-10 08:58:15 -05:00
|
|
|
if (size) {
|
|
|
|
void* buffer = malloc(size);
|
|
|
|
size = settings->Read(buffer, size);
|
2010-05-07 04:47:10 -05:00
|
|
|
XML_Parse(fParser, (const char*)buffer, size, true);
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
delete settings;
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
if (fParser)
|
2010-05-07 04:47:10 -05:00
|
|
|
XML_ParserFree(fParser);
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
printf("Emoconfig: loaded %d faces\n", numfaces);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Emoconfig::~Emoconfig()
|
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
void
|
|
|
|
Emoconfig::StartElement(void * /*pUserData*/, const char* pName, const char** /*pAttr*/)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
//printf("StartElement %s\n",pName);
|
|
|
|
BString name(pName);
|
2010-07-10 08:58:15 -05:00
|
|
|
if (name.ICompare("emoticon") == 0) {
|
|
|
|
faces = new BMessage();
|
|
|
|
svg = false;
|
|
|
|
} else if (name.ICompare("text") == 0 && faces) {
|
|
|
|
valid = true;
|
|
|
|
} else if (name.ICompare("file") == 0 && faces) {
|
|
|
|
fname = true;
|
|
|
|
} else if (name.ICompare("svg") == 0 && faces) {
|
|
|
|
// printf("File is SVG\n");
|
|
|
|
svg = true;
|
|
|
|
} else if (name.ICompare("size") == 0) {
|
|
|
|
size = true;
|
2010-05-07 04:47:10 -05:00
|
|
|
gCharacters = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
void
|
|
|
|
Emoconfig::EndElement(void* pUserData, const char* pName)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
//printf("EndElement %s\n",pName);
|
|
|
|
BString name(pName);
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
if (name.ICompare("emoticon") == 0 && faces) {
|
2010-05-07 04:47:10 -05:00
|
|
|
//faces->PrintToStream(); //debug
|
|
|
|
delete faces;
|
2010-07-10 08:58:15 -05:00
|
|
|
faces = NULL;
|
|
|
|
|
|
|
|
} else if (name.ICompare("text") == 0 && faces) {
|
|
|
|
valid = false;
|
|
|
|
faces->AddString("face", face);
|
2010-05-07 04:47:10 -05:00
|
|
|
//printf("to ]%s[\n",face.String());
|
|
|
|
face.SetTo("");
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
} else if (name.ICompare("file") == 0 && faces) {
|
2010-05-07 04:47:10 -05:00
|
|
|
//load file
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
//compose the filename
|
|
|
|
BPath p(path);
|
|
|
|
p.Append(filename.String());
|
2010-07-10 08:58:15 -05:00
|
|
|
BBitmap* icons = NULL;
|
|
|
|
|
|
|
|
if ( !svg ) {
|
|
|
|
//
|
|
|
|
icons = BTranslationUtils::GetBitmap(p.Path());
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
//assign to faces;
|
2010-07-10 08:58:15 -05:00
|
|
|
fname = false;
|
|
|
|
|
|
|
|
// printf("Filename %s [%s]\n",p.Path(),path.Path());
|
|
|
|
if (!icons) return;
|
|
|
|
|
|
|
|
int i = 0;
|
2010-05-07 04:47:10 -05:00
|
|
|
BString s;
|
2010-07-10 08:58:15 -05:00
|
|
|
while (faces->FindString("face", i, &s) == B_OK) {
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
((Emoconfig*)pUserData)->menu.AddPointer(s.String(), (const void*)icons);
|
|
|
|
((Emoconfig*)pUserData)->menu.AddString("face", s.String());
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
2010-07-10 08:58:15 -05:00
|
|
|
((BMessage*)pUserData)->AddPointer(s.String(), (const void*)icons);
|
|
|
|
((BMessage*)pUserData)->AddString("face", s.String());
|
2010-05-07 04:47:10 -05:00
|
|
|
((Emoconfig*)pUserData)->numfaces++;
|
|
|
|
i++;
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
2010-07-10 08:58:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
} else if (name.ICompare("size") == 0) {
|
|
|
|
if ( size ) {
|
2010-05-07 04:47:10 -05:00
|
|
|
((Emoconfig*)pUserData)->fEmoticonSize = atoi(gCharacters.String());
|
|
|
|
}
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
size = false;
|
|
|
|
}
|
2010-07-10 08:58:15 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2010-07-10 08:58:15 -05:00
|
|
|
void
|
|
|
|
Emoconfig::Characters(void * /*pUserData*/, const char* pString, int pLen)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2010-07-10 08:58:15 -05:00
|
|
|
BString f(pString, pLen);
|
2010-05-07 04:47:10 -05:00
|
|
|
//printf("Characters %s\n",f.String());
|
2010-07-10 08:58:15 -05:00
|
|
|
if (faces && valid) {
|
2010-05-07 04:47:10 -05:00
|
|
|
f.RemoveAll(" ");
|
|
|
|
f.RemoveAll("\"");
|
2010-07-10 08:58:15 -05:00
|
|
|
if (f.Length() > 0)
|
|
|
|
face.Append(f);
|
|
|
|
} else if (fname) {
|
2010-05-07 04:47:10 -05:00
|
|
|
f.RemoveAll(" ");
|
2010-07-10 08:58:15 -05:00
|
|
|
filename = f;
|
|
|
|
|
|
|
|
} else {
|
2010-05-07 04:47:10 -05:00
|
|
|
gCharacters.Append(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|