loadWidget.cc 15.6 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40
41
\*===========================================================================*/

42

Jan Möbius's avatar
 
Jan Möbius committed
43
44
45
46
47
48




#include "loadWidget.hh"

Dirk Wilden's avatar
Dirk Wilden committed
49
50
#include "FileOptionsDialog.hh"

Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
51
52
#include <QFileInfo>

Jan Möbius's avatar
 
Jan Möbius committed
53
54
55
56
57
LoadWidget::LoadWidget(std::vector<fileTypes>& _supportedTypes , QWidget *parent)
  : QFileDialog(parent),
    loadMode_(true),
    supportedTypes_(_supportedTypes)
{
58
  setOption (QFileDialog::DontUseNativeDialog, true);
Jan Möbius's avatar
 
Jan Möbius committed
59
60
61
62
63

  // Get our layout
  QGridLayout *gridLayout = (QGridLayout*)layout();

  //supported Types
Dirk Wilden's avatar
Dirk Wilden committed
64
  optionsBox_ = new QCheckBox(tr("use defaults"), this);
Jan Möbius's avatar
Jan Möbius committed
65
  optionsBox_->setChecked( OpenFlipperSettings().value("Core/File/UseLoadDefaults",false).toBool() );
Dirk Wilden's avatar
Dirk Wilden committed
66
  
Dirk Wilden's avatar
Dirk Wilden committed
67
68
  // add the options box to the bottom
  gridLayout->addWidget( optionsBox_, gridLayout->rowCount() , 1 );
Jan Möbius's avatar
 
Jan Möbius committed
69

Dirk Wilden's avatar
Dirk Wilden committed
70
71
  // Add a very nice label for it
  QLabel* typeLabel = new QLabel(tr("Options:") , this);
Jan Möbius's avatar
 
Jan Möbius committed
72
73
74
75
76
  gridLayout->addWidget( typeLabel, gridLayout->rowCount() -1 , 0 );

  //overwrite dialog shouldn't be handled by the qfiledialog
  setConfirmOverwrite(false);

77
  setDirectory( OpenFlipperSettings().value("Core/CurrentDir").toString() );
Jan Möbius's avatar
 
Jan Möbius committed
78
79
}

80
/// Destructor
81
82
LoadWidget::~LoadWidget()
{
Dirk Wilden's avatar
Dirk Wilden committed
83

Dirk Wilden's avatar
Dirk Wilden committed
84
}
Dirk Wilden's avatar
Dirk Wilden committed
85

Dirk Wilden's avatar
Dirk Wilden committed
86
87
/// adjust load-filters to current datatype
void LoadWidget::slotSetLoadFilters(){
Dirk Wilden's avatar
Dirk Wilden committed
88

Dirk Wilden's avatar
Dirk Wilden committed
89
  QStringList allFilters;
Dirk Wilden's avatar
Dirk Wilden committed
90

Dirk Wilden's avatar
Dirk Wilden committed
91
92
93
94
95
96
97
  //TODO All files filter
  
  for (int i=0; i < (int)supportedTypes_.size(); i++){
    QStringList filters = supportedTypes_[i].loadFilters.split(";;");
    for (int f=filters.size()-1; f >= 0;  f--){
      if (filters[f].trimmed() == "") { filters.removeAt(f); continue; }
      if (filters[f].contains( tr("All files") ) ) filters.removeAt(f);
Dirk Wilden's avatar
Dirk Wilden committed
98
99
    }

Dirk Wilden's avatar
Dirk Wilden committed
100
    allFilters.append( filters );
Jan Möbius's avatar
 
Jan Möbius committed
101
102
  }

Dirk Wilden's avatar
Dirk Wilden committed
103
104
  allFilters.removeDuplicates();
  allFilters.sort();
Jan Möbius's avatar
 
Jan Möbius committed
105

Dirk Wilden's avatar
Dirk Wilden committed
106
107
108
109
110
111
112
  QStringList allExt;
  
  //get all possible extensions
  for (int i=0; i < allFilters.size(); i++){
     QString ext = allFilters[i].section("(",1).section(")",0,0);
     allExt.append( ext.split(" ") );
  }
Jan Möbius's avatar
 
Jan Möbius committed
113

Dirk Wilden's avatar
Dirk Wilden committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  for (int f=allExt.size()-1; f >= 0;  f--)
    if (allExt[f].trimmed() == "") allExt.removeAt(f);
  
  allExt.removeDuplicates();
  allExt.sort();
  
  QString allFiles = tr("All Files (");
  
  for (int i=0; i < allExt.size(); i++)
    allFiles += " " + allExt[i];
  
  allFiles += " )";

  allFilters.push_front(allFiles);
  
  setNameFilters(allFilters);
Jan Möbius's avatar
 
Jan Möbius committed
130
131
132
}

/// adjust save-filters to current datatype
Dirk Wilden's avatar
Dirk Wilden committed
133
void LoadWidget::slotSetSaveFilters(DataType _type){
Jan Möbius's avatar
 
Jan Möbius committed
134

Dirk Wilden's avatar
Dirk Wilden committed
135
  QStringList allFilters;
Dirk Wilden's avatar
Dirk Wilden committed
136

137
138
  bool multipleFiles = (ids_.size() > 1);
  
Jan Möbius's avatar
 
Jan Möbius committed
139
  for (int i=0; i < (int)supportedTypes_.size(); i++)
140
141
142
143
144
     if ( supportedTypes_[i].type.contains(_type) ){
       
       if ( multipleFiles && !supportedTypes_[i].saveMultipleObjects)
         continue;

Jan Möbius's avatar
 
Jan Möbius committed
145
      QStringList filters = supportedTypes_[i].saveFilters.split(";;");
Dirk Wilden's avatar
Dirk Wilden committed
146
147
148
      for (int f=filters.size()-1; f >= 0;  f--){
        if (filters[f].trimmed() == "") { filters.removeAt(f); continue; }
        if (filters[f].contains( tr("All files") ) ) filters.removeAt(f);
Jan Möbius's avatar
 
Jan Möbius committed
149
      }
150
      
Dirk Wilden's avatar
Dirk Wilden committed
151
      allFilters.append( filters );
Jan Möbius's avatar
 
Jan Möbius committed
152
153
    }

Dirk Wilden's avatar
Dirk Wilden committed
154
155
  allFilters.removeDuplicates();
  allFilters.sort();
Jan Möbius's avatar
 
Jan Möbius committed
156

Dirk Wilden's avatar
Dirk Wilden committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  QStringList allExt;
  
  //get all possible extensions
  for (int i=0; i < allFilters.size(); i++){
     QString ext = allFilters[i].section("(",1).section(")",0,0);
     allExt.append( ext.split(" ") );
  }

  for (int f=allExt.size()-1; f >= 0;  f--)
    if (allExt[f].trimmed() == "") allExt.removeAt(f);
  
  allExt.removeDuplicates();
  allExt.sort();
  
  QString allFiles = tr("All Files (");
  
  for (int i=0; i < allExt.size(); i++)
    allFiles += " " + allExt[i];
  
  allFiles += " )";

  allFilters.push_front(allFiles);
  
  setNameFilters(allFilters);
}
Jan Möbius's avatar
 
Jan Möbius committed
182
183
184
185


/// find suitable plugin for loading current file
void LoadWidget::loadFile(){
186
  
Jan Möbius's avatar
 
Jan Möbius committed
187
188
189
  //get selection
  QStringList files = selectedFiles();

Dirk Wilden's avatar
Dirk Wilden committed
190
191
192
193
194
195
196
197
198
199
200
  //get all extensions
  QStringList ext;

  for (int i=0; i < files.size(); i++)
    ext.push_back( QFileInfo(files[i]).suffix() );
  
   
  //find plugins that can handle the current extensions
  pluginForExtension_.clear();
  
  for (int i=0; i < ext.size(); i++){
201

Dirk Wilden's avatar
Dirk Wilden committed
202
203
204
    for (uint t=0; t < supportedTypes_.size(); t++){
      
      QString filters = supportedTypes_[t].loadFilters;  
205

206
207
208
209
210
211
212
213
214
      // Take only part inside brackets
      filters = filters.section("(",1).section(")",0,0);

      QStringList separateFilters = filters.split(" ");

      bool found = false;

      for ( int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {

215
        if (separateFilters[filterId].endsWith("*." + ext[i],Qt::CaseInsensitive)){
216
217
218
219
          pluginForExtension_[ ext[i] ] = t;
          found = true;
        }

Dirk Wilden's avatar
Dirk Wilden committed
220
      }
221
222
223
224

      if ( found )
        break;

Dirk Wilden's avatar
Dirk Wilden committed
225
226
    }
  }
Jan Möbius's avatar
Jan Möbius committed
227

Dirk Wilden's avatar
Dirk Wilden committed
228
229
230
231
232
233
234
235
236
237
238
  // display options for all dataTypes
  if ( !optionsBox_->isChecked() ){

    FileOptionsDialog options(supportedTypes_,ext, loadMode_);

    connect(&options, SIGNAL(setPluginForExtension(QString,int)), this, SLOT(slotSetPluginForExtension(QString,int)) );

    if ( !options.exec() )
      return;
  }

239

Dirk Wilden's avatar
Dirk Wilden committed
240
  //load the selected files
Matthias Möller's avatar
Matthias Möller committed
241
242
  QStringList loadableFiles;
  IdList pluginIds;
Jan Möbius's avatar
 
Jan Möbius committed
243
  for (int i=0; i < files.size(); i++){
Dirk Wilden's avatar
Dirk Wilden committed
244
    
Jan Möbius's avatar
 
Jan Möbius committed
245
246
    QFileInfo fi(files[i]);
    QString filename = fi.absoluteFilePath();
247
    OpenFlipperSettings().setValue("Core/CurrentDir", fi.absolutePath());
Jan Möbius's avatar
 
Jan Möbius committed
248
    QFile file(filename);
249

Jan Möbius's avatar
 
Jan Möbius committed
250
251
252
    if (fi.isDir() || !file.exists()) continue; //do nothing if its a not a valid file
    QString ext = fi.suffix();

253
254
255
    // 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();
256

257
258
259
260
261
262
263
264
265
266
267
268
269
      // 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;
    }
270

271
272
273
    //emit load signal
    if ( pluginForExtension_.find( ext ) != pluginForExtension_.end() ){
      emit load(filename, pluginForExtension_[ ext ]);
Matthias Möller's avatar
Matthias Möller committed
274
275
      loadableFiles.push_back(filename);
      pluginIds.push_back(pluginForExtension_[ext]);
Dirk Wilden's avatar
Dirk Wilden committed
276
277
    }
  }
Matthias Möller's avatar
Matthias Möller committed
278
  emit loadFiles(loadableFiles, pluginIds);
Jan Möbius's avatar
 
Jan Möbius committed
279
280
281
282
283
284
285
286
}

/// find suitable plugin for saving current file
void LoadWidget::saveFile(){
  //get selection
  QStringList files = selectedFiles();

  if ( files.size() != 1 ) {
Marlin Frickenschmidt's avatar
Marlin Frickenschmidt committed
287
    std::cerr << "Error: zero or multiple save files selected!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
288
289
290
291
292
    return;
  }

  QString filename = files[0];

Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
293
  if (QFileInfo(filename).completeSuffix().isEmpty()) {
Jan Möbius's avatar
 
Jan Möbius committed
294

295
296
297
    int s = selectedNameFilter().indexOf("*")+1;
    int e = selectedNameFilter().indexOf(" ", s);
    int e2 = selectedNameFilter().indexOf(")", s);
Dirk Wilden's avatar
Dirk Wilden committed
298
299
    if (e == -1 || e2 < e) e = e2;

300
    QString ext = selectedNameFilter().mid(s,e-s);
Jan Möbius's avatar
 
Jan Möbius committed
301
302
303
    filename += ext;
  }

Dirk Wilden's avatar
Dirk Wilden committed
304
305
306
307
308
309
310
311
  QFile      f(filename);
  QFileInfo fi(filename);
   
  //find plugin that can handle the current extension
  pluginForExtension_.clear();
  
  for (uint t=0; t < supportedTypes_.size(); t++){

312
    QString filters = supportedTypes_[t].saveFilters;  
Dirk Wilden's avatar
Dirk Wilden committed
313

314
315
316
317
318
319
320
321
322
323
324
325
326
327
    // Take only part inside brackets
    filters = filters.section("(",1).section(")",0,0);

    QStringList separateFilters = filters.split(" ");

    bool found = false;

    for ( int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {

      if (separateFilters[filterId].endsWith(fi.suffix(),Qt::CaseInsensitive)){
        pluginForExtension_[ fi.suffix() ] = t;
        found = true;
      }

Dirk Wilden's avatar
Dirk Wilden committed
328
    }
329
330
331
332

    if ( found )
      break;

Dirk Wilden's avatar
Dirk Wilden committed
333
334
335
336
337
338
339
340
341
342
343
344
345
  }
  
  // display options for all dataTypes
  if ( !optionsBox_->isChecked() ){

    FileOptionsDialog options(supportedTypes_,QStringList(fi.suffix()), loadMode_);

    connect(&options, SIGNAL(setPluginForExtension(QString,int)), this, SLOT(slotSetPluginForExtension(QString,int)) );

    if ( !options.exec() )
      return;
  }

Jan Möbius's avatar
 
Jan Möbius committed
346
347
348
349
350
351
352
  if (f.exists()){ //check for extension
    int ret = QMessageBox::warning(this, tr("File exists"),tr("This file already exists.\n"
        "Do you want to overwrite the file?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::No);
    if (ret == QMessageBox::No)
      return; //abort if users doesn't want to overwrite
  }

Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
353
354
355
  const std::map< QString, int >::iterator saving_plugin =
          pluginForExtension_.find( fi.suffix() );
  if ( saving_plugin != pluginForExtension_.end() ){
356
    if (ids_.size() == 1)
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
357
      emit save(ids_[0],filename, saving_plugin->second);
358
    else
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
359
      emit save(ids_   ,filename, saving_plugin->second);
360
  }
Jan Möbius's avatar
 
Jan Möbius committed
361

362
  OpenFlipperSettings().setValue("Core/CurrentDir", fi.absolutePath() );
Jan Möbius's avatar
 
Jan Möbius committed
363
364
365
366
367
}

/// show Widget for loading Files
int LoadWidget::showLoad(){
  setAcceptMode ( QFileDialog::AcceptOpen );
368
  setWindowTitle(tr("Load Object"));
Jan Möbius's avatar
 
Jan Möbius committed
369
370
371
372
  loadMode_ = true;

  setFileMode(QFileDialog::ExistingFiles);

373
374
375
  // Set directory to last Directory used for Opening Files
  setDirectory(OpenFlipperSettings().value("Core/CurrentDir").toString() );

Dirk Wilden's avatar
Dirk Wilden committed
376
  slotSetLoadFilters();
Jan Möbius's avatar
 
Jan Möbius committed
377
378
379
380
381
382
383
384

  return this->exec();
}

/// show Widget for saving Files
int LoadWidget::showSave(int _id, QString _filename){
  setAcceptMode ( QFileDialog::AcceptSave );
  setFileMode( QFileDialog::AnyFile );
385
  setWindowTitle(tr("Save Object"));
Jan Möbius's avatar
 
Jan Möbius committed
386
387
  loadMode_ = false;

388
389
  ids_.clear();
  ids_.push_back(_id);
Jan Möbius's avatar
 
Jan Möbius committed
390
391
392

  //set dataType
  BaseObjectData* object;
Jan Möbius's avatar
   
Jan Möbius committed
393
  PluginFunctions::getObject(_id,object);
Jan Möbius's avatar
 
Jan Möbius committed
394

Dirk Wilden's avatar
Dirk Wilden committed
395
  //check if we can save this dataType
Jan Möbius's avatar
 
Jan Möbius committed
396
  bool typeFound = false;
Dirk Wilden's avatar
Dirk Wilden committed
397
398
399
  
  for (int i=0; i < (int)supportedTypes_.size(); i++)
    if ( object->dataType( supportedTypes_[i].type ) )
Jan Möbius's avatar
 
Jan Möbius committed
400
      typeFound = true;
Dirk Wilden's avatar
Dirk Wilden committed
401

Jan Möbius's avatar
 
Jan Möbius committed
402
403
404
405
406
407

  if (!typeFound){
    std::cerr << "No suitable plugin for saving this dataType." << std::endl;
    return QDialog::Rejected;
  }

Dirk Wilden's avatar
Dirk Wilden committed
408
  slotSetSaveFilters( object->dataType() );
Dirk Wilden's avatar
Dirk Wilden committed
409

Jan Möbius's avatar
 
Jan Möbius committed
410
411
412
  //display correct path/name
  QFileInfo fi(_filename);
  QFile file(_filename);
Marlin Frickenschmidt's avatar
Marlin Frickenschmidt committed
413
414
415
  
  setDirectory(OpenFlipperSettings().value("Core/CurrentDir").toString() );
  selectFile ( fi.fileName() );
Dirk Wilden's avatar
Dirk Wilden committed
416

Dirk Wilden's avatar
Dirk Wilden committed
417
418
419
420
  //try to select the best fitting name filter
  for (int i=0; i < nameFilters().count(); i++){
    int s = nameFilters()[i].indexOf("*")+2;
    int e = nameFilters()[i].indexOf(" ", s);
Dirk Wilden's avatar
Dirk Wilden committed
421
422
423
    int e2 = nameFilters()[i].indexOf(")", s);
    if (e == -1 || e2 < e) e = e2;

Dirk Wilden's avatar
Dirk Wilden committed
424
    QString ext = nameFilters()[i].mid(s,e-s);
Jan Möbius's avatar
 
Jan Möbius committed
425

Dirk Wilden's avatar
Dirk Wilden committed
426
427
428
429
430
    if (ext == fi.completeSuffix()){
      selectNameFilter(nameFilters()[i]);
      break;
    }
  }
Jan Möbius's avatar
 
Jan Möbius committed
431
432
433
434

  return this->exec();
}

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/// show Widget for saving Files
int LoadWidget::showSave(IdList _ids, QString _filename){
  setAcceptMode ( QFileDialog::AcceptSave );
  setFileMode( QFileDialog::AnyFile );
  setWindowTitle(tr("Save Objects"));
  loadMode_ = false;

  ids_ = _ids;

  DataType types = 0;
  
  for (uint i=0; i < _ids.size(); i++){
    
    BaseObjectData* object;
    PluginFunctions::getObject(_ids[i], object);
    
    types |= object->dataType();
  }
  
  //check if we can save this dataType
  bool typeFound = false;
  
  for (int i=0; i < (int)supportedTypes_.size(); i++)
    if ( supportedTypes_[i].type.contains(types) )
      typeFound = true;


  if (!typeFound){
    std::cerr << "No suitable plugin for saving this dataType." << std::endl;
    return QDialog::Rejected;
  }

  slotSetSaveFilters( types );

  //display correct path/name
  QFileInfo fi(_filename);
  QFile file(_filename);

Marlin Frickenschmidt's avatar
Marlin Frickenschmidt committed
473
474
  setDirectory(OpenFlipperSettings().value("Core/CurrentDir").toString() );
  selectFile ( fi.fileName() );
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

  //try to select the best fitting name filter
  for (int i=0; i < nameFilters().count(); i++){
    int s = nameFilters()[i].indexOf("*")+2;
    int e = nameFilters()[i].indexOf(" ", s);
    int e2 = nameFilters()[i].indexOf(")", s);
    if (e == -1 || e2 < e) e = e2;

    QString ext = nameFilters()[i].mid(s,e-s);

    if (ext == fi.completeSuffix()){
      selectNameFilter(nameFilters()[i]);
      break;
    }
  }

  return this->exec();
}

494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
bool LoadWidget::validFilename() {
    
  // Only proceed if selected file is REALLY a file
  // Consider two cases:
  // Case 1: Filename is neither a valid file nor a directory -> continue and wait for valid file
  // Case 2: Entered filename is a directory -> Change to directory and wait for valid file
  QString firstEntered = selectedFiles()[0];
  
  // Test if directory exists
  QDir testdir(firstEntered);
  if(testdir.exists()) {
      setDirectory(testdir);
      return false;
  }
  
  // Test if file exists
  QFile file(firstEntered);
  if(!file.exists()) return false;
  
  return true;
}
Jan Möbius's avatar
 
Jan Möbius committed
515

516
517
518
519
520
521
522
bool LoadWidget::dirExists()
{
  QFileInfo firstEntered = selectedFiles()[0];
  // Test if directory exists
  return QDir(firstEntered.dir()).exists();
}

523
524
void LoadWidget::accept() {
    
Jan Möbius's avatar
Jan Möbius committed
525
  if( (!loadMode_) || validFilename() ) {
526
527
528
529
    
    if ( loadMode_ )
      loadFile();
    else
530
531
532
    {
      if (!dirExists()) //if dir does not exist, don't accept
        return;
533
      saveFile();
534
    }
Jan Möbius's avatar
 
Jan Möbius committed
535

536
537
    QFileDialog::accept();
  }
Jan Möbius's avatar
 
Jan Möbius committed
538
}
Dirk Wilden's avatar
Dirk Wilden committed
539
540
541
542
543
544

void LoadWidget::slotSetPluginForExtension(QString _extension, int _pluginId ){
  pluginForExtension_[ _extension ] = _pluginId;
}