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
;
45 // A single preference, with a name and a value
49 Preference(const Preference
&p
) : m_name(p
.m_name
), isSet(p
.isSet
), value(p
.value
) { }
50 Preference(const QString
&n
) : m_name(n
), isSet(false) { }
51 template <typename T
> Preference(const QString
&n
, const T
&t
) : m_name(n
), isSet(false) { set(t
); }
53 const QString
&toString() const { return value
; }
54 int toInt() const { return value
.toInt(); }
55 bool toBool() const { return value
.compare("yes", Qt::CaseInsensitive
) == 0 || value
.toInt(); }
56 QStringList
toList() const { return value
.split(',', QString::SkipEmptyParts
); }
57 void listAdd(const QString
&);
58 void listRemove(const QString
&);
59 bool listContains(const QString
&);
61 void set(const char *v
) { isSet
= true; value
= v
; }
62 void set(const QString
&v
) { isSet
= true; value
= v
; }
63 void set(int v
) { isSet
= true; value
.setNum(v
); }
64 void set(bool v
) { isSet
= true; value
= v
? "yes" : "no"; }
65 void set(const QStringList
&v
) { isSet
= true; value
= v
.join(","); }
67 template <typename T
> void setIfNotSet(const T
&v
) { if (!isSet
) set(v
); }
69 const QString
&name() const { return m_name
; }
71 bool operator<(const Preference
&rhs
) const {
72 return m_name
< rhs
.m_name
;
81 // disable assignment. we want preference names to be immutable.
82 Preference
&operator=(const Preference
&);
85 // A collection of preferences that can be loaded/saved
87 class BasePreferences
{
89 BasePreferences() { };
92 bool load(const QString
&);
93 bool save(const QString
&);
95 Preference
&get(const QString
&);
98 int count() const { return prefs
.size(); }
101 // this is a list of pointers, so we can control the life time of each
102 // Preference. we want references to them to be valid forever. Only
103 // QLinkedList could give that guarantee, but it's unpractical for
104 // sorting. QList<Preference> would technically be implemented as an
105 // array of pointers too, but its sorting semantics with regard to
106 // references are not the one we want.
107 QList
<Preference
*> prefs
;
109 DISABLE_COPY_AND_ASSIGNMENT(BasePreferences
);
112 // preferences with some utils
114 class Preferences
: public BasePreferences
{
118 void setPerCallerPreference(const QString
&, int);
120 DISABLE_COPY_AND_ASSIGNMENT(Preferences
);
123 // The preferences dialog
125 class PreferencesDialog
: public QDialog
{
129 void closePerCallerDialog();
132 void hideEvent(QHideEvent
*);
135 void updateFormatSettings();
136 void editPerCallerPreferences();
137 void updatePatternToolTip(const QString
&);
138 void browseOutputPath();
141 QList
<QWidget
*> mp3Settings
;
142 QList
<QWidget
*> vorbisSettings
;
143 SmartLineEdit
*outputPathEdit
;
144 SmartComboBox
*formatWidget
;
145 QPointer
<PerCallerPreferencesDialog
> perCallerDialog
;
146 SmartEditableComboBox
*patternWidget
;
148 DISABLE_COPY_AND_ASSIGNMENT(PreferencesDialog
);
151 // The per caller editor dialog
153 class PerCallerPreferencesDialog
: public QDialog
{
156 PerCallerPreferencesDialog(QWidget
*);
159 void add(const QString
& = QString(), int = 1, bool = true);
161 void selectionChanged();
166 QListView
*listWidget
;
167 PerCallerModel
*model
;
168 QRadioButton
*radioYes
;
169 QRadioButton
*radioAsk
;
170 QRadioButton
*radioNo
;
172 DISABLE_COPY_AND_ASSIGNMENT(PerCallerPreferencesDialog
);
177 class PerCallerModel
: public QAbstractListModel
{
180 PerCallerModel(QObject
*parent
) : QAbstractListModel(parent
) { }
181 int rowCount(const QModelIndex
& = QModelIndex()) const;
182 QVariant
data(const QModelIndex
&, int) const;
183 bool setData(const QModelIndex
&, const QVariant
&, int = Qt::EditRole
);
184 bool insertRows(int, int, const QModelIndex
&);
185 bool removeRows(int, int, const QModelIndex
&);
186 void sort(int = 0, Qt::SortOrder
= Qt::AscendingOrder
);
187 Qt::ItemFlags
flags(const QModelIndex
&) const;
190 QStringList skypeNames
;
194 // the only instance of Preferences
196 extern Preferences preferences
;
197 extern QString
getOutputPath();
198 extern QString
getFileName(const QString
&, const QString
&, const QString
&,
199 const QString
&, const QDateTime
&, const QString
& = QString());
201 // preference constants
203 #define X(name, string) const char * const name = #string;
207 X(AutoRecordDefault
, autorecord
.default)
208 X(AutoRecordAsk
, autorecord
.ask
)
209 X(AutoRecordYes
, autorecord
.yes
)
210 X(AutoRecordNo
, autorecord
.no
)
211 X(OutputPath
, output
.path
)
212 X(OutputPattern
, output
.pattern
)
213 X(OutputFormat
, output
.format
)
214 X(OutputFormatMp3Bitrate
, output
.format
.mp3
.bitrate
)
215 X(OutputFormatVorbisQuality
, output
.format
.vorbis
.quality
)
216 X(OutputChannelMode
, output
.channelmode
)
217 X(OutputSaveTags
, output
.savetags
)
218 X(SuppressLegalInformation
, suppress
.legalinformation
)
219 X(SuppressFirstRunInformation
, suppress
.firstruninformation
)
220 X(PreferencesVersion
, preferences
.version
)
221 X(NotifyRecordingStart
, notify
.recordingstart
)
222 X(DebugWriteSyncFile
, debug
.writesyncfile
)