Skip to content

Commit 6e920b7

Browse files
committed
RetroFe now accepts Themes from <Home directory>/layouts. For the FunKey S, this means any new themes can be added to /mnt/FunKey/.retrofe/layouts. Can't wait to see what's going to come out of this
1 parent f162704 commit 6e920b7

File tree

12 files changed

+156
-78
lines changed

12 files changed

+156
-78
lines changed

RetroFE/Source/Database/Configuration.cpp

Lines changed: 86 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <locale>
2121
#include <fstream>
2222
#include <sstream>
23+
#include <sys/stat.h>
2324

2425
#ifdef WIN32
2526
#include <windows.h>
@@ -33,6 +34,8 @@
3334
#endif
3435

3536
std::string Configuration::absolutePath;
37+
std::string Configuration::userPath;
38+
bool Configuration::isUserLayout_ = false;
3639

3740
Configuration::Configuration()
3841
{
@@ -54,13 +57,13 @@ void Configuration::initialize()
5457
{
5558
absolutePath = environment;
5659
}
57-
#if defined(__linux) || defined(__APPLE__)
60+
/*#if defined(__linux) || defined(__APPLE__)
5861
// Or check for home based flat file works on linux/mac
5962
else if (retrofe_path && std::getline( retrofe_path, absolutePath ))
6063
{
61-
retrofe_path.close();
64+
retrofe_path.close();
6265
}
63-
#endif
66+
#endif*/
6467
// Or check executable for path
6568
else
6669
{
@@ -94,6 +97,13 @@ void Configuration::initialize()
9497

9598
absolutePath = sPath;
9699
}
100+
101+
/** Get user path */
102+
struct stat info;
103+
if(stat(home_load.c_str(), &info) == 0){
104+
//if(IsPathExist(home_load)){
105+
userPath = home_load;
106+
}
97107
}
98108

99109
bool Configuration::import(std::string keyPrefix, std::string file)
@@ -136,7 +146,7 @@ bool Configuration::import(std::string collection, std::string keyPrefix, std::s
136146
return retVal;
137147
}
138148

139-
bool Configuration::importLayouts(std::string folder, std::string file, bool mustExist)
149+
bool Configuration::importLayouts(std::string folder, std::string file, bool userLayout, bool mustExist)
140150
{
141151
bool retVal = true;
142152
int lineCount = 0;
@@ -169,21 +179,32 @@ bool Configuration::importLayouts(std::string folder, std::string file, bool mus
169179

170180
if(line.empty() || (line.find_first_not_of(" \t\r") == std::string::npos))
171181
{
172-
retVal = true;
182+
retVal = true;
173183
}
174184
else
175185
{
176-
std::string layoutName = trimEnds(line);
177-
std::string layoutPath = Utils::combinePath(folder, layoutName);
178186

179-
/* Set new layoutPath */
180-
layouts_.push_back(layoutPath);
181187

182-
std::stringstream ss;
183-
ss << "Dump layouts: " << "\"" << layoutPath << "\"";
188+
std::string layoutName = trimEnds(line);
189+
std::string layoutPath = Utils::combinePath(folder, layoutName);
190+
191+
/** Check if dir exists */
192+
struct stat info;
193+
if(stat(layoutPath.c_str(), &info) != 0){
194+
//if(!IsPathExist(layoutPath)){
195+
printf("Layout path: %s does not exist\n", layoutPath.c_str());
196+
Logger::write(Logger::ZONE_ERROR, "Configuration", "Layout path: " + layoutPath + " does not exist");
197+
continue;
198+
}
199+
200+
/* Set new layoutPath */
201+
layouts_.push_back( LayoutPair(layoutPath, userLayout) );
202+
203+
std::stringstream ss;
204+
ss << "Dump layouts: " << "\"" << layoutPath << "\"";
184205

185-
Logger::write(Logger::ZONE_INFO, "Configuration", ss.str());
186-
retVal = true;
206+
Logger::write(Logger::ZONE_INFO, "Configuration", ss.str());
207+
retVal = true;
187208
}
188209
}
189210

@@ -230,46 +251,74 @@ bool Configuration::importCurrentLayout(std::string folder, std::string file, bo
230251
{
231252
retVal = false;
232253
}
233-
// finding layout in existing list
254+
// Check if layout is in existing list
234255
else
235256
{
236257
std::string seekedLayoutName = trimEnds(line);
237-
std::string layoutPathFound;
238258
bool layoutFoundInList = false;
259+
bool userLayout = false;
260+
std::string layoutPath;
239261

240-
// check existing layout list */
241-
for(std::vector<std::string>::iterator it = layouts_.begin(); it != layouts_.end(); ++it){
242-
std::string curLayoutName = Utils::getFileName(*it);
262+
/** Check existing layout list */
263+
for(std::vector<LayoutPair>::iterator it = layouts_.begin(); it != layouts_.end(); ++it){
264+
std::string curLayoutName = Utils::getFileName((*it).first);
265+
userLayout = (*it).second;
243266
if(!curLayoutName.compare(seekedLayoutName)){
244-
layoutPathFound = *it;
245267
layoutFoundInList = true;
246268
break;
247269
}
248270
index++;
249271
}
250272

251-
if (layoutFoundInList){
273+
/** Reset default theme if not found in list */
274+
if(!layoutFoundInList){
275+
Logger::write(Logger::ZONE_ERROR, "Configuration", "Layout \"" + seekedLayoutName + "\" not found in list! Resetting \"Classic\" theme by default");
276+
printf("Layout \"%s\" not found in list!\n", seekedLayoutName.c_str());
252277

253-
/* remove layout properties if they already exist */
254-
if(properties_.find("layout") != properties_.end())
255-
{
256-
properties_.erase("layout");
257-
}
278+
seekedLayoutName = std::string("Classic");
279+
userLayout = false;
280+
layoutPath = Utils::combinePath(Configuration::absolutePath, "layouts", seekedLayoutName);
281+
index = 0;
282+
}
258283

259-
/* Set new pair <key, value> for key = layout */
260-
properties_.insert(PropertiesPair("layout", seekedLayoutName));
284+
/** Check if Layout path exists */
285+
if(userLayout){
286+
layoutPath = Utils::combinePath(Configuration::userPath, "layouts", seekedLayoutName);
287+
}
288+
else{
289+
layoutPath = Utils::combinePath(Configuration::absolutePath, "layouts", seekedLayoutName);
290+
}
291+
printf("Layout directory is \"%s\" \n", layoutPath.c_str());
292+
struct stat info;
293+
if(stat(layoutPath.c_str(), &info) != 0){
294+
//if(IsPathExist(layoutPath)){
295+
Logger::write(Logger::ZONE_ERROR, "Configuration", "Layout directory\"" + layoutPath + "\" was not found! Resetting \"Classic\" theme by default");
296+
printf("Layout directory \"%s\" was not found!\n", layoutPath.c_str());
297+
}
261298

262-
std::stringstream ss;
263-
//printf("Found layout: %s at idx %d\n", layoutPathFound.c_str(), index);
264-
ss << "Found layout: " << "\"" << layoutPathFound << "\" in layouts list at idx " << index;
265-
Logger::write(Logger::ZONE_INFO, "Configuration", ss.str());
266-
retVal = true;
299+
/* Remove layout properties if they already exist */
300+
if(properties_.find("layout") != properties_.end())
301+
{
302+
properties_.erase("layout");
303+
}
304+
if(properties_.find("userTheme") != properties_.end())
305+
{
306+
properties_.erase("userTheme");
307+
}
267308

268-
break;
269-
}
270-
else{
271-
index = 0;
272-
}
309+
/* Set new pair <key, value> for key = layout */
310+
properties_.insert(PropertiesPair("layout", seekedLayoutName));
311+
properties_.insert(PropertiesPair("userTheme", userLayout?"yes":"no"));
312+
313+
Configuration::isUserLayout_ = userLayout;
314+
315+
std::stringstream ss;
316+
//printf("Found layout: %s at idx %d\n", layoutPathFound.c_str(), index);
317+
ss << "Found layout: " << "\"" << layoutPath << "\" in layouts list at idx " << index;
318+
Logger::write(Logger::ZONE_INFO, "Configuration", ss.str());
319+
retVal = true;
320+
321+
break;
273322
}
274323
}
275324

RetroFE/Source/Database/Configuration.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Configuration
3030
// gets the global configuration
3131
bool import(std::string keyPrefix, std::string file);
3232
bool import(std::string collection, std::string keyPrefix, std::string file, bool mustExist = true);
33-
bool importLayouts(std::string folder, std::string file, bool mustExist = true);
33+
bool importLayouts(std::string folder, std::string file, bool userLayout=false, bool mustExist = true);
3434
bool importCurrentLayout(std::string folder, std::string file, bool mustExist = true);
3535
bool exportCurrentLayout(std::string layoutFilePath, std::string layoutName);
3636
bool getProperty(std::string key, std::string &value);
@@ -45,7 +45,10 @@ class Configuration
4545
void getMediaPropertyAbsolutePath(std::string collectionName, std::string mediaType, bool system, std::string &value);
4646
void getCollectionAbsolutePath(std::string collectionName, std::string &value);
4747
static std::string absolutePath;
48-
std::vector<std::string> layouts_;
48+
static std::string userPath;
49+
static bool isUserLayout_;
50+
typedef std::pair<std::string, bool> LayoutPair;
51+
std::vector<LayoutPair> layouts_;
4952
int currentLayoutIdx_;
5053

5154
private:

RetroFE/Source/Graphics/Component/ReloadableMedia.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void ReloadableMedia::reloadTexture( bool previousItem )
419419
{
420420
std::string imagePath;
421421
ImageBuilder imageBuild;
422-
imagePath = Utils::combinePath(Configuration::absolutePath, "collections", collectionName );
422+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "collections", collectionName );
423423
imagePath = Utils::combinePath( imagePath, "system_artwork" );
424424
loadedComponent_ = imageBuild.CreateImage( imagePath, page, std::string("fallback"), scaleX_, scaleY_, ditheringAuthorized_ );
425425
}
@@ -448,11 +448,11 @@ Component *ReloadableMedia::findComponent(std::string collection, std::string ty
448448
config_.getProperty("layout", layoutName);
449449
if (commonMode_)
450450
{
451-
imagePath = Utils::combinePath(Configuration::absolutePath, "layouts", layoutName, "collections", "_common");
451+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "layouts", layoutName, "collections", "_common");
452452
}
453453
else
454454
{
455-
imagePath = Utils::combinePath(Configuration::absolutePath, "layouts", layoutName, "collections", collection);
455+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "layouts", layoutName, "collections", collection);
456456
}
457457
if (systemMode)
458458
imagePath = Utils::combinePath(imagePath, "system_artwork");
@@ -463,7 +463,7 @@ Component *ReloadableMedia::findComponent(std::string collection, std::string ty
463463
{
464464
if (commonMode_)
465465
{
466-
imagePath = Utils::combinePath(Configuration::absolutePath, "collections", "_common" );
466+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "collections", "_common" );
467467
if (systemMode)
468468
imagePath = Utils::combinePath(imagePath, "system_artwork");
469469
else

RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ void ReloadableScrollingText::loadText( std::string collection, std::string type
483483
{
484484
std::string layoutName;
485485
config_.getProperty("layout", layoutName);
486-
textPath = Utils::combinePath(Configuration::absolutePath, "layouts", layoutName, "collections", collection);
486+
textPath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "layouts", layoutName, "collections", collection);
487487
if (systemMode)
488488
textPath = Utils::combinePath(textPath, "system_artwork");
489489
else

RetroFE/Source/Graphics/Component/ScrollingList.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -658,17 +658,17 @@ bool ScrollingList::allocateTexture( unsigned int index, Item *item )
658658
if ( layoutMode_ )
659659
{
660660
if ( commonMode_ )
661-
imagePath = Utils::combinePath(Configuration::absolutePath, "layouts", layoutName, "collections", "_common");
661+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "layouts", layoutName, "collections", "_common");
662662
else
663-
imagePath = Utils::combinePath( Configuration::absolutePath, "layouts", layoutName, "collections", collectionName );
663+
imagePath = Utils::combinePath( Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "layouts", layoutName, "collections", collectionName );
664664

665665
imagePath = Utils::combinePath( imagePath, "medium_artwork", imageType_ );
666666
}
667667
else
668668
{
669669
if ( commonMode_ )
670670
{
671-
imagePath = Utils::combinePath(Configuration::absolutePath, "collections", "_common" );
671+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "collections", "_common" );
672672
imagePath = Utils::combinePath( imagePath, "medium_artwork", imageType_ );
673673
}
674674
else
@@ -681,7 +681,7 @@ bool ScrollingList::allocateTexture( unsigned int index, Item *item )
681681
{
682682
if ( layoutMode_ )
683683
{
684-
imagePath = Utils::combinePath( Configuration::absolutePath, "layouts", layoutName, "collections", item->collectionInfo->name );
684+
imagePath = Utils::combinePath( Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "layouts", layoutName, "collections", item->collectionInfo->name );
685685
imagePath = Utils::combinePath( imagePath, "medium_artwork", imageType_ );
686686
}
687687
else
@@ -698,18 +698,18 @@ bool ScrollingList::allocateTexture( unsigned int index, Item *item )
698698
if ( layoutMode_ )
699699
{
700700
if ( commonMode_ ){
701-
imagePath = Utils::combinePath(Configuration::absolutePath, "layouts", layoutName, "collections", "_common");
701+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "layouts", layoutName, "collections", "_common");
702702
}
703703
else{
704-
imagePath = Utils::combinePath( Configuration::absolutePath, "layouts", layoutName, "collections", item->name );
704+
imagePath = Utils::combinePath( Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "layouts", layoutName, "collections", item->name );
705705
}
706706
imagePath = Utils::combinePath( imagePath, "system_artwork" );
707707
}
708708
else
709709
{
710710
if ( commonMode_ )
711711
{
712-
imagePath = Utils::combinePath(Configuration::absolutePath, "collections", "_common" );
712+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "collections", "_common" );
713713
imagePath = Utils::combinePath( imagePath, "system_artwork" );
714714
}
715715
else{
@@ -726,7 +726,7 @@ bool ScrollingList::allocateTexture( unsigned int index, Item *item )
726726

727727
// Image fallback
728728
if ( !t && imageType_.compare(std::string("null"))){
729-
imagePath = Utils::combinePath(Configuration::absolutePath, "collections", collectionName );
729+
imagePath = Utils::combinePath(Configuration::isUserLayout_?Configuration::userPath:Configuration::absolutePath, "collections", collectionName );
730730
imagePath = Utils::combinePath( imagePath, "system_artwork" );
731731
t = imageBuild.CreateImage( imagePath, page, std::string("fallback"), scaleX_, scaleY_, ditheringAuthorized_ );
732732
}

0 commit comments

Comments
 (0)