Fix preferences on BB10. Using a key of "general/colorNum" made Bedside.conf look...
[jaffas-playground:bedside.git] / src / applicationdata.h
1 #ifndef MAIN_H
2 #define MAIN_H
3
4 #include <QSettings>
5 #include <QColor>
6 #include <QDebug>
7 #include <qplatformdefs.h>
8
9 #ifdef MEEGO_EDITION_HARMATTAN
10   #include <MLocale>
11 #elif defined(Q_OS_BLACKBERRY)
12   #include <bb/pim/calendar/CalendarService>
13   #include <bb/pim/calendar/CalendarSettings>
14 #endif
15
16 class ApplicationData : public QObject
17 {
18     Q_OBJECT
19     Q_PROPERTY(int colorNum READ colorNum WRITE setColorNum NOTIFY colorNumChanged)
20     Q_PROPERTY(QColor color READ color NOTIFY colorChanged)
21     Q_PROPERTY(bool dimmed READ dimmed WRITE setDimmed NOTIFY dimmedChanged)
22 public:
23     void initialize() {
24         QSettings settings("jaffa","Bedside");
25         m_colorNum = settings.value("colorNum",0).toInt();
26         m_dimmed = settings.value("dimmed",false).toBool();
27     }
28
29     bool twelveHourClock() {
30         bool ampm = false;
31
32         #ifdef MEEGO_EDITION_HARMATTAN
33             MLocale locale;
34             MLocale::TimeFormat24h timeFormat = locale.timeFormat24h();
35             if (timeFormat == MLocale::LocaleDefaultTimeFormat24h)
36                 timeFormat = locale.defaultTimeFormat24h();
37
38             ampm = timeFormat == MLocale::TwelveHourTimeFormat24h;
39
40         #elif defined(Q_OS_BLACKBERRY)
41             bb::pim::calendar::CalendarService calendarService;
42             ampm = !calendarService.settings().is24HourFormat();
43
44         #else
45             QLocale locale;
46             ampm = locale.timeFormat().indexOf("AP") != -1;
47         #endif
48         qDebug() << "Twelve hour clock = " << ampm;
49
50         return ampm;
51     }
52
53     int colorNum() {
54         return m_colorNum;
55     }
56
57     QColor color() {
58         QColor c;
59         switch (m_colorNum)
60         {
61         case 1:
62             c = Qt::cyan;
63             break;
64         case 2:
65             c = Qt::blue;
66             break;
67         case 3:
68             c = Qt::magenta;
69             break;
70         case 4:
71             c = Qt::red;
72             break;
73         case 5:
74             c = QColor("orange");
75             break;
76         case 6:
77             c = Qt::white;
78             break;
79         default:
80             c = Qt::green;
81             break;
82         }
83         return c;
84     }
85
86     bool dimmed() {
87         return m_dimmed;
88     }
89
90     void setColorNum(const int color) {
91         if (color != m_colorNum) {
92             QSettings settings("jaffa","Bedside");
93             m_colorNum = color;
94             settings.setValue("colorNum", color);
95             emit colorNumChanged();
96             emit colorChanged();
97         }
98     }
99
100     void setDimmed(const bool dim) {
101         if (dim != m_dimmed) {
102             QSettings settings("jaffa","Bedside");
103             m_dimmed = dim;
104             settings.setValue("dimmed", dim);
105             emit dimmedChanged();
106         }
107     }
108         
109 signals:
110     void colorNumChanged();
111     void colorChanged();
112     void dimmedChanged();
113 private:
114     int m_colorNum;
115     bool m_dimmed;
116 };
117
118 #endif //MAIN_H