Commit 58ad738f authored by Jan Möbius's avatar Jan Möbius

Extended ini interface and load settings dialog

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4583 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4cfd50a1
......@@ -419,7 +419,7 @@ Core::init() {
}
// Load global ini files. Use plugin and global options from these files
openIniFile( optionFiles[i] ,true,true);
openIniFile( optionFiles[i] ,true,true,false);
}
......
......@@ -180,6 +180,9 @@ signals:
/// This signal is used to tell the plugins to load their new status
void iniLoadOptions( INIFile& _ini );
/// This signal is used to tell the plugins to load their new status after objects are loaded
void iniLoadOptionsLast( INIFile& _ini );
/// Tell plugins to create a backup
void createBackup( int _id , QString _name , int nextBackupId_);
......@@ -451,11 +454,15 @@ private:
* This function will open an ini file and load the information in it.
*
* @param _filename Name of the ini file
* @param _coreSettings Load core settings from the file
* @param _perPluginSettings Load per plugin settings from the file
* @param _coreSettings Load core settings from the file
* @param _loadObjects Load objects defined in the ini file
*
*/
void openIniFile(QString _filename, bool _coreSettings , bool _perPluginSettings);
void openIniFile( QString _filename,
bool _coreSettings ,
bool _perPluginSettings,
bool _loadObjects );
/// Open an obj file and load everything in it ( Application/File Options )
void openObjFile(QString _filename);
......@@ -472,9 +479,16 @@ private:
* @param _filename filename of the ini file to write with full path
* @param _relativePaths This defines if the paths to the objects should be made relative
* @param _targetOnly Select if we want all open objects or only the ones which are selected as target.
* @param _systemSettings Choose if you also want to save system settings into the ini file.
* @param _saveSystemSettings Choose if you also want to save system settings into the ini file.
* @param _savePluginSettings Choose if you want to save per Plugin global settings into the ini file.
* @param _saveObjectInfo If you want to store information about all open objects this has to be true
*/
void writeIniFile(QString _filename, bool _relativePaths, bool _targetOnly, bool _systemSettings);
void writeIniFile( QString _filename,
bool _relativePaths,
bool _targetOnly,
bool _saveSystemSettings,
bool _savePluginSettings ,
bool _saveObjectInfo );
/** \brief Write current status to obj file (Application and File Options)
*
......
......@@ -457,7 +457,10 @@ void Core::writeApplicationOptions(INIFile& _ini) {
_ini.add_entry("Options","Stereo",OpenFlipper::Options::stereo() );
}
void Core::openIniFile(QString _filename, bool _coreSettings, bool _perPluginSettings ){
void Core::openIniFile( QString _filename,
bool _coreSettings,
bool _perPluginSettings,
bool _loadObjects ){
INIFile ini;
if ( ! ini.connect(_filename,false) ) {
......@@ -476,74 +479,82 @@ void Core::openIniFile(QString _filename, bool _coreSettings, bool _perPluginSet
if ( _coreSettings )
readApplicationOptions(ini);
QStringList openFiles;
// if requested load per Plugin settings from the settings file
if ( _perPluginSettings )
emit iniLoadOptions( ini );
// Parse File section for files to open
if ( ini.section_exists("OpenFiles") && ini.get_entry(openFiles,"OpenFiles","open") ) {
if ( _loadObjects ) {
bool newActiveObject = false;
QStringList openFiles;
for ( int i = 0 ; i < openFiles.size(); ++i ) {
// Parse File section for files to open
if ( ini.section_exists("OpenFiles") && ini.get_entry(openFiles,"OpenFiles","open") ) {
QString sectionName = openFiles[i];
bool newActiveObject = false;
QString path;
ini.get_entry( path, sectionName , "path" );
for ( int i = 0 ; i < openFiles.size(); ++i ) {
//check if path is relative
if (path.startsWith( "." + OpenFlipper::Options::dirSeparator() )){
//check if _filename contains a path
if (_filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) != ""){
path.remove(0,1); // remove .
path = _filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) + path;
QString sectionName = openFiles[i];
QString path;
ini.get_entry( path, sectionName , "path" );
//check if path is relative
if (path.startsWith( "." + OpenFlipper::Options::dirSeparator() )){
//check if _filename contains a path
if (_filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) != ""){
path.remove(0,1); // remove .
path = _filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) + path;
}
}
}
int tmpType;
DataType type = DATA_TRIANGLE_MESH;
int tmpType;
DataType type = DATA_TRIANGLE_MESH;
if ( ini.get_entry( tmpType, sectionName , "type" )) {
type = DataType(tmpType);
emit log(LOGWARN, "This ini file uses old int style ObjectType fields!" );
emit log(LOGWARN, "Please convert it to new format! ( ... just save it )" );
} else {
if ( ini.get_entry( tmpType, sectionName , "type" )) {
type = DataType(tmpType);
emit log(LOGWARN, "This ini file uses old int style ObjectType fields!" );
emit log(LOGWARN, "Please convert it to new format! ( ... just save it )" );
} else {
QString typeName="";
QString typeName="";
if ( ini.get_entry( typeName, sectionName , "type" )) {
type = typeId(typeName);
} else
emit log(LOGWARN, "Unable to get DataType for object " + sectionName + " assuming Triangle Mesh" );
}
if ( ini.get_entry( typeName, sectionName , "type" )) {
type = typeId(typeName);
} else
emit log(LOGWARN, "Unable to get DataType for object " + sectionName + " assuming Triangle Mesh" );
}
int newObjectId = loadObject(type, path);
int newObjectId = loadObject(type, path);
BaseObject* object = objectRoot_->childExists( newObjectId );
if ( object == 0 ) {
emit log(LOGERR,"Unable to open Object " + path);
continue;
}
BaseObject* object = objectRoot_->childExists( newObjectId );
if ( object == 0 ) {
emit log(LOGERR,"Unable to open Object " + path);
continue;
}
bool flag;
if ( ini.get_entry( flag, sectionName , "target" ) ) {
object->target(flag);
newActiveObject = true;
}
if ( ini.get_entry( flag, sectionName , "source" ) )
object->source(flag);
bool flag;
if ( ini.get_entry( flag, sectionName , "target" ) ) {
object->target(flag);
newActiveObject = true;
emit iniLoad( ini,object->id() );
}
if ( ini.get_entry( flag, sectionName , "source" ) )
object->source(flag);
if ( newActiveObject )
emit activeObjectChanged();
emit iniLoad( ini,object->id() );
}
if ( newActiveObject )
emit activeObjectChanged();
}
// if requested load per Plugin settings from the settings file
// Tell Plugins that all objects are
if ( _perPluginSettings )
emit iniLoadOptions( ini );
emit iniLoadOptionsLast( ini );
ini.disconnect();
......@@ -558,10 +569,12 @@ void Core::openIniFile(QString _filename, bool _coreSettings, bool _perPluginSet
}
void Core::writeIniFile(QString _filename, bool _relativePaths, bool _targetOnly, bool _systemSettings ) {
std::cerr << "Currently unsupported : Saving ini files without including global settings" << std::endl;
void Core::writeIniFile(QString _filename,
bool _relativePaths,
bool _targetOnly,
bool _saveSystemSettings,
bool _savePluginSettings ,
bool _saveObjectInfo ) {
INIFile ini;
......@@ -576,57 +589,58 @@ void Core::writeIniFile(QString _filename, bool _relativePaths, bool _targetOnly
}
// Only save application settings when requested
if ( _systemSettings )
if ( _saveSystemSettings )
writeApplicationOptions(ini);
// This vector will hold the file sections to open
QStringList openFiles;
PluginFunctions::IteratorRestriction restriction;
if ( _targetOnly )
restriction = PluginFunctions::TARGET_OBJECTS;
else
restriction = PluginFunctions::ALL_OBJECTS;
QString keyName;
QString sectionName;
for ( PluginFunctions::ObjectIterator o_it(restriction) ;
o_it != PluginFunctions::objects_end(); ++o_it) {
QString file = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
if (QFile(file).exists()){
// Add a section for this object
sectionName = o_it->name();
ini.add_section( sectionName );
openFiles.push_back( sectionName );
//modify filename if relativePaths are wanted
if (_relativePaths){
int prefixLen = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2).length();
file.remove(0, prefixLen);
file = "." + file;
}
// Add the path of this object to the section
ini.add_entry( sectionName , "path" , file );
ini.add_entry( sectionName , "type" , typeName(o_it->dataType() ) );
ini.add_entry( sectionName , "target" , o_it->target() );
ini.add_entry( sectionName , "source" , o_it->source() );
if ( _savePluginSettings )
emit iniSaveOptions( ini );
if ( _saveObjectInfo ) {
// This vector will hold the file sections to open
QStringList openFiles;
PluginFunctions::IteratorRestriction restriction;
if ( _targetOnly )
restriction = PluginFunctions::TARGET_OBJECTS;
else
restriction = PluginFunctions::ALL_OBJECTS;
QString keyName;
QString sectionName;
for ( PluginFunctions::ObjectIterator o_it(restriction) ;
o_it != PluginFunctions::objects_end(); ++o_it) {
QString file = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
if (QFile(file).exists()){
// Add a section for this object
sectionName = o_it->name();
ini.add_section( sectionName );
openFiles.push_back( sectionName );
//modify filename if relativePaths are wanted
if (_relativePaths){
int prefixLen = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2).length();
file.remove(0, prefixLen);
file = "." + file;
}
// Add the path of this object to the section
ini.add_entry( sectionName , "path" , file );
ini.add_entry( sectionName , "type" , typeName(o_it->dataType() ) );
ini.add_entry( sectionName , "target" , o_it->target() );
ini.add_entry( sectionName , "source" , o_it->source() );
}
}
}
ini.add_entry("OpenFiles","open",openFiles);
ini.add_entry("OpenFiles","open",openFiles);
///@todo :write ini file ( Ask for objects which are not written yet
std::cerr << "Todo : write ini file ( Ask for objects which are not written yet )" << std::endl;
// Tell plugins to save their information for the given object
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
o_it != PluginFunctions::objects_end(); ++o_it)
emit iniSave( ini , o_it->id() );
}
// Tell plugins to save their information for the given object
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
o_it != PluginFunctions::objects_end(); ++o_it)
emit iniSave( ini , o_it->id() );
// TODO : Save per plugin options only if requested
emit iniSaveOptions( ini );
ini.disconnect();
......
......@@ -756,6 +756,10 @@ void Core::loadPlugin(QString filename, bool silent){
if ( checkSlot( plugin , "loadIniFileOptions(INIFile&)" ) )
connect(this , SIGNAL(iniLoadOptions( INIFile& )),
plugin , SLOT( loadIniFileOptions( INIFile& ) ),Qt::DirectConnection);
if ( checkSlot( plugin , "loadIniFileOptionsLast(INIFile&)" ) )
connect(this , SIGNAL(iniLoadOptionsLast( INIFile& )),
plugin , SLOT( loadIniFileOptionsLast( INIFile& ) ),Qt::DirectConnection);
}
//Check if the plugin supports Texture-Interface
......
......@@ -101,7 +101,7 @@ int Core::loadObject ( QString _filename ) {
if (_filename.endsWith(".ini")) {
// Load all information from the given ini file
openIniFile(_filename,true,true);
openIniFile(_filename,true,true,true);
if ( OpenFlipper::Options::gui() )
coreWidget_->addRecent(_filename, DATA_NONE);
......@@ -297,19 +297,70 @@ void Core::loadSettings(){
QString complete_name;
complete_name = ACG::getOpenFileName(coreWidget_,
tr("Load Settings"),
tr("INI files (*.ini);;OBJ files (*.obj)"),
OpenFlipper::Options::currentDirStr());
if (complete_name.isEmpty())
QFileDialog fileDialog( coreWidget_,
tr("Load Settings"),
OpenFlipper::Options::currentDirStr(),
tr("INI files (*.ini);;OBJ files (*.obj )") );
fileDialog.setAcceptMode ( QFileDialog::AcceptOpen );
fileDialog.setFileMode ( QFileDialog::AnyFile );
QGridLayout *layout = (QGridLayout*)fileDialog.layout();
QGroupBox* optionsBox = new QGroupBox( &fileDialog ) ;
optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
optionsBox->setTitle("Options");
layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
QCheckBox *loadProgramSettings = new QCheckBox(optionsBox);
loadProgramSettings->setText("Load program settings");
loadProgramSettings->setToolTip("Load all current program settings from the file ( This will include view settings, colors,...) ");
loadProgramSettings->setCheckState( Qt::Unchecked );
QCheckBox *loadPluginSettings = new QCheckBox(optionsBox);
loadPluginSettings->setText("Load per Plugin Settings");
loadPluginSettings->setToolTip("Plugins should load their current global settings from the file");
loadPluginSettings->setCheckState( Qt::Checked );
QCheckBox *loadObjectInfo = new QCheckBox(optionsBox);
loadObjectInfo->setText("Load all objects defined in the file");
loadObjectInfo->setToolTip("Load all objects which are defined in the file");
loadObjectInfo->setCheckState( Qt::Checked );
QBoxLayout* frameLayout = new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
frameLayout->addWidget( loadProgramSettings , 0 , 0);
frameLayout->addWidget( loadPluginSettings , 1 , 0);
frameLayout->addWidget( loadObjectInfo , 2 , 0);
frameLayout->addStretch();
// ========================================================================================
// show the saveSettings-Dialog and get the target file
// ========================================================================================
QStringList fileNames;
if (fileDialog.exec()) {
fileNames = fileDialog.selectedFiles();
} else {
return;
}
if ( fileNames.size() > 1 ) {
std::cerr << "Too many save filenames selected" << std::endl;
return;
}
complete_name = fileNames[0];
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath);
if ( complete_name.endsWith("ini") ) {
// TODO OptionsDialog for choosing which information should be read
openIniFile(complete_name,true,true);
openIniFile( complete_name,
loadProgramSettings->isChecked(),
loadPluginSettings->isChecked(),
loadObjectInfo->isChecked());
applyOptions();
} else if ( complete_name.endsWith("obj") ) {
openObjFile(complete_name);
......@@ -331,7 +382,7 @@ void Core::loadSettings(QString _filename){
if ( _filename.endsWith("ini") ) {
// Loaded function for recent files. Load everything.
openIniFile(_filename,true,true);
openIniFile(_filename,true,true,true);
applyOptions();
} else if ( _filename.endsWith("obj") ) {
openObjFile(_filename);
......
......@@ -71,6 +71,16 @@ void Core::saveSettings(){
saveProgramSettings->setToolTip("Save all current program settings to the file ( This will include view settings, colors,...) ");
saveProgramSettings->setCheckState( Qt::Unchecked );
QCheckBox *savePluginSettings = new QCheckBox(optionsBox);
savePluginSettings->setText("Save per Plugin Settings");
savePluginSettings->setToolTip("Plugins should add their current global settings to the file");
savePluginSettings->setCheckState( Qt::Checked );
QCheckBox *saveObjectInfo = new QCheckBox(optionsBox);
saveObjectInfo->setText("Save open object information to the file");
saveObjectInfo->setToolTip("Save all open Objects and add them to the settings file ( they will be loaded if opening the settings file");
saveObjectInfo->setCheckState( Qt::Checked );
QCheckBox *saveAllBox = new QCheckBox(optionsBox);
saveAllBox->setText("Save everything to same folder");
saveAllBox->setToolTip("Save all open files to the same folder as the ini file");
......@@ -87,10 +97,12 @@ void Core::saveSettings(){
targetOnly->setCheckState( Qt::Unchecked );
QBoxLayout* frameLayout = new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
frameLayout->addWidget( saveProgramSettings , 0 , 0);
frameLayout->addWidget( saveAllBox , 1 , 0);
frameLayout->addWidget( askOverwrite , 2 , 0);
frameLayout->addWidget( targetOnly , 3 , 0);
frameLayout->addWidget( saveProgramSettings , 0 , 0);
frameLayout->addWidget( savePluginSettings , 1 , 0);
frameLayout->addWidget( saveObjectInfo , 2 , 0);
frameLayout->addWidget( saveAllBox , 3 , 0);
frameLayout->addWidget( askOverwrite , 4 , 0);
frameLayout->addWidget( targetOnly , 5 , 0);
frameLayout->addStretch();
......@@ -141,55 +153,58 @@ void Core::saveSettings(){
// ========================================================================================
// Depending on the checkbox iterate over all objects or only the selected ones.
PluginFunctions::IteratorRestriction restriction;
if ( targetOnly->isChecked() )
restriction = PluginFunctions::TARGET_OBJECTS;
else
restriction = PluginFunctions::ALL_OBJECTS;
if ( saveObjectInfo->isChecked() ) {
//Iterate over opened objects and save them
for ( PluginFunctions::ObjectIterator o_it(restriction);
o_it != PluginFunctions::objects_end(); ++o_it)
{
QString filename;
if ( saveAllBox->isChecked() )
{
// Use path of settings file for all objects
filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
}
PluginFunctions::IteratorRestriction restriction;
if ( targetOnly->isChecked() )
restriction = PluginFunctions::TARGET_OBJECTS;
else
restriction = PluginFunctions::ALL_OBJECTS;
//Iterate over opened objects and save them
for ( PluginFunctions::ObjectIterator o_it(restriction);
o_it != PluginFunctions::objects_end(); ++o_it)
{
// Use objects own path if it has one. Otherwise also use path of settings file
filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
QString filename;
// handle the case that the object was created in current session and not loaded from disk
if (o_it->path() == ".") {
if ( saveAllBox->isChecked() )
{
// Use path of settings file for all objects
filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
std::cerr << "newpath : " << newpath.toStdString() << std::endl;
std::cerr << "name : " << o_it->name().toStdString() << std::endl;
}
}
else
{
// Use objects own path if it has one. Otherwise also use path of settings file
filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
// handle the case that the object was created in current session and not loaded from disk
if (o_it->path() == ".") {
filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
std::cerr << "newpath : " << newpath.toStdString() << std::endl;
std::cerr << "name : " << o_it->name().toStdString() << std::endl;
}
}
// enforce that all files end with obj extension if its an obj-settings file
if ( complete_name.endsWith("obj") )
{
if (!filename.endsWith("obj"))
// enforce that all files end with obj extension if its an obj-settings file
if ( complete_name.endsWith("obj") )
{
// remove old extension
int pos = filename.lastIndexOf(".");
filename.remove(pos+1, filename.length() - pos);
// add obj extension
filename += "obj";
if (!filename.endsWith("obj"))
{
// remove old extension
int pos = filename.lastIndexOf(".");
filename.remove(pos+1, filename.length() - pos);
// add obj extension
filename += "obj";
}
}
}
// decide whether to use saveObject or saveObjectTo
if ( !QFile(filename).exists() || !askOverwrite->isChecked() )
saveObject( o_it->id(), filename);
else
saveObjectTo(o_it->id(), filename);
// decide whether to use saveObject or saveObjectTo
if ( !QFile(filename).exists() || !askOverwrite->isChecked() )
saveObject( o_it->id(), filename);
else
saveObjectTo(o_it->id(), filename);
}
}
......@@ -199,7 +214,12 @@ void Core::saveSettings(){
if ( complete_name.endsWith("ini") ) {
// write to ini
writeIniFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked(), saveProgramSettings->isChecked());
writeIniFile( complete_name,
saveAllBox->isChecked(),
targetOnly->isChecked(),
saveProgramSettings->isChecked(),
savePluginSettings->isChecked(),
saveObjectInfo->isChecked());
} else if ( complete_name.endsWith("obj") ) {
......
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