]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #279 Give an ability for user to define the path to plugins
authorsbh <sergey.belash@opencascade.com>
Thu, 27 Nov 2014 18:51:53 +0000 (21:51 +0300)
committersbh <sergey.belash@opencascade.com>
Thu, 27 Nov 2014 18:51:53 +0000 (21:51 +0300)
src/Config/Config_Common.cpp
src/Config/Config_Prop.h
src/Config/Config_XMLReader.cpp
src/XGUI/NewGeom.xml
src/XGUI/XGUI_IPrefMgr.h
src/XGUI/XGUI_Preferences.cpp
src/XGUI/XGUI_Workshop.cpp

index b3a93acd1963a5fd52eaf6a78e9294803172cd55..a8c6df0a55ceafc3d9983aaa00f667cd963d68fb 100644 (file)
@@ -14,7 +14,8 @@
 #include <sstream> // for stringstream\r
 \r
 #include <string>\r
-#include <algorithm> // for std::transform\r\r
+#include <algorithm> // for std::transform\r
+\r
 bool isElementNode(xmlNodePtr theNode)\r
 {\r
   return theNode->type == XML_ELEMENT_NODE;\r
@@ -95,6 +96,8 @@ bool getValidatorInfo(xmlNodePtr theNode, std::string& outValidatorId,
 \r
 std::string library(const std::string& theLibName)\r
 {\r
+  if(theLibName.empty())\r
+    return std::string();\r
   std::string aLibName = theLibName;\r
 #ifndef WIN32\r
   static std::string aLibExt( ".so" );\r
index 4430bade8b68c4c6f655c2201a37c23f640e57b0..496e8fd95ab655ccc10ecfeeb936335e5a128f1c 100644 (file)
@@ -37,7 +37,8 @@ class Config_Prop
     Shortcut,
     ShortcutTree,
     BiColor,
-    Background
+    Background,
+    Directory
   };
 
   /** 
index 44c806ce919faebbb6e70e7121e6ee6eecf0cd4c..818180e1129bc0705176edb88dd9ed98bdf17b4c 100644 (file)
@@ -9,11 +9,15 @@
 #include <Config_Keywords.h>
 #include <Config_Common.h>
 #include <Config_ValidatorMessage.h>
+#include <Config_PropManager.h>
 
 #include <Events_Loop.h>
+#include <Events_Error.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
+#include <fstream>
+
 #ifdef WIN32
 #pragma warning(disable : 4996) // for getenv
 #endif
 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()
index 1b1bd2a0bbc129665136b8ad95e8ba64b494bc1c..af912ddf29af4d43a3329736d7c346f6dbe31f1c 100644 (file)
@@ -10,4 +10,9 @@
     <parameter name="item_size" value="25" />
     <parameter name="rows_number" value="3" />
   </section>
+  <section name="Plugins" >
+    <!-- Plugins preferences -->
+    <parameter name="default_path" value="" />
+  </section>
+
 </document>
index af0752d6f36d438409f18ee9af8a0408ac7206cd..9530a6caba8dfed0801cbf901b93586c72159e97 100644 (file)
@@ -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
index 635462d89a999eb020f7fbb3ea476dd5e7348606..0dc2e5f8e6d5ffdfbea5a24145f5b117de53e8a0 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_PreferenceMgr.h>
+#include <Qtx.h>
 
 #include <QLayout>
 #include <QApplication>
@@ -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:
index 5a856925ccd2f0f173e9bfea3fcc753c269806ec..820acdb563f6eacdc396aaef7c831418537dee66 100644 (file)
@@ -51,6 +51,7 @@
 #include <Config_FeatureMessage.h>
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
+#include <Config_PropManager.h>
 
 #include <QApplication>
 #include <QFileDialog>
@@ -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();
 }