|
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 HbWidgets 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 "hbdeviceinputdialogsymbian.h" |
|
27 |
|
28 #include <hbsymbianvariant.h> |
|
29 #include <hbdevicedialogsymbian.h> |
|
30 #include <coreapplicationuisdomainpskeys.h> |
|
31 |
|
32 #define ARG_UNUSED(x) (void)x; |
|
33 |
|
34 //_LIT(KDialogText, "text"); |
|
35 |
|
36 enum TInputDialogPanic { |
|
37 ELineEditPanic, |
|
38 EPropertyPanic, |
|
39 EButtonIdPanic |
|
40 }; |
|
41 |
|
42 NONSHARABLE_CLASS(CHbDeviceInputDialogPrivate) : public CBase, public MHbDeviceDialogObserver |
|
43 { |
|
44 public: |
|
45 |
|
46 void ConstructL(MHbDeviceInputDialogObserver *aObserver); |
|
47 ~CHbDeviceInputDialogPrivate(); |
|
48 |
|
49 void SetButtonNull(CHbDeviceInputDialogSymbian::TButtonId aButtonId, bool aValue); |
|
50 void SetButtonTextL(CHbDeviceInputDialogSymbian::TButtonId aButtonId, const TDesC &aValue); |
|
51 void SendToServerL(bool aShow = false); |
|
52 void Close(); |
|
53 bool WaitForClosed(); |
|
54 void AddVariantL(const TDesC& aKey, const TAny* aData,CHbSymbianVariant::TType aDataType, CHbSymbianVariantMap* map); |
|
55 |
|
56 public: // MHbDeviceDialogObserver |
|
57 void DataReceived(CHbSymbianVariantMap& aData); |
|
58 void DeviceDialogClosed(TInt aCompletionCode); |
|
59 |
|
60 public: // data |
|
61 |
|
62 CHbDeviceInputDialogSymbian *q; |
|
63 CHbDeviceDialogSymbian *mDeviceDialog; |
|
64 bool mShowCalled; |
|
65 CHbDeviceInputDialogSymbian::TButtonId mReceivedButton; |
|
66 MHbDeviceInputDialogObserver *mObserver; |
|
67 CHbSymbianVariantMap* iVariantMap; |
|
68 |
|
69 bool *mDeleted; |
|
70 CActiveSchedulerWait mActiveSchedulerWait; |
|
71 }; |
|
72 |
|
73 |
|
74 void CHbDeviceInputDialogPrivate::ConstructL(MHbDeviceInputDialogObserver *aObserver) |
|
75 { |
|
76 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::ConstructL::Begin") ) ); |
|
77 mDeviceDialog = CHbDeviceDialogSymbian::NewL(); |
|
78 iVariantMap = CHbSymbianVariantMap::NewL(); |
|
79 |
|
80 |
|
81 |
|
82 mReceivedButton = CHbDeviceInputDialogSymbian::ERejectButton; |
|
83 mObserver = aObserver; |
|
84 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::ConstructL::End") ) ); |
|
85 } |
|
86 |
|
87 // Destructor |
|
88 CHbDeviceInputDialogPrivate::~CHbDeviceInputDialogPrivate() |
|
89 { |
|
90 // If no observer, remove observer from device dialog. This leaves the |
|
91 // dialog widget executing at server when client closes connection. |
|
92 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::Destructor::Begin") ) ); |
|
93 if (!mObserver) { |
|
94 mDeviceDialog->SetObserver(0); |
|
95 } |
|
96 |
|
97 delete mDeviceDialog; |
|
98 delete iVariantMap; |
|
99 |
|
100 // Set object deleted flag |
|
101 if (mDeleted) { |
|
102 // Mark the object as deleted. |
|
103 *mDeleted = true; |
|
104 mDeleted = 0; |
|
105 } |
|
106 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::Destructor::End") ) ); |
|
107 } |
|
108 |
|
109 void CHbDeviceInputDialogPrivate::AddVariantL(const TDesC& aKey,const TAny* aData,CHbSymbianVariant::TType aDataType,CHbSymbianVariantMap* map ) |
|
110 { |
|
111 CHbSymbianVariant *variant = CHbSymbianVariant::NewL(aData, aDataType); |
|
112 CleanupStack::PushL(variant); |
|
113 User::LeaveIfError(map->Add(aKey, variant)); |
|
114 CleanupStack::Pop(variant); |
|
115 } |
|
116 |
|
117 // Send properties to server. Show or update. |
|
118 void CHbDeviceInputDialogPrivate::SendToServerL(bool /* aShow */) |
|
119 { |
|
120 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::SendToServerL::Begin") ) ); |
|
121 _LIT(KDeviceDialogType, "com.nokia.hb.deviceinputdialog/1.0"); |
|
122 TInt error; |
|
123 mReceivedButton = CHbDeviceInputDialogSymbian::ERejectButton; |
|
124 error = mDeviceDialog->Show(KDeviceDialogType, *iVariantMap, this); |
|
125 User::LeaveIfError(error); |
|
126 mShowCalled = true; |
|
127 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::SendToServerL::End") ) ); |
|
128 } |
|
129 |
|
130 |
|
131 // Close input dialog |
|
132 void CHbDeviceInputDialogPrivate::Close() |
|
133 { |
|
134 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::Close::Begin") ) ); |
|
135 mDeviceDialog->Cancel(); |
|
136 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::Close::End") ) ); |
|
137 } |
|
138 |
|
139 // Wait for input dialog to close |
|
140 bool CHbDeviceInputDialogPrivate::WaitForClosed() |
|
141 { |
|
142 // Returns true if object was not deleted during wait |
|
143 if (!mShowCalled) { |
|
144 return true; |
|
145 } |
|
146 return true; |
|
147 } |
|
148 |
|
149 // Observer, data received from device input dialog |
|
150 void CHbDeviceInputDialogPrivate::DataReceived(CHbSymbianVariantMap& aData) |
|
151 { |
|
152 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::DataReceived::Begin") ) ); |
|
153 mReceivedButton = CHbDeviceInputDialogSymbian::ERejectButton; |
|
154 _LIT(KKeyOk, "ok"); |
|
155 _LIT(KKeyCancel, "cancel"); |
|
156 const CHbSymbianVariant* variantOk = aData.Get(KKeyOk); |
|
157 const CHbSymbianVariant* variantCancel = aData.Get(KKeyCancel); |
|
158 if (variantOk) |
|
159 { |
|
160 const TDesC *value = variantOk->Value<const TDesC>(); |
|
161 q->iPassword = *value; |
|
162 mReceivedButton = CHbDeviceInputDialogSymbian::EAcceptButton; |
|
163 RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPowerMenuCustomDialogStatus, ECoreAppUIsMemoryCardCustomDialogOk ); |
|
164 } |
|
165 else if(variantCancel) |
|
166 { |
|
167 const TDesC *value = variantCancel->Value<const TDesC>(); |
|
168 q->iPassword = *value; |
|
169 mReceivedButton = CHbDeviceInputDialogSymbian::EAcceptButton; |
|
170 RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsPowerMenuCustomDialogStatus, ECoreAppUIsMemoryCardCustomDialogCancel); |
|
171 } |
|
172 |
|
173 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::DataReceived::End") ) ); |
|
174 } |
|
175 |
|
176 // Observer, device input dialog closed |
|
177 void CHbDeviceInputDialogPrivate::DeviceDialogClosed(TInt aCompletionCode) |
|
178 { |
|
179 ARG_UNUSED(aCompletionCode) |
|
180 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::DeviceDialogClosed::Begin") ) ); |
|
181 |
|
182 mShowCalled = false; |
|
183 |
|
184 |
|
185 if (mObserver) { |
|
186 mObserver->InputDialogClosed(q, mReceivedButton); |
|
187 return; // observer callback deleted this object. Do not touch it anymore. |
|
188 } |
|
189 TRACES( RDebug::Print( _L("CHbDeviceInputDialogPrivate::DeviceDialogClosed::End") ) ); |
|
190 } |
|
191 |
|
192 // Constructor |
|
193 CHbDeviceInputDialogSymbian::CHbDeviceInputDialogSymbian() |
|
194 { |
|
195 } |
|
196 |
|
197 // Destructor |
|
198 CHbDeviceInputDialogSymbian::~CHbDeviceInputDialogSymbian() |
|
199 { |
|
200 delete d; |
|
201 } |
|
202 |
|
203 CHbDeviceInputDialogSymbian* CHbDeviceInputDialogSymbian::NewL(MHbDeviceInputDialogObserver *aObserver) |
|
204 { |
|
205 TRACES( RDebug::Print( _L("CHbDeviceInputDialogSymbian::NewL::Begin") ) ); |
|
206 ARG_UNUSED(aObserver) |
|
207 CHbDeviceInputDialogSymbian *inputDialog = new (ELeave) CHbDeviceInputDialogSymbian; |
|
208 CleanupStack::PushL(inputDialog); |
|
209 CHbDeviceInputDialogPrivate *idialogPrivate = new (ELeave) CHbDeviceInputDialogPrivate; |
|
210 idialogPrivate->q = inputDialog; |
|
211 CleanupStack::PushL(idialogPrivate); |
|
212 idialogPrivate->ConstructL( aObserver); |
|
213 inputDialog->d = idialogPrivate; |
|
214 CleanupStack::Pop(2); // inputDialog, idialogPrivate |
|
215 inputDialog->SetObserver(aObserver); |
|
216 TRACES( RDebug::Print( _L("CHbDeviceInputDialogSymbian::NewL::End") ) ); |
|
217 return inputDialog; |
|
218 } |
|
219 |
|
220 |
|
221 void CHbDeviceInputDialogSymbian::ShowL() |
|
222 { |
|
223 TRACES( RDebug::Print( _L("CHbDeviceInputDialogSymbian::ShowL::Begin") ) ); |
|
224 d->SendToServerL(true); |
|
225 TRACES( RDebug::Print( _L("CHbDeviceInputDialogSymbian::ShowL::End") ) ); |
|
226 } |
|
227 |
|
228 |
|
229 TPtrC CHbDeviceInputDialogSymbian::getTextL() |
|
230 { |
|
231 TRACES( RDebug::Print( _L("CHbDeviceInputDialogSymbian::getTextL::Begin") ) ); |
|
232 TRACES( RDebug::Print(_L( "CHbDeviceInputDialogSymbian::getTextL::Begin %S" ),&iPassword)); |
|
233 HBufC* sample1 = HBufC::NewLC(iPassword.Length()); |
|
234 TPtrC aStringPointer = sample1->Des(); |
|
235 aStringPointer.Set(iPassword); |
|
236 CleanupStack::PopAndDestroy(); |
|
237 TRACES( RDebug::Print( _L("CHbDeviceInputDialogSymbian::getTextL::End") ) ); |
|
238 return aStringPointer; |
|
239 } |
|
240 |
|
241 void CHbDeviceInputDialogSymbian::Close() |
|
242 { |
|
243 TRACES( RDebug::Print( _L("CHbDeviceInputDialogSymbian::Close::Begin") ) ); |
|
244 d->Close(); |
|
245 } |
|
246 |
|
247 void CHbDeviceInputDialogSymbian::SetObserver(MHbDeviceInputDialogObserver *aObserver) |
|
248 { |
|
249 d->mObserver = aObserver; |
|
250 } |