File indexing completed on 2024-05-19 04:55:56
0001 /** 0002 * \file playlistconfig.h 0003 * Configuration for playlist dialog. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 16 Sep 2009 0008 * 0009 * Copyright (C) 2009-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 <QString> 0030 #include "generalconfig.h" 0031 #include "kid3api.h" 0032 0033 /** 0034 * Playlist configuration. 0035 */ 0036 class KID3_CORE_EXPORT PlaylistConfig : public StoredConfig<PlaylistConfig> { 0037 Q_OBJECT 0038 /** Playlist location */ 0039 Q_PROPERTY(int location READ location WRITE setLocationInt 0040 NOTIFY locationChanged) 0041 /** Playlist format */ 0042 Q_PROPERTY(int format READ format WRITE setFormatInt NOTIFY formatChanged) 0043 /** Playlist file name format */ 0044 Q_PROPERTY(QString fileNameFormat READ fileNameFormat WRITE setFileNameFormat 0045 NOTIFY fileNameFormatChanged) 0046 /** Playlist file name formats */ 0047 Q_PROPERTY(QStringList fileNameFormats READ fileNameFormats WRITE setFileNameFormats 0048 NOTIFY fileNameFormatsChanged) 0049 /** Tag field used for sorting */ 0050 Q_PROPERTY(QString sortTagField READ sortTagField WRITE setSortTagField 0051 NOTIFY sortTagFieldChanged) 0052 /** Format for additional information */ 0053 Q_PROPERTY(QString infoFormat READ infoFormat WRITE setInfoFormat 0054 NOTIFY infoFormatChanged) 0055 /** Use file name format if true, else directory name */ 0056 Q_PROPERTY(bool useFileNameFormat READ useFileNameFormat 0057 WRITE setUseFileNameFormat NOTIFY useFileNameFormatChanged) 0058 /** Include only selected files if true, else all files */ 0059 Q_PROPERTY(bool onlySelectedFiles READ onlySelectedFiles 0060 WRITE setOnlySelectedFiles NOTIFY onlySelectedFilesChanged) 0061 /** Sort by tag field if true, else file name */ 0062 Q_PROPERTY(bool useSortTagField READ useSortTagField WRITE setUseSortTagField 0063 NOTIFY useSortTagFieldChanged) 0064 /** Use full path for files in playlist if true, else relative path */ 0065 Q_PROPERTY(bool useFullPath READ useFullPath WRITE setUseFullPath 0066 NOTIFY useFullPathChanged) 0067 /** Write info format, else only list of files */ 0068 Q_PROPERTY(bool writeInfo READ writeInfo WRITE setWriteInfo 0069 NOTIFY writeInfoChanged) 0070 /** window geometry */ 0071 Q_PROPERTY(QByteArray windowGeometry READ windowGeometry 0072 WRITE setWindowGeometry NOTIFY windowGeometryChanged) 0073 Q_ENUMS(PlaylistFormat) 0074 Q_ENUMS(PlaylistLocation) 0075 public: 0076 /** 0077 * Playlist format. 0078 */ 0079 enum PlaylistFormat { 0080 PF_M3U, /**< M3U */ 0081 PF_PLS, /**< PLS */ 0082 PF_XSPF /**< XSPF */ 0083 }; 0084 0085 /** 0086 * Location to create playlist. 0087 */ 0088 enum PlaylistLocation { 0089 PL_CurrentDirectory, /**< create in current directory */ 0090 PL_EveryDirectory, /**< create in every directory */ 0091 PL_TopLevelDirectory /**< create in top-level directory */ 0092 }; 0093 0094 /** 0095 * Constructor. 0096 */ 0097 explicit PlaylistConfig(); 0098 0099 /** 0100 * Copy constructor. 0101 * @param other instance to be copied 0102 */ 0103 PlaylistConfig(const PlaylistConfig& other); 0104 0105 /** 0106 * Destructor. 0107 */ 0108 ~PlaylistConfig() override = default; 0109 0110 /** 0111 * Assignment operator. 0112 * @param other instance to be copied 0113 * @return reference to this instance. 0114 */ 0115 PlaylistConfig& operator=(const PlaylistConfig& other); 0116 0117 /** 0118 * Persist configuration. 0119 * 0120 * @param config KDE configuration 0121 */ 0122 void writeToConfig(ISettings* config) const override; 0123 0124 /** 0125 * Read persisted configuration. 0126 * 0127 * @param config KDE configuration 0128 */ 0129 void readFromConfig(ISettings* config) override; 0130 0131 /** Get playlist location. */ 0132 PlaylistLocation location() const { return m_location; } 0133 0134 /** Set playlist location. */ 0135 void setLocation(PlaylistLocation location); 0136 0137 /** Get playlist format. */ 0138 PlaylistFormat format() const { return m_format;} 0139 0140 /** Set playlist format. */ 0141 void setFormat(PlaylistFormat format); 0142 0143 /** Get playlist file name format. */ 0144 QString fileNameFormat() const { return m_fileNameFormat; } 0145 0146 /** Set playlist file name format. */ 0147 void setFileNameFormat(const QString& fileNameFormat); 0148 0149 /** Get playlist file name formats. */ 0150 QStringList fileNameFormats() const { 0151 return m_fileNameFormatItems; 0152 } 0153 0154 /** Set playlist file name formats. */ 0155 void setFileNameFormats(const QStringList& fileNameFormatItems); 0156 0157 /** Get tag field used for sorting. */ 0158 QString sortTagField() const { return m_sortTagField; } 0159 0160 /** Set tag field used for sorting. */ 0161 void setSortTagField(const QString& sortTagField); 0162 0163 /** Get format for additional information. */ 0164 QString infoFormat() const { return m_infoFormat; } 0165 0166 /** Set format for additional information. */ 0167 void setInfoFormat(const QString& infoFormat); 0168 0169 /** Check if file name format is used. */ 0170 bool useFileNameFormat() const { return m_useFileNameFormat; } 0171 0172 /** Set if file name format is used. */ 0173 void setUseFileNameFormat(bool useFileNameFormat); 0174 0175 /** Check if only selected files are included. */ 0176 bool onlySelectedFiles() const { return m_onlySelectedFiles; } 0177 0178 /** Set if only selected files are included. */ 0179 void setOnlySelectedFiles(bool onlySelectedFiles); 0180 0181 /** Check if sorted by tag field. */ 0182 bool useSortTagField() const { return m_useSortTagField; } 0183 0184 /** Set if sorted by tag field. */ 0185 void setUseSortTagField(bool useSortTagField); 0186 0187 /** Check if full path for files is used in playlist. */ 0188 bool useFullPath() const { return m_useFullPath; } 0189 0190 /** Set if full path for files is used in playlist. */ 0191 void setUseFullPath(bool useFullPath); 0192 0193 /** Check if info format is written. */ 0194 bool writeInfo() const { return m_writeInfo; } 0195 0196 /** Set if info format is written. */ 0197 void setWriteInfo(bool writeInfo); 0198 0199 /** 0200 * Get file extension for playlist format. 0201 * @return ".m3u", ".pls" or ".xspf". 0202 */ 0203 QString fileExtensionForFormat() const; 0204 0205 /** 0206 * Get playlist format from file extension. 0207 * @param path file path or name ending with extension 0208 * @param ok if set true is returned here if @a path has a playlist extension 0209 * @return playlist format. 0210 */ 0211 static PlaylistFormat formatFromFileExtension(const QString& path, 0212 bool* ok = nullptr); 0213 0214 /** 0215 * Get window geometry. 0216 * @return window geometry. 0217 */ 0218 QByteArray windowGeometry() const { return m_windowGeometry; } 0219 0220 /** 0221 * Set window geometry. 0222 * @param windowGeometry geometry 0223 */ 0224 void setWindowGeometry(const QByteArray& windowGeometry); 0225 0226 signals: 0227 /** Emitted when @a location changed. */ 0228 void locationChanged(PlaylistConfig::PlaylistLocation location); 0229 0230 /** Emitted when @a format changed. */ 0231 void formatChanged(PlaylistConfig::PlaylistFormat format); 0232 0233 /** Emitted when @a fileNameFormat changed. */ 0234 void fileNameFormatChanged(const QString& fileNameFormat); 0235 0236 /** Emitted when @a fileNameFormats changed. */ 0237 void fileNameFormatsChanged(const QStringList& fileNameFormats); 0238 0239 /** Emitted when @a sortTagField changed. */ 0240 void sortTagFieldChanged(const QString& sortTagField); 0241 0242 /** Emitted when @a infoFormat changed. */ 0243 void infoFormatChanged(const QString& infoFormat); 0244 0245 /** Emitted when @a useFileNameFormat changed. */ 0246 void useFileNameFormatChanged(bool useFileNameFormat); 0247 0248 /** Emitted when @a onlySelectedFiles changed. */ 0249 void onlySelectedFilesChanged(bool onlySelectedFiles); 0250 0251 /** Emitted when @a useSortTagField changed. */ 0252 void useSortTagFieldChanged(bool useSortTagField); 0253 0254 /** Emitted when @a useFullPath changed. */ 0255 void useFullPathChanged(bool useFullPath); 0256 0257 /** Emitted when @a writeInfo changed. */ 0258 void writeInfoChanged(bool writeInfo); 0259 0260 /** Emitted when @a windowGeometry changed. */ 0261 void windowGeometryChanged(const QByteArray& windowGeometry); 0262 0263 private: 0264 friend PlaylistConfig& StoredConfig<PlaylistConfig>::instance(); 0265 0266 void initFormatListsIfEmpty(); 0267 0268 void setLocationInt(int location) { 0269 setLocation(static_cast<PlaylistLocation>(location)); 0270 } 0271 0272 void setFormatInt(int format) { 0273 setFormat(static_cast<PlaylistFormat>(format)); 0274 } 0275 0276 PlaylistLocation m_location; 0277 PlaylistFormat m_format; 0278 QString m_fileNameFormat; 0279 QStringList m_fileNameFormatItems; 0280 QString m_sortTagField; 0281 QString m_infoFormat; 0282 QByteArray m_windowGeometry; 0283 bool m_useFileNameFormat; 0284 bool m_onlySelectedFiles; 0285 bool m_useSortTagField; 0286 bool m_useFullPath; 0287 bool m_writeInfo; 0288 0289 /** Index in configuration storage */ 0290 static int s_index; 0291 };