more work on pages and ressources.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/timestamp.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/directory.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
@@ -75,6 +76,8 @@ static int _getColorComponent(GWEN_DB_NODE *dbPost, const char *sValueName, cons
|
||||
static void _setOnOffData(AQH_DATACLIENT *dc, const AQH_VALUE *value, const char *sValue);
|
||||
static void _setOnOffAutoData(AQH_DATACLIENT *dc, const AQH_VALUE *value, const char *sValue);
|
||||
|
||||
static void _sendPageList(AQH_MODULE *m, GWEN_BUFFER *dbuf);
|
||||
static GWEN_STRINGLIST *_listPageFiles(AQH_MODULE *m);
|
||||
static GWEN_XMLNODE *_readPage(AQH_MODULE *m, const char *sPageName);
|
||||
static GWEN_XMLNODE *_readPageFile(const char *sFilename);
|
||||
static int _layoutFromString(const char *s);
|
||||
@@ -93,7 +96,7 @@ void AQH_ModDevices_RunPageGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *se
|
||||
|
||||
DBG_INFO(NULL, "RunPageGet");
|
||||
dbQuery=AQCGI_Request_GetDbQuery(rq);
|
||||
sPageId=GWEN_DB_GetCharValue(dbQuery, "page", 0, NULL);
|
||||
sPageId=dbQuery?GWEN_DB_GetCharValue(dbQuery, "page", 0, NULL):NULL;
|
||||
if (sPageId && *sPageId) {
|
||||
GWEN_XMLNODE *fileNode;
|
||||
|
||||
@@ -115,6 +118,10 @@ void AQH_ModDevices_RunPageGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *se
|
||||
DBG_INFO(NULL, "here");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Reading page list");
|
||||
_sendPageList(m, dbuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -812,6 +819,86 @@ void _setOnOffAutoData(AQH_DATACLIENT *dc, const AQH_VALUE *value, const char *s
|
||||
|
||||
|
||||
|
||||
void _sendPageList(AQH_MODULE *m, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
GWEN_STRINGLIST *sl;
|
||||
|
||||
GBAS(dbuf, "<h1>Page List</h1>\n");
|
||||
sl=_listPageFiles(m);
|
||||
if (sl) {
|
||||
GWEN_STRINGLISTENTRY *se;
|
||||
|
||||
GBAS(dbuf,
|
||||
"<table class=\"datatable\">\n"
|
||||
"<thead><tr><th>Page</th><th>Title</th></tr></thead>\n"
|
||||
"<tbody>\n");
|
||||
se=GWEN_StringList_FirstEntry(sl);
|
||||
while(se) {
|
||||
const char *filename;
|
||||
|
||||
filename=GWEN_StringListEntry_Data(se);
|
||||
if (filename && *filename) {
|
||||
GWEN_XMLNODE *node;
|
||||
|
||||
DBG_ERROR(NULL, "Reading file \"%s\"", filename);
|
||||
node=_readPageFile(filename);
|
||||
if (node) {
|
||||
GWEN_XMLNODE *nPage;
|
||||
|
||||
nPage=GWEN_XMLNode_FindFirstTag(node, "page", NULL, NULL);
|
||||
if (nPage) {
|
||||
const char *sId;
|
||||
const char *sTitle;
|
||||
|
||||
sId=GWEN_XMLNode_GetProperty(nPage, "id", NULL);
|
||||
sTitle=GWEN_XMLNode_GetProperty(nPage, "title", sId);
|
||||
if (sId && *sId)
|
||||
GBAA(dbuf, "<tr><td><a href=\"page.html?page=%s\">%s</a></td><td>%s</td></tr>\n", sId, sId, sTitle);
|
||||
}
|
||||
GWEN_XMLNode_free(node);
|
||||
}
|
||||
}
|
||||
se=GWEN_StringListEntry_Next(se);
|
||||
}
|
||||
GBAS(dbuf, "</tbody></table>");
|
||||
GWEN_StringList_free(sl);
|
||||
}
|
||||
else {
|
||||
GBAS(dbuf, "No pages.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_STRINGLIST *_listPageFiles(AQH_MODULE *m)
|
||||
{
|
||||
GWEN_BUFFER *fbuf;
|
||||
AQH_SERVICE *sv;
|
||||
GWEN_STRINGLIST *sl;
|
||||
int rv;
|
||||
|
||||
sv=AQH_ModService_GetService(m);
|
||||
fbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GBAA(fbuf, "%s%spages", AQH_Service_GetRuntimeFolder(sv), GWEN_DIR_SEPARATOR_S);
|
||||
sl=GWEN_StringList_new();
|
||||
rv=GWEN_Directory_GetMatchingFilesRecursively(GWEN_Buffer_GetStart(fbuf), sl, "*.xml");
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error reading pages (%d)", rv);
|
||||
GWEN_StringList_free(sl);
|
||||
GWEN_Buffer_free(fbuf);
|
||||
return NULL;
|
||||
}
|
||||
if (GWEN_StringList_Count(sl)<1) {
|
||||
GWEN_StringList_free(sl);
|
||||
GWEN_Buffer_free(fbuf);
|
||||
return NULL;
|
||||
}
|
||||
GWEN_Buffer_free(fbuf);
|
||||
|
||||
return sl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_XMLNODE *_readPage(AQH_MODULE *m, const char *sPageName)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
<ul class="mainmenu" >
|
||||
<li><a href="/aqhome/devices/index.html">Devices</a></li>
|
||||
<li><a href="/aqhome/devices/page.html">Pages</a></li>
|
||||
<li><a href="/aqhome/admin/index.html">Admin</a></li>
|
||||
<li><a href="#news">News</a></li>
|
||||
<li><a href="#contact">Contact</a></li>
|
||||
|
||||
@@ -67,6 +67,7 @@ static int AQH_Tool_ReadAndDumpBmpFile(const char *fname);
|
||||
static int AQH_Tool_ExportBmpFile(const char *fname);
|
||||
|
||||
static int _exportBmp_1bpp(const BMP_FILE *bf);
|
||||
static int _exportBmp_gray8bpp(const BMP_FILE *bf);
|
||||
|
||||
static BMP_FILEHEADER *_fileHeader_new();
|
||||
static void _fileHeader_free(BMP_FILEHEADER *fh);
|
||||
@@ -166,6 +167,8 @@ int AQH_Tool_ExportBmpFile(const char *fname)
|
||||
_dumpBmpImageHeader(bf->imageHeader);
|
||||
if (bf->imageHeader->bitsPerPixel==1)
|
||||
rv=_exportBmp_1bpp(bf);
|
||||
else if (bf->imageHeader->bitsPerPixel==8)
|
||||
rv=_exportBmp_gray8bpp(bf);
|
||||
else {
|
||||
fprintf(stderr, "Invalid bits per pixel (%d)", bf->imageHeader->bitsPerPixel);
|
||||
rv=2;
|
||||
@@ -220,6 +223,69 @@ int _exportBmp_1bpp(const BMP_FILE *bf)
|
||||
|
||||
|
||||
|
||||
int _exportBmp_gray8bpp(const BMP_FILE *bf)
|
||||
{
|
||||
const uint8_t *ptrBuffer;
|
||||
uint32_t lenBuffer;
|
||||
uint32_t offsPixels;
|
||||
const uint8_t *ptrPixels;
|
||||
int imageWidth;
|
||||
int imageHeight;
|
||||
int rowWidthInBytes;
|
||||
int columns;
|
||||
int y;
|
||||
|
||||
ptrBuffer=(const uint8_t *) GWEN_Buffer_GetStart(bf->buffer);
|
||||
lenBuffer=GWEN_Buffer_GetUsedBytes(bf->buffer);
|
||||
offsPixels=bf->fileHeader->offsPixels;
|
||||
ptrPixels=ptrBuffer+offsPixels;
|
||||
imageWidth=bf->imageHeader->imgWidth;
|
||||
imageHeight=bf->imageHeader->imgHeight;
|
||||
columns=imageWidth;
|
||||
rowWidthInBytes=4*((columns+3)/4); /* BMPs have multiple of 4 bytes per row! */
|
||||
fprintf(stdout, "imgData: \n");
|
||||
fprintf(stdout, " .dw %d, %d\n", imageWidth, imageHeight);
|
||||
|
||||
for (y=imageHeight-1; y>=0; y--) {
|
||||
const uint8_t *rowPtr;
|
||||
int x;
|
||||
uint8_t currentByte=0;
|
||||
int writtenBytes=0;
|
||||
int packedPixels=0;
|
||||
|
||||
fprintf(stdout, " .db ");
|
||||
rowPtr=ptrPixels+(y*rowWidthInBytes);
|
||||
for (x=0; x<columns; x++) {
|
||||
uint8_t pixel;
|
||||
uint8_t newPix;
|
||||
|
||||
pixel=rowPtr[x];
|
||||
switch(pixel) {
|
||||
case 0x00: newPix=0b01; break; /* outline color */
|
||||
case 0x60: newPix=0b10; break; /* color 1 */
|
||||
case 0xc0: newPix=0b11; break; /* color 2 */
|
||||
case 0xff: newPix=0b00; break; /* background color */
|
||||
default: newPix=0b00; break; /* background color */
|
||||
}
|
||||
currentByte<<=2;
|
||||
currentByte|=newPix;
|
||||
packedPixels++;
|
||||
if (packedPixels==4) {
|
||||
if (writtenBytes)
|
||||
fprintf(stdout, ", ");
|
||||
fprintf(stdout, "0x%02x", currentByte);
|
||||
writtenBytes++;
|
||||
packedPixels=0;
|
||||
currentByte=0;
|
||||
}
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BMP_FILE *BMP_File_new(const char *fname)
|
||||
|
||||
Reference in New Issue
Block a user