Commit ab1572c5 authored by Pierre Kraemer's avatar Pierre Kraemer

update plugin loading to accept dylib extension

parent ae5dff32
...@@ -18,6 +18,8 @@ find_package(QGLViewer REQUIRED) ...@@ -18,6 +18,8 @@ find_package(QGLViewer REQUIRED)
#======SCHNApps=======# #======SCHNApps=======#
SET(SCHNApps_ROOT_DIR ${CGoGN_ROOT_DIR}/SCHNApps) SET(SCHNApps_ROOT_DIR ${CGoGN_ROOT_DIR}/SCHNApps)
SET(EXECUTABLE_OUTPUT_PATH ${SCHNApps_ROOT_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${SCHNApps_ROOT_DIR}/plugins/lib)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Release Release) ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Release Release)
IF (NOT WIN32) IF (NOT WIN32)
...@@ -27,10 +29,6 @@ ENDIF (NOT WIN32) ...@@ -27,10 +29,6 @@ ENDIF (NOT WIN32)
configure_file(${CMAKE_SOURCE_DIR}/settings/state_save.xml ${EXECUTABLE_OUTPUT_PATH}/state_save.xml @ONLY) configure_file(${CMAKE_SOURCE_DIR}/settings/state_save.xml ${EXECUTABLE_OUTPUT_PATH}/state_save.xml @ONLY)
#======Plugins=======#
#ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Plugins)
#======Documentation=======# #======Documentation=======#
find_package(Doxygen) find_package(Doxygen)
if(DOXYGEN_FOUND) if(DOXYGEN_FOUND)
...@@ -41,4 +39,3 @@ add_custom_target(doc ...@@ -41,4 +39,3 @@ add_custom_target(doc
COMMENT "Generating API documentation with Doxygen" VERBATIM COMMENT "Generating API documentation with Doxygen" VERBATIM
) )
endif(DOXYGEN_FOUND) endif(DOXYGEN_FOUND)
...@@ -60,15 +60,18 @@ QT4_ADD_RESOURCES( RCC_FILES ...@@ -60,15 +60,18 @@ QT4_ADD_RESOURCES( RCC_FILES
${SCHNApps_ROOT_DIR}/resources/resources.qrc ${SCHNApps_ROOT_DIR}/resources/resources.qrc
) )
ADD_EXECUTABLE( SCHNappsD ADD_EXECUTABLE( SCHNAppsD
${SCHNApps_SRC_FILES} ${SCHNApps_SRC_FILES}
${UI_H_FILES} ${UI_H_FILES}
${MOC_FILES} ${MOC_FILES}
${RCC_FILES} ${RCC_FILES}
) )
TARGET_LINK_LIBRARIES( SCHNappsD TARGET_LINK_LIBRARIES( SCHNAppsD
${CGoGN_LIBS_D} ${CGoGN_LIBS_D}
${COMMON_LIBS} ${COMMON_LIBS}
${QGLVIEWER_LIBRARIES} ${QGLVIEWER_LIBRARIES}
) )
ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/Plugins PluginsD)
#ifndef FIRSTPLUGIN_H_ #ifndef FIRSTPLUGIN_H_
#define FIRSTPLUGIN_H_ #define FIRSTPLUGIN_H_
#include "visualPlugin.h" #include "plugins/visualPlugin.h"
/**---CGoGN includes **/ /**---CGoGN includes **/
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
......
...@@ -62,15 +62,18 @@ QT4_ADD_RESOURCES( RCC_FILES ...@@ -62,15 +62,18 @@ QT4_ADD_RESOURCES( RCC_FILES
${SCHNApps_ROOT_DIR}/resources/resources.qrc ${SCHNApps_ROOT_DIR}/resources/resources.qrc
) )
ADD_EXECUTABLE( SCHNapps ADD_EXECUTABLE( SCHNApps
${SCHNApps_SRC_FILES} ${SCHNApps_SRC_FILES}
${UI_H_FILES} ${UI_H_FILES}
${MOC_FILES} ${MOC_FILES}
${RCC_FILES} ${RCC_FILES}
) )
TARGET_LINK_LIBRARIES( SCHNapps TARGET_LINK_LIBRARIES( SCHNApps
${CGoGN_LIBS_R} ${CGoGN_LIBS_R}
${COMMON_LIBS} ${COMMON_LIBS}
${QGLVIEWER_LIBRARIES} ${QGLVIEWER_LIBRARIES}
) )
ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/Plugins Plugins)
...@@ -68,9 +68,11 @@ PluginDialog::PluginDialog(Window* parent, PluginHash* activePlugins) : QDialog( ...@@ -68,9 +68,11 @@ PluginDialog::PluginDialog(Window* parent, PluginHash* activePlugins) : QDialog(
init=false; init=false;
} }
PluginDialog::~PluginDialog(){} PluginDialog::~PluginDialog()
{}
bool PluginDialog::loadInfoPlugins(){ bool PluginDialog::loadInfoPlugins()
{
QFile xmlFile(System::app_path.toStdString().c_str() + QFile xmlFile(System::app_path.toStdString().c_str() +
QString("/state_save.xml")); QString("/state_save.xml"));
...@@ -80,29 +82,34 @@ bool PluginDialog::loadInfoPlugins(){ ...@@ -80,29 +82,34 @@ bool PluginDialog::loadInfoPlugins(){
return false; return false;
} }
if(!xmlFile.open(QIODevice::ReadOnly)){ if(!xmlFile.open(QIODevice::ReadOnly))
{
System::Error::code= System::Error::ERROR_OPEN_PLUGIN_FILE; System::Error::code= System::Error::ERROR_OPEN_PLUGIN_FILE;
return false; return false;
} }
QDomDocument doc; QDomDocument doc;
if(!doc.setContent(&xmlFile)){ if(!doc.setContent(&xmlFile))
{
System::Error::code= System::Error::BAD_PLUGIN_PATH_FILE; System::Error::code= System::Error::BAD_PLUGIN_PATH_FILE;
xmlFile.close(); xmlFile.close();
return false; return false;
} }
xmlFile.close(); xmlFile.close();
QDomElement root= doc.documentElement(); QDomElement root= doc.documentElement();
QDomElement plugins_node= root.firstChildElement("PLUGINS"); QDomElement plugins_node= root.firstChildElement("PLUGINS");
if(!plugins_node.isNull()){ if(!plugins_node.isNull())
{
QDomElement plugins_subNode= plugins_node.firstChildElement(); QDomElement plugins_subNode= plugins_node.firstChildElement();
while(!plugins_subNode.isNull()){ while(!plugins_subNode.isNull())
if(plugins_subNode.tagName()=="DIR"){ {
if(plugins_subNode.tagName()=="DIR")
{
QString pluginDirPath= plugins_subNode.attribute("path","./plugins"); QString pluginDirPath= plugins_subNode.attribute("path","./plugins");
QFileInfo fi(pluginDirPath); QFileInfo fi(pluginDirPath);
if(fi.exists() && fi.isDir()){ if(fi.exists() && fi.isDir())
{
QDir pluginDir(pluginDirPath); QDir pluginDir(pluginDirPath);
QTreeWidgetItem* dirItem= new QTreeWidgetItem(treeWidget, DIR); QTreeWidgetItem* dirItem= new QTreeWidgetItem(treeWidget, DIR);
...@@ -110,37 +117,45 @@ bool PluginDialog::loadInfoPlugins(){ ...@@ -110,37 +117,45 @@ bool PluginDialog::loadInfoPlugins(){
QStringList filters, dirFiles; QStringList filters, dirFiles;
filters << "lib*.so"; filters << "lib*.so";
filters << "lib*.dylib";
dirFiles= pluginDir.entryList(filters,QDir::Files); dirFiles= pluginDir.entryList(filters,QDir::Files);
foreach(QString fileName, dirFiles){ foreach(QString fileName, dirFiles)
QString pluginName= fileName; {
pluginName.remove(0,3); QFileInfo pfi(fileName);
pluginName.remove(pluginName.lastIndexOf(".so"),3); QString pluginName= pfi.baseName().remove(0,3);
QTreeWidgetItem* item= new QTreeWidgetItem(dirItem, FILE_DIR); QTreeWidgetItem* item= new QTreeWidgetItem(dirItem, FILE_DIR);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if(activePlugins->find(pluginName)!=activePlugins->end()){ if(activePlugins->find(pluginName)!=activePlugins->end())
{
item->setCheckState(0,Qt::Checked); item->setCheckState(0,Qt::Checked);
} }
else{ else
{
item->setCheckState(0,Qt::Unchecked); item->setCheckState(0,Qt::Unchecked);
} }
item->setText(1,pluginDir.absoluteFilePath(fileName)); item->setText(1,pluginDir.absoluteFilePath(fileName));
} }
} }
} }
else if(plugins_subNode.tagName()=="FILE"){ else if(plugins_subNode.tagName()=="FILE")
{
QString pluginPath= plugins_subNode.attribute("path"); QString pluginPath= plugins_subNode.attribute("path");
if(!pluginPath.isEmpty()){ if(!pluginPath.isEmpty())
{
QFileInfo fi(pluginPath); QFileInfo fi(pluginPath);
if(fi.exists() && pluginPath.left(3)=="lib" && fi.suffix()=="so"){ if(fi.exists() && pluginPath.left(3)=="lib" && (fi.suffix()=="so" || fi.suffix()=="dylib"))
{
QString pluginName= fi.baseName().remove(0,3); QString pluginName= fi.baseName().remove(0,3);
QTreeWidgetItem* item= new QTreeWidgetItem(treeWidget, FILE); QTreeWidgetItem* item= new QTreeWidgetItem(treeWidget, FILE);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if(activePlugins->find(pluginName)!=activePlugins->end()){ if(activePlugins->find(pluginName)!=activePlugins->end())
{
item->setCheckState(0,Qt::Checked); item->setCheckState(0,Qt::Checked);
} }
else{ else
{
item->setCheckState(0,Qt::Unchecked); item->setCheckState(0,Qt::Unchecked);
} }
item->setText(1,pluginPath); item->setText(1,pluginPath);
...@@ -211,8 +226,10 @@ bool PluginDialog::loadInfoPlugins(){ ...@@ -211,8 +226,10 @@ bool PluginDialog::loadInfoPlugins(){
// //
//} //}
void PluginDialog::showPluginsDir(QDir directory){ void PluginDialog::showPluginsDir(QDir directory)
if(!directory.exists()){ {
if(!directory.exists())
{
System::Error::code= System::Error::BAD_PLUGIN_PATH_IN_FILE_f(directory.absolutePath()); System::Error::code= System::Error::BAD_PLUGIN_PATH_IN_FILE_f(directory.absolutePath());
} }
...@@ -221,27 +238,30 @@ void PluginDialog::showPluginsDir(QDir directory){ ...@@ -221,27 +238,30 @@ void PluginDialog::showPluginsDir(QDir directory){
QStringList filters, dirFiles; QStringList filters, dirFiles;
filters << "lib*.so"; filters << "lib*.so";
filters << "lib*.dylib";
dirFiles= directory.entryList(filters, QDir::Files); dirFiles= directory.entryList(filters, QDir::Files);
foreach(QString file, dirFiles){ foreach(QString file, dirFiles)
QString pluginName= file; {
pluginName.remove(0,3); QFileInfo pfi(file);
pluginName.remove(pluginName.lastIndexOf(".so"),3); QString pluginName= pfi.baseName().remove(0,3);
QTreeWidgetItem* item= new QTreeWidgetItem(dirItem, FILE_DIR); QTreeWidgetItem* item= new QTreeWidgetItem(dirItem, FILE_DIR);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if(activePlugins->find(pluginName)!=activePlugins->end()){ if(activePlugins->find(pluginName)!=activePlugins->end())
{
item->setCheckState(0,Qt::Checked); item->setCheckState(0,Qt::Checked);
} }
else{ else
{
item->setCheckState(0,Qt::Unchecked); item->setCheckState(0,Qt::Unchecked);
} }
item->setText(1,directory.absoluteFilePath(file)); item->setText(1,directory.absoluteFilePath(file));
} }
if(dirFiles.isEmpty()){ if(dirFiles.isEmpty())
{
System::Error::code= System::Error::NO_PLUGIN_IN_DIR_f(directory.absolutePath()); System::Error::code= System::Error::NO_PLUGIN_IN_DIR_f(directory.absolutePath());
} }
} }
...@@ -252,7 +272,7 @@ void PluginDialog::cb_addPlugins(){ ...@@ -252,7 +272,7 @@ void PluginDialog::cb_addPlugins(){
this, this,
"Select one or more plugin to open", "Select one or more plugin to open",
"/home", "/home",
"Plugins (lib*.so)"); "Plugins (lib*.so, lib*.dylib)");
if(!files.empty()){ if(!files.empty()){
// QDomElement root= doc.documentElement(); // QDomElement root= doc.documentElement();
// QDomNode node= root.firstChild(); // QDomNode node= root.firstChild();
...@@ -430,9 +450,12 @@ void PluginDialog::cb_removePlugins(){ ...@@ -430,9 +450,12 @@ void PluginDialog::cb_removePlugins(){
} }
} }
void PluginDialog::cb_activePlugin(QTreeWidgetItem* item, int column){ void PluginDialog::cb_activePlugin(QTreeWidgetItem* item, int column)
if(!init && column==0){ {
if(item->checkState(0)==Qt::Checked){ if(!init && column==0)
{
if(item->checkState(0)==Qt::Checked)
{
// QDomElement root= doc.documentElement(); // QDomElement root= doc.documentElement();
// QDomNode node= root.firstChild(); // QDomNode node= root.firstChild();
// QDomElement balise; // QDomElement balise;
...@@ -453,10 +476,7 @@ void PluginDialog::cb_activePlugin(QTreeWidgetItem* item, int column){ ...@@ -453,10 +476,7 @@ void PluginDialog::cb_activePlugin(QTreeWidgetItem* item, int column){
QString pluginFile= item->text(1); QString pluginFile= item->text(1);
QFileInfo pluginInfo(pluginFile); QFileInfo pluginInfo(pluginFile);
QString pluginName= pluginInfo.fileName(); QString pluginName= pluginInfo.baseName().remove(0,3);
pluginName.remove(0,3);
pluginName.remove(pluginName.lastIndexOf(".so"),3);
if(activePlugins->find(pluginName)!= activePlugins->end()){ if(activePlugins->find(pluginName)!= activePlugins->end()){
System::Error::code= System::Error::PLUGIN_EXISTS_f(pluginName); System::Error::code= System::Error::PLUGIN_EXISTS_f(pluginName);
...@@ -495,12 +515,8 @@ void PluginDialog::cb_activePlugin(QTreeWidgetItem* item, int column){ ...@@ -495,12 +515,8 @@ void PluginDialog::cb_activePlugin(QTreeWidgetItem* item, int column){
// } // }
QString pluginFile= item->text(1); QString pluginFile= item->text(1);
QString pluginName= QFileInfo(pluginFile).fileName(); QFileInfo pluginInfo(pluginFile);
QString pluginName= pluginInfo.baseName().remove(0,3);
pluginName.remove(0,3);
pluginName.remove(pluginName.lastIndexOf(".so"),3);
PluginHash::iterator it= activePlugins->find(pluginName); PluginHash::iterator it= activePlugins->find(pluginName);
bool pluginHasDependencies= (it!=activePlugins->end())?(*it)->hasDependantPlugins():false; bool pluginHasDependencies= (it!=activePlugins->end())?(*it)->hasDependantPlugins():false;
...@@ -538,9 +554,9 @@ void PluginDialog::cb_activePlugin(QTreeWidgetItem* item, int column){ ...@@ -538,9 +554,9 @@ void PluginDialog::cb_activePlugin(QTreeWidgetItem* item, int column){
QTreeWidgetItemIterator tree_it(treeWidget, QTreeWidgetItemIterator::Checked); QTreeWidgetItemIterator tree_it(treeWidget, QTreeWidgetItemIterator::Checked);
while(*tree_it){ while(*tree_it){
QString depPlugPath=(*tree_it)->text(1); QString depPlugPath=(*tree_it)->text(1);
QString depPlugName= QFileInfo(depPlugPath).fileName();
depPlugName.remove(0,3); QFileInfo depPlugInfo(depPlugPath);
depPlugName.remove(depPlugName.lastIndexOf(".so"),3); QString depPlugName= depPlugInfo.baseName().remove(0,3);
if(depList.contains(depPlugName)){ if(depList.contains(depPlugName)){
init=true; init=true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment