|
1 /* |
|
2 * Copyright (c) 2006 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: Defines the utility interface class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __MMI_UTILS_H__ |
|
21 #define __MMI_UTILS_H__ |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <eikenv.h> |
|
25 |
|
26 class TMMIKeyValuePair |
|
27 { |
|
28 public: |
|
29 const TDesC* iKey; |
|
30 const TDesC* iVal; |
|
31 }; |
|
32 |
|
33 const TUint8 KDataRequestSuccess = 1; |
|
34 const TUint8 KDataRequestFail = 0; |
|
35 |
|
36 class MMIUtils |
|
37 { |
|
38 protected: // this class is not for instantiation |
|
39 inline MMIUtils() {} |
|
40 public: |
|
41 |
|
42 virtual CEikonEnv* GetEikonEnv() = 0; |
|
43 |
|
44 |
|
45 virtual void SendEvent(RPointerArray<TDesC>& aArgs) = 0; |
|
46 |
|
47 virtual TInt GetIntFromDescL(const TDesC& aDesc) = 0; |
|
48 |
|
49 virtual short SetReturnStringFromKeyValuePairsL(const CArrayFix<TMMIKeyValuePair>* aArray, const TAny* aRetVal) = 0; |
|
50 virtual short SetReturnStringFromIntL(TInt aInt, const TAny* aRetVal) = 0; |
|
51 virtual short SetReturnStringFromDes16L(const TDesC& aDes, const TAny* aRetVal) = 0; |
|
52 |
|
53 // data request functions |
|
54 virtual void DataRequestSetStringProperty(const TAny* aRequestHandle, const TDesC& aKey, const TDesC& aValue) = 0; |
|
55 virtual void DataRequestSetNumberProperty(const TAny* aRequestHandle, const TDesC& aKey, TInt aValue) = 0; |
|
56 virtual TAny* DataRequestCreateObjectProperty(const TAny* aRequestHandle, const TDesC& aKey) = 0; |
|
57 virtual void DataRequestSetComplete(const TAny* aRequestHandle, TUint8 aSuccess) = 0; |
|
58 |
|
59 }; |
|
60 |
|
61 class MObjectOwner |
|
62 { |
|
63 public: |
|
64 virtual void DeleteObject(CBase* aObject)=0; |
|
65 }; |
|
66 |
|
67 class TValueKeyPairParser |
|
68 { |
|
69 public: |
|
70 inline TValueKeyPairParser(const TDesC& aString) :iContainer(aString),iLastWasKey(EFalse) { iRemaining=iContainer.Length(); } |
|
71 |
|
72 public: |
|
73 inline TPtrC NextKey() |
|
74 { |
|
75 ASSERT(!iLastWasKey); |
|
76 iLastWasKey=ETrue; |
|
77 return GetNext(TChar('=')); |
|
78 } |
|
79 inline TPtrC NextValue() |
|
80 { |
|
81 ASSERT(iLastWasKey); |
|
82 iLastWasKey=EFalse; |
|
83 return GetNext(TChar('&')); |
|
84 } |
|
85 TBool Done() const |
|
86 { |
|
87 return(iRemaining==0); |
|
88 } |
|
89 private: |
|
90 inline TPtrC GetNext(TChar aChar) |
|
91 { |
|
92 TPtrC temp(iContainer.Right(iRemaining)); |
|
93 TInt index=temp.Locate(aChar); |
|
94 TBool found = ETrue; |
|
95 |
|
96 if(index==KErrNotFound) |
|
97 { |
|
98 index=temp.Length(); // i.e. the end |
|
99 found = EFalse; |
|
100 } |
|
101 |
|
102 if (found) |
|
103 { |
|
104 iRemaining-=(index+1); // +1 to count for '=' or '&' char which is thrown away |
|
105 } |
|
106 else |
|
107 { |
|
108 iRemaining-=(index); |
|
109 } |
|
110 return TPtrC(temp.Left(index)); |
|
111 } |
|
112 private: |
|
113 const TPtrC iContainer; |
|
114 TInt iRemaining; |
|
115 TBool iLastWasKey; |
|
116 }; |
|
117 |
|
118 #endif // __MMI_UTILS__ |