Commit a4557a84 authored by Jan Möbius's avatar Jan Möbius

Documentation for saveSettings

added checkBox to choose if we want to save global settings into ini file

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4284 383ad7c9-94d9-4d36-a494-682f7c89f535
parent aa6af50f
...@@ -460,8 +460,13 @@ private: ...@@ -460,8 +460,13 @@ private:
/** \brief Write current status to ini file (Application and File Options) /** \brief Write current status to ini file (Application and File Options)
* *
* Writes the complete status to an ini file ( All open objects and their Information ) * Writes the complete status to an ini file ( All open objects and their Information )
*
* @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.
*/ */
void writeIniFile(QString _filename, bool _relativePaths, bool _targetOnly); void writeIniFile(QString _filename, bool _relativePaths, bool _targetOnly, bool _systemSettings);
/** \brief Write current status to obj file (Application and File Options) /** \brief Write current status to obj file (Application and File Options)
* *
......
...@@ -549,7 +549,11 @@ void Core::openIniFile(QString _filename) { ...@@ -549,7 +549,11 @@ void Core::openIniFile(QString _filename) {
} }
void Core::writeIniFile(QString _filename, bool _relativePaths, bool _targetOnly) { void Core::writeIniFile(QString _filename, bool _relativePaths, bool _targetOnly, bool _systemSettings ) {
if ( ! _systemSettings )
std::cerr << "Currently unsupported : Saving ini files without including global settings" << std::endl;
INIFile ini; INIFile ini;
if ( ! ini.connect(_filename,true) ) { if ( ! ini.connect(_filename,true) ) {
......
...@@ -45,7 +45,9 @@ ...@@ -45,7 +45,9 @@
/// Save Settings (slot is called from CoreWidget's File-Menu) /// Save Settings (slot is called from CoreWidget's File-Menu)
void Core::saveSettings(){ void Core::saveSettings(){
// ========================================================================================
// generate the saveSettings-Dialog // generate the saveSettings-Dialog
// ========================================================================================
QString complete_name; QString complete_name;
...@@ -64,6 +66,11 @@ void Core::saveSettings(){ ...@@ -64,6 +66,11 @@ void Core::saveSettings(){
optionsBox->setTitle("Options"); optionsBox->setTitle("Options");
layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() ); layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
QCheckBox *saveProgramSettings = new QCheckBox(optionsBox);
saveProgramSettings->setText("Save program settings");
saveProgramSettings->setToolTip("Save all current program settings to the file ( This will include view settings, colors,...) ");
saveProgramSettings->setCheckState( Qt::Unchecked );
QCheckBox *saveAllBox = new QCheckBox(optionsBox); QCheckBox *saveAllBox = new QCheckBox(optionsBox);
saveAllBox->setText("Save everything to same folder"); saveAllBox->setText("Save everything to same folder");
saveAllBox->setToolTip("Save all open files to the same folder as the ini file"); saveAllBox->setToolTip("Save all open files to the same folder as the ini file");
...@@ -80,14 +87,16 @@ void Core::saveSettings(){ ...@@ -80,14 +87,16 @@ void Core::saveSettings(){
targetOnly->setCheckState( Qt::Unchecked ); targetOnly->setCheckState( Qt::Unchecked );
QBoxLayout* frameLayout = new QBoxLayout(QBoxLayout::TopToBottom,optionsBox); QBoxLayout* frameLayout = new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
frameLayout->addWidget( saveAllBox , 0 , 0); frameLayout->addWidget( saveProgramSettings , 0 , 0);
frameLayout->addWidget( askOverwrite , 1 , 0); frameLayout->addWidget( saveAllBox , 1 , 0);
frameLayout->addWidget( targetOnly , 2 , 0); frameLayout->addWidget( askOverwrite , 2 , 0);
frameLayout->addWidget( targetOnly , 3 , 0);
frameLayout->addStretch(); frameLayout->addStretch();
// show the saveSettings-Dialog // ========================================================================================
// show the saveSettings-Dialog and get the target file
// ========================================================================================
QStringList fileNames; QStringList fileNames;
if (fileDialog.exec()) { if (fileDialog.exec()) {
fileNames = fileDialog.selectedFiles(); fileNames = fileDialog.selectedFiles();
...@@ -102,19 +111,24 @@ void Core::saveSettings(){ ...@@ -102,19 +111,24 @@ void Core::saveSettings(){
complete_name = fileNames[0]; complete_name = fileNames[0];
//check the extension //check the extension if its a known one
if ( !complete_name.endsWith(".ini", Qt::CaseInsensitive) && !complete_name.endsWith(".obj", Qt::CaseInsensitive) ){ if ( !complete_name.endsWith(".ini", Qt::CaseInsensitive) && !complete_name.endsWith(".obj", Qt::CaseInsensitive) ){
// If its unknown, get the type from the currently selected filter and add this extension to the filename
if ( fileDialog.selectedNameFilter().contains("INI files (*.ini)") ) if ( fileDialog.selectedNameFilter().contains("INI files (*.ini)") )
complete_name += ".ini"; complete_name += ".ini";
else else
complete_name += ".obj"; complete_name += ".obj";
} }
// Get the chosen directory and remember it.
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2); QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath); OpenFlipper::Options::currentDir(newpath);
//update status // ========================================================================================
// update status information
// ========================================================================================
OpenFlipper::Options::savingSettings(true); OpenFlipper::Options::savingSettings(true);
if ( OpenFlipper::Options::gui() ) { if ( OpenFlipper::Options::gui() ) {
...@@ -122,14 +136,18 @@ void Core::saveSettings(){ ...@@ -122,14 +136,18 @@ void Core::saveSettings(){
coreWidget_->setStatus(ApplicationStatus::BLOCKED ); coreWidget_->setStatus(ApplicationStatus::BLOCKED );
} }
// ========================================================================================
// Save the objects itself
// ========================================================================================
// Depending on the checkbox iterate over all objects or only the selected ones.
PluginFunctions::IteratorRestriction restriction; PluginFunctions::IteratorRestriction restriction;
if ( targetOnly->isChecked() ) if ( targetOnly->isChecked() )
restriction = PluginFunctions::TARGET_OBJECTS; restriction = PluginFunctions::TARGET_OBJECTS;
else else
restriction = PluginFunctions::ALL_OBJECTS; restriction = PluginFunctions::ALL_OBJECTS;
//iterate over opened objects and save them //Iterate over opened objects and save them
for ( PluginFunctions::ObjectIterator o_it(restriction); for ( PluginFunctions::ObjectIterator o_it(restriction);
o_it != PluginFunctions::objects_end(); ++o_it) o_it != PluginFunctions::objects_end(); ++o_it)
{ {
...@@ -144,7 +162,6 @@ void Core::saveSettings(){ ...@@ -144,7 +162,6 @@ void Core::saveSettings(){
{ {
// Use objects own path if it has one. Otherwise also use path of settings file // 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(); filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
// filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
// handle the case that the object was created in current session and not loaded from disk // handle the case that the object was created in current session and not loaded from disk
if (o_it->path() == ".") { if (o_it->path() == ".") {
...@@ -176,17 +193,22 @@ void Core::saveSettings(){ ...@@ -176,17 +193,22 @@ void Core::saveSettings(){
} }
//finally save all Settings // ========================================================================================
// Finally save all Settings
// ========================================================================================
if ( complete_name.endsWith("ini") ) { if ( complete_name.endsWith("ini") ) {
//write to ini
writeIniFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked() ); // write to ini
writeIniFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked(), saveProgramSettings->isChecked());
} else if ( complete_name.endsWith("obj") ) { } else if ( complete_name.endsWith("obj") ) {
//write to obj //write to obj
writeObjFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked() ); writeObjFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked() );
} }
//update status // update status
OpenFlipper::Options::savingSettings(false); OpenFlipper::Options::savingSettings(false);
if ( OpenFlipper::Options::gui() ) { if ( OpenFlipper::Options::gui() ) {
......
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