summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/symbian_ua_gui/src/symbian_ua_guiContainerView.cpp
blob: 0fae4f626e4a12eb2f3d86f443c2f93ef46fe12a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/* $Id: symbian_ua_guiContainerView.cpp 3550 2011-05-05 05:33:27Z nanang $ */
/* 
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */
// [[[ begin generated region: do not modify [Generated System Includes]
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <barsread.h>
#include <stringloader.h>
#include <eiklabel.h>
#include <eikenv.h>
#include <gdi.h>
#include <eikedwin.h>
#include <akncontext.h>
#include <akntitle.h>
#include <eikbtgpc.h>
#include <aknnotewrappers.h>
#include <aknquerydialog.h>
#include <symbian_ua_gui.rsg>
// ]]] end generated region [Generated System Includes]

// [[[ begin generated region: do not modify [Generated User Includes]
#include "symbian_ua_gui.hrh"
#include "symbian_ua_guiContainerView.h"
#include "symbian_ua_guiContainer.hrh"
#include "symbian_ua_guiSettingItemList.hrh"
#include "symbian_ua_guiContainer.h"
// ]]] end generated region [Generated User Includes]

#include <utf.h>
#include "symbian_ua.h"

// [[[ begin generated region: do not modify [Generated Constants]
// ]]] end generated region [Generated Constants]

Csymbian_ua_guiContainerView *myinstance = NULL;
_LIT(KStCall, "Call");
_LIT(KStHangUp, "Hang Up");

void on_info(const wchar_t* buf)
{
	TPtrC aBuf((const TUint16*)buf);
	
	if (myinstance)
		myinstance->PutMessage(aBuf);
}

void on_incoming_call(const wchar_t* caller_disp, const wchar_t* caller_uri)
{
	TBuf<512> buf;
	TPtrC aDisp((const TUint16*)caller_disp);
	TPtrC aUri((const TUint16*)caller_uri);
	_LIT(KFormat, "Incoming call from %S, accept?");
	
	buf.Format(KFormat, &aDisp);
	if (Csymbian_ua_guiContainerView::RunQry_accept_callL(&buf) == EAknSoftkeyYes)
	{
		CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
		if (cba != NULL) {
			TRAPD(result, cba->SetCommandL(ESymbian_ua_guiContainerViewControlPaneRightId, KStHangUp));
			cba->DrawDeferred();
		}
		symbian_ua_answercall();
	} else {
		symbian_ua_endcall();	
	}
}

void on_call_end(const wchar_t* reason)
{
	TPtrC aReason((const TUint16*)reason);
	
	CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
	if (cba != NULL) {
		TRAPD(result, cba->SetCommandL(ESymbian_ua_guiContainerViewControlPaneRightId, KStCall));
		cba->DrawDeferred();
	}
	
	Csymbian_ua_guiContainerView::RunNote_infoL(&aReason);
}

void on_reg_state(bool success)
{
	if (success)
		Csymbian_ua_guiContainerView::RunNote_infoL();
	else
		Csymbian_ua_guiContainerView::RunNote_warningL();
}

void on_unreg_state(bool success)
{
	TPtrC st_success(_L("Unregistration Success!"));
	TPtrC st_failed(_L("Unregistration Failed!"));
	
	if (success)
		Csymbian_ua_guiContainerView::RunNote_infoL(&st_success);
	else
		Csymbian_ua_guiContainerView::RunNote_warningL(&st_failed);
}

void Csymbian_ua_guiContainerView::PutMessage(const TDesC &msg)
	{
	if (!iSymbian_ua_guiContainer)
		return;
	
	CEikEdwin *obj_info = (CEikEdwin*) iSymbian_ua_guiContainer->ComponentControl(iSymbian_ua_guiContainer->EEd_info);

	obj_info->SetTextL(&msg);
	obj_info->DrawDeferred();
	}

/**
 * First phase of Symbian two-phase construction. Should not contain any
 * code that could leave.
 */
Csymbian_ua_guiContainerView::Csymbian_ua_guiContainerView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	iSymbian_ua_guiContainer = NULL;
	// ]]] end generated region [Generated Contents]
	
	}
/** 
 * The view's destructor removes the container from the control
 * stack and destroys it.
 */
Csymbian_ua_guiContainerView::~Csymbian_ua_guiContainerView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	delete iSymbian_ua_guiContainer;
	iSymbian_ua_guiContainer = NULL;
	// ]]] end generated region [Generated Contents]
	
	symbian_ua_set_info_callback(NULL);
	myinstance = NULL;
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance then calls the second-phase constructor
 * without leaving the instance on the cleanup stack.
 * @return new instance of Csymbian_ua_guiContainerView
 */
Csymbian_ua_guiContainerView* Csymbian_ua_guiContainerView::NewL()
	{
	Csymbian_ua_guiContainerView* self = Csymbian_ua_guiContainerView::NewLC();
	CleanupStack::Pop( self );
	return self;
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance, pushes it on the cleanup stack,
 * then calls the second-phase constructor.
 * @return new instance of Csymbian_ua_guiContainerView
 */
Csymbian_ua_guiContainerView* Csymbian_ua_guiContainerView::NewLC()
	{
	Csymbian_ua_guiContainerView* self = new ( ELeave ) Csymbian_ua_guiContainerView();
	CleanupStack::PushL( self );
	self->ConstructL();
	return self;
	}


/**
 * Second-phase constructor for view.  
 * Initialize contents from resource.
 */ 
void Csymbian_ua_guiContainerView::ConstructL()
	{
	// [[[ begin generated region: do not modify [Generated Code]
	BaseConstructL( R_SYMBIAN_UA_GUI_CONTAINER_SYMBIAN_UA_GUI_CONTAINER_VIEW );
	// ]]] end generated region [Generated Code]
	
	// add your own initialization code here
	symbian_ua_info_cb_t cb;
	Mem::FillZ(&cb, sizeof(cb));

	cb.on_info = &on_info;
	cb.on_incoming_call = &on_incoming_call;
	cb.on_reg_state = &on_reg_state;
	cb.on_unreg_state = &on_unreg_state;
	cb.on_call_end = &on_call_end;
	
	symbian_ua_set_info_callback(&cb);
	myinstance = this;
	}
	
/**
 * @return The UID for this view
 */
TUid Csymbian_ua_guiContainerView::Id() const
	{
	return TUid::Uid( ESymbian_ua_guiContainerViewId );
	}

/**
 * Handle a command for this view (override)
 * @param aCommand command id to be handled
 */
void Csymbian_ua_guiContainerView::HandleCommandL( TInt aCommand )
	{   
	// [[[ begin generated region: do not modify [Generated Code]
	TBool commandHandled = EFalse;
	switch ( aCommand )
		{	// code to dispatch to the AknView's menu and CBA commands is generated here
	
		case ESymbian_ua_guiContainerViewControlPaneRightId:
			commandHandled = CallSoftKeyPressedL( aCommand );
			break;
		case ESymbian_ua_guiContainerViewSettingMenuItemCommand:
			commandHandled = HandleSettingMenuItemSelectedL( aCommand );
			break;
		default:
			break;
		}
	
		
	if ( !commandHandled ) 
		{
	
		if ( aCommand == ESymbian_ua_guiContainerViewControlPaneRightId )
			{
			AppUi()->HandleCommandL( EEikCmdExit );
			}
	
		}
	// ]]] end generated region [Generated Code]
	
	}

/**
 *	Handles user actions during activation of the view, 
 *	such as initializing the content.
 */
void Csymbian_ua_guiContainerView::DoActivateL(
		const TVwsViewId& /*aPrevViewId*/,
		TUid /*aCustomMessageId*/,
		const TDesC8& /*aCustomMessage*/ )
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	SetupStatusPaneL();
	
	CEikButtonGroupContainer* cba = AppUi()->Cba();
	if ( cba != NULL ) 
		{
		cba->MakeVisible( EFalse );
		}
	
	if ( iSymbian_ua_guiContainer == NULL )
		{
		iSymbian_ua_guiContainer = CSymbian_ua_guiContainer::NewL( ClientRect(), NULL, this );
		iSymbian_ua_guiContainer->SetMopParent( this );
		AppUi()->AddToStackL( *this, iSymbian_ua_guiContainer );
		} 
	// ]]] end generated region [Generated Contents]
	
	cba = CEikButtonGroupContainer::Current();
	if (cba != NULL) {
		if (symbian_ua_anycall())
			cba->SetCommandL(ESymbian_ua_guiContainerViewControlPaneRightId, KStHangUp);
		else
			cba->SetCommandL(ESymbian_ua_guiContainerViewControlPaneRightId, KStCall);
	}
	
	}

/**
 */
void Csymbian_ua_guiContainerView::DoDeactivate()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CleanupStatusPane();
	
	CEikButtonGroupContainer* cba = AppUi()->Cba();
	if ( cba != NULL ) 
		{
		cba->MakeVisible( ETrue );
		cba->DrawDeferred();
		}
	
	if ( iSymbian_ua_guiContainer != NULL )
		{
		AppUi()->RemoveFromViewStack( *this, iSymbian_ua_guiContainer );
		delete iSymbian_ua_guiContainer;
		iSymbian_ua_guiContainer = NULL;
		}
	// ]]] end generated region [Generated Contents]
	
	}

// [[[ begin generated function: do not modify
void Csymbian_ua_guiContainerView::SetupStatusPaneL()
	{
	// reset the context pane
	TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
	CEikStatusPaneBase::TPaneCapabilities subPaneContext = 
		StatusPane()->PaneCapabilities( contextPaneUid );
	if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
		{
		CAknContextPane* context = static_cast< CAknContextPane* > ( 
			StatusPane()->ControlL( contextPaneUid ) );
		context->SetPictureToDefaultL();
		}
	
	// setup the title pane
	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
	CEikStatusPaneBase::TPaneCapabilities subPaneTitle = 
		StatusPane()->PaneCapabilities( titlePaneUid );
	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
		{
		CAknTitlePane* title = static_cast< CAknTitlePane* >( 
			StatusPane()->ControlL( titlePaneUid ) );
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SYMBIAN_UA_GUI_CONTAINER_TITLE_RESOURCE );
		title->SetFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
				
	}
// ]]] end generated function

// [[[ begin generated function: do not modify
void Csymbian_ua_guiContainerView::CleanupStatusPane()
	{
	}
// ]]] end generated function

/** 
 * Handle status pane size change for this view (override)
 */
void Csymbian_ua_guiContainerView::HandleStatusPaneSizeChange()
	{
	CAknView::HandleStatusPaneSizeChange();
	
	// this may fail, but we're not able to propagate exceptions here
	TInt result;
	TRAP( result, SetupStatusPaneL() ); 
	}
	
/** 
 * Handle the rightSoftKeyPressed event.
 * @return ETrue if the command was handled, EFalse if not
 */
TBool Csymbian_ua_guiContainerView::CallSoftKeyPressedL( TInt aCommand )
	{
	CEikEdwin *obj_url = (CEikEdwin*) iSymbian_ua_guiContainer->ComponentControl(iSymbian_ua_guiContainer->EEd_url);
	CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
	
	if (symbian_ua_anycall()) {
		symbian_ua_endcall();
		return ETrue;
	}

	PutMessage(_L("Making call..."));
	if ( cba != NULL ) {
		cba->SetCommandL(aCommand, KStHangUp);
		cba->DrawDeferred();
	}
	

	TUint8 url[256];
	TPtr8 aUrl(url, 256);

	HBufC *buf = obj_url->GetTextInHBufL();
	CnvUtfConverter::ConvertFromUnicodeToUtf8(aUrl, *buf);
	delete buf;

	if (symbian_ua_makecall((char *)aUrl.PtrZ()) != 0) {
		PutMessage(_L("Making call failed!"));
		if ( cba != NULL ) {
			cba->SetCommandL(aCommand, KStCall);
			cba->DrawDeferred();
		}
	}
	
	return ETrue;
	}
				
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool Csymbian_ua_guiContainerView::HandleSettingMenuItemSelectedL( TInt aCommand )
	{
	AppUi()->ActivateLocalViewL(TUid::Uid(ESymbian_ua_guiSettingItemListViewId));
	return ETrue;
	}
				
// [[[ begin generated function: do not modify
/**
 * Show the popup note for note_error
 * @param aOverrideText optional override text
 */
void Csymbian_ua_guiContainerView::RunNote_errorL( const TDesC* aOverrideText )
	{
	CAknErrorNote* note = new ( ELeave ) CAknErrorNote();
	if ( aOverrideText == NULL )
		{
		HBufC* noteText = StringLoader::LoadLC( R_SYMBIAN_UA_GUI_CONTAINER_NOTE_ERROR );
		note->ExecuteLD( *noteText );
		CleanupStack::PopAndDestroy( noteText );
		}
	else
		{
		note->ExecuteLD( *aOverrideText );
		}
	}
// ]]] end generated function

// [[[ begin generated function: do not modify
/**
 * Show the popup note for note_info
 * @param aOverrideText optional override text
 */
void Csymbian_ua_guiContainerView::RunNote_infoL( const TDesC* aOverrideText )
	{
	CAknInformationNote* note = new ( ELeave ) CAknInformationNote();
	if ( aOverrideText == NULL )
		{
		HBufC* noteText = StringLoader::LoadLC( R_SYMBIAN_UA_GUI_CONTAINER_NOTE_INFO );
		note->ExecuteLD( *noteText );
		CleanupStack::PopAndDestroy( noteText );
		}
	else
		{
		note->ExecuteLD( *aOverrideText );
		}
	}
// ]]] end generated function

// [[[ begin generated function: do not modify
/**
 * Show the popup note for note_warning
 * @param aOverrideText optional override text
 */
void Csymbian_ua_guiContainerView::RunNote_warningL( const TDesC* aOverrideText )
	{
	CAknWarningNote* note = new ( ELeave ) CAknWarningNote();
	if ( aOverrideText == NULL )
		{
		HBufC* noteText = StringLoader::LoadLC( R_SYMBIAN_UA_GUI_CONTAINER_NOTE_WARNING );
		note->ExecuteLD( *noteText );
		CleanupStack::PopAndDestroy( noteText );
		}
	else
		{
		note->ExecuteLD( *aOverrideText );
		}
	}
// ]]] end generated function

// [[[ begin generated function: do not modify
/**
 * Show the popup dialog for qry_accept_call
 * @param aOverrideText optional override text
 * @return EAknSoftkeyYes (left soft key id) or 0
 */
TInt Csymbian_ua_guiContainerView::RunQry_accept_callL( const TDesC* aOverrideText )
	{
				
	CAknQueryDialog* queryDialog = CAknQueryDialog::NewL();	
	
	if ( aOverrideText != NULL )
		{
		queryDialog->SetPromptL( *aOverrideText );
		}
	return queryDialog->ExecuteLD( R_SYMBIAN_UA_GUI_CONTAINER_QRY_ACCEPT_CALL );
	}
// ]]] end generated function