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
30 #include <QStringList>
31 #include <QAbstractListModel>
39 class PerCallerPreferencesDialog
;
41 class SmartEditableComboBox
;
46 // A single preference, with a name and a value
50 Preference(const Preference
&p
) : m_name(p
.m_name
), isSet(p
.isSet
), value(p
.value
) { }
51 Preference(const QString
&n
) : m_name(n
), isSet(false) { }
52 template <typename T
> Preference(const QString
&n
, const T
&t
) : m_name(n
), isSet(false) { set(t
); }
54 const QString
&toString() const { return value
; }
55 int toInt() const { return value
.toInt(); }
56 bool toBool() const { return value
.compare("yes", Qt::CaseInsensitive
) == 0 || value
.toInt(); }
57 QStringList
toList() const { return value
.split(',', QString::SkipEmptyParts
); }
58 void listAdd(const QString
&);
59 void listRemove(const QString
&);
60 bool listContains(const QString
&);
62 void set(const char *v
) { isSet
= true; value
= v
; }
63 void set(const QString
&v
) { isSet
= true; value
= v
; }
64 void set(int v
) { isSet
= true; value
.setNum(v
); }
65 void set(bool v
) { isSet
= true; value
= v
? "yes" : "no"; }
66 void set(const QStringList
&v
) { isSet
= true; value
= v
.join(","); }
68 template <typename T
> void setIfNotSet(const T
&v
) { if (!isSet
) set(v
); }
70 const QString
&name() const { return m_name
; }
72 bool operator<(const Preference
&rhs
) const {
73 return m_name
< rhs
.m_name
;
82 // disable assignment. we want preference names to be immutable.
83 Preference
&operator=(const Preference
&);
86 // A collection of preferences that can be loaded/saved
88 class BasePreferences
{
90 BasePreferences() { };
93 bool load(const QString
&);
94 bool save(const QString
&);
96 Preference
&get(const QString
&);
97 // Warning: remove() must only be used if nobody has a pointer to the
98 // preference, like for example smart widgets
99 void remove(const QString
&);
100 bool exists(const QString
&) const;
103 int count() const { return prefs
.size(); }
106 // this is a list of pointers, so we can control the life time of each
107 // Preference. we want references to them to be valid forever. Only
108 // QLinkedList could give that guarantee, but it's unpractical for
109 // sorting. QList<Preference> would technically be implemented as an
110 // array of pointers too, but its sorting semantics with regard to
111 // references are not the one we want.
112 QList
<Preference
*> prefs
;
114 DISABLE_COPY_AND_ASSIGNMENT(BasePreferences
);
117 // preferences with some utils
119 class Preferences
: public BasePreferences
{
123 void setPerCallerPreference(const QString
&, int);
125 DISABLE_COPY_AND_ASSIGNMENT(Preferences
);
128 // The preferences dialog
130 class PreferencesDialog
: public QDialog
{
134 void closePerCallerDialog();
137 void hideEvent(QHideEvent
*);
140 void updateFormatSettings();
141 void editPerCallerPreferences();
142 void updatePatternToolTip(const QString
&);
143 void updateStereoSettings(bool);
144 void updateStereoMixLabel(int);
145 void browseOutputPath();
148 QList
<QWidget
*> mp3Settings
;
149 QList
<QWidget
*> vorbisSettings
;
150 QList
<QWidget
*> stereoSettings
;
151 SmartLineEdit
*outputPathEdit
;
152 SmartComboBox
*formatWidget
;
153 QPointer
<PerCallerPreferencesDialog
> perCallerDialog
;
154 SmartEditableComboBox
*patternWidget
;
155 QLabel
*stereoMixLabel
;
157 DISABLE_COPY_AND_ASSIGNMENT(PreferencesDialog
);
160 // The per caller editor dialog
162 class PerCallerPreferencesDialog
: public QDialog
{
165 PerCallerPreferencesDialog(QWidget
*);
168 void add(const QString
& = QString(), int = 1, bool = true);
170 void selectionChanged();
175 QListView
*listWidget
;
176 PerCallerModel
*model
;
177 QRadioButton
*radioYes
;
178 QRadioButton
*radioAsk
;
179 QRadioButton
*radioNo
;
181 DISABLE_COPY_AND_ASSIGNMENT(PerCallerPreferencesDialog
);
186 class PerCallerModel
: public QAbstractListModel
{
189 PerCallerModel(QObject
*parent
) : QAbstractListModel(parent
) { }
190 int rowCount(const QModelIndex
& = QModelIndex()) const;
191 QVariant
data(const QModelIndex
&, int) const;
192 bool setData(const QModelIndex
&, const QVariant
&, int = Qt::EditRole
);
193 bool insertRows(int, int, const QModelIndex
&);
194 bool removeRows(int, int, const QModelIndex
&);
195 void sort(int = 0, Qt::SortOrder
= Qt::AscendingOrder
);
196 Qt::ItemFlags
flags(const QModelIndex
&) const;
199 QStringList skypeNames
;
203 // the only instance of Preferences
205 extern Preferences preferences
;
206 extern QString
getOutputPath();
207 extern QString
getFileName(const QString
&, const QString
&, const QString
&,
208 const QString
&, const QDateTime
&, const QString
& = QString());
210 // preference constants
212 #define X(name, string) const char * const name = #string;
216 X(AutoRecordDefault
, autorecord
.default)
217 X(AutoRecordAsk
, autorecord
.ask
)
218 X(AutoRecordYes
, autorecord
.yes
)
219 X(AutoRecordNo
, autorecord
.no
)
220 X(OutputPath
, output
.path
)
221 X(OutputPattern
, output
.pattern
)
222 X(OutputFormat
, output
.format
)
223 X(OutputFormatMp3Bitrate
, output
.format
.mp3
.bitrate
)
224 X(OutputFormatVorbisQuality
, output
.format
.vorbis
.quality
)
225 X(OutputStereo
, output
.stereo
)
226 X(OutputStereoMix
, output
.stereo
.mix
)
227 X(OutputSaveTags
, output
.savetags
)
228 X(SuppressLegalInformation
, suppress
.legalinformation
)
229 X(SuppressFirstRunInformation
, suppress
.firstruninformation
)
230 X(PreferencesVersion
, preferences
.version
)
231 X(NotifyRecordingStart
, notify
.recordingstart
)
232 X(GuiWindowed
, gui
.windowed
)
233 X(DebugWriteSyncFile
, debug
.writesyncfile
)