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>
36 class PerCallerPreferencesDialog
;
38 class SmartEditableComboBox
;
41 // A single preference, with a name and a value
45 Preference(const Preference
&p
) : m_name(p
.m_name
), isSet(p
.isSet
), value(p
.value
) { }
46 Preference
&operator=(const Preference
&p
) { m_name
= p
.m_name
; isSet
= p
.isSet
; value
= p
.value
; return *this; }
47 Preference(const QString
&n
) : m_name(n
), isSet(false) { }
48 template <typename T
> Preference(const QString
&n
, const T
&t
) : m_name(n
), isSet(false) { set(t
); }
50 const QString
&toString() const { return value
; }
51 int toInt() const { return value
.toInt(); }
52 bool toBool() const { return value
.compare("yes", Qt::CaseInsensitive
) == 0 || value
.toInt(); }
53 QStringList
toList() const { return value
.split(',', QString::SkipEmptyParts
); }
54 void listAdd(const QString
&);
55 void listRemove(const QString
&);
56 bool listContains(const QString
&);
58 void set(const char *v
) { isSet
= true; value
= v
; }
59 void set(const QString
&v
) { isSet
= true; value
= v
; }
60 void set(int v
) { isSet
= true; value
.setNum(v
); }
61 void set(bool v
) { isSet
= true; value
= v
? "yes" : "no"; }
62 void set(const QStringList
&v
) { isSet
= true; value
= v
.join(","); }
64 template <typename T
> void setIfNotSet(const T
&v
) { if (!isSet
) set(v
); }
66 const QString
&name() const { return m_name
; }
68 bool operator<(const Preference
&rhs
) const {
69 return m_name
< rhs
.m_name
;
78 // A collection of preferences that can be loaded/saved
80 class BasePreferences
{
82 bool load(const QString
&);
83 bool save(const QString
&);
85 Preference
&get(const QString
&);
86 void clear() { preferences
.clear(); }
88 int count() const { return preferences
.size(); }
91 QList
<Preference
> preferences
;
94 // preferences with some utils
96 class Preferences
: public BasePreferences
{
98 void setPerCallerPreference(const QString
&, int);
101 // The preferences dialog
103 class PreferencesDialog
: public QDialog
{
109 void hideEvent(QHideEvent
*);
112 void enableMp3Settings();
113 void editPerCallerPreferences();
114 void perCallerFinished();
115 void updatePatternToolTip(const QString
&);
118 QList
<QWidget
*> mp3Settings
;
119 SmartComboBox
*formatWidget
;
120 PerCallerPreferencesDialog
*perCallerDialog
;
121 SmartEditableComboBox
*patternWidget
;
125 PreferencesDialog(const PreferencesDialog
&);
126 PreferencesDialog
&operator=(const PreferencesDialog
&);
129 // The per caller editor dialog
131 class PerCallerPreferencesDialog
: public QDialog
{
134 PerCallerPreferencesDialog(QWidget
*);
137 void add(const QString
& = QString(), int = 1, bool = true);
139 void selectionChanged();
144 QListView
*listWidget
;
145 PerCallerModel
*model
;
146 QRadioButton
*radioYes
;
147 QRadioButton
*radioAsk
;
148 QRadioButton
*radioNo
;
153 class PerCallerModel
: public QAbstractListModel
{
156 PerCallerModel(QObject
*parent
) : QAbstractListModel(parent
) { }
157 int rowCount(const QModelIndex
& = QModelIndex()) const;
158 QVariant
data(const QModelIndex
&, int) const;
159 bool setData(const QModelIndex
&, const QVariant
&, int = Qt::EditRole
);
160 bool insertRows(int, int, const QModelIndex
&);
161 bool removeRows(int, int, const QModelIndex
&);
162 void sort(int = 0, Qt::SortOrder
= Qt::AscendingOrder
);
163 Qt::ItemFlags
flags(const QModelIndex
&) const;
166 QStringList skypeNames
;
170 // the only instance of Preferences
172 extern Preferences preferences
;
173 extern QString
getOutputPath();
174 extern QString
getFileName(const QString
&, const QString
&, const QString
&,
175 const QString
&, const QDateTime
&, const QString
& = QString());