Make sure refused calls are removed
[skype-call-recorder.git] / preferences.h
blob7c7b3957c5f5d4995784b56f9ba7ef33ebf3c7a6
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;
39 // A single preference, with a name and a value
41 class Preference {
42 public:
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;
70 private:
71 QString m_name;
72 bool isSet;
73 QString value;
76 // A collection of preferences that can be loaded/saved
78 class BasePreferences {
79 public:
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(); }
88 private:
89 QList<Preference> preferences;
92 // preferences with some utils
94 class Preferences : public BasePreferences {
95 public:
96 void setPerCallerPreference(const QString &, int);
99 // The preferences dialog
101 class PreferencesDialog : public QDialog {
102 Q_OBJECT
103 public:
104 PreferencesDialog();
106 protected:
107 void hideEvent(QHideEvent *);
109 private slots:
110 void enableMp3Settings();
111 void editPerCallerPreferences();
112 void perCallerFinished();
114 private:
115 QList<QWidget *> mp3Settings;
116 SmartComboBox *formatWidget;
117 PerCallerPreferencesDialog *perCallerDialog;
119 private:
120 // disabled
121 PreferencesDialog(const PreferencesDialog &);
122 PreferencesDialog &operator=(const PreferencesDialog &);
125 // The per caller editor dialog
127 class PerCallerPreferencesDialog : public QDialog {
128 Q_OBJECT
129 public:
130 PerCallerPreferencesDialog(QWidget *);
132 private slots:
133 void add(const QString & = QString(), int = 1, bool = true);
134 void remove();
135 void selectionChanged();
136 void radioChanged();
137 void save();
139 private:
140 QListView *listWidget;
141 PerCallerModel *model;
142 QRadioButton *radioYes;
143 QRadioButton *radioAsk;
144 QRadioButton *radioNo;
147 // per caller model
149 class PerCallerModel : public QAbstractListModel {
150 Q_OBJECT
151 public:
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;
161 private:
162 QStringList skypeNames;
163 QList<int> modes;
166 // the only instance of Preferences
168 extern Preferences preferences;
169 extern QString getOutputPath();
171 #endif