nettools/conntest/src/ConnTestDocument.cpp
changeset 0 857a3e953887
equal deleted inserted replaced
-1:000000000000 0:857a3e953887
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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: The document class for ConnTest, stores the settings
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "ConnTestDocument.h"
       
    20 #include "ConnTestAppUi.h"
       
    21 #include "ConnTestApp.h"
       
    22 #include "SettingData.h"
       
    23 #include "CustomPrefsData.h"
       
    24 
       
    25 // ================= MEMBER FUNCTIONS =======================
       
    26 
       
    27 // constructor
       
    28 CConnTestDocument::CConnTestDocument(CEikApplication& aApp)
       
    29     : CEikDocument(aApp)    
       
    30     {
       
    31     }
       
    32 
       
    33 // destructor
       
    34 CConnTestDocument::~CConnTestDocument()
       
    35     {
       
    36     RDebug::Print(_L("ConnTest: CConnTestDocument::~CConnTestDocument"));
       
    37     for(TInt i = 0; i < KConnTestViews; i++)
       
    38         {
       
    39         delete iSettingDataArray[i];
       
    40         delete iCustomPrefsDataArray[i];
       
    41         }
       
    42     }
       
    43 
       
    44 // Symbian default constructor can leave.
       
    45 void CConnTestDocument::ConstructL()
       
    46     {
       
    47     RDebug::Print(_L("ConnTest: CConnTestDocument::ConstructL"));
       
    48     for(TInt i = 0; i < KConnTestViews; i++)
       
    49         {
       
    50         iSettingDataArray[i] = CSettingData::NewL();
       
    51         iCustomPrefsDataArray[i] = CCustomPrefsData::NewL();
       
    52         }
       
    53     }
       
    54 
       
    55 // Two-phased constructor.
       
    56 CConnTestDocument* CConnTestDocument::NewL(CEikApplication& aApp)
       
    57     {
       
    58     CConnTestDocument* self = new (ELeave) CConnTestDocument( aApp );
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop(self);
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ----------------------------------------------------
       
    66 // CConnTestDocument::CreateAppUiL()
       
    67 // constructs CConnTestAppUi
       
    68 // ----------------------------------------------------
       
    69 //
       
    70 CEikAppUi* CConnTestDocument::CreateAppUiL()
       
    71     {
       
    72     return new (ELeave) CConnTestAppUi(iSettingDataArray, iCustomPrefsDataArray);
       
    73     }
       
    74 
       
    75 
       
    76 // ----------------------------------------------------
       
    77 // CConnTestDocument::StoreL()
       
    78 // Store current settings into file \\private\\101F6D2B\\ConnTest
       
    79 // ----------------------------------------------------
       
    80 //
       
    81 void CConnTestDocument::StoreL(CStreamStore& aStore, 
       
    82                                CStreamDictionary& aStreamDic) const
       
    83     {
       
    84     RStoreWriteStream stream;
       
    85     TStreamId id = stream.CreateLC(aStore);
       
    86     for(TInt i = 0; i < KConnTestViews; i++)
       
    87         {
       
    88         stream << iSettingDataArray[i]->iServerName;
       
    89         stream.WriteInt32L(iSettingDataArray[i]->iPort);
       
    90         stream.WriteInt32L(iSettingDataArray[i]->iProtocol);
       
    91         stream.WriteInt32L(iSettingDataArray[i]->iRoaming);
       
    92         stream.WriteInt32L(iSettingDataArray[i]->iPacketSize);
       
    93         stream.WriteInt32L(iSettingDataArray[i]->iPackets);
       
    94         stream.WriteInt32L(iSettingDataArray[i]->iDelay);
       
    95         stream << iSettingDataArray[i]->iHttpPage;
       
    96         }
       
    97     stream.CommitL();
       
    98     CleanupStack::PopAndDestroy(&stream); // stream
       
    99     aStreamDic.AssignL(KUidConnTest, id);
       
   100     }
       
   101 
       
   102 
       
   103 // ----------------------------------------------------
       
   104 // CConnTestDocument::RestoreL()
       
   105 // Read previous settings from file
       
   106 // ----------------------------------------------------
       
   107 //
       
   108 void CConnTestDocument::RestoreL(const CStreamStore& aStore, 
       
   109                                  const CStreamDictionary& aStreamDic)
       
   110     {
       
   111     TStreamId id = aStreamDic.At(KUidConnTest);
       
   112     RStoreReadStream stream;
       
   113     stream.OpenLC(aStore, id);
       
   114     for(TInt i = 0; i < KConnTestViews; i++)
       
   115         {
       
   116         stream >> iSettingDataArray[i]->iServerName;
       
   117         iSettingDataArray[i]->iPort       = stream.ReadInt32L();
       
   118         iSettingDataArray[i]->iProtocol   = stream.ReadInt32L();
       
   119         iSettingDataArray[i]->iRoaming    = stream.ReadInt32L();
       
   120         iSettingDataArray[i]->iPacketSize = stream.ReadInt32L();
       
   121         iSettingDataArray[i]->iPackets    = stream.ReadInt32L();
       
   122         iSettingDataArray[i]->iDelay      = stream.ReadInt32L();
       
   123         stream >> iSettingDataArray[i]->iHttpPage;
       
   124         }
       
   125     CleanupStack::PopAndDestroy(&stream); // stream    
       
   126     }
       
   127 
       
   128 
       
   129 // End of File