265
265
//---------------------------------------------------------
266
// getFilterExtension
267
//---------------------------------------------------------
269
QString getFilterExtension(const QString &filter)
272
// Return the first extension found. Must contain at least one * character.
275
int pos = filter.find('*');
280
int len = filter.length();
282
for( ; pos < len; ++pos)
284
QChar c = filter[pos];
285
if((c == ')') || (c == ';') || (c == ',') || (c == ' '))
292
//---------------------------------------------------------
266
293
// getOpenFileName
267
294
//---------------------------------------------------------
269
296
QString getOpenFileName(const QString &startWith,
270
const char** filters, QWidget* parent, const QString& name, bool* all)
297
//const char** filters, QWidget* parent, const QString& name, bool* all)
298
const QStringList& filters, QWidget* parent, const QString& name, bool* all)
272
300
QString initialSelection;
273
301
MFileDialog *dlg = new MFileDialog(startWith, QString::null, parent, false);
294
322
//---------------------------------------------------------
296
324
QString getSaveFileName(const QString &startWith,
297
const char** filters, QWidget* parent, const QString& name)
325
//const char** filters, QWidget* parent, const QString& name)
326
const QStringList& filters, QWidget* parent, const QString& name)
299
328
MFileDialog *dlg = new MFileDialog(startWith, QString::null, parent, true);
300
329
dlg->setFilters(filters);
301
330
dlg->setCaption(name);
302
331
dlg->setMode(QFileDialog::AnyFile);
304
if (dlg->exec() == QDialog::Accepted) {
305
result = dlg->selectedFile();
333
if (dlg->exec() == QDialog::Accepted)
334
result = dlg->selectedFile();
338
if(!result.isEmpty())
340
QString filt = dlg->selectedFilter();
341
filt = getFilterExtension(filt);
342
// Do we have a valid extension?
345
// If the rightmost characters of the filename do not already contain
346
// the extension, add the extension to the filename.
347
//if(result.right(filt.length()) != filt)
348
if(!result.endsWith(filt))
353
// No valid extension, or just * was given. Although it would be nice to allow no extension
354
// or any desired extension by commenting this section out, it's probably not a good idea to do so.
356
// NOTE: Most calls to this routine getSaveFileName() are followed by fileOpen(),
357
// which can tack on its own extension, but only if the *complete* extension is blank.
358
// So there is some overlap going on. Enabling this actually stops that action,
359
// but only if there are no errors in the list of filters. fileOpen() will act as a 'catchall'.
361
// Force the filter list to the first one (the preferred one), and then get the filter.
362
dlg->setSelectedFilter(0);
363
filt = dlg->selectedFilter();
364
filt = getFilterExtension(filt);
366
// Do we have a valid extension?
369
// If the rightmost characters of the filename do not already contain
370
// the extension, add the extension to the filename.
371
//if(result.right(filt.length()) != filt)
372
if(!result.endsWith(filt))
313
384
//---------------------------------------------------------
315
386
QString getImageFileName(const QString& startWith,
316
const char** filters, QWidget* parent, const QString& name)
387
//const char** filters, QWidget* parent, const QString& name)
388
const QStringList& filters, QWidget* parent, const QString& name)
318
390
QString initialSelection;
319
391
QString* workingDirectory = new QString(QDir::currentDirPath());
445
517
//---------------------------------------------------------
447
FILE* MFile::open(const char* mode, const char** pattern,
519
//FILE* MFile::open(const char* mode, const char** pattern,
520
FILE* MFile::open(const char* mode, const QStringList& pattern,
448
521
QWidget* parent, bool noError, bool warnIfOverwrite, const QString& caption)