00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "total99resources.h"
00021 #include <cstdlib>
00022 #include <QApplication>
00023 #include <QFile>
00024 #include <QDir>
00025 #include <QFileInfo>
00026 #include <QPluginLoader>
00027 #include <QStringList>
00028 #include "configurationparameters.h"
00029 #include "factory.h"
00030 #include "farsaplugin.h"
00031 #include "icubsimulator.h"
00032 #include "icubsimulatorviewer.h"
00033 #include "evorobotviewer.h"
00034 #include "logger.h"
00035
00036
00037
00038 #if defined(_MSC_VER)
00039 #pragma warning(push)
00040 #pragma warning(disable:4996)
00041 #endif
00042
00043 using namespace farsa;
00044
00045 QString Total99Resources::findResource( QString resourceName ) {
00046
00047 if ( QFile::exists( confUserPath + "/" + resourceName ) ) {
00048 return ( confUserPath + "/" + resourceName );
00049 }
00050
00051 if ( QFile::exists( confUserPath + "/templates/" + uiTemplate + "/" + resourceName ) ) {
00052 return ( confUserPath + "/templates/" + uiTemplate + "/" + resourceName );
00053 }
00054
00055 if ( QFile::exists( confBasePath + "/" + resourceName ) ) {
00056 return ( confBasePath + "/" + resourceName );
00057 }
00058
00059 if ( QFile::exists( confBasePath + "/templates/" + uiTemplate + "/" + resourceName ) ) {
00060 return ( confBasePath + "/templates/" + uiTemplate + "/" + resourceName );
00061 }
00062
00063 return QString();
00064 }
00065
00066 QString Total99Resources::confBasePath;
00067 QString Total99Resources::confUserPath;
00068 QString Total99Resources::pluginBasePath;
00069 QString Total99Resources::pluginUserPath;
00070 QString Total99Resources::uiTemplate;
00071
00072 bool Total99Resources::loadPlugin( QString filename ) {
00073 QPluginLoader loader( filename );
00074 FarsaPlugin* plugin = qobject_cast<FarsaPlugin*>( loader.instance() );
00075 if ( !plugin ) {
00076
00077 return false;
00078 }
00079
00080 plugin->registerTypesOnFactory();
00081 return true;
00082 }
00083
00084 void Total99Resources::loadPlugins( QDir dir ) {
00085 foreach( QString pluginfile, dir.entryList() ) {
00086 if ( ! QLibrary::isLibrary( pluginfile ) ) continue;
00087 if ( loadPlugin( dir.absoluteFilePath(pluginfile) ) ) {
00088 Logger::info( "Loaded Plugin \"" + pluginfile + "\"");
00089 }
00090 }
00091 }
00092
00093 void Total99Resources::loadPlugins( const farsa::ConfigurationParameters& params ) {
00094 QStringList pluginPaths = params.getParametersWithPrefixList( "TOTAL99", "pluginPath" );
00095 foreach( QString path, pluginPaths ) {
00096 QString value = params.getValue( "TOTAL99/"+path );
00097 if ( ! QFileInfo( value ).isDir() ) {
00098 Logger::warning( "Ignoring un-existing plugin path \"" + value + "\"" );
00099 continue;
00100 }
00101 loadPlugins( QDir( value ) );
00102 }
00103 }
00104
00105 void Total99Resources::initialize() {
00106 #ifdef FARSA_WIN
00107 confBasePath = qApp->applicationDirPath() + "/../conf";
00108 pluginBasePath = qApp->applicationDirPath() + "/../plugins";
00109 #else
00110 confBasePath = qApp->applicationDirPath() + "/../share/FARSA/conf";
00111 pluginBasePath = qApp->applicationDirPath() + "/../share/FARSA/plugins";
00112 #endif
00113 #ifdef FARSA_LINUX
00114 confUserPath = QString(getenv("HOME")) + "/.FARSA/total99";
00115 pluginUserPath = QString(getenv("HOME")) + "/.FARSA/total99/plugins";
00116 #endif
00117 #ifdef FARSA_MAC
00118 confUserPath = QString(getenv("HOME")) + "/Library/Application Support/FARSA/Total99";
00119 pluginUserPath = QString(getenv("HOME")) + "/Library/Application Support/FARSA/Total99/plugins";
00120 #endif
00121 #ifdef FARSA_WIN
00122 confUserPath = QString(getenv("APPDATA")) + "/FARSA/Total99";
00123 pluginUserPath = QString(getenv("APPDATA")) + "/FARSA/Total99/plugins";
00124 #endif
00125
00126 QDir dir;
00127 dir.mkpath( confUserPath );
00128 dir.mkpath( pluginUserPath );
00129
00130
00131 loadPlugins( QDir( pluginBasePath ) );
00132 loadPlugins( QDir( pluginUserPath ) );
00133
00134 uiTemplate = "kids";
00135 Logger::info( "Total99 Resources Initialized" );
00136 }
00137
00138
00139 #if defined(_MSC_VER)
00140 #pragma warning(pop)
00141 #endif
00142