1 /* BEGIN_COMMON_COPYRIGHT_HEADER 2 * (c)LGPL2+ 3 * 4 * Flacon - audio File Encoder 5 * https://github.com/flacon/flacon 6 * 7 * Copyright: 2012-2013 8 * Alexander Sokoloff <sokoloff.a@gmail.com> 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; either 13 * version 2.1 of the License, or (at your option) any later version. 14 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * 24 * END_COMMON_COPYRIGHT_HEADER */ 25 26 #ifndef SETTINGS_H 27 #define SETTINGS_H 28 29 #include <QSettings> 30 #include <QSet> 31 #include "types.h" 32 #include "profiles.h" 33 34 class OutFormat; 35 36 class Settings : public QSettings 37 { 38 Q_OBJECT 39 public: 40 enum Key { 41 Tags_DefaultCodepage, 42 43 // MainWindow *************************** 44 MainWindow_Width, 45 MainWindow_Height, 46 47 // Globals ****************************** 48 Encoder_ThreadCount, 49 Encoder_TmpDir, 50 51 // Out Files **************************** 52 OutFiles_DirectoryHistory, 53 OutFiles_Profile, 54 OutFiles_PatternHistory, 55 56 // Internet ***************************** 57 Inet_CDDBHost, 58 59 // Misc ********************************* 60 Misc_LastDir, 61 62 // ConfigureDialog ********************** 63 ConfigureDialog_Width, 64 ConfigureDialog_Height, 65 66 // Cover image ************************** 67 Cover_Mode, 68 Cover_Size, 69 EmbeddedCover_Mode, 70 EmbeddedCover_Size, 71 72 }; 73 74 static Settings *i(); 75 static void setFileName(const QString &fileName); fileName()76 static QString fileName() { return mFileName; } 77 78 QVariant value(Key key, const QVariant &defaultValue = QVariant()) const; 79 void setValue(Key key, const QVariant &value); 80 81 void setValue(const QString &key, const QVariant &value); 82 QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; 83 84 bool checkProgram(const QString &program) const; 85 QString programName(const QString &program) const; 86 programs()87 QSet<QString> programs() const { return mPrograms; } 88 QString findProgram(const QString &program) const; 89 90 OutFormat *outFormat() const; 91 92 QString tmpDir() const; 93 void setTmpDir(const QString &value); 94 95 QString defaultCodepage() const; 96 void setDefaultCodepage(const QString &value); 97 98 CoverMode coverMode() const; 99 void setCoverMode(CoverMode value); 100 101 int coverImageSize() const; 102 void setCoverImageSize(int value); 103 104 CoverMode embeddedCoverMode() const; 105 void setEmbeddedCoverMode(CoverMode value); 106 107 int embeddedCoverImageSize() const; 108 void setEmbeddedCoverImageSize(int value); 109 110 Profiles &profiles(); 111 const Profiles &profiles() const; 112 void setProfiles(const Profiles &profiles); 113 114 const Profile ¤tProfile() const; 115 Profile ¤tProfile(); 116 bool selectProfile(const QString &profileId); 117 118 uint encoderThreadsCount() const; 119 void setEncoderThreadsCount(uint value); 120 121 QString cddbHost() const; 122 void setCddbHost(const QString &value); 123 124 signals: 125 void changed(); 126 127 protected: 128 explicit Settings(const QString &organization, const QString &application); 129 explicit Settings(const QString &fileName); 130 virtual ~Settings(); 131 132 private: 133 void init(); 134 void setDefaultValue(const QString &key, const QVariant &defaultValue); 135 void setDefaultValue(Key key, const QVariant &defaultValue); 136 QString keyToString(Key key) const; 137 QStringList groups(const QString &parentGroup) const; 138 void loadProfiles(); 139 140 QSet<QString> mPrograms; 141 static QString mFileName; 142 static Settings *mInstance; 143 Profiles mProfiles; 144 }; 145 146 #endif // SETTINGS_H 147