saveSettings.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "Core.hh"
00045
00046 #include "OpenFlipper/common/GlobalOptions.hh"
00047
00048 #include "OpenFlipper/BasePlugin/PluginFunctions.hh"
00049
00050 #include "OpenFlipper/widgets/loadWidget/loadWidget.hh"
00051
00052 #include <QFileDialog>
00053 #include <QGroupBox>
00054 #include <QBoxLayout>
00055
00057 void Core::saveSettings(){
00058
00059
00060
00061
00062
00063 QString complete_name;
00064
00065 QFileDialog fileDialog( coreWidget_,
00066 tr("Save Settings"),
00067 OpenFlipper::Options::currentDirStr(),
00068 tr("INI files (*.ini);;OBJ files (*.obj )") );
00069
00070 fileDialog.setOption (QFileDialog::DontUseNativeDialog, true);
00071 fileDialog.setAcceptMode ( QFileDialog::AcceptSave );
00072 fileDialog.setFileMode ( QFileDialog::AnyFile );
00073
00074 QGridLayout *layout = (QGridLayout*)fileDialog.layout();
00075
00076 QGroupBox* optionsBox = new QGroupBox( &fileDialog ) ;
00077 optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
00078 optionsBox->setTitle(tr("Options"));
00079 layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
00080
00081 QCheckBox *saveProgramSettings = new QCheckBox(optionsBox);
00082 saveProgramSettings->setText(tr("Save program settings"));
00083 saveProgramSettings->setToolTip(tr("Save all current program settings to the file ( This will include view settings, colors,...) "));
00084 saveProgramSettings->setCheckState( Qt::Unchecked );
00085
00086 QCheckBox *savePluginSettings = new QCheckBox(optionsBox);
00087 savePluginSettings->setText(tr("Save per Plugin Settings"));
00088 savePluginSettings->setToolTip(tr("Plugins should add their current global settings to the file"));
00089 savePluginSettings->setCheckState( Qt::Checked );
00090
00091 QCheckBox *saveObjectInfo = new QCheckBox(optionsBox);
00092 saveObjectInfo->setText(tr("Save open object information to the file"));
00093 saveObjectInfo->setToolTip(tr("Save all open Objects and add them to the settings file ( they will be loaded if opening the settings file"));
00094 saveObjectInfo->setCheckState( Qt::Checked );
00095
00096 QCheckBox *saveAllBox = new QCheckBox(optionsBox);
00097 saveAllBox->setText(tr("Save everything to same folder"));
00098 saveAllBox->setToolTip(tr("Save all open files to the same folder as the ini file"));
00099 saveAllBox->setCheckState( Qt::Checked );
00100
00101 QCheckBox *askOverwrite = new QCheckBox(optionsBox);
00102 askOverwrite->setText(tr("Ask before overwriting files"));
00103 askOverwrite->setToolTip(tr("If a file exists you will get asked what to do"));
00104 askOverwrite->setCheckState( Qt::Checked );
00105
00106 QCheckBox *targetOnly = new QCheckBox(optionsBox);
00107 targetOnly->setText(tr("Save only target objects"));
00108 targetOnly->setToolTip(tr("Only objects with target flag will be handled"));
00109 targetOnly->setCheckState( Qt::Unchecked );
00110
00111 QBoxLayout* frameLayout = new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
00112 frameLayout->addWidget( saveProgramSettings , 0 , 0);
00113 frameLayout->addWidget( savePluginSettings , 1 , 0);
00114 frameLayout->addWidget( saveObjectInfo , 2 , 0);
00115 frameLayout->addWidget( saveAllBox , 3 , 0);
00116 frameLayout->addWidget( askOverwrite , 4 , 0);
00117 frameLayout->addWidget( targetOnly , 5 , 0);
00118 frameLayout->addStretch();
00119
00120 fileDialog.resize(550 ,600);
00121
00122
00123
00124
00125 QStringList fileNames;
00126 if (fileDialog.exec()) {
00127 fileNames = fileDialog.selectedFiles();
00128 } else {
00129 return;
00130 }
00131
00132 if ( fileNames.size() > 1 ) {
00133 std::cerr << "Too many save filenames selected" << std::endl;
00134 return;
00135 }
00136
00137 complete_name = fileNames[0];
00138
00139
00140 if ( !complete_name.endsWith(".ini", Qt::CaseInsensitive) && !complete_name.endsWith(".obj", Qt::CaseInsensitive) ){
00141
00142
00143 if ( fileDialog.selectedNameFilter().contains(tr("INI files (*.ini)")) )
00144 complete_name += ".ini";
00145 else
00146 complete_name += ".obj";
00147
00148 }
00149
00150
00151 QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
00152 OpenFlipper::Options::currentDir(newpath);
00153
00154
00155
00156
00157 OpenFlipper::Options::savingSettings(true);
00158
00159 if ( OpenFlipper::Options::gui() ) {
00160 coreWidget_->statusMessage( tr("Saving Settings to ") + complete_name + " ...");
00161 coreWidget_->setStatus(ApplicationStatus::BLOCKED );
00162 }
00163
00164
00165
00166
00167
00168
00169 if ( saveObjectInfo->isChecked() ) {
00170
00171 PluginFunctions::IteratorRestriction restriction;
00172 if ( targetOnly->isChecked() )
00173 restriction = PluginFunctions::TARGET_OBJECTS;
00174 else
00175 restriction = PluginFunctions::ALL_OBJECTS;
00176
00177
00178 for ( PluginFunctions::ObjectIterator o_it(restriction);
00179 o_it != PluginFunctions::objectsEnd(); ++o_it)
00180 {
00181 QString filename;
00182
00183 if ( saveAllBox->isChecked() )
00184 {
00185
00186 filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
00187 }
00188 else
00189 {
00190
00191 filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
00192
00193
00194 if (o_it->path() == ".") {
00195 filename = newpath + OpenFlipper::Options::dirSeparator() + o_it->name();
00196 std::cerr << "newpath : " << newpath.toStdString() << std::endl;
00197 std::cerr << "name : " << o_it->name().toStdString() << std::endl;
00198 }
00199 }
00200
00201
00202 if ( complete_name.endsWith("obj") )
00203 {
00204 if (!filename.endsWith("obj"))
00205 {
00206
00207 int pos = filename.lastIndexOf(".");
00208 filename.remove(pos+1, filename.length() - pos);
00209
00210 filename += "obj";
00211 }
00212 }
00213
00214
00215 if ( !QFile(filename).exists() || !askOverwrite->isChecked() )
00216 saveObject( o_it->id(), filename);
00217 else
00218 saveObjectTo(o_it->id(), filename);
00219
00220 }
00221 }
00222
00223
00224
00225
00226
00227 if ( complete_name.endsWith("ini") ) {
00228
00229
00230 writeIniFile( complete_name,
00231 saveAllBox->isChecked(),
00232 targetOnly->isChecked(),
00233 saveProgramSettings->isChecked(),
00234 savePluginSettings->isChecked(),
00235 saveObjectInfo->isChecked());
00236
00237 } else if ( complete_name.endsWith("obj") ) {
00238
00239
00240 writeObjFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked() );
00241
00242 }
00243
00244
00245 OpenFlipper::Options::savingSettings(false);
00246
00247 if ( OpenFlipper::Options::gui() ) {
00248 coreWidget_->statusMessage( tr("Saving Settings to ") + complete_name + tr(" ... Done"), 4000);
00249 coreWidget_->setStatus(ApplicationStatus::READY );
00250 }
00251
00252
00253 if ( OpenFlipper::Options::gui() )
00254 coreWidget_->addRecent( complete_name, DATA_UNKNOWN );
00255
00256 }