Make snapshots remember what git commit they are
[skype-call-recorder.git] / preferences.h
blobc256674516739e0bf2d7830beab7e3ca6d5eb429
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>
33 class SmartComboBox;
34 class QListView;
35 class PerCallerModel;
36 class PerCallerPreferencesDialog;
37 class QRadioButton;
38 class SmartEditableComboBox;
39 class QDateTime;
41 // A single preference, with a name and a value
43 class Preference {
44 public:
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;
72 private:
73 QString m_name;
74 bool isSet;
75 QString value;
78 // A collection of preferences that can be loaded/saved
80 class BasePreferences {
81 public:
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(); }
90 private:
91 QList<Preference> preferences;
94 // preferences with some utils
96 class Preferences : public BasePreferences {
97 public:
98 void setPerCallerPreference(const QString &, int);
101 // The preferences dialog
103 class PreferencesDialog : public QDialog {
104 Q_OBJECT
105 public:
106 PreferencesDialog();
108 protected:
109 void hideEvent(QHideEvent *);
111 private slots:
112 void enableMp3Settings();
113 void editPerCallerPreferences();
114 void perCallerFinished();
115 void updatePatternToolTip(const QString &);
117 private:
118 QList<QWidget *> mp3Settings;
119 SmartComboBox *formatWidget;
120 PerCallerPreferencesDialog *perCallerDialog;
121 SmartEditableComboBox *patternWidget;
123 private:
124 // disabled
125 PreferencesDialog(const PreferencesDialog &);
126 PreferencesDialog &operator=(const PreferencesDialog &);
129 // The per caller editor dialog
131 class PerCallerPreferencesDialog : public QDialog {
132 Q_OBJECT
133 public:
134 PerCallerPreferencesDialog(QWidget *);
136 private slots:
137 void add(const QString & = QString(), int = 1, bool = true);
138 void remove();
139 void selectionChanged();
140 void radioChanged();
141 void save();
143 private:
144 QListView *listWidget;
145 PerCallerModel *model;
146 QRadioButton *radioYes;
147 QRadioButton *radioAsk;
148 QRadioButton *radioNo;
151 // per caller model
153 class PerCallerModel : public QAbstractListModel {
154 Q_OBJECT
155 public:
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;
165 private:
166 QStringList skypeNames;
167 QList<int> modes;
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());
177 #endif