messagingappbase/smartmessaging/gmsmodel/src/CGmsWrapper.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     Wrapper for handling GMS message. It wraps a CGmsModel.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CGmsPictureControl.h"
       
    23 #include "CGmsWrapper.h"
       
    24 
       
    25 #include <gmsModel.h>
       
    26 #include <s32file.h>                // RFileReadStream
       
    27 #include <txtrich.h>                // CRIchText
       
    28 #include <akntitle.h>
       
    29 #include <StringLoader.h>
       
    30 #include <DocumentHandler.h>        // CDocumentHandler
       
    31 #include <aknnotewrappers.h>        // Avkon note wrappers
       
    32 #include <mmsgbiocontrol.h>         // for KErrMsgBioMessageNotValid
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // The picture is written to this temporary file because Photoalbum wants it
       
    37 // in a file. And the file ending has to be 'ota', otherwise it won't be
       
    38 // recognised by the photoalbum viewer.
       
    39 _LIT(KTempOtaFileName, "gmstmp.ota");
       
    40 
       
    41 _LIT(KCGmsWrapper,"CGmsWrapper");
       
    42 
       
    43 //  MEMBER FUNCTIONS
       
    44 
       
    45 EXPORT_C CGmsWrapper* CGmsWrapper::NewL(RFs& aFs)
       
    46     {
       
    47     CGmsWrapper* self = new (ELeave) CGmsWrapper(aFs);
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop(self);
       
    51     return self;
       
    52     }
       
    53 
       
    54 EXPORT_C CGmsWrapper::~CGmsWrapper()
       
    55     {
       
    56     delete iModel;
       
    57     if (iExistsTmpFile)
       
    58         {
       
    59         __ASSERT_DEBUG(iFileName.Length() > 0, Panic(EGmsWrFilenameEmpty2));
       
    60         iFs.Delete(iFileName);
       
    61         }
       
    62     
       
    63     }
       
    64 
       
    65 EXPORT_C void CGmsWrapper::LoadMsgL(const CRichText& aMsgRich)
       
    66     {
       
    67     iModel->ImportGMSL(aMsgRich);
       
    68     ExportBitmapToTempFileL();
       
    69     }
       
    70 
       
    71 EXPORT_C void CGmsWrapper::AddPictureControlToViewL(CMsgEditorView& aView, TInt aId)
       
    72     {
       
    73     __ASSERT_DEBUG(iModel, Panic(EGmsWrNoModel1));
       
    74     __ASSERT_ALWAYS(iModel->HasPicture(), Panic(EGmsWrNoPicture));
       
    75     __ASSERT_ALWAYS(iFileName.Length() > 0, Panic(EGmsWrFilenameEmpty));
       
    76     CGmsPictureControl* imageControl = CGmsPictureControl::NewL(&aView);
       
    77     CleanupStack::PushL(imageControl);
       
    78     imageControl->SetControlId(aId);
       
    79     imageControl->LoadImageL(iFileName);
       
    80     aView.AddControlL(imageControl, imageControl->ControlId(),
       
    81     EMsgFirstControl, EMsgBody);
       
    82     CleanupStack::Pop(imageControl);
       
    83     }
       
    84 
       
    85 EXPORT_C void CGmsWrapper::PictureSelectionPopupL(TInt /*aBadPicTextResId*/ )
       
    86     {
       
    87     // This method is deprecated
       
    88     User::Leave( KErrNotSupported );
       
    89     }
       
    90 
       
    91 EXPORT_C CRichText* CGmsWrapper::GetTextLC()
       
    92     {
       
    93     CRichText* richText = CRichText::NewL(
       
    94         STATIC_CAST(CEikonEnv*, CCoeEnv::Static())->SystemParaFormatLayerL(),
       
    95         STATIC_CAST(CEikonEnv*, CCoeEnv::Static())->SystemCharFormatLayerL());
       
    96     CleanupStack::PushL(richText);
       
    97     HBufC16* text = iModel->TextAsHBufC16LC();
       
    98     richText->Reset(); // is this needed?
       
    99     richText->InsertL( 0, *text);
       
   100     CleanupStack::PopAndDestroy(text);
       
   101     return richText;
       
   102     }
       
   103 
       
   104 EXPORT_C void CGmsWrapper::SetTextL(CRichText& aRich)
       
   105     {
       
   106     TInt docLength = aRich.DocumentLength();
       
   107     HBufC16* buf = HBufC16::NewLC(docLength);
       
   108     TPtr16 ptr16(buf->Des());
       
   109     aRich.Extract(ptr16, 0, docLength);
       
   110     iModel->SetTextL(ptr16);
       
   111     CleanupStack::PopAndDestroy(buf);
       
   112     }
       
   113 
       
   114 EXPORT_C HBufC* CGmsWrapper::GetMessageLC()
       
   115     {
       
   116     return iModel->ExportGMS16LC();
       
   117     }
       
   118 
       
   119 EXPORT_C void CGmsWrapper::SetPictureMsgTitleL(CEikStatusPane& aStatusPane,
       
   120     TInt aTitleTextResIs)
       
   121     {
       
   122     CEikStatusPane* sp = &aStatusPane;
       
   123     CAknTitlePane* title = STATIC_CAST(
       
   124         CAknTitlePane*,
       
   125         sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle )));
       
   126     HBufC* text = StringLoader::LoadLC(aTitleTextResIs);
       
   127     title->SetTextL(*text);
       
   128     CleanupStack::PopAndDestroy(text);
       
   129     }
       
   130 
       
   131 EXPORT_C TInt CGmsWrapper::MsgSizeExcludingText()
       
   132     {
       
   133     return iModel->TotalSizeExcludingText();
       
   134     }
       
   135 
       
   136 EXPORT_C void CGmsWrapper::AddToPhotoAlbumL(TInt aDefaultNameResIs,
       
   137     TInt /*aPictureCopiedResId*/)
       
   138     {
       
   139     CDocumentHandler* handler = CDocumentHandler::NewLC(NULL);
       
   140     TDataType nullType;
       
   141     TInt err = handler->CopyL(
       
   142         iFileName,
       
   143         *StringLoader::LoadLC(aDefaultNameResIs),
       
   144         nullType, NULL);
       
   145     CleanupStack::PopAndDestroy(2, handler); // (pic name) + handler
       
   146     if (err != KUserCancel && err != KErrNone)
       
   147         {
       
   148         User::Leave(err);
       
   149         }
       
   150     /* These are the other docHandler error codes:
       
   151     KBadMimeType         = 12002; // Mime type conflict etc.
       
   152     KMimeNotSupported    = 12003; // No handler found
       
   153     KNullContent         = 12005; // Empty content
       
   154     KDataDirNotFound     = 12006; // No data dir found
       
   155     KExecNotAllowed      = 12007; // Executables not allowed
       
   156     KNoHostProcess       = 12008; // Embedding without host
       
   157     KNotInitialized      = 12009; // Not initialized
       
   158     */
       
   159     }
       
   160 
       
   161 EXPORT_C const CGmsModel& CGmsWrapper::Model() const
       
   162     {
       
   163     return *iModel;
       
   164     }
       
   165 
       
   166 void CGmsWrapper::Panic(TGmsWrapperPanic aCode)
       
   167     {
       
   168     User::Panic(KCGmsWrapper, aCode);
       
   169     }
       
   170 
       
   171 void CGmsWrapper::ExportBitmapToTempFileL()
       
   172     {
       
   173     __ASSERT_ALWAYS(iFileName.Length() == 0, Panic(EGmsWrTmpPicFileNotNeeded));
       
   174     __ASSERT_ALWAYS(!iExistsTmpFile, Panic(EGmsWrTmpFileAlreadyExists));
       
   175 
       
   176 	User::LeaveIfError(iFs.CreatePrivatePath(EDriveC));
       
   177 	
       
   178 	TChar driveChar;
       
   179     iFs.DriveToChar( EDriveC,driveChar);
       
   180     TDriveName driveName;
       
   181     driveName.Append(driveChar);
       
   182     driveName.Append(KDriveDelimiter);
       
   183     
       
   184     iFs.PrivatePath(iFileName);
       
   185     iFileName.Insert(0,driveName);
       
   186    	iFileName.Append(KTempOtaFileName);
       
   187     RFileWriteStream writeStream;
       
   188     User::LeaveIfError(writeStream.Replace(
       
   189         iFs,
       
   190         iFileName,
       
   191         EFileStream ));
       
   192     iExistsTmpFile = ETrue;
       
   193     
       
   194     writeStream.PushL();
       
   195     iModel->ExportOTABitmapL(writeStream);
       
   196     writeStream.CommitL();
       
   197     writeStream.Close();
       
   198     CleanupStack::Pop(); // (writeStream cleanup item)
       
   199     }
       
   200 
       
   201 void CGmsWrapper::ConstructL()
       
   202     {
       
   203     iModel = CGmsModel::NewL(iFs, KErrMsgBioMessageNotValid);
       
   204     }
       
   205 
       
   206 CGmsWrapper::CGmsWrapper(RFs& aFs) : iFs(aFs), iExistsTmpFile(EFalse)
       
   207     {
       
   208     }
       
   209 
       
   210 // end of file