mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-20 06:06:13 +00:00
Changed: #1206 Update sheet builder plugin. Now plugin is using ICore for reading and writing settings, and it adds action in menu Sheet.
This commit is contained in:
parent
4b96864a9e
commit
5d0be05baf
12 changed files with 561 additions and 573 deletions
|
@ -43,6 +43,8 @@ const char * const M_TOOLS = "ObjectViewerQt.Menu.Tools";
|
||||||
const char * const M_WINDOW = "ObjectViewerQt.Menu.Window";
|
const char * const M_WINDOW = "ObjectViewerQt.Menu.Window";
|
||||||
const char * const M_HELP = "ObjectViewerQt.Menu.Help";
|
const char * const M_HELP = "ObjectViewerQt.Menu.Help";
|
||||||
|
|
||||||
|
const char * const M_SHEET = "ObjectViewerQt.Menu.Sheet";
|
||||||
|
|
||||||
//actions
|
//actions
|
||||||
const char * const NEW = "ObjectViewerQt.New";
|
const char * const NEW = "ObjectViewerQt.New";
|
||||||
const char * const OPEN = "ObjectViewerQt.Open";
|
const char * const OPEN = "ObjectViewerQt.Open";
|
||||||
|
|
|
@ -58,12 +58,11 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr
|
||||||
_plugMan = pluginManager;
|
_plugMan = pluginManager;
|
||||||
|
|
||||||
_mainWindow = new MainWindow(pluginManager);
|
_mainWindow = new MainWindow(pluginManager);
|
||||||
/* if (QtWin::isCompositionEnabled())
|
/*if (QtWin::isCompositionEnabled())
|
||||||
{
|
{
|
||||||
QtWin::extendFrameIntoClientArea(_mainWindow);
|
QtWin::extendFrameIntoClientArea(_mainWindow);
|
||||||
_mainWindow->setContentsMargins(0, 0, 0, 0);
|
_mainWindow->setContentsMargins(0, 0, 0, 0);
|
||||||
}
|
}*/
|
||||||
*/
|
|
||||||
bool success = _mainWindow->initialize(errorString);
|
bool success = _mainWindow->initialize(errorString);
|
||||||
CSearchPathsSettingsPage *serchPathPage = new CSearchPathsSettingsPage(this);
|
CSearchPathsSettingsPage *serchPathPage = new CSearchPathsSettingsPage(this);
|
||||||
serchPathPage->applySearchPaths();
|
serchPathPage->applySearchPaths();
|
||||||
|
|
|
@ -231,8 +231,10 @@ void MainWindow::createMenus()
|
||||||
m_toolsMenu = menuBar()->addMenu(tr("&Tools"));
|
m_toolsMenu = menuBar()->addMenu(tr("&Tools"));
|
||||||
menuManager()->registerMenu(m_toolsMenu, Constants::M_TOOLS);
|
menuManager()->registerMenu(m_toolsMenu, Constants::M_TOOLS);
|
||||||
|
|
||||||
|
m_sheetMenu = m_toolsMenu->addMenu(tr("&Sheet"));
|
||||||
|
menuManager()->registerMenu(m_sheetMenu, Constants::M_SHEET);
|
||||||
|
|
||||||
m_toolsMenu->addSeparator();
|
// m_toolsMenu->addSeparator();
|
||||||
|
|
||||||
m_toolsMenu->addAction(m_settingsAction);
|
m_toolsMenu->addAction(m_settingsAction);
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,8 @@ private:
|
||||||
QMenu *m_toolsMenu;
|
QMenu *m_toolsMenu;
|
||||||
QMenu *m_helpMenu;
|
QMenu *m_helpMenu;
|
||||||
|
|
||||||
|
QMenu *m_sheetMenu;
|
||||||
|
|
||||||
QAction *m_openAction;
|
QAction *m_openAction;
|
||||||
QAction *m_exitAction;
|
QAction *m_exitAction;
|
||||||
QAction *m_settingsAction;
|
QAction *m_settingsAction;
|
||||||
|
|
|
@ -21,7 +21,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC})
|
||||||
|
|
||||||
ADD_LIBRARY(ovqt_plugin_sheet_builder MODULE ${SRC} ${OVQT_PLUG_SHEET_BUILDER_MOC_SRC} ${OVQT_EXT_SYS_SRC})
|
ADD_LIBRARY(ovqt_plugin_sheet_builder MODULE ${SRC} ${OVQT_PLUG_SHEET_BUILDER_MOC_SRC} ${OVQT_EXT_SYS_SRC})
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(ovqt_plugin_sheet_builder nelmisc ${QT_LIBRARIES})
|
TARGET_LINK_LIBRARIES(ovqt_plugin_sheet_builder ovqt_plugin_core nelmisc ${QT_LIBRARIES})
|
||||||
|
|
||||||
NL_DEFAULT_PROPS(ovqt_plugin_sheet_builder "NeL, Tools, 3D: Object Viewer Qt Plugin: Sheet builder")
|
NL_DEFAULT_PROPS(ovqt_plugin_sheet_builder "NeL, Tools, 3D: Object Viewer Qt Plugin: Sheet builder")
|
||||||
NL_ADD_RUNTIME_FLAGS(ovqt_plugin_sheet_builder)
|
NL_ADD_RUNTIME_FLAGS(ovqt_plugin_sheet_builder)
|
||||||
|
|
|
@ -14,8 +14,18 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Project includes
|
||||||
#include "ovqt_sheet_builder.h"
|
#include "ovqt_sheet_builder.h"
|
||||||
|
#include "sheetbuilderdialog.h"
|
||||||
|
#include "sheetbuilderconfgdialog.h"
|
||||||
|
#include "../core/icore.h"
|
||||||
|
#include "../core/imenu_manager.h"
|
||||||
|
#include "../core/core_constants.h"
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
|
@ -23,47 +33,29 @@
|
||||||
#include <QtGui/QAction>
|
#include <QtGui/QAction>
|
||||||
#include <QtGui/QMenuBar>
|
#include <QtGui/QMenuBar>
|
||||||
|
|
||||||
#include "../../extension_system/iplugin_spec.h"
|
|
||||||
|
|
||||||
#include "nel/misc/debug.h"
|
|
||||||
#include "sheetbuilderdialog.h"
|
|
||||||
#include "sheetbuilderconfgdialog.h"
|
|
||||||
|
|
||||||
using namespace Plugin;
|
using namespace Plugin;
|
||||||
|
|
||||||
bool SheetBuilderPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
|
bool SheetBuilderPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
|
||||||
{
|
{
|
||||||
Q_UNUSED(errorString);
|
Q_UNUSED(errorString);
|
||||||
_plugMan = pluginManager;
|
_plugMan = pluginManager;
|
||||||
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
|
|
||||||
if (!wnd)
|
|
||||||
{
|
|
||||||
*errorString = tr("Not found MainWindow Object Viewer Qt.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
|
|
||||||
if (!toolsMenu)
|
|
||||||
{
|
|
||||||
*errorString = tr("Not found QMenu Tools.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderPlugin::extensionsInitialized()
|
void SheetBuilderPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
|
Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager();
|
||||||
nlassert(toolsMenu);
|
|
||||||
|
|
||||||
toolsMenu->addSeparator();
|
QMenu *sheetMenu = menuManager->menu(Core::Constants::M_SHEET);
|
||||||
|
QAction *sheetBuilderAction = sheetMenu->addAction(tr("Sheet builder"));
|
||||||
QAction *actBuilder = toolsMenu->addAction("Sheet builder");
|
menuManager->registerAction(sheetBuilderAction, "SheetBuilder");
|
||||||
connect(actBuilder, SIGNAL(triggered()), this, SLOT(execBuilderDialog()));
|
connect(sheetBuilderAction, SIGNAL(triggered()), this, SLOT(execBuilderDialog()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderPlugin::execBuilderDialog()
|
void SheetBuilderPlugin::execBuilderDialog()
|
||||||
{
|
{
|
||||||
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
|
QMainWindow *wnd = Core::ICore::instance()->mainWindow();
|
||||||
nlassert(wnd);
|
nlassert(wnd);
|
||||||
|
|
||||||
SheetBuilderDialog dlg(wnd);
|
SheetBuilderDialog dlg(wnd);
|
||||||
|
@ -100,25 +92,11 @@ QString SheetBuilderPlugin::description() const
|
||||||
return "make_sheet_id equivalent";
|
return "make_sheet_id equivalent";
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> SheetBuilderPlugin::dependencies() const
|
QStringList SheetBuilderPlugin::dependencies() const
|
||||||
{
|
{
|
||||||
return QList<QString>();
|
QStringList list;
|
||||||
}
|
list.append(Core::Constants::OVQT_CORE_PLUGIN);
|
||||||
|
return list;
|
||||||
QObject* SheetBuilderPlugin::objectByName(const QString &name) const
|
|
||||||
{
|
|
||||||
Q_FOREACH (QObject *qobj, _plugMan->allObjects())
|
|
||||||
if (qobj->objectName() == name)
|
|
||||||
return qobj;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtensionSystem::IPluginSpec *SheetBuilderPlugin::pluginByName(const QString &name) const
|
|
||||||
{
|
|
||||||
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, _plugMan->plugins())
|
|
||||||
if (spec->name() == name)
|
|
||||||
return spec;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN(SheetBuilderPlugin)
|
Q_EXPORT_PLUGIN(SheetBuilderPlugin)
|
||||||
|
|
|
@ -25,48 +25,45 @@
|
||||||
|
|
||||||
namespace NLMISC
|
namespace NLMISC
|
||||||
{
|
{
|
||||||
class CLibraryContext;
|
class CLibraryContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ExtensionSystem
|
namespace ExtensionSystem
|
||||||
{
|
{
|
||||||
class IPluginSpec;
|
class IPluginSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Plugin
|
namespace Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
class SheetBuilderPlugin : public QObject, public ExtensionSystem::IPlugin
|
class SheetBuilderPlugin : public QObject, public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_INTERFACES(ExtensionSystem::IPlugin)
|
Q_INTERFACES(ExtensionSystem::IPlugin)
|
||||||
public:
|
public:
|
||||||
bool initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString);
|
bool initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString);
|
||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
|
|
||||||
void setNelContext(NLMISC::INelContext *nelContext);
|
void setNelContext(NLMISC::INelContext *nelContext);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QString version() const;
|
QString version() const;
|
||||||
QString vendor() const;
|
QString vendor() const;
|
||||||
QString description() const;
|
QString description() const;
|
||||||
QList<QString> dependencies() const;
|
QStringList dependencies() const;
|
||||||
|
|
||||||
QObject *objectByName(const QString &name) const;
|
void buildSheet(bool clean);
|
||||||
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
|
|
||||||
|
|
||||||
void buildSheet(bool clean);
|
private Q_SLOTS:
|
||||||
|
void execBuilderDialog();
|
||||||
|
|
||||||
private Q_SLOTS:
|
protected:
|
||||||
void execBuilderDialog();
|
NLMISC::CLibraryContext *_LibContext;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
NLMISC::CLibraryContext *_LibContext;
|
ExtensionSystem::IPluginManager *_plugMan;
|
||||||
|
|
||||||
private:
|
};
|
||||||
ExtensionSystem::IPluginManager *_plugMan;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Plugin
|
} // namespace Plugin
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,8 @@
|
||||||
// std
|
// std
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -42,18 +40,24 @@ using namespace std;
|
||||||
*/
|
*/
|
||||||
union TFormId
|
union TFormId
|
||||||
{
|
{
|
||||||
uint32 Id;
|
uint32 Id;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32 Type : 8;
|
uint32 Type : 8;
|
||||||
uint32 Id : 24;
|
uint32 Id : 24;
|
||||||
} FormIDInfos;
|
} FormIDInfos;
|
||||||
|
|
||||||
void serial(NLMISC::IStream &f) { f.serial(Id); }
|
void serial(NLMISC::IStream &f)
|
||||||
|
{
|
||||||
|
f.serial(Id);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator<(const TFormId& fid1, const TFormId& fid2) { return fid1.Id<fid2.Id; }
|
bool operator<(const TFormId& fid1, const TFormId& fid2)
|
||||||
|
{
|
||||||
|
return fid1.Id<fid2.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
map<string,TFormId> FormToId;
|
map<string,TFormId> FormToId;
|
||||||
|
@ -86,15 +90,15 @@ bool getFileType( string& fileName, string& fileType );
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
sint16 getFirstFreeFileTypeId()
|
sint16 getFirstFreeFileTypeId()
|
||||||
{
|
{
|
||||||
for( sint16 id=0; id<256; ++id )
|
for( sint16 id=0; id<256; ++id )
|
||||||
{
|
{
|
||||||
if( IdToFileType.find((uint8)id) == IdToFileType.end() )
|
if( IdToFileType.find((uint8)id) == IdToFileType.end() )
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
} // getFirstFreeFileTypeId //
|
} // getFirstFreeFileTypeId //
|
||||||
|
|
||||||
|
@ -105,238 +109,232 @@ sint16 getFirstFreeFileTypeId()
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void readFormId( string& outputFileName )
|
void readFormId( string& outputFileName )
|
||||||
{
|
{
|
||||||
CIFile f;
|
CIFile f;
|
||||||
if( f.open( outputFileName ) )
|
if( f.open( outputFileName ) )
|
||||||
{
|
{
|
||||||
f.serialCont( IdToForm );
|
f.serialCont( IdToForm );
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert an unknown entry
|
// insert an unknown entry
|
||||||
TFormId formId;
|
TFormId formId;
|
||||||
formId.Id = 0;
|
formId.Id = 0;
|
||||||
IdToForm.insert( make_pair( formId, string("unknown.unknown") ) );
|
IdToForm.insert( make_pair( formId, string("unknown.unknown") ) );
|
||||||
|
|
||||||
// remove integer file extensions (created by CVS) and init FileTypeToId (associates the form type to the form type id)
|
// remove integer file extensions (created by CVS) and init FileTypeToId (associates the form type to the form type id)
|
||||||
map<TFormId,string>::iterator itIF;
|
map<TFormId,string>::iterator itIF;
|
||||||
for( itIF = IdToForm.begin(); itIF != IdToForm.end(); )
|
for( itIF = IdToForm.begin(); itIF != IdToForm.end(); )
|
||||||
{
|
{
|
||||||
// get the file type from form name
|
// get the file type from form name
|
||||||
TFormId fid = (*itIF).first;
|
TFormId fid = (*itIF).first;
|
||||||
string fileType;
|
string fileType;
|
||||||
|
|
||||||
if((*itIF).second.empty() || (*itIF).second=="." || (*itIF).second==".." || (*itIF).second[0]=='_' || (*itIF).second.find(".#")==0)
|
if((*itIF).second.empty() || (*itIF).second=="." || (*itIF).second==".." || (*itIF).second[0]=='_' || (*itIF).second.find(".#")==0)
|
||||||
{
|
{
|
||||||
map<TFormId,string>::iterator itErase = itIF;
|
map<TFormId,string>::iterator itErase = itIF;
|
||||||
++itIF;
|
++itIF;
|
||||||
IdToForm.erase(itErase);
|
IdToForm.erase(itErase);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( getFileType( (*itIF).second, fileType ) )
|
if( getFileType( (*itIF).second, fileType ) )
|
||||||
{
|
{
|
||||||
// insert the association (file type/file type id)
|
// insert the association (file type/file type id)
|
||||||
map<string,uint8>::iterator itFT = FileTypeToId.find(fileType);
|
map<string,uint8>::iterator itFT = FileTypeToId.find(fileType);
|
||||||
if( itFT == FileTypeToId.end() )
|
if( itFT == FileTypeToId.end() )
|
||||||
{
|
{
|
||||||
FileTypeToId.insert( make_pair(fileType,fid.FormIDInfos.Type) );
|
FileTypeToId.insert( make_pair(fileType,fid.FormIDInfos.Type) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nlwarning("Unknown file type for the file : %s",(*itIF).second.c_str());
|
nlwarning("Unknown file type for the file : %s",(*itIF).second.c_str());
|
||||||
}
|
}
|
||||||
++itIF;
|
++itIF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// init FormToId (associates the form name to its id )
|
// init FormToId (associates the form name to its id )
|
||||||
for( itIF = IdToForm.begin(); itIF != IdToForm.end(); ++itIF )
|
for( itIF = IdToForm.begin(); itIF != IdToForm.end(); ++itIF )
|
||||||
{
|
{
|
||||||
FormToId.insert( make_pair((*itIF).second,(*itIF).first) );
|
FormToId.insert( make_pair((*itIF).second,(*itIF).first) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// init IdToFileType (associates the form type id to the form type name)
|
// init IdToFileType (associates the form type id to the form type name)
|
||||||
map<string,uint8>::iterator itIFT;
|
map<string,uint8>::iterator itIFT;
|
||||||
for( itIFT = FileTypeToId.begin(); itIFT != FileTypeToId.end(); ++itIFT )
|
for( itIFT = FileTypeToId.begin(); itIFT != FileTypeToId.end(); ++itIFT )
|
||||||
{
|
{
|
||||||
IdToFileType.insert( make_pair((*itIFT).second,(*itIFT).first) );
|
IdToFileType.insert( make_pair((*itIFT).second,(*itIFT).first) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// init TypeToLastId (associates the type id to the last index used for this type)
|
// init TypeToLastId (associates the type id to the last index used for this type)
|
||||||
for( itIF = IdToForm.begin(); itIF != IdToForm.end(); ++itIF )
|
for( itIF = IdToForm.begin(); itIF != IdToForm.end(); ++itIF )
|
||||||
{
|
{
|
||||||
uint8 type = (*itIF).first.FormIDInfos.Type;
|
uint8 type = (*itIF).first.FormIDInfos.Type;
|
||||||
uint32 id = (*itIF).first.FormIDInfos.Id;
|
uint32 id = (*itIF).first.FormIDInfos.Id;
|
||||||
map<uint8,uint32>::iterator itTLI = TypeToLastId.find( type );
|
map<uint8,uint32>::iterator itTLI = TypeToLastId.find( type );
|
||||||
if( itTLI != TypeToLastId.end() )
|
if( itTLI != TypeToLastId.end() )
|
||||||
{
|
{
|
||||||
if( (*itTLI).second < id )
|
if( (*itTLI).second < id )
|
||||||
{
|
{
|
||||||
(*itTLI).second = id;
|
(*itTLI).second = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TypeToLastId.insert( make_pair(type,id) );
|
TypeToLastId.insert( make_pair(type,id) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // readFormId //
|
} // readFormId //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// makeId
|
// makeId
|
||||||
//
|
//
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void makeId( list<string>& dirs )
|
void makeId( list<string>& dirs )
|
||||||
{
|
{
|
||||||
list<string>::const_iterator itDir;
|
list<string>::const_iterator itDir;
|
||||||
for( itDir = dirs.begin(); itDir != dirs.end(); ++itDir )
|
for( itDir = dirs.begin(); itDir != dirs.end(); ++itDir )
|
||||||
{
|
{
|
||||||
nlinfo ("Searching files in directory '%s'...", (*itDir).c_str());
|
nlinfo ("Searching files in directory '%s'...", (*itDir).c_str());
|
||||||
vector<string> files;
|
vector<string> files;
|
||||||
CPath::getPathContent(*itDir,true,false,true,files);
|
CPath::getPathContent(*itDir,true,false,true,files);
|
||||||
|
|
||||||
nlinfo ("Found %d files in directory '%s'", files.size(), (*itDir).c_str());
|
nlinfo ("Found %d files in directory '%s'", files.size(), (*itDir).c_str());
|
||||||
for(uint i = 0; i < files.size(); i++)
|
for(uint i = 0; i < files.size(); i++)
|
||||||
{
|
{
|
||||||
addId(CFile::getFilename(files[i]));
|
addId(CFile::getFilename(files[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // makeId //
|
} // makeId //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// addId
|
// addId
|
||||||
//
|
//
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void addId( string fileName )
|
void addId( string fileName )
|
||||||
{
|
{
|
||||||
if(fileName.empty() || fileName=="." || fileName==".." || fileName[0]=='_' || fileName.find(".#")==0)
|
if(fileName.empty() || fileName=="." || fileName==".." || fileName[0]=='_' || fileName.find(".#")==0)
|
||||||
{
|
{
|
||||||
//nlinfo("Discarding file '%s'", fileName.c_str());
|
//nlinfo("Discarding file '%s'", fileName.c_str());
|
||||||
NbFilesDiscarded++;
|
NbFilesDiscarded++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( !ExtensionsAllowed.empty() )
|
if( !ExtensionsAllowed.empty() )
|
||||||
{
|
{
|
||||||
string extStr = CFile::getExtension( fileName );
|
string extStr = CFile::getExtension( fileName );
|
||||||
if( ExtensionsAllowed.find(extStr) == ExtensionsAllowed.end() )
|
if( ExtensionsAllowed.find(extStr) == ExtensionsAllowed.end() )
|
||||||
{
|
{
|
||||||
NbFilesDiscarded++;
|
NbFilesDiscarded++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the file is new
|
// if the file is new
|
||||||
map<string,TFormId>::iterator itFI = FormToId.find( fileName );
|
map<string,TFormId>::iterator itFI = FormToId.find( fileName );
|
||||||
if( itFI == FormToId.end() )
|
if( itFI == FormToId.end() )
|
||||||
{
|
{
|
||||||
// double check : if file not found we check with lower case version of filename
|
// double check : if file not found we check with lower case version of filename
|
||||||
map<string,TFormId>::iterator itFILwr = FormToId.find( toLower(fileName) );
|
map<string,TFormId>::iterator itFILwr = FormToId.find( toLower(fileName) );
|
||||||
if( itFILwr != FormToId.end() )
|
if( itFILwr != FormToId.end() )
|
||||||
{
|
{
|
||||||
nlwarning("Trying to add %s but the file %s is already known ! becareful with lower case and upper case.", fileName.c_str(), toLower(fileName).c_str());
|
nlwarning("Trying to add %s but the file %s is already known ! becareful with lower case and upper case.", fileName.c_str(), toLower(fileName).c_str());
|
||||||
NbFilesDiscarded++;
|
NbFilesDiscarded++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string fileType;
|
string fileType;
|
||||||
if( getFileType( fileName, fileType ) )
|
if( getFileType( fileName, fileType ) )
|
||||||
{
|
{
|
||||||
map<string,uint8>::iterator itFTI = FileTypeToId.find( fileType );
|
map<string,uint8>::iterator itFTI = FileTypeToId.find( fileType );
|
||||||
TFormId fid;
|
TFormId fid;
|
||||||
|
|
||||||
// if the type of this file is a new type
|
// if the type of this file is a new type
|
||||||
if( itFTI == FileTypeToId.end() )
|
if( itFTI == FileTypeToId.end() )
|
||||||
{
|
{
|
||||||
sint16 firstFreeFileTypeId = getFirstFreeFileTypeId();
|
sint16 firstFreeFileTypeId = getFirstFreeFileTypeId();
|
||||||
if( firstFreeFileTypeId == -1 )
|
if( firstFreeFileTypeId == -1 )
|
||||||
{
|
{
|
||||||
nlwarning("MORE THAN 256 FILE TYPES!!!!");
|
nlwarning("MORE THAN 256 FILE TYPES!!!!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FileTypeToId.insert( make_pair(fileType,(uint8)firstFreeFileTypeId) );
|
FileTypeToId.insert( make_pair(fileType,(uint8)firstFreeFileTypeId) );
|
||||||
IdToFileType.insert( make_pair((uint8)firstFreeFileTypeId,fileType) );
|
IdToFileType.insert( make_pair((uint8)firstFreeFileTypeId,fileType) );
|
||||||
TypeToLastId.insert( make_pair((uint8)firstFreeFileTypeId,0) );
|
TypeToLastId.insert( make_pair((uint8)firstFreeFileTypeId,0) );
|
||||||
|
|
||||||
fid.FormIDInfos.Type = (uint8)firstFreeFileTypeId;
|
fid.FormIDInfos.Type = (uint8)firstFreeFileTypeId;
|
||||||
fid.FormIDInfos.Id = 0;
|
fid.FormIDInfos.Id = 0;
|
||||||
|
|
||||||
nlinfo("Adding file type '%s' with id %d", fileType.c_str(), firstFreeFileTypeId);
|
nlinfo("Adding file type '%s' with id %d", fileType.c_str(), firstFreeFileTypeId);
|
||||||
NbTypesAdded++;
|
NbTypesAdded++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else the file type already exist
|
// else the file type already exist
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// id of the file type
|
// id of the file type
|
||||||
uint8 fileTypeId = (*itFTI).second;
|
uint8 fileTypeId = (*itFTI).second;
|
||||||
|
|
||||||
// last id used for this file type
|
// last id used for this file type
|
||||||
map<uint8,uint32>::iterator itTLI = TypeToLastId.find(fileTypeId);
|
map<uint8,uint32>::iterator itTLI = TypeToLastId.find(fileTypeId);
|
||||||
nlassert(itTLI != TypeToLastId.end());
|
nlassert(itTLI != TypeToLastId.end());
|
||||||
(*itTLI).second++;
|
(*itTLI).second++;
|
||||||
|
|
||||||
// add the new association
|
// add the new association
|
||||||
fid.FormIDInfos.Type = fileTypeId;
|
fid.FormIDInfos.Type = fileTypeId;
|
||||||
fid.FormIDInfos.Id = (*itTLI).second;
|
fid.FormIDInfos.Id = (*itTLI).second;
|
||||||
}
|
}
|
||||||
FormToId.insert( make_pair(fileName,fid) );
|
FormToId.insert( make_pair(fileName,fid) );
|
||||||
IdToForm.insert( make_pair(fid,fileName) );
|
IdToForm.insert( make_pair(fid,fileName) );
|
||||||
nlinfo("Adding file '%s' id %d with type '%s' id %d", fileName.c_str(), fid.FormIDInfos.Id, fileType.c_str(), fid.FormIDInfos.Type);
|
nlinfo("Adding file '%s' id %d with type '%s' id %d", fileName.c_str(), fid.FormIDInfos.Id, fileType.c_str(), fid.FormIDInfos.Type);
|
||||||
NbFilesAdded++;
|
NbFilesAdded++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//nlinfo("Unknown file type for the file : '%s' --> not added",fileName.c_str());
|
//nlinfo("Unknown file type for the file : '%s' --> not added",fileName.c_str());
|
||||||
NbFilesUnknownType++;
|
NbFilesUnknownType++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//nlinfo("Skipping file '%s', already in the file", fileName.c_str());
|
//nlinfo("Skipping file '%s', already in the file", fileName.c_str());
|
||||||
NbFilesAlreadyAdded++;
|
NbFilesAlreadyAdded++;
|
||||||
}
|
}
|
||||||
} // addId //
|
} // addId //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// getFileType
|
// getFileType
|
||||||
//
|
//
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
bool getFileType( string& fileName, string& fileType )
|
bool getFileType( string& fileName, string& fileType )
|
||||||
{
|
{
|
||||||
fileType = CFile::getExtension(CFile::getFilename(fileName));
|
fileType = CFile::getExtension(CFile::getFilename(fileName));
|
||||||
return !fileType.empty();
|
return !fileType.empty();
|
||||||
|
|
||||||
} // getFileType //
|
} // getFileType //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// display
|
// display
|
||||||
//
|
//
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void display()
|
void display()
|
||||||
{
|
{
|
||||||
nldebug ("Output :");
|
nldebug ("Output :");
|
||||||
map<TFormId,string>::iterator it1;
|
map<TFormId,string>::iterator it1;
|
||||||
for( it1 = IdToForm.begin(); it1 != IdToForm.end(); ++it1 )
|
for( it1 = IdToForm.begin(); it1 != IdToForm.end(); ++it1 )
|
||||||
{
|
{
|
||||||
nldebug("type: %d id: %d file: %s", (*it1).first.FormIDInfos.Type, (*it1).first.FormIDInfos.Id, (*it1).second.c_str());
|
nldebug("type: %d id: %d file: %s", (*it1).first.FormIDInfos.Type, (*it1).first.FormIDInfos.Id, (*it1).second.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // display //
|
} // display //
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "sheetbuilderconfgdialog.h"
|
#include "sheetbuilderconfgdialog.h"
|
||||||
|
#include "../core/icore.h"
|
||||||
|
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
@ -25,187 +26,196 @@
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
|
||||||
SheetBuilderConfigDialog::SheetBuilderConfigDialog(QWidget *parent) :
|
SheetBuilderConfigDialog::SheetBuilderConfigDialog(QWidget *parent)
|
||||||
QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Paths
|
* Paths
|
||||||
*/
|
*/
|
||||||
QLabel *lblPaths = new QLabel(tr("Paths:"));
|
QLabel *lblPaths = new QLabel(tr("Paths:"));
|
||||||
lstPaths = new QListWidget;
|
lstPaths = new QListWidget;
|
||||||
lstPaths->addItem("");
|
lstPaths->addItem("");
|
||||||
|
|
||||||
QPushButton *btnAddPath = new QPushButton(tr("Add"));
|
QPushButton *btnAddPath = new QPushButton(tr("Add"));
|
||||||
connect(btnAddPath, SIGNAL(clicked()), SLOT(addPath()));
|
connect(btnAddPath, SIGNAL(clicked()), SLOT(addPath()));
|
||||||
QPushButton *btnDeletePath = new QPushButton(tr("Delete"));
|
QPushButton *btnDeletePath = new QPushButton(tr("Delete"));
|
||||||
connect(btnDeletePath, SIGNAL(clicked()), SLOT(deletePath()));
|
connect(btnDeletePath, SIGNAL(clicked()), SLOT(deletePath()));
|
||||||
|
|
||||||
QVBoxLayout *ltButtonsPaths = new QVBoxLayout();
|
QVBoxLayout *ltButtonsPaths = new QVBoxLayout();
|
||||||
ltButtonsPaths->addWidget(btnAddPath);
|
ltButtonsPaths->addWidget(btnAddPath);
|
||||||
ltButtonsPaths->addWidget(btnDeletePath);
|
ltButtonsPaths->addWidget(btnDeletePath);
|
||||||
ltButtonsPaths->addStretch(1);
|
ltButtonsPaths->addStretch(1);
|
||||||
|
|
||||||
QHBoxLayout *ltPaths = new QHBoxLayout;
|
QHBoxLayout *ltPaths = new QHBoxLayout;
|
||||||
ltPaths->addWidget(lstPaths);
|
ltPaths->addWidget(lstPaths);
|
||||||
ltPaths->addLayout(ltButtonsPaths);
|
ltPaths->addLayout(ltButtonsPaths);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output file
|
* Output file
|
||||||
*/
|
*/
|
||||||
QLabel *lblOutputFile = new QLabel(tr("Output file:"));
|
QLabel *lblOutputFile = new QLabel(tr("Output file:"));
|
||||||
txtOutputFile = new QLineEdit();
|
txtOutputFile = new QLineEdit();
|
||||||
QPushButton *btnBrowse = new QPushButton(tr("Browse..."));
|
QPushButton *btnBrowse = new QPushButton(tr("Browse..."));
|
||||||
connect(btnBrowse, SIGNAL(clicked()), SLOT(browseOutput()));
|
connect(btnBrowse, SIGNAL(clicked()), SLOT(browseOutput()));
|
||||||
|
|
||||||
QHBoxLayout *ltOutput = new QHBoxLayout();
|
QHBoxLayout *ltOutput = new QHBoxLayout();
|
||||||
ltOutput->addWidget(txtOutputFile);
|
ltOutput->addWidget(txtOutputFile);
|
||||||
ltOutput->addWidget(btnBrowse);
|
ltOutput->addWidget(btnBrowse);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extensions
|
* Extensions
|
||||||
*/
|
*/
|
||||||
QLabel *lblExtensions = new QLabel(tr("Allowed extensions:"));
|
QLabel *lblExtensions = new QLabel(tr("Allowed extensions:"));
|
||||||
lstExtensionsAllowed = new QListWidget();
|
lstExtensionsAllowed = new QListWidget();
|
||||||
|
|
||||||
QPushButton *btnAddExtension = new QPushButton(tr("Add"));
|
QPushButton *btnAddExtension = new QPushButton(tr("Add"));
|
||||||
connect(btnAddExtension, SIGNAL(clicked()), SLOT(addExtension()));
|
connect(btnAddExtension, SIGNAL(clicked()), SLOT(addExtension()));
|
||||||
QPushButton *btnDeleteExtension = new QPushButton(tr("Delete"));
|
QPushButton *btnDeleteExtension = new QPushButton(tr("Delete"));
|
||||||
connect(btnDeleteExtension, SIGNAL(clicked()), SLOT(deleteExtension()));
|
connect(btnDeleteExtension, SIGNAL(clicked()), SLOT(deleteExtension()));
|
||||||
|
|
||||||
QVBoxLayout *ltButtonsExtensions = new QVBoxLayout();
|
QVBoxLayout *ltButtonsExtensions = new QVBoxLayout();
|
||||||
ltButtonsExtensions->addWidget(btnAddExtension);
|
ltButtonsExtensions->addWidget(btnAddExtension);
|
||||||
ltButtonsExtensions->addWidget(btnDeleteExtension);
|
ltButtonsExtensions->addWidget(btnDeleteExtension);
|
||||||
ltButtonsExtensions->addStretch(1);
|
ltButtonsExtensions->addStretch(1);
|
||||||
|
|
||||||
QHBoxLayout *ltExtensions = new QHBoxLayout();
|
QHBoxLayout *ltExtensions = new QHBoxLayout();
|
||||||
ltExtensions->addWidget(lstExtensionsAllowed);
|
ltExtensions->addWidget(lstExtensionsAllowed);
|
||||||
ltExtensions->addLayout(ltButtonsExtensions);
|
ltExtensions->addLayout(ltButtonsExtensions);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Buttons
|
* Buttons
|
||||||
*/
|
*/
|
||||||
QPushButton *btnOk = new QPushButton(tr("OK"));
|
QPushButton *btnOk = new QPushButton(tr("OK"));
|
||||||
connect(btnOk, SIGNAL(clicked()), SLOT(accept()));
|
connect(btnOk, SIGNAL(clicked()), SLOT(accept()));
|
||||||
connect(btnOk, SIGNAL(clicked()), SLOT(writeSettings()));
|
connect(btnOk, SIGNAL(clicked()), SLOT(writeSettings()));
|
||||||
|
|
||||||
QPushButton *btnCancel = new QPushButton(tr("Cancel"));
|
QPushButton *btnCancel = new QPushButton(tr("Cancel"));
|
||||||
connect(btnCancel, SIGNAL(clicked()), SLOT(reject()));
|
connect(btnCancel, SIGNAL(clicked()), SLOT(reject()));
|
||||||
|
|
||||||
QHBoxLayout *ltButtons = new QHBoxLayout;
|
QHBoxLayout *ltButtons = new QHBoxLayout;
|
||||||
ltButtons->addStretch(1);
|
ltButtons->addStretch(1);
|
||||||
ltButtons->addWidget(btnOk);
|
ltButtons->addWidget(btnOk);
|
||||||
ltButtons->addWidget(btnCancel);
|
ltButtons->addWidget(btnCancel);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main layout
|
* Main layout
|
||||||
*/
|
*/
|
||||||
QVBoxLayout *ltMain = new QVBoxLayout;
|
QVBoxLayout *ltMain = new QVBoxLayout;
|
||||||
ltMain->addWidget(lblPaths);
|
ltMain->addWidget(lblPaths);
|
||||||
ltMain->addLayout(ltPaths);
|
ltMain->addLayout(ltPaths);
|
||||||
ltMain->addWidget(lblOutputFile);
|
ltMain->addWidget(lblOutputFile);
|
||||||
ltMain->addLayout(ltOutput);
|
ltMain->addLayout(ltOutput);
|
||||||
ltMain->addWidget(lblExtensions);
|
ltMain->addWidget(lblExtensions);
|
||||||
ltMain->addLayout(ltExtensions);
|
ltMain->addLayout(ltExtensions);
|
||||||
ltMain->addLayout(ltButtons);
|
ltMain->addLayout(ltButtons);
|
||||||
|
|
||||||
setLayout(ltMain);
|
setLayout(ltMain);
|
||||||
setWindowTitle(tr("Sheet builder configuration"));
|
setWindowTitle(tr("Sheet builder configuration"));
|
||||||
resize(500, 450);
|
resize(500, 450);
|
||||||
readSettings();
|
readSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderConfigDialog::addPath()
|
void SheetBuilderConfigDialog::addPath()
|
||||||
{
|
{
|
||||||
QString path =
|
QString path =
|
||||||
QFileDialog::getExistingDirectory(this, "Choose path");
|
QFileDialog::getExistingDirectory(this, tr("Choose path"));
|
||||||
if (!path.isEmpty()) {
|
if (!path.isEmpty())
|
||||||
QListWidgetItem *newItem = new QListWidgetItem;
|
{
|
||||||
newItem->setText(path);
|
QListWidgetItem *newItem = new QListWidgetItem;
|
||||||
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
newItem->setText(path);
|
||||||
lstPaths->addItem(newItem);
|
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
lstPaths->setCurrentItem(newItem);
|
lstPaths->addItem(newItem);
|
||||||
}
|
lstPaths->setCurrentItem(newItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderConfigDialog::addExtension()
|
void SheetBuilderConfigDialog::addExtension()
|
||||||
{
|
{
|
||||||
QListWidgetItem *newItem = new QListWidgetItem;
|
QListWidgetItem *newItem = new QListWidgetItem;
|
||||||
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
lstExtensionsAllowed->addItem(newItem);
|
lstExtensionsAllowed->addItem(newItem);
|
||||||
lstExtensionsAllowed->setCurrentItem(newItem);
|
lstExtensionsAllowed->setCurrentItem(newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderConfigDialog::deletePath()
|
void SheetBuilderConfigDialog::deletePath()
|
||||||
{
|
{
|
||||||
QListWidgetItem *removeItem = lstPaths->takeItem(lstPaths->currentRow());
|
QListWidgetItem *removeItem = lstPaths->takeItem(lstPaths->currentRow());
|
||||||
if (!removeItem)
|
if (!removeItem)
|
||||||
delete removeItem;
|
delete removeItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderConfigDialog::deleteExtension()
|
void SheetBuilderConfigDialog::deleteExtension()
|
||||||
{
|
{
|
||||||
QListWidgetItem *removeItem
|
QListWidgetItem *removeItem
|
||||||
= lstExtensionsAllowed->takeItem(lstExtensionsAllowed->currentRow());
|
= lstExtensionsAllowed->takeItem(lstExtensionsAllowed->currentRow());
|
||||||
if (!removeItem)
|
if (!removeItem)
|
||||||
delete removeItem;
|
delete removeItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderConfigDialog::browseOutput()
|
void SheetBuilderConfigDialog::browseOutput()
|
||||||
{
|
{
|
||||||
QString fileName =
|
QString fileName =
|
||||||
QFileDialog::getSaveFileName(this,tr("Choose output file"), "");
|
QFileDialog::getSaveFileName(this, tr("Choose output file"), "");
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
txtOutputFile->setText(fileName);
|
txtOutputFile->setText(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderConfigDialog::readSettings()
|
void SheetBuilderConfigDialog::readSettings()
|
||||||
{
|
{
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
QString outputFile;
|
QString outputFile;
|
||||||
QStringList extensions;
|
QStringList extensions;
|
||||||
|
|
||||||
QSettings settings("ovqt_sheet_builder.ini", QSettings::IniFormat);
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
|
settings->beginGroup("SheetBuilder");
|
||||||
|
paths = settings->value("SheetPaths").toStringList();
|
||||||
|
outputFile = settings->value("SheetOutputFile").toString();
|
||||||
|
extensions = settings->value("ExtensionsAllowed").toStringList();
|
||||||
|
settings->endGroup();
|
||||||
|
|
||||||
paths = settings.value("SheetPaths").toStringList();
|
lstPaths->clear();
|
||||||
outputFile = settings.value("SheetOutputFile").toString();
|
lstExtensionsAllowed->clear();
|
||||||
extensions = settings.value("ExtensionsAllowed").toStringList();
|
|
||||||
|
|
||||||
lstPaths->clear();
|
QListWidgetItem *newItem;
|
||||||
lstExtensionsAllowed->clear();
|
|
||||||
|
|
||||||
QListWidgetItem *newItem;
|
Q_FOREACH (QString path, paths)
|
||||||
|
{
|
||||||
|
newItem = new QListWidgetItem;
|
||||||
|
newItem->setText(path);
|
||||||
|
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
|
lstPaths->addItem(newItem);
|
||||||
|
}
|
||||||
|
|
||||||
Q_FOREACH (QString path, paths) {
|
txtOutputFile->setText(outputFile);
|
||||||
newItem = new QListWidgetItem;
|
|
||||||
newItem->setText(path);
|
|
||||||
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
||||||
lstPaths->addItem(newItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
txtOutputFile->setText(outputFile);
|
Q_FOREACH (QString extension, extensions)
|
||||||
|
{
|
||||||
Q_FOREACH (QString extension, extensions) {
|
newItem = new QListWidgetItem;
|
||||||
newItem = new QListWidgetItem;
|
newItem->setText(extension);
|
||||||
newItem->setText(extension);
|
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
lstExtensionsAllowed->addItem(newItem);
|
||||||
lstExtensionsAllowed->addItem(newItem);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderConfigDialog::writeSettings()
|
void SheetBuilderConfigDialog::writeSettings()
|
||||||
{
|
{
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
for (int i = 0; i < lstPaths->count(); i++)
|
for (int i = 0; i < lstPaths->count(); i++)
|
||||||
paths.push_back(lstPaths->item(i)->text());
|
paths.push_back(lstPaths->item(i)->text());
|
||||||
|
|
||||||
QString outputFile = txtOutputFile->text();
|
QString outputFile = txtOutputFile->text();
|
||||||
|
|
||||||
QStringList extensions;
|
QStringList extensions;
|
||||||
for (int i = 0; i < lstExtensionsAllowed->count(); i++)
|
for (int i = 0; i < lstExtensionsAllowed->count(); i++)
|
||||||
extensions.push_back(lstExtensionsAllowed->item(i)->text());
|
extensions.push_back(lstExtensionsAllowed->item(i)->text());
|
||||||
|
|
||||||
QSettings settings("./ovqt_sheet_builder.ini", QSettings::IniFormat);
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
settings.setValue("SheetPaths", paths);
|
settings->beginGroup("SheetBuilder");
|
||||||
settings.setValue("SheetOutputFile", outputFile);
|
settings->setValue("SheetPaths", paths);
|
||||||
settings.setValue("ExtensionsAllowed", extensions);
|
settings->setValue("SheetOutputFile", outputFile);
|
||||||
|
settings->setValue("ExtensionsAllowed", extensions);
|
||||||
|
settings->endGroup();
|
||||||
|
|
||||||
|
// Forced save settings
|
||||||
|
settings->sync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,23 +24,23 @@ class QLineEdit;
|
||||||
|
|
||||||
class SheetBuilderConfigDialog : public QDialog
|
class SheetBuilderConfigDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SheetBuilderConfigDialog(QWidget *parent = 0);
|
explicit SheetBuilderConfigDialog(QWidget *parent = 0);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void addPath();
|
void addPath();
|
||||||
void addExtension();
|
void addExtension();
|
||||||
void deletePath();
|
void deletePath();
|
||||||
void deleteExtension();
|
void deleteExtension();
|
||||||
void browseOutput();
|
void browseOutput();
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QListWidget *lstPaths;
|
QListWidget *lstPaths;
|
||||||
QListWidget *lstExtensionsAllowed;
|
QListWidget *lstExtensionsAllowed;
|
||||||
QLineEdit *txtOutputFile;
|
QLineEdit *txtOutputFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHEETBUILDERCONFGDIALOG_H
|
#endif // SHEETBUILDERCONFGDIALOG_H
|
||||||
|
|
|
@ -15,6 +15,11 @@
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "sheetbuilderdialog.h"
|
#include "sheetbuilderdialog.h"
|
||||||
|
#include "sheetbuilder.h"
|
||||||
|
#include "sheetbuilderconfgdialog.h"
|
||||||
|
#include "../core/icore.h"
|
||||||
|
#include "../core/core_constants.h"
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
|
@ -23,190 +28,185 @@
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "sheetbuilder.h"
|
SheetBuilderDialog::SheetBuilderDialog(QWidget *parent)
|
||||||
#include "sheetbuilderconfgdialog.h"
|
: QDialog(parent)
|
||||||
|
|
||||||
SheetBuilderDialog::SheetBuilderDialog(QWidget *parent) :
|
|
||||||
QDialog(parent)
|
|
||||||
{
|
{
|
||||||
|
QPushButton *btnOk = new QPushButton(tr("Make sheet"));
|
||||||
|
connect(btnOk, SIGNAL(clicked()), SLOT(buildSheet()));
|
||||||
|
|
||||||
QPushButton *btnOk = new QPushButton(tr("Make sheet"));
|
QPushButton *btnCancel = new QPushButton(tr("Close"));
|
||||||
connect(btnOk, SIGNAL(clicked()), SLOT(buildSheet()));
|
connect(btnCancel, SIGNAL(clicked()), SLOT(reject()));
|
||||||
|
|
||||||
QPushButton *btnCancel = new QPushButton(tr("Close"));
|
chckClean = new QCheckBox(tr("Clean unwanted types from input"));
|
||||||
connect(btnCancel, SIGNAL(clicked()), SLOT(reject()));
|
|
||||||
|
|
||||||
chckClean = new QCheckBox(tr("Clean unwanted types from input"));
|
txtOutput = new QTextEdit;
|
||||||
|
txtOutput->setMinimumHeight(300);
|
||||||
|
txtOutput->setMinimumWidth(500);
|
||||||
|
txtOutput->setReadOnly(true);
|
||||||
|
txtOutput->setFontFamily("Monospace, Courier New, monospace");
|
||||||
|
|
||||||
txtOutput = new QTextEdit;
|
QPushButton *btnDetails = new QPushButton(tr("Show/Hide details..."));
|
||||||
txtOutput->setMinimumHeight(300);
|
connect(btnDetails, SIGNAL(clicked()), SLOT(detailsShowHide()));
|
||||||
txtOutput->setMinimumWidth(500);
|
|
||||||
txtOutput->setReadOnly(true);
|
|
||||||
txtOutput->setFontFamily("Monospace, Courier New, monospace");
|
|
||||||
|
|
||||||
QPushButton *btnDetails = new QPushButton(tr("Show/Hide details..."));
|
QPushButton *btnConfig = new QPushButton(tr("Settings"));
|
||||||
connect(btnDetails, SIGNAL(clicked()), SLOT(detailsShowHide()));
|
connect(btnConfig, SIGNAL(clicked()), SLOT(showConfig()));
|
||||||
|
|
||||||
QPushButton *btnConfig = new QPushButton(tr("Settings"));
|
QHBoxLayout *ltButtons = new QHBoxLayout;
|
||||||
connect(btnConfig, SIGNAL(clicked()), SLOT(showConfig()));
|
ltButtons->addWidget(btnConfig);
|
||||||
|
ltButtons->addWidget(btnDetails);
|
||||||
|
ltButtons->addStretch(1);
|
||||||
|
ltButtons->addWidget(btnOk);
|
||||||
|
ltButtons->addWidget(btnCancel);
|
||||||
|
|
||||||
QHBoxLayout *ltButtons = new QHBoxLayout;
|
QVBoxLayout *ltMain = new QVBoxLayout;
|
||||||
ltButtons->addWidget(btnConfig);
|
ltMain->addWidget(chckClean);
|
||||||
ltButtons->addWidget(btnDetails);
|
ltMain->addWidget(txtOutput, 1);
|
||||||
ltButtons->addStretch(1);
|
ltMain->addLayout(ltButtons);
|
||||||
ltButtons->addWidget(btnOk);
|
ltMain->addStretch();
|
||||||
ltButtons->addWidget(btnCancel);
|
|
||||||
|
|
||||||
QVBoxLayout *ltMain = new QVBoxLayout;
|
txtOutput->hide();
|
||||||
ltMain->addWidget(chckClean);
|
detailsVisible = false;
|
||||||
ltMain->addWidget(txtOutput, 1);
|
|
||||||
ltMain->addLayout(ltButtons);
|
|
||||||
ltMain->addStretch();
|
|
||||||
|
|
||||||
txtOutput->hide();
|
setLayout(ltMain);
|
||||||
detailsVisible = false;
|
defHeight = height();
|
||||||
|
defWidth = 500;
|
||||||
setLayout(ltMain);
|
resize(defWidth, defHeight);
|
||||||
defHeight = height();
|
setWindowTitle(tr("Sheet builder"));
|
||||||
defWidth = 500;
|
|
||||||
resize(defWidth, defHeight);
|
|
||||||
setWindowTitle(tr("Sheet builder"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderDialog::showConfig()
|
void SheetBuilderDialog::showConfig()
|
||||||
{
|
{
|
||||||
SheetBuilderConfigDialog dlg(this);
|
SheetBuilderConfigDialog dlg(this);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderDialog::detailsShowHide()
|
void SheetBuilderDialog::detailsShowHide()
|
||||||
{
|
{
|
||||||
if (!detailsVisible) {
|
if (!detailsVisible)
|
||||||
defHeight = height();
|
{
|
||||||
defWidth = width();
|
defHeight = height();
|
||||||
}
|
defWidth = width();
|
||||||
|
}
|
||||||
|
|
||||||
detailsVisible = !detailsVisible;
|
detailsVisible = !detailsVisible;
|
||||||
txtOutput->setVisible(detailsVisible);
|
txtOutput->setVisible(detailsVisible);
|
||||||
|
|
||||||
if (!detailsVisible) {
|
if (!detailsVisible)
|
||||||
adjustSize();
|
{
|
||||||
resize(defWidth, defHeight);
|
adjustSize();
|
||||||
}
|
resize(defWidth, defHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderDialog::displayInfo(QString str)
|
void SheetBuilderDialog::displayInfo(QString str)
|
||||||
{
|
{
|
||||||
txtOutput->append(str);
|
txtOutput->append(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetBuilderDialog::buildSheet()
|
void SheetBuilderDialog::buildSheet()
|
||||||
{
|
{
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
QString outputFile;
|
QString outputFile;
|
||||||
QStringList extensions;
|
QStringList extensions;
|
||||||
|
|
||||||
QSettings settings("ovqt_sheet_builder.ini", QSettings::IniFormat);
|
// read settings
|
||||||
paths = settings.value("SheetPaths").toStringList();
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
outputFile = settings.value("SheetOutputFile").toString();
|
settings->beginGroup("SheetBuilder");
|
||||||
extensions = settings.value("ExtensionsAllowed").toStringList();
|
paths = settings->value("SheetPaths").toStringList();
|
||||||
|
outputFile = settings->value("SheetOutputFile").toString();
|
||||||
|
extensions = settings->value("ExtensionsAllowed").toStringList();
|
||||||
|
settings->endGroup();
|
||||||
|
|
||||||
bool clean = chckClean->isChecked();
|
bool clean = chckClean->isChecked();
|
||||||
string configFileName("ovqt_sheet_builder.ini");
|
|
||||||
string outputFileName(outputFile.toStdString());
|
|
||||||
|
|
||||||
if (outputFileName.empty()) {
|
string outputFileName(outputFile.toStdString());
|
||||||
displayInfo("Error: Output file is not specified");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
list<string> inputDirs;
|
if (outputFileName.empty())
|
||||||
Q_FOREACH (QString str, paths)
|
{
|
||||||
inputDirs.push_back(str.toStdString());
|
displayInfo("Error: Output file is not specified");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// load the config files
|
list<string> inputDirs;
|
||||||
CConfigFile configFile;
|
Q_FOREACH (QString str, paths)
|
||||||
if(!CFile::fileExists(configFileName))
|
inputDirs.push_back(str.toStdString());
|
||||||
{
|
|
||||||
displayInfo(QString("Config file '%1' not found, working whithout filter").arg(configFileName.c_str()) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Q_FOREACH (QString str, extensions) {
|
|
||||||
ExtensionsAllowed.insert(str.toStdString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the current associations (read the sheet_id and fill the working structures)
|
Q_FOREACH (QString str, extensions)
|
||||||
readFormId( outputFileName );
|
{
|
||||||
|
ExtensionsAllowed.insert(str.toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
// output path
|
// get the current associations (read the sheet_id and fill the working structures)
|
||||||
sint lastSeparator = CFile::getLastSeparator(outputFileName);
|
readFormId( outputFileName );
|
||||||
string outputPath;
|
|
||||||
if( lastSeparator != -1 )
|
|
||||||
{
|
|
||||||
outputPath = outputFileName.substr(0,lastSeparator+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// erase the unwanted extensions from map (modify the map, save it, and quit)
|
// output path
|
||||||
if( clean )
|
sint lastSeparator = CFile::getLastSeparator(outputFileName);
|
||||||
{
|
string outputPath;
|
||||||
if( ExtensionsAllowed.empty() )
|
if( lastSeparator != -1 )
|
||||||
displayInfo("None extension list provided, the input will not be cleaned");
|
{
|
||||||
else
|
outputPath = outputFileName.substr(0,lastSeparator+1);
|
||||||
{
|
}
|
||||||
map<TFormId,string>::iterator itSheets;
|
|
||||||
for( itSheets = IdToForm.begin(); itSheets != IdToForm.end(); )
|
|
||||||
{
|
|
||||||
string extStr = CFile::getExtension( (*itSheets).second );
|
|
||||||
if( !extStr.empty() )
|
|
||||||
{
|
|
||||||
if( ExtensionsAllowed.find(extStr) == ExtensionsAllowed.end() )
|
|
||||||
{
|
|
||||||
map<TFormId,string>::iterator itDel = itSheets++;
|
|
||||||
IdToForm.erase( itDel );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
++itSheets;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
COFile f( outputFileName );
|
|
||||||
f.serialCont( IdToForm );
|
|
||||||
}
|
|
||||||
displayInfo("The file has been cleaned");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make the ids
|
// erase the unwanted extensions from map (modify the map, save it, and quit)
|
||||||
makeId( inputDirs );
|
if( clean )
|
||||||
|
{
|
||||||
|
if( ExtensionsAllowed.empty() )
|
||||||
|
displayInfo(tr("None extension list provided, the input will not be cleaned"));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
map<TFormId,string>::iterator itSheets;
|
||||||
|
for( itSheets = IdToForm.begin(); itSheets != IdToForm.end(); )
|
||||||
|
{
|
||||||
|
string extStr = CFile::getExtension( (*itSheets).second );
|
||||||
|
if( !extStr.empty() )
|
||||||
|
{
|
||||||
|
if( ExtensionsAllowed.find(extStr) == ExtensionsAllowed.end() )
|
||||||
|
{
|
||||||
|
map<TFormId,string>::iterator itDel = itSheets++;
|
||||||
|
IdToForm.erase( itDel );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++itSheets;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
COFile f( outputFileName );
|
||||||
|
f.serialCont( IdToForm );
|
||||||
|
}
|
||||||
|
displayInfo("The file has been cleaned");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCursor(Qt::WaitCursor);
|
||||||
|
// make the ids
|
||||||
|
makeId( inputDirs );
|
||||||
|
setCursor(Qt::ArrowCursor);
|
||||||
|
|
||||||
// save the new map
|
// save the new map
|
||||||
COFile f( outputFileName );
|
COFile f( outputFileName );
|
||||||
f.serialCont( IdToForm );
|
f.serialCont( IdToForm );
|
||||||
|
|
||||||
string sheetListFileName = outputPath + "sheets.txt";
|
string sheetListFileName = outputPath + "sheets.txt";
|
||||||
COFile output;
|
COFile output;
|
||||||
if( !output.open(sheetListFileName,false,true) )
|
if( !output.open(sheetListFileName,false,true) )
|
||||||
{
|
{
|
||||||
displayInfo(QString("Can't open output file %1").arg(sheetListFileName.c_str()));
|
displayInfo(tr("Can't open output file %1").arg(sheetListFileName.c_str()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
map<TFormId,string>::iterator it1;
|
map<TFormId,string>::iterator it1;
|
||||||
for( it1 = IdToForm.begin(); it1 != IdToForm.end(); ++it1 )
|
for( it1 = IdToForm.begin(); it1 != IdToForm.end(); ++it1 )
|
||||||
{
|
{
|
||||||
string outputLine = " id: " + toString((*it1).first.Id) + " file: " + (*it1).second +"\n";
|
string outputLine = " id: " + toString((*it1).first.Id) + " file: " + (*it1).second +"\n";
|
||||||
output.serialBuffer((uint8*)(const_cast<char*>(outputLine.data())),(uint)outputLine.size());
|
output.serialBuffer((uint8*)(const_cast<char*>(outputLine.data())),(uint)outputLine.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
displayInfo ("------------- results ----------------");
|
displayInfo (tr("------------- results ----------------"));
|
||||||
displayInfo (QString("%1 files added in '%2'").arg(NbFilesAdded).arg(outputFileName.c_str()));
|
displayInfo (tr("%1 files added in '%2'").arg(NbFilesAdded).arg(outputFileName.c_str()));
|
||||||
displayInfo (QString("%1 files discarded because they are empty, begin with .# _ and so on").arg(NbFilesDiscarded));
|
displayInfo (tr("%1 files discarded because they are empty, begin with .# _ and so on").arg(NbFilesDiscarded));
|
||||||
displayInfo (QString("%1 files skipped because don't have extension").arg(NbFilesUnknownType));
|
displayInfo (tr("%1 files skipped because don't have extension").arg(NbFilesUnknownType));
|
||||||
displayInfo (QString("%1 types added in '%1'").arg(NbTypesAdded).arg(outputFileName.c_str()));
|
displayInfo (tr("%1 types added in '%1'").arg(NbTypesAdded).arg(outputFileName.c_str()));
|
||||||
|
|
||||||
displayInfo (QString("%1 supported file types :").arg(FileTypeToId.size()));
|
displayInfo (tr("%1 supported file types :").arg(FileTypeToId.size()));
|
||||||
for ( map<string,uint8>::iterator it = FileTypeToId.begin(); it != FileTypeToId.end(); ++it )
|
for ( map<string,uint8>::iterator it = FileTypeToId.begin(); it != FileTypeToId.end(); ++it )
|
||||||
{
|
{
|
||||||
displayInfo(QString("%1").arg((*it).first.c_str()));
|
displayInfo(QString("%1").arg((*it).first.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,24 +24,24 @@ class QTextEdit;
|
||||||
|
|
||||||
class SheetBuilderDialog : public QDialog
|
class SheetBuilderDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SheetBuilderDialog(QWidget *parent = 0);
|
explicit SheetBuilderDialog(QWidget *parent = 0);
|
||||||
~SheetBuilderDialog() {}
|
~SheetBuilderDialog() {}
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void buildSheet();
|
void buildSheet();
|
||||||
void detailsShowHide();
|
void detailsShowHide();
|
||||||
void showConfig();
|
void showConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void displayInfo(QString str);
|
void displayInfo(QString str);
|
||||||
|
|
||||||
int defHeight;
|
int defHeight;
|
||||||
int defWidth;
|
int defWidth;
|
||||||
bool detailsVisible;
|
bool detailsVisible;
|
||||||
QCheckBox *chckClean;
|
QCheckBox *chckClean;
|
||||||
QTextEdit *txtOutput;
|
QTextEdit *txtOutput;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHEETBUILDERDIALOG_H
|
#endif // SHEETBUILDERDIALOG_H
|
||||||
|
|
Loading…
Reference in a new issue