creator/src/creator_note.cpp
branchRCL_3
changeset 19 b3cee849fa46
parent 18 48060abbbeaf
child 20 fad26422216a
equal deleted inserted replaced
18:48060abbbeaf 19:b3cee849fa46
     1 /*
       
     2 * Copyright (c) 2008 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 "creator_note.h" 
       
    20 #include "creator_traces.h"
       
    21 
       
    22 const TInt KCreatorDiskSpaceNeededForSingleDeletion( 8192 );
       
    23 _LIT( KCreatorNotepadFile, "c:Notepad.dat" );
       
    24 
       
    25 // @see \s60\app\organizer\notepad\notepad1\LibSrc\NpdCoreModel.cpp KSecureUid.Name()
       
    26 _LIT( KCreatorNotepadFormat, "SECURE[101F8878]" ); 
       
    27 _LIT( KCreatorNotepadDeleteAllSQL, "DELETE FROM Table1");
       
    28 
       
    29 //----------------------------------------------------------------------------
       
    30 
       
    31 CNotepadParameters::CNotepadParameters()
       
    32     {
       
    33     LOGSTRING("Creator: CNotepadParameters::CNotepadParameters");
       
    34 
       
    35     iNoteText = HBufC::New(KNotepadFieldLength);
       
    36     }
       
    37 
       
    38 CNotepadParameters::~CNotepadParameters()
       
    39     {
       
    40     LOGSTRING("Creator: CNotepadParameters::~CNotepadParameters");
       
    41 
       
    42     delete iNoteText;
       
    43     }
       
    44 
       
    45 //----------------------------------------------------------------------------
       
    46 
       
    47 CCreatorNotepad* CCreatorNotepad::NewL(CCreatorEngine* aEngine)
       
    48     {
       
    49     CCreatorNotepad* self = CCreatorNotepad::NewLC(aEngine);
       
    50     CleanupStack::Pop(self);
       
    51     return self;
       
    52     }
       
    53 
       
    54 CCreatorNotepad* CCreatorNotepad::NewLC(CCreatorEngine* aEngine)
       
    55     {
       
    56     CCreatorNotepad* self = new (ELeave) CCreatorNotepad;
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL(aEngine);
       
    59     return self;
       
    60     }
       
    61 
       
    62 CCreatorNotepad::CCreatorNotepad() : iFs ( CEikonEnv::Static()->FsSession() )
       
    63     {
       
    64     }
       
    65 
       
    66 void CCreatorNotepad::ConstructL(CCreatorEngine* aEngine)
       
    67     {
       
    68     LOGSTRING("Creator: CCreatorNotepad::ConstructL");
       
    69 
       
    70     iEngine = aEngine;
       
    71 
       
    72     iNotepadApi = CNotepadApi::NewL();
       
    73     }
       
    74 
       
    75 CCreatorNotepad::~CCreatorNotepad()
       
    76     {
       
    77     LOGSTRING("Creator: CCreatorNotepad::~CCreatorNotepad");
       
    78     
       
    79     delete iNotepadApi;
       
    80     
       
    81     if (iParameters)
       
    82         delete iParameters;
       
    83     }
       
    84 
       
    85 //----------------------------------------------------------------------------
       
    86 
       
    87 TBool CCreatorNotepad::AskDataFromUserL(TInt aCommand, TInt& aNumberOfEntries)
       
    88     {
       
    89     LOGSTRING("Creator: CCreatorNotepad::AskDataFromUserL");
       
    90 
       
    91     if ( aCommand == ECmdDeleteNotes )
       
    92         {
       
    93         return iEngine->YesNoQueryDialogL( _L("Delete all Notes?") );
       
    94         }
       
    95     
       
    96     // By Creator not supported because 
       
    97     // note id is not available via Notepad API
       
    98 
       
    99     return iEngine->EntriesQueryDialogL(aNumberOfEntries, _L("How many entries to create?"));
       
   100     }
       
   101 
       
   102 
       
   103 //----------------------------------------------------------------------------
       
   104 
       
   105 TInt CCreatorNotepad::CreateNoteEntryL(CNotepadParameters *aParameters)
       
   106     {
       
   107     LOGSTRING("Creator: CCreatorNotepad::CreateNoteEntryL");
       
   108 
       
   109     // clear any existing parameter definations
       
   110     delete iParameters;
       
   111     iParameters = NULL;
       
   112     
       
   113     CNotepadParameters* parameters = aParameters;
       
   114     
       
   115     // random data needed if no predefined data available
       
   116     if (!parameters)
       
   117         {
       
   118         iParameters = new(ELeave) CNotepadParameters;
       
   119         parameters = iParameters;
       
   120         parameters->iNoteText->Des() = iEngine->RandomString(CCreatorEngine::EMessageText);
       
   121         }
       
   122     
       
   123     TInt err = KErrNone;
       
   124 
       
   125     iNotepadApi->AddContentL(parameters->iNoteText->Des());
       
   126     
       
   127     return err;
       
   128     }
       
   129 
       
   130 //----------------------------------------------------------------------------
       
   131 void CCreatorNotepad::DeleteAllL()
       
   132     {
       
   133     LOGSTRING("Creator: CCreatorNotepad::DeleteAllL");
       
   134     // Open Notes db
       
   135     RDbs dbs;
       
   136     User::LeaveIfError( dbs.Connect() );
       
   137     CleanupClosePushL( dbs );
       
   138     RDbNamedDatabase db;
       
   139     TInt openErr( db.Open( dbs, KCreatorNotepadFile, KCreatorNotepadFormat ) );
       
   140     CleanupClosePushL( db );
       
   141     
       
   142     if ( openErr && openErr !=  KErrNotFound )
       
   143         {
       
   144         User::Leave( openErr );
       
   145         }
       
   146     
       
   147     // do not leave if openErr == KErrNotFound, 
       
   148     // it means there is no notes (file) created -> no need to delete
       
   149     
       
   150     if ( openErr !=  KErrNotFound )
       
   151         {
       
   152         TInt retval = iFs.ReserveDriveSpace( KDefaultDrive, KCreatorDiskSpaceNeededForSingleDeletion );
       
   153         if ( retval == KErrNone )
       
   154             {
       
   155             retval = iFs.GetReserveAccess( KDefaultDrive );
       
   156             }
       
   157 
       
   158         // Delete all Notes. Ignore rowCount returnvalue
       
   159         db.Execute( KCreatorNotepadDeleteAllSQL );            
       
   160         
       
   161         User::LeaveIfError( db.Compact() );
       
   162         
       
   163         if ( retval == KErrNone )
       
   164             {
       
   165             retval = iFs.ReleaseReserveAccess( KDefaultDrive );
       
   166             }
       
   167         }
       
   168     
       
   169     CleanupStack::PopAndDestroy( &db );
       
   170     CleanupStack::PopAndDestroy( &dbs );
       
   171     }
       
   172 
       
   173 //----------------------------------------------------------------------------
       
   174 void CCreatorNotepad::DeleteAllCreatedByCreatorL()
       
   175     {
       
   176     LOGSTRING("Creator: CCreatorNotepad::DeleteAllCreatedByCreatorL");
       
   177     // Not supported because note id is not available via Notepad API
       
   178     User::Leave( KErrNotSupported );
       
   179     }