mirror of
https://git.koehlerweb.org/frodovdr/vdr-plugin-skindesigner.git
synced 2025-12-26 23:26:51 +01:00
implemented Skin Repositories
This commit is contained in:
236
libcore/curlfuncs.c
Normal file
236
libcore/curlfuncs.c
Normal file
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
Copyright (c) 2002, Mayukh Bose
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Mayukh Bose nor the names of other
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
Change History:
|
||||
11/23/2004 - Removed the #include <unistd.h> line because I didn't
|
||||
need it. Wonder why I had it there in the first place :).
|
||||
10/20/2004 - Publicly released this code.
|
||||
*/
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <curl/curl.h>
|
||||
#include <curl/easy.h>
|
||||
#include <vdr/tools.h>
|
||||
#include "curlfuncs.h"
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Local function prototypes
|
||||
int CurlDoPost(const char *url, string *sOutput, const string &sReferer,
|
||||
struct curl_httppost *formpost, struct curl_slist *headerlist);
|
||||
|
||||
namespace curlfuncs {
|
||||
string sBuf;
|
||||
bool bInitialized = false;
|
||||
CURL *curl = NULL;
|
||||
}
|
||||
|
||||
size_t collect_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
{
|
||||
string sTmp;
|
||||
register size_t actualsize = size * nmemb;
|
||||
if ((FILE *)stream == NULL) {
|
||||
sTmp.assign((char *)ptr, actualsize);
|
||||
curlfuncs::sBuf += sTmp;
|
||||
}
|
||||
else {
|
||||
fwrite(ptr, size, nmemb, (FILE *)stream);
|
||||
}
|
||||
return actualsize;
|
||||
}
|
||||
|
||||
inline void InitCurlLibraryIfNeeded()
|
||||
{
|
||||
if (!curlfuncs::bInitialized) {
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curlfuncs::curl = curl_easy_init();
|
||||
if (!curlfuncs::curl)
|
||||
throw string("Could not create new curl instance");
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_NOPROGRESS, 1); // Do not show progress
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_WRITEFUNCTION, collect_data);
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_WRITEDATA, 0); // Set option to write to string
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_FOLLOWLOCATION, TRUE);
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Mayukh's libcurl wrapper http://www.mayukhbose.com/)");
|
||||
curlfuncs::bInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
int CurlGetUrl(const char *url, string *sOutput, const string &sReferer)
|
||||
{
|
||||
InitCurlLibraryIfNeeded();
|
||||
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_URL, url); // Set the URL to get
|
||||
if (sReferer != "")
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_REFERER, sReferer.c_str());
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_HTTPGET, TRUE);
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_WRITEDATA, 0); // Set option to write to string
|
||||
curlfuncs::sBuf = "";
|
||||
if (curl_easy_perform(curlfuncs::curl) == 0)
|
||||
*sOutput = curlfuncs::sBuf;
|
||||
else {
|
||||
// We have an error here mate!
|
||||
*sOutput = "";
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CurlGetUrlFile(const char *url, const char *filename, const string &sReferer)
|
||||
{
|
||||
int nRet = 0;
|
||||
InitCurlLibraryIfNeeded();
|
||||
|
||||
// Point the output to a file
|
||||
FILE *fp;
|
||||
if ((fp = fopen(filename, "w")) == NULL)
|
||||
return 0;
|
||||
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_WRITEDATA, fp); // Set option to write to file
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_URL, url); // Set the URL to get
|
||||
if (sReferer != "")
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_REFERER, sReferer.c_str());
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_HTTPGET, TRUE);
|
||||
if (curl_easy_perform(curlfuncs::curl) == 0)
|
||||
nRet = 1;
|
||||
else
|
||||
nRet = 0;
|
||||
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_WRITEDATA, NULL); // Set option back to default (string)
|
||||
fclose(fp);
|
||||
return nRet;
|
||||
}
|
||||
|
||||
int CurlPostUrl(const char *url, const string &sPost, string *sOutput, const string &sReferer)
|
||||
{
|
||||
InitCurlLibraryIfNeeded();
|
||||
|
||||
int retval = 1;
|
||||
string::size_type nStart = 0, nEnd, nPos;
|
||||
string sTmp, sName, sValue;
|
||||
struct curl_httppost *formpost=NULL;
|
||||
struct curl_httppost *lastptr=NULL;
|
||||
struct curl_slist *headerlist=NULL;
|
||||
|
||||
// Add the POST variables here
|
||||
while ((nEnd = sPost.find("##", nStart)) != string::npos) {
|
||||
sTmp = sPost.substr(nStart, nEnd - nStart);
|
||||
if ((nPos = sTmp.find("=")) == string::npos)
|
||||
return 0;
|
||||
sName = sTmp.substr(0, nPos);
|
||||
sValue = sTmp.substr(nPos+1);
|
||||
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, sName.c_str(), CURLFORM_COPYCONTENTS, sValue.c_str(), CURLFORM_END);
|
||||
nStart = nEnd + 2;
|
||||
}
|
||||
sTmp = sPost.substr(nStart);
|
||||
if ((nPos = sTmp.find("=")) == string::npos)
|
||||
return 0;
|
||||
sName = sTmp.substr(0, nPos);
|
||||
sValue = sTmp.substr(nPos+1);
|
||||
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, sName.c_str(), CURLFORM_COPYCONTENTS, sValue.c_str(), CURLFORM_END);
|
||||
|
||||
retval = CurlDoPost(url, sOutput, sReferer, formpost, headerlist);
|
||||
|
||||
curl_formfree(formpost);
|
||||
curl_slist_free_all(headerlist);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int CurlPostRaw(const char *url, const string &sPost, string *sOutput, const string &sReferer)
|
||||
{
|
||||
InitCurlLibraryIfNeeded();
|
||||
|
||||
int retval;
|
||||
struct curl_httppost *formpost=NULL;
|
||||
struct curl_slist *headerlist=NULL;
|
||||
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_POSTFIELDS, sPost.c_str());
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_POSTFIELDSIZE, 0); //FIXME: Should this be the size instead, in case this is binary string?
|
||||
|
||||
retval = CurlDoPost(url, sOutput, sReferer, formpost, headerlist);
|
||||
|
||||
curl_formfree(formpost);
|
||||
curl_slist_free_all(headerlist);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int CurlDoPost(const char *url, string *sOutput, const string &sReferer,
|
||||
struct curl_httppost *formpost, struct curl_slist *headerlist)
|
||||
{
|
||||
headerlist = curl_slist_append(headerlist, "Expect:");
|
||||
|
||||
// Now do the form post
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_URL, url);
|
||||
if (sReferer != "")
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_REFERER, sReferer.c_str());
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_HTTPPOST, formpost);
|
||||
|
||||
curl_easy_setopt(curlfuncs::curl, CURLOPT_WRITEDATA, 0); // Set option to write to string
|
||||
curlfuncs::sBuf = "";
|
||||
if (curl_easy_perform(curlfuncs::curl) == 0) {
|
||||
*sOutput = curlfuncs::sBuf;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
// We have an error here mate!
|
||||
*sOutput = "";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void FreeCurlLibrary(void)
|
||||
{
|
||||
if (curlfuncs::curl)
|
||||
curl_easy_cleanup(curlfuncs::curl);
|
||||
curl_global_cleanup();
|
||||
curlfuncs::bInitialized = false;
|
||||
}
|
||||
|
||||
int CurlSetCookieFile(char *filename)
|
||||
{
|
||||
InitCurlLibraryIfNeeded();
|
||||
if (curl_easy_setopt(curlfuncs::curl, CURLOPT_COOKIEFILE, filename) != 0)
|
||||
return 0;
|
||||
if (curl_easy_setopt(curlfuncs::curl, CURLOPT_COOKIEJAR, filename) != 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *CurlEscape(const char *url) {
|
||||
InitCurlLibraryIfNeeded();
|
||||
return curl_escape(url , strlen(url));
|
||||
}
|
||||
45
libcore/curlfuncs.h
Normal file
45
libcore/curlfuncs.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright (c) 2002, Mayukh Bose
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Mayukh Bose nor the names of other
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __CURLFUNCS_H_20020513__
|
||||
#define __CURLFUNCS_H_20020513__
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
int CurlGetUrl(const char *url, string *sOutput, const string &sReferer="");
|
||||
int CurlGetUrlFile(const char *url, const char *filename, const string &sReferer="");
|
||||
void FreeCurlLibrary(void);
|
||||
int CurlSetCookieFile(char *filename);
|
||||
int CurlPostUrl(const char *url, const string &sPost, string *sOutput, const string &sReferer = "");
|
||||
int CurlPostRaw(const char *url, const string &sPost, string *sOutput, const string &sReferer = "");
|
||||
char *CurlEscape(const char *url);
|
||||
#endif
|
||||
@@ -178,3 +178,18 @@ int cFontManager::GetFontHeight(const char *name, int height, int charWidth) {
|
||||
|
||||
return realHeight;
|
||||
}
|
||||
|
||||
bool cFontManager::FontInstalled(string fontName) {
|
||||
cStringList availableFonts;
|
||||
cFont::GetAvailableFontNames(&availableFonts);
|
||||
int numFonts = availableFonts.Size();
|
||||
string compare = fontName + ":";
|
||||
for (int i=0; i<numFonts; i++) {
|
||||
string currentFont = availableFonts[i];
|
||||
if (currentFont.find(compare) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ class cFontManager {
|
||||
cFont *FontUncached(string fontName, int fontSize);
|
||||
void Debug(void);
|
||||
void ListAvailableFonts(void);
|
||||
bool FontInstalled(string fontName);
|
||||
};
|
||||
|
||||
#endif //__FONTMANAGER_H
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "helpers.h"
|
||||
#include <vdr/skins.h>
|
||||
|
||||
|
||||
@@ -27,18 +27,20 @@ cImageCache::~cImageCache() {
|
||||
}
|
||||
|
||||
void cImageCache::SetPathes(void) {
|
||||
string logoPathSkin = *cString::sprintf("%s%s/themes/%s/logos/", *config.skinPath, Setup.OSDSkin, Setup.OSDTheme);
|
||||
cString skinPath = config.GetSkinPath(Setup.OSDSkin);
|
||||
|
||||
string logoPathSkin = *cString::sprintf("%s%s/themes/%s/logos/", *skinPath, Setup.OSDSkin, Setup.OSDTheme);
|
||||
if (FolderExists(logoPathSkin)) {
|
||||
logoPath = logoPathSkin;
|
||||
} else {
|
||||
logoPath = *config.logoPath;
|
||||
}
|
||||
|
||||
iconPathSkin = *cString::sprintf("%s%s/", *config.skinPath, Setup.OSDSkin);
|
||||
skinPartsPathSkin = *cString::sprintf("%s%s/skinparts/", *config.skinPath, Setup.OSDSkin);
|
||||
iconPathSkin = *cString::sprintf("%s%s/", *skinPath, Setup.OSDSkin);
|
||||
skinPartsPathSkin = *cString::sprintf("%s%s/skinparts/", *skinPath, Setup.OSDSkin);
|
||||
|
||||
iconPathTheme = *cString::sprintf("%s%s/themes/%s/", *config.skinPath, Setup.OSDSkin, Setup.OSDTheme);
|
||||
skinPartsPathTheme = *cString::sprintf("%s%s/themes/%s/skinparts/", *config.skinPath, Setup.OSDSkin, Setup.OSDTheme);
|
||||
iconPathTheme = *cString::sprintf("%s%s/themes/%s/", *skinPath, Setup.OSDSkin, Setup.OSDTheme);
|
||||
skinPartsPathTheme = *cString::sprintf("%s%s/themes/%s/skinparts/", *skinPath, Setup.OSDSkin, Setup.OSDTheme);
|
||||
|
||||
dsyslog("skindesigner: using channel logo path %s", logoPath.c_str());
|
||||
dsyslog("skindesigner: using icon path %s", iconPathTheme.c_str());
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "skinrepo.h"
|
||||
#include "../libcore/helpers.h"
|
||||
|
||||
@@ -8,25 +10,59 @@ using namespace std;
|
||||
cSkinRepo::cSkinRepo(void) {
|
||||
name = "";
|
||||
repoType = rtUndefined;
|
||||
action = eaUndefined;
|
||||
url = "";
|
||||
author = "unknown";
|
||||
command = "";
|
||||
command2 = "";
|
||||
tempfile = "";
|
||||
result = -1;
|
||||
skinPath = "";
|
||||
themesPath = "";
|
||||
}
|
||||
|
||||
cSkinRepo::~cSkinRepo() {
|
||||
}
|
||||
|
||||
void cSkinRepo::Install(string path) {
|
||||
void cSkinRepo::Install(string path, string themesPath) {
|
||||
if (Running())
|
||||
return;
|
||||
action = eaInstall;
|
||||
this->skinPath = path + name;
|
||||
this->themesPath = themesPath;
|
||||
if (repoType == rtGit) {
|
||||
|
||||
command = *cString::sprintf("git clone --progress %s %s%s", url.c_str(), path.c_str(), name.c_str());
|
||||
command = *cString::sprintf("git clone --progress %s %s", url.c_str(), skinPath.c_str());
|
||||
tempfile = *cString::sprintf("gitclone_%s_%ld.out", name.c_str(), time(0));
|
||||
|
||||
Start();
|
||||
|
||||
} else if (repoType == rtZipUrl) {
|
||||
|
||||
size_t hit = url.find_last_of('/');
|
||||
if (hit == string::npos)
|
||||
return;
|
||||
string filename = url.substr(hit+1);
|
||||
|
||||
command = *cString::sprintf("wget -P /tmp/ %s", url.c_str());
|
||||
command2 = *cString::sprintf("unzip /tmp/%s -d %s", filename.c_str(), path.c_str());
|
||||
|
||||
Start();
|
||||
}
|
||||
}
|
||||
|
||||
void cSkinRepo::Update(string path) {
|
||||
if (Running())
|
||||
return;
|
||||
action = eaUpdate;
|
||||
this->skinPath = path + name;
|
||||
if (repoType == rtGit) {
|
||||
|
||||
command = *cString::sprintf("cd %s; git pull", skinPath.c_str());
|
||||
tempfile = *cString::sprintf("gitpull_%s_%ld.out", name.c_str(), time(0));
|
||||
|
||||
Start();
|
||||
|
||||
} else if (repoType == rtZipUrl) {
|
||||
|
||||
//TODO
|
||||
@@ -40,9 +76,66 @@ void cSkinRepo::Action(void) {
|
||||
if (tempfile.size() > 0) {
|
||||
command = *cString::sprintf("%s > /tmp/%s 2>&1", command.c_str(), tempfile.c_str());
|
||||
}
|
||||
dsyslog("skindesigner: executing %s", command.c_str());
|
||||
|
||||
result = system (command.c_str());
|
||||
dsyslog("skindesigner: execution done, result: %d", result);
|
||||
|
||||
if (result == 0 && command2.size() > 0) {
|
||||
result = system (command2.c_str());
|
||||
}
|
||||
|
||||
if (result == 0) {
|
||||
if (action == eaInstall)
|
||||
CreateThemeFiles();
|
||||
}
|
||||
}
|
||||
|
||||
void cSkinRepo::CreateThemeFiles(void) {
|
||||
string availableThemesPath = skinPath + "/themes/";
|
||||
DIR *folder = NULL;
|
||||
struct dirent *dirEntry;
|
||||
folder = opendir(availableThemesPath.c_str());
|
||||
if (!folder) {
|
||||
return;
|
||||
}
|
||||
vector<string> skinThemes;
|
||||
while (dirEntry = readdir(folder)) {
|
||||
string dirEntryName = dirEntry->d_name;
|
||||
int dirEntryType = dirEntry->d_type;
|
||||
if (!dirEntryName.compare(".") || !dirEntryName.compare("..") || dirEntryType != DT_DIR)
|
||||
continue;
|
||||
skinThemes.push_back(dirEntryName);
|
||||
}
|
||||
for (vector<string>::iterator it = skinThemes.begin(); it != skinThemes.end(); it++) {
|
||||
string themeName = *it;
|
||||
string themeFileName = themesPath;
|
||||
themeFileName += name + "-" + themeName + ".theme";
|
||||
if (FileExists(themeFileName)) {
|
||||
continue;
|
||||
}
|
||||
ofstream themeFile (themeFileName.c_str());
|
||||
if (themeFile.is_open()) {
|
||||
themeFile << "Description = ";
|
||||
themeFile << themeName << "\n";
|
||||
themeFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool cSkinRepo::SuccessfullyUpdated(void) {
|
||||
string logfilePath = "/tmp/" + tempfile;
|
||||
bool updated = true;
|
||||
string line;
|
||||
ifstream logfile(logfilePath.c_str());
|
||||
if (logfile.is_open()) {
|
||||
while ( getline (logfile, line) ) {
|
||||
if (line.find("up-to-date") != string::npos) {
|
||||
updated = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
logfile.close();
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
void cSkinRepo::Debug() {
|
||||
@@ -53,6 +146,7 @@ void cSkinRepo::Debug() {
|
||||
strRepoType = "ZipUrl";
|
||||
dsyslog("skindesigner: --- skinrepo %s, Type %s ---", name.c_str(), strRepoType.c_str());
|
||||
dsyslog("skindesigner: url %s", url.c_str());
|
||||
dsyslog("skindesigner: author %s", author.c_str());
|
||||
if (specialFonts.size() > 0) {
|
||||
for (vector<string>::iterator it = specialFonts.begin(); it != specialFonts.end(); it++) {
|
||||
dsyslog("skindesigner: special font %s", (*it).c_str());
|
||||
@@ -87,7 +181,6 @@ cSkinRepos::~cSkinRepos() {
|
||||
|
||||
void cSkinRepos::Read(string path) {
|
||||
string filepath = path + repoFile;
|
||||
esyslog("skindesigner: reading skinrepos from %s", filepath.c_str());
|
||||
xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
|
||||
xmlNodePtr root = NULL;
|
||||
|
||||
@@ -132,6 +225,14 @@ cSkinRepo *cSkinRepos::GetRepo(string name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cSkinRepo *cSkinRepos::GetNextRepo(void) {
|
||||
if (repoIt == repos.end())
|
||||
return NULL;
|
||||
cSkinRepo *repo = *repoIt;
|
||||
repoIt++;
|
||||
return repo;
|
||||
}
|
||||
|
||||
|
||||
void cSkinRepos::Debug(void) {
|
||||
for (vector<cSkinRepo*>::iterator it = repos.begin(); it != repos.end(); it++) {
|
||||
@@ -171,6 +272,11 @@ void cSkinRepos::ReadRepository(xmlNodePtr node) {
|
||||
value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
|
||||
if (value)
|
||||
repo->SetUrl((const char *)value);
|
||||
//Skin Author
|
||||
} else if (!xmlStrcmp(node->name, (const xmlChar *) "author")) {
|
||||
value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
|
||||
if (value)
|
||||
repo->SetAuthor((const char *)value);
|
||||
//Repo Specialfonts
|
||||
} else if (!xmlStrcmp(node->name, (const xmlChar *) "specialfonts")) {
|
||||
xmlNodePtr child = node->xmlChildrenNode;
|
||||
|
||||
@@ -18,33 +18,55 @@ enum eRepoType {
|
||||
rtZipUrl
|
||||
};
|
||||
|
||||
enum eAction {
|
||||
eaUndefined,
|
||||
eaInstall,
|
||||
eaUpdate
|
||||
};
|
||||
|
||||
// --- cSkinRepo -------------------------------------------------------------
|
||||
|
||||
class cSkinRepo : public cThread {
|
||||
private:
|
||||
string name;
|
||||
eRepoType repoType;
|
||||
eAction action;
|
||||
string url;
|
||||
string author;
|
||||
vector<string> specialFonts;
|
||||
vector<string> supportedPlugins;
|
||||
vector< pair < string, string > > screenshots;
|
||||
//helpers for execution
|
||||
string command;
|
||||
string command2;
|
||||
string tempfile;
|
||||
int result;
|
||||
string skinPath;
|
||||
string themesPath;
|
||||
virtual void Action(void);
|
||||
void CreateThemeFiles(void);
|
||||
public:
|
||||
cSkinRepo(void);
|
||||
virtual ~cSkinRepo(void);
|
||||
void SetName(string name) { this->name = name; };
|
||||
void SetRepoType(eRepoType type) { this->repoType = type; };
|
||||
void SetUrl(string url) { this->url = url; };
|
||||
void SetAuthor(string author) { this->author = author; };
|
||||
void SetSpecialFont(string font) { specialFonts.push_back(font); };
|
||||
void SetSupportedPlugin(string plugin) { supportedPlugins.push_back(plugin); };
|
||||
void SetScreenshot(string desc, string url) { screenshots.push_back(pair<string, string>(desc, url)); };
|
||||
eRepoType Type(void) { return repoType; };
|
||||
string Name(void) { return name; };
|
||||
void Install(string path);
|
||||
string Author(void) { return author; };
|
||||
string Url(void) { return url; };
|
||||
vector<string> SpecialFonts(void) { return specialFonts; };
|
||||
vector<string> SupportedPlugins(void) { return supportedPlugins; };
|
||||
vector< pair < string, string > > Screenshots(void) { return screenshots; };
|
||||
void Install(string path, string themesPath);
|
||||
void Update(string path);
|
||||
bool InstallationFinished(void) { return !(Running()); };
|
||||
bool SuccessfullyInstalled(void) { if (result == 0) return true; return false; };
|
||||
bool SuccessfullyUpdated(void);
|
||||
void Debug(void);
|
||||
};
|
||||
|
||||
@@ -55,12 +77,16 @@ private:
|
||||
string repoFile;
|
||||
xmlDocPtr doc;
|
||||
vector<cSkinRepo*> repos;
|
||||
vector<cSkinRepo*>::iterator repoIt;
|
||||
void ReadRepository(xmlNodePtr node);
|
||||
public:
|
||||
cSkinRepos(void);
|
||||
virtual ~cSkinRepos(void);
|
||||
void Read(string path);
|
||||
int Count(void) { return repos.size(); };
|
||||
cSkinRepo *GetRepo(string name);
|
||||
void InitRepoIterator(void) { repoIt = repos.begin(); };
|
||||
cSkinRepo *GetNextRepo(void);
|
||||
void Debug(void);
|
||||
};
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ cSkinSetupMenu::cSkinSetupMenu(void) {
|
||||
}
|
||||
|
||||
cSkinSetupMenu::~cSkinSetupMenu(void) {
|
||||
for (map < string, cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) {
|
||||
delete p->second;
|
||||
for (vector < cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) {
|
||||
delete (*p);
|
||||
}
|
||||
for (vector < cSkinSetupMenu* >::iterator s = subMenus.begin(); s != subMenus.end(); s++) {
|
||||
delete (*s);
|
||||
@@ -43,7 +43,7 @@ cSkinSetupMenu::~cSkinSetupMenu(void) {
|
||||
cSkinSetupParameter *cSkinSetupMenu::GetNextParameter(bool deep) {
|
||||
cSkinSetupParameter *param = NULL;
|
||||
if (paramIt != parameters.end()) {
|
||||
param = paramIt->second;
|
||||
param = *paramIt;
|
||||
paramIt++;
|
||||
return param;
|
||||
}
|
||||
@@ -64,9 +64,10 @@ cSkinSetupParameter *cSkinSetupMenu::GetNextParameter(bool deep) {
|
||||
}
|
||||
|
||||
cSkinSetupParameter *cSkinSetupMenu::GetParameter(string name) {
|
||||
map < string, cSkinSetupParameter* >::iterator hit = parameters.find(name);
|
||||
if (hit != parameters.end())
|
||||
return hit->second;
|
||||
for (vector < cSkinSetupParameter* >::iterator it = parameters.begin(); it != parameters.end(); it++) {
|
||||
if (!name.compare((*it)->name))
|
||||
return *it;
|
||||
}
|
||||
|
||||
cSkinSetupParameter *paramHit = NULL;
|
||||
for (vector < cSkinSetupMenu* >::iterator subMenu = subMenus.begin(); subMenu != subMenus.end(); subMenu++) {
|
||||
@@ -101,7 +102,7 @@ void cSkinSetupMenu::SetParameter(eSetupParameterType paramType, xmlChar *name,
|
||||
}
|
||||
param->value = atoi((const char*)value);
|
||||
|
||||
parameters.insert(pair< string, cSkinSetupParameter* >(param->name, param));
|
||||
parameters.push_back(param);
|
||||
}
|
||||
|
||||
cSkinSetupMenu *cSkinSetupMenu::GetMenu(string &name) {
|
||||
@@ -134,8 +135,8 @@ cSkinSetupMenu *cSkinSetupMenu::GetNextSubMenu(bool deep) {
|
||||
|
||||
void cSkinSetupMenu::Debug(bool deep) {
|
||||
dsyslog("skindesigner: Menu %s Setup Parameters", name.c_str());
|
||||
for (map < string, cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) {
|
||||
(p->second)->Debug();
|
||||
for (vector < cSkinSetupParameter* >::iterator p = parameters.begin(); p != parameters.end(); p++) {
|
||||
(*p)->Debug();
|
||||
}
|
||||
if (subMenus.empty())
|
||||
return;
|
||||
@@ -159,7 +160,7 @@ cSkinSetup::~cSkinSetup() {
|
||||
}
|
||||
|
||||
bool cSkinSetup::ReadFromXML(void) {
|
||||
string xmlPath = *cString::sprintf("%s%s/setup.xml", *config.skinPath, skin.c_str());
|
||||
string xmlPath = *cString::sprintf("%s%s/setup.xml", *config.GetSkinPath(skin), skin.c_str());
|
||||
cXmlParser parser;
|
||||
if (!parser.ReadSkinSetup(this, xmlPath)) {
|
||||
return false;
|
||||
|
||||
@@ -43,8 +43,8 @@ private:
|
||||
cSkinSetupMenu *parent;
|
||||
vector < cSkinSetupMenu* > subMenus;
|
||||
vector < cSkinSetupMenu* >::iterator subMenuIt;
|
||||
map < string, cSkinSetupParameter* > parameters;
|
||||
map < string, cSkinSetupParameter* >::iterator paramIt;
|
||||
vector < cSkinSetupParameter* > parameters;
|
||||
vector < cSkinSetupParameter* >::iterator paramIt;
|
||||
public:
|
||||
cSkinSetupMenu(void);
|
||||
virtual ~cSkinSetupMenu(void);
|
||||
|
||||
Reference in New Issue
Block a user