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
00104 bool Core::saveObjectTo( int _id, QString _filename ) {
00105
00106 bool result = false;
00107
00108 if ( OpenFlipper::Options::gui() ){
00109
00110 BaseObjectData* object;
00111 PluginFunctions::getObject(_id,object);
00112
00113
00114 LoadWidget* widget = new LoadWidget(supportedTypes_);
00115 widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
00116
00117 connect(widget,SIGNAL(load(QString, DataType, int&)),this,SLOT(slotLoad(QString, DataType, int&)));
00118 connect(widget,SIGNAL(save(int, QString)),this,SLOT(saveObject(int, QString)));
00119
00120 if (supportedTypes_.size() != 0)
00121 result = widget->showSave(_id,_filename);
00122 else
00123 emit log(LOGERR,tr("Could not show 'save objects' dialog. Missing file-plugins."));
00124
00125 widget->disconnect();
00126 delete widget;
00127 }
00128
00129 return result;
00130 }
00131
00132
00133
00135 void Core::saveAllObjects(){
00136
00137 if ( OpenFlipper::Options::gui() ){
00138
00139
00140 for (int i=0; i < (int)supportedTypes_.size(); i++)
00141 supportedTypes_[i].plugin->saveOptionsWidget("");
00142
00143
00144 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ;
00145 o_it != PluginFunctions::objectsEnd(); ++o_it) {
00146
00147 if ( !QDir(o_it->path()).exists() || o_it->path().trimmed() == "" )
00148 saveObjectTo(o_it->id(),o_it->name());
00149 else{
00150
00151 QString filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name() ;
00152 saveObject(o_it->id(),filename);
00153 }
00154 }
00155 }
00156 }
00157
00158
00159
00161 void Core::saveAllObjectsTo(){
00162 if ( OpenFlipper::Options::gui() ){
00163 if (supportedTypes_.size() != 0){
00164
00165 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS);
00166 o_it != PluginFunctions::objectsEnd(); ++o_it) {
00167 QString filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
00168 saveObjectTo(o_it->id(),filename);
00169 }
00170 }else
00171 emit log(LOGERR,tr("Could not show 'save objects' dialog. Missing file-plugins."));
00172 }
00173 }
00174
00175
00176