saveFunctions.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
00053
00054
00055
00059 bool Core::saveObject( int _id, QString _filename ) {
00060 BaseObjectData* object;
00061 PluginFunctions::getObject(_id,object);
00062
00063 for (int i=0; i < (int)supportedTypes_.size(); i++)
00064 if (object->dataType() == supportedTypes_[i].type) {
00065
00066 if ( OpenFlipper::Options::gui() ) {
00067 coreWidget_->statusMessage( tr("Saving ") + _filename + " ...");
00068 if ( !OpenFlipper::Options::savingSettings() )
00069 coreWidget_->setStatus(ApplicationStatus::PROCESSING );
00070 }
00071
00072
00073 bool ok = supportedTypes_[i].plugin->saveObject(_id,_filename);
00074
00075 if ( OpenFlipper::Options::gui() ) {
00076 if (ok)
00077 coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... done"), 4000 );
00078 else
00079 coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... failed!"), 4000 );
00080
00081 if ( !OpenFlipper::Options::savingSettings() )
00082 coreWidget_->setStatus(ApplicationStatus::READY );
00083 }
00084
00085
00086 if (ok && !OpenFlipper::Options::savingSettings()
00087 && OpenFlipper::Options::gui() )
00088 coreWidget_->addRecent( _filename, object->dataType() );
00089
00090 return ok;
00091 }
00092
00093
00094 if ( OpenFlipper::Options::gui() )
00095 coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... failed!"), 4000 );
00096
00097 return false;
00098 }
00099
00100
00101
00105 void Core::saveObject( int _id, QString _filename, int _pluginID ) {
00106 BaseObjectData* object;
00107 PluginFunctions::getObject(_id,object);
00108
00109
00110 if ( OpenFlipper::Options::gui() ) {
00111 coreWidget_->statusMessage( tr("Saving ") + _filename + " ...");
00112 if ( !OpenFlipper::Options::savingSettings() )
00113 coreWidget_->setStatus(ApplicationStatus::PROCESSING );
00114 }
00115
00116
00117 bool ok = supportedTypes_[_pluginID].plugin->saveObject(_id,_filename);
00118
00119 if ( OpenFlipper::Options::gui() ) {
00120 if (ok)
00121 coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... done"), 4000 );
00122 else
00123 coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... failed!"), 4000 );
00124
00125 if ( !OpenFlipper::Options::savingSettings() )
00126 coreWidget_->setStatus(ApplicationStatus::READY );
00127 }
00128
00129
00130 if (ok && !OpenFlipper::Options::savingSettings()
00131 && OpenFlipper::Options::gui() )
00132 coreWidget_->addRecent( _filename, object->dataType() );
00133
00134 }
00135
00136
00137
00140 bool Core::saveObjectTo( int _id, QString _filename ) {
00141
00142 bool result = false;
00143
00144 if ( OpenFlipper::Options::gui() ){
00145
00146 BaseObjectData* object;
00147 PluginFunctions::getObject(_id,object);
00148
00149
00150 LoadWidget* widget = new LoadWidget(supportedTypes_);
00151 widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
00152
00153 connect(widget,SIGNAL(load(QString, int)),this,SLOT(slotLoad(QString, int)));
00154 connect(widget,SIGNAL(save(int, QString, int)),this,SLOT(saveObject(int, QString, int)));
00155
00156 if (supportedTypes_.size() != 0)
00157 result = widget->showSave(_id,_filename);
00158 else
00159 emit log(LOGERR,tr("Could not show 'save objects' dialog. Missing file-plugins."));
00160
00161 widget->disconnect();
00162 delete widget;
00163 }
00164
00165 return result;
00166 }
00167
00168
00169
00171 void Core::saveAllObjects(){
00172
00173 if ( OpenFlipper::Options::gui() ){
00174
00175
00176 for (int i=0; i < (int)supportedTypes_.size(); i++)
00177 supportedTypes_[i].plugin->saveOptionsWidget("");
00178
00179
00180 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ;
00181 o_it != PluginFunctions::objectsEnd(); ++o_it) {
00182
00183 if ( !QDir(o_it->path()).exists() || o_it->path().trimmed() == "" )
00184 saveObjectTo(o_it->id(),o_it->name());
00185 else{
00186
00187 QString filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name() ;
00188 saveObject(o_it->id(),filename);
00189 }
00190 }
00191 }
00192 }
00193
00194
00195
00197 void Core::saveAllObjectsTo(){
00198 if ( OpenFlipper::Options::gui() ){
00199 if (supportedTypes_.size() != 0){
00200
00201 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS);
00202 o_it != PluginFunctions::objectsEnd(); ++o_it) {
00203 QString filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
00204 saveObjectTo(o_it->id(),filename);
00205 }
00206 }else
00207 emit log(LOGERR,tr("Could not show 'save objects' dialog. Missing file-plugins."));
00208 }
00209 }
00210
00211
00212