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