| 1 | /* |
| 2 | * Copyright (C) 2019 Damir Porobic <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "SavePathProvider.h" |
| 21 | |
| 22 | SavePathProvider::SavePathProvider(const QSharedPointer<IConfig> &config) : |
| 23 | mConfig(config) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | QString SavePathProvider::savePath() const |
| 28 | { |
| 29 | if (mConfig->overwriteFile()) { |
| 30 | return NameProvider::makeFilename(saveDirectory(), getFilename(), getFormat(mConfig->saveFormat())); |
| 31 | } else { |
| 32 | return UniqueNameProvider::makeUniqueFilename(saveDirectory(), getFilename(), getFormat(mConfig->saveFormat())); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | QString SavePathProvider::savePathWithFormat(const QString &format) const |
| 37 | { |
| 38 | return UniqueNameProvider::makeUniqueFilename(saveDirectory(), getFilename(), getFormat(format)); |
| 39 | } |
| 40 | |
| 41 | QString SavePathProvider::getFilename() const |
| 42 | { |
| 43 | auto filename = WildcardResolver::replaceDateTimeWildcards(mConfig->saveFilename()); |
| 44 | return WildcardResolver::replaceNumberWildcards(filename, saveDirectory(), getFormat(mConfig->saveFormat())); |
| 45 | } |
| 46 | |
| 47 | QString SavePathProvider::getFormat(const QString &format) const |
| 48 | { |
| 49 | return format.startsWith(QLatin1Char('.')) ? format : QLatin1Char('.') + format; |
| 50 | } |
| 51 | |
| 52 | QString SavePathProvider::saveDirectory() const |
| 53 | { |
| 54 | return WildcardResolver::replaceDateTimeWildcards(mConfig->saveDirectory()); |
| 55 | } |
| 56 |