1 /* |
|
2 * Copyright (c) 2005 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: Utility class for info view dialog. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "pbkinfoviewdialogutil.h" |
|
22 #include "pbkinfoviewutil.h" |
|
23 #include "pbkinfoviewdefines.h" |
|
24 |
|
25 #include <akntitle.h> // CAknTitlePane |
|
26 #include <akncontext.h> // CAknTitlePane |
|
27 #include <aknnotewrappers.h> // CAknInformationNote |
|
28 #include <eikmenup.h> // CEikMenuPane |
|
29 #include <aknlists.h> // CAknSingleHeadingPopupMenuStyleListBox |
|
30 |
|
31 #include <StringLoader.h> |
|
32 |
|
33 #include "rubydebug.h" |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 |
|
39 /******************************************************************************* |
|
40 * class TDialogUtil |
|
41 *******************************************************************************/ |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // TDialogUtil::ConstructListBoxItemL |
|
45 // @param aID Item ID of the masked bitmap to be created. |
|
46 // @param aFilename Filename to be used to construct the item, |
|
47 // @param aFileBitmapId Id (for bitmap) in the file. |
|
48 // @param aFileMaskId Id (for mask) in the file. |
|
49 // @return CGulIcon* Pointer to the newly created CGulIcon object. |
|
50 // Ownership of the object is transferred to the caller. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 HBufC* TDialogUtil::ConstructListBoxItemLC( const TDesC& aFirstLine, |
|
54 const TDesC& aSecondLine, |
|
55 TInt aIndex1 ) |
|
56 { |
|
57 _LIT( KFormat, "%d\t%S\t%S" ); |
|
58 |
|
59 TInt len = aFirstLine.Length() + aSecondLine.Length() + KBufSize16; |
|
60 |
|
61 HBufC* hBuf = HBufC::NewLC( len ); |
|
62 TPtr ptr = hBuf->Des(); |
|
63 |
|
64 ptr.Format( KFormat , aIndex1, &aFirstLine, &aSecondLine ); |
|
65 |
|
66 return hBuf; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // TDialogUtil::CreateIconL |
|
71 // |
|
72 // Constructs an independent CGulIcon object with fallback support. |
|
73 // If no matching item (aId) is found in the currently active skin, |
|
74 // attempts to construct the item using the given file (last 3 parameters). |
|
75 // @param aID Item ID of the masked bitmap to be created. |
|
76 // @param aFilename Filename to be used to construct the item, |
|
77 // @param aFileBitmapId Id (for bitmap) in the file. |
|
78 // @param aFileMaskId Id (for mask) in the file. |
|
79 // @return CGulIcon* Pointer to the newly created CGulIcon object. |
|
80 // Ownership of the object is transferred to the caller. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CGulIcon* TDialogUtil::CreateIconL( TAknsItemID aId, const TDesC& aFileName, TInt aFileBitmapId, TInt aFileMaskId ) |
|
84 { |
|
85 CGulIcon* icon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(), aId, aFileName, aFileBitmapId, aFileMaskId); |
|
86 return icon; |
|
87 } |
|
88 |
|
89 /******************************************************************************* |
|
90 * class CStatusPaneHandler |
|
91 *******************************************************************************/ |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CStatusPaneHandler::NewLC |
|
95 // |
|
96 // Two-phased constructor. |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CStatusPaneHandler* CStatusPaneHandler::NewL(CAknAppUi* aAppUi) |
|
100 { |
|
101 CStatusPaneHandler* self = new (ELeave) CStatusPaneHandler(aAppUi); |
|
102 CleanupStack::PushL(self); |
|
103 self->ConstructL(); |
|
104 CleanupStack::Pop(self); |
|
105 return self; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // Destructor |
|
110 // |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 CStatusPaneHandler::~CStatusPaneHandler() |
|
114 { |
|
115 TInt error( KErrNone ); |
|
116 |
|
117 TRAP( error, RestorePreviousTitleL() ); |
|
118 if ( error != KErrNone ) |
|
119 { |
|
120 RUBY_DEBUG1( "RestoreOriginalTitleL() error: %d", error ); |
|
121 } |
|
122 |
|
123 TRAP( error, RestoreOriginalImageL() ); |
|
124 if ( error != KErrNone ) |
|
125 { |
|
126 RUBY_DEBUG1( "RestoreOriginalImageL() error: %d", error ); |
|
127 } |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CStatusPaneHandler::ConstructL |
|
132 // |
|
133 // Symbian 2nd phase constructor can leave. |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CStatusPaneHandler::ConstructL(void) |
|
137 { |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CStatusPaneHandler::CStatusPaneHandler |
|
142 // |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 CStatusPaneHandler::CStatusPaneHandler( CAknAppUi* aAppUi ) : iAppUi( aAppUi ) |
|
146 { |
|
147 __ASSERT_ALWAYS( iAppUi, TPbkInfoViewUtil::Panic( KErrGeneral ) ); |
|
148 |
|
149 iOriginalTitleStored = EFalse; |
|
150 iOriginalTitle = KNullDesC; |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // CStatusPaneHandler::GetPreviousTitleL |
|
155 // Gets the title from previous view. |
|
156 // @param aAppUi Pointer to UI class. |
|
157 // @param aText Title will be put to this variable. |
|
158 // @return TBool ETrue: success / EFalse: failure. |
|
159 // ---------------------------------------------------------------------------- |
|
160 // |
|
161 TBool CStatusPaneHandler::GetPreviousTitleL( CAknAppUi* aAppUi, TDes& aTitle ) |
|
162 { |
|
163 aTitle = KNullDesC; |
|
164 |
|
165 CEikStatusPane* statusPane = aAppUi->StatusPane(); |
|
166 if ( statusPane && |
|
167 statusPane->PaneCapabilities |
|
168 ( TUid::Uid( EEikStatusPaneUidTitle) ).IsPresent() ) |
|
169 { |
|
170 CAknTitlePane* titlePane = static_cast<CAknTitlePane*> |
|
171 (statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
172 if ( titlePane->Text() ) |
|
173 { |
|
174 TPbkInfoViewUtil::StrCopy( aTitle, *titlePane->Text() ); |
|
175 return ETrue; |
|
176 } |
|
177 } |
|
178 return EFalse; |
|
179 } |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // CStatusPaneHandler::SetTitleL |
|
183 // Sets the dialog title. |
|
184 // @param aAppUi Pointer to the UI class. |
|
185 // @param aText Title text. |
|
186 // ---------------------------------------------------------------------------- |
|
187 // |
|
188 void CStatusPaneHandler::SetTitleL( CAknAppUi* aAppUi, const TDesC& aTitle ) |
|
189 { |
|
190 CEikStatusPane* statusPane = aAppUi->StatusPane(); |
|
191 if ( statusPane && |
|
192 statusPane->PaneCapabilities |
|
193 (TUid::Uid(EEikStatusPaneUidTitle)).IsPresent()) |
|
194 { |
|
195 CAknTitlePane* titlePane = static_cast<CAknTitlePane*> |
|
196 (statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle))); |
|
197 if ( titlePane->Text() ) |
|
198 { |
|
199 titlePane->SetTextL(aTitle); |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 // ---------------------------------------------------------------------------- |
|
205 // CStatusPaneHandler::StoreOriginalTitleL |
|
206 // Sets the member variable for previous title. |
|
207 // ---------------------------------------------------------------------------- |
|
208 // |
|
209 void CStatusPaneHandler::StoreOriginalTitleL() |
|
210 { |
|
211 TBool ret = GetPreviousTitleL( iAppUi, iOriginalTitle ); |
|
212 |
|
213 if ( ret ) |
|
214 { |
|
215 iOriginalTitleStored = ETrue; |
|
216 } |
|
217 } |
|
218 |
|
219 // ---------------------------------------------------------------------------- |
|
220 // CStatusPaneHandler::RestorePreviousTitleL |
|
221 // Restores previous title when returning to previous view. |
|
222 // ---------------------------------------------------------------------------- |
|
223 // |
|
224 void CStatusPaneHandler::RestorePreviousTitleL() |
|
225 { |
|
226 if ( iOriginalTitleStored ) |
|
227 { |
|
228 SetTitleL( iAppUi, iOriginalTitle ); |
|
229 } |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------------------------- |
|
233 // CStatusPaneHandler::SetTitleL |
|
234 // Sets the dialog title. |
|
235 // @param aResourceId Resource id from resource file. |
|
236 // ---------------------------------------------------------------------------- |
|
237 // |
|
238 void CStatusPaneHandler::SetTitleL( TInt aResourceId ) |
|
239 { |
|
240 // Get title from resource file |
|
241 HBufC* dialogTitle = StringLoader::LoadLC( aResourceId ); |
|
242 |
|
243 SetTitleL( iAppUi, dialogTitle->Des() ); |
|
244 CleanupStack::PopAndDestroy( dialogTitle ); |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // CStatusPaneHandler::RestoreOriginalImageL |
|
249 // Restores previous image when returning to previous view. |
|
250 // ---------------------------------------------------------------------------- |
|
251 // |
|
252 void CStatusPaneHandler::RestoreOriginalImageL() |
|
253 { |
|
254 if (!iOriginalImage) |
|
255 { |
|
256 return; // image has not been replaced |
|
257 } |
|
258 |
|
259 CEikImage* image = NULL; |
|
260 TRAPD(err, image = SetImageL( iAppUi, iOriginalImage ) ); |
|
261 |
|
262 if (err == KErrNone && image) |
|
263 { |
|
264 delete image; // delete our own image |
|
265 } |
|
266 else |
|
267 { |
|
268 delete iOriginalImage; // delete original image (could not restore it) |
|
269 iOriginalImage = NULL; |
|
270 } |
|
271 } |
|
272 |
|
273 // ---------------------------------------------------------------------------- |
|
274 // CStatusPaneHandler::SetImageL |
|
275 // Sets dialog image. |
|
276 // ---------------------------------------------------------------------------- |
|
277 // |
|
278 CEikImage* CStatusPaneHandler::SetImageL( CAknAppUi* aAppUi, CEikImage* aIcon ) |
|
279 { |
|
280 CEikStatusPane* statusPane = aAppUi->StatusPane(); |
|
281 if ( statusPane && statusPane->PaneCapabilities |
|
282 (TUid::Uid(EEikStatusPaneUidContext)).IsPresent() ) |
|
283 { |
|
284 CAknContextPane* contextPane = static_cast<CAknContextPane*> |
|
285 ( statusPane->ControlL( TUid::Uid( EEikStatusPaneUidContext ) ) ); |
|
286 if ( contextPane ) |
|
287 { |
|
288 return contextPane->SwapPicture( aIcon ); |
|
289 } |
|
290 } |
|
291 |
|
292 return NULL; |
|
293 } |
|
294 |
|
295 // End of File |
|