/* ============================================================================ Name : Placeads2AppUi.cpp Author : Copyright : Your copyright notice Description : CPlaceads2AppUi implementation ============================================================================ */ #include #include #include #include #include #include #include #include #include "InnerActiveAd.hrh" #include #include #ifdef _HELP_AVAILABLE_ #include "Placeads2_0xEDE5C37C.hlp.hrh" #endif #include "Placeads2.hrh" #include "Placeads2.pan" #include "Placeads2Application.h" #include "Placeads2AppUi.h" #include "Placeads2AppView.h" _LIT( KFileName, "C:\\private\\EDE5C37C\\Placeads2.txt" ); _LIT( KText, "Hello World!"); // ============================ MEMBER FUNCTIONS =============================== // ----------------------------------------------------------------------------- // CPlaceads2AppUi::ConstructL() // Symbian 2nd phase constructor can leave. // ----------------------------------------------------------------------------- // void CPlaceads2AppUi::ConstructL() { // Initialise app UI with standard value. BaseConstructL(CAknAppUi::EAknEnableSkin); // Create view object iAppView = CPlaceads2AppView::NewL(ClientRect()); //INNERACTIVE::BEGIN ibAdModuleInitialized = EFalse; ipExampleControl = NULL; cancelCount = 0; InitAdModule(); //INNERACTIVE::END AddToStackL(iAppView); } // ----------------------------------------------------------------------------- // CPlaceads2AppUi::CPlaceads2AppUi() // C++ default constructor can NOT contain any code, that might leave. // ----------------------------------------------------------------------------- // CPlaceads2AppUi::CPlaceads2AppUi() { // No implementation required } // ----------------------------------------------------------------------------- // CPlaceads2AppUi::~CPlaceads2AppUi() // Destructor. // ----------------------------------------------------------------------------- // CPlaceads2AppUi::~CPlaceads2AppUi() { if (iAppView) { delete iAppView; iAppView = NULL; } //INNERACTIVE::BEGIN // delete ad module if(ipInnerActiveMobileAdModule) delete ipInnerActiveMobileAdModule; //INNERACTIVE::END } // ----------------------------------------------------------------------------- // CPlaceads2AppUi::HandleCommandL() // Takes care of command handling. // ----------------------------------------------------------------------------- // void CPlaceads2AppUi::HandleCommandL(TInt aCommand) { switch (aCommand) { case EEikCmdExit: case EAknSoftkeyExit: Exit(); break; //INNERACTIVE::BEGIN case ECmdInitAdModule: { InitAdModule(); } break; case ECmdOpenAdDlg: { TInt dlgContainerType = KIaCustomDialogContainer; TInt dlgContainerId = KIaCustomDialogContainerId; TInt dlgSkipBtnId = ECmdAdDlg_btnSkip; TInt dlgOpenAdBtnId = ECmdAdDlg_btnOpenAd; TRAPD(err, ipInnerActiveMobileAdModule->OpenAdDialogL(R_AD_DIALOG, R_IA_SOFTKEYS_SKIP, dlgSkipBtnId, dlgOpenAdBtnId, dlgContainerType, dlgContainerId, 10)); #ifdef IA_TEST_MODE if(err) { TBuf<100> errBuf, errTitle; if(err == KErrNotReady) { errTitle.Copy(_L("Open Ad Dialog")); errBuf.Copy(_L("Ad data is not ready: processing Init/Reload request.")); } else { errTitle.Copy(_L("Open Ad Dialog")); errBuf.AppendFormat(_L("Error: %d"), err); } TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif } break; case ECmdOpenFsAdDlg: { TInt dlgContainerType = KIaFullScreenDialogContainer; TInt dlgContainerId = KIaFullScreenDialogContainerId; TInt dlgSkipBtnId = ECmdAdDlg_btnSkip; TInt dlgOpenAdBtnId = ECmdAdDlg_btnOpenAd; TRAPD(err, ipInnerActiveMobileAdModule->OpenAdDialogL(R_FS_AD_DIALOG, R_IA_SOFTKEYS_SKIP, dlgSkipBtnId, dlgOpenAdBtnId, dlgContainerType, dlgContainerId, 10)); #ifdef IA_TEST_MODE if(err) { TBuf<100> errBuf, errTitle; if(err == KErrNotReady) { errTitle.Copy(_L("Open full screen Ad Dialog")); errBuf.Copy(_L("Ad data is not ready: processing Init/Reload request.")); } else { errTitle.Copy(_L("Open full screen Ad Dialog")); errBuf.AppendFormat(_L("Error: %d"), err); } TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif } break; case ECmdReloadAd: { TRAPD(err, ipInnerActiveMobileAdModule->ReloadAdL()); #ifdef IA_TEST_MODE if(err) { TBuf<100> errBuf, errTitle; if(err == KErrInUse) { errTitle.Copy(_L("Reload Ad")); errBuf.Copy(_L("Cannot reload Ad: processing Init/Reload request.")); } else { errTitle.Copy(_L("Reload Ad")); errBuf.AppendFormat(_L("Error: %d"), err); } TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif } break; //INNERACTIVE::END case ECommand1: { // Load a string from the resource file and display it HBufC* textResource = StringLoader::LoadLC(R_COMMAND1_TEXT); CAknInformationNote* informationNote; informationNote = new (ELeave) CAknInformationNote; // Show the information Note with // textResource loaded with StringLoader. informationNote->ExecuteLD(*textResource); // Pop HBuf from CleanUpStack and Destroy it. CleanupStack::PopAndDestroy(textResource); } break; case ECommand2: { RFile rFile; //Open file where the stream text is User::LeaveIfError(rFile.Open(CCoeEnv::Static()->FsSession(), KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText)); CleanupClosePushL(rFile); // copy stream from file to RFileStream object RFileReadStream inputFileStream(rFile); CleanupClosePushL(inputFileStream); // HBufC descriptor is created from the RFileStream object. HBufC* fileData = HBufC::NewLC(inputFileStream, 32); CAknInformationNote* informationNote; informationNote = new (ELeave) CAknInformationNote; // Show the information Note informationNote->ExecuteLD(*fileData); // Pop loaded resources from the cleanup stack CleanupStack::PopAndDestroy(3); // filedata, inputFileStream, rFile } break; case EHelp: { CArrayFix* buf = CCoeAppUi::AppHelpContextL(); HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf); } break; case EAbout: { CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog(); dlg->PrepareLC(R_ABOUT_QUERY_DIALOG); HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE); dlg->QueryHeading()->SetTextL(*title); CleanupStack::PopAndDestroy(); //title HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT); dlg->SetMessageTextL(*msg); CleanupStack::PopAndDestroy(); //msg dlg->RunLD(); } break; default: Panic( EPlaceads2Ui); break; } } // ----------------------------------------------------------------------------- // Called by the framework when the application status pane // size is changed. Passes the new client rectangle to the // AppView // ----------------------------------------------------------------------------- // void CPlaceads2AppUi::HandleStatusPaneSizeChange() { iAppView->SetRect(ClientRect()); } CArrayFix* CPlaceads2AppUi::HelpContextL() const { #warning "Please see comment about help and UID3..." // Note: Help will not work if the application uid3 is not in the // protected range. The default uid3 range for projects created // from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so that they // can be self signed and installed on the device during testing. // Once you get your official uid3 from Symbian Ltd. and find/replace // all occurrences of uid3 in your project, the context help will // work. Alternatively, a patch now exists for the versions of // HTML help compiler in SDKs and can be found here along with an FAQ: // http://www3.symbian.com/faq.nsf/AllByDate/E9DF3257FD565A658025733900805EA2?OpenDocument CArrayFixFlat* array = new (ELeave) CArrayFixFlat< TCoeHelpContext> (1); CleanupStack::PushL(array); ///array->AppendL(TCoeHelpContext(KUidInnerActiveAddApp, KGeneral_Information)); CleanupStack::Pop(array); return array; } // End of File //INNERACTIVE::BEGIN void CPlaceads2AppUi::InitAdModule() { // Query for inneractive_created Application UID TBuf<256> buffInput, buffAppUid, buffPrompt; buffInput.Copy(_L("GlobalTakeoffInc_YuppTV_OVI")); buffAppUid.Copy(_L("GlobalTakeoffInc_YuppTV_OVI")); buffPrompt.Copy(_L("Application UID:")); CAknTextQueryDialog* inputQuery = CAknTextQueryDialog::NewL(buffInput); inputQuery->PrepareLC(R_TEXT_INPUT_DIALOG); inputQuery->SetPromptL(buffPrompt); TInt nRes = inputQuery->RunLD(); if(nRes != ECsCmdGd2) { buffAppUid.Copy(buffInput); } // Define APN UID - if the application uses network TUint32 apnUid = 0;//3-Winsock in emulator; // Define ad auto Reload period in seconds TInt nAutoReload = 30; // Create Ad module ipInnerActiveMobileAdModule = CInnerActiveMobileAd::NewL(*this, buffAppUid, apnUid, nAutoReload); /*//TEST TBuf<50> bufPo, bufEid, bufAge, bufGender, bufMn, bufKw, bufCat, bufLoc, bufLocGps, buftest; bufPo.Copy(_L("551")); bufEid.Copy(_L("testEid")); bufAge.Copy(_L("23")); bufGender.Copy(_L("female")); bufMn.Copy(_L("+12020000000")); bufKw.Copy(_L("testKeyword")); bufCat.Copy(_L("testCategory")); bufLoc.Copy(_L("Waverly Pl, West Village, New York, USA, Earth")); bufLocGps.Copy(_L("40.733275,-74.000956")); buftest.Copy(_L("true")); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_DistributionChannelPortal, bufPo); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_ExternalId, bufEid); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_Age, bufAge); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_Gender, bufGender); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_MobileNumber, bufMn); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_Keywords, bufKw); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_Category, bufCat); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_LocationString, bufLoc); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_LocationGps, bufLocGps); ipInnerActiveMobileAdModule->SetProtocolParamL(EIaProtocolParams_TestMode, buftest); //TEST*/ ipInnerActiveMobileAdModule->InitializeL(); ibAdModuleInitialized = ETrue; } void CPlaceads2AppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane) { if(aResourceId == R_MENU) { if(!ibAdModuleInitialized) { aMenuPane->SetItemDimmed(ECmdOpenAdDlg, ETrue); aMenuPane->SetItemDimmed(ECmdOpenFsAdDlg, ETrue); aMenuPane->SetItemDimmed(ECmdReloadAd, ETrue); } else aMenuPane->SetItemDimmed(ECmdInitAdModule, ETrue); } } void CPlaceads2AppUi::InnerActiveAdStateChanged( TInnerActiveAdObserverEvent aEvent, TInt aParam /*=KErrNone*/, const TDesC8& aData /*= _L8("")*/) { switch (aEvent) { case EIaaObserver_AdReady: { // Ad was successfully retrieved/reloaded if(!ipExampleControl) { TRAPD(err, ipExampleControl = ipInnerActiveMobileAdModule->GetAdControlL(ClientRect(), iAppView)); #ifdef IA_TEST_MODE if(err) { TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Get Ad Control")); errBuf.AppendFormat(_L("Error: %d"), err); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif iAppView->AddCustomControl(ipExampleControl); } else { TRAPD(err, ipInnerActiveMobileAdModule->UpdateAdControlL(ipExampleControl)); #ifdef IA_TEST_MODE if(err) { TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Update Ad Control")); errBuf.AppendFormat(_L("Error: %d"), err); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif iAppView->ReloadView(); } } break; case EIaaObserver_InitApnInProcess: { // Ad module APN selection process started } break; case EIaaObserver_InitAdInProcess: { // Ad module initialization started } break; case EIaaObserver_ReloadAdInProcess: { // Ad reload process started } break; case EIaaObserver_AdImageCorrupted: #ifdef IA_TEST_MODE { // Ad image is corrupted TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Ad Module Error!")); errBuf.Copy(_L("Ad Image is NULL or corrupted.")); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif break; case EIaaObserver_LogoImageCorrupted: #ifdef IA_TEST_MODE { // InnerActive logo image is corrupted TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Ad Module Error!")); errBuf.Copy(_L("Logo Image is NULL or corrupted.")); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif break; case EIaaObserver_BadAdXmlResponse: #ifdef IA_TEST_MODE { // Ad XML is corrupted TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Ad Module Error!")); errBuf.Copy(_L("Xml Response/Ad Image - NULL or corrupted.")); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif break; case EIaaObserver_ApnSelectionCanceled: { // User pressed "Cancel" on APN_Selection_Dialog // Ad module performed reset Selected/Provided APN UID // Action: Re-Init Ad module (APN selection dialog will pop up) //ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_APN_SELECTION_DIALOG); // OR // Action: Re-Init Ad module with some other defined APN (Here, for example, Winsock APN UID in Emulator). //ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_NEW_APN, 3); // 3 - Winsock APN in Emulator // Ask for APN only 3 times if (cancelCount < 3) { cancelCount++; ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_APN_SELECTION_DIALOG); } else { // Connection has been canceled TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Internet connection necessary for this app.")); errBuf.Copy(_L("Please configure the connection, and try again.")); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); // Exit the application Exit(); } } break; case EIaaObserver_ApnSelectionError: { // Connection via selected/provided APN failed // Ad module performed reset Selected/Provided APN UID // Action: Re-Init Ad module (APN selection dialog will pop up) //ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_APN_SELECTION_DIALOG); // OR // Action: Re-Init Ad module with some other defined APN (Here, for example, Winsock APN UID in Emulator). //ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_NEW_APN, 3); // 3 - Winsock APN in Emulator ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_APN_SELECTION_DIALOG); } break; case EIaaObserver_ServerTimeOut: #ifdef IA_TEST_MODE { // Request to Ad server timed out TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Ad Module Error!")); errBuf.Copy(_L("Request to server timed out.")); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif break; case EIaaObserver_ServerError: { // Some communication/server error, check aParam for error code and aData for description (if applicable) // For example: KerrNotReady - HTTP request failed due to lost socket connection. if(aParam == KErrNotReady) { // Re-Init Ad module with new APN in case of (roaming)/(client side APN handling logic)/(etc.) //ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_NEW_APN, 3); // 3 - Winsock in Emulator //OR // Re-Init ad data with currently selected APN //ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_CURRENT_APN); ipInnerActiveMobileAdModule->ReconnectL(EIAAPNMODE_CURRENT_APN); } #ifdef IA_TEST_MODE else { TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Ad Module Error!")); errBuf.AppendFormat(_L("Server Error: [%d]"), aParam); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif } break; case EIaaObserver_GeneralError: #ifdef IA_TEST_MODE { // General system wide error TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Ad Module Error!")); errBuf.AppendFormat(_L("General Error: [%d]"), aParam); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); } #endif break; case EIaaObserver_SessionFailed: { // Most common error; no access point configured, and session creation // leaves with KErrNotFound. TBuf<100> errBuf, errTitle; errTitle.Copy(_L("Internet connection failed.")); errBuf.Copy(_L("Is access point configured?")); TRAPD(err, CEikonEnv::Static()->InfoWinL(errTitle, errBuf)); // Exit the application Exit(); } break; case EIaaObserver_GetButtonInProcess: break; default: break; } }