fax/faxclientandserver/FAXCLI/CFAXTSRC.CPP
changeset 20 244d7c5f118e
parent 19 1f776524b15c
child 23 6b1d113cdff3
equal deleted inserted replaced
19:1f776524b15c 20:244d7c5f118e
     1 // Copyright (c) 1997-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18 */
       
    19 
       
    20 
       
    21 #include "CFAX32.H"
       
    22 
       
    23 /********************************************************************/
       
    24 
       
    25 CFaxTransferSource *CFaxTransferSource::NewLC()
       
    26 	{
       
    27 	CFaxTransferSource *self = new(ELeave) CFaxTransferSource;
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL();
       
    30 	return self;
       
    31 	}
       
    32 /********************************************************************/
       
    33 
       
    34 CFaxTransferSource *CFaxTransferSource::NewL()
       
    35 	{
       
    36 	CFaxTransferSource *self = NewLC();
       
    37 	CleanupStack::Pop();
       
    38 	return self;
       
    39 	}
       
    40 /********************************************************************/
       
    41 
       
    42 void CFaxTransferSource::ConstructL ()
       
    43    {
       
    44    iSources = CBufSeg::NewL (256);
       
    45    }
       
    46 /********************************************************************/
       
    47 
       
    48 CFaxTransferSource::~CFaxTransferSource ()
       
    49    {
       
    50    delete iSources;
       
    51    iSources = NULL;
       
    52    }
       
    53 /********************************************************************/
       
    54 
       
    55 // we come here with a document and a page or range of pages
       
    56 //EXPORT_C void CFaxTransferSource::AddSourceL (const TFileName & aFaxPageStore, const TFileName & aFaxPageStore2)
       
    57 //	{
       
    58 //	AddSourceL(aFaxPageStore,1);
       
    59 //	AddSourceL(aFaxPageStore2,1);
       
    60 //	iFaxPages=iFaxPages/2;
       
    61 //	}
       
    62 
       
    63 EXPORT_C void CFaxTransferSource::AddSourceL (const TFileName & aFaxPageStore, TFaxPreferredCompression aPreferredCompression)
       
    64 /**
       
    65 @capability WriteUserData
       
    66 */
       
    67    {
       
    68    AddSourceL (aFaxPageStore, 1, aPreferredCompression);
       
    69    }
       
    70 
       
    71 EXPORT_C void CFaxTransferSource::AddSourceL (const TFileName & aFaxPageStore, TInt aStartPage, TFaxPreferredCompression aPreferredCompression)
       
    72 /**
       
    73 @capability WriteUserData
       
    74 */
       
    75    {
       
    76    if (aStartPage < 1)
       
    77       User::Leave (KErrUnderflow);
       
    78    TInt lastPage = OpenFaxOutL (aFaxPageStore);
       
    79    CloseFaxStore ();
       
    80    AddSourceL (aFaxPageStore, aStartPage, lastPage, aPreferredCompression);
       
    81    }
       
    82 
       
    83 EXPORT_C void CFaxTransferSource::AddSourceL (const TFileName & aFaxPageStore, TInt aStartPage, TInt aEndPage, TFaxPreferredCompression aPreferredCompression)
       
    84 /**
       
    85 @capability WriteUserData
       
    86 */
       
    87    {
       
    88    iPage = 0;
       
    89    if (aStartPage < 1)
       
    90       User::Leave (KErrUnderflow);
       
    91    else
       
    92       {
       
    93       if (aStartPage > aEndPage)
       
    94          User::Leave (KErrOverflow);
       
    95       else
       
    96          {
       
    97          iOurFaxEntry.iFaxPageStore = aFaxPageStore;
       
    98          iOurFaxEntry.iStartPage = aStartPage;
       
    99          iOurFaxEntry.iPageCount = (aEndPage - aStartPage + 1);
       
   100 
       
   101          iOutstream.Append (*iSources);
       
   102          iOutstream << iOurFaxEntry;
       
   103          iOutstream.CommitL ();
       
   104 
       
   105          iFaxListEntries++;
       
   106          iFaxPages += iOurFaxEntry.iPageCount;
       
   107 		 iOurPreferredCompression=aPreferredCompression;
       
   108          }
       
   109       }
       
   110    }
       
   111 /********************************************************************/
       
   112 
       
   113 EXPORT_C void CFaxTransferSource::RemoveAllSources ()
       
   114 /**
       
   115 @capability WriteUserData
       
   116 */
       
   117    {
       
   118    iFaxPages = 0;
       
   119    iFaxListEntries = 0;
       
   120    iSources->Reset ();
       
   121    }
       
   122 /********************************************************************/
       
   123 
       
   124 // this gets the next page of the fax
       
   125 // and makes it all ready to be sent
       
   126 
       
   127 // the iInstream is opened already, and
       
   128 // we never call this if iFaxListEntries
       
   129 // and iOurFaxEntry.iPageCount are both zero
       
   130 
       
   131 void CFaxTransferSource::GetNextPageReadyL ()
       
   132    {
       
   133    // if no pages in a current open document we need to get the next doc
       
   134 
       
   135    if (iOurFaxEntry.iPageCount == 0)
       
   136       {
       
   137 
       
   138       // if page count is 0 we haven't started yet
       
   139       // otherwise close the finished document
       
   140       // then read the next entry in
       
   141       // mark one less entry to deal with
       
   142       // and open the next document
       
   143 
       
   144       if (iPage != 0)
       
   145          CloseFaxStore ();
       
   146 
       
   147       iInstream >> iOurFaxEntry;
       
   148 
       
   149       --iFaxListEntries;
       
   150       OpenFaxOutL (iOurFaxEntry.iFaxPageStore);
       
   151 
       
   152       // skip pages if we don't send from page 1
       
   153 
       
   154       for (--iOurFaxEntry.iStartPage; iOurFaxEntry.iStartPage; --iOurFaxEntry.iStartPage)
       
   155          ReadPageParmsL ();
       
   156       }
       
   157    ReadPageParmsL ();
       
   158    iPage++;
       
   159    --iOurFaxEntry.iPageCount;
       
   160    }
       
   161 /********************************************************************/
       
   162 
       
   163 void CFaxTransferSource::OpenFaxInL (const TDesC & aFileName)
       
   164    {
       
   165    if (iWriteFaxFile == NULL)
       
   166       iWriteFaxFile = CWriteFaxFile::NewL ();
       
   167    iWriteFaxFile->OpenL (aFileName, 0);
       
   168    }
       
   169 
       
   170 void CFaxTransferSource::PagePrepare ()
       
   171    {
       
   172    iLines = 0;
       
   173    ++iPage;
       
   174    }
       
   175 
       
   176 void CFaxTransferSource::WriteFaxDataL (const TDesC8 & aBuffer)
       
   177    {
       
   178    iWriteFaxFile->iWriteFaxPages->AddEncodedScanLineL (aBuffer);
       
   179    if (aBuffer.Length () != KMaxT4Des)
       
   180       iLines++;
       
   181    }
       
   182 
       
   183 void CFaxTransferSource::WritePageParmsL (TFaxBufSenderId & aSenderId)
       
   184    {
       
   185    iWriteFaxFile->iWriteFaxPages->EndPageL (TFaxResolution (iResolu), aSenderId, TFaxCompression (iCompression));
       
   186    iWriteFaxFile->CommitL ();
       
   187    }
       
   188 
       
   189 void CFaxTransferSource::CloseFaxInStore ()
       
   190    {
       
   191    iWriteFaxFile->Close ();     // was CloseL till 6/3/97
       
   192    delete iWriteFaxFile;
       
   193    iWriteFaxFile = NULL;
       
   194    }
       
   195 /*******************************************************************/
       
   196 
       
   197 TInt CFaxTransferSource::OpenFaxOutL (const TDesC & aFileName)
       
   198    {
       
   199    CReadFaxFile *fax = iReadFaxFile;
       
   200    if (fax == NULL)
       
   201       iReadFaxFile = fax = CReadFaxFile::NewL ();
       
   202    fax->OpenL (aFileName);
       
   203    iPageInCurrentFile = 0;
       
   204    return (fax->iReadFaxPages->NumPages ());
       
   205    }
       
   206 
       
   207 TInt CFaxTransferSource::NextPageFind ()
       
   208    {
       
   209    return (iReadFaxFile->iReadFaxPages->NumPages ()) - iPageInCurrentFile;
       
   210    }
       
   211 
       
   212 void CFaxTransferSource::ReadPageParmsL ()
       
   213    {
       
   214    CReadFaxPages & pages = *iReadFaxFile->iReadFaxPages;
       
   215    pages.SetPageL (iPageInCurrentFile++);
       
   216    const TFaxPageInfo & info = pages.CurrentPageInfo ();
       
   217    iLines = info.iNumScanLines;
       
   218    iResolu = info.iResolution;
       
   219    iCompression = info.iCompression;
       
   220    }
       
   221 
       
   222 void CFaxTransferSource::ReadFaxData(TDes8& aBuffer)
       
   223 	{
       
   224 	// Discard the following error
       
   225 	TRAP_IGNORE(iReadFaxFile->iReadFaxPages->GetEncodedScanLineL(aBuffer));
       
   226 	}
       
   227 
       
   228 void CFaxTransferSource::PreviousPageFindL()
       
   229 	{
       
   230 	--iPageInCurrentFile;
       
   231 	ReadPageParmsL();
       
   232 	}
       
   233 
       
   234 void CFaxTransferSource::CloseFaxStore ()
       
   235    {
       
   236    if (iReadFaxFile != NULL)
       
   237       {
       
   238       iReadFaxFile->Close ();
       
   239       delete iReadFaxFile;
       
   240       iReadFaxFile = NULL;
       
   241       }
       
   242    }
       
   243 
       
   244 
       
   245 /*******************************************************************/
       
   246 
       
   247 // we've also got a small subclass to handle the details of pages in the fax
       
   248 
       
   249 void TFaxEntry::ExternalizeL (RWriteStream & aStream) const
       
   250    {
       
   251    aStream << iFaxPageStore;
       
   252    aStream.WriteUint8L (iStartPage);
       
   253    aStream.WriteUint8L (iPageCount);
       
   254    }
       
   255 
       
   256 void TFaxEntry::InternalizeL (RReadStream & aStream)
       
   257    {
       
   258    aStream >> iFaxPageStore;
       
   259    iStartPage = aStream.ReadUint8L ();
       
   260    iPageCount = aStream.ReadUint8L ();
       
   261    }
       
   262 /********************************************************************/