|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbdevicefadecontrol_p.h" |
|
27 |
|
28 #include <e32base.h> |
|
29 #include <e32std.h> |
|
30 #include <e32property.h> |
|
31 |
|
32 #include <QApplication> |
|
33 #include <QEvent> |
|
34 |
|
35 // There is only one fade control setter, all other applications are getters. |
|
36 // Device dialog is the setter. |
|
37 const TUid PropertyCategoryUid = {0x20022FC5}; |
|
38 const TUint FadeKey = 'fade'; |
|
39 |
|
40 class HbDeviceFadeControlPrivate : public CActive |
|
41 { |
|
42 public: |
|
43 struct FadeControl { |
|
44 int fadeOff:1; // command for application to unfade |
|
45 int spare:31; |
|
46 }; |
|
47 |
|
48 public: |
|
49 HbDeviceFadeControlPrivate(HbDeviceFadeControl *parent); |
|
50 ~HbDeviceFadeControlPrivate(); |
|
51 |
|
52 FadeControl get(); |
|
53 void set(FadeControl control); |
|
54 |
|
55 void start(); |
|
56 |
|
57 static void create(HbDeviceFadeControl *parent); |
|
58 |
|
59 public: // from CActive |
|
60 void RunL(); |
|
61 void DoCancel(); |
|
62 |
|
63 public: |
|
64 HbDeviceFadeControl *p; |
|
65 RProperty mProperty; |
|
66 bool mIsSetter; |
|
67 FadeControl mSetValue; |
|
68 }; |
|
69 |
|
70 HbDeviceFadeControlPrivate::HbDeviceFadeControlPrivate(HbDeviceFadeControl *parent) : |
|
71 CActive(EPriorityHigh), p(parent) |
|
72 { |
|
73 RProcess process; |
|
74 mIsSetter = process.SecureId().operator TUid() == PropertyCategoryUid; |
|
75 |
|
76 mSetValue.fadeOff = false; |
|
77 mSetValue.spare = 0; |
|
78 |
|
79 // Device dialog server is a writer and creates the property. |
|
80 if (mIsSetter) { |
|
81 _LIT_SECURITY_POLICY_PASS(KRdPolicy); // all pass |
|
82 _LIT_SECURITY_POLICY_S0(KWrPolicy, PropertyCategoryUid.iUid); // pass device dialog server |
|
83 mProperty.Define(PropertyCategoryUid, FadeKey, RProperty::EInt, KRdPolicy, KWrPolicy); |
|
84 } |
|
85 mProperty.Attach(PropertyCategoryUid, FadeKey); |
|
86 if (!mIsSetter) { |
|
87 CActiveScheduler::Add(this); |
|
88 start(); |
|
89 } |
|
90 } |
|
91 |
|
92 HbDeviceFadeControlPrivate::~HbDeviceFadeControlPrivate() |
|
93 { |
|
94 Cancel(); |
|
95 mProperty.Close(); |
|
96 } |
|
97 |
|
98 // Get fade control |
|
99 HbDeviceFadeControlPrivate::FadeControl HbDeviceFadeControlPrivate::get() |
|
100 { |
|
101 union { |
|
102 FadeControl asBits; |
|
103 TInt asInt; |
|
104 } fadeControl; |
|
105 fadeControl.asInt = 0; |
|
106 if (!mIsSetter) { |
|
107 mProperty.Get(PropertyCategoryUid, FadeKey, fadeControl.asInt); |
|
108 } |
|
109 return fadeControl.asBits; |
|
110 } |
|
111 |
|
112 // Set (write) fade control |
|
113 void HbDeviceFadeControlPrivate::set(FadeControl control) |
|
114 { |
|
115 if (mIsSetter && control.fadeOff != mSetValue.fadeOff) { |
|
116 mSetValue.fadeOff = control.fadeOff; |
|
117 union { |
|
118 FadeControl asBits; |
|
119 TInt asInt; |
|
120 } fadeControl; |
|
121 fadeControl.asBits = mSetValue; |
|
122 mProperty.Set(PropertyCategoryUid, FadeKey, fadeControl.asInt); |
|
123 if (!mSetValue.fadeOff) { |
|
124 // If underlying applications are to restore their fading, set this process priority |
|
125 // to background to allow faster restore. |
|
126 //RProcess().SetPriority(EPriorityBackground); |
|
127 } |
|
128 } |
|
129 } |
|
130 |
|
131 // Start property watch request |
|
132 void HbDeviceFadeControlPrivate::start() |
|
133 { |
|
134 mProperty.Subscribe(iStatus); |
|
135 SetActive(); |
|
136 } |
|
137 |
|
138 // Create private if not yet created |
|
139 void HbDeviceFadeControlPrivate::create(HbDeviceFadeControl *parent) |
|
140 { |
|
141 if (!parent->d) { |
|
142 parent->d = new HbDeviceFadeControlPrivate(parent); |
|
143 } |
|
144 } |
|
145 |
|
146 |
|
147 // Property value has changed |
|
148 void HbDeviceFadeControlPrivate::RunL() |
|
149 { |
|
150 TInt completionCode = iStatus.Int(); |
|
151 if (completionCode != KErrCancel) { |
|
152 start(); |
|
153 } |
|
154 if (completionCode == KErrNone) { |
|
155 emit p->fadeChange(get().fadeOff); |
|
156 } |
|
157 } |
|
158 |
|
159 // Cancel property subscribe |
|
160 void HbDeviceFadeControlPrivate::DoCancel() |
|
161 { |
|
162 mProperty.Cancel(); |
|
163 } |
|
164 |
|
165 HbDeviceFadeControl::HbDeviceFadeControl(QObject *parent) : QObject(parent) |
|
166 { |
|
167 // Creation of private is delayed until any popups are created |
|
168 d = 0; |
|
169 } |
|
170 |
|
171 HbDeviceFadeControl::~HbDeviceFadeControl() |
|
172 { |
|
173 delete d; |
|
174 } |
|
175 |
|
176 // Return background fading off control |
|
177 bool HbDeviceFadeControl::fadeOff() |
|
178 { |
|
179 HbDeviceFadeControlPrivate::create(this); // create private if not created |
|
180 return d->get().fadeOff; |
|
181 } |
|
182 |
|
183 // Set (write) background fading off control |
|
184 void HbDeviceFadeControl::setFadeOff(bool fadeOff) |
|
185 { |
|
186 HbDeviceFadeControlPrivate::create(this); // create private if not created |
|
187 HbDeviceFadeControlPrivate::FadeControl control = {0, 0}; |
|
188 control.fadeOff = fadeOff; |
|
189 d->set(control); |
|
190 } |
|
191 |
|
192 // Return if this fade controll is a setter. There is only one setter |
|
193 // (device dialog server)in a device. All other instances are getters. |
|
194 bool HbDeviceFadeControl::isSetter() |
|
195 { |
|
196 HbDeviceFadeControlPrivate::create(this); // create private if not created |
|
197 return d->mIsSetter; |
|
198 } |