]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 28 Jun 2016 16:42:40 +0000 (11:42 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 28 Jun 2016 16:42:40 +0000 (11:42 -0500)
18 files changed:
appli/PipelineEditor/PipelineEditorMainWindow.cxx
appli/PipelineEditor/PipelineEditorMainWindow.h
appli/PipelineEditor/PipelineEditorMainWindow.ui
appli/examples/plugins/example_plugins_GuessPlugins.cxx
appli/examples/plugins/example_plugins_LoadDirectory.cxx
appli/examples/plugins/example_plugins_LoadFile.cxx
appli/examples/plugins/example_plugins_LoadPlugin.cxx
appli/examples/plugins/example_plugins_ReadImage.cxx
lib/cpBaseQtApplication/MainWindow.cxx
lib/cpBaseQtApplication/MainWindow.h
lib/cpBaseQtApplication/PathsDialog.cxx [new file with mode: 0644]
lib/cpBaseQtApplication/PathsDialog.h [new file with mode: 0644]
lib/cpBaseQtApplication/PathsDialog.ui [new file with mode: 0644]
lib/cpPlugins/DLLManager.cxx [moved from lib/cpPlugins/LoadDynamicLibrariesFunctions.cxx with 96% similarity]
lib/cpPlugins/DLLManager.h [moved from lib/cpPlugins/LoadDynamicLibrariesFunctions.h with 66% similarity]
lib/cpPlugins/Interface.cxx
lib/cpPlugins/Interface.h
lib/cpPlugins/Utilities.h

index 20ddc16524a5f854050454bc1cbd69b76bca7d79..5057790fe059d97730a76deeeedaedbf761a40f1 100644 (file)
@@ -26,12 +26,31 @@ PipelineEditorMainWindow(
     );
 
   // Slots <-> signals
-  _QT_CONNECT_ACTION( Open );
-  _QT_CONNECT_ACTION( Save );
-  _QT_CONNECT_ACTION( Close );
-  _QT_CONNECT_ACTION( LoadPluginFile );
-  _QT_CONNECT_ACTION( LoadPluginDirectory );
-  _QT_CONNECT_ACTION( ShowPlugins );
+  this->connect(
+    this->m_UI->ActionOpen, SIGNAL( triggered( ) ),
+    this, SLOT( _InteractiveLoadWorkspace( ) )
+    );
+  this->connect(
+    this->m_UI->ActionSave, SIGNAL( triggered( ) ),
+    this, SLOT( _InteractiveSaveWorkspace( ) )
+    );
+  // TODO: _QT_CONNECT_ACTION( Close );
+  this->connect(
+    this->m_UI->ActionLoadPluginFile, SIGNAL( triggered( ) ),
+    this, SLOT( _InteractiveLoadPlugins( ) )
+    );
+  this->connect(
+    this->m_UI->ActionLoadPluginDirectory, SIGNAL( triggered( ) ),
+    this, SLOT( _InteractiveLoadPluginsFromPath( ) )
+    );
+  this->connect(
+    this->m_UI->ActionShowPlugins, SIGNAL( triggered( ) ),
+    this, SLOT( _ShowPlugins( ) )
+    );
+  this->connect(
+    this->m_UI->ActionAddEnvironmentPath, SIGNAL( triggered( ) ),
+    this, SLOT( _InteractiveAddEnviromentPaths( ) )
+    );
 }
 
 // -------------------------------------------------------------------------
@@ -41,45 +60,4 @@ PipelineEditorMainWindow::
   delete this->m_UI;
 }
 
-// -------------------------------------------------------------------------
-void PipelineEditorMainWindow::
-_ActionOpen( )
-{
-  this->_InteractiveLoadWorkspace( );
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditorMainWindow::
-_ActionSave( )
-{
-  this->_InteractiveSaveWorkspace( );
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditorMainWindow::
-_ActionClose( )
-{
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditorMainWindow::
-_ActionLoadPluginFile( )
-{
-  this->_InteractiveLoadPlugins( );
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditorMainWindow::
-_ActionLoadPluginDirectory( )
-{
-  this->_InteractiveLoadPluginsFromPath( );
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditorMainWindow::
-_ActionShowPlugins( )
-{
-  this->_ShowPlugins( );
-}
-
 // eof - $RCSfile$
index aa88f1eeffb86c8d982047c9847adaad790bdc37..81f7680e18734637309b075518d72690dea5b93a 100644 (file)
@@ -27,14 +27,6 @@ public:
     );
   virtual ~PipelineEditorMainWindow( );
 
-protected slots:
-  void _ActionOpen( );
-  void _ActionSave( );
-  void _ActionClose( );
-  void _ActionLoadPluginFile( );
-  void _ActionLoadPluginDirectory( );
-  void _ActionShowPlugins( );
-
   /*
     void _ActionBackgroundMPR( );
     void _ActionBackground3D( );
index 0da84326a7efc20f5966591746472ef63de60a98..b5242a96cb75595d784e4341f43ce52386acc9ba 100644 (file)
@@ -94,6 +94,7 @@
     <addaction name="ActionLoadPluginDirectory"/>
     <addaction name="separator"/>
     <addaction name="ActionShowPlugins"/>
+    <addaction name="ActionAddEnvironmentPath"/>
    </widget>
    <addaction name="menuFile"/>
    <addaction name="menuPlugins"/>
     <string>Ctrl+Shift+S</string>
    </property>
   </action>
+  <action name="ActionAddEnvironmentPath">
+   <property name="text">
+    <string>&amp;Manage enviroment paths</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+F9</string>
+   </property>
+  </action>
  </widget>
  <customwidgets>
   <customwidget>
index 16a42e3df7fe12724fca47d0e486706c7e01483a..77a7494beb7e508c5f947c7aa188c2673c2cdf18 100644 (file)
@@ -7,7 +7,7 @@ int main( int argc, char* argv[] )
   cpPlugins::Interface interface;
   try
   {
-    interface.LoadEnvironment( );
+    interface.LoadEnvironments( );
     interface.GuessPlugins( );
   }
   catch( std::exception& err )
index 7bd093fce064ccc1c118e9d3c68986bfc3fabf97..af1a6bd0457ee4a9a20ca55646d271e979b3e6a8 100644 (file)
@@ -16,7 +16,7 @@ int main( int argc, char* argv[] )
   cpPlugins::Interface interface;
   try
   {
-    interface.LoadEnvironment( );
+    interface.LoadEnvironments( );
     interface.LoadDirectory( directory );
   }
   catch( std::exception& err )
index 8749aeffa6c78b90ce1c6a2872fdb3b939c94cee..dc2b0b8e24e5b4423a3cb84f9bdcb1cc1a119fad 100644 (file)
@@ -16,7 +16,7 @@ int main( int argc, char* argv[] )
   cpPlugins::Interface interface;
   try
   {
-    interface.LoadEnvironment( );
+    interface.LoadEnvironments( );
     interface.LoadFile( library_file );
   }
   catch( std::exception& err )
index 8334e2e132e943df7816b84710fa2490ce05e176..d92f459b90fe20eccf388a725b5289f3ba81cb21 100644 (file)
@@ -16,7 +16,7 @@ int main( int argc, char* argv[] )
   cpPlugins::Interface interface;
   try
   {
-    interface.LoadEnvironment( );
+    interface.LoadEnvironments( );
     interface.LoadPlugin( plugin );
   }
   catch( std::exception& err )
index 43a00a760001aacd51ca115ffea54dba6fa39ad1..41dbb6abd814184b617cb334032bb45fbdb0ed20 100644 (file)
@@ -15,7 +15,7 @@ int main( int argc, char* argv[] )
   cpPlugins::Interface interface;
   try
   {
-    interface.LoadEnvironment( );
+    interface.LoadEnvironments( );
     interface.GuessPlugins( );
   }
   catch( std::exception& err )
index d70d4c014bca5b19988f95a417bfb165ab5b38b1..46312b14d025fbe67c58282a4707c84c953b4ea9 100644 (file)
@@ -3,6 +3,7 @@
 #include <cpExtensions/QT/SimpleMPRWidget.h>
 #include <cpBaseQtApplication/ActorPropertiesQDialog.h>
 #include <cpBaseQtApplication/Editor.h>
+#include <cpBaseQtApplication/PathsDialog.h>
 #include <vtkRenderer.h>
 #include <QApplication>
 #include <QColorDialog>
@@ -51,15 +52,16 @@ MainWindow(
   if( i.exists( ) )
   {
     this->m_ExecutionPath = i.canonicalPath( ).toStdString( );
-    try
-    {
-      this->m_Interface.OpenEnvironments( this->m_ExecutionPath );
-      this->m_Interface.UpdateEnvironments( this->m_ExecutionPath );
-    }
+    try { this->m_Interface.AddEnvironments( this->m_ExecutionPath ); }
+    catch( ... ) { }
+    try { this->m_Interface.OpenEnvironments( this->m_ExecutionPath ); }
+    catch( ... ) { }
+    try { this->m_Interface.SaveEnvironments( this->m_ExecutionPath ); }
     catch( ... ) { }
   }
   else
     this->m_ExecutionPath = "";
+  this->UpdateEnvironment( );
   this->m_Workspace.SetInterface( &( this->m_Interface ) );
 }
 
@@ -75,7 +77,7 @@ UpdateEnvironment( )
 {
   try
   {
-    this->m_Interface.LoadEnvironment( );
+    this->m_Interface.LoadEnvironments( );
     this->m_Interface.GuessPlugins( );
   }
   catch( std::exception& err )
@@ -147,6 +149,17 @@ _ClearWorkspace( )
   this->m_Workspace.Clear( );
 }
 
+// -------------------------------------------------------------------------
+void cpBaseQtApplication::MainWindow::
+_AddEnvironments( const std::string& environments )
+{
+  try { this->m_Interface.AddEnvironments( environments ); }
+  catch( ... ) { }
+  try { this->m_Interface.SaveEnvironments( this->m_ExecutionPath ); }
+  catch( ... ) { }
+  this->UpdateEnvironment( );
+}
+
 // -------------------------------------------------------------------------
 void cpBaseQtApplication::MainWindow::
 _LoadPlugins( const std::string& filename )
@@ -249,26 +262,6 @@ _UpdateLoadedPlugins( )
       );
 }
 
-// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_ShowPlugins( )
-{
-  auto paths = this->m_Interface.GetPaths( );
-  auto plugins = this->m_Interface.GetPlugins( );
-  std::stringstream info;
-  info << "-----   PATHS   -----" << std::endl;
-  for( auto i = paths.begin( ); i != paths.end( ); ++i )
-    info << "   " << *i << std::endl;
-  info << std::endl << "-----  PLUGINS  -----" << std::endl;
-  for( auto i = plugins.begin( ); i != plugins.end( ); ++i )
-    info << "   " << *i << std::endl;
-  QMessageBox::information(
-    this,
-    "Loaded libraries and plugins information",
-    info.str( ).c_str( )
-    );
-}
-
 // -------------------------------------------------------------------------
 void cpBaseQtApplication::MainWindow::
 _Block( )
@@ -485,6 +478,26 @@ _InteractiveLoadPluginsFromPath( )
   this->_LoadPluginsFromPath( d.selectedFiles( ).begin( )->toStdString( ) );
 }
 
+// -------------------------------------------------------------------------
+void cpBaseQtApplication::MainWindow::
+_ShowPlugins( )
+{
+  auto paths = this->m_Interface.GetPaths( );
+  auto plugins = this->m_Interface.GetPlugins( );
+  std::stringstream info;
+  info << "-----   PATHS   -----" << std::endl;
+  for( auto i = paths.begin( ); i != paths.end( ); ++i )
+    info << "   " << *i << std::endl;
+  info << std::endl << "-----  PLUGINS  -----" << std::endl;
+  for( auto i = plugins.begin( ); i != plugins.end( ); ++i )
+    info << "   " << *i << std::endl;
+  QMessageBox::information(
+    this,
+    "Loaded libraries and plugins information",
+    info.str( ).c_str( )
+    );
+}
+
 // -------------------------------------------------------------------------
 void cpBaseQtApplication::MainWindow::
 _InteractiveLoadWorkspace( )
@@ -518,6 +531,26 @@ _InteractiveSaveWorkspace( )
   this->_SaveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) );
 }
 
+// -------------------------------------------------------------------------
+void cpBaseQtApplication::MainWindow::
+_InteractiveAddEnviromentPaths( )
+{
+  PathsDialog dlg( this );
+  dlg.addPaths( this->m_Interface.GetPaths( ) );
+  if( dlg.exec( ) )
+  {
+    auto paths = dlg.getPaths( );
+    for( auto p = paths.begin( ); p != paths.end( ); ++p )
+    {
+      try { this->m_Interface.AddEnvironments( *p ); }
+      catch( ... ) { }
+
+    } // rof
+    this->UpdateEnvironment( );
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 void cpBaseQtApplication::MainWindow::
 _ExecFilter( const std::string& filter_name )
index 7c7bcf9551d676f95c340c5195d302ec0ec46025..c68aac9267eb7f56074322e0ac59a65f358ce504 100644 (file)
@@ -57,10 +57,10 @@ namespace cpBaseQtApplication
       cpBaseQtApplication::Editor* editor
       );
     void _ClearWorkspace( );
+    void _AddEnvironments( const std::string& environments );
     void _LoadPlugins( const std::string& filename );
     void _LoadPluginsFromPath( const std::string& path );
     void _UpdateLoadedPlugins( );
-    void _ShowPlugins( );
     void _Block( );
     void _UnBlock( );
 
@@ -72,8 +72,10 @@ namespace cpBaseQtApplication
   protected slots:
     void _InteractiveLoadPlugins( );
     void _InteractiveLoadPluginsFromPath( );
+    void _ShowPlugins( );
     void _InteractiveLoadWorkspace( );
     void _InteractiveSaveWorkspace( );
+    void _InteractiveAddEnviromentPaths( );
     void _ExecFilter( const std::string& filter_name );
     void _ShowData(
       const std::string& filter_name, const std::string& output_name
diff --git a/lib/cpBaseQtApplication/PathsDialog.cxx b/lib/cpBaseQtApplication/PathsDialog.cxx
new file mode 100644 (file)
index 0000000..66f6dab
--- /dev/null
@@ -0,0 +1,71 @@
+#include <cpBaseQtApplication/PathsDialog.h>
+
+#include <cpBaseQtApplication/ui_PathsDialog.h>
+#include <QFileDialog>
+
+// -------------------------------------------------------------------------
+cpBaseQtApplication::PathsDialog::
+PathsDialog( QWidget* parent, Qt::WindowFlags flags )
+  : QDialog( parent, flags ),
+    m_UI( new Ui::PathsDialog )
+{
+  this->m_UI->setupUi( this );
+  this->connect(
+    this->m_UI->AddButton, SIGNAL( clicked( ) ),
+    this, SLOT( _addPath( ) )
+    );
+  this->connect(
+    this->m_UI->RemoveButton, SIGNAL( clicked( ) ),
+    this, SLOT( _removePath( ) )
+    );
+}
+
+// -------------------------------------------------------------------------
+cpBaseQtApplication::PathsDialog::
+~PathsDialog( )
+{
+  delete this->m_UI;
+}
+
+// -------------------------------------------------------------------------
+void cpBaseQtApplication::PathsDialog::
+addPaths( const std::set< std::string >& paths )
+{
+  QStringList lst;
+  for( auto i = paths.begin( ); i != paths.end( ); ++i )
+    lst << i->c_str( );
+  this->m_UI->Paths->addItems( lst );
+}
+
+// -------------------------------------------------------------------------
+std::set< std::string > cpBaseQtApplication::PathsDialog::
+getPaths( ) const
+{
+  std::set< std::string > paths;
+  for( int c = 0; c < this->m_UI->Paths->count( ); ++c )
+    paths.insert( this->m_UI->Paths->item( c )->text( ).toStdString( ) );
+  return( paths );
+}
+
+// -------------------------------------------------------------------------
+void cpBaseQtApplication::PathsDialog::
+_addPath( )
+{
+  auto res =
+    QFileDialog::getExistingDirectory( this, "Choose a directory", "." );
+  if( res.toStdString( ) != "" )
+    this->m_UI->Paths->addItem( res );
+}
+
+// -------------------------------------------------------------------------
+void cpBaseQtApplication::PathsDialog::
+_removePath( )
+{
+  /* TODO
+     auto items = this->m_UI->Paths->selectedItems( );
+     if( items.size( ) == 1 )
+     this->m_UI->Paths->removeItemWidget( items[ 0 ] );
+  */
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpBaseQtApplication/PathsDialog.h b/lib/cpBaseQtApplication/PathsDialog.h
new file mode 100644 (file)
index 0000000..4161555
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef __CPBASEQTAPPLICATION__PATHSDIALOG__H__
+#define __CPBASEQTAPPLICATION__PATHSDIALOG__H__
+
+#include <cpBaseQtApplication_Export.h>
+#include <cpPlugins/Config.h>
+#include <set>
+#include <string>
+#include <QDialog>
+
+// -------------------------------------------------------------------------
+namespace Ui
+{
+  class PathsDialog;
+}
+
+// -------------------------------------------------------------------------
+namespace cpBaseQtApplication
+{
+  /**
+   */
+  class cpBaseQtApplication_EXPORT PathsDialog
+    : public QDialog
+  {
+    Q_OBJECT;
+
+  public:
+    explicit PathsDialog( QWidget* parent = 0, Qt::WindowFlags flags = 0 );
+    virtual ~PathsDialog( );
+
+    void addPaths( const std::set< std::string >& paths );
+    std::set< std::string > getPaths( ) const;
+
+  protected slots:
+    void _addPath( );
+    void _removePath( );
+
+  protected:
+    Ui::PathsDialog* m_UI;
+  };
+
+} // ecapseman
+
+#endif // __CPBASEQTAPPLICATION__PATHSDIALOG__H__
+
+// eof - $RCSfile$
diff --git a/lib/cpBaseQtApplication/PathsDialog.ui b/lib/cpBaseQtApplication/PathsDialog.ui
new file mode 100644 (file)
index 0000000..b938343
--- /dev/null
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PathsDialog</class>
+ <widget class="QDialog" name="PathsDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <property name="spacing">
+    <number>1</number>
+   </property>
+   <property name="margin">
+    <number>1</number>
+   </property>
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QListWidget" name="Paths"/>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <widget class="QPushButton" name="RemoveButton">
+         <property name="minimumSize">
+          <size>
+           <width>25</width>
+           <height>25</height>
+          </size>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>25</width>
+           <height>25</height>
+          </size>
+         </property>
+         <property name="text">
+          <string>-</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="AddButton">
+         <property name="minimumSize">
+          <size>
+           <width>25</width>
+           <height>25</height>
+          </size>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>25</width>
+           <height>25</height>
+          </size>
+         </property>
+         <property name="text">
+          <string>+</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>PathsDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>PathsDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
similarity index 96%
rename from lib/cpPlugins/LoadDynamicLibrariesFunctions.cxx
rename to lib/cpPlugins/DLLManager.cxx
index 9aeafeee66fda627cbf4a0569c7665fd1cef4c10..4a95fb298c74eb22aa5471bd011bfc3db3aa5dbb 100644 (file)
@@ -1,4 +1,4 @@
-#include <cpPlugins/LoadDynamicLibrariesFunctions.h>
+#include <cpPlugins/DLLManager.h>
 
 #ifdef cpPlugins_SYS_WINDOWS
 #  include <Windows.h>
similarity index 66%
rename from lib/cpPlugins/LoadDynamicLibrariesFunctions.h
rename to lib/cpPlugins/DLLManager.h
index 0fa1df58a1f099d9694e2523a896babcb40aa1ae..a054928156dc629c3967cb9d55d2b1549567639d 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef __CPPLUGINS__LOADDYNAMICLIBRARIESFUNCTIONS__H__
-#define __CPPLUGINS__LOADDYNAMICLIBRARIESFUNCTIONS__H__
+#ifndef __CPPLUGINS__DLLMANAGER__H__
+#define __CPPLUGINS__DLLMANAGER__H__
 
 #include <cpPlugins/Config.h>
 
@@ -17,6 +17,6 @@ namespace cpPlugins
 
 } // ecapseman
 
-#endif // __CPPLUGINS__LOADDYNAMICLIBRARIESFUNCTIONS__H__
+#endif // __CPPLUGINS__DLLMANAGER__H__
 
 // eof - $RCSfile$
index f898e7b1e92d7c2237cc34d05159d1c4664c2b28..1f78e27976998f1dd6f53c3f48c1f59a3b7cb53b 100644 (file)
@@ -1,6 +1,6 @@
 #include <cpPlugins/Interface.h>
 #include <cpPlugins/Utilities.h>
-#include <cpPlugins/LoadDynamicLibrariesFunctions.h>
+#include <cpPlugins/DLLManager.h>
 #include <cpPlugins/dirent.h>
 #include <algorithm>
 
@@ -13,7 +13,7 @@ Interface( )
   if( p != NULL )
     str << p << cpPlugins_SEPARATOR;
   str << ".";
-  this->UpdateEnvironments( str.str( ) );
+  this->AddEnvironments( str.str( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -23,17 +23,19 @@ cpPlugins::Interface::
 }
 
 // -------------------------------------------------------------------------
-const std::set< std::string >& cpPlugins::Interface::
+const cpPlugins::Interface::
+TStrings& cpPlugins::Interface::
 GetPaths( ) const
 {
   return( this->m_Paths );
 }
 
 // -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::Interface::
+cpPlugins::Interface::
+TStrings cpPlugins::Interface::
 GetLibraries( ) const
 {
-  std::set< std::string > res;
+  TStrings res;
   for(
     auto i = this->m_Libraries.begin( ); i != this->m_Libraries.end( ); ++i
     )
@@ -42,71 +44,79 @@ GetLibraries( ) const
 }
 
 // -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::Interface::
+cpPlugins::Interface::
+TStrings cpPlugins::Interface::
 GetPlugins( ) const
 {
-  std::set< std::string > res;
+  TStrings res;
   for( auto i = this->m_Plugins.begin( ); i != this->m_Plugins.end( ); ++i )
     res.insert( i->first );
   return( res );
 }
 
 // -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::Interface::
+cpPlugins::Interface::
+TStrings cpPlugins::Interface::
 GetCategories( ) const
 {
-  std::set< std::string > res;
+  TStrings res;
   for( auto i = this->m_Filters.begin( ); i != this->m_Filters.end( ); ++i )
     res.insert( i->first );
   return( res );
 }
 
 // -------------------------------------------------------------------------
-std::set< std::string > cpPlugins::Interface::
+cpPlugins::Interface::
+TStrings cpPlugins::Interface::
 GetFilters( const std::string& category ) const
 {
-  std::set< std::string > res;
+  TStrings res;
   auto cIt = this->m_Filters.find( category );
   if( cIt != this->m_Filters.end( ) )
-  {
     for( auto i = cIt->second.begin( ); i != cIt->second.end( ); ++i )
       res.insert( i->first );
-
-  } // rof
   return( res );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::
-UpdateEnvironments( const std::string& new_environment )
+AddEnvironments( const std::string& new_environment )
 {
   std::vector< std::string > tokens;
   cpPlugins::TokenizeString( tokens, new_environment, cpPlugins_SEPARATOR );
   for( auto i = tokens.begin( ); i != tokens.end( ); ++i )
   {
-    std::string dir = cpPlugins::CanonicalPath( *i );
-    if( dir != "" )
-      this->m_Paths.insert( dir );
+    std::stringstream dir;
+    dir << cpPlugins::CanonicalPath( *i );
+    if( dir.str( ) != "" )
+    {
+      if( !cpPlugins::IsPathSeparator( dir.str( ).back( ) ) )
+        dir << cpPlugins_PATH_SEPARATOR;
+      std::stringstream name;
+      name << dir.str( ) << cpPlugins_CONFIG;
+      std::ifstream check( name.str( ).c_str( ), std::ifstream::binary );
+      if( check )
+        this->m_Paths.insert( dir.str( ) );
+      check.close( );
+
+    } // fi
 
   } // rof
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::
-LoadEnvironment( )
+LoadEnvironments( )
 {
   std::stringstream all_errors;
-  for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
+  for( auto d = this->m_Paths.begin( ); d != this->m_Paths.end( ); ++d )
   {
-    std::stringstream dir;
-    dir << *i;
-    if( !cpPlugins::IsPathSeparator( i->back( ) ) )
-      dir << cpPlugins_PATH_SEPARATOR;
-    std::string fname = dir.str( ) + std::string( cpPlugins_CONFIG );
-    std::string config_file;
-    if( cpPlugins::ReadFileIntoBuffer( config_file, fname ) )
+    std::stringstream name;
+    name << *d << cpPlugins_CONFIG;
+    std::string buffer;
+    if( cpPlugins::ReadFileIntoBuffer( buffer, name.str( ) ) )
     {
-      std::istringstream input( config_file );
+      std::istringstream input( buffer );
       for( std::string line; std::getline( input, line ); )
       {
         std::vector< std::string > tokens;
@@ -115,10 +125,8 @@ LoadEnvironment( )
         if( tokens[ 0 ] == "local" )
           library_file =
             cpPlugins::CanonicalPath(
-              dir.str( ) +
-              std::string( cpPlugins_LIB_PREFIX ) +
-              tokens[ 1 ] +
-              std::string( "." ) + 
+              *d + std::string( cpPlugins_LIB_PREFIX ) +
+              tokens[ 1 ] + std::string( "." ) + 
               std::string( cpPlugins_LIB_EXT )
               );
         else if( tokens[ 0 ] == "global" )
@@ -162,10 +170,10 @@ SaveEnvironments( const std::string& dir ) const
 
     std::stringstream fname;
     fname << dir;
-    if( cpPlugins::IsPathSeparator( dir.back( ) ) )
+    if( !cpPlugins::IsPathSeparator( dir.back( ) ) )
       fname << cpPlugins_PATH_SEPARATOR;
-    fname << cpPlugins_CONFIG;
-    if( !( cpPlugins::WriteBufferToFile( buffer.str( ), fname.str( ) ) ) )
+    fname << cpPlugins_PATHS;
+    if( !cpPlugins::WriteBufferToFile( buffer.str( ), fname.str( ) ) )
       throw std::runtime_error( "Error writing environment file." );
   }
   else
@@ -178,15 +186,17 @@ OpenEnvironments( const std::string& dir )
 {
   std::stringstream fname;
   fname << dir;
-  if( cpPlugins::IsPathSeparator( dir.back( ) ) )
+  if( !cpPlugins::IsPathSeparator( dir.back( ) ) )
     fname << cpPlugins_PATH_SEPARATOR;
-  fname << cpPlugins_CONFIG;
+  fname << cpPlugins_PATHS;
   std::string buffer;
   if( cpPlugins::ReadFileIntoBuffer( buffer, fname.str( ) ) )
   {
     std::istringstream input( buffer );
+    std::stringstream paths;
     for( std::string line; std::getline( input, line ); )
-      this->m_Paths.insert( cpPlugins::CanonicalPath( line ) );
+      paths << line << cpPlugins_SEPARATOR;
+    this->AddEnvironments( paths.str( ) );
   }
   else
     throw std::runtime_error( "Error opening environment file." );
@@ -375,13 +385,8 @@ GuessPlugins( )
 {
   for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
   {
-    try
-    {
-      this->LoadDirectory( *i );
-    }
-    catch( ... )
-    {
-    } // yrt
+    try { this->LoadDirectory( *i ); }
+    catch( ... ) { }
 
   } // rof
 }
index 86c46b9ce18b60535a5cff5f2583c16faed42ee8..ee3fa0c2f2d64e9101e15e98f5d67bb22365d642 100644 (file)
@@ -25,20 +25,22 @@ namespace cpPlugins
       void*       LibraryHandle;
       TCreator    Creator;
     };
-    typedef std::map< std::string, std::map< std::string, TCreatorData > > TFilters;
+    typedef std::map< std::string, TCreatorData > TFilterData;
+    typedef std::map< std::string, TFilterData >  TFilters;
+    typedef std::set< std::string >               TStrings;
 
   public:
     Interface( );
     virtual ~Interface( );
 
-    const std::set< std::string >& GetPaths( ) const;
-    std::set< std::string > GetLibraries( ) const;
-    std::set< std::string > GetPlugins( ) const;
-    std::set< std::string > GetCategories( ) const;
-    std::set< std::string > GetFilters( const std::string& category ) const;
+    const TStrings& GetPaths( ) const;
+    TStrings GetLibraries( ) const;
+    TStrings GetPlugins( ) const;
+    TStrings GetCategories( ) const;
+    TStrings GetFilters( const std::string& category ) const;
 
-    void UpdateEnvironments( const std::string& new_environment );
-    void LoadEnvironment( );
+    void AddEnvironments( const std::string& new_environment );
+    void LoadEnvironments( );
     void SaveEnvironments( const std::string& dir ) const;
     void OpenEnvironments( const std::string& dir );
 
@@ -52,48 +54,10 @@ namespace cpPlugins
       );
 
   protected:
-    std::set< std::string > m_Paths;
+    TStrings   m_Paths;
     TLibraries m_Libraries;
     TLibraries m_Plugins;
-    TFilters m_Filters;
-
-
-    /* TODO
-       const TFilters& GetFilters( );
-
-       void UpdatePaths( );
-       void GuessAccesiblePlugins( );
-       void LoadPlugin( const std::string& name );
-       void LoadPluginDir( const std::string& dirname );
-       void LoadPluginFile( const std::string& filename );
-       void UnloadAll( );
-
-       ProcessObject::Pointer Create(
-       const std::string& category, const std::string& name
-       );
-       std::string GetPluginName(
-       const std::string& category, const std::string& name
-       ) const;
-       std::string GetPluginName( const ProcessObject* obj ) const;
-       std::set< std::string > GetPlugins( ) const;
-
-       protected:
-       static void* _DLOpen( const std::string& fname, std::string& error );
-       static const char* _DLGetName( void* hnd );
-       static TFilters _DLGetFilters( void* hnd );
-       static TCreator _DLGetCreator(
-       void* hnd, const std::string& category, const std::string& name
-       );
-       static void _DLClose( void* hnd );
-
-       protected:
-       std::vector< std::string > m_Paths;
-       TDynLibraries m_DynLibraries;
-       TDynFilters   m_DynFilters;
-       TFilters      m_Filters;
-
-       static unsigned int InterfacesCount;
-    */
+    TFilters   m_Filters;
   };
 
 } // ecapseman
index ff033b4b62277e674a8c85cded12860f8f6e19af..d4eff536b392d3ce7a3d0c08c4fc817bc3bdccec 100644 (file)
@@ -113,9 +113,7 @@ namespace cpPlugins
     const std::string& buffer, const std::string& fname
     )
   {
-    std::ofstream file_stream(
-      CanonicalPath( fname ).c_str( ), std::ofstream::binary
-      );
+    std::ofstream file_stream( fname.c_str( ), std::ofstream::binary );
     if( !file_stream )
       return( false );
     file_stream.write( buffer.c_str( ), buffer.size( ) );