ImagePrint/ImagePrintUI/imgpprintdll/src/cdiscoverydlgmanager.cpp
changeset 0 d11fb78c4374
child 2 acc370d7f2f6
equal deleted inserted replaced
-1:000000000000 0:d11fb78c4374
       
     1 /*
       
     2 * Copyright (c) 2004-2007 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  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <imageprintapp.rsg>
       
    20 #include <aknlists.h>
       
    21 #include <aknPopup.h>
       
    22 #include <StringLoader.h>
       
    23 #include <AknQueryDialog.h>
       
    24 #include <aknPopupHeadingPane.h>
       
    25 #include <badesca.h>
       
    26 #include <eikenv.h>
       
    27 #include <StringLoader.h>
       
    28 #include <AknWaitDialog.h>
       
    29 #include <AknIconUtils.h>
       
    30 #include <AknGlobalMsgQuery.h>      // global message query
       
    31 #include <apgcli.h>                 // rapalssession
       
    32 #include <centralrepository.h>      // repository
       
    33 #include <aknmessagequerydialog.h>
       
    34 #include <bluetooth/hci/hcierrors.h>
       
    35 #include <imgprintbitmaps.mbg>
       
    36 #include <upnpsettings.h>
       
    37 #include <upnprunsetupcommand.h>
       
    38 #include <upnpshowcommand.h>
       
    39 
       
    40 #include "cdiscoverydlgmanager.h"
       
    41 #include "imageprint.h"
       
    42 #include "mdiscovery.h"
       
    43 #include "mprintsettings.h"
       
    44 #include "ciffactory.h"
       
    45 #include "mprintsettings.h"
       
    46 #include "imgpprintapputil.h"
       
    47 #include "cimageprintappui.h"
       
    48 #include "imageprintconsts.h"
       
    49 #include "cimageprintdoc.h"
       
    50 #include "cimageprintengine.h"
       
    51 #include "tprinter.h"
       
    52 #include "clog.h"
       
    53 
       
    54 const TInt KArrayGranularity( 5 );
       
    55 const TInt KSearchAgainUID ( -1 );
       
    56 
       
    57 _LIT( KEmptyIconIndex, "0" );
       
    58 _LIT( KCachedIconIndex, "1" );
       
    59 _LIT( KBTIconIndex, "2" );
       
    60 _LIT( KKioskIconIndex, "3" );
       
    61 _LIT( KMMCIconIndex, "4" );
       
    62 _LIT( KUSBIconIndex, "5" );
       
    63 _LIT( KIconFile, "z:\\resource\\apps\\imgprintbitmaps.mif" );
       
    64 
       
    65 const TUint KSpaceForSingleIcon( 2 ); // icon index + tab = 2 chars
       
    66 const TUint KSpaceForBothIcons( 4 ); // icon index + tab + cache index + tab = 4 chars
       
    67 
       
    68 const TInt KNumberOfIcons( 7 );
       
    69 _LIT( KWLANIconIndex, "6" );
       
    70 
       
    71 void CleanUpResetAndDestroy(TAny* aArray)
       
    72 	{
       
    73 	if(aArray)
       
    74 		{
       
    75 		CArrayPtrFlat<TDesC>* array=(CArrayPtrFlat<TDesC>*)aArray;
       
    76 		array->ResetAndDestroy();
       
    77 		delete array;
       
    78 		}
       
    79 	}
       
    80 // CONSTRUCTION
       
    81 CDiscoveryDlgManager* CDiscoveryDlgManager::NewL(
       
    82 		CIFFactory& aIFFactory )
       
    83 	{
       
    84 	CDiscoveryDlgManager* self = NewLC( aIFFactory );
       
    85 	CleanupStack::Pop(self);
       
    86 	return self;
       
    87 	}
       
    88 
       
    89 CDiscoveryDlgManager* CDiscoveryDlgManager::NewLC(
       
    90 		CIFFactory& aIFFactory )
       
    91 	{
       
    92 	CDiscoveryDlgManager* self =
       
    93 	new (ELeave) CDiscoveryDlgManager ();
       
    94 	CleanupStack::PushL(self);
       
    95 	self->ConstructL( aIFFactory );
       
    96 	return self;
       
    97 	}
       
    98 
       
    99 // Constructor
       
   100 CDiscoveryDlgManager::CDiscoveryDlgManager()
       
   101 	{
       
   102 	}
       
   103 
       
   104 // 2nd phase constructor
       
   105 void CDiscoveryDlgManager::ConstructL( CIFFactory& aIFFactory )
       
   106 	{
       
   107 	iUidArray = new ( ELeave ) CArrayFixFlat<TInt>( KArrayGranularity );
       
   108 	iBrandArray = new ( ELeave ) CArrayFixFlat<TUint>( KArrayGranularity );
       
   109 	iProtocolArray = new ( ELeave ) CArrayFixFlat<TPrinterType>( KArrayGranularity );
       
   110 	iListOfDeviceNames = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   111 	iActivePopup = EFalse;  // Popuplist is not activated
       
   112 	iNameArray = new (ELeave) CDesCArrayFlat( KArrayGranularity );
       
   113 	iDiscovery = aIFFactory.DiscoveryIF();
       
   114 	iSettings = aIFFactory.SettingsIF();
       
   115 	iSelectDeviceText = StringLoader::LoadL( R_QTN_POPUP_LIST_TITLE );
       
   116 	iSearchingText = StringLoader::LoadL( R_QTN_POPUP_LIST_TITLE2 );
       
   117 	iActiveTitleText.Set( iSearchingText->Des() );
       
   118 	}
       
   119 
       
   120 // Destructor
       
   121 CDiscoveryDlgManager::~CDiscoveryDlgManager()
       
   122 	{
       
   123 	if ( iDiscovery )
       
   124 		{
       
   125 		iDiscovery->RemoveDiscoveryObserver();
       
   126 		}
       
   127 	if ( iActivePopup )
       
   128 		{
       
   129 		if ( iPopupList )
       
   130 			{
       
   131 			iPopupList->CancelPopup();
       
   132 			}
       
   133 		}
       
   134 	delete iListBox;
       
   135 	delete iUidArray;
       
   136 	delete iBrandArray;
       
   137 	delete iProtocolArray;
       
   138 	delete iListOfDeviceNames;
       
   139 	if ( iNameArray )
       
   140 		{
       
   141 		iNameArray->Reset();
       
   142 		}
       
   143 	delete iNameArray;
       
   144 	delete iPrinterName;
       
   145 	delete iSearchingText;
       
   146 	delete iSelectDeviceText;
       
   147 	}
       
   148 
       
   149 // Called when new device is found
       
   150 void CDiscoveryDlgManager::NotifyNewPrintDeviceL(
       
   151 		HBufC* aText,
       
   152 		TInt aUid,
       
   153 		TBool aCached,
       
   154 		TPrinterType aType,
       
   155 		TUint aVendor )
       
   156 	{
       
   157 	LOG("CDiscoveryDlgManager::NotifyNewPrintDevice BEGIN");
       
   158 	if( iHiddenDiscovery )
       
   159 		{
       
   160 		// multi-device hidden discovery (bt/wlan) handled differently
       
   161 		if ( iMultiDiscovery )
       
   162 			{
       
   163 			LOG("CDiscoveryDlgManager::NotifyNewPrintDevice doing hidden multi-discovery");
       
   164 			TInt uid = iSettings->GetDefaultPrintID();
       
   165 			LOG2("CDiscoveryDlgManager::NotifyNewPrintDevice found: %d default: %d", aUid, uid);
       
   166 			if ( uid == aUid )
       
   167 				{
       
   168 				if( iHiddenDiscoveryDialog )
       
   169 					{
       
   170 					TRAP_IGNORE( iHiddenDiscoveryDialog->ProcessFinishedL() );
       
   171 					iHiddenDiscoveryDialog = NULL;
       
   172 					}
       
   173 
       
   174 				TInt printerErrorCode(0);
       
   175 				printerErrorCode = iDiscovery->ChoosePrinterL( aUid );
       
   176 				iSettings->SetCurrentPrinterProtocol( aType );
       
   177 				iSettings->SetCurrentPrinterVendor( aVendor );
       
   178 				iSettings->SetCurrentPrinterName( *aText );
       
   179 				if( printerErrorCode == 0 )
       
   180 					{
       
   181 					iPrinterFound = ETrue;
       
   182 					iDiscoveryCompleted = ETrue;
       
   183 					delete iPrinterName;
       
   184 					iPrinterName = NULL;
       
   185 					// Cancel the discovery when device is found printjob is done.
       
   186 					iDiscovery->CancelDeviceDiscoveryL();
       
   187 					iPrinterName = aText->AllocL();
       
   188 					}
       
   189 				else
       
   190 					{
       
   191 					iPrinterFound = EFalse;
       
   192 					}
       
   193 				}
       
   194 			}
       
   195 		// USB and MMC hidden discovery only find one printer or not a printer at all
       
   196 		else
       
   197 			{
       
   198 			if( iHiddenDiscoveryDialog )
       
   199 				{
       
   200 				iHiddenDiscoveryDialog->ProcessFinishedL();
       
   201 				iHiddenDiscoveryDialog = NULL;
       
   202 				}
       
   203 
       
   204 			TInt printerErrorCode(0);
       
   205 			printerErrorCode = iDiscovery->ChoosePrinterL( aUid );
       
   206 			iSettings->SetCurrentPrinterProtocol( aType );
       
   207 			iSettings->SetCurrentPrinterVendor( aVendor );            
       
   208 			if( printerErrorCode == 0 )
       
   209 				{
       
   210 				iPrinterFound = ETrue;
       
   211 				iDiscoveryCompleted = ETrue;
       
   212 				delete iPrinterName;
       
   213 				iPrinterName = 0;
       
   214 				if( aType == MDiscoveryObserver::EMMC )
       
   215 					{
       
   216 					HBufC* memoryCard = 0;
       
   217 					memoryCard = StringLoader::LoadLC
       
   218 					( R_QTN_PRINT_MEMORY_CARD );
       
   219 
       
   220 					iSettings->SetCurrentPrinterName( *memoryCard );
       
   221 					iPrinterName = memoryCard->AllocL();                    
       
   222 					CleanupStack::PopAndDestroy( memoryCard );
       
   223 					}
       
   224 				else
       
   225 					{
       
   226 					iSettings->SetCurrentPrinterName( *aText );
       
   227 					iPrinterName = aText->AllocL();
       
   228 					}
       
   229 				}
       
   230 			else
       
   231 				{
       
   232 				iPrinterFound = EFalse;
       
   233 				}
       
   234 			}
       
   235 		}
       
   236 	else
       
   237 		{
       
   238 		if ( aType == MDiscoveryObserver::EUSB )
       
   239 			{
       
   240 			iUsbPrinterID = aUid;
       
   241 			}
       
   242 
       
   243 		TRAPD( err, AddNewDeviceToListL( aText, aUid, aCached, aType, aVendor ) );
       
   244 		if ( err )
       
   245 			{
       
   246 			LOG1("CDiscoveryDlgManager::NotifyNewPrintDevice device adding leaved with: %d", err );
       
   247 			// Nothing to do with the error code coming from ShowErrorMsgL
       
   248 			TRAP_IGNORE( IMGPPrintAppUtil::ShowErrorMsgL( err ) );
       
   249 			}
       
   250 		}
       
   251 	LOG("CDiscoveryDlgManager::NotifyNewPrintDevice END");
       
   252 	}
       
   253 
       
   254 // Called when error is found
       
   255 void CDiscoveryDlgManager::DiscoveryError(
       
   256 		TInt aErrCode )
       
   257 	{
       
   258 	if ( aErrCode == ENoConnection )
       
   259 		{		
       
   260 		CancelDiscovery();
       
   261 		}
       
   262 	}
       
   263 
       
   264 // Called when process completed
       
   265 void CDiscoveryDlgManager::DeviceDiscoveryCompleted()
       
   266 	{
       
   267 	LOG1("[CDiscoveryDlgManager::DeviceDiscoveryCompleted]\t Before dissmissing the process/wait dialog, iDiscoveryCompleted has value of %d", iDiscoveryCompleted);
       
   268 	// // Added this to avoid multiple "Search Again" texts, because server sends DeviceDiscoveryCompleted() more than once 
       
   269 	if( iDiscoveryCompleted )
       
   270 		{
       
   271 		return;
       
   272 		}
       
   273 
       
   274 	// Searching over, flag is essential
       
   275 	iSearchingCancelled = ETrue;
       
   276 
       
   277 	iActiveTitleText.Set( iSelectDeviceText->Des() );
       
   278 	// Set the title of the pop-up list
       
   279 	if ( iPopupList )
       
   280 		{
       
   281 		TRAP_IGNORE( iPopupList->SetTitleL( iActiveTitleText ) );
       
   282 		}
       
   283 	LOG("CDiscoveryDlgManager::DeviceDiscoveryCompleted BEGIN");
       
   284 	if( iHiddenDiscoveryDialog )
       
   285 		{
       
   286 		TRAP_IGNORE( iHiddenDiscoveryDialog->ProcessFinishedL() );
       
   287 		iHiddenDiscoveryDialog = NULL;
       
   288 		}
       
   289 
       
   290 	iDiscoveryCompleted = ETrue;
       
   291 	if ( iActivePopup )
       
   292 		{
       
   293 		iPopupList->Heading()->CancelAnimation();
       
   294 
       
   295 		TRAP_IGNORE( RemoveCachedIconsL() );
       
   296 		TRAP_IGNORE( AddSearchAgainTextL() );
       
   297 
       
   298 		if ( iPopupList )
       
   299 			{
       
   300 			TRAP_IGNORE( iPopupList->ButtonGroupContainer()->SetCommandSetL(
       
   301 					R_AVKON_SOFTKEYS_SELECT_CANCEL );
       
   302 			iPopupList->ButtonGroupContainer()->DrawNow() );
       
   303 			}
       
   304 		}
       
   305 	if ( iCancelling )
       
   306 		{
       
   307 		iCancelling = EFalse;
       
   308 		TRAP_IGNORE( iCancellingDialog->ProcessFinishedL() );
       
   309 		iCancellingDialog = NULL;
       
   310 		}
       
   311 	LOG("CDiscoveryDlgManager::DeviceDiscoveryCompleted END");
       
   312 	}
       
   313 
       
   314 // Displays the printer devices
       
   315 TBool CDiscoveryDlgManager::StartDlgManagerL( TInt aProtocol, TBool aHidden )
       
   316 	{
       
   317 	LOG2("CDiscoveryDlgManager::StartDlgManagerL BEGIN: protocol %d, hidden: %d", aProtocol, aHidden);
       
   318 	iDiscoveryCompleted = EFalse;
       
   319 	TBool okToContinue( ETrue );
       
   320 	iHiddenDiscovery = aHidden;
       
   321 
       
   322 	// Start the device discovery with all the supported protocols
       
   323 	if( aProtocol == 0 )
       
   324 		{
       
   325 		iSupportedProtocols = iDiscovery->SupportedProtocols();
       
   326 
       
   327 		// If discovering WLAN, AP must be defined before continuing
       
   328 		if ( iSupportedProtocols & KImagePrint_PrinterProtocol_UPnP )
       
   329 			{
       
   330 			LOG("CDiscoveryDlgManager::StartDlgManagerL: TryWlanDiscoveryL");
       
   331 			TryDeviceDiscoveryL( iSupportedProtocols, EFalse );
       
   332 			}
       
   333 		// Discovery without WLAN    
       
   334 		else
       
   335 			{
       
   336 			LOG("CDiscoveryDlgManager::StartDlgManagerL: StartDeviceDiscoveryL");
       
   337 			iDiscovery->StartDeviceDiscoveryL( this, iSupportedProtocols );
       
   338 			}
       
   339 		}
       
   340 	else
       
   341 		{
       
   342 		iSupportedProtocols = aProtocol;
       
   343 
       
   344 		// If discovering WLAN
       
   345 		if ( iSupportedProtocols & KImagePrint_PrinterProtocol_UPnP )
       
   346 			{
       
   347 			LOG("CDiscoveryDlgManager::StartDlgManagerL - discovering WLAN");
       
   348 			if ( !TryDeviceDiscoveryL( aProtocol, ETrue ) )
       
   349 				{
       
   350 				LOG("CDiscoveryDlgManager::StartDlgManagerL - discovering WLAN failed");
       
   351 				// If discovering failed, do not continue
       
   352 				okToContinue = EFalse;
       
   353 				return okToContinue;
       
   354 				}
       
   355 			}
       
   356 		else
       
   357 			{
       
   358 			LOG("iDiscovery->StartDeviceDiscoveryL START");
       
   359 			iDiscovery->StartDeviceDiscoveryL( this, aProtocol );
       
   360 			} 
       
   361 
       
   362 		LOG("iDiscovery->StartDeviceDiscoveryL END");
       
   363 		}
       
   364 
       
   365 	// BT & WLAN cases can find multiple devices which has to be handled
       
   366 	if ( aProtocol & KImagePrint_PrinterProtocol_BPP ||
       
   367 			aProtocol & KImagePrint_PrinterProtocol_BIP ||
       
   368 			aProtocol & KImagePrint_PrinterProtocol_OPP_Printer ||
       
   369 			aProtocol & KImagePrint_PrinterProtocol_OPP_PC ||
       
   370 			aProtocol & KImagePrint_PrinterProtocol_UPnP )
       
   371 		{
       
   372 		iMultiDiscovery = ETrue;
       
   373 		}
       
   374 
       
   375 	if( iHiddenDiscovery )
       
   376 		{
       
   377 		okToContinue = StartHiddenDiscoveryL();
       
   378 		}
       
   379 	else
       
   380 		{
       
   381 		okToContinue = StartNormalDiscoveryL();
       
   382 		}
       
   383 
       
   384 	LOG1("CDiscoveryDlgManager::StartDlgManagerL END return: %d", okToContinue);
       
   385 	return okToContinue;
       
   386 	}
       
   387 
       
   388 TBool CDiscoveryDlgManager::StartNormalDiscoveryL()
       
   389 	{
       
   390 	iActiveTitleText.Set( iSearchingText->Des() );
       
   391 	LOG("CDiscoveryDlgManager::StartNormalDiscoveryL BEGIN");
       
   392 	TInt printerErrorCode = 0;
       
   393 	TBool continueSearch( ETrue );
       
   394 	TBool okToContinue( ETrue );
       
   395 	iSearchingCancelled = EFalse; // ADDED
       
   396 	TInt uid; // Printer uid
       
   397 	// Loop until printer is selected or user decides to exit
       
   398 	while ( continueSearch )
       
   399 		{
       
   400 		// Create pop-up list
       
   401 		if ( !iPopupList )
       
   402 			{
       
   403 			iPopupList = CreatePopupListL();
       
   404 			}
       
   405 
       
   406 		// Show the pop-up list
       
   407 		if ( iListOfDeviceNames->Count() > 0 )
       
   408 			{
       
   409 			iPopupList->ButtonGroupContainer()->SetCommandSetL(
       
   410 					R_AVKON_SOFTKEYS_STOP
       
   411 			);
       
   412 			}
       
   413 
       
   414 		// Launch the pop-up list for found devices
       
   415 		LOG("CDiscoveryDlgManager::StartNormalDiscoveryL before launch popuplist");
       
   416 		TBool selected = iPopupList->ExecuteLD();
       
   417 		LOG1("CDiscoveryDlgManager::StartNormalDiscoveryL after popupList, selected: %d", selected);
       
   418 		iPopupList = NULL;
       
   419 		iActivePopup = EFalse;
       
   420 		LOG("CDiscoveryDlgManager::StartNormalDiscoveryL returned from popup");
       
   421 		TInt index = iListBox->CurrentItemIndex();
       
   422 
       
   423 		// Search again was selected
       
   424 		if ( selected && iUidArray->At( index ) == KSearchAgainUID )
       
   425 			{
       
   426 			RestartDiscoveryL();
       
   427 			}
       
   428 		// Device was selected
       
   429 		else if ( selected )
       
   430 			{
       
   431 			uid = iUidArray->At( index );
       
   432 			if ( uid == iUsbPrinterID )
       
   433 				{
       
   434 				iUSBPrinterSelected = ETrue ;
       
   435 				}
       
   436 			else
       
   437 				{
       
   438 				iUSBPrinterSelected = EFalse;
       
   439 				}
       
   440 
       
   441 			iCurrentPrinterUid = uid;
       
   442 			printerErrorCode = iDiscovery->ChoosePrinterL( uid );
       
   443 			if ( printerErrorCode != KErrNone )
       
   444 				{
       
   445 				IMGPPrintAppUtil::ShowErrorMsgL( printerErrorCode  );
       
   446 				User::Leave( printerErrorCode );
       
   447 				}
       
   448 			else
       
   449 				{
       
   450 				if ( iUidArray->At( 0 ) == KSearchAgainUID )
       
   451 					{
       
   452 					iSettings->SetCurrentPrinterProtocol( iProtocolArray->At( index - 1 ) );
       
   453 					iSettings->SetCurrentPrinterVendor( iBrandArray->At( index - 1 ) );
       
   454 					iSettings->SetCurrentPrinterName( (*iNameArray)[index-1] );
       
   455 					}
       
   456 				else
       
   457 					{
       
   458 					iSettings->SetCurrentPrinterProtocol( iProtocolArray->At( index ) );
       
   459 					iSettings->SetCurrentPrinterVendor( iBrandArray->At( index ));
       
   460 					iSettings->SetCurrentPrinterName( (*iNameArray)[index] );
       
   461 					}
       
   462 
       
   463 				continueSearch = EFalse;
       
   464 				// If there wasn't default protocol then set selected printer and protocol as default
       
   465 				if ( iSettings->GetDefaultPrinterProtocol() == KErrNotFound )
       
   466 					{
       
   467 					LOG1("CDiscoveryDlgManager::StartNormalDiscoveryL default protocol wasn't set, setting uid: %d", uid );
       
   468 					iSettings->SetDefaultPrinterID( uid );
       
   469 					// Discovery has completed and 'Search again' was added as a first item
       
   470 					// access protocol array with index-1
       
   471 					if ( iUidArray->At( 0 ) == KSearchAgainUID )
       
   472 						{
       
   473 						iSettings->SetDefaultPrinterProtocol( iProtocolArray->At( index-1 ) );
       
   474 						iSettings->SetDefaultPrinterNameL( (*iNameArray)[index-1] );
       
   475 						}
       
   476 					else
       
   477 						{
       
   478 						iSettings->SetDefaultPrinterProtocol( iProtocolArray->At( index ) );
       
   479 						iSettings->SetDefaultPrinterNameL( (*iNameArray)[index] );
       
   480 						}
       
   481 					}
       
   482 				else
       
   483 					{
       
   484 					LOG("CDiscoveryDlgManager::StartNormalDiscoveryL default protocol was already set" );
       
   485 					}
       
   486 				}
       
   487 
       
   488 			TPtrC name = iListOfDeviceNames->MdcaPoint( index );
       
   489 			delete iPrinterName;
       
   490 			iPrinterName = NULL;
       
   491 			iPrinterName = name.AllocL();
       
   492 			}
       
   493 		// Stop/Cancel was selected
       
   494 		else
       
   495 			{
       
   496 			LOG("CDiscoveryDlgManager::StartNormalDiscoveryL Stop/Cancel was selected" );
       
   497 			// Searching cancelled by user, cancel device discovery
       
   498 			if ( !iSearchingCancelled )
       
   499 				{
       
   500 				LOG("CDiscoveryDlgManager::StartNormalDiscoveryL iSearchingCancelled EFalse" );
       
   501 				iSearchingCancelled = ETrue;
       
   502 				iDiscovery->CancelDeviceDiscoveryL();
       
   503 				}
       
   504 
       
   505 			// User cancelled the whole discovery dialog
       
   506 			else
       
   507 				{
       
   508 				LOG("CDiscoveryDlgManager::StartNormalDiscoveryL iSearchingCancelled ETrue" );
       
   509 				continueSearch = EFalse;
       
   510 				okToContinue = EFalse;
       
   511 				iCancelling = ETrue;
       
   512 
       
   513 				// User cancelled the discovery dialog before all the printers were found
       
   514 				if ( !iDiscoveryCompleted )
       
   515 					{
       
   516 					//ShowCancelWaitNoteL();
       
   517 					}
       
   518 				}
       
   519 			}
       
   520 		}
       
   521 	LOG("CDiscoveryDlgManager::StartNormalDiscoveryL END");
       
   522 	return okToContinue;
       
   523 	}
       
   524 
       
   525 TBool CDiscoveryDlgManager::StartHiddenDiscoveryL()
       
   526 	{
       
   527 	LOG("CDiscoveryDlgManager::StartHiddenDiscoveryL BEGIN");
       
   528 	iHiddenDiscoveryDialog =
       
   529 	new (ELeave)CAknWaitDialog(
       
   530 			(REINTERPRET_CAST(CEikDialog**,&iHiddenDiscoveryDialog)));
       
   531 	LOG("iHiddenDiscoveryDialog->ExecuteLD( R_HIDDEN_DIALOG ) BEGIN");
       
   532 	iHiddenDiscoveryDialog->ExecuteLD( R_HIDDEN_DIALOG );
       
   533 	LOG("iHiddenDiscoveryDialog->ExecuteLD( R_HIDDEN_DIALOG ) END");
       
   534 	LOG1("iPrinterFound = %d", iPrinterFound);
       
   535 	LOG("CDiscoveryDlgManager::StartHiddenDiscoveryL END");
       
   536 	return iPrinterFound;
       
   537 	}
       
   538 
       
   539 void CDiscoveryDlgManager::DialogDismissedL( TInt /*aButtonId*/ )
       
   540 	{
       
   541 	LOG("CDiscoveryDlgManager::DialogDismissedL BEGIN");
       
   542 	// This is called only if hidden discovery is cancelled
       
   543 	// start cancelling operation and put cancelling note on.
       
   544 	iPrinterFound = EFalse;
       
   545 	iCancelling = ETrue;
       
   546 	iDiscovery->CancelDeviceDiscoveryL();
       
   547 	// User cancelled the discovery dialog before all the printers were found
       
   548 	if ( !iDiscoveryCompleted )
       
   549 		{
       
   550 		ShowCancelWaitNoteL();
       
   551 		}
       
   552 	LOG("CDiscoveryDlgManager::DialogDismissedL END");
       
   553 	}
       
   554 
       
   555 void CDiscoveryDlgManager::ShowCancelWaitNoteL()
       
   556 	{
       
   557 	iCancellingDialog  =
       
   558 	new ( ELeave ) CAknWaitDialog(
       
   559 			(REINTERPRET_CAST(CEikDialog**,&iCancellingDialog)));
       
   560 	iCancellingDialog->PrepareLC(R_CANCEL_PRINTING_DIALOG);
       
   561 	HBufC* text = StringLoader::LoadLC( R_QTN_PRINT_PROGRESS_PROMPT_CANCEL );
       
   562 	iCancellingDialog->SetTextL( *text );
       
   563 	CleanupStack::PopAndDestroy(text);
       
   564 
       
   565 	iCancellingDialog->SetTone( CAknNoteDialog::ENoTone );
       
   566 	iCancellingDialog->RunLD();
       
   567 	}
       
   568 
       
   569 // Creates and initializees the popup list
       
   570 CAknPopupList* CDiscoveryDlgManager::CreatePopupListL()
       
   571 	{
       
   572 	LOG("CDiscoveryDlgManager::CreatePopupListL BEGIN");
       
   573 	if ( iListBox )
       
   574 		{
       
   575 		delete iListBox;
       
   576 		iListBox = 0;
       
   577 		}
       
   578 	// Creates list box for the pop-up list
       
   579 	iListBox = new ( ELeave ) CAknSingleGraphicPopupMenuStyleListBox;//CAknSingleGraphicPopupMenuStyleListBox;
       
   580 
       
   581 	// Create and initialize the popup list
       
   582 	iPopupList = CAknPopupList::NewL(
       
   583 			iListBox,
       
   584 			/*R_AVKON_SOFTKEYS_CANCEL,*/
       
   585 			R_AVKON_SOFTKEYS_STOP,
       
   586 			AknPopupLayouts::EDynMenuWindow );
       
   587 
       
   588 	// Set the title of the pop-up list
       
   589 	iPopupList->SetTitleL( iActiveTitleText );
       
   590 
       
   591 	// Initialize list box
       
   592 	iListBox->ConstructL( iPopupList,
       
   593 			EAknListBoxSelectionList ); // EAknListBoxMenuList
       
   594 	iListBox->CreateScrollBarFrameL( ETrue );
       
   595 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   596 			CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   597 	HBufC* text = StringLoader::LoadLC( R_QTN_PRINT_NO_PRINTERS );
       
   598 	iListBox->View()->SetListEmptyTextL( *text );
       
   599 	CleanupStack::PopAndDestroy( text );
       
   600 
       
   601 	//Array of icons to show in the pop-up list
       
   602 	CArrayPtrFlat< CGulIcon >* icons =
       
   603 	new( ELeave ) CArrayPtrFlat< CGulIcon >( KNumberOfIcons );
       
   604 
       
   605 	//Push to ClenupStack. Array and all of items added to it
       
   606 	//are deleted if leave occurs
       
   607 	CleanupStack::PushL(TCleanupItem(CleanUpResetAndDestroy, icons));
       
   608 	icons->SetReserveL( KNumberOfIcons );
       
   609 
       
   610 	CFbsBitmap* bitmap = NULL;
       
   611 	CFbsBitmap* mask = NULL;
       
   612 
       
   613 	bitmap = new( ELeave ) CFbsBitmap();
       
   614 	User::LeaveIfError( bitmap->Create( TSize(0,0), EColor256 ) );
       
   615 	CleanupStack::PushL( bitmap );
       
   616 	CGulIcon* icon = CGulIcon::NewL( bitmap );
       
   617 	CleanupStack::Pop( bitmap );
       
   618 	CleanupStack::PushL( icon );
       
   619 	icons->AppendL( icon );
       
   620 	CleanupStack::Pop( icon );
       
   621 
       
   622 	AknIconUtils::CreateIconLC( bitmap, mask, KIconFile,
       
   623 			EMbmImgprintbitmapsQgn_indi_print_cached,
       
   624 			EMbmImgprintbitmapsQgn_indi_print_cached_mask );
       
   625 	icon = CGulIcon::NewL(bitmap,mask);
       
   626 	CleanupStack::Pop( 2 ); // bitmap, mask
       
   627 	CleanupStack::PushL( icon );
       
   628 	icons->AppendL( icon );
       
   629 	CleanupStack::Pop( icon );
       
   630 
       
   631 	AknIconUtils::CreateIconLC( bitmap, mask, KIconFile,
       
   632 			EMbmImgprintbitmapsQgn_prop_print_bt,
       
   633 			EMbmImgprintbitmapsQgn_prop_print_bt_mask );
       
   634 	icon = CGulIcon::NewL( bitmap, mask );
       
   635 	CleanupStack::Pop( 2 ); // bitmap, mask
       
   636 	CleanupStack::PushL( icon );
       
   637 	icons->AppendL( icon );
       
   638 	CleanupStack::Pop( icon );
       
   639 
       
   640 	AknIconUtils::CreateIconLC( bitmap, mask, KIconFile,
       
   641 			EMbmImgprintbitmapsQgn_prop_print_kiosk,
       
   642 			EMbmImgprintbitmapsQgn_prop_print_kiosk_mask );
       
   643 	icon = CGulIcon::NewL( bitmap, mask );
       
   644 	CleanupStack::Pop( 2 ); // bitmap, mask
       
   645 	CleanupStack::PushL( icon );
       
   646 	icons->AppendL( icon );
       
   647 	CleanupStack::Pop( icon );
       
   648 
       
   649 	AknIconUtils::CreateIconLC( bitmap, mask, KIconFile,
       
   650 			EMbmImgprintbitmapsQgn_prop_print_mmc,
       
   651 			EMbmImgprintbitmapsQgn_prop_print_mmc_mask );
       
   652 	icon = CGulIcon::NewL( bitmap, mask );
       
   653 	CleanupStack::Pop( 2 ); // bitmap, mask
       
   654 	CleanupStack::PushL( icon );
       
   655 	icons->AppendL( icon );
       
   656 	CleanupStack::Pop( icon );
       
   657 
       
   658 	AknIconUtils::CreateIconLC( bitmap, mask, KIconFile,
       
   659 			EMbmImgprintbitmapsQgn_prop_print_usb,
       
   660 			EMbmImgprintbitmapsQgn_prop_print_usb_mask );
       
   661 	icon = CGulIcon::NewL( bitmap, mask );
       
   662 	CleanupStack::Pop( 2 ); // bitmap, mask
       
   663 	CleanupStack::PushL( icon );
       
   664 	icons->AppendL( icon );
       
   665 	CleanupStack::Pop( icon );
       
   666 
       
   667 	AknIconUtils::CreateIconLC( bitmap, mask, KIconFile,
       
   668 			EMbmImgprintbitmapsQgn_prop_print_wlan,
       
   669 			EMbmImgprintbitmapsQgn_prop_print_wlan_mask );
       
   670 	icon = CGulIcon::NewL( bitmap, mask );
       
   671 	CleanupStack::Pop( 2 ); // bitmap, mask
       
   672 	CleanupStack::PushL( icon );
       
   673 	icons->AppendL( icon );
       
   674 	CleanupStack::Pop( icon );
       
   675 
       
   676 	CleanupStack::Pop( icons );
       
   677 	iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( icons );
       
   678 	iListBox->Model()->SetItemTextArray( iListOfDeviceNames );
       
   679 	iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   680 
       
   681 	// Set the animation
       
   682 	iPopupList->Heading()->SetHeaderAnimationL( R_IMAGEPRINT_ANIMATION );
       
   683 	iActivePopup = ETrue;
       
   684 
       
   685 	LOG("CDiscoveryDlgManager::CreatePopupListL END");
       
   686 	return iPopupList;
       
   687 	}
       
   688 
       
   689 // Adds new device to list, updates popup list
       
   690 void CDiscoveryDlgManager::AddNewDeviceToListL(
       
   691 		HBufC* aText,
       
   692 		TInt aUid,
       
   693 		TBool aCached,
       
   694 		TPrinterType aType,
       
   695 		TUint aVendor )
       
   696 	{
       
   697 	LOG("CDiscoveryDlgManager::AddNewDeviceToListL BEGIN");
       
   698 	HBufC* buf;
       
   699 
       
   700 	// if the device is memory card
       
   701 	if( aType == MDiscoveryObserver::EMMC )
       
   702 		{
       
   703 		HBufC* stringholdercopy = StringLoader::LoadLC
       
   704 		( R_QTN_PRINT_MEMORY_CARD );
       
   705 		buf = HBufC::NewLC( stringholdercopy->Size() + KSpaceForSingleIcon );
       
   706 		TPtr ptr = buf->Des();
       
   707 		ptr.Append( KMMCIconIndex );
       
   708 		ptr.Append( KTabChar );
       
   709 		ptr.Append( stringholdercopy->Des() );
       
   710 
       
   711 		// Add new device into array
       
   712 		iListOfDeviceNames->InsertL( 0, *buf );
       
   713 		iNameArray->InsertL( 0, *stringholdercopy );
       
   714 		CleanupStack::PopAndDestroy( 2, stringholdercopy ); //buf, stringholdercopy
       
   715 		}
       
   716 	else // any other device
       
   717 		{
       
   718 		if ( aCached )
       
   719 			{
       
   720 			buf = HBufC::NewLC( aText->Size() + KSpaceForBothIcons );
       
   721 			}
       
   722 		else
       
   723 			{
       
   724 			buf = HBufC::NewLC( aText->Size() + KSpaceForSingleIcon );
       
   725 			}
       
   726 		TPtr ptr = buf->Des();
       
   727 		if( aType == MDiscoveryObserver::EBPP )
       
   728 			{
       
   729 			ptr.Append( KBTIconIndex );
       
   730 			}
       
   731 		else if( aType == MDiscoveryObserver::EOPP )
       
   732 			{
       
   733 			ptr.Append( KKioskIconIndex );
       
   734 			}
       
   735 		else if( aType == MDiscoveryObserver::EUSB )
       
   736 			{
       
   737 			ptr.Append( KUSBIconIndex );
       
   738 			}
       
   739 		else if( aType == MDiscoveryObserver::EWLAN )
       
   740 			{
       
   741 			ptr.Append( KWLANIconIndex );
       
   742 			}
       
   743 		else
       
   744 			{
       
   745 			ptr.Append( KEmptyIconIndex );
       
   746 			}
       
   747 		ptr.Append( KTabChar );        	
       
   748 		ptr.Append( aText->Des() );
       
   749 
       
   750 		if ( aCached )
       
   751 			{
       
   752 			ptr.Append( KTabChar );  
       
   753 			ptr.Append( KCachedIconIndex );
       
   754 			}
       
   755 
       
   756 		// Add new device into array
       
   757 		iListOfDeviceNames->InsertL( 0, *buf );
       
   758 		CleanupStack::PopAndDestroy( buf );
       
   759 		}
       
   760 
       
   761 	// Add Uid of the device into array
       
   762 	iUidArray->InsertL( 0, aUid );
       
   763 
       
   764 	aVendor = TPrinter::EVendorNone;
       
   765 
       
   766 	iBrandArray->InsertL( 0, aVendor );
       
   767 	iProtocolArray->InsertL( 0, aType );
       
   768 	if( aType != MDiscoveryObserver::EMMC )
       
   769 		{
       
   770 		iNameArray->InsertL( 0, *aText );
       
   771 		}
       
   772 
       
   773 	if ( iActivePopup )
       
   774 		{
       
   775 		LOG("CDiscoveryDlgManager::AddNewDeviceToListL popup update");
       
   776 		iListBox->HandleItemAdditionL();
       
   777 		iPopupList->DrawNow();
       
   778 
       
   779 		if ( iListOfDeviceNames->MdcaCount() == 1 )
       
   780 			{
       
   781 			// First item to appear, change CBA
       
   782 			iPopupList->ButtonGroupContainer()->SetCommandSetL(
       
   783 					R_AVKON_SOFTKEYS_STOP
       
   784 			);
       
   785 			iPopupList->ButtonGroupContainer()->DrawNow();
       
   786 			}
       
   787 		}
       
   788 	LOG("CDiscoveryDlgManager::AddNewDeviceToListL END");
       
   789 	}
       
   790 
       
   791 // Returns the name of the chosen printer
       
   792 TInt CDiscoveryDlgManager::PrinterUid() const
       
   793 	{
       
   794 	return iCurrentPrinterUid;
       
   795 	}
       
   796 
       
   797 // Returns the name of the chosen printer
       
   798 const TDesC& CDiscoveryDlgManager::PrinterName() const
       
   799 	{
       
   800 	LOG("CDiscoveryDlgManager::PrinterName() BEGIN");
       
   801 	if ( !iPrinterName )
       
   802 		{
       
   803 		return KNullDesC();
       
   804 		}
       
   805 	else
       
   806 		{
       
   807 		return *iPrinterName;
       
   808 		}
       
   809 	}
       
   810 	
       
   811 	TBool CDiscoveryDlgManager::USBPrinterSelected() const
       
   812 	{
       
   813 	return iUSBPrinterSelected;
       
   814 	}
       
   815 
       
   816 // Resets the popup list and starts the device discovery again
       
   817 void CDiscoveryDlgManager::RestartDiscoveryL()
       
   818 	{
       
   819 	iSearchingCancelled = EFalse;
       
   820 
       
   821 	iListOfDeviceNames->Reset();
       
   822 	iUidArray->Reset();
       
   823 	iBrandArray->Reset();
       
   824 	iProtocolArray->Reset();
       
   825 	iActiveTitleText.Set( iSearchingText->Des() );
       
   826 	iPopupList = CreatePopupListL();
       
   827 	iDiscoveryCompleted = EFalse;
       
   828 	iDiscovery->StartDeviceDiscoveryL( this, iSupportedProtocols );
       
   829 	}
       
   830 
       
   831 // Removes cached printer from the list
       
   832 void CDiscoveryDlgManager::RemoveCachedPrinterL(
       
   833 		TInt aUid )
       
   834 	{
       
   835 	TInt i( 0 );
       
   836 	TBool found( EFalse );
       
   837 	for ( i = 0; i < iUidArray->Count() && !found; i++ )
       
   838 		{
       
   839 		if ( aUid == iUidArray->At( i ) )
       
   840 			{
       
   841 			TInt curIndex = iListBox->CurrentItemIndex();
       
   842 			if ( curIndex >= i &&
       
   843 					iListOfDeviceNames->MdcaCount() > 1 && curIndex > 0 )
       
   844 				{
       
   845 				iListBox->SetCurrentItemIndexAndDraw( curIndex - 1 );
       
   846 				}
       
   847 
       
   848 			iUidArray->Delete( i );
       
   849 			iBrandArray->Delete( i );
       
   850 			iProtocolArray->Delete( i );
       
   851 			iNameArray->Delete( i );
       
   852 			iListOfDeviceNames->Delete( i );
       
   853 			iListBox->HandleItemRemovalL();
       
   854 			iPopupList->DrawNow();
       
   855 
       
   856 			if ( iListOfDeviceNames->MdcaCount() == 0 )
       
   857 				{
       
   858 				// Zero items, change softkeys
       
   859 				if ( iActivePopup )
       
   860 					{
       
   861 					iPopupList->ButtonGroupContainer()->SetCommandSetL(
       
   862 							R_AVKON_SOFTKEYS_CANCEL );
       
   863 					iPopupList->ButtonGroupContainer()->DrawNow();
       
   864 					}
       
   865 				}
       
   866 			found = ETrue;
       
   867 			}
       
   868 		}
       
   869 	}
       
   870 
       
   871 // Removes cached printer icons from the list
       
   872 void CDiscoveryDlgManager::RemoveCachedIconsL()
       
   873 	{
       
   874 	TInt counter = iListOfDeviceNames->MdcaCount();
       
   875 	TChar KTabChar( 0x0009 );
       
   876 	for ( TInt i = 0 ; i < counter; i++ )
       
   877 		{
       
   878 		TPtrC tmp( iListOfDeviceNames->MdcaPoint( i ) );
       
   879 		//locate the rightmost tab
       
   880 		TInt tabPosition = tmp.LocateReverse( KTabChar );
       
   881 		if ( tabPosition != KErrNotFound &&
       
   882 				tabPosition > 1 ) //don't remove the pre-text tab
       
   883 			{
       
   884 			iListOfDeviceNames->InsertL( i, tmp.Left( tabPosition ) );
       
   885 			iListOfDeviceNames->Delete( i + 1 );
       
   886 			}
       
   887 		}
       
   888 	iListBox->HandleItemAdditionL();
       
   889 	iPopupList->DrawNow();
       
   890 	}
       
   891 
       
   892 // Adds serarch again text to list
       
   893 void CDiscoveryDlgManager::AddSearchAgainTextL()
       
   894 	{
       
   895 	HBufC* str = StringLoader::LoadLC
       
   896 	( R_QTN_SEARCH_AGAIN );
       
   897 	HBufC* buf = HBufC::NewLC( str->Size() + KSpaceForSingleIcon );
       
   898 	TPtr ptr = buf->Des();
       
   899 	ptr.Append( KEmptyIconIndex );
       
   900 	ptr.Append( KTabChar );
       
   901 	ptr.Append( str->Des() );
       
   902 
       
   903 	iListOfDeviceNames->InsertL( 0, *buf );
       
   904 
       
   905 	CleanupStack::PopAndDestroy( 2, str ); //buf, str
       
   906 
       
   907 	iUidArray->InsertL( 0, KSearchAgainUID );
       
   908 	iListBox->HandleItemAdditionL();
       
   909 	iPopupList->DrawNow();
       
   910 	}
       
   911 
       
   912 //--------------------------------------------------------------------------------------------
       
   913 //
       
   914 // CDiscoveryDlgManager::WlanAccessPointExists
       
   915 //
       
   916 //--------------------------------------------------------------------------------------------
       
   917 TBool CDiscoveryDlgManager::WlanAccessPointExistsL()
       
   918 	{
       
   919 	LOG("[CDiscoveryDlgManager::WlanAccessPointExists] BEGIN");
       
   920 	TBool accessPointExists( EFalse );
       
   921         CUpnpShowCommand* upnpShowCommand = NULL;
       
   922         TRAPD ( error, upnpShowCommand = CUpnpShowCommand::NewL() );   
       
   923         if ( error != KErrNone )
       
   924         	{
       
   925         	LOG1("[CDiscoveryDlgManager::WlanAccessPointExists] CUpnpShowCommand::NewL leaves, with: %d", error);
       
   926         	return accessPointExists;
       
   927         	}
       
   928         CleanupStack::PushL( upnpShowCommand );    
       
   929         accessPointExists = upnpShowCommand->IsAvailableL();
       
   930         CleanupStack::PopAndDestroy(); // upnpShowCommand
       
   931 		LOG1("[CDiscoveryDlgManager::WlanAccessPointExists]\t END, AccessPointExists: %d", accessPointExists);
       
   932         return accessPointExists;  
       
   933 	}
       
   934 
       
   935 //--------------------------------------------------------------------------------------------
       
   936 //
       
   937 // CDiscoveryDlgManager::TryDeviceDiscoveryL()
       
   938 //
       
   939 //--------------------------------------------------------------------------------------------
       
   940 TBool CDiscoveryDlgManager::TryDeviceDiscoveryL( TUint aProtocols, TBool aSingleDiscovery )
       
   941 	{
       
   942 	LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL");
       
   943 
       
   944 	// WLAN access point not defined 	
       
   945 	if ( !WlanAccessPointExistsL() )
       
   946 		{          
       
   947 		LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - AP not defined, launch WLAN wizard query");
       
   948 
       
   949 		// Launch WLAN wizard query
       
   950 		LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - CAknMessageQueryDialog");
       
   951 		CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog;
       
   952 
       
   953 		// User pressed OK
       
   954 		if ( dlg->ExecuteLD( R_LAUNCH_WLAN_WIZARD_QUERY ) )
       
   955 			{
       
   956 			LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Launch WLAN wizard");
       
   957 
       
   958 			// Launch WLAN wizard
       
   959 			CUpnpRunSetupCommand* runSetupCommand = CUpnpRunSetupCommand::NewL();
       
   960 			CleanupStack::PushL(runSetupCommand);
       
   961 			runSetupCommand->RunSetupL();
       
   962 			CleanupStack::PopAndDestroy(runSetupCommand);
       
   963 
       
   964 
       
   965 			// If access point defined by the WLAN wizard
       
   966 			if ( WlanAccessPointExistsL() )
       
   967 				{
       
   968 				LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - AP defined in WLAN wizard");
       
   969 
       
   970 				if ( aSingleDiscovery )
       
   971 					{
       
   972 					// Start discovery
       
   973 					// Continues to StartDeviceDiscoveryL
       
   974 					LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Start discovery with single protocol");
       
   975 					iDiscovery->StartDeviceDiscoveryL( this, aProtocols );
       
   976 					}
       
   977 				else
       
   978 					{
       
   979 					// Start discovery
       
   980 					// Continues to StartDeviceDiscoveryL
       
   981 					LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Start discovery with all prots");
       
   982 					iDiscovery->StartDeviceDiscoveryL( this, iSupportedProtocols );
       
   983 					}
       
   984 				}
       
   985 
       
   986 			// Access point not defined by the WLAN wizard
       
   987 			else
       
   988 				{
       
   989 				// Thus, WLAN discovery not supported
       
   990 				iSupportedProtocols = iSupportedProtocols - KImagePrint_PrinterProtocol_UPnP;
       
   991 
       
   992 				if ( aSingleDiscovery )
       
   993 					{
       
   994 					// Do nothing
       
   995 					// WLAN not supported
       
   996 					LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Launch WLAN wizard canceled");
       
   997 					return EFalse;
       
   998 					}
       
   999 				else
       
  1000 					{
       
  1001 					LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Start discovery without WLAN");
       
  1002 					iDiscovery->StartDeviceDiscoveryL( this, iSupportedProtocols );
       
  1003 					}
       
  1004 
       
  1005 				iSupportedProtocols = iSupportedProtocols - KImagePrint_PrinterProtocol_UPnP;
       
  1006 				LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Start discovery without WLAN");
       
  1007 				iDiscovery->StartDeviceDiscoveryL( this, iSupportedProtocols );
       
  1008 				}
       
  1009 			}
       
  1010 
       
  1011 		// User pressed cancel
       
  1012 		else
       
  1013 			{  
       
  1014 			LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - User pressed cancel");
       
  1015 
       
  1016 			// WLAN discovery not supported
       
  1017 			iSupportedProtocols = iSupportedProtocols - KImagePrint_PrinterProtocol_UPnP; 
       
  1018 
       
  1019 			if ( aSingleDiscovery )
       
  1020 				{
       
  1021 				// Do nothing
       
  1022 				// WLAN not supported
       
  1023 				LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Launch WLAN wizard canceled");
       
  1024 				return EFalse;
       
  1025 				}
       
  1026 			else
       
  1027 				{
       
  1028 				LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Start discovery without WLAN");
       
  1029 				iDiscovery->StartDeviceDiscoveryL( this, iSupportedProtocols );
       
  1030 				}  
       
  1031 			}
       
  1032 
       
  1033 		return ETrue;
       
  1034 		}
       
  1035 
       
  1036 	// If WLAN access point is defined
       
  1037 	else 
       
  1038 		{
       
  1039 		LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - AP is defined");
       
  1040 
       
  1041 		// Start discovery
       
  1042 		// Continues to StartDeviceDiscoveryL
       
  1043 
       
  1044 		if ( aSingleDiscovery )
       
  1045 			{
       
  1046 			LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Start WLAN discovery");
       
  1047 			iDiscovery->StartDeviceDiscoveryL( this, aProtocols );
       
  1048 			}
       
  1049 		else
       
  1050 			{
       
  1051 			LOG("[CUPnPPrintingDevice]\t TryDeviceDiscoveryL - Start discovery with all prots");
       
  1052 			iDiscovery->StartDeviceDiscoveryL( this, iSupportedProtocols ); 
       
  1053 			}
       
  1054 
       
  1055 		return ETrue;
       
  1056 		}
       
  1057 	}
       
  1058 
       
  1059 //--------------------------------------------------------------------------------------------
       
  1060 //
       
  1061 // CDiscoveryDlgManager::CancelDiscovery()
       
  1062 //
       
  1063 //--------------------------------------------------------------------------------------------
       
  1064 void CDiscoveryDlgManager::CancelDiscovery()
       
  1065 	{
       
  1066 	LOG("CDiscoveryDlgManager::CancelDiscovery begin");
       
  1067 	if(iPopupList)
       
  1068 		{
       
  1069 		LOG("CDiscoveryDlgManager::CancelDiscovery canceling popup device list.");
       
  1070 		iSearchingCancelled = ETrue;
       
  1071 
       
  1072 		TInt error ( KErrNone );
       
  1073 		TRAP( error, iDiscovery->CancelDeviceDiscoveryL());
       
  1074 
       
  1075 
       
  1076 		iPopupList->CancelPopup();
       
  1077 		}
       
  1078 	LOG("CDiscoveryDlgManager::CancelDiscovery end");
       
  1079 	}
       
  1080 
       
  1081 //  End of File