File indexing completed on 2024-05-19 04:56:13
0001 /** 0002 * \file saferename.h 0003 * Safely rename a file. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 16 Feb 2012 0008 * 0009 * Copyright (C) 2012-2018 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include <QString> 0030 #include "kid3api.h" 0031 0032 namespace Utils { 0033 0034 /** 0035 * Check if file name has illegal characters. 0036 * 0037 * @param fileName file name 0038 * 0039 * @return true if file name contains illegal characters. 0040 */ 0041 bool KID3_CORE_EXPORT hasIllegalFileNameCharacters(const QString& fileName); 0042 0043 /** 0044 * Rename a file. 0045 * Renames the file using QDir::rename() if @a newName does not contain 0046 * illegal characters. 0047 * 0048 * @param oldName old file name 0049 * @param newName new file name 0050 * 0051 * @return true if ok. 0052 */ 0053 bool KID3_CORE_EXPORT safeRename(const QString& oldName, const QString& newName); 0054 0055 /** 0056 * Rename a file. 0057 * Renames the file using QDir::rename() if @a newName does not contain 0058 * illegal characters. 0059 * 0060 * @param dirPath directory path 0061 * @param oldName old file name 0062 * @param newName new file name 0063 * 0064 * @return true if ok. 0065 */ 0066 bool KID3_CORE_EXPORT safeRename(const QString& dirPath, 0067 const QString& oldName, const QString& newName); 0068 0069 /** 0070 * Replace illegal characters in a file name. 0071 * Use replacements from the file name format config if enabled, 0072 * otherwise remove the characters. 0073 * @param fileName fileName, illegal characters will be replaced 0074 * @param defaultReplacement optional default for replacement 0075 * @param illegalChars optional string containing the illegal characters 0076 * @return true if @a fileName was changed. 0077 */ 0078 bool KID3_CORE_EXPORT replaceIllegalFileNameCharacters( 0079 QString& fileName, const QString& defaultReplacement = QString(), 0080 const char* illegalChars = nullptr); 0081 0082 }