utils/makerpm: Fix building of RPMs
[skype-call-recorder.git] / preferences.h
blobd812589bcc164ea2b36def28434a0b3def9ac8a2
1 /*
2 Skype Call Recorder
3 Copyright (C) 2008 jlh (jlh at gmx dot ch)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2 of the License, version 3 of
8 the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 The GNU General Public License version 2 is included with the source of
20 this program under the file name COPYING. You can also get a copy on
21 http://www.fsf.org/
24 #ifndef PREFERENCES_H
25 #define PREFERENCES_H
27 #include <QDialog>
28 #include <QList>
29 #include <QString>
30 #include <QStringList>
31 #include <QAbstractListModel>
32 #include <QPointer>
34 #include "common.h"
36 class SmartComboBox;
37 class QWidget;
38 class QListView;
39 class PerCallerModel;
40 class PerCallerPreferencesDialog;
41 class QRadioButton;
42 class SmartEditableComboBox;
43 class SmartLineEdit;
44 class QDateTime;
45 class QLabel;
47 // A single preference, with a name and a value
49 class Preference {
50 public:
51 Preference(const Preference &p) : m_name(p.m_name), isSet(p.isSet), value(p.value) { }
52 Preference(const QString &n) : m_name(n), isSet(false) { }
53 template <typename T> Preference(const QString &n, const T &t) : m_name(n), isSet(false) { set(t); }
55 const QString &toString() const { return value; }
56 int toInt() const { return value.toInt(); }
57 bool toBool() const { return value.compare("yes", Qt::CaseInsensitive) == 0 || value.toInt(); }
58 QStringList toList() const { return value.split(',', QString::SkipEmptyParts); }
59 void listAdd(const QString &);
60 void listRemove(const QString &);
61 bool listContains(const QString &);
63 void set(const char *v) { isSet = true; value = v; }
64 void set(const QString &v) { isSet = true; value = v; }
65 void set(int v) { isSet = true; value.setNum(v); }
66 void set(bool v) { isSet = true; value = v ? "yes" : "no"; }
67 void set(const QStringList &v) { isSet = true; value = v.join(","); }
69 template <typename T> void setIfNotSet(const T &v) { if (!isSet) set(v); }
71 const QString &name() const { return m_name; }
73 bool operator<(const Preference &rhs) const {
74 return m_name < rhs.m_name;
77 private:
78 QString m_name;
79 bool isSet;
80 QString value;
82 private:
83 // disable assignment. we want preference names to be immutable.
84 Preference &operator=(const Preference &);
87 // A collection of preferences that can be loaded/saved
89 class BasePreferences {
90 public:
91 BasePreferences() { };
92 ~BasePreferences();
94 bool load(const QString &);
95 bool save(const QString &);
97 Preference &get(const QString &);
98 // Warning: remove() must only be used if nobody has a pointer to the
99 // preference, like for example smart widgets
100 void remove(const QString &);
101 bool exists(const QString &) const;
102 void clear();
104 int count() const { return prefs.size(); }
106 private:
107 // this is a list of pointers, so we can control the life time of each
108 // Preference. we want references to them to be valid forever. Only
109 // QLinkedList could give that guarantee, but it's unpractical for
110 // sorting. QList<Preference> would technically be implemented as an
111 // array of pointers too, but its sorting semantics with regard to
112 // references are not the one we want.
113 QList<Preference *> prefs;
115 DISABLE_COPY_AND_ASSIGNMENT(BasePreferences);
118 // preferences with some utils
120 class Preferences : public BasePreferences {
121 public:
122 Preferences() { };
124 void setPerCallerPreference(const QString &, int);
126 DISABLE_COPY_AND_ASSIGNMENT(Preferences);
129 // The preferences dialog
131 class PreferencesDialog : public QDialog {
132 Q_OBJECT
133 public:
134 PreferencesDialog();
135 void closePerCallerDialog();
137 protected:
138 void hideEvent(QHideEvent *);
140 private slots:
141 void updateFormatSettings();
142 void editPerCallerPreferences();
143 void updatePatternToolTip(const QString &);
144 void updateStereoSettings(bool);
145 void updateStereoMixLabel(int);
146 void browseOutputPath();
147 void updateAbsolutePathWarning(const QString &);
149 private:
150 QWidget *createRecordingTab();
151 QWidget *createPathTab();
152 QWidget *createFormatTab();
153 QWidget *createMiscTab();
155 private:
156 QList<QWidget *> mp3Settings;
157 QList<QWidget *> vorbisSettings;
158 QList<QWidget *> stereoSettings;
159 SmartLineEdit *outputPathEdit;
160 SmartComboBox *formatWidget;
161 QPointer<PerCallerPreferencesDialog> perCallerDialog;
162 SmartEditableComboBox *patternWidget;
163 QLabel *stereoMixLabel;
164 QLabel *absolutePathWarningLabel;
166 DISABLE_COPY_AND_ASSIGNMENT(PreferencesDialog);
169 // The per caller editor dialog
171 class PerCallerPreferencesDialog : public QDialog {
172 Q_OBJECT
173 public:
174 PerCallerPreferencesDialog(QWidget *);
176 private slots:
177 void add(const QString & = QString(), int = 1, bool = true);
178 void remove();
179 void selectionChanged();
180 void radioChanged();
181 void save();
183 private:
184 QListView *listWidget;
185 PerCallerModel *model;
186 QRadioButton *radioYes;
187 QRadioButton *radioAsk;
188 QRadioButton *radioNo;
190 DISABLE_COPY_AND_ASSIGNMENT(PerCallerPreferencesDialog);
193 // per caller model
195 class PerCallerModel : public QAbstractListModel {
196 Q_OBJECT
197 public:
198 PerCallerModel(QObject *parent) : QAbstractListModel(parent) { }
199 int rowCount(const QModelIndex & = QModelIndex()) const;
200 QVariant data(const QModelIndex &, int) const;
201 bool setData(const QModelIndex &, const QVariant &, int = Qt::EditRole);
202 bool insertRows(int, int, const QModelIndex &);
203 bool removeRows(int, int, const QModelIndex &);
204 void sort(int = 0, Qt::SortOrder = Qt::AscendingOrder);
205 Qt::ItemFlags flags(const QModelIndex &) const;
207 private:
208 QStringList skypeNames;
209 QList<int> modes;
212 // the only instance of Preferences
214 extern Preferences preferences;
215 extern QString getOutputPath();
216 extern QString getFileName(const QString &, const QString &, const QString &,
217 const QString &, const QDateTime &, const QString & = QString());
219 // preference constants
221 #define X(name, string) const char * const name = #string;
223 namespace Pref {
225 X(AutoRecordDefault, autorecord.default)
226 X(AutoRecordAsk, autorecord.ask)
227 X(AutoRecordYes, autorecord.yes)
228 X(AutoRecordNo, autorecord.no)
229 X(OutputPath, output.path)
230 X(OutputPattern, output.pattern)
231 X(OutputFormat, output.format)
232 X(OutputFormatMp3Bitrate, output.format.mp3.bitrate)
233 X(OutputFormatVorbisQuality, output.format.vorbis.quality)
234 X(OutputStereo, output.stereo)
235 X(OutputStereoMix, output.stereo.mix)
236 X(OutputSaveTags, output.savetags)
237 X(SuppressLegalInformation, suppress.legalinformation)
238 X(SuppressFirstRunInformation, suppress.firstruninformation)
239 X(PreferencesVersion, preferences.version)
240 X(NotifyRecordingStart, notify.recordingstart)
241 X(GuiWindowed, gui.windowed)
242 X(DebugWriteSyncFile, debug.writesyncfile)
246 #undef X
248 #endif