[DEV] reviw theme methode

This commit is contained in:
Edouard DUPIN 2014-01-17 21:12:56 +01:00
parent 8c3d0e0fcf
commit 7d28c888f7
3 changed files with 50 additions and 42 deletions

View File

@ -70,7 +70,7 @@ namespace etk {
* @brief Contructor of the Hach table.
* @param[in] _count Number ob basic elent in the vector.
*/
Hash(int32_t _count=0) :
Hash(int32_t _count = 0) :
m_data(_count) {
// nothing to do
}
@ -85,7 +85,7 @@ namespace etk {
* @note It does not delete pointer if your value is a pointer type...
*/
void clear(void) {
for (size_t iii=0; iii<m_data.size(); iii++) {
for (size_t iii = 0; iii < m_data.size(); ++iii) {
if (m_data[iii] != NULL) {
delete(m_data[iii]);
m_data[iii]=NULL;

View File

@ -12,6 +12,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <etk/tool.h>
#include <etk/Hash.h>
#ifdef __TARGET_OS__Windows
#include "windows.h"
#endif
@ -716,11 +717,12 @@ void etk::FSNode::generateFileSystemPath(void) {
}
TK_DBG_MODE(" THEME party : \"" << themeName << "\" => \"" << basicName << "\"");
themeName = etk::theme::getName(themeName);
std::string themeNameDefault = etk::theme::getNameDefault(themeName);
TK_DBG_MODE(" ==> theme Folder \"" << themeName << "\"");
// search the corect folder :
if (themeName == "") {
TK_WARNING("no theme name detected : set it to \"default\"");
} else if (themeName != "default") {
TK_WARNING("no theme name detected : set it to '" << themeNameDefault << "'");
} else if (themeName != themeNameDefault) {
// Selected theme :
// check in the user data :
m_systemFileName = simplifyPath(baseFolderDataUser + "theme/" + themeName + "/" + basicName);
@ -734,15 +736,14 @@ void etk::FSNode::generateFileSystemPath(void) {
return;
}
}
themeName = "default";
// default theme :
// check in the user data :
m_systemFileName = simplifyPath(baseFolderDataUser + "theme/" + themeName + "/" + basicName);
m_systemFileName = simplifyPath(baseFolderDataUser + "theme/" + themeNameDefault + "/" + basicName);
if (true==directCheckFile(m_systemFileName)) {
return;
}
// check in the Appl data : In every case we return this one ...
m_systemFileName = simplifyPath(baseFolderData + "theme/" + themeName + "/" + basicName);
m_systemFileName = simplifyPath(baseFolderData + "theme/" + themeNameDefault + "/" + basicName);
if (true==directCheckFile(m_systemFileName, true)) {
m_type = etk::FSN_TYPE_THEME_DATA;
return;
@ -1679,50 +1680,19 @@ void etk::FSNode::fileFlush(void) {
// TODO : Add an INIT to reset all allocated parameter :
static etk::Hash<std::string> g_listTheme;
class tmpThemeElement {
public:
std::string refName;
std::string folderName;
};
static std::vector<tmpThemeElement*> g_listTheme;
// set the Folder of a subset of a theme ...
void etk::theme::setName(const std::string& _refName, const std::string& _folderName) {
for(size_t iii=0; iii<g_listTheme.size(); iii++) {
if (NULL != g_listTheme[iii]) {
if (g_listTheme[iii]->refName==_refName) {
g_listTheme[iii]->folderName = _folderName;
// action done
return;
}
}
}
// we did not find it ...
tmpThemeElement* tmpp = new tmpThemeElement();
if (NULL==tmpp) {
TK_ERROR("pb to add a reference theme");
return;
}
tmpp->refName = _refName;
tmpp->folderName = _folderName;
g_listTheme.push_back(tmpp);
g_listTheme.set(_refName, _folderName);
}
void etk::theme::setName(const std::u32string& _refName, const std::u32string& _folderName) {
setName(std::to_string(_refName), std::to_string(_folderName));
}
// get the folder from a Reference theme
std::string etk::theme::getName(const std::string& _refName) {
for(size_t iii=0; iii<g_listTheme.size(); iii++) {
if (NULL != g_listTheme[iii]) {
if (g_listTheme[iii]->refName==_refName) {
return g_listTheme[iii]->folderName;
}
}
if (g_listTheme.exist(_refName) == true) {
return g_listTheme[_refName];
}
// We did not find the theme
return _refName;
}
std::u32string etk::theme::getName(const std::u32string& _refName) {
@ -1741,6 +1711,24 @@ std::vector<std::u32string> etk::theme::listU(void) {
// TODO :
}
static etk::Hash<std::string> g_listThemeDefault;
void etk::theme::setNameDefault(const std::string& _refName, const std::string& _folderName) {
g_listThemeDefault.set(_refName, _folderName);
}
void etk::theme::setNameDefault(const std::u32string& _refName, const std::u32string& _folderName) {
setNameDefault(std::to_string(_refName), std::to_string(_folderName));
}
std::string etk::theme::getNameDefault(const std::string& _refName) {
if (g_listThemeDefault.exist(_refName) == true) {
return g_listThemeDefault[_refName];
}
return "default";
}
std::u32string etk::theme::getNameDefault(const std::u32string& _refName) {
return to_u32string(getNameDefault(std::to_string(_refName)));
}
/* --------------------------------------------------------------------------
*

View File

@ -495,6 +495,7 @@ namespace etk {
* @param[in] _folderName The associated folder of the Theme (like "myTheme/folder/folder2/")
*/
void setName(const std::string& _refName, const std::string& _folderName);
//! @previous
void setName(const std::u32string& _refName, const std::u32string& _folderName);
/**
* @brief get the folder from a Reference theme
@ -502,12 +503,31 @@ namespace etk {
* @return the path of the theme
*/
std::string getName(const std::string& _refName);
//! @previous
std::u32string getName(const std::u32string& _refName);
/**
* @brief Set the default folder of a subset of a theme ...
* @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT"
* @param[in] _folderName The associated default folder of the Theme (like "myTheme/color/default/")
*/
void setNameDefault(const std::string& _refName, const std::string& _folderName);
//! @previous
void setNameDefault(const std::u32string& _refName, const std::u32string& _folderName);
/**
* @brief get the default folder from a Reference theme
* @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT"
* @return the path of the theme
*/
std::string getNameDefault(const std::string& _refName);
//! @previous
std::u32string getNameDefault(const std::u32string& _refName);
/**
* @brief Get the list of all the theme folder availlable in the user Home/appl
* @return The list of elements
*/
std::vector<std::string> list(void);
//! @previous
std::vector<std::u32string> listU(void);
};