From 43b18c0fa2a689ae429e93036be2f8d7bf689b96 Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 27 Nov 2014 21:51:53 +0300 Subject: [PATCH] Issue #279 Give an ability for user to define the path to plugins --- src/Config/Config_Common.cpp | 5 ++++- src/Config/Config_Prop.h | 3 ++- src/Config/Config_XMLReader.cpp | 26 +++++++++++++++++++++----- src/XGUI/NewGeom.xml | 5 +++++ src/XGUI/XGUI_IPrefMgr.h | 7 ++++++- src/XGUI/XGUI_Preferences.cpp | 24 ++++++++++++++++++++---- src/XGUI/XGUI_Workshop.cpp | 10 +++++++++- 7 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/Config/Config_Common.cpp b/src/Config/Config_Common.cpp index b3a93acd1..a8c6df0a5 100644 --- a/src/Config/Config_Common.cpp +++ b/src/Config/Config_Common.cpp @@ -14,7 +14,8 @@ #include // for stringstream #include -#include // for std::transform +#include // for std::transform + bool isElementNode(xmlNodePtr theNode) { return theNode->type == XML_ELEMENT_NODE; @@ -95,6 +96,8 @@ bool getValidatorInfo(xmlNodePtr theNode, std::string& outValidatorId, std::string library(const std::string& theLibName) { + if(theLibName.empty()) + return std::string(); std::string aLibName = theLibName; #ifndef WIN32 static std::string aLibExt( ".so" ); diff --git a/src/Config/Config_Prop.h b/src/Config/Config_Prop.h index 4430bade8..496e8fd95 100644 --- a/src/Config/Config_Prop.h +++ b/src/Config/Config_Prop.h @@ -37,7 +37,8 @@ class Config_Prop Shortcut, ShortcutTree, BiColor, - Background + Background, + Directory }; /** diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 44c806ce9..818180e11 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -9,11 +9,15 @@ #include #include #include +#include #include +#include #include #include +#include + #ifdef WIN32 #pragma warning(disable : 4996) // for getenv #endif @@ -25,19 +29,31 @@ Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName) : myXmlDoc(NULL) { - std::string prefix = ""; + std::string prefix = ""; + Config_Prop* aProp = Config_PropManager::findProp("Plugins", "default_path"); + if (aProp) + prefix = aProp->value(); /* * Get path to *.xml files (typically ./bin/../plugins/) * the problem: application may be launched using python executable, * to use environment variable (at least for the current moment) */ - char* anEnv = getenv("NEW_GEOM_CONFIG_FILE"); - if (anEnv) { - prefix = std::string(anEnv) + "/"; + if (prefix.empty()) { + char* anEnv = getenv("NEW_GEOM_CONFIG_FILE"); + if (anEnv) { + prefix = std::string(anEnv); + } } - +#ifdef WIN32 + prefix += "\\"; +#else + prefix += "/"; +#endif myDocumentPath = prefix + theXmlFileName; + std::ifstream aTestFile(myDocumentPath); + if (!aTestFile) Events_Error::send("Unable to open " + myDocumentPath); + aTestFile.close(); } Config_XMLReader::~Config_XMLReader() diff --git a/src/XGUI/NewGeom.xml b/src/XGUI/NewGeom.xml index 1b1bd2a0b..af912ddf2 100644 --- a/src/XGUI/NewGeom.xml +++ b/src/XGUI/NewGeom.xml @@ -10,4 +10,9 @@ +
+ + +
+ diff --git a/src/XGUI/XGUI_IPrefMgr.h b/src/XGUI/XGUI_IPrefMgr.h index af0752d6f..9530a6cab 100644 --- a/src/XGUI/XGUI_IPrefMgr.h +++ b/src/XGUI/XGUI_IPrefMgr.h @@ -17,6 +17,7 @@ class XGUI_IPrefMgr { public: + /** * Add preference item into preference dialog box * \param theLbl - label of the item @@ -30,8 +31,12 @@ public: SUIT_PreferenceMgr::PrefItemType theType, const QString& theSection, const QString& theName ) = 0; + virtual void setItemProperty(const QString& thePropName, + const QVariant& theValue, + const int theId = -1) = 0; + /// Returns incapsulated preference manager virtual SUIT_PreferenceMgr* prefMgr() const = 0; }; -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_Preferences.cpp b/src/XGUI/XGUI_Preferences.cpp index 635462d89..0dc2e5f8e 100644 --- a/src/XGUI/XGUI_Preferences.cpp +++ b/src/XGUI/XGUI_Preferences.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -125,10 +126,20 @@ void XGUI_Preferences::createCustomPage(XGUI_IPrefMgr* thePref, int thePageId) isResModified = true; } // Add item - if (aProp->type() != Config_Prop::Disabled) - thePref->addPreference(QObject::tr(aProp->title().c_str()), aTab, - (SUIT_PreferenceMgr::PrefItemType) aProp->type(), - QString(aProp->section().c_str()), QString(aProp->name().c_str())); + if (aProp->type() != Config_Prop::Disabled) { + SUIT_PreferenceMgr::PrefItemType aPrefType = SUIT_PreferenceMgr::Auto; + if (aProp->type() == Config_Prop::Directory) { + aPrefType = SUIT_PreferenceMgr::File; + } else { + aPrefType = (SUIT_PreferenceMgr::PrefItemType) aProp->type(); + } + int anId = thePref->addPreference(QObject::tr(aProp->title().c_str()), aTab, aPrefType, + QString::fromStdString(aProp->section()), + QString::fromStdString(aProp->name())); + if(aProp->type() == Config_Prop::Directory) { + thePref->setItemProperty("path_type", Qtx::PT_Directory, anId); + } + } } } } @@ -148,6 +159,11 @@ public: return myMgr->addItem(theLbl, pId, theType, theSection, theName); } + virtual void setItemProperty( const QString& thePropName, const QVariant& theValue, + const int theId = -1) { + myMgr->setItemProperty(thePropName, theValue, theId); + } + virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; } private: diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 5a856925c..820acdb56 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -137,6 +138,10 @@ XGUI_Workshop::~XGUI_Workshop(void) void XGUI_Workshop::startApplication() { initMenu(); + + Config_PropManager::registerProp("Plugins", "default_path", "Default Path", + Config_Prop::Directory, ""); + //Initialize event listening Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors. @@ -153,12 +158,15 @@ void XGUI_Workshop::startApplication() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE)); registerValidators(); + // Calling of loadCustomProps before activating module is required + // by Config_PropManger to restore user-defined path to plugins + XGUI_Preferences::loadCustomProps(); activateModule(); if (myMainWindow) { myMainWindow->show(); updateCommandStatus(); } - XGUI_Preferences::loadCustomProps(); + onNew(); } -- 2.39.2