Commit dde5cf97 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE #9] - WModuleMetaInformation now loads and returns several...

[CHANGE #9] - WModuleMetaInformation now loads and returns several information. Still missing is online doc support.
parent 622fac70
......@@ -22,6 +22,7 @@
//
//---------------------------------------------------------------------------
#include <algorithm>
#include <string>
#include "../common/WException.h"
......@@ -40,7 +41,9 @@ WModuleMetaInformation::WModuleMetaInformation( std::string name ):
WModuleMetaInformation::WModuleMetaInformation( boost::shared_ptr< WModule > module ):
m_name( module->getName() ),
m_loaded( false )
m_description( module->getDescription() ),
m_loaded( false ),
m_localPath( module->getLocalPath() )
{
// check whether file exists
boost::filesystem::path metafile = module->getLocalPath() / "META";
......@@ -53,7 +56,13 @@ WModuleMetaInformation::WModuleMetaInformation( boost::shared_ptr< WModule > mod
try
{
m_metaData = WStructuredTextParser::StructuredValueTree( metafile );
m_loaded = true;
// is there a module definition?
// If there is no meta info for this module, assume we could not load a meta file
m_loaded = m_metaData.exists( m_name );
if( !m_loaded )
{
wlog::error( "Module (" + m_name + ")" ) << "Meta file loaded but no entry for module \"" << m_name << "\" found. Ignoring.";
}
}
catch( const WException& e )
{
......@@ -66,3 +75,102 @@ WModuleMetaInformation::~WModuleMetaInformation()
// cleanup
}
std::string WModuleMetaInformation::getName() const
{
return m_name;
}
boost::filesystem::path WModuleMetaInformation::getIcon() const
{
// return a default if not meta data was loaded
if( !m_loaded )
{
return boost::filesystem::path();
}
// find key-value pair
return m_localPath / m_metaData.getValue< boost::filesystem::path >( m_name + "/icon", boost::filesystem::path( "icon.png" ) );
}
std::string WModuleMetaInformation::getWebsite() const
{
// return a default if not meta data was loaded
if( !m_loaded )
{
return "";
}
// find key-value pair
return m_metaData.getValue< std::string >( m_name + "/website", "" );
}
std::string WModuleMetaInformation::getDescription() const
{
// return a default if not meta data was loaded
if( !m_loaded )
{
return m_description;
}
// find key-value pair
return m_metaData.getValue< std::string >( m_name + "/description", m_description );
}
boost::filesystem::path WModuleMetaInformation::getHelp() const
{
// return a default if not meta data was loaded
if( !m_loaded )
{
return boost::filesystem::path();
}
// find key-value pair
return m_localPath / m_metaData.getValue< boost::filesystem::path >( m_name + "/help", boost::filesystem::path( "help.html" ) );
}
std::vector< WModuleMetaInformation::Author > WModuleMetaInformation::getAuthors() const
{
std::vector< WModuleMetaInformation::Author > r;
// return a default if not meta data was loaded
if( !m_loaded )
{
return r;
}
// how much author information is available?
std::vector< std::string > authors = m_metaData.getValues< std::string >( m_name + "/author" );
// prepare some memory
r.resize( authors.size() );
// for each author, get some associated data if available
for( std::vector< std::string >::const_iterator i = authors.begin(); i != authors.end(); ++i )
{
r[ i - authors.begin() ].m_email = m_metaData.getValue< std::string >( m_name + "/" + *i + "/email", "" );
r[ i - authors.begin() ].m_what = m_metaData.getValue< std::string >( m_name + "/" + *i + "/what", "" );
r[ i - authors.begin() ].m_url = m_metaData.getValue< std::string >( m_name + "/" + *i + "/url", "" );
}
// did we find some author info? If not, add a nice default OpenWalnut author
if( !r.size() )
{
WModuleMetaInformation::Author ow = { "OpenWalnut Project", "", "http://www.openwalnut.org", "Design, Development and Bug fixing" };
r.push_back( ow );
}
return r;
}
std::vector< WModuleMetaInformation::Online > WModuleMetaInformation::getOnlineResources() const
{
std::vector< WModuleMetaInformation::Online > r;
// return a default if not meta data was loaded
if( !m_loaded )
{
return r;
}
// TODO(ebaum): implement me
return r;
}
......@@ -52,6 +52,56 @@ public:
*/
typedef boost::shared_ptr< const WModuleMetaInformation > ConstSPtr;
///////////////////////////////////////////////////////////////////////////////////////////////
// these are some structs to simply handling of the meta file structures
/**
* Structure to contain all supported author information
*/
struct Author
{
/**
* Author name. Will never be empty.
*/
std::string m_name;
/**
* URL to a website of the author. Can be empty.
*/
std::string m_url;
/**
* E-Mail contact to the author. Can be empty.
*/
std::string m_email;
/**
* What has this author done on the module? Can be empty.
*/
std::string m_what;
};
/**
* Structure to encapsulate the META info online resources.
*/
struct Online
{
/**
* Online resource's name.
*/
std::string m_name;
/**
* Online resource's description.
*/
std::string m_description;
/**
* The url to the resource.
*/
std::string m_url;
};
/**
* Constructor. The help object will be empty, meaning there is no further meta info available. The name is the only required value. Of
* course, this is of limited use in most cases.
......@@ -72,6 +122,56 @@ public:
* Destructor. Cleans internal list.
*/
virtual ~WModuleMetaInformation();
/**
* The name of the module. Will always return the name of the module given on construction.
*
* \return the name
*/
std::string getName() const;
/**
* Get the icon path. Can be invalid. Check for existence before opening.
*
* \return the path to the icon file
*/
boost::filesystem::path getIcon() const;
/**
* The URL to a module website. Can be empty.
*
* \return URL to website
*/
std::string getWebsite() const;
/**
* A module description. Can be empty but is initialized with the description of the module given on construction.
*
* \return the description.
*/
std::string getDescription() const;
/**
* Path to a text or HTML file containing some module help. Can be invalid. Check for existence before opening.
*
* \return the path to help
*/
boost::filesystem::path getHelp() const;
/**
* A list of authors. If the META file did not contain any author information, this returns the OpenWalnut Team as author.
*
* \return Author list.
*/
std::vector< Author > getAuthors() const;
/**
* A list of online resources. Can be empty.
*
* \return list of online material
*/
std::vector< Online > getOnlineResources() const;
protected:
private:
/**
......@@ -79,6 +179,12 @@ private:
*/
std::string m_name;
/**
* The default description if none was specified in the META file. Initialized with the description of the module specified during
* construction.
*/
std::string m_description;
/**
* The tree representing the data
*/
......@@ -89,6 +195,11 @@ private:
* could not be found.
*/
bool m_loaded;
/**
* The module local path. Used for several meta infos returning a path.
*/
boost::filesystem::path m_localPath;
};
#endif // WMODULEMETAINFORMATION_H
......
......@@ -27,57 +27,66 @@
// NOTE: everything but the module name is optional, even if this makes no
// sense at all.
module
// This defines some properties of the module "Navigation Slices". This must
// match the name specified in WMNavigationSlices::getName().
"Navigation Slices"
{
// The name of the module. This must be the same as the one in your getName()
// method!
name = "Navigation Slices";
// Provide an icon
// Provide an icon. If the icon exists, it overrides the one provided by your
// getIcon method. This path is relative to your module's resource directory.
icon="navslices.png";
// Where to find the module?
website = "http://www.openwalnut.org";
// Provide a description, If you do so, this description overrides the one
// provided by your getDescription method.
// HINT: multi-line strings are not supported. Please provide long texts in
// one line.
description = "This module shows all loaded datesets sliced using three, orthogonally oriented slices. It allows navigation through datasets to get a first impression of them. It supports all properties a data colormap allows and respects them during rendering.";
// Help file. This should be an HTML or TXT document
help ="help/index.html";
// Provide a list of authors. These authors can have further information associated with them.
author = "OpenWalnut Project";
author = "Students";
// Provide author information. Especially a contact address is very handy.
author
// This associates some URL and Mail contact info to "OpenWalnut Project".
"OpenWalnut Project"
{
name = "OpenWalnut Project";
url="http://www.openwalnut.org";
email="contact@openwalnut.org";
what="Design, Development and Bug fixing";
};
// Multiple authors allowed. The order of appearance is the same as in the
// GUI.
author
// These additional author information are optional.
Students
{
name = "Students";
what="Bug fixing";
};
// Provide a description, If you do so, this description overrides the one
// provided by your getDescription method.
// HINT: multi-line strings are not supported. Please provide long texts in
// one line.
description = "This module shows all loaded datesets sliced using three, orthogonally oriented slices. It allows navigation through datasets to get a first impression of them. It supports all properties a data colormap allows and respects them during rendering.";
// Help file. This should be an HTML or TXT document
help ="help/index.html";
// You can provide online resources. They are shown in the GUI. You should
// additionally provide a description to help the user know what this is.
online
{
// Name that appears for this resource. Required.
name="First Steps";
// Optional description for a resource
description ="First Steps Tutorial, showing the first steps to take with OpenWalnut.";
// The URL. Required.
url="http://www.openwalnut.org/projects/openwalnut/wiki/FirstSteps";
};
// Multiple online resources allowed.
online
{
name="Visualization Article";
description="Description of the term visualization.";
url="http://en.wikipedia.org/wiki/Visualization_(computer_graphics)";
};
online
{
name="Video Demonstration";
description="Video demonstration showing basic working principoles.";
url="http://www.youtube.com/watch?v=5Afw6P6wWSU&context=C375513dADOEgsToPDskJXOVbrVDAV5rydr7H173AT";
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment