diff --git a/Core/Core.cc b/Core/Core.cc index c1316bb8c26f5db22739632f8b78bd2b36a247cf..35abeac0c6910ad4534515e806a5ef2b970257fd 100644 --- a/Core/Core.cc +++ b/Core/Core.cc @@ -528,7 +528,8 @@ Core::init() { scenegraphCheckTimer_->start (); } - QTimer::singleShot(100, this, SLOT(slotCommandLineOpen())); + + QTimer::singleShot(100, this, SLOT(slotExecuteAfterStartup())); } diff --git a/Core/Core.hh b/Core/Core.hh index 87d48c225a2ac4fc71b214e613e600c33d8519e1..1cb134ef6604c12f3efb2032aa10e451e16007d3 100644 --- a/Core/Core.hh +++ b/Core/Core.hh @@ -418,7 +418,7 @@ private: private slots: /// Executed after loading core completly - void slotCommandLineOpen(); + void slotExecuteAfterStartup(); private: std::vector< std::pair < const char* , bool > > commandLineFileNames_; diff --git a/Core/openFunctions.cc b/Core/openFunctions.cc index 3848e1e3461a4bf5e384469363ecb6ef0878a1c1..3c0d49256c17f8b9e12c274774d3c2a6a68acd38 100644 --- a/Core/openFunctions.cc +++ b/Core/openFunctions.cc @@ -85,7 +85,26 @@ void Core::commandLineScript(const char* _filename ) { commandLineScriptNames_.push_back(_filename); } -void Core::slotCommandLineOpen() { +void Core::slotExecuteAfterStartup() { + + //check if we have scripting support: + bool scriptingSupport = false; + slotPluginExists("scripting",scriptingSupport); + if ( ! scriptingSupport ) { + emit log(LOGERR ,"No scripting support available, please check if we load a scripting plugin .. Skipping script execution on startup"); + } + + // Collect all script files from the scripting subdirectory and execute them if possible + if ( scriptingSupport ) { + + QDir scriptDir = OpenFlipper::Options::scriptDir(); + QStringList scriptFiles = scriptDir.entryList(QDir::Files,QDir::Name); + + for ( int i = 0 ; i < scriptFiles.size(); ++i ) + emit executeFileScript(scriptDir.path() + QDir::separator() + scriptFiles[i]); + + } + for ( uint i = 0 ; i < commandLineFileNames_.size() ; ++i ) { if (commandLineFileNames_[i].second) loadObject(DATA_POLY_MESH, commandLineFileNames_[i].first); @@ -93,17 +112,9 @@ void Core::slotCommandLineOpen() { loadObject(commandLineFileNames_[i].first); } - for ( uint i = 0 ; i < commandLineScriptNames_.size() ; ++i ) { - //check if we have scripting support: - bool ok = false; - slotPluginExists("scripting",ok); - if ( ! ok ) { - emit log(LOGERR ,"No scripting support available, please check if we load a scripting plugin"); - return; - } - - emit executeFileScript(commandLineScriptNames_[i]); - } + if ( scriptingSupport ) + for ( uint i = 0 ; i < commandLineScriptNames_.size() ; ++i ) + emit executeFileScript(commandLineScriptNames_[i]); if ( !OpenFlipper::Options::gui() && !OpenFlipper::Options::remoteControl()) exitApplication(); diff --git a/Core/optionHandling.cc b/Core/optionHandling.cc index f0d6a13f6637782edbfae20f26bd3a69e6885c2f..ddc559ec7df487814b64a022ec3add5bd809d22e 100644 --- a/Core/optionHandling.cc +++ b/Core/optionHandling.cc @@ -221,6 +221,14 @@ void Core::setupOptions() { tempDir.cd("Textures"); OpenFlipper::Options::textureDir(tempDir.absolutePath()); + // Set the Path to the Scripts + tempDir = QDir(OpenFlipper::Options::applicationDir()); + #ifdef OPENFLIPPER_DATADIR + tempDir.cd(OPENFLIPPER_DATADIR); + #endif + tempDir.cd("Scripts"); + OpenFlipper::Options::scriptDir(tempDir.absolutePath()); + // Set the Path to the Icons tempDir = QDir(OpenFlipper::Options::applicationDir()); #ifdef OPENFLIPPER_DATADIR diff --git a/common/GlobalOptions.cc b/common/GlobalOptions.cc index 60aec89ce5a3452a602077547a5b7bcd3aafcaf6..83b3a0aae158a7cd4f0f94aee10bc538f75d3bf1 100644 --- a/common/GlobalOptions.cc +++ b/common/GlobalOptions.cc @@ -64,6 +64,9 @@ static QDir shaderDir_; /// Stores the Path to the Textures static QDir textureDir_; +/// Stores the Path to the Scripts +static QDir scriptDir_; + /// Stores the Path to the Icons static QDir iconDir_; @@ -278,6 +281,7 @@ QDir configDir() { return configDir_; } QDir pluginDir() { return pluginDir_; } QDir shaderDir() { return shaderDir_; } QDir textureDir() { return textureDir_; } +QDir scriptDir() { return scriptDir_; } QDir iconDir() { return iconDir_; } QDir fontsDir() { return fontsDir_; } QDir helpDir() { return helpDir_; } @@ -290,6 +294,7 @@ QString configDirStr() { return configDir_.absolutePath(); } QString pluginDirStr() { return pluginDir_.absolutePath(); } QString shaderDirStr() { return shaderDir_.absolutePath(); } QString textureDirStr() { return textureDir_.absolutePath(); } +QString scriptDirStr() { return scriptDir_.absolutePath(); } QString iconDirStr() { return iconDir_.absolutePath(); } QString fontsDirStr() { return fontsDir_.absolutePath(); } QString helpDirStr() { return helpDir_.absolutePath(); } @@ -303,9 +308,10 @@ void applicationDir(QDir _dir) { applicationDir_ = _dir; } void pluginDir(QDir _dir) { pluginDir_ = _dir; } void shaderDir(QDir _dir) { shaderDir_ = _dir; } void textureDir(QDir _dir) { textureDir_ = _dir; } +void scriptDir(QDir _dir) { scriptDir_ = _dir; } void iconDir(QDir _dir) { iconDir_ = _dir; } void fontsDir(QDir _dir) { fontsDir_ = _dir;} -void helpDir(QDir _dir) { helpDir_ = _dir;} +void helpDir(QDir _dir) { helpDir_ = _dir;} void configDir(QDir _dir) { configDir_ = _dir; } void currentDir(QDir _dir) { currentDir_ = _dir; } void currentScriptDir(QDir _dir) { currentScriptDir_ = _dir; } @@ -349,6 +355,15 @@ bool textureDir(QString _dir) { return false; } +bool scriptDir(QString _dir) { + QDir tmp(_dir); + if (tmp.exists()) { + scriptDir_ = tmp; + return true; + } + return false; +} + bool iconDir(QString _dir) { QDir tmp(_dir); if (tmp.exists()) { diff --git a/common/GlobalOptions.hh b/common/GlobalOptions.hh index 366fa4d5db87a2e727ac35e374f99332120296bc..17175ec4d2cf908b6e2d729b2aacaa771c730dce 100644 --- a/common/GlobalOptions.hh +++ b/common/GlobalOptions.hh @@ -68,6 +68,10 @@ QDir pluginDir(); DLLEXPORT QDir textureDir(); +/// Returns the Path to the Scripts +DLLEXPORT +QDir scriptDir(); + /// Returns the Path to the shaders DLLEXPORT QDir shaderDir(); @@ -96,6 +100,10 @@ QString shaderDirStr(); DLLEXPORT QString textureDirStr(); +/// Returns the Path to the Scripts +DLLEXPORT +QString scriptDirStr(); + /// Returns the Path to the Icons DLLEXPORT QString iconDirStr(); @@ -128,6 +136,10 @@ void shaderDir(QDir _dir); DLLEXPORT void textureDir(QDir _dir); +/// Sets the Path to the Scripts +DLLEXPORT +void scriptDir( QDir _dir); + /// Sets the Path to the Icons DLLEXPORT void iconDir(QDir _dir); @@ -156,6 +168,10 @@ bool shaderDir(QString _dir); DLLEXPORT bool textureDir(QString _dir); +/// Sets the Path to the Scripts +DLLEXPORT +bool scriptDir(QString _dir); + /// Sets the Path to the Icons DLLEXPORT bool iconDir(QString _dir);