Commit bf82dec6 authored by Isaak Lim's avatar Isaak Lim

- adjusted the openFunctions and loadWidget to handle several plugins than can...

- adjusted the openFunctions and loadWidget to handle several plugins than can load the same file format
- a default plugin choice for each file format can also be saved via OpenFlipperSettings

refs #1274

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16701 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e5590d7f
......@@ -309,7 +309,8 @@ int Core::loadObject( DataType _type, QString _filename) {
QFileInfo fi(_filename);
for (int i=0; i < (int)supportedTypes().size(); i++)
std::vector<int> typeIds;
for (int i=0; i < (int)supportedTypes().size(); i++) {
if (supportedTypes()[i].type & _type || supportedTypes()[i].type == _type) {
QString filters = supportedTypes()[i].plugin->getLoadFilters();
......@@ -320,69 +321,96 @@ int Core::loadObject( DataType _type, QString _filename) {
// Split into blocks
QStringList separateFilters = filters.split(" ");
bool found = false;
// for all filters associated with this plugin
for ( int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
separateFilters[filterId] = separateFilters[filterId].trimmed();
//check extension
if ( separateFilters[filterId].endsWith( "*." + fi.completeSuffix() , Qt::CaseInsensitive) ) {
found = true;
break;
typeIds.push_back(i);
continue;
}
if ( separateFilters[filterId].endsWith( "*." + fi.suffix() , Qt::CaseInsensitive) ) {
found = true;
typeIds.push_back(i);
emit log(LOGWARN,"Found supported datatype but only the suffix is matched not the complete suffix!");
break;
continue;
}
}
}
}
// continue processing only if found
if ( ! found )
continue;
// load file with plugins
int nPlugins = typeIds.size();
if (nPlugins > 0) {
int i = -1;
// several plugins can load this type
if (nPlugins > 1) {
// let the user choose the plugin for loading
if ( OpenFlipper::Options::gui() ) {
coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
coreWidget_->setStatus(ApplicationStatus::PROCESSING );
QStringList items;
for (int j = 0; j < nPlugins; ++j) {
items << supportedTypes()[typeIds[j]].name;
}
bool ok;
QString item = QInputDialog::getItem(coreWidget_, tr("File Plugins"),
tr("Please choose a plugin for loading:"), items, 0, false, &ok);
if (!ok) {
emit log(LOGERR, tr("Unable to load object. No suitable plugin found!") );
return -1; //no plugin found
} else
i = typeIds[items.indexOf(item)];
}
// if there is no gui just take the first one for now
else {
i = 0;
}
} else
i = typeIds[0];
int id = -1;
if ( OpenFlipper::Options::gui() ) {
coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
coreWidget_->setStatus(ApplicationStatus::PROCESSING );
}
//load file
if ( checkSlot( supportedTypes()[i].object , "loadObject(QString,DataType)" ) )
id = supportedTypes()[i].plugin->loadObject(_filename, _type);
else
id = supportedTypes()[i].plugin->loadObject(_filename);
int id = -1;
if ( OpenFlipper::Options::gui() ) {
if ( id != -1 ) {
coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
// Get the object to figure out the data type
BaseObject* object;
PluginFunctions::getObject(id,object);
// Add to recent files with the given datatype
if ( OpenFlipper::Options::gui() )
coreWidget_->addRecent(_filename, object->dataType());
} else
coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );
//load file
if ( checkSlot( supportedTypes()[i].object , "loadObject(QString,DataType)" ) )
id = supportedTypes()[i].plugin->loadObject(_filename, _type);
else
id = supportedTypes()[i].plugin->loadObject(_filename);
if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
coreWidget_->setStatus(ApplicationStatus::READY );
}
if ( OpenFlipper::Options::gui() ) {
if ( id != -1 ) {
coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
return id;
// Get the object to figure out the data type
BaseObject* object;
PluginFunctions::getObject(id,object);
// Add to recent files with the given datatype
if ( OpenFlipper::Options::gui() )
coreWidget_->addRecent(_filename, object->dataType());
} else
coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );
if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
coreWidget_->setStatus(ApplicationStatus::READY );
}
emit log(LOGERR, tr("Unable to load object. No suitable plugin found!") );
return -1; //no plugin found
return id;
} else {
emit log(LOGERR, tr("Unable to load object. No suitable plugin found!") );
return -1; //no plugin found
}
}
......
......@@ -51,7 +51,8 @@ FileOptionsDialog::FileOptionsDialog(std::vector<fileTypes>& _supportedTypes, QS
: QDialog(parent),
ext_(_extensions),
supportedTypes_(_supportedTypes),
loadMode_(_loadMode)
loadMode_(_loadMode),
defaultPluginBox_(NULL)
{
ext_.removeDuplicates();
......@@ -98,14 +99,21 @@ FileOptionsDialog::FileOptionsDialog(std::vector<fileTypes>& _supportedTypes, QS
if (count > 1){
QLabel* label = new QLabel( tr("For *.%1 use plugin ").arg(ext_[i]) );
QComboBox* box = new QComboBox();
defaultPluginBox_ = new QCheckBox(tr("Make this plugin the default"));
box->addItems(names);
box->setAccessibleName(ext_[i]);
currentName_ = box->currentText();
currentExtension_ = ext_[i];
grid->addWidget(label, grid->rowCount(), 0);
grid->addWidget(box, grid->rowCount()-1, 1);
grid->addWidget(defaultPluginBox_, grid->rowCount()+1, 0);
connect(box, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotPluginChanged(QString)) );
connect(defaultPluginBox_, SIGNAL(stateChanged(int)), this, SLOT(slotPluginDefault(int)) );
boxes_.push_back(box);
}
}
......@@ -191,8 +199,16 @@ int FileOptionsDialog::exec(){
if ( tabs_.count() == 0 && boxes_.count() == 0 )
return QDialog::Accepted;
else
else {
return QDialog::exec();
}
}
bool FileOptionsDialog::makePluginDefault() {
if (!defaultPluginBox_)
return false;
return defaultPluginBox_->isChecked();
}
void FileOptionsDialog::slotPluginChanged(QString _name){
......@@ -201,9 +217,25 @@ void FileOptionsDialog::slotPluginChanged(QString _name){
for (unsigned int t=0; t < supportedTypes_.size(); t++)
if ( supportedTypes_[t].name == _name ){
currentName_ = _name;
currentExtension_ = box->accessibleName();
if (makePluginDefault()) {
OpenFlipperSettings().setValue(QString("Core/File/DefaultLoader/").append(currentExtension_), currentName_);
}
emit setPluginForExtension(box->accessibleName(), t ); //accessibleName contains the extension
break;
}
}
void FileOptionsDialog::slotPluginDefault(int _state) {
// store the name of the default plugin for loading
if (_state == Qt::Checked) {
OpenFlipperSettings().setValue(QString("Core/File/DefaultLoader/").append(currentExtension_), currentName_);
} else {
OpenFlipperSettings().setValue(QString("Core/File/DefaultLoader/").append(currentExtension_), "");
}
}
......@@ -61,14 +61,24 @@ class FileOptionsDialog : public QDialog
private slots:
void slotPluginChanged(QString _name);
void slotPluginDefault(int _state);
signals:
void setPluginForExtension(QString _extension, int _pluginId );
public slots:
int exec();
bool makePluginDefault();
private:
bool loadMode_;
QString currentName_;
QString currentExtension_;
QVector< QComboBox* > boxes_;
};
\ No newline at end of file
QCheckBox* defaultPluginBox_;
};
......@@ -246,6 +246,7 @@ void LoadWidget::loadFile(){
return;
}
//load the selected files
for (int i=0; i < files.size(); i++){
......@@ -257,11 +258,27 @@ void LoadWidget::loadFile(){
if (fi.isDir() || !file.exists()) continue; //do nothing if its a not a valid file
QString ext = fi.suffix();
// if the default options should be used find the default plugin
if (optionsBox_->isChecked()) {
QString pluginName = OpenFlipperSettings().value(QString("Core/File/DefaultLoader/").append(ext)).toString();
//emit load signal
if ( pluginForExtension_.find( fi.suffix() ) != pluginForExtension_.end() ){
// find the id of the plugin
bool found = false;
unsigned int j;
for (j = 0; j < supportedTypes_.size(); ++j) {
if (supportedTypes_[j].name == pluginName) {
found = true;
break;
}
}
if (found)
pluginForExtension_[ ext ] = j;
}
emit load(filename, pluginForExtension_[ fi.suffix() ]);
//emit load signal
if ( pluginForExtension_.find( ext ) != pluginForExtension_.end() ){
emit load(filename, pluginForExtension_[ ext ]);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment