1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
29
#include "../common/WException.h"
30
#include "../common/WLogger.h"
31
#include "../common/WStructuredTextParser.h"
34
#include "WModuleMetaInformation.h"
36
WModuleMetaInformation::WModuleMetaInformation( std::string name ):
43
WModuleMetaInformation::WModuleMetaInformation( boost::shared_ptr< WModule > module ):
44
m_name( module->getName() ),
45
m_description( module->getDescription() ),
47
m_localPath( module->getLocalPath() )
49
// check whether file exists
50
boost::filesystem::path metafile = module->getLocalPath() / "META";
51
if( !boost::filesystem::exists( metafile ) )
59
m_metaData = WStructuredTextParser::StructuredValueTree( metafile );
60
// is there a module definition?
61
// If there is no meta info for this module, assume we could not load a meta file
62
m_loaded = m_metaData.exists( m_name );
65
wlog::error( "Module (" + m_name + ")" ) << "Meta file loaded but no entry for module \"" << m_name << "\" found. Ignoring.";
68
catch( const WException& e )
70
wlog::error( "Module (" + m_name + ")" ) << "Meta file load failed. Message: " << e.what();
74
WModuleMetaInformation::~WModuleMetaInformation()
79
std::string WModuleMetaInformation::getName() const
84
boost::filesystem::path WModuleMetaInformation::getIcon() const
86
// return a default if not meta data was loaded
89
return boost::filesystem::path();
92
// find key-value pair
93
return m_localPath / m_metaData.getValue< boost::filesystem::path >( m_name + "/icon", boost::filesystem::path( "icon.png" ) );
96
bool WModuleMetaInformation::isIconAvailable() const
100
return m_metaData.exists( m_name + "/icon", true );
108
std::string WModuleMetaInformation::getWebsite() const
110
// return a default if not meta data was loaded
116
// find key-value pair
117
return m_metaData.getValue< std::string >( m_name + "/website", "" );
120
std::string WModuleMetaInformation::getDescription() const
122
// return a default if not meta data was loaded
125
return m_description;
128
// find key-value pair
129
return m_metaData.getValue< std::string >( m_name + "/description", m_description );
132
boost::filesystem::path WModuleMetaInformation::getHelp() const
134
// return a default if not meta data was loaded
137
return boost::filesystem::path();
140
// find key-value pair
141
return m_localPath / m_metaData.getValue< boost::filesystem::path >( m_name + "/help", boost::filesystem::path( "help.html" ) );
144
std::vector< WModuleMetaInformation::Author > WModuleMetaInformation::getAuthors() const
146
std::vector< WModuleMetaInformation::Author > r;
148
// did we find some author info? If not, add a nice default OpenWalnut author
149
WModuleMetaInformation::Author ow = { "OpenWalnut Project", "http://www.openwalnut.org", "", "Design, Development, and Bug Fixing" };
151
// return a default if not meta data was loaded
158
// how much author information is available?
159
std::vector< std::string > authors = m_metaData.getValues< std::string >( m_name + "/author" );
161
if( authors.empty() )
167
// for each author, get some associated data if available
168
// prepare some memory
169
r.resize( authors.size() );
170
for( std::vector< std::string >::const_iterator i = authors.begin(); i != authors.end(); ++i )
172
r[ i - authors.begin() ].m_name = *i;
173
r[ i - authors.begin() ].m_email = m_metaData.getValue< std::string >( m_name + "/" + *i + "/email", "" );
174
r[ i - authors.begin() ].m_what = m_metaData.getValue< std::string >( m_name + "/" + *i + "/what", "" );
175
r[ i - authors.begin() ].m_url = m_metaData.getValue< std::string >( m_name + "/" + *i + "/url", "" );
181
std::vector< WModuleMetaInformation::Online > WModuleMetaInformation::getOnlineResources() const
183
std::vector< WModuleMetaInformation::Online > r;
184
// return a default if not meta data was loaded
190
// get the "online"-subtrees
191
typedef std::vector< WStructuredTextParser::StructuredValueTree > TreeList;
192
TreeList onlineInfos = m_metaData.getSubTrees( m_name + "/online" );
193
for( TreeList::const_iterator i = onlineInfos.begin(); i != onlineInfos.end(); ++i )
195
WModuleMetaInformation::Online o;
199
// these are required
200
o.m_name = ( *i ).getValue< std::string >( "name", "" );
201
o.m_url = ( *i ).getValue< std::string >( "url", "" );
202
if( o.m_name.empty() || o.m_url.empty() )
208
o.m_description = ( *i ).getValue< std::string >( "description", "" );
217
std::vector< std::string > WModuleMetaInformation::getTags() const
219
// return a default if not meta data was loaded
222
return std::vector< std::string >();
225
// find key-value pair
226
return m_metaData.getValues< std::string >( m_name + "/tag" );
229
std::vector< WModuleMetaInformation::Screenshot > WModuleMetaInformation::getScreenshots() const
231
std::vector< WModuleMetaInformation::Screenshot > r;
232
// return a default if not meta data was loaded
238
// get the "screenshot"-subtrees
239
typedef std::vector< WStructuredTextParser::StructuredValueTree > TreeList;
240
TreeList screenshotInfos = m_metaData.getSubTrees( m_name + "/screenshot" );
241
for( TreeList::const_iterator i = screenshotInfos.begin(); i != screenshotInfos.end(); ++i )
243
WModuleMetaInformation::Screenshot s;
247
// these are required
248
s.m_filename = ( *i ).getValue< boost::filesystem::path >( "filename", "" );
249
if( s.m_filename.empty() )
255
s.m_description = ( *i ).getValue< std::string >( "description", "" );