|
1 |
|
2 // Copyright (c) 2004-2009 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 // INCLUDE FILES |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 #include "SIPExAppUi.h" |
|
21 #include "SIPExGameContainer.h" |
|
22 #include "SIPEx.hrh" |
|
23 #include "SIPExAddrQueryDlg.h" |
|
24 #include "SIPExProfileQueryDlg.h" |
|
25 #include "SIPExIMDialog.h" |
|
26 #include "SIPExDoc.h" |
|
27 #include <sipex.rsg> |
|
28 #include <eikenv.h> // CEikonEnv |
|
29 #include <eikmenup.h> // CEikMenupane |
|
30 #include <eikbtgpc.h> // CEikButtonGroupContainer |
|
31 #include <eikinfo.h> // CEikInfoDialog |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CSIPExAppUi::CSIPExAppUi |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CSIPExAppUi::CSIPExAppUi() |
|
42 : iState( CSIPExEngine::EIdle ) |
|
43 { |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CSIPExAppUi::ConstructL |
|
48 // Symbian 2nd phase constructor can leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CSIPExAppUi::ConstructL() |
|
52 { |
|
53 BaseConstructL(); |
|
54 |
|
55 iEngine = ( static_cast< CSIPExDoc* >( Document() ) )->CreateEngineL( *this ); |
|
56 iGameContainer = CSIPExGameContainer::NewL( ClientRect(), *iEngine ); |
|
57 iEngine->SetViewNotifier( *iGameContainer ); |
|
58 |
|
59 RegisterViewL( *iGameContainer ); |
|
60 SetDefaultViewL( *iGameContainer ); |
|
61 |
|
62 HandleToolbar(); |
|
63 |
|
64 AddToStackL( iGameContainer ); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CSIPExAppUi::~CSIPExAppUi |
|
69 // Destructor |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CSIPExAppUi::~CSIPExAppUi() |
|
73 { |
|
74 if( iGameContainer ) |
|
75 { |
|
76 DeregisterView( *iGameContainer ); |
|
77 iEikonEnv->RemoveFromStack( iGameContainer ); |
|
78 delete iGameContainer; |
|
79 } |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CSIPExAppUi::HandleCommandL |
|
84 // User interaction handling. The views capture most of the events, but some |
|
85 // might get pushed here |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CSIPExAppUi::HandleCommandL( TInt aCommand ) |
|
89 { |
|
90 switch ( aCommand ) |
|
91 { |
|
92 case EEikCmdExit: |
|
93 { |
|
94 // If game is ongoing, notify opponent, ignore errors |
|
95 TRAPD( err, iEngine->EndGameL() ); |
|
96 CBaActiveScheduler::Exit(); |
|
97 break; |
|
98 } |
|
99 |
|
100 case ECmdInviteForGame: |
|
101 { |
|
102 CSIPExAddrQueryDlg* dlg = CSIPExAddrQueryDlg::NewL( iAddress ); |
|
103 if( dlg->ExecuteLD( R_INVITE_ADDRESS_DLG ) ) |
|
104 { |
|
105 iEngine->InviteL( iAddress ); |
|
106 } |
|
107 iGameContainer->DrawNow(); |
|
108 break; |
|
109 } |
|
110 |
|
111 case ECmdEnableProfile: |
|
112 { |
|
113 TRAPD( err, iEngine->EnableProfileL()); |
|
114 if (err == KErrNotFound) |
|
115 { |
|
116 CSIPExProfileQueryDlg* dlg = CSIPExProfileQueryDlg::NewL( ); |
|
117 if( dlg->ExecuteLD( R_PROFILE_DLG ) ) |
|
118 { |
|
119 // iEngine->InviteL( iAddress ); |
|
120 } |
|
121 iGameContainer->DrawNow(); |
|
122 iEngine->EnableProfileL(); |
|
123 } |
|
124 else |
|
125 { |
|
126 User::Leave(err); |
|
127 } |
|
128 break; |
|
129 } |
|
130 |
|
131 case ECmdDisableProfile: |
|
132 { |
|
133 iEngine->DisableProfileL(); |
|
134 break; |
|
135 } |
|
136 |
|
137 // Send instant message |
|
138 case ECmdSendIM: |
|
139 { |
|
140 TBuf< 256 > msg; |
|
141 CSIPExIMDialog* dlg = CSIPExIMDialog::NewL( iAddress, msg ); |
|
142 if( dlg->ExecuteLD( R_INSTANT_MESSAGE_DLG ) ) |
|
143 { |
|
144 iEngine->SendInstantMsgL( iAddress, msg ); |
|
145 } |
|
146 iGameContainer->DrawNow(); |
|
147 break; |
|
148 } |
|
149 |
|
150 // End game |
|
151 case ECmdEndGame: |
|
152 { |
|
153 iEngine->EndGameL(); |
|
154 break; |
|
155 } |
|
156 |
|
157 default: |
|
158 { |
|
159 // Do nothing, no-one will handle it |
|
160 // No use of leaving though, because this isn't an error - only |
|
161 // an unhandled command |
|
162 break; |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CSIPExAppUi::GameStateChanged |
|
169 // From MSIPExGameObserver. |
|
170 // Game state changed. Then the game should be redraw. |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CSIPExAppUi::GameStateChanged( CSIPExEngine::TEngineState aState ) |
|
174 { |
|
175 iState = aState; |
|
176 HandleToolbar(); |
|
177 iGameContainer->DrawDeferred(); |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CSIPExAppUi::HandleToolbar |
|
182 // Sets the toolbar items dimmed/undimmed according game state. |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CSIPExAppUi::HandleToolbar() |
|
186 { |
|
187 CEikButtonGroupContainer* toolbar = iEikonEnv->AppUiFactory()->ToolBar(); |
|
188 |
|
189 switch( iState ) |
|
190 { |
|
191 case CSIPExEngine::EIdle: |
|
192 toolbar->DimCommand( ECmdInviteForGame, ETrue ); |
|
193 toolbar->DimCommand( ECmdEnableProfile, EFalse ); |
|
194 toolbar->DimCommand( ECmdDisableProfile, ETrue ); |
|
195 toolbar->DimCommand( ECmdSendIM, ETrue ); |
|
196 toolbar->DimCommand( ECmdEndGame, ETrue ); |
|
197 break; |
|
198 case CSIPExEngine::EEnabled: |
|
199 toolbar->DimCommand( ECmdInviteForGame, EFalse ); |
|
200 toolbar->DimCommand( ECmdEnableProfile, ETrue ); |
|
201 toolbar->DimCommand( ECmdDisableProfile, EFalse ); |
|
202 toolbar->DimCommand( ECmdSendIM, EFalse ); |
|
203 toolbar->DimCommand( ECmdEndGame, ETrue ); |
|
204 break; |
|
205 case CSIPExEngine::EActivating: |
|
206 toolbar->DimCommand( ECmdInviteForGame, ETrue ); |
|
207 toolbar->DimCommand( ECmdEnableProfile, ETrue ); |
|
208 toolbar->DimCommand( ECmdDisableProfile, ETrue ); |
|
209 toolbar->DimCommand( ECmdSendIM, EFalse ); |
|
210 toolbar->DimCommand( ECmdEndGame, ETrue ); |
|
211 break; |
|
212 case CSIPExEngine::EActive: |
|
213 toolbar->DimCommand( ECmdInviteForGame, ETrue ); |
|
214 toolbar->DimCommand( ECmdEnableProfile, ETrue ); |
|
215 toolbar->DimCommand( ECmdDisableProfile, ETrue ); |
|
216 toolbar->DimCommand( ECmdSendIM, EFalse ); |
|
217 toolbar->DimCommand( ECmdEndGame, EFalse ); |
|
218 break; |
|
219 default: |
|
220 break; |
|
221 } |
|
222 toolbar->DrawDeferred(); |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CSIPExAppUi::AcceptInvitationL |
|
227 // From MSIPExGameObserver. |
|
228 // Show confirmation dialog with summoner's address. |
|
229 // If accepted return ETrue else EFalse. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 TBool CSIPExAppUi::AcceptInvitationL( const TDesC& aFrom ) |
|
233 { |
|
234 HBufC* title = |
|
235 iEikonEnv->AllocReadResourceLC( R_SIP_EX_ACCEPT_INVITATION_DLG_TITLE ); |
|
236 |
|
237 HBufC* temp = iEikonEnv->AllocReadResourceLC( R_SIP_EX_ACCEPT_INVITATION ); |
|
238 |
|
239 HBufC* buf = HBufC::NewL( temp->Length() + aFrom.Length() ); |
|
240 TPtr pbuf( buf->Des() ); |
|
241 pbuf.AppendFormat( *temp, &aFrom ); |
|
242 |
|
243 CleanupStack::PopAndDestroy( temp ); |
|
244 CleanupStack::PushL( buf ); |
|
245 |
|
246 TBool retVal( EFalse ); |
|
247 if( CEikInfoDialog::RunDlgLD( *title, pbuf, CEikInfoDialog::EAllowEnter ) ) |
|
248 { |
|
249 retVal = ETrue; |
|
250 } |
|
251 |
|
252 CleanupStack::PopAndDestroy( buf ); |
|
253 CleanupStack::PopAndDestroy( title ); |
|
254 |
|
255 iGameContainer->DrawDeferred(); |
|
256 return retVal; |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CSIPExAppUi::IMReceivedL |
|
261 // From MSIPExGameObserver. |
|
262 // Show the received instant message in info editor. |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void CSIPExAppUi::IMReceivedL( const TDesC8& aFrom, const TDesC8& aMsg ) |
|
266 { |
|
267 HBufC* from = HBufC::NewLC( aFrom.Length() ); |
|
268 from->Des().Copy( aFrom ); |
|
269 |
|
270 HBufC* msg = HBufC::NewLC( aMsg.Length() ); |
|
271 msg->Des().Copy( aMsg ); |
|
272 |
|
273 HBufC* temp = iEikonEnv->AllocReadResourceLC( R_SIP_EX_IM_RECEIVED ); |
|
274 |
|
275 HBufC* buf = |
|
276 HBufC::NewLC( temp->Length() + aFrom.Length() + aMsg.Length() ); |
|
277 TPtr pbuf( buf->Des() ); |
|
278 pbuf.AppendFormat( *temp, from, msg ); |
|
279 |
|
280 iGameContainer->ShowInfoL( pbuf ); |
|
281 CleanupStack::PopAndDestroy( 4 ); |
|
282 } |
|
283 |
|
284 // End of File |