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
;
39 // A single preference, with a name and a value
43 Preference(const Preference
&p
) : m_name(p
.m_name
), isSet(p
.isSet
), value(p
.value
) { }
44 Preference
&operator=(const Preference
&p
) { m_name
= p
.m_name
; isSet
= p
.isSet
; value
= p
.value
; return *this; }
45 Preference(const QString
&n
) : m_name(n
), isSet(false) { }
46 template <typename T
> Preference(const QString
&n
, const T
&t
) : m_name(n
), isSet(false) { set(t
); }
48 const QString
&toString() const { return value
; }
49 int toInt() const { return value
.toInt(); }
50 bool toBool() const { return value
.compare("yes", Qt::CaseInsensitive
) == 0 || value
.toInt(); }
51 QStringList
toList() const { return value
.split(',', QString::SkipEmptyParts
); }
52 void listAdd(const QString
&);
53 void listRemove(const QString
&);
54 bool listContains(const QString
&);
56 void set(const char *v
) { isSet
= true; value
= v
; }
57 void set(const QString
&v
) { isSet
= true; value
= v
; }
58 void set(int v
) { isSet
= true; value
.setNum(v
); }
59 void set(bool v
) { isSet
= true; value
= v
? "yes" : "no"; }
60 void set(const QStringList
&v
) { isSet
= true; value
= v
.join(","); }
62 template <typename T
> void setIfNotSet(const T
&v
) { if (!isSet
) set(v
); }
64 const QString
&name() const { return m_name
; }
66 bool operator<(const Preference
&rhs
) const {
67 return m_name
< rhs
.m_name
;
76 // A collection of preferences that can be loaded/saved
78 class BasePreferences
{
80 bool load(const QString
&);
81 bool save(const QString
&);
83 Preference
&get(const QString
&);
84 void clear() { preferences
.clear(); }
86 int count() const { return preferences
.size(); }
89 QList
<Preference
> preferences
;
92 // preferences with some utils
94 class Preferences
: public BasePreferences
{
96 void setPerCallerPreference(const QString
&, int);
99 // The preferences dialog
101 class PreferencesDialog
: public QDialog
{
107 void hideEvent(QHideEvent
*);
110 void enableMp3Settings();
111 void editPerCallerPreferences();
112 void perCallerFinished();
115 QList
<QWidget
*> mp3Settings
;
116 SmartComboBox
*formatWidget
;
117 PerCallerPreferencesDialog
*perCallerDialog
;
121 PreferencesDialog(const PreferencesDialog
&);
122 PreferencesDialog
&operator=(const PreferencesDialog
&);
125 // The per caller editor dialog
127 class PerCallerPreferencesDialog
: public QDialog
{
130 PerCallerPreferencesDialog(QWidget
*);
133 void add(const QString
& = QString(), int = 1, bool = true);
135 void selectionChanged();
140 QListView
*listWidget
;
141 PerCallerModel
*model
;
142 QRadioButton
*radioYes
;
143 QRadioButton
*radioAsk
;
144 QRadioButton
*radioNo
;
149 class PerCallerModel
: public QAbstractListModel
{
152 PerCallerModel(QObject
*parent
) : QAbstractListModel(parent
) { }
153 int rowCount(const QModelIndex
& = QModelIndex()) const;
154 QVariant
data(const QModelIndex
&, int) const;
155 bool setData(const QModelIndex
&, const QVariant
&, int = Qt::EditRole
);
156 bool insertRows(int, int, const QModelIndex
&);
157 bool removeRows(int, int, const QModelIndex
&);
158 void sort(int = 0, Qt::SortOrder
= Qt::AscendingOrder
);
159 Qt::ItemFlags
flags(const QModelIndex
&) const;
162 QStringList skypeNames
;
166 // the only instance of Preferences
168 extern Preferences preferences
;
169 extern QString
getOutputPath();