diff --git a/RetroFE/Source/Collection/Item.cpp b/RetroFE/Source/Collection/Item.cpp index 7f74e79..595e911 100644 --- a/RetroFE/Source/Collection/Item.cpp +++ b/RetroFE/Source/Collection/Item.cpp @@ -15,7 +15,9 @@ */ #include "Item.h" +#include "../Utility/Log.h" #include "../Utility/Utils.h" +#include #include #include @@ -50,3 +52,63 @@ std::string Item::lowercaseFullTitle() return lcstr; } + +void Item::setInfo( std::string key, std::string value ) +{ + info_.insert( InfoPair( key, value ) ); +} + + +bool Item::getInfo( std::string key, std::string & value ) +{ + + bool retVal = false; + + if ( info_.find( key ) != info_.end( ) ) + { + value = info_[key]; + retVal = true; + } + + return retVal; + +} + + +void Item::loadInfo( std::string path ) +{ + + int lineCount = 0; + std::string line; + std::ifstream ifs( path.c_str( ) ); + size_t position; + std::string key; + std::string value; + + if ( !ifs.is_open( ) ) + { + return; + } + + while ( std::getline( ifs, line ) ) + { + lineCount++; + line = Utils::filterComments( line ); + // Check if the line has an assigment operator + if ( (position = line.find( "=" )) != std::string::npos ) + { + key = line.substr( 0, position ); + key = Utils::trimEnds( key ); + value = line.substr( position + 1, line.size( )-1 ); + value = Utils::trimEnds( value ); + setInfo( key, value ); + } + else + { + std::stringstream ss; + ss << "Missing an assignment operator (=) on line " << lineCount; + Logger::write(Logger::ZONE_ERROR, "Item", ss.str()); + } + } + +} diff --git a/RetroFE/Source/Collection/Item.h b/RetroFE/Source/Collection/Item.h index fab12fe..b6b32cb 100644 --- a/RetroFE/Source/Collection/Item.h +++ b/RetroFE/Source/Collection/Item.h @@ -16,6 +16,7 @@ #pragma once #include +#include #include "CollectionInfo.h" class Item @@ -43,4 +44,11 @@ public: std::string score; CollectionInfo *collectionInfo; bool leaf; + + typedef std::map InfoType; + typedef std::pair InfoPair; + InfoType info_; + void setInfo( std::string key, std::string value ); + bool getInfo( std::string key, std::string &value ); + void loadInfo( std::string path ); }; diff --git a/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp b/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp index 1c8cbd8..eb1cb67 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp +++ b/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp @@ -236,10 +236,7 @@ void ReloadableMedia::reloadTexture() } else if(typeLC == "manufacturer") { - if ( selectedItem->leaf ) // item is a leaf - basename = selectedItem->manufacturer; - else // item is a collection - (void)config_.getProperty("collections." + selectedItem->name + ".manufacturer", basename ); + basename = selectedItem->manufacturer; } else if(typeLC == "genre") { @@ -270,6 +267,23 @@ void ReloadableMedia::reloadTexture() basename = selectedItem->fullTitle.at(0); } + if (!selectedItem->leaf) // item is not a leaf + { + (void)config_.getProperty("collections." + selectedItem->name + "." + type_, basename ); + } + + bool overwriteXML = false; + config_.getProperty( "overwriteXML", overwriteXML ); + if ( basename == "" || overwriteXML ) // No basename was found yet; check the info in stead + { + std::string basename_tmp; + selectedItem->getInfo( type_, basename_tmp ); + if ( basename_tmp != "" ) + { + basename = basename_tmp; + } + } + Utils::replaceSlashesWithUnderscores(basename); if(systemMode_) diff --git a/RetroFE/Source/Graphics/Component/ReloadableText.cpp b/RetroFE/Source/Graphics/Component/ReloadableText.cpp index 2ae6321..7573ce2 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableText.cpp +++ b/RetroFE/Source/Graphics/Component/ReloadableText.cpp @@ -149,10 +149,7 @@ void ReloadableText::ReloadTexture() } else if (type_ == "year") { - if (selectedItem->leaf) // item is a leaf text = selectedItem->year; - else // item is a collection - (void)config_.getProperty("collections." + selectedItem->name + ".year", text ); } else if (type_ == "title") { @@ -169,17 +166,11 @@ void ReloadableText::ReloadTexture() } else if (type_ == "manufacturer") { - if (selectedItem->leaf) // item is a leaf - text = selectedItem->manufacturer; - else // item is a collection - (void)config_.getProperty("collections." + selectedItem->name + ".manufacturer", text ); + text = selectedItem->manufacturer; } else if (type_ == "genre") { - if (selectedItem->leaf) // item is a leaf - text = selectedItem->genre; - else // item is a collection - (void)config_.getProperty("collections." + selectedItem->name + ".genre", text ); + text = selectedItem->genre; } else if (type_ == "playlist") { @@ -238,11 +229,24 @@ void ReloadableText::ReloadTexture() ss << pluralPrefix_ << (page.getSelectedIndex()+1) << "/" << page.getCollectionSize() << pluralPostfix_; } } - else if (!selectedItem->leaf) // item is not a leaf + + if (!selectedItem->leaf) // item is not a leaf { (void)config_.getProperty("collections." + selectedItem->name + "." + type_, text ); } + bool overwriteXML = false; + config_.getProperty( "overwriteXML", overwriteXML ); + if ( text == "" || overwriteXML ) // No text was found yet; check the info in stead + { + std::string text_tmp; + selectedItem->getInfo( type_, text_tmp ); + if ( text_tmp != "" ) + { + text = text_tmp; + } + } + if (text == "0") { text = singlePrefix_ + text + pluralPostfix_; diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 1aca5de..628cbd1 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -168,7 +168,7 @@ void ScrollingList::allocateSpritePoints( ) resetTweens( c, tweenPoints_->at( i ), view, view, 0 ); - if ( old ) + if ( old && !newItemSelected ) { c->baseViewInfo = old->baseViewInfo; delete old; diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 1753219..2884c8c 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -1090,6 +1090,13 @@ CollectionInfo *RetroFE::getCollection(std::string collectionName) cib.addPlaylists( collection ); collection->sortFavoriteItems( ); + // Add extra info, if available + for ( std::vector::iterator it = collection->items.begin( ); it != collection->items.end( ); it++ ) + { + std::string path = Utils::combinePath( Configuration::absolutePath, "collections", collectionName, "info", (*it)->name + ".conf" ); + (*it)->loadInfo( path ); + } + // Remove parenthesis and brackets, if so configured bool showParenthesis = true; bool showSquareBrackets = true; diff --git a/RetroFE/Source/Utility/Utils.cpp b/RetroFE/Source/Utility/Utils.cpp index ab3b6c6..3049966 100644 --- a/RetroFE/Source/Utility/Utils.cpp +++ b/RetroFE/Source/Utility/Utils.cpp @@ -237,3 +237,19 @@ std::string Utils::getFileName(std::string filePath) return filename; } + +std::string Utils::trimEnds(std::string str) +{ + // strip off any initial tabs or spaces + size_t trimStart = str.find_first_not_of(" \t"); + + if(trimStart != std::string::npos) + { + size_t trimEnd = str.find_last_not_of(" \t"); + + str = str.substr(trimStart, trimEnd - trimStart + 1); + } + + return str; +} + diff --git a/RetroFE/Source/Utility/Utils.h b/RetroFE/Source/Utility/Utils.h index 2e0abcc..a66e8f3 100644 --- a/RetroFE/Source/Utility/Utils.h +++ b/RetroFE/Source/Utility/Utils.h @@ -34,6 +34,7 @@ public: static std::string toLower(std::string str); static std::string uppercaseFirst(std::string str); static std::string filterComments(std::string line); + static std::string trimEnds(std::string str); //todo: there has to be a better way to do this static std::string combinePath(std::list &paths); diff --git a/RetroFE/Source/Version.cpp b/RetroFE/Source/Version.cpp index 0358094..7f9374e 100644 --- a/RetroFE/Source/Version.cpp +++ b/RetroFE/Source/Version.cpp @@ -21,7 +21,7 @@ std::string retrofe_version_major = "0"; std::string retrofe_version_minor = "8"; -std::string retrofe_version_build = "10"; +std::string retrofe_version_build = "11"; std::string Version::getString( )