| 267 | } |
| 268 | |
| 269 | QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, |
| 270 | const QString &filter, |
| 271 | QString *selectedSuffixOut) |
| 272 | { |
| 273 | QString selectedFilter; |
| 274 | QString myDir; |
| 275 | if(dir.isEmpty()) // Default to user documents location |
| 276 | { |
| 277 | #if QT_VERSION < 0x050000 |
| 278 | myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); |
| 279 | #else |
| 280 | myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); |
| 281 | #endif |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | myDir = dir; |
| 286 | } |
| 287 | /* Directly convert path to native OS path separators */ |
| 288 | QString result = QDir::toNativeSeparators(QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter)); |
| 289 | |
| 290 | /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ |
| 291 | QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); |
| 292 | QString selectedSuffix; |
| 293 | if(filter_re.exactMatch(selectedFilter)) |
| 294 | { |
| 295 | selectedSuffix = filter_re.cap(1); |
| 296 | } |
| 297 | |
| 298 | /* Add suffix if needed */ |
| 299 | QFileInfo info(result); |
| 300 | if(!result.isEmpty()) |
| 301 | { |
| 302 | if(info.suffix().isEmpty() && !selectedSuffix.isEmpty()) |
| 303 | { |
| 304 | /* No suffix specified, add selected suffix */ |
| 305 | if(!result.endsWith(".")) |
| 306 | result.append("."); |
| 307 | result.append(selectedSuffix); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /* Return selected suffix if asked to */ |
| 312 | if(selectedSuffixOut) |
| 313 | { |
| 314 | *selectedSuffixOut = selectedSuffix; |
| 315 | } |
| 316 | return result; |
| 317 | } |
| 318 | |
| 319 | QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, |
| 320 | const QString &filter, |
no outgoing calls
no test coverage detected