examples/sfexamples/IRDevice/src/IRDeviceAppUi.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 // INCLUDES
00018 #include <IRDevice.rsg>
00019 
00020 #include "IRDeviceAppUi.h"
00021 #include "IRDeviceMainView.h"
00022 #include "IRDevice.hrh"
00023 #include <es_sock.h>
00024 
00025 void CIRDeviceAppUi::SearchIrDevicesL()
00026         {
00027         RSocketServ ss;
00028         TProtocolDesc pInfo;
00029         User::LeaveIfError(ss.Connect());
00030         CleanupClosePushL(ss);
00031 
00032         _LIT(KTinyTP,"IrTinyTP");
00033         TProtocolName protocolName(KTinyTP);    
00034         User::LeaveIfError(ss.FindProtocol(protocolName,pInfo));
00035 
00036         RHostResolver hr;
00037         User::LeaveIfError(hr.Open(ss,pInfo.iAddrFamily,pInfo.iProtocol));
00038         CleanupClosePushL(hr);
00039 
00040         TNameEntry log;
00041         _LIT(KMask, "*");
00042         THostName name(KMask);
00043 
00044         TInt ret = hr.GetByName(name, log);
00045         if (ret!=KErrNone)
00046                 {
00047                 // No devices discovered - may be none present
00048                 CEikonEnv::Static()->InfoWinL(
00049                                                 R_IRDEVICE_CAPTION, R_IRDEVICE_CAPTION);
00050                 CleanupStack::PopAndDestroy(2);         
00051                 }
00052         // Call RHostResolver::Next() on 9.2 here
00053         else
00054                 {
00055                 while (hr.Next(log) == KErrNone)
00056                         {
00057                         CEikonEnv::Static()->InfoWinL(name,KNullDesC);
00058                         }
00059                 }
00060         CleanupStack::PopAndDestroy(2); // ss, hr       
00061         }
00062 // MEMBER FUNCTIONS
00063 
00064 // --------------------------------------------------------------------------
00065 // Constructor
00066 // --------------------------------------------------------------------------
00067 void CIRDeviceAppUi::ConstructL()
00068         {
00069         BaseConstructL(EAknEnableSkin);
00070         
00071         iMainView = CIRDeviceMainView::NewL(ClientRect());
00072         }
00073         
00074 // --------------------------------------------------------------------------
00075 // Destructor
00076 // --------------------------------------------------------------------------
00077 CIRDeviceAppUi::~CIRDeviceAppUi()
00078     {
00079     if (iMainView)
00080         {
00081         delete iMainView;
00082         iMainView = NULL;
00083         }
00084     }
00085 
00086 // --------------------------------------------------------------------------
00087 // Handles user command.
00088 // --------------------------------------------------------------------------
00089 void CIRDeviceAppUi::HandleCommandL(TInt aCommand)
00090         {
00091         switch ( aCommand )
00092                 {
00093 
00094                 // For S60, we need to handle this event, which is normally
00095                 // an event from the right soft key.
00096                 case EAknSoftkeyExit:
00097 
00098                 case EEikCmdExit:
00099                         {
00100                         Exit();
00101                         break;
00102                         }
00103                 
00104                 case EIRDeviceCommand1:
00105                         {                       
00106                         SearchIrDevicesL();
00107                         break;
00108                         }
00109                 
00110                 default:
00111                         // Do nothing
00112                         break;
00113                 }
00114         }
00115 
00116 
00117 // --------------------------------------------------------------------------
00118 // Handles screen resolution/size changes.
00119 // --------------------------------------------------------------------------
00120 void CIRDeviceAppUi::HandleResourceChangeL(TInt aType)
00121         {
00122         CAknAppUi::HandleResourceChangeL(aType);
00123         iMainView->SetRect(ClientRect());
00124         }
00125 
00126 
00127 // End of File

Generated by  doxygen 1.6.2