File indexing completed on 2024-05-19 04:55:54
0001 /** 0002 * \file fileconfig.h 0003 * File related configuration. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 29 Jun 2013 0008 * 0009 * Copyright (C) 2013-2024 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 <QStringList> 0030 #include "generalconfig.h" 0031 #include "kid3api.h" 0032 0033 /** 0034 * File related configuration. 0035 */ 0036 class KID3_CORE_EXPORT FileConfig : public StoredConfig<FileConfig> { 0037 Q_OBJECT 0038 /** filter of file names to be opened */ 0039 Q_PROPERTY(QString nameFilter READ nameFilter WRITE setNameFilter 0040 NOTIFY nameFilterChanged) 0041 /** patterns for folders to include in file list */ 0042 Q_PROPERTY(QStringList includeFolders READ includeFolders 0043 WRITE setIncludeFolders NOTIFY includeFoldersChanged) 0044 /** patterns for folders to exclude in file list */ 0045 Q_PROPERTY(QStringList excludeFolders READ excludeFolders 0046 WRITE setExcludeFolders NOTIFY excludeFoldersChanged) 0047 /** true to show hidden files */ 0048 Q_PROPERTY(bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles 0049 NOTIFY showHiddenFilesChanged) 0050 /** true if punctuation characters and symbols are ignored when sorting */ 0051 Q_PROPERTY(bool sortIgnoringPunctuation READ sortIgnoringPunctuation 0052 WRITE setSortIgnoringPunctuation 0053 NOTIFY sortIgnoringPunctuationChanged) 0054 /** filename format */ 0055 Q_PROPERTY(QString toFilenameFormat READ toFilenameFormat 0056 WRITE setToFilenameFormat NOTIFY toFilenameFormatChanged) 0057 /** filename formats */ 0058 Q_PROPERTY(QStringList toFilenameFormats READ toFilenameFormats 0059 WRITE setToFilenameFormats NOTIFY toFilenameFormatsChanged) 0060 /** from filename format */ 0061 Q_PROPERTY(QString fromFilenameFormat READ fromFilenameFormat 0062 WRITE setFromFilenameFormat NOTIFY fromFilenameFormatChanged) 0063 /** from filename formats */ 0064 Q_PROPERTY(QStringList fromFilenameFormats READ fromFilenameFormats 0065 WRITE setFromFilenameFormats NOTIFY fromFilenameFormatsChanged) 0066 /** default file name to save cover art */ 0067 Q_PROPERTY(QString defaultCoverFileName READ defaultCoverFileName 0068 WRITE setDefaultCoverFileName NOTIFY defaultCoverFileNameChanged) 0069 /** path to last opened file */ 0070 Q_PROPERTY(QString lastOpenedFile READ lastOpenedFile WRITE setLastOpenedFile 0071 NOTIFY lastOpenedFileChanged) 0072 /** text encoding used for exports and playlists */ 0073 Q_PROPERTY(QString textEncoding READ textEncoding WRITE setTextEncoding 0074 NOTIFY textEncodingChanged) 0075 /** text encoding used for exports and playlists */ 0076 Q_PROPERTY(int textEncodingIndex READ textEncodingIndex 0077 WRITE setTextEncodingIndex NOTIFY textEncodingChanged) 0078 /** true to preserve file time stamps */ 0079 Q_PROPERTY(bool preserveTime READ preserveTime WRITE setPreserveTime 0080 NOTIFY preserveTimeChanged) 0081 /** true to mark changed fields */ 0082 Q_PROPERTY(bool markChanges READ markChanges WRITE setMarkChanges 0083 NOTIFY markChangesChanged) 0084 /** true to open last opened file on startup */ 0085 Q_PROPERTY(bool loadLastOpenedFile READ loadLastOpenedFile 0086 WRITE setLoadLastOpenedFile NOTIFY loadLastOpenedFileChanged) 0087 0088 public: 0089 /** 0090 * Constructor. 0091 */ 0092 FileConfig(); 0093 0094 /** 0095 * Destructor. 0096 */ 0097 ~FileConfig() override = default; 0098 0099 /** 0100 * Persist configuration. 0101 * 0102 * @param config configuration 0103 */ 0104 void writeToConfig(ISettings* config) const override; 0105 0106 /** 0107 * Read persisted configuration. 0108 * 0109 * @param config configuration 0110 */ 0111 void readFromConfig(ISettings* config) override; 0112 0113 /** Get filter of file names to be opened. */ 0114 QString nameFilter() const { return m_nameFilter; } 0115 0116 /** Set filter of file names to be opened. */ 0117 void setNameFilter(const QString& nameFilter); 0118 0119 /** Get patterns for folders to include in file list. */ 0120 QStringList includeFolders() const { return m_includeFolders; } 0121 0122 /** Set patterns for folders to include in file list. */ 0123 void setIncludeFolders(const QStringList& includeFolders); 0124 0125 /** Get patterns for folders to exclude in file list. */ 0126 QStringList excludeFolders() const { return m_excludeFolders; } 0127 0128 /** Set patterns for folders to exclude in file list. */ 0129 void setExcludeFolders(const QStringList& excludeFolders); 0130 0131 /** Check if hidden files are shown. */ 0132 bool showHiddenFiles() const { return m_showHiddenFiles; } 0133 0134 /** Set if hidden files are shown. */ 0135 void setShowHiddenFiles(bool showHiddenFiles); 0136 0137 /** Check if punctuation characters and symbols are ignored when sorting. */ 0138 bool sortIgnoringPunctuation() const { return m_sortIgnoringPunctuation; } 0139 0140 /** Set if punctuation characters and symbols are ignored when sorting. */ 0141 void setSortIgnoringPunctuation(bool sortIgnoringPunctuation); 0142 0143 /** Get filename format. */ 0144 QString toFilenameFormat() const { return m_formatText; } 0145 0146 /** Set filename format. */ 0147 void setToFilenameFormat(const QString& formatText); 0148 0149 /** Get filename formats. */ 0150 QStringList toFilenameFormats() const { return m_formatItems; } 0151 0152 /** Set filename formats. */ 0153 void setToFilenameFormats(const QStringList& formatItems); 0154 0155 /** Get from filename format. */ 0156 QString fromFilenameFormat() const { return m_formatFromFilenameText; } 0157 0158 /** Set from filename format. */ 0159 void setFromFilenameFormat(const QString& formatFromFilenameText); 0160 0161 /** Get from filename formats. */ 0162 QStringList fromFilenameFormats() const { 0163 return m_formatFromFilenameItems; 0164 } 0165 0166 /** Set from filename formats. */ 0167 void setFromFilenameFormats(const QStringList& fromFilenameFormats); 0168 0169 /** Get default file name to save cover art. */ 0170 QString defaultCoverFileName() const { return m_defaultCoverFileName; } 0171 0172 /** Set default file name to save cover art. */ 0173 void setDefaultCoverFileName(const QString& defaultCoverFileName); 0174 0175 /** Get path to last opened file. */ 0176 QString lastOpenedFile() const { return m_lastOpenedFile; } 0177 0178 /** Set path to last opened file. */ 0179 void setLastOpenedFile(const QString& lastOpenedFile); 0180 0181 /** Get text encoding used for exports and playlists. */ 0182 QString textEncoding() const { return m_textEncoding; } 0183 0184 /** Set text encoding used for exports and playlists. */ 0185 void setTextEncoding(const QString& textEncoding); 0186 0187 /** Get index of text encoding in getTextCodecNames() */ 0188 int textEncodingIndex() const; 0189 0190 /** Set text encoding from index in getTextCodecNames(). */ 0191 void setTextEncodingIndex(int index); 0192 0193 /** Check if file time stamps are preserved. */ 0194 bool preserveTime() const { return m_preserveTime; } 0195 0196 /** Set if file time stamps are preserved. */ 0197 void setPreserveTime(bool preserveTime); 0198 0199 /** Check if changed fields are marked. */ 0200 bool markChanges() const { return m_markChanges; } 0201 0202 /** Set if changed fields are marked. */ 0203 void setMarkChanges(bool markChanges); 0204 0205 /** Check if the last opened file is loaded on startup. */ 0206 bool loadLastOpenedFile() const { return m_loadLastOpenedFile; } 0207 0208 /** Set if the last opened file is loaded on startup. */ 0209 void setLoadLastOpenedFile(bool loadLastOpenedFile); 0210 0211 signals: 0212 /** Emitted when @a nameFilter changed. */ 0213 void nameFilterChanged(const QString& nameFilter); 0214 0215 /** Emitted when @a includeFolders changed. */ 0216 void includeFoldersChanged(const QStringList& includeFolders); 0217 0218 /** Emitted when @a excludeFolders changed. */ 0219 void excludeFoldersChanged(const QStringList& excludeFolders); 0220 0221 /** Emitted when @a showHiddenFiles changed. */ 0222 void showHiddenFilesChanged(bool showHiddenFiles); 0223 0224 /** Emitted when @a sortIgnoringPunctuation changed. */ 0225 void sortIgnoringPunctuationChanged(bool sortIgnoringPunctuation); 0226 0227 /** Emitted when @a formatText changed. */ 0228 void toFilenameFormatChanged(const QString& toFilenameFormat); 0229 0230 /** Emitted when @a formatItems changed. */ 0231 void toFilenameFormatsChanged(const QStringList& toFilenameFormats); 0232 0233 /** Emitted when @a formatFromFilenameText changed. */ 0234 void fromFilenameFormatChanged(const QString& fromFilenameFormat); 0235 0236 /** Emitted when @a formatFromFilenameItems changed. */ 0237 void fromFilenameFormatsChanged(const QStringList& fromFilenameFormats); 0238 0239 /** Emitted when @a defaultCoverFileName changed. */ 0240 void defaultCoverFileNameChanged(const QString& defaultCoverFileName); 0241 0242 /** Emitted when @a lastOpenedFile changed. */ 0243 void lastOpenedFileChanged(const QString& lastOpenedFile); 0244 0245 /** Emitted when @a textEncoding changed. */ 0246 void textEncodingChanged(const QString& textEncoding); 0247 0248 /** Emitted when @a preserveTime changed. */ 0249 void preserveTimeChanged(bool preserveTime); 0250 0251 /** Emitted when @a markChanges changed. */ 0252 void markChangesChanged(bool markChanges); 0253 0254 /** Emitted when @a loadLastOpenedFile changed. */ 0255 void loadLastOpenedFileChanged(bool loadLastOpenedFile); 0256 0257 private: 0258 friend FileConfig& StoredConfig<FileConfig>::instance(); 0259 0260 void initFormatListsIfEmpty(); 0261 0262 QString m_nameFilter; 0263 QStringList m_includeFolders; 0264 QStringList m_excludeFolders; 0265 QString m_formatText; 0266 QStringList m_formatItems; 0267 QString m_formatFromFilenameText; 0268 QStringList m_formatFromFilenameItems; 0269 QString m_defaultCoverFileName; 0270 QString m_lastOpenedFile; 0271 QString m_textEncoding; 0272 bool m_preserveTime; 0273 bool m_markChanges; 0274 bool m_loadLastOpenedFile; 0275 bool m_showHiddenFiles; 0276 bool m_sortIgnoringPunctuation; 0277 0278 /** Index in configuration storage */ 0279 static int s_index; 0280 };