|
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: |
|
15 * Go to URL command object.Opens browser to the URL address |
|
16 * saved in contact details. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CPbkGoToURLCmd.h" |
|
23 #include <CPbkContactItem.h> |
|
24 #include <CPbkURLAddressSelect.h> |
|
25 #include <PbkView.rsg> |
|
26 #include <SchemeHandler.h> |
|
27 #include <aknnotewrappers.h> |
|
28 #include <pbkdebug.h> |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // Default constructor |
|
32 CPbkGoToURLCmd::CPbkGoToURLCmd |
|
33 (const CPbkContactItem& aContact, |
|
34 const TPbkContactItemField* aFocusedField) : |
|
35 iContact(aContact), |
|
36 iFocusedField(aFocusedField) |
|
37 { |
|
38 PBK_DEBUG_PRINT |
|
39 (PBK_DEBUG_STRING("CPbkGoToURLCmd::CPbkGoToURLCmd(0x%x)"), this); |
|
40 } |
|
41 |
|
42 |
|
43 // Static constructor |
|
44 CPbkGoToURLCmd* CPbkGoToURLCmd::NewL |
|
45 (const CPbkContactItem& aContact, |
|
46 const TPbkContactItemField* aFocusedField) |
|
47 { |
|
48 CPbkGoToURLCmd* self = new(ELeave) |
|
49 CPbkGoToURLCmd(aContact, aFocusedField); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // Destructor |
|
54 CPbkGoToURLCmd::~CPbkGoToURLCmd() |
|
55 { |
|
56 delete iHandler; |
|
57 |
|
58 // Tells ExecuteLD this object has been destroyed |
|
59 if(iDestroyedPtr) |
|
60 { |
|
61 *iDestroyedPtr = ETrue; |
|
62 } |
|
63 |
|
64 PBK_DEBUG_PRINT |
|
65 (PBK_DEBUG_STRING("CPbkGoToURLCmd::~CPbkGoToURLCmd(0x%x)"), this); |
|
66 } |
|
67 |
|
68 void CPbkGoToURLCmd::ExecuteLD() |
|
69 { |
|
70 PBK_DEBUG_PRINT |
|
71 (PBK_DEBUG_STRING("CPbkGoToURLCmd::ExecuteLD(0x%x)"), this); |
|
72 |
|
73 CleanupStack::PushL(this); |
|
74 |
|
75 TBool thisDestroyed = EFalse; |
|
76 iDestroyedPtr = &thisDestroyed; |
|
77 |
|
78 // Show URL address selection dialog, if necessary |
|
79 CPbkURLAddressSelect* selectDlg = new(ELeave) CPbkURLAddressSelect; |
|
80 CPbkURLAddressSelect::TParams params(iContact); |
|
81 params.SetFocusedField(iFocusedField); |
|
82 params.SetUseDefaultDirectly(EFalse); // no defaults in case of URL |
|
83 |
|
84 TPtrC address; |
|
85 address.Set(selectDlg->ExecuteLD(params)); |
|
86 |
|
87 if (address.Length() > 0) |
|
88 { |
|
89 // All ok, launch browser |
|
90 TRAPD(err, DoGoToUrlL(address)); |
|
91 switch(err) |
|
92 { |
|
93 case KErrNone: |
|
94 { |
|
95 // Fix cleanup stack, this object is deleted later |
|
96 // in NotifyExit |
|
97 CleanupStack::Pop(); // this |
|
98 break; |
|
99 } |
|
100 |
|
101 case KErrArgument: // FALLTHROUGH |
|
102 case KErrNotFound: |
|
103 { |
|
104 // The URL was not in valid form |
|
105 CAknNoteWrapper * note = new(ELeave) CAknNoteWrapper; |
|
106 note->ExecuteLD(R_QTN_PHOB_NOTE_INVALID_URL); |
|
107 // Fix cleanup stack |
|
108 if (!thisDestroyed) |
|
109 { |
|
110 CleanupStack::PopAndDestroy(); // this |
|
111 } |
|
112 else |
|
113 { |
|
114 CleanupStack::Pop(); // this |
|
115 } |
|
116 break; |
|
117 } |
|
118 |
|
119 default: |
|
120 { |
|
121 // Some other error occurred |
|
122 if (thisDestroyed) |
|
123 { |
|
124 // Avoid double deletion |
|
125 CleanupStack::Pop(); // this |
|
126 } |
|
127 User::Leave(err); |
|
128 break; |
|
129 } |
|
130 } |
|
131 } |
|
132 else |
|
133 { |
|
134 CleanupStack::PopAndDestroy(this); |
|
135 } |
|
136 } |
|
137 |
|
138 void CPbkGoToURLCmd::DoGoToUrlL(const TDesC& aUrl) |
|
139 { |
|
140 delete iHandler; |
|
141 iHandler = NULL; |
|
142 |
|
143 // Launch browser via SchemeHandler, the following leaves |
|
144 // with KErrArgument if the URL is not in valid form |
|
145 iHandler = CSchemeHandler::NewL(aUrl); |
|
146 iHandler->Observer(this); |
|
147 iHandler->HandleUrlStandaloneL(); |
|
148 } |
|
149 |
|
150 void CPbkGoToURLCmd::HandleServerAppExit(TInt aReason) |
|
151 { |
|
152 MAknServerAppExitObserver::HandleServerAppExit(aReason); |
|
153 delete this; |
|
154 } |
|
155 |
|
156 // End of File |