1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "infowidgetpreferences.h" |
|
19 #include "infowidgetlogging.h" |
|
20 |
|
21 /*! |
|
22 \class InfoWidgetPreferences |
|
23 \brief Preference store for widget |
|
24 display etc. options |
|
25 */ |
|
26 |
|
27 |
|
28 /*! |
|
29 InfoWidgetPreferences::InfoWidgetPreferences() |
|
30 */ |
|
31 InfoWidgetPreferences::InfoWidgetPreferences(QObject *parent): |
|
32 QObject(parent) |
|
33 { |
|
34 DPRINT; |
|
35 } |
|
36 |
|
37 /*! |
|
38 InfoWidgetPreferences::~InfoWidgetPreferences() |
|
39 */ |
|
40 InfoWidgetPreferences::~InfoWidgetPreferences() |
|
41 { |
|
42 DPRINT; |
|
43 } |
|
44 |
|
45 /*! |
|
46 InfoWidgetPreferences::storePreferences() |
|
47 |
|
48 Store acceptable preference set |
|
49 */ |
|
50 bool InfoWidgetPreferences::storePreferences() |
|
51 { |
|
52 DPRINT; |
|
53 bool changed(false); |
|
54 |
|
55 if (validate() && |
|
56 m_validatedOptions != m_options){ |
|
57 DPRINT << ": preferences differ"; |
|
58 changed = true; |
|
59 m_validatedOptions = m_options; |
|
60 } |
|
61 else if (visibleItemCount() <= 0) { |
|
62 DPRINT << ": invalid options, restoring initial options"; |
|
63 restorePreferences(); |
|
64 } |
|
65 |
|
66 return changed; |
|
67 } |
|
68 |
|
69 /*! |
|
70 InfoWidgetPreferences::restorePreferences() |
|
71 |
|
72 Restores last acceptable preference set |
|
73 */ |
|
74 void InfoWidgetPreferences::restorePreferences() |
|
75 { |
|
76 DPRINT; |
|
77 m_options = m_validatedOptions; |
|
78 } |
|
79 |
|
80 /*! |
|
81 InfoWidgetPreferences::preference() |
|
82 */ |
|
83 QString InfoWidgetPreferences::preference(Option preferenceId) const |
|
84 { |
|
85 DPRINT << ": preference id: " << static_cast<int>(preferenceId); |
|
86 |
|
87 QString preferenceString; |
|
88 if (m_options.testFlag(preferenceId)) { |
|
89 preferenceString = DISPLAY_SETTING_ON; |
|
90 } else { |
|
91 preferenceString = DISPLAY_SETTING_OFF; |
|
92 } |
|
93 |
|
94 return preferenceString; |
|
95 } |
|
96 |
|
97 /*! |
|
98 InfoWidgetPreferences::isPreferenceSet() |
|
99 */ |
|
100 bool InfoWidgetPreferences::isPreferenceSet(Option preferenceId) const |
|
101 { |
|
102 DPRINT << ": preference id: " << static_cast<int>(preferenceId); |
|
103 return m_options.testFlag(preferenceId); |
|
104 } |
|
105 |
|
106 /*! |
|
107 InfoWidgetPreferences::preferences() |
|
108 */ |
|
109 InfoWidgetPreferences::Options InfoWidgetPreferences::preferences() const |
|
110 { |
|
111 return m_options; |
|
112 } |
|
113 |
|
114 /*! |
|
115 InfoWidgetPreferences::setPreference() |
|
116 */ |
|
117 void InfoWidgetPreferences::setPreference(Option preferenceId, |
|
118 const QString& preferenceString) |
|
119 { |
|
120 DPRINT << ": preference id: " << static_cast<int>(preferenceId); |
|
121 DPRINT << ": preference string: " << preferenceString; |
|
122 DPRINT << ": initial options: " << m_options; |
|
123 |
|
124 if (preferenceString.compare(DISPLAY_SETTING_ON) == 0) { |
|
125 m_options |= preferenceId; |
|
126 emit prefChanged(preferenceId,DisplayOn); |
|
127 } else { |
|
128 m_options &= ~preferenceId; |
|
129 emit prefChanged(preferenceId,DisplayOff); |
|
130 } |
|
131 |
|
132 DPRINT << ": modified options: " << m_options; |
|
133 } |
|
134 |
|
135 /*! |
|
136 InfoWidgetPreferences::visibleItemCount() |
|
137 */ |
|
138 int InfoWidgetPreferences::visibleItemCount() |
|
139 { |
|
140 DPRINT << ": IN"; |
|
141 |
|
142 int visibleItems = 0; |
|
143 if (m_options.testFlag(DisplayHomeZone)){ |
|
144 visibleItems++; |
|
145 } |
|
146 if (m_options.testFlag(DisplayMcn)){ |
|
147 visibleItems++; |
|
148 } |
|
149 if (m_options.testFlag(DisplayActiveLine)){ |
|
150 visibleItems++; |
|
151 } |
|
152 if (m_options.testFlag(DisplaySatText)){ |
|
153 visibleItems++; |
|
154 } |
|
155 if (m_options.testFlag(DisplaySpn)){ |
|
156 visibleItems++; |
|
157 } |
|
158 |
|
159 DPRINT << ": visible item count: " << visibleItems; |
|
160 return visibleItems; |
|
161 } |
|
162 |
|
163 /*! |
|
164 InfoWidgetPreferences::validate() |
|
165 */ |
|
166 bool InfoWidgetPreferences::validate() |
|
167 { |
|
168 return visibleItemCount() > 0; |
|
169 } |
|
170 |
|
171 /*! |
|
172 InfoWidgetPreferences::preferenceNames() |
|
173 |
|
174 Convenience function for getting all preference names |
|
175 */ |
|
176 QStringList InfoWidgetPreferences::preferenceNames() |
|
177 { |
|
178 QStringList preferenceList; |
|
179 preferenceList << "spnDisplay" << "homeZoneDisplay" << |
|
180 "activeLineDisplay" << "satDisplay" << "mcnDisplay"; |
|
181 return preferenceList; |
|
182 } |
|
183 |
|
184 |
|
185 // End of File. |
|
186 |
|