|
1 /* |
|
2 * Copyright (c) 2002 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: DM Idle SoftKey Adapter |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "IdleSoftkeysAppTargetManager.h" |
|
20 #include "UiSettingsUtil.h" |
|
21 // symbian |
|
22 // s60 |
|
23 #include <centralrepository.h> |
|
24 // tarm |
|
25 #include "IsAdapterLiterals.h" |
|
26 #include "IsAdapterDefines.h" |
|
27 #include "nsmldmuri.h" |
|
28 #include "TARMCharConv.h" |
|
29 #include "TPtrC8I.h" |
|
30 #include "debug.h" |
|
31 |
|
32 |
|
33 CIdleSoftkeysAppTargetManager::CIdleSoftkeysAppTargetManager(MSmlDmCallback *& aCallBack) |
|
34 : iCallBack( aCallBack ) |
|
35 { |
|
36 iUiSettingsNotInitialized = ETrue; |
|
37 } |
|
38 |
|
39 CIdleSoftkeysAppTargetManager::~CIdleSoftkeysAppTargetManager() |
|
40 { |
|
41 if(iUiSettingsNotInitialized == EFalse) |
|
42 { |
|
43 delete iUiSettings; |
|
44 } |
|
45 } |
|
46 |
|
47 // ------------------------------------------------------------------------------------- |
|
48 // CIdleSoftkeysAppTargetManager::ListTargetsL |
|
49 // This method will list all application targets in the shortcut engine |
|
50 // ------------------------------------------------------------------------------------- |
|
51 TInt CIdleSoftkeysAppTargetManager::ListTargetsL( CBufFlat &aList ) |
|
52 { |
|
53 RDEBUG( "CIdleSoftkeysAppTargetManager::ListTargetsL() >" ); |
|
54 |
|
55 TInt i, num ; |
|
56 |
|
57 if(iUiSettingsNotInitialized) |
|
58 { |
|
59 iUiSettings = CUiSettingsUtil::NewL( ); |
|
60 iUiSettings->ReadTargetsL(); |
|
61 iUiSettingsNotInitialized = EFalse; |
|
62 } |
|
63 |
|
64 num = iUiSettings->GetNoOfTargetApps(); |
|
65 |
|
66 for(i=0; i<num; i++) |
|
67 { |
|
68 if(i>0) |
|
69 { |
|
70 aList.InsertL( aList.Size(), KNSmlISSeparator() ); |
|
71 } |
|
72 |
|
73 HBufC8* targetName = GenerateNodeNameL( i ); |
|
74 CleanupStack::PushL( targetName ); |
|
75 |
|
76 aList.InsertL( aList.Size(), *targetName ); |
|
77 |
|
78 CleanupStack::PopAndDestroy( targetName ); |
|
79 } |
|
80 |
|
81 RDEBUG( "CIdleSoftkeysAppTargetManager::ListTargetsL() <" ); |
|
82 return KErrNone; |
|
83 } |
|
84 |
|
85 |
|
86 // ------------------------------------------------------------------------------------- |
|
87 // CIdleSoftkeysAppTargetManager::GenerateNodeNameL |
|
88 // This method generates name for a target according to a given index |
|
89 // ------------------------------------------------------------------------------------- |
|
90 HBufC8* CIdleSoftkeysAppTargetManager::GenerateNodeNameL(TInt aIndex) |
|
91 { |
|
92 RDEBUG( "CIdleSoftkeysAppTargetManager::GenerateNodeNameL() >" ); |
|
93 |
|
94 HBufC8* targetName = HBufC8::NewL( KPrefixTargetNodeName().Length() |
|
95 + MAX_NUMBER_OF_DIGITS_IN_10BASE_INT64 ); |
|
96 |
|
97 TPtr8 ptr( targetName->Des() ); |
|
98 |
|
99 ptr.Format(KFormatTargetNodeName, aIndex+1); |
|
100 |
|
101 RDEBUG8_2( "CIdleSoftkeysAppTargetManager::GenerateNodeNameL() < %S", &targetName ); |
|
102 return targetName; |
|
103 } |
|
104 |
|
105 |
|
106 // ------------------------------------------------------------------------------------- |
|
107 // CIdleSoftkeysAppTargetManager::GetTargetFromNodeNameL |
|
108 // This method parses a node name and returns matching application index and caption |
|
109 // ------------------------------------------------------------------------------------- |
|
110 void CIdleSoftkeysAppTargetManager::GetTargetFromNodeNameL(const TDesC8& aNodeName, TInt &aIndex, TDes8 &aTargetCaption) |
|
111 { |
|
112 RDEBUG( "CIdleSoftkeysAppTargetManager::GetTargetFromNodeNameL() >" ); |
|
113 |
|
114 TInt index = -1; |
|
115 TInt compareLenApp = KPrefixTargetNodeName().Length(); |
|
116 |
|
117 if(aNodeName.Left(compareLenApp) == KFormatTargetNodeName().Left(compareLenApp)) |
|
118 { |
|
119 if(iUiSettingsNotInitialized) |
|
120 { |
|
121 iUiSettings = CUiSettingsUtil::NewL( ); |
|
122 iUiSettings->ReadTargetsL() ; |
|
123 iUiSettingsNotInitialized = EFalse; |
|
124 } |
|
125 |
|
126 TInt num; |
|
127 num = iUiSettings->GetNoOfTargetApps(); |
|
128 |
|
129 TLex8 lex; |
|
130 lex.Assign( aNodeName ); |
|
131 |
|
132 lex.Inc( compareLenApp ); |
|
133 User::LeaveIfError( lex.Val(index) ); |
|
134 index--; |
|
135 User::LeaveIfError( index>=0 && index<num ? KErrNone : KErrGeneral ); |
|
136 |
|
137 HBufC8* targetName = GenerateNodeNameL( index ); |
|
138 CleanupStack::PushL( targetName ); |
|
139 |
|
140 TPtr8 ptr( targetName->Des() ); |
|
141 User::LeaveIfError( ptr == aNodeName ? KErrNone : KErrGeneral ); |
|
142 |
|
143 CleanupStack::PopAndDestroy( targetName ); |
|
144 |
|
145 HBufC* buffer = HBufC::NewLC( aTargetCaption.MaxLength() ); |
|
146 RDEBUG_2( "CIdleSoftkeysAppTargetManager::GetTargetFromNodeNameL() HBufC buffer ALLOC %x", buffer); |
|
147 TPtr bufferPtr( buffer->Des() ); |
|
148 User::LeaveIfError(iUiSettings->GetAppTargetCaptionL( index, bufferPtr )) ; |
|
149 aTargetCaption.Copy( bufferPtr ); |
|
150 CleanupStack::PopAndDestroy( buffer ); |
|
151 aIndex = index; |
|
152 } |
|
153 else |
|
154 { |
|
155 #ifdef __WINS_DEBUG_TRACE__ |
|
156 User::Panic( _L("IsAdapter"), 1 ); |
|
157 #else |
|
158 User::Leave( KErrNotFound ); |
|
159 #endif |
|
160 } |
|
161 |
|
162 RDEBUG( "CIdleSoftkeysAppTargetManager::GetTargetFromNodeNameL() <" ); |
|
163 } |
|
164 |
|
165 |
|
166 // ------------------------------------------------------------------------------------- |
|
167 // CIdleSoftkeysAppTargetManager::SetCaptionL |
|
168 // This method sets a new caption to a target (shortcut) |
|
169 // ------------------------------------------------------------------------------------- |
|
170 void CIdleSoftkeysAppTargetManager::SetCaptionL( const TDesC8& aURI, const TDesC8& aCaption ) |
|
171 { |
|
172 RDEBUG( "CIdleSoftkeysAppTargetManager::SetCaptionL() >" ); |
|
173 |
|
174 TBuf8<ISADAPTER_SHORTCUT_CAPTION_MAXLENGTH> caption; |
|
175 TInt index; |
|
176 GetTargetFromNodeNameL( NSmlDmURI::URISeg( aURI, 3 ), index, caption ); |
|
177 |
|
178 HBufC* newCaption = CTARMCharConv::ConvertFromUtf8LC( aCaption ); |
|
179 CleanupStack::PopAndDestroy( newCaption ); |
|
180 |
|
181 RDEBUG( "CIdleSoftkeysAppTargetManager::SetCaptionL() <" ); |
|
182 } |
|
183 |
|
184 //End of file |