ADD : Caching as a preference
[semperweb:semperweb.git] / MyPreferences.h
1 //
2 // C++ Interface: MyPreferences
3 //
4 // Description:
5 //
6 //
7 // Author: cbro <cbro@semperpax.com> (C) 2008, 2009
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #ifndef MYPREFERENCES_H
14 #define MYPREFERENCES_H
15
16 #include <QDialog>
17
18 class QSettings;
19
20 #define M_PARAM_DECLARE_BOOL(Param, Category) \
21     private: \
22         bool m_##Category##Param; \
23         void initWidget##Category##Param(); \
24         void retrieveWidget##Category##Param(); \
25     public slots: \
26         void set##Category##Param(bool theValue); \
27     public: \
28         bool get##Category##Param();
29
30 #define M_PARAM_DECLARE_STRING(Param, Category) \
31     private: \
32         QString m_##Category##Param; \
33         void initWidget##Category##Param(); \
34         void retrieveWidget##Category##Param(); \
35     public slots: \
36         void set##Category##Param(QString theValue); \
37     public: \
38         QString get##Category##Param();
39
40 #define M_PARAM_DECLARE_INT(Param, Category) \
41     private: \
42         int m_##Category##Param; \
43         void initWidget##Category##Param(); \
44         void retrieveWidget##Category##Param(); \
45     public slots: \
46         void set##Category##Param(int theValue); \
47     public: \
48         int get##Category##Param();
49
50 #define M_PARAM_DECLARE_DOUBLE(Param, Category) \
51     private: \
52         double m_##Category##Param; \
53         void initWidget##Category##Param(); \
54         void retrieveWidget##Category##Param(); \
55     public slots: \
56         void set##Category##Param(double theValue); \
57     public: \
58         double get##Category##Param();
59
60 #define SAFE_DELETE(x) {delete (x); x = NULL;}
61 #define STRINGIFY(x) XSTRINGIFY(x)
62 #define XSTRINGIFY(x) #x
63
64 #define M_PREFS MyPreferences::instance()
65
66 /***************************/
67
68 namespace Ui {
69     class MyPreferencesDialog;
70 }
71
72 class MyPreferences : public QWidget
73 {
74     Q_OBJECT
75
76 public:
77     MyPreferences(QWidget *parent = 0);
78     ~MyPreferences();
79
80     static MyPreferences* instance() {
81         if (!m_prefInstance) {
82             m_prefInstance = new MyPreferences;
83         }
84
85         return m_prefInstance;
86     }
87     static MyPreferences* m_prefInstance;
88
89 public slots:
90     bool execPreferences();
91
92 private slots:
93     void accept();
94     void reject();
95
96 protected:
97     void changeEvent(QEvent *e);
98
99 private:
100     Ui::MyPreferencesDialog *ui;
101     int m_dialogResult;
102
103     QSettings * Sets;
104
105 public:
106     M_PARAM_DECLARE_INT(UserAgent, General)
107     M_PARAM_DECLARE_STRING(LastPicDownloadDir, General)
108     M_PARAM_DECLARE_STRING(LastDataDownloadDir, General)
109     M_PARAM_DECLARE_INT(InstantHistorySize, Caching)
110 };
111
112 #endif // MYPREFERENCES_H