networkingutils/nameresolverutility/src/nslookup.cpp
branchRCL_3
changeset 10 4ca382093dae
parent 5 6beaa9cf4752
child 11 493058e57c8c
equal deleted inserted replaced
5:6beaa9cf4752 10:4ca382093dae
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // nslookup.cpp - nslookup client main module
       
    15 //
       
    16 
       
    17 #include <coemain.h>
       
    18 #include <eikenv.h>
       
    19 #include <eikdef.h>
       
    20 #include <eikappui.h>
       
    21 #include <eikapp.h>
       
    22 #include <techview/eikdialg.h>
       
    23 #include <eikdoc.h>
       
    24 #include <techview/eikchkbx.h>
       
    25 #include <techview/eiktbar.h>
       
    26 #include <techview/eikedwin.h>
       
    27 
       
    28 #if EPOC_SDK >= 0x06000000
       
    29 #   include <techview/eikon.hrh>
       
    30 #else
       
    31 #   include <eikdialg.hrh>
       
    32 #   include <eikedwin.hrh>
       
    33 #   include <eikcmds.hrh>
       
    34 #endif
       
    35 
       
    36 #ifdef MAKE_EXE_APPLICATION
       
    37 #include <eikstart.h>
       
    38 #endif
       
    39 
       
    40 #include <nslookup.rsg>
       
    41 #include "engine.h"
       
    42 #include "nslookup.hrh"
       
    43 #include "nslookup.h"
       
    44 
       
    45 #ifdef CALYPSO
       
    46 #include <AknTextSettingPage.h>
       
    47 #endif
       
    48 
       
    49 // 
       
    50 // CConsoleControl
       
    51 //
       
    52 
       
    53 
       
    54 CConsoleControl::~CConsoleControl()
       
    55 	{
       
    56     delete iConsole;
       
    57 	}
       
    58 
       
    59 void CConsoleControl::ConstructL(const TPoint& aTopLeft, const TSize& aSize, TInt aFlags)
       
    60     {
       
    61     TRect rect(aTopLeft,aTopLeft + aSize.AsPoint());
       
    62 #if EPOC_SDK >= 0x06000000
       
    63     SetRect(rect);
       
    64 #else
       
    65     SetRectL(rect);
       
    66 #endif
       
    67     iConsole=new(ELeave) CEikConsoleScreen;
       
    68     iConsole->ConstructL(_L("TEST"),aTopLeft,aSize,aFlags,EEikConsWinInPixels);
       
    69     iConsole->SetHistorySizeL(200,0);
       
    70     iHistory=200;
       
    71     }
       
    72 
       
    73 void CConsoleControl::ActivateL()
       
    74     {
       
    75     CCoeControl::ActivateL();
       
    76     iConsole->SetKeepCursorInSight(TRUE);
       
    77     iConsole->DrawCursor();
       
    78     iConsole->SetAtt(ATT_NORMAL);
       
    79     }
       
    80 
       
    81 
       
    82 void CConsoleControl::HandleCommandL(TInt /* aCommand */)
       
    83 	{
       
    84 	}
       
    85 
       
    86 void CConsoleControl::FocusChanged(TDrawNow aDrawNow)
       
    87 	{
       
    88     iConsole->ConsoleControl()->SetFocus(IsFocused(), aDrawNow); 
       
    89 	}
       
    90 
       
    91 
       
    92 void CConsoleControl::SetScrollBarVisibilityL(CEikScrollBarFrame::TScrollBarVisibility aHBarVisibility, CEikScrollBarFrame::TScrollBarVisibility aVBarVisibility)
       
    93 	{
       
    94     iConsole->SetScrollBarVisibilityL(aHBarVisibility,aVBarVisibility);
       
    95     iConsole->ConsoleControl()->UpdateArea();
       
    96     iConsole->UpdateScrollBars();
       
    97     iConsole->ConsoleControl()->UpdateArea();
       
    98 	}
       
    99 
       
   100 
       
   101 void CConsoleControl::DrawCursor()
       
   102 	{
       
   103     iConsole->DrawCursor();
       
   104 	}
       
   105 
       
   106 
       
   107 void CConsoleControl::Write(const TDesC &aMsg)
       
   108 	{
       
   109     iConsole->Write(aMsg);
       
   110     iConsole->FlushChars();
       
   111 	}
       
   112 
       
   113 
       
   114 
       
   115 CEikConsoleControl *CConsoleControl::ConsoleControl() const
       
   116 	{
       
   117     return iConsole->ConsoleControl();
       
   118 	}
       
   119 
       
   120 TBool CConsoleControl::UpdateScrollBars()
       
   121 	{
       
   122     return iConsole->UpdateScrollBars();
       
   123 	}
       
   124 
       
   125 void CConsoleControl::ClearScreen()
       
   126 	{
       
   127     iConsole->ClearScreen();
       
   128 	}
       
   129 
       
   130 
       
   131 void CConsoleControl::Redraw(const TRect &aRect)
       
   132 	{
       
   133 	iConsole->Redraw(aRect);
       
   134 	}
       
   135 
       
   136 void CConsoleControl::Lf()
       
   137 	{
       
   138     iConsole->Lf();
       
   139 	}
       
   140 
       
   141 
       
   142 TSize CConsoleControl::ScreenSize() const
       
   143 	{
       
   144     return iConsole->ScreenSize();
       
   145 	}
       
   146 
       
   147 
       
   148 CNslookupView::CNslookupView(CNslookup *aModel)
       
   149 	{
       
   150     iModel = aModel;
       
   151 	}
       
   152 
       
   153 void CNslookupView::ConstructL(const TRect& aRect)
       
   154 {
       
   155     CreateWindowL();
       
   156     Window().SetShadowDisabled(ETrue);
       
   157     iContext=this;
       
   158     iBrushStyle=CGraphicsContext::ESolidBrush;
       
   159     iBrushColor=KRgbWhite;
       
   160 #if EPOC_SDK >= 0x06000000
       
   161     SetRect(aRect);
       
   162 #else
       
   163     SetRectL(aRect);
       
   164 #endif
       
   165     
       
   166     // Create its only component, a CNslookupContainer
       
   167     
       
   168     iContainer = new(ELeave) CNslookupContainer(iModel);
       
   169     iContainer->SetContainerWindowL(*this);
       
   170     TRect containerRect = Rect();
       
   171     iContainer->ConstructL(containerRect);
       
   172 
       
   173     ActivateL();
       
   174     DrawNow();
       
   175 }
       
   176 
       
   177 CNslookupView::~CNslookupView()
       
   178     {
       
   179 
       
   180     delete iContainer;
       
   181     }
       
   182     
       
   183 TInt CNslookupView::CountComponentControls() const
       
   184     {   
       
   185     return 1; //Just the container
       
   186     }
       
   187 
       
   188 CCoeControl* CNslookupView::ComponentControl(TInt /*aIndex*/) const
       
   189     {
       
   190     return iContainer;
       
   191     }
       
   192 
       
   193 
       
   194 void CNslookupView::ResetScreen()
       
   195 {
       
   196     iContainer->ResetScreen();
       
   197 }
       
   198 
       
   199 
       
   200 TKeyResponse CNslookupView::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
       
   201 {
       
   202     return EKeyWasNotConsumed;
       
   203 }
       
   204 
       
   205 void CNslookupView::Draw(const TRect& /*aRect*/) const
       
   206     {
       
   207 
       
   208     CWindowGc& gc = SystemGc();
       
   209     gc.SetPenStyle(CGraphicsContext::ENullPen);
       
   210     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   211     gc.DrawRect(Rect());
       
   212 
       
   213     }
       
   214 
       
   215 
       
   216 //
       
   217 // CNslookupcontainer
       
   218 //
       
   219 const TInt KLabelHeight=25;
       
   220 
       
   221 
       
   222  // Construction
       
   223 CNslookupContainer::CNslookupContainer(CNslookup* aModel)
       
   224 	{
       
   225     iModel = aModel;
       
   226 	}
       
   227 
       
   228 
       
   229 // Destruction
       
   230 CNslookupContainer::~CNslookupContainer()
       
   231 {
       
   232     delete iLabel;
       
   233     delete iLabel2;
       
   234     delete iConsole;
       
   235 }
       
   236 
       
   237 void CNslookupContainer::ConstructL(const TRect& aRect)
       
   238 {
       
   239     iModel->SetConsole(this);
       
   240 
       
   241 #if EPOC_SDK >= 0x06000000
       
   242     SetRect(aRect);
       
   243 #else
       
   244     SetRectL(aRect);
       
   245 #endif
       
   246 
       
   247     TRect rect=Rect();
       
   248     rect.iTl.iY += KLabelHeight;    // make way for top label
       
   249     rect.iBr.iY -= KLabelHeight;    // make way for bottom label
       
   250 
       
   251     CreateConsoleL(rect);
       
   252 
       
   253     //Bottom label
       
   254     iLabel=new (ELeave) CEikLabel;
       
   255     rect=Rect();
       
   256     rect.iTl.iY=rect.iBr.iY-KLabelHeight; // make it bottom 20 pixels
       
   257     iLabel->SetContainerWindowL(*this);
       
   258 #if EPOC_SDK >= 0x06000000
       
   259     iLabel->SetRect(rect);
       
   260 #else
       
   261     iLabel->SetRectL(rect);
       
   262 #endif
       
   263     iLabel->SetAlignment(EHLeftVCenter); // center text
       
   264     iLabel->SetBufferReserveLengthL(500); // nice long buffer
       
   265     iLabel->SetTextL(_L("ok"));			// Label needs to have some content to prevent panics..
       
   266     //Top label
       
   267     iLabel2=new (ELeave) CEikLabel;
       
   268     rect=Rect();
       
   269     rect.iBr.iY=rect.iTl.iY+KLabelHeight; // make it top 20 pixels
       
   270     iLabel2->SetContainerWindowL(*this);
       
   271 #if EPOC_SDK >= 0x06000000
       
   272     iLabel2->SetRect(rect);
       
   273 #else
       
   274     iLabel2->SetRectL(rect);
       
   275 #endif
       
   276     iLabel2->SetAlignment(EHLeftVCenter); // center text
       
   277     iLabel2->SetBufferReserveLengthL(500); // nice long buffer
       
   278     WriteHostL(_L("<None>"));
       
   279     ActivateL();
       
   280 }
       
   281 
       
   282 
       
   283 void CNslookupContainer::CreateConsoleL(const TRect& aRect)
       
   284 {
       
   285     iConsole = new(ELeave) CConsoleControl;
       
   286 #if defined(CRYSTAL)  //This is a patch to put the console in the right place. 
       
   287                 //For some unknown reason appears displaced.
       
   288     aRect.iBr.iX += 92;
       
   289     aRect.iTl.iX += 92;
       
   290     iConsole->ConstructL(aRect.iTl, aRect.Size(), CEikConsoleScreen::ENoInitialCursor);
       
   291 #elif defined(CALYPSO)
       
   292     TSize size;
       
   293     size.iHeight = aRect.iBr.iY - aRect.iTl.iY;
       
   294     size.iWidth = aRect.iBr.iX - aRect.iTl.iX - 10; // -10 to leave some space on the right
       
   295                                                     // (based on trial and error)
       
   296     TPoint position;
       
   297     position.iY = 70; // To skip the status pane and host name field (based on trial and error)
       
   298     position.iX = 5;  // 5 to leave some space on the left (based on trial and error)
       
   299 
       
   300     iConsole->ConstructL(position, size, CEikConsoleScreen::ENoInitialCursor);
       
   301 #else
       
   302     iConsole->ConstructL(aRect.iTl, aRect.Size(), CEikConsoleScreen::ENoInitialCursor);    
       
   303 #endif
       
   304     
       
   305     iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);
       
   306 }
       
   307 
       
   308 void CNslookupContainer::ResetScreen()
       
   309 	{
       
   310     iConsole->ClearScreen();
       
   311 	}
       
   312 
       
   313 void CNslookupContainer::WriteHostL(const TDesC& aHostname)
       
   314 {
       
   315     TBuf<100> aux;
       
   316     
       
   317     aux.Append(aHostname);
       
   318 
       
   319     iLabel2->SetTextL(aux);
       
   320     iLabel2->DrawNow();
       
   321 }
       
   322 
       
   323 
       
   324 void CNslookupContainer::WriteLine(const TDesC& abuf)
       
   325 	{
       
   326     iConsole->Write(abuf);
       
   327 	}
       
   328 
       
   329 TKeyResponse CNslookupContainer::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
       
   330 	{
       
   331     return EKeyWasNotConsumed;
       
   332 	}
       
   333 
       
   334 // Virtual, defined by CCoeControl; replaces the default implementation
       
   335 // provided by CCoeControl.
       
   336 void CNslookupContainer::Draw(const TRect& aRect) const
       
   337 {
       
   338     CWindowGc& gc = SystemGc();
       
   339     gc.SetClippingRect(aRect);
       
   340     gc.DrawRect(Rect());
       
   341 
       
   342 }
       
   343     
       
   344 // Virtual, defined by CCoeControl; replaces the default implementation
       
   345 // provided by CCoeControl. 
       
   346 TInt CNslookupContainer::CountComponentControls() const
       
   347 {
       
   348     return 3;
       
   349 }
       
   350 
       
   351 // Virtual, defined by CCoeControl; replaces the default implementation
       
   352 // provided by CCoeControl.
       
   353 CCoeControl* CNslookupContainer::ComponentControl(TInt aIndex) const
       
   354 {
       
   355     switch (aIndex)
       
   356     {
       
   357     case 0: return iLabel;
       
   358     case 1: return iLabel2;
       
   359     case 2: return iConsole;
       
   360     //case 2: return iEdit;
       
   361 	default: break;
       
   362     }
       
   363 
       
   364     return NULL;
       
   365 }
       
   366 
       
   367 // Defined as pure virtual by the mixin class MCoeControlObserver 
       
   368 // inherited by CCoeControl. An empty implementation provided by 
       
   369 // this class (its containees do not report events).
       
   370 void CNslookupContainer::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   371 {
       
   372 
       
   373 
       
   374 }
       
   375 
       
   376 
       
   377 //
       
   378 // CHostNameDialog
       
   379 //
       
   380 #ifdef CALYPSO
       
   381 CHostNameDialog::CHostNameDialog(TDes& aHostname) : CAknTextQueryDialog(aHostname)
       
   382 {
       
   383 }
       
   384 #else
       
   385 CHostNameDialog::CHostNameDialog(CNslookup *aModel):CEikDialog()
       
   386 {
       
   387     iModel=aModel;
       
   388 }
       
   389 #endif
       
   390 
       
   391 // Checks if data entered by user is correct
       
   392 // returns ETrue to exit dialog anf EFalse to not exit it (no name entered)
       
   393 
       
   394 #ifdef CALYPSO
       
   395 TBool CHostNameDialog::OkToExitL(TInt aButton)
       
   396 {   
       
   397     return CAknTextQueryDialog::OkToExitL(aButton);
       
   398 }
       
   399 #else
       
   400 TBool CHostNameDialog::OkToExitL(TInt aButton)
       
   401 {   
       
   402 	iModel->iQueryType = ChoiceListCurrentItem(ENslookupQueryType);
       
   403  	iModel->iShowSource = (CheckBoxState(ENslookupShowSource)== CEikButtonBase::ESet);
       
   404 
       
   405     TBuf<KHostNameLimit> hostname(_L(""));
       
   406     if (aButton==EEikBidCancel) //CANCEL BUTTON
       
   407     {
       
   408         iOKPressed=EFalse;
       
   409         return ETrue;
       
   410     }
       
   411     
       
   412     GetEdwinText(hostname,ENslookupHostName);
       
   413     
       
   414     if (hostname.Length()!=0)
       
   415     {
       
   416         iModel->SetHostName(hostname);
       
   417         return ETrue;
       
   418     }
       
   419     else
       
   420         return EFalse;  //If no hostname specified can't continue
       
   421     
       
   422 }
       
   423 #endif // CALYPSO
       
   424 
       
   425 //To initialize dialog data
       
   426 #ifdef CALYPSO
       
   427 void CHostNameDialog::PreLayoutDynInitL()
       
   428 {
       
   429     CAknTextQueryDialog::PreLayoutDynInitL();
       
   430 }
       
   431 #else
       
   432 void CHostNameDialog::PreLayoutDynInitL()
       
   433 {
       
   434 	SetCheckBoxState(ENslookupShowSource, iModel->iShowSource  ? CEikButtonBase::ESet : CEikButtonBase::EClear);
       
   435 	SetChoiceListCurrentItem(ENslookupQueryType, iModel->iQueryType);
       
   436     SetEdwinTextL(ENslookupHostName,iModel->GetHostName());
       
   437 }
       
   438 #endif
       
   439 
       
   440 
       
   441 
       
   442 //
       
   443 // CNslookupAppUi
       
   444 //
       
   445 
       
   446 void CNslookupAppUi::ConstructL()
       
   447 {
       
   448     BaseConstructL();
       
   449     
       
   450     InitModelL();
       
   451     iAppView=new(ELeave) CNslookupView(iModel);
       
   452     iAppView->ConstructL(ClientRect());
       
   453 
       
   454 #if EPOC_SDK < 0x06000000
       
   455     //Just to watch the name of the file on the top of the toolbar
       
   456     CEikFileNameLabel* pingLabel=(CEikFileNameLabel*)iToolBar->ControlById(ENslookupCmdFileName);
       
   457     pingLabel->UpdateL();
       
   458 #endif
       
   459 
       
   460 #ifndef CALYPSO
       
   461     
       
   462     // add app view to stack; enables key event handling.
       
   463     AddToStackL(iAppView);
       
   464     
       
   465 #else // if CALYPSO defined
       
   466     
       
   467     AppViewToStackL();
       
   468 
       
   469     iAppView->ActivateL();
       
   470 
       
   471     iSettingView = new (ELeave) CSettingView(iModel);
       
   472     iSettingView->ConstructL(ClientRect());
       
   473     iSettingView->SetComponentsToInheritVisibility( ETrue );
       
   474 
       
   475     SettingViewToStackL();
       
   476 
       
   477     iSettingView->ActivateL();
       
   478 
       
   479     ShowAppViewL();
       
   480     
       
   481 #endif
       
   482 }
       
   483 
       
   484 #ifdef CALYPSO
       
   485 
       
   486 void CNslookupAppUi::ShowAppViewL()
       
   487 {
       
   488     iSettingView->MakeVisible( EFalse );
       
   489     SettingViewFromStack();
       
   490     AppViewToStackL();
       
   491     iAppView->MakeVisible( ETrue );
       
   492     iAppView->DrawNow();
       
   493 
       
   494     CEikButtonGroupContainer *cba = ((CAknAppUi*)CEikonEnv::Static()->EikAppUi())->Cba();
       
   495     cba->SetCommandSetL(R_NSLOOKUP_CBA);
       
   496     cba->DrawDeferred();
       
   497 
       
   498     // Make sure that setting view's scroll indicators are not shown in the app view
       
   499     iSettingView->ListBox()->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff);
       
   500     iSettingView->ListBox()->UpdateScrollBarsL();
       
   501 }
       
   502 
       
   503 void CNslookupAppUi::ShowSettingViewL()
       
   504 {
       
   505     iAppView->MakeVisible( EFalse );
       
   506     AppViewFromStack();
       
   507     SettingViewToStackL();
       
   508     iSettingView->MakeVisible( ETrue );
       
   509     iSettingView->DrawNow();
       
   510 
       
   511     CEikButtonGroupContainer *cba = ((CAknAppUi*)CEikonEnv::Static()->EikAppUi())->Cba();
       
   512     cba->SetCommandSetL(R_SETTINGS_CBA);
       
   513     cba->DrawDeferred();
       
   514 
       
   515     // Make sure that scroll bars are shown if needed
       
   516     iSettingView->ListBox()->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
       
   517     iSettingView->ListBox()->UpdateScrollBarsL();
       
   518 }
       
   519 
       
   520 void CNslookupAppUi::AppViewToStackL()
       
   521 {
       
   522     if (!iAppViewOnStack)
       
   523     {
       
   524         AddToStackL(iAppView);
       
   525         iAppViewOnStack = ETrue;
       
   526     }
       
   527 }
       
   528 
       
   529 void CNslookupAppUi::SettingViewToStackL()
       
   530 {
       
   531     if (!iSettingViewOnStack)
       
   532     {
       
   533         AddToStackL(iSettingView);
       
   534         iSettingViewOnStack = ETrue;
       
   535     }
       
   536 }
       
   537 
       
   538 void CNslookupAppUi::AppViewFromStack()
       
   539 {
       
   540     if (iAppViewOnStack) 
       
   541     {
       
   542         RemoveFromStack(iAppView);
       
   543         iAppViewOnStack = EFalse;
       
   544     }
       
   545 }
       
   546 
       
   547 void CNslookupAppUi::SettingViewFromStack()
       
   548 {
       
   549     if (iSettingViewOnStack)
       
   550     {
       
   551         RemoveFromStack(iSettingView);
       
   552         iSettingViewOnStack = EFalse;
       
   553     }
       
   554 }
       
   555 
       
   556 #endif // #ifdef CALYPSO
       
   557 
       
   558 void CNslookupAppUi::InitModelL()
       
   559 {
       
   560     TPreferences param;
       
   561 
       
   562     RestorePreferencesL(param); //Reads the .ini file
       
   563 
       
   564     iModel= new (ELeave) CNslookup();
       
   565     iModel->ConstructL(param);
       
   566 }
       
   567 
       
   568 void CNslookupAppUi::HandleCommandL(TInt aCommand)
       
   569 {
       
   570     TPreferences param;
       
   571     
       
   572     switch (aCommand)
       
   573     {
       
   574     case ENslookupStart:
       
   575         if (!(iModel->IsRunning()))
       
   576             if (CreateHostNameDialogL())
       
   577                 iModel->BeginL();
       
   578         break;
       
   579 
       
   580     case ENslookupStop: //Stop ping
       
   581         if (iModel->IsRunning())
       
   582             iModel->EndNslookup();
       
   583         break;
       
   584 
       
   585     case ENslookupReset:
       
   586         iAppView->ResetScreen();
       
   587         break;
       
   588 
       
   589     case ENslookupAbout:
       
   590         CreateAboutDialogL();
       
   591         break;
       
   592 
       
   593     case EEikCmdExit:
       
   594         if (iModel->IsRunning())
       
   595             iModel->EndNslookup();
       
   596         iModel->GetPreferences(param);
       
   597         StorePreferencesL(param);
       
   598 #ifdef CALYPSO
       
   599         AppViewFromStack();
       
   600         SettingViewFromStack();
       
   601 #endif        
       
   602         Exit();
       
   603         return;
       
   604 
       
   605 #ifdef CALYPSO
       
   606         
       
   607     case ENslookupSave:
       
   608         // Try to save settings data
       
   609         if ( iSettingView->SaveSettingsL() )
       
   610         {
       
   611             // Switch back to the normal view
       
   612             ShowAppViewL();
       
   613         }
       
   614         break;
       
   615 
       
   616     case ENslookupCancel:
       
   617         // Simply switch back to the normal view
       
   618         ShowAppViewL();
       
   619         break;
       
   620 
       
   621 #endif // #ifdef CALYPSO
       
   622 
       
   623 	default:
       
   624 		break;
       
   625     }
       
   626 }
       
   627 
       
   628     
       
   629 // Launches a dialog to show an about box
       
   630 void CNslookupAppUi::CreateAboutDialogL() const
       
   631     {
       
   632     CEikDialog* dialog = new (ELeave) CEikDialog();
       
   633     dialog->ExecuteLD(R_NSLOOKUP_ABOUT);    //Final D means the dialog is destructed by itself
       
   634     }
       
   635 
       
   636 
       
   637 //Launches a dialog to specify a hostname and returns if Ok has been pressed to
       
   638 //
       
   639 #ifdef CALYPSO
       
   640 TBool CNslookupAppUi::CreateHostNameDialogL()
       
   641 {
       
   642     TBuf<KHostNameLimit> hostname;
       
   643 
       
   644     hostname.Copy(*(iModel->GetHostName()));
       
   645 
       
   646     CAknTextQueryDialog* dialog = new (ELeave) CHostNameDialog(hostname);
       
   647 
       
   648     TInt button = dialog->ExecuteLD(R_NSLOOKUP_HOSTNAME_AVKON);
       
   649 
       
   650     if ((button == EAknSoftkeyOk) && (hostname.Length() != 0))
       
   651     {
       
   652         iModel->SetHostName(hostname);
       
   653         return ETrue;
       
   654     }
       
   655     else
       
   656     {
       
   657         return EFalse;
       
   658     }
       
   659 }
       
   660 #else
       
   661 TBool CNslookupAppUi::CreateHostNameDialogL()
       
   662     {
       
   663     CEikDialog* dialog = new (ELeave) CHostNameDialog(iModel);
       
   664     TInt button=dialog->ExecuteLD(R_NSLOOKUP_HOSTNAME); //Final D means the dialog is destructed by itself
       
   665     return (button==EEikBidOk); // If button is CANCEL then the ping is not executed
       
   666     }
       
   667 #endif // CALYPSO
       
   668 
       
   669 void CNslookupAppUi::RestorePreferencesL(TPreferences& aPreferences) const
       
   670 {
       
   671 	CNslookup::DefaultPreferences(aPreferences);
       
   672 }
       
   673 
       
   674 
       
   675 void CNslookupAppUi::StorePreferencesL(const TPreferences & /*aPreferences*/) const
       
   676 {
       
   677 	// not supported
       
   678 }
       
   679 
       
   680 
       
   681 
       
   682 CNslookupAppUi::~CNslookupAppUi()
       
   683     {
       
   684 #ifndef CALYPSO
       
   685 	RemoveFromStack(iAppView);
       
   686 #endif
       
   687     delete iAppView;
       
   688 #ifdef CALYPSO
       
   689     delete iSettingView;
       
   690 #endif
       
   691     delete iModel;
       
   692     }
       
   693 
       
   694 //
       
   695 // CNslookupDocument
       
   696 //
       
   697 
       
   698 CNslookupDocument::CNslookupDocument(CEikApplication& aApp)
       
   699         : CEikDocument(aApp)
       
   700     {
       
   701     }
       
   702 
       
   703 CEikAppUi* CNslookupDocument::CreateAppUiL()
       
   704     {
       
   705     return(new(ELeave) CNslookupAppUi);
       
   706     }
       
   707 
       
   708 //
       
   709 // CNslookupApplication
       
   710 //
       
   711 
       
   712 TUid CNslookupApplication::AppDllUid() const
       
   713     {
       
   714     return KUidNslookupApp;
       
   715     }
       
   716 
       
   717 
       
   718 CApaDocument* CNslookupApplication::CreateDocumentL()
       
   719     {
       
   720     return new(ELeave) CNslookupDocument(*this);
       
   721     }
       
   722 
       
   723 //
       
   724 // EXPORTed functions
       
   725 //
       
   726 
       
   727 EXPORT_C CApaApplication* NewApplication()
       
   728     {
       
   729     return new CNslookupApplication;
       
   730     }
       
   731 
       
   732 
       
   733 #ifdef MAKE_EXE_APPLICATION
       
   734 
       
   735 GLDEF_C TInt E32Main()
       
   736 	{
       
   737 	return EikStart::RunApplication(NewApplication);
       
   738 	}
       
   739 
       
   740 #else
       
   741 
       
   742 
       
   743 #endif // MAKE_EXE_APPLICATION
       
   744 
       
   745 #ifdef CALYPSO
       
   746 
       
   747 //------------------------------------------------------------------
       
   748 // CNslookupBinaryPopupSettingItem
       
   749 //
       
   750 // NOTE. This class is implemented only to circumvent
       
   751 // a bug (?) in CAknBinaryPopupSettingItem::Load
       
   752 //------------------------------------------------------------------
       
   753 
       
   754 CNslookupBinaryPopupSettingItem::CNslookupBinaryPopupSettingItem( TInt aIdentifier, TBool& aBinaryValue ) :
       
   755    CAknBinaryPopupSettingItem( aIdentifier, aBinaryValue )
       
   756 	{
       
   757 	}
       
   758 
       
   759 void CNslookupBinaryPopupSettingItem::LoadL()
       
   760 	{
       
   761     // Call CAknEnumeratedTextPopupSettingItem::LoadL to copy
       
   762     // the external boolean value to an internal value
       
   763     // NOTE. CAknBinaryPopupSettingItem::LoadL must NOT be called
       
   764     CAknEnumeratedTextPopupSettingItem::LoadL();
       
   765 	}
       
   766 
       
   767 //-----------------------------------------------------------------
       
   768 // CNslookupTextSettingItem
       
   769 //
       
   770 // NOTE. This is a re-implementation/copy of CAknTextSettingItem
       
   771 // (the only difference is in the LoadL method) due to a bug/
       
   772 // feature in CAknTextSettingItem::LoadL()
       
   773 //-----------------------------------------------------------------
       
   774 
       
   775 CNslookupTextSettingItem::CNslookupTextSettingItem( TInt aIdentifier, TDes& aText ) : 
       
   776    CAknSettingItem(aIdentifier), iExternalText( aText ), iInternalTextPtr(0,0)
       
   777 	{
       
   778 	}
       
   779 
       
   780 CNslookupTextSettingItem::~CNslookupTextSettingItem()
       
   781 	{
       
   782     delete iInternalText;
       
   783 	}
       
   784 
       
   785 void CNslookupTextSettingItem::StoreL()
       
   786 	{
       
   787     // Copy the internal to the external
       
   788     iExternalText.Copy(iInternalText->Des() );
       
   789 	}
       
   790 
       
   791 // NOTE. This is the only method that has changed from CAknTextSettingItem
       
   792 void CNslookupTextSettingItem::LoadL()
       
   793 	{
       
   794     delete iInternalText;
       
   795     iInternalText = 0;
       
   796     // NOTE. The difference is below
       
   797     // OLD CODE:
       
   798     // iInternalText = iExternalText.AllocL();
       
   799     // END OF OLD CODE
       
   800     // NEW CODE:
       
   801     iInternalText = HBufC::NewL( iExternalText.MaxLength() );
       
   802     TPtr ptrText = iInternalText->Des();
       
   803     ptrText.Copy( iExternalText );
       
   804     // END OF NEW CODE
       
   805     // Use Set so that the whole TPtr is just overwritten - and gets a new buffer 
       
   806     iInternalTextPtr.Set(iInternalText->Des() );
       
   807 	}
       
   808 
       
   809 const TDesC& CNslookupTextSettingItem::SettingTextL()
       
   810 {
       
   811     return *iInternalText;
       
   812 }
       
   813 
       
   814 void CNslookupTextSettingItem::EditItemL( TBool /* aCalledFromMenu */)
       
   815 	{
       
   816     CAknSettingPage* dlg = new( ELeave )CAknTextSettingPage( SettingPageResourceId(), iInternalTextPtr, 0 );
       
   817     SetSettingPage( dlg );
       
   818     SettingPage()->SetSettingPageObserver(this);
       
   819     SetUpStandardSettingPageL();
       
   820     SettingPage()->ExecuteLD(CAknSettingPage::EUpdateWhenChanged);
       
   821 	}
       
   822 
       
   823 TPtr& CNslookupTextSettingItem::InternalTextPtr()
       
   824 {
       
   825     return iInternalTextPtr;
       
   826 }
       
   827 
       
   828 TPtrC CNslookupTextSettingItem::ExternalText()
       
   829 {
       
   830     return (TPtrC)(iExternalText);
       
   831 }
       
   832 
       
   833 void CNslookupTextSettingItem::SetExternalText( TDesC& aNewExternalText )
       
   834 {
       
   835     iExternalText.Copy( aNewExternalText );
       
   836 }
       
   837 
       
   838 //-----------------------------------------------------------------
       
   839 // CSettingView
       
   840 //-----------------------------------------------------------------
       
   841 
       
   842 void CSettingView::ConstructL(const TRect& /*aRect*/)
       
   843 {
       
   844     // Copy data from the model to member variables
       
   845 
       
   846     iLimitPacketCount = iModel->iPackLimit ? ETrue : EFalse;
       
   847     iMaxPacketCount.Num( iModel->iTotalPackets );
       
   848     iPacketDataSize.Num( iModel->iPacketDataSize );
       
   849     iWaitTime.Num( iModel->iSecWait );
       
   850     iLastWaitTime.Num( iModel->iLastSecWait );
       
   851 
       
   852     iPattern.Copy( iModel->iPattern );
       
   853     iQuiet = iModel->iQuiet ? ETrue : EFalse;
       
   854     iVerbose = iModel->iVerbose ? ETrue : EFalse;
       
   855     iDebug = iModel->iDebug ? ETrue : EFalse;
       
   856 
       
   857     CAknSettingItemList::ConstructFromResourceL( R_NSLOOKUP_SETTINGS );
       
   858 }
       
   859 
       
   860 CSettingView::CSettingView(CNslookup *aModel)
       
   861 	{
       
   862     iModel = aModel;
       
   863 	}
       
   864 
       
   865 CSettingView::~CSettingView()
       
   866 	{
       
   867 	}
       
   868 
       
   869 void CSettingView::ProcessCommandL(TInt /*aCommand*/)
       
   870 	{
       
   871 	}
       
   872 
       
   873 CAknSettingItem* CSettingView::CreateSettingItemL( TInt identifier )
       
   874 	{
       
   875     CAknSettingItem* settingItem;
       
   876 
       
   877     switch (identifier)
       
   878     {
       
   879         case 1:
       
   880             settingItem = new (ELeave) CNslookupBinaryPopupSettingItem( identifier, iLimitPacketCount );
       
   881             return settingItem;
       
   882             break;
       
   883         case 2:
       
   884             settingItem = new (ELeave) CNslookupTextSettingItem( identifier, iMaxPacketCount );
       
   885             return settingItem;
       
   886             break;
       
   887         case 3:
       
   888             settingItem = new (ELeave) CNslookupTextSettingItem(identifier, iPacketDataSize);
       
   889             return settingItem;
       
   890             break;
       
   891         case 4:
       
   892             settingItem = new (ELeave) CNslookupTextSettingItem(identifier, iWaitTime);
       
   893             return settingItem;
       
   894             break;
       
   895         case 5:
       
   896             settingItem = new (ELeave) CNslookupTextSettingItem(identifier, iLastWaitTime);
       
   897             return settingItem;
       
   898             break;
       
   899         case 6:
       
   900             settingItem = new (ELeave) CNslookupTextSettingItem(identifier, iPattern);
       
   901             return settingItem;
       
   902             break;
       
   903         case 7:
       
   904             settingItem = new (ELeave) CNslookupBinaryPopupSettingItem( identifier, iQuiet );
       
   905             return settingItem;
       
   906             break;
       
   907         case 8:
       
   908             settingItem = new (ELeave) CNslookupBinaryPopupSettingItem( identifier, iVerbose );
       
   909             return settingItem;
       
   910             break;
       
   911         case 9:
       
   912             settingItem = new (ELeave) CNslookupBinaryPopupSettingItem( identifier, iDebug );
       
   913             return settingItem;
       
   914             break;
       
   915         default:
       
   916             settingItem = new (ELeave) CAknSettingItem(identifier);
       
   917             return settingItem;
       
   918             break;
       
   919     }
       
   920 }
       
   921 
       
   922 TBool CSettingView::SaveSettingsL()
       
   923 	{
       
   924     // Save settings to the member variables
       
   925 
       
   926     StoreSettingsL();
       
   927 
       
   928     // Validate input
       
   929 
       
   930     TLex lex;
       
   931 
       
   932     TInt maxPacketCount;
       
   933     lex.Assign( iMaxPacketCount );
       
   934     if ( lex.Val( maxPacketCount ) != KErrNone ) 
       
   935     {
       
   936         CEikonEnv::Static()->InfoMsg(_L("Packet count must be numeric"));
       
   937         return EFalse;
       
   938     }
       
   939 
       
   940     TInt packetDataSize;
       
   941     lex.Assign( iPacketDataSize );
       
   942     if ( lex.Val( packetDataSize ) != KErrNone ) 
       
   943     {
       
   944         CEikonEnv::Static()->InfoMsg(_L("Packet size must be numeric"));
       
   945         return EFalse;
       
   946     }
       
   947 
       
   948     TInt waitTime;
       
   949     lex.Assign( iWaitTime );
       
   950     if ( lex.Val( waitTime ) != KErrNone ) 
       
   951     {
       
   952         CEikonEnv::Static()->InfoMsg(_L("Wait time must be numeric"));
       
   953         return EFalse;
       
   954     }
       
   955 
       
   956     TInt lastWaitTime;
       
   957     lex.Assign( iLastWaitTime );
       
   958     if ( lex.Val( lastWaitTime ) != KErrNone ) 
       
   959     {
       
   960         CEikonEnv::Static()->InfoMsg(_L("Last wait time must be numeric"));
       
   961         return EFalse;
       
   962     }
       
   963 
       
   964     lex.Assign( iPattern );
       
   965     while (!lex.Eos())
       
   966     {
       
   967         if (!lex.Get().IsHexDigit())
       
   968         {
       
   969             CEikonEnv::Static()->InfoMsg(_L("Pattern must be hexadecimal"));
       
   970             return EFalse;
       
   971         }
       
   972     }
       
   973 
       
   974     // Validation OK, so save settings to the model
       
   975 
       
   976     iModel->iPackLimit = iLimitPacketCount;
       
   977     iModel->iTotalPackets = maxPacketCount;
       
   978     iModel->iPacketDataSize = packetDataSize;
       
   979     iModel->iSecWait = waitTime;
       
   980     iModel->iLastSecWait = lastWaitTime;
       
   981     iModel->iPattern.Copy(iPattern);
       
   982     iModel->iQuiet = iQuiet;
       
   983     iModel->iVerbose = iVerbose;
       
   984     iModel->iDebug = iDebug;
       
   985 
       
   986     return ETrue;
       
   987 }
       
   988     
       
   989 #endif // #ifdef CALYPSO