Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



GUIApp: GUI application with C engine


Example code

These are the main files contained in the examples. Some extra files may be needed to run the examples, and these will be found in the appropriate examples directory.

Found in: examples\stdlib\GUIApp

Note: This code is designed to work only with Techview and is not guaranteed to work with other interfaces

// CRC.C
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

/*-
 * Copyright (c) 1991, 1993
 * The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * James W. Williams of NASA Goddard Space Flight Center.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 * This product includes software developed by the University of
 * California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef lint
const static char sccsid[] = "@(#)crc.c   8.1 (Berkeley) 6/17/93";
#endif /* not lint */

#include <unistd.h>

const static u_long crctab[] = {
    0x0,
    0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
    0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
    0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
    0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
    0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
    0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
    0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
    0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58,
    0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033,
    0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe,
    0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
    0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4,
    0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
    0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5,
    0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
    0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
    0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c,
    0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
    0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
    0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b,
    0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698,
    0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d,
    0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
    0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f,
    0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
    0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80,
    0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
    0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a,
    0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629,
    0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c,
    0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
    0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e,
    0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65,
    0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
    0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
    0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2,
    0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
    0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74,
    0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
    0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21,
    0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a,
    0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087,
    0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
    0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d,
    0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce,
    0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb,
    0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
    0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09,
    0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
    0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf,
    0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};

/*
 * Compute a POSIX 1003.2 checksum.  This routine has been broken out so that
 * other programs can use it.  It takes a file descriptor to read from and
 * locations to store the crc and the number of bytes read.  It returns 0 on
 * success and 1 on failure.  Errno is set on failure.
 */


EXPORT_C int crc(register int fd, u_long *cval, u_long *clen)
{
    u_long crc_total = (u_long)~0;   /* The crc over a number of files*/
    register u_char *p;
    register int nr;
    register u_long crc, len;
//  u_char buf[16 * 1024]; // too large for stack
    u_char buf[3 * 1024];

#define COMPUTE(var, ch)  (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]

    crc = len = 0;
    crc_total = ~crc_total;
    while ((nr = read(fd, (char*)buf, sizeof(buf))) > 0)
        for (len += nr, p = buf; nr--; ++p) {
            COMPUTE(crc, *p);
            COMPUTE(crc_total, *p);
        }
    if (nr < 0)
        return (1);

    *clen = len;

    /* Include the length of the file. */
    for (; len != 0; len >>= 8) {
        COMPUTE(crc, len & 0xff);
        COMPUTE(crc_total, len & 0xff);
    }

    *cval = ~crc;
    crc_total = ~crc_total;
    return (0);
}

// GUIApp.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

//////////////////////////////////////////////////////////////////////////////
//
// OVERVIEW
// --------
//
// This is a GUI application to use the checksum engine.
//
// DIALOGS
// -------
//
// The two dialogs which this application defines:
// 
// a. Allows the user to select a file for which a checksum is calculated
// b. Displays the list of all checksums calculated 
//
//////////////////////////////////////////////////////////////////////////////

#include "GUIApp.h"
#include <stdlib.h> 

CExampleChecksumDialog::CExampleChecksumDialog(TDes* aFileName,TInt aTitleId)
    : iFileName(aFileName),iTitleId(aTitleId)
    {}

void CExampleChecksumDialog::PreLayoutDynInitL()
    {
    CEikFileNameSelector* fileNameSelector = (CEikFileNameSelector*) 
        (Control(EEikCidFileNameSel));
    CEikFolderNameSelector* folderNameSelector = (CEikFolderNameSelector*) 
        (Control(EEikCidFolderNameSel));
    CEikDriveNameSelector* driveNameSelector = (CEikDriveNameSelector*) 
        (Control(EEikCidDriveNameSel));
    folderNameSelector->SetFileSelectionObserver(fileNameSelector);
    driveNameSelector->SetFileSelectionObserver(folderNameSelector);
    User::LeaveIfError(EikFileUtils::Parse(*iFileName));
    TParsePtr parse(*iFileName);
    driveNameSelector->SetFullNameL(parse.FullName());
    if (iTitleId)
        SetTitleL(iTitleId);
    }

TBool CExampleChecksumDialog::OkToExitL(TInt /*aKeycode*/)
    {
    _LIT(KSpace," ");

    CEikFileNameSelector* fileNameSelector = (CEikFileNameSelector*) 
        (Control(EEikCidFileNameSel));
    fileNameSelector->ValidateStateL();
    // get the selected filename
    *iFileName = fileNameSelector->FullName();
    // Calculate the checksum
    TUint32 checksum, filesize;
    const TUint16* fn=iFileName->PtrZ();
    int fd = wopen((const wchar_t*)fn, O_RDONLY, 0); // Open file for reading
    if (fd < 0)
        // Can't open file
        {
        iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ERROR,iFileName);
        return EFalse;
        }
    TInt err=crc(fd, &checksum, &filesize); // (filesize not used)
    if (err==0)
        {
        // display the checksum in an infomessage
        iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_CKSUM,checksum);
        // Append the filename and checksum to the container's descriptor array
        TDes* fileNameAndCksum=iFileName;
        // Append a space to separate filename from checksum
        fileNameAndCksum->Append(KSpace);
        // Convert the checksum to text then append to the descriptor.
        fileNameAndCksum->AppendNum(checksum,EDecimal);
        }
    else iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_CKSUM_ERROR); 
            // can't calculate checksum
    close(fd); // close file
    return ETrue;
    }

CExampleListBoxDialog::CExampleListBoxDialog(CDesCArrayFlat* aCksumArray)
        : iCksumArray(aCksumArray)
    {
    }

void CExampleListBoxDialog::PreLayoutDynInitL()
    {
    CEikTextListBox* listbox=(CEikTextListBox*)Control(EExampleChecksumListBox);
    CDesCArray* listboxArray=((CDesCArray*)listbox->Model()->ItemTextArray());
    if (iCksumArray!=NULL)
        {
        // append contents of the model's checksum array to listbox for display
        for (TInt i=0; i<iCksumArray->Count(); i++)
            listboxArray->AppendL(iCksumArray->operator[](i));
        }
    CEikScrollBarFrame* scrollbarFrame = listbox->CreateScrollBarFrameL();
    // set horizontal and vertical scroll bars to appear when required
    scrollbarFrame->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,
        CEikScrollBarFrame::EAuto);
    }

void CExampleListBoxDialog::SetSizeAndPositionL(const TSize& aSize)
    {
    // Resize the dialog - keep aSize's height, double its width
    TSize dialogSize(((aSize.iWidth)*2), aSize.iHeight);
    SetCornerAndSize(EHCenterVCenter,dialogSize);
    }

TBool CExampleListBoxDialog::OkToExitL(TInt /*aKeycode*/)
    {
    return(ETrue);
    }


//////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleContainer (definition)
//
//////////////////////////////////////////////////////////////////////////////
CExampleContainer::CExampleContainer()
    {}

    
CExampleContainer::~CExampleContainer()
    {
    delete iChecksumArray;
    }

void CExampleContainer::ConstructL(const TRect& aRect)
    {
      // Create the window
    CreateWindowL();

      // granularity 3, ie space for 3 elements added when buffer is reallocated
    iChecksumArray = new (ELeave) CDesCArrayFlat(3);
    
      // Set the bounding rectangle of this control (this will result in 
      // a call to the SizeChangedL() member function 
    SetRect(aRect);

      // Prepares this control and ALL of its contained controls for drawing 
    ActivateL();    
    }


void CExampleContainer::Draw(const TRect&) const
    {
    // Draw the container control 
    CWindowGc& gc=SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.SetBrushColor(KRgbWhite);
    gc.DrawRect(Rect());
    }


void CExampleContainer::AppendChecksumL(const TDesC& aFilename)
    {
    // Check that the filename and cksum don't already exist in the array
    // If already there, do nothing
    TInt pos; // not interested in value
    if (iChecksumArray->Find(aFilename,pos,ECmpNormal))
        {
        TRAPD(error,iChecksumArray->AppendL(aFilename));
        if (error)
            {
            iChecksumArray->Reset();
            delete iChecksumArray;
            iChecksumArray=0;
            User::Leave(error);
            }
        }
    }

CDesCArrayFlat* CExampleContainer::GetChecksumArray() const
    {
    return iChecksumArray;
    }

void CExampleContainer::HandleControlEventL(CCoeControl* /*aControl*/,
                                        TCoeEvent /*aEventType*/
                                        )
    {
    }


//////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleAppUi (implementation)
//
//////////////////////////////////////////////////////////////////////////////
void CExampleAppUi::ConstructL()
    {
    // Disable control environment's automatic resource checking
    // If we don't do this when using stdlib, we get a CONE 36 panic
    iCoeEnv->DisableExitChecks(ETrue);

    // Allow base class (CEikAppUi) to perform necessary construction
    BaseConstructL();

      // Construct the container control which forms the main view
      // for this application. Construction requires the rectangle
      // available.
    iContainer = new(ELeave) CExampleContainer;
    iContainer->ConstructL(ClientRect());

      // The container is added to the control stack (for key event
      // handling).
    AddToStackL(iContainer);
    }
    

CExampleAppUi::~CExampleAppUi()
    {
    RemoveFromStack(iContainer);
      // Delete the container (control)
    delete iContainer;
    }

void CExampleAppUi::HandleCommandL(TInt aCommand)
    {
      // Handle the command generated by:
      //   1. menu item selection
      //   2. short-cut key press
      //   3. tool bar item selection
    switch (aCommand)
        {
    case EExampleCmdChecksum:
        OnCmdChecksumL();
        break;
    case EExampleCmdViewChecksums:
        OnCmdViewChecksumsL();
        break;
        // EXIT comand
    case EEikCmdExit:
        OnCmdExit();
        break;
    default :
        break;
        }
    }

void CExampleAppUi::OnCmdChecksumL()
    {
    // Ensure buffer is long enough to hold the max length filename 
    // and the max length checksum 
    _LIT(KM,"C:\\Documents\\");
    TBuf<KMaxFileName+KMaxChecksumLength> fileName(KM);
    CEikDialog* dialog = new (ELeave) CExampleChecksumDialog(&fileName);
    if (dialog->ExecuteLD(R_EXAMPLE_CHECKSUM_DIALOG))
        {
        // A checksum was calculated, so append the descriptor containing it and 
        // the filename to the container's array
        iContainer->AppendChecksumL(fileName);
        }
    }

void CExampleAppUi::OnCmdViewChecksumsL()
    {
    CEikDialog* dialog = new(ELeave) CExampleListBoxDialog
        (iContainer->GetChecksumArray());
    dialog->ExecuteLD(R_EXAMPLE_CHECKSUM_INFO_DIALOG);
    }

void CExampleAppUi::OnCmdExit()
    {
    CBaActiveScheduler::Exit();
    }

void CExampleAppUi::DrawViewL()
    {
    iContainer->SetRect(ClientRect());
    iContainer->DrawNow();
    }

////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleDocument (implementation)
//
/////////////////////////////////////////////////////////////////////////////
CExampleDocument::CExampleDocument(CEikApplication& aApp)
     : CEikDocument(aApp)
    {}

CExampleDocument::~CExampleDocument()
    {
    // release all of the STDLIB resources associated with this thread
    // Satisfies the CONE policy that the heap should be balanced across 
    // the lifetime of a CCoeEnv.
    CloseSTDLIB();
    }

CExampleDocument* CExampleDocument::NewL(CEikApplication& aApp)
    {
    CExampleDocument* self=new(ELeave) CExampleDocument(aApp);
    return self;
    }


CEikAppUi* CExampleDocument::CreateAppUiL()
    {
    return(new(ELeave) CExampleAppUi);
    }


//////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleApplication (implementation)
//
//////////////////////////////////////////////////////////////////////////////
TUid CExampleApplication::AppDllUid() const
    {
    return(KUidCksumApp);
    }


CApaDocument* CExampleApplication::CreateDocumentL()
    {
    return CExampleDocument::NewL(*this);
    }

//
// EXPORTed functions
//

EXPORT_C CApaApplication* NewApplication()
    {
    return(new CExampleApplication);
    }


GLDEF_C TInt E32Dll(TDllReason)
    {
    return(KErrNone);
    }

// GUIAppEng.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#include <e32std.h>

EXPORT_C TInt E32Dll(TDllReason)
    {
    return 0;
    }

// EXTERN.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

/*-
 * Copyright (c) 1991, 1993
 *  The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *  This product includes software developed by the University of
 *  California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *  @(#)extern.h    8.1 (Berkeley) 6/6/93
*/


#ifdef __cplusplus
extern "C" {
#endif

#define __BEGIN_DECLS   
#define __END_DECLS     
#define __P(x) x       /* use function protoypes */

__BEGIN_DECLS
int crc __P((int, unsigned long *, unsigned long *));
void pcrc __P((char *, unsigned long, unsigned long));
void psum1 __P((char *, unsigned long, unsigned long));
void psum2 __P((char *, unsigned long, unsigned long));
int csum1 __P((int, unsigned long *, unsigned long *));
int csum2 __P((int, unsigned long *, unsigned long *));
__END_DECLS

#ifdef __cplusplus
}
#endif

// GUIAppEng.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__SLSUMEIK_H__)
#define __SLSUMEIK_H__

//////////////////////////////////////////////////////////////////////////////
//
// Include files containing:
//
// 1. Symbol definitions used by C++ code and resource scripts (the *.hrh)
// 2. Resource ids generated by resource compilation of 
//    resource scripts (the *.rsg)
// 3. Class definitions required by this app (the *.h)
//    
//////////////////////////////////////////////////////////////////////////////

// 1.
#include <eikon.hrh>
#include "GUIApp.hrh"

#include <e32std.h> // required to avoid warning
// C header files
#include <fcntl.h>
#include <unistd.h>
#include <sys/reent.h>
#include "extern.h"

#include <eikon.rsg> // needed for file browse dialog
#include <GUIApp.rsg>

// 3.
#include <eikenv.h>
#include <eikappui.h>
#include <eikproc.h>
#include <eiktbar.h>
#include <eikfsel.h>
#include <eikapp.h>
#include <eikdoc.h>
#include <eikfnlab.h>
#include <eikfbrow.h>
#include <eikfutil.h>
#include <eiktxlbm.h>

#include <coeutils.h>

#include <basched.h>

  // The unique identifier for this application.
  // NOTE that the number has been arbitrarily chosen for the purpose
  // of the example.
const TUid KUidCksumApp={0x01000a03};

// Number of digits required to hold the maximum length checksum
const TInt KMaxChecksumLength=10; 

//////////////////////////////////////////////////////////////////////////////
//
// -----> CExamplePrefsDialog(definition)
//
//////////////////////////////////////////////////////////////////////////////

class CExampleChecksumDialog : public CEikDialog
    {
public:
    CExampleChecksumDialog(TDes* aFileName, TInt aTitleId=0);
private:    
    void       PreLayoutDynInitL();
    TBool      OkToExitL(TInt aKeycode);
private:
      // Data members defined by this class.
    TDes* iFileName;
    TInt iTitleId;
    };

class CExampleListBoxDialog : public CEikDialog
    {
public:
    CExampleListBoxDialog(CDesCArrayFlat* aCksumArray); // (change name of parameter)
private: // framework
    void PreLayoutDynInitL();
    void SetSizeAndPositionL(const TSize& aSize);
    TBool OkToExitL(TInt aKeycode);
    CDesCArrayFlat* iCksumArray;
    };


//////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleContainer(definition)
//
//////////////////////////////////////////////////////////////////////////////
class CExampleContainer : public CCoeControl, 
                      public MCoeControlObserver
    {
public:
      // Construction
    CExampleContainer();
    void ConstructL(const TRect& aRect);
      // Destruction
    ~CExampleContainer();
    
private:
      // Virtual, defined by CCoeControl; replaces the default implementation
      // provided by CCoeControl.
    void         Draw(const TRect& aRect) const;

      // Defined as pure virtual by the mixin class MCoeControlObserver 
      // inherited by CCoeControl. An empty implementation provided by 
      // this class (its containees do not report events).
    void         HandleControlEventL(CCoeControl* aControl,
                                     TCoeEvent aEventType
                                    );
    
public:
      // Member functions defined by this class
    void             AppendChecksumL(const TDesC& aFilename);
    CDesCArrayFlat*  GetChecksumArray() const;


private:
      // Data members defined and used by this class.
    CDesCArrayFlat* iChecksumArray;            // List of filenames and checksums
    };

//////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleAppUi (definition)
//
//////////////////////////////////////////////////////////////////////////////
class CExampleAppUi : public CEikAppUi
    {
public:
      // Destruction.
    ~CExampleAppUi();

public:
      // Virtual, defined by CEikAppUi; replaces the implementation 
      // provided by CEikAppUi.
    void ConstructL();
    
private:
      // Virtual, defined by CEikAppUi; ; empty implementation
      // provided by CEikAppUi; full implementation provided
      // by this class. 
    void  HandleCommandL(TInt aCommand);
    
private:
      // Member functions defined by this class
    void         OnCmdExit();
    void         OnCmdChecksumL();
    void         OnCmdViewChecksumsL();
    void         DrawViewL();

private:
      // Data members defined by this class.
    CExampleContainer* iContainer;      // The container control (ie the view)
    };

//////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleDocument (definition)
//
//////////////////////////////////////////////////////////////////////////////
class CExampleDocument : public CEikDocument
    {
public:
      // Construction.
    static CExampleDocument* NewL(CEikApplication& aApp);
    CExampleDocument(CEikApplication& aApp);
      // Destruction.
    ~CExampleDocument();

private:
      // Defined as pure virtual by CEikDocument; full implementation
      // provided by this class
    CEikAppUi* CreateAppUiL();     // Construct an app.user interface
    };

//////////////////////////////////////////////////////////////////////////////
//
// -----> CExampleApplication (definition)
//
//////////////////////////////////////////////////////////////////////////////
class CExampleApplication : public CEikApplication
    {
private:        
      // Defined as pure virtual by CApaApplication; implementation
      // provided by this class 
    TUid          AppDllUid() const; // Returns Uid associated with app

      // Defined as pure virtual by CEikApplication; implementation
      // provided by this class.
    CApaDocument* CreateDocumentL(); // Construct new document
    };

#endif

// GUIAppEng.HRH
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//


//////////////////////////////////////////////////////////////////////////////      
//
// Command ids
// Identify all commands defined by this application.
//
//////////////////////////////////////////////////////////////////////////////
enum
    {
      EExampleCmdChecksum=0x1000,
    EExampleCmdViewChecksums,
    EExampleCmdDocName                     // Identify the label control on
                                           // the toolbar.
      };


//////////////////////////////////////////////////////////////////////////////      
//
// Control ids
// Identify all controls defined and used by this application.
//
//////////////////////////////////////////////////////////////////////////////   
enum
    {
    EExampleChecksumListBox
    };
            
        
    

// BLD.INF
// Component description file 
//
// Copyright (c) 2000 Symbian Ltd.  All rights reserved.

PRJ_MMPFILES
GUIAppEng.mmp
GUIApp.mmp

// GUIApp.MMP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//
TARGET        GUIApp.app
TARGETTYPE    app
UID           0x100039ce 0x01000a03
VENDORID 0x70000001
TARGETPATH    \system\apps\GUIApp

SOURCEPATH  .
SOURCE        GUIApp.cpp
RESOURCE      GUIApp.rss

SYSTEMINCLUDE \epoc32\include\libc  \epoc32\include 
SYSTEMINCLUDE \epoc32\include\techview
LIBRARY       GUIAppEng.lib euser.lib efsrv.lib
LIBRARY       cone.lib  eikcore.lib  eikcoctl.lib apparc.lib 
LIBRARY       bafl.lib estlib.lib eikfile.lib eikdlg.lib

// GUIAppEng.MMP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

TARGET      GUIAppEng.dll
TARGETTYPE  dll
UID             0x1000008d 0x01000a02
VENDORID 0x70000001
SOURCEPATH  .
SOURCE      crc.c GUIAppeng.cpp
SYSTEMINCLUDE   \epoc32\include\libc \epoc32\include
LIBRARY     estlib.lib euser.lib 

#if defined(WINS)
    deffile ..\GUIApp\GuiAppEngWINS.def
#else if defined(ARM)
    deffile ..\GUIApp\GuiAppEngARM.def
#endif
nostrictdef

// GUIAPP.RSS
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//


NAME slsm
        // Include definitions of resource STRUCTS used by this
        // resource script 

#include <eikon.rh>
#include <eikon.rsg>

#include "GUIApp.hrh"


RESOURCE RSS_SIGNATURE
    {
    }
    
RESOURCE TBUF { buf=""; } // default document name. if "empty" eikon takes 
                          // the iCaption value in ApaProcess

RESOURCE EIK_APP_INFO
    {   
    hotkeys=r_example_hotkeys; 
    menubar=r_example_main_menubar; 
    }


//////////////////////////////////////////////////////////////////////////////
//
// Short cut keys
//
//////////////////////////////////////////////////////////////////////////////
RESOURCE HOTKEYS r_example_hotkeys
    {
    control=
            {
            HOTKEY {command=EEikCmdExit;                 key='e';},
            HOTKEY {command=EExampleCmdChecksum;         key='c';},
            HOTKEY {command=EExampleCmdViewChecksums;    key='k';}
            };
    }

//////////////////////////////////////////////////////////////////////////////
//
// The menu bar
//
//////////////////////////////////////////////////////////////////////////////
RESOURCE MENU_BAR r_example_main_menubar
    {
    titles=
        {
        MENU_TITLE { menu_pane=r_example_file_menu;   txt="File"; }
        };
    }

//////////////////////////////////////////////////////////////////////////////
//
// The "file" menu pane hung directly from the menu bar
//
//////////////////////////////////////////////////////////////////////////////
RESOURCE MENU_PANE r_example_file_menu
    {
    items=
        {
        MENU_ITEM
            {
            command=EExampleCmdChecksum;
            txt="Calculate checksum...";
            },
        MENU_ITEM
            {
            command=EExampleCmdViewChecksums;
            txt="View checksums...";
            flags=EEikMenuItemSeparatorAfter; 
            },
        MENU_ITEM 
            { 
            command=EEikCmdExit; 
            txt="Close";
            }
        };
    }


//////////////////////////////////////////////////////////////////////////////
//
// Dialog to select a file and calculate a checksum
//
//////////////////////////////////////////////////////////////////////////////
RESOURCE DIALOG r_example_checksum_dialog
    {
    title="Calculate checksum";
    buttons=R_EIK_BUTTONS_CONTINUE;
    flags=EEikDialogFlagWait;
    items=
        {
        DLG_LINE
            {
            prompt="Name";
            type=EEikCtFileNameSel;
            id=EEikCidFileNameSel;
            control=FILENAMESELECTOR {};
            },
        DLG_LINE
            {
            prompt="Folder";
            type=EEikCtFolderNameSel;
            id=EEikCidFolderNameSel;
            control=FOLDERNAMESELECTOR {};
            },
        DLG_LINE
            {
            prompt="Disk";
            type=EEikCtDriveNameSel;
            id=EEikCidDriveNameSel;
            control=DRIVENAMESELECTOR {};
          }
        };
    }

//////////////////////////////////////////////////////////////////////////////
//
// Dialog to view all checksums
//
//////////////////////////////////////////////////////////////////////////////
RESOURCE DIALOG r_example_checksum_info_dialog
    {
    title = "Checksum information";
    buttons=R_EIK_BUTTONS_CONTINUE;
    flags=EEikDialogFlagWait;
    items =
        {
        DLG_LINE
            {
            type = EEikCtListBox;
            id = EExampleChecksumListBox;
            control = LISTBOX
                {
                flags = EEikListBoxIncrementalMatching;
                };
            }
        };
    }

//////////////////////////////////////////////////////////////////////////////
//
// Text used for the info messages
//
//////////////////////////////////////////////////////////////////////////////
RESOURCE TBUF r_example_text_cksum               { buf="Checksum = %u"; }
RESOURCE TBUF r_example_text_error               { buf="Error opening file %S"; }
RESOURCE TBUF r_example_text_cksum_error     { buf="Error assigning checksum"; }

[Top]


Description

GUIApp is an example of an GUI application whose engine is written in C.

The engine is a DLL, produced by project GUIAppEng.mmp, was taken from the FreeBSD cksum (checksum) utility. The only code in the project which was not written in C is the following function, defined in file GUIAppEng.cpp:

EXPORT_C TInt E32Dll(TDllReason)

This fulfils the requirement that all DLLs need an entry point called E32Dll().

[Top]


Usage

The program is operated using the following commands on the File menu: