65 tr(
"INI files (*.ini);;OBJ files (*.obj )") );
67 fileDialog.setOption (QFileDialog::DontUseNativeDialog,
true);
68 fileDialog.setAcceptMode ( QFileDialog::AcceptSave );
69 fileDialog.setFileMode ( QFileDialog::AnyFile );
71 QGridLayout *layout = (QGridLayout*)fileDialog.layout();
73 QGroupBox* optionsBox =
new QGroupBox( &fileDialog ) ;
74 optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
75 optionsBox->setTitle(tr(
"Options"));
76 layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
78 QCheckBox *saveProgramSettings =
new QCheckBox(optionsBox);
79 saveProgramSettings->setText(tr(
"Save program settings"));
80 saveProgramSettings->setToolTip(tr(
"Save all current program settings to the file ( This will include view settings, colors,...) "));
81 saveProgramSettings->setCheckState( Qt::Unchecked );
83 QCheckBox *savePluginSettings =
new QCheckBox(optionsBox);
84 savePluginSettings->setText(tr(
"Save per Plugin Settings"));
85 savePluginSettings->setToolTip(tr(
"Plugins should add their current global settings to the file"));
86 savePluginSettings->setCheckState( Qt::Checked );
88 QCheckBox *saveObjectInfo =
new QCheckBox(optionsBox);
89 saveObjectInfo->setText(tr(
"Save open object information to the file"));
90 saveObjectInfo->setToolTip(tr(
"Save all open Objects and add them to the settings file ( they will be loaded if opening the settings file"));
91 saveObjectInfo->setCheckState( Qt::Checked );
93 QCheckBox *saveAllBox =
new QCheckBox(optionsBox);
94 saveAllBox->setText(tr(
"Save everything to same folder"));
95 saveAllBox->setToolTip(tr(
"Save all open files to the same folder as the ini file"));
96 saveAllBox->setCheckState( Qt::Checked );
98 QCheckBox *askOverwrite =
new QCheckBox(optionsBox);
99 askOverwrite->setText(tr(
"Ask before overwriting files"));
100 askOverwrite->setToolTip(tr(
"If a file exists you will get asked what to do"));
101 askOverwrite->setCheckState( Qt::Checked );
103 QCheckBox *targetOnly =
new QCheckBox(optionsBox);
104 targetOnly->setText(tr(
"Save only target objects"));
105 targetOnly->setToolTip(tr(
"Only objects with target flag will be handled"));
106 targetOnly->setCheckState( Qt::Unchecked );
108 QBoxLayout* frameLayout =
new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
109 frameLayout->addWidget( saveProgramSettings , 0 , 0);
110 frameLayout->addWidget( savePluginSettings , 1 , 0);
111 frameLayout->addWidget( saveObjectInfo , 2 , 0);
112 frameLayout->addWidget( saveAllBox , 3 , 0);
113 frameLayout->addWidget( askOverwrite , 4 , 0);
114 frameLayout->addWidget( targetOnly , 5 , 0);
115 frameLayout->addStretch();
117 fileDialog.resize(550 ,600);
122 QStringList fileNames;
123 if (fileDialog.exec()) {
124 fileNames = fileDialog.selectedFiles();
129 if ( fileNames.size() > 1 ) {
130 std::cerr <<
"Too many save filenames selected" << std::endl;
134 QString complete_name = fileNames[0];
137 if ( !complete_name.endsWith(
".ini", Qt::CaseInsensitive) && !complete_name.endsWith(
".obj", Qt::CaseInsensitive) ){
140 if ( fileDialog.selectedNameFilter().contains(tr(
"INI files (*.ini)")) )
141 complete_name +=
".ini";
143 complete_name +=
".obj";
147 bool is_saveObjectInfo = saveObjectInfo->isChecked();
148 bool is_targetOnly = targetOnly->isChecked();
149 bool is_saveAll = saveAllBox->isChecked();
150 bool is_askOverwrite = askOverwrite->isChecked();
151 bool is_saveProgramSettings = saveProgramSettings->isChecked();
152 bool is_savePluginSettings = savePluginSettings->isChecked();
154 saveSettings(complete_name, is_saveObjectInfo, is_targetOnly, is_saveAll, is_askOverwrite, is_saveProgramSettings, is_savePluginSettings);
157 void Core::saveSettings(QString complete_name,
bool is_saveObjectInfo,
bool is_targetOnly,
bool is_saveAll,
158 bool is_askOverwrite,
bool is_saveProgramSettings,
bool is_savePluginSettings){
160 QFileInfo fileInfo(complete_name);
166 OpenFlipper::Options::savingSettings(
true);
168 if ( OpenFlipper::Options::gui() ) {
169 coreWidget_->statusMessage( tr(
"Saving Settings to ") + complete_name +
" ...");
179 std::map<int,QString> savedFiles;
181 if ( is_saveObjectInfo ) {
190 std::multiset<QString> originalFiles;
193 std::map<DataType,QString> defaultExtensions;
195 QMultiMap<DataType,QString> allFilters;
196 const std::vector<fileTypes>& types = supportedTypes();
197 for (
int i=0; i < (int)types.size(); i++) {
198 QString filters = types[i].saveFilters;
201 filters = filters.section(
"(",1).section(
")",0,0);
202 if (filters.trimmed() ==
"")
205 QStringList separateFilters = filters.split(
" ");
207 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
208 if (separateFilters[filterId].trimmed() ==
"")
212 allFilters.insert(types[i].type,separateFilters[filterId]);
216 allFilters.insert(types[i].type,filters);
221 QGridLayout extensionLayout;
222 const QString extensionCheckBoxPrefixString =
"Apply extension to all Objects without preset extensions with DataType: ";
223 QCheckBox extensionCheckBox;
224 QComboBox extensionComboBox;
225 QDialogButtonBox extensionButtons(QDialogButtonBox::Ok);
226 QDialogButtonBox::connect(&extensionButtons, SIGNAL(accepted()), &extensionDialog, SLOT(accept()));
228 extensionLayout.addWidget(&extensionComboBox);
229 extensionLayout.addWidget(&extensionCheckBox);
230 extensionLayout.addWidget(&extensionButtons);
231 extensionDialog.setLayout(&extensionLayout);
242 filename = fileInfo.absolutePath() + OpenFlipper::Options::dirSeparator() + o_it->name();
247 filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
250 if (o_it->path() ==
".") {
251 filename = fileInfo.absolutePath() + OpenFlipper::Options::dirSeparator() + o_it->name();
252 std::cerr <<
"newpath : " << fileInfo.absolutePath().toStdString() << std::endl;
253 std::cerr <<
"name : " << o_it->name().toStdString() << std::endl;
258 if ( complete_name.endsWith(
"obj") )
260 if (!filename.endsWith(
"obj"))
263 int pos = filename.lastIndexOf(
".");
264 filename.remove(pos+1, filename.length() - pos);
278 originalFiles.insert(filename);
282 size_t c = originalFiles.count(filename);
284 QFileInfo finfo(filename);
285 filename = finfo.absolutePath() + OpenFlipper::Options::dirSeparator();
286 filename += finfo.baseName() + QString(
"_%1").arg(c-1) +
".";
287 filename += finfo.completeSuffix();
291 bool extInName =
false;
292 for (QMultiMap<DataType,QString>::const_iterator e_it = allFilters.begin(); e_it != allFilters.end(); ++e_it)
295 extInName = e_it.key().contains(o_it->dataType()) && e_it.value() == QString(
"*.")+QFileInfo(filename).suffix();
303 std::map<DataType,QString>::const_iterator defaultExtIt = defaultExtensions.find(o_it->dataType());
304 bool useDefault = defaultExtIt != defaultExtensions.end();
305 QString extension = (useDefault) ? defaultExtIt->second :
"";
311 QStringList supportedFilters;
312 for (QMultiMap<DataType,QString>::const_iterator it = allFilters.begin(); it != allFilters.end() ; ++it)
314 if (it.key().contains(o_it->dataType()))
315 supportedFilters.append(it.value());
318 extensionComboBox.clear();
319 extensionComboBox.addItems(supportedFilters);
320 extensionDialog.setWindowTitle(
"Please specify a file extension for " + o_it->name());
321 extensionCheckBox.setText(extensionCheckBoxPrefixString +
typeName(o_it->dataType()));
322 extensionDialog.move(
coreWidget_->width()/2 - extensionDialog.width(),
323 coreWidget_->height()/2 - extensionDialog.height());
325 if (extensionDialog.exec() && !supportedFilters.isEmpty())
327 extension = extensionComboBox.currentText();
328 extension = QFileInfo(extension).suffix();
329 filename +=
"." + extension;
330 if (extensionCheckBox.isChecked())
331 defaultExtensions[o_it->dataType()] = extension;
335 emit
log(
LOGERR, tr(
"Unabel to save %1. No extension specified.").arg(o_it->name()));
340 filename +=
"." + extension;
346 if ( !QFile(filename).exists() || !is_askOverwrite )
352 savedFiles.insert(std::pair<int,QString>(o_it->id(),filename));
361 if ( complete_name.endsWith(
"obj") ) {
364 writeObjFile(complete_name, is_saveAll, is_targetOnly, savedFiles);
371 is_saveProgramSettings,
372 is_savePluginSettings,
378 OpenFlipper::Options::savingSettings(
false);
380 if ( OpenFlipper::Options::gui() ) {
381 coreWidget_->statusMessage( tr(
"Saving Settings to ") + complete_name + tr(
" ... Done"), 4000);
386 if ( OpenFlipper::Options::gui() )
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
bool saveObject(int _id, QString _filename)
Save an object.
const QStringList ALL_OBJECTS
Iterable object range.
void saveSettings()
Save current status to a settings file. Solicit file name through dialog.
const DataType DATA_UNKNOWN(0)
None of the other Objects.
void writeObjFile(QString _filename, bool _relativePaths, bool _targetOnly, std::map< int, QString > &_fileMapping)
Write current status to obj file (Application and File Options)
bool getObject(int _identifier, BSplineCurveObject *&_object)
bool saveObjectTo(int _id, QString _filename)
bool defaultLight() const
Is light default light source?
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
Status is processing and blocked system will not allow interaction (red light)
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void addRecent(QString _filename, DataType _type)
Add a recent file and update menu.
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
QStringList IteratorRestriction
Iterable object range.
void writeIniFile(QString _filename, bool _relativePaths, bool _targetOnly, bool _saveSystemSettings, bool _savePluginSettings, bool _saveObjectInfo, std::map< int, QString > &_fileMapping)
Write current status to ini file (Application and File Options)
Status is ready (green light)
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...