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);
106 frameLayout->addWidget( saveProgramSettings , 0 , 0);
107 frameLayout->addWidget( savePluginSettings , 1 , 0);
108 frameLayout->addWidget( saveObjectInfo , 2 , 0);
109 frameLayout->addWidget( saveAllBox , 3 , 0);
110 frameLayout->addWidget( askOverwrite , 4 , 0);
111 frameLayout->addWidget( targetOnly , 5 , 0);
112 frameLayout->addStretch();
114 fileDialog.resize(550 ,600);
119 QStringList fileNames;
120 if (fileDialog.exec()) {
121 fileNames = fileDialog.selectedFiles();
126 if ( fileNames.size() > 1 ) {
127 std::cerr <<
"Too many save filenames selected" << std::endl;
131 QString complete_name = fileNames[0];
134 if ( !complete_name.endsWith(
".ini", Qt::CaseInsensitive) && !complete_name.endsWith(
".obj", Qt::CaseInsensitive) ){
137 if ( fileDialog.selectedNameFilter().contains(tr(
"INI files (*.ini)")) )
138 complete_name +=
".ini";
140 complete_name +=
".obj";
144 bool is_saveObjectInfo = saveObjectInfo->isChecked();
145 bool is_targetOnly = targetOnly->isChecked();
146 bool is_saveAll = saveAllBox->isChecked();
147 bool is_askOverwrite = askOverwrite->isChecked();
148 bool is_saveProgramSettings = saveProgramSettings->isChecked();
149 bool is_savePluginSettings = savePluginSettings->isChecked();
151 saveSettings(complete_name, is_saveObjectInfo, is_targetOnly, is_saveAll, is_askOverwrite, is_saveProgramSettings, is_savePluginSettings);
154 void Core::saveSettings(QString complete_name,
bool is_saveObjectInfo,
bool is_targetOnly,
bool is_saveAll,
155 bool is_askOverwrite,
bool is_saveProgramSettings,
bool is_savePluginSettings){
157 QFileInfo fileInfo(complete_name);
163 OpenFlipper::Options::savingSettings(
true);
165 if ( OpenFlipper::Options::gui() ) {
166 coreWidget_->statusMessage( tr(
"Saving Settings to ") + complete_name +
" ...");
176 std::map<int,QString> savedFiles;
178 if ( is_saveObjectInfo ) {
187 std::multiset<QString> originalFiles;
190 std::map<DataType,QString> defaultExtensions;
192 QMultiMap<DataType,QString> allFilters;
193 const std::vector<fileTypes>& types = supportedTypes();
194 for (
int i=0; i < (int)types.size(); i++) {
195 QString filters = types[i].saveFilters;
198 filters = filters.section(
"(",1).section(
")",0,0);
199 if (filters.trimmed() ==
"")
202 QStringList separateFilters = filters.split(
" ");
204 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
205 if (separateFilters[filterId].trimmed() ==
"")
209 allFilters.insert(types[i].type,separateFilters[filterId]);
213 allFilters.insert(types[i].type,filters);
218 QGridLayout extensionLayout;
219 const QString extensionCheckBoxPrefixString =
"Apply extension to all Objects without preset extensions with DataType: ";
220 QCheckBox extensionCheckBox;
221 QComboBox extensionComboBox;
222 QDialogButtonBox extensionButtons(QDialogButtonBox::Ok);
223 QDialogButtonBox::connect(&extensionButtons, SIGNAL(accepted()), &extensionDialog, SLOT(accept()));
225 extensionLayout.addWidget(&extensionComboBox);
226 extensionLayout.addWidget(&extensionCheckBox);
227 extensionLayout.addWidget(&extensionButtons);
228 extensionDialog.setLayout(&extensionLayout);
239 filename = fileInfo.absolutePath() + OpenFlipper::Options::dirSeparator() + o_it->name();
244 filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
247 if (o_it->path() ==
".") {
248 filename = fileInfo.absolutePath() + OpenFlipper::Options::dirSeparator() + o_it->name();
249 std::cerr <<
"newpath : " << fileInfo.absolutePath().toStdString() << std::endl;
250 std::cerr <<
"name : " << o_it->name().toStdString() << std::endl;
255 if ( complete_name.endsWith(
"obj") )
257 if (!filename.endsWith(
"obj"))
260 int pos = filename.lastIndexOf(
".");
261 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() )
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.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
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.
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.