62 tr(
"INI files (*.ini);;OBJ files (*.obj )") );
64 fileDialog.setOption (QFileDialog::DontUseNativeDialog,
true);
65 fileDialog.setAcceptMode ( QFileDialog::AcceptSave );
66 fileDialog.setFileMode ( QFileDialog::AnyFile );
68 QGridLayout *layout = (QGridLayout*)fileDialog.layout();
70 QGroupBox* optionsBox =
new QGroupBox( &fileDialog ) ;
71 optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
72 optionsBox->setTitle(tr(
"Options"));
73 layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
75 QCheckBox *saveProgramSettings =
new QCheckBox(optionsBox);
76 saveProgramSettings->setText(tr(
"Save program settings"));
77 saveProgramSettings->setToolTip(tr(
"Save all current program settings to the file ( This will include view settings, colors,...) "));
78 saveProgramSettings->setCheckState( Qt::Unchecked );
80 QCheckBox *savePluginSettings =
new QCheckBox(optionsBox);
81 savePluginSettings->setText(tr(
"Save per Plugin Settings"));
82 savePluginSettings->setToolTip(tr(
"Plugins should add their current global settings to the file"));
83 savePluginSettings->setCheckState( Qt::Checked );
85 QCheckBox *saveObjectInfo =
new QCheckBox(optionsBox);
86 saveObjectInfo->setText(tr(
"Save open object information to the file"));
87 saveObjectInfo->setToolTip(tr(
"Save all open Objects and add them to the settings file ( they will be loaded if opening the settings file"));
88 saveObjectInfo->setCheckState( Qt::Checked );
90 QCheckBox *saveAllBox =
new QCheckBox(optionsBox);
91 saveAllBox->setText(tr(
"Save everything to same folder"));
92 saveAllBox->setToolTip(tr(
"Save all open files to the same folder as the ini file"));
93 saveAllBox->setCheckState( Qt::Checked );
95 QCheckBox *askOverwrite =
new QCheckBox(optionsBox);
96 askOverwrite->setText(tr(
"Ask before overwriting files"));
97 askOverwrite->setToolTip(tr(
"If a file exists you will get asked what to do"));
98 askOverwrite->setCheckState( Qt::Checked );
100 QCheckBox *targetOnly =
new QCheckBox(optionsBox);
101 targetOnly->setText(tr(
"Save only target objects"));
102 targetOnly->setToolTip(tr(
"Only objects with target flag will be handled"));
103 targetOnly->setCheckState( Qt::Unchecked );
105 QBoxLayout* frameLayout =
new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
107 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) 108 frameLayout->addWidget( saveProgramSettings , 0 , 0);
109 frameLayout->addWidget( savePluginSettings , 1 , 0);
110 frameLayout->addWidget( saveObjectInfo , 2 , 0);
111 frameLayout->addWidget( saveAllBox , 3 , 0);
112 frameLayout->addWidget( askOverwrite , 4 , 0);
113 frameLayout->addWidget( targetOnly , 5 , 0);
115 frameLayout->addWidget( saveProgramSettings , 0 , Qt::Alignment());
116 frameLayout->addWidget( savePluginSettings , 1 , Qt::Alignment());
117 frameLayout->addWidget( saveObjectInfo , 2 , Qt::Alignment());
118 frameLayout->addWidget( saveAllBox , 3 , Qt::Alignment());
119 frameLayout->addWidget( askOverwrite , 4 , Qt::Alignment());
120 frameLayout->addWidget( targetOnly , 5 , Qt::Alignment());
122 frameLayout->addStretch();
124 fileDialog.resize(550 ,600);
129 QStringList fileNames;
130 if (fileDialog.exec()) {
131 fileNames = fileDialog.selectedFiles();
136 if ( fileNames.size() > 1 ) {
137 std::cerr <<
"Too many save filenames selected" << std::endl;
141 QString complete_name = fileNames[0];
144 if ( !complete_name.endsWith(
".ini", Qt::CaseInsensitive) && !complete_name.endsWith(
".obj", Qt::CaseInsensitive) ){
147 if ( fileDialog.selectedNameFilter().contains(tr(
"INI files (*.ini)")) )
148 complete_name +=
".ini";
150 complete_name +=
".obj";
154 bool is_saveObjectInfo = saveObjectInfo->isChecked();
155 bool is_targetOnly = targetOnly->isChecked();
156 bool is_saveAll = saveAllBox->isChecked();
157 bool is_askOverwrite = askOverwrite->isChecked();
158 bool is_saveProgramSettings = saveProgramSettings->isChecked();
159 bool is_savePluginSettings = savePluginSettings->isChecked();
161 saveSettings(complete_name, is_saveObjectInfo, is_targetOnly, is_saveAll, is_askOverwrite, is_saveProgramSettings, is_savePluginSettings);
164 void Core::saveSettings(QString complete_name,
bool is_saveObjectInfo,
bool is_targetOnly,
bool is_saveAll,
165 bool is_askOverwrite,
bool is_saveProgramSettings,
bool is_savePluginSettings){
167 QFileInfo fileInfo(complete_name);
173 OpenFlipper::Options::savingSettings(
true);
175 if ( OpenFlipper::Options::gui() ) {
176 coreWidget_->statusMessage( tr(
"Saving Settings to ") + complete_name +
" ...");
186 std::map<int,QString> savedFiles;
188 if ( is_saveObjectInfo ) {
197 std::multiset<QString> originalFiles;
200 std::map<DataType,QString> defaultExtensions;
202 QMultiMap<DataType,QString> allFilters;
203 const std::vector<fileTypes>& types = supportedTypes();
204 for (
int i=0; i < (int)types.size(); i++) {
205 QString filters = types[i].saveFilters;
208 filters = filters.section(
"(",1).section(
")",0,0);
209 if (filters.trimmed() ==
"")
212 QStringList separateFilters = filters.split(
" ");
214 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
215 if (separateFilters[filterId].trimmed() ==
"")
219 allFilters.insert(types[i].type,separateFilters[filterId]);
223 allFilters.insert(types[i].type,filters);
228 QGridLayout extensionLayout;
229 const QString extensionCheckBoxPrefixString =
"Apply extension to all Objects without preset extensions with DataType: ";
230 QCheckBox extensionCheckBox;
231 QComboBox extensionComboBox;
232 QDialogButtonBox extensionButtons(QDialogButtonBox::Ok);
233 QDialogButtonBox::connect(&extensionButtons, SIGNAL(accepted()), &extensionDialog, SLOT(accept()));
235 extensionLayout.addWidget(&extensionComboBox);
236 extensionLayout.addWidget(&extensionCheckBox);
237 extensionLayout.addWidget(&extensionButtons);
238 extensionDialog.setLayout(&extensionLayout);
247 filename = fileInfo.absolutePath() + OpenFlipper::Options::dirSeparator() + o_it->name();
252 filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
255 if (o_it->path() ==
".") {
256 filename = fileInfo.absolutePath() + OpenFlipper::Options::dirSeparator() + o_it->name();
257 std::cerr <<
"newpath : " << fileInfo.absolutePath().toStdString() << std::endl;
258 std::cerr <<
"name : " << o_it->name().toStdString() << std::endl;
263 if ( complete_name.endsWith(
"obj") )
265 if (!filename.endsWith(
"obj"))
268 int pos = filename.lastIndexOf(
".");
269 filename.remove(pos+1, filename.length() - pos);
286 originalFiles.insert(filename);
290 size_t c = originalFiles.count(filename);
292 QFileInfo finfo(filename);
293 filename = finfo.absolutePath() + OpenFlipper::Options::dirSeparator();
294 filename += finfo.baseName() + QString(
"_%1").arg(c-1) +
".";
295 filename += finfo.completeSuffix();
299 bool extInName =
false;
300 for (QMultiMap<DataType,QString>::const_iterator e_it = allFilters.begin(); e_it != allFilters.end(); ++e_it)
303 extInName = e_it.key().contains(o_it->dataType()) && e_it.value() == QString(
"*.")+QFileInfo(filename).suffix();
311 std::map<DataType,QString>::const_iterator defaultExtIt = defaultExtensions.find(o_it->dataType());
312 bool useDefault = defaultExtIt != defaultExtensions.end();
313 QString extension = (useDefault) ? defaultExtIt->second :
"";
319 QStringList supportedFilters;
320 for (QMultiMap<DataType,QString>::const_iterator it = allFilters.begin(); it != allFilters.end() ; ++it)
322 if (it.key().contains(o_it->dataType()))
323 supportedFilters.append(it.value());
326 extensionComboBox.clear();
327 extensionComboBox.addItems(supportedFilters);
328 extensionDialog.setWindowTitle(
"Please specify a file extension for " + o_it->name());
329 extensionCheckBox.setText(extensionCheckBoxPrefixString +
typeName(o_it->dataType()));
330 extensionDialog.move(
coreWidget_->width()/2 - extensionDialog.width(),
331 coreWidget_->height()/2 - extensionDialog.height());
333 if (extensionDialog.exec() && !supportedFilters.isEmpty())
335 extension = extensionComboBox.currentText();
336 extension = QFileInfo(extension).suffix();
337 filename +=
"." + extension;
338 if (extensionCheckBox.isChecked())
339 defaultExtensions[o_it->dataType()] = extension;
343 emit
log(
LOGERR, tr(
"Unabel to save %1. No extension specified.").arg(o_it->name()));
348 filename +=
"." + extension;
354 if ( !QFile(filename).exists() || !is_askOverwrite )
360 savedFiles.insert(std::pair<int,QString>(o_it->id(),filename));
369 if ( complete_name.endsWith(
"obj") ) {
372 writeObjFile(complete_name, is_saveAll, is_targetOnly, savedFiles);
379 is_saveProgramSettings,
380 is_savePluginSettings,
386 OpenFlipper::Options::savingSettings(
false);
388 if ( OpenFlipper::Options::gui() ) {
389 coreWidget_->statusMessage( tr(
"Saving Settings to ") + complete_name + tr(
" ... Done"), 4000);
394 if ( OpenFlipper::Options::gui() )
Status is ready (green light)
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)
const QStringList ALL_OBJECTS
Iterable object range.
void saveSettings()
Save current status to a settings file. Solicit file name through dialog.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
bool saveObjectTo(int _id, QString _filename)
QStringList IteratorRestriction
Iterable object range.
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
Status is processing and blocked system will not allow interaction (red light)
void writeObjFile(QString _filename, bool _relativePaths, bool _targetOnly, std::map< int, QString > &_fileMapping)
Write current status to obj file (Application and File Options)
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
bool saveObject(int _id, QString _filename)
Save an object.
const DataType DATA_UNKNOWN(0)
None of the other Objects.