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