| 347 | } |
| 348 | |
| 349 | QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, |
| 350 | const QString &filter, |
| 351 | QString *selectedSuffixOut) |
| 352 | { |
| 353 | QString selectedFilter; |
| 354 | QString myDir; |
| 355 | if(dir.isEmpty()) // Default to user documents location |
| 356 | { |
| 357 | myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); |
| 358 | } |
| 359 | else |
| 360 | { |
| 361 | myDir = dir; |
| 362 | } |
| 363 | /* Directly convert path to native OS path separators */ |
| 364 | QString result = QDir::toNativeSeparators(QFileDialog::getOpenFileName(parent, caption, myDir, filter, &selectedFilter)); |
| 365 | |
| 366 | if(selectedSuffixOut) |
| 367 | { |
| 368 | /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ |
| 369 | QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); |
| 370 | QString selectedSuffix; |
| 371 | if(filter_re.exactMatch(selectedFilter)) |
| 372 | { |
| 373 | selectedSuffix = filter_re.cap(1); |
| 374 | } |
| 375 | *selectedSuffixOut = selectedSuffix; |
| 376 | } |
| 377 | return result; |
| 378 | } |
| 379 | |
| 380 | Qt::ConnectionType blockingGUIThreadConnection() |
| 381 | { |