messagingapp/msgui/msguiutils/src/mmsconformancecheck.cpp
changeset 43 35b64624a9e7
parent 34 84197e66a4bd
child 44 36f374c67aa8
equal deleted inserted replaced
34:84197e66a4bd 43:35b64624a9e7
    32 #include <hbaction.h>
    32 #include <hbaction.h>
    33 
    33 
    34 #include "unidatamodelloader.h"
    34 #include "unidatamodelloader.h"
    35 #include "unidatamodelplugininterface.h"
    35 #include "unidatamodelplugininterface.h"
    36 #include "UniEditorGenUtils.h" // This is needed for KDefaultMaxSize
    36 #include "UniEditorGenUtils.h" // This is needed for KDefaultMaxSize
    37 #include "s60qconversions.h"
    37 #include <xqconversions.h>
    38 #include "debugtraces.h"
    38 #include "debugtraces.h"
    39 
    39 
    40 //DEFINES
    40 //DEFINES
    41 #define RMODE_INSERT_ERROR hbTrId("Unable to insert. Object format not supported in restricted creation mode.")
    41 #define RMODE_INSERT_ERROR hbTrId("Unable to insert. Object format not supported in restricted creation mode.")
    42 #define INSERT_ERROR hbTrId("txt_messaging_dpopinfo_unable_to_attach_item_file")
    42 #define INSERT_ERROR hbTrId("txt_messaging_dpopinfo_unable_to_attach_item_file")
       
    43 #define INSERT_PROTECTED_ERROR hbTrId("txt_messaging_dpopinfo_unable_to_attach_protected")
    43 #define INSERT_QUERY_CONFRM hbTrId("The receiving phone may not support this object. Continue?")
    44 #define INSERT_QUERY_CONFRM hbTrId("The receiving phone may not support this object. Continue?")
    44 // -----------------------------------------------------------------------------
    45 // -----------------------------------------------------------------------------
    45 // MmsConformanceCheck::MmsConformanceCheck
    46 // MmsConformanceCheck::MmsConformanceCheck
    46 // -----------------------------------------------------------------------------
    47 // -----------------------------------------------------------------------------
    47 //
    48 //
    48 MmsConformanceCheck::MmsConformanceCheck()
    49 MmsConformanceCheck::MmsConformanceCheck()
    49 {
    50 {
    50     QDEBUG_WRITE("MmsConformanceCheck::MmsConformanceCheck start");
    51     QDEBUG_WRITE("MmsConformanceCheck::MmsConformanceCheck start");
    51 
    52 
    52     TRAP_IGNORE(        
    53     TRAP_IGNORE(
    53         CRepository* repository = CRepository::NewL(KCRUidMmsEngine);
    54         CRepository* repository = CRepository::NewL(KCRUidMmsEngine);
    54     CleanupStack::PushL(repository);
    55     CleanupStack::PushL(repository);
    55 
    56 
    56     //Fetch and set creation mode
    57     //Fetch and set creation mode
    57     TInt creationMode = EMmsCreationModeRestricted;
    58     TInt creationMode = EMmsCreationModeRestricted;
    61     //Fetch and set max mms composition size
    62     //Fetch and set max mms composition size
    62     TInt maxSize = KDefaultMaxSize;
    63     TInt maxSize = KDefaultMaxSize;
    63     repository->Get( KMmsEngineMaximumSendSize, maxSize );
    64     repository->Get( KMmsEngineMaximumSendSize, maxSize );
    64     iMaxMmsSize = maxSize;
    65     iMaxMmsSize = maxSize;
    65 
    66 
    66     CleanupStack::PopAndDestroy(repository);        
    67     CleanupStack::PopAndDestroy(repository);
    67     );
    68     );
    68 
    69 
    69     QDEBUG_WRITE("MmsConformanceCheck::MmsConformanceCheck end");
    70     QDEBUG_WRITE("MmsConformanceCheck::MmsConformanceCheck end");
    70 }
    71 }
    71 
    72 
    84 //
    85 //
    85 int MmsConformanceCheck::checkModeForInsert(const QString& file,
    86 int MmsConformanceCheck::checkModeForInsert(const QString& file,
    86     bool showNote)
    87     bool showNote)
    87 {
    88 {
    88     QDEBUG_WRITE("MmsConformanceCheck::CheckModeForInsert start");
    89     QDEBUG_WRITE("MmsConformanceCheck::CheckModeForInsert start");
    89     HBufC* filePath = S60QConversions::qStringToS60Desc(file);
    90     HBufC* filePath = XQConversions::qStringToS60Desc(file);
    90     if (filePath)
    91     if (filePath)
    91     {
    92     {
    92         CleanupStack::PushL(filePath);
    93         CleanupStack::PushL(filePath);
    93 
    94 
    94         CMmsConformance* mmsConformance = CMmsConformance::NewL();
    95         CMmsConformance* mmsConformance = CMmsConformance::NewL();
    95         mmsConformance->CheckCharacterSet(EFalse);
    96         mmsConformance->CheckCharacterSet(EFalse);
    96         
    97 
    97         CleanupStack::PushL(mmsConformance);
    98         CleanupStack::PushL(mmsConformance);
    98         
    99 
    99         CMsgMediaResolver* mediaResolver = CMsgMediaResolver::NewL();     
   100         CMsgMediaResolver* mediaResolver = CMsgMediaResolver::NewL();
   100         mediaResolver->SetCharacterSetRecognition(EFalse);
   101         mediaResolver->SetCharacterSetRecognition(EFalse);
   101         
   102 
   102         CleanupStack::PushL(mediaResolver);
   103         CleanupStack::PushL(mediaResolver);
   103         
   104 
   104         RFile fileHandle = mediaResolver->FileHandleL(*filePath);
   105         RFile fileHandle = mediaResolver->FileHandleL(*filePath);
   105         CleanupClosePushL(fileHandle);
   106         CleanupClosePushL(fileHandle);
   106 
   107 
   107         CMsgMediaInfo* info = mediaResolver->CreateMediaInfoL(fileHandle);
   108         CMsgMediaInfo* info = mediaResolver->CreateMediaInfoL(fileHandle);
   108         mediaResolver->ParseInfoDetailsL(info,fileHandle);
   109         mediaResolver->ParseInfoDetailsL(info,fileHandle);
   109         
   110 
   110         TMmsConformance conformance = mmsConformance->MediaConformance(*info);
   111         TMmsConformance conformance = mmsConformance->MediaConformance(*info);
   111         iConfStatus = conformance.iConfStatus;
   112         iConfStatus = conformance.iConfStatus;
   112 
   113 
   113         CleanupStack::PopAndDestroy(4);
   114         CleanupStack::PopAndDestroy(4);
   114 
   115 
   115         
   116 
   116         // In "free" mode user can insert images that are larger by dimensions than allowed by conformance
   117         // In "free" mode user can insert images that are larger by dimensions than allowed by conformance
   117         if (iCreationMode != EMmsCreationModeRestricted)
   118         if (iCreationMode != EMmsCreationModeRestricted)
   118         {
   119         {
   119             TInt i = EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded
   120             TInt i = EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded
   120                     | EMmsConfNokTooBig;
   121                     | EMmsConfNokTooBig;
   150         {
   151         {
   151             // Sanity check
   152             // Sanity check
   152             // "Not conformant" assumed if check fails.
   153             // "Not conformant" assumed if check fails.
   153             if(showNote)
   154             if(showNote)
   154             {
   155             {
   155                 showPopup(INSERT_ERROR);
   156                 // For protected objects.
       
   157                 if (EFileProtNoProtection != info->Protection())
       
   158                 {
       
   159                     showPopup(INSERT_PROTECTED_ERROR);
       
   160                 }
       
   161                 else
       
   162                 {
       
   163                     showPopup(INSERT_ERROR);
       
   164                 }
   156             }
   165             }
   157 
   166 
   158             return EInsertNotSupported;
   167             return EInsertNotSupported;
   159         }
   168         }
   160         delete info;
   169         delete info;
   161     }
   170     }
   162     QDEBUG_WRITE("MmsConformanceCheck::CheckModeForInsert end");
   171     QDEBUG_WRITE("MmsConformanceCheck::CheckModeForInsert end");
   163     return EInsertSuccess;
   172     return EInsertSuccess;
       
   173 }
       
   174 
       
   175 // ---------------------------------------------------------
       
   176 // MmsConformanceCheck::validateMsgForForward
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 bool MmsConformanceCheck::validateMsgForForward(int messageId)
       
   180 {
       
   181     UniDataModelLoader* pluginLoader = new UniDataModelLoader();
       
   182     UniDataModelPluginInterface* pluginInterface =
       
   183             pluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
       
   184     pluginInterface->setMessageId(messageId);
       
   185 
       
   186     //Check if slide count is greater than 1
       
   187     if (pluginInterface->slideCount() > 1)
       
   188     {
       
   189         delete pluginLoader;
       
   190         return false;
       
   191     }
       
   192 
       
   193     //Check if message size is inside max mms composition limits
       
   194     if (pluginInterface->messageSize() > iMaxMmsSize)
       
   195     {
       
   196         return false;
       
   197     }
       
   198 
       
   199     //If there is restricted content then return false
       
   200     UniMessageInfoList slideContentList = pluginInterface->slideContent(0);
       
   201     bool retValue = true;
       
   202 
       
   203     for (int i = 0; i < slideContentList.size(); ++i)
       
   204     {
       
   205         if (checkModeForInsert(slideContentList.at(i)->path(), false)
       
   206                 != EInsertSuccess)
       
   207         {
       
   208             retValue = false;
       
   209             break;
       
   210         }
       
   211     }
       
   212 
       
   213     foreach(UniMessageInfo *slide,slideContentList)
       
   214         {
       
   215             delete slide;
       
   216         }
       
   217 
       
   218     if (!retValue)
       
   219     {
       
   220         delete pluginLoader;
       
   221 
       
   222         return false;
       
   223     }
       
   224 
       
   225     UniMessageInfoList modelAttachmentList = pluginInterface->attachmentList();
       
   226 
       
   227     for (int i = 0; i < modelAttachmentList.count(); ++i)
       
   228     {
       
   229         if (checkModeForInsert(modelAttachmentList.at(i)->path(), false)
       
   230                 != EInsertSuccess)
       
   231         {
       
   232             retValue = false;
       
   233             break;
       
   234         }
       
   235     }
       
   236 
       
   237     foreach(UniMessageInfo *attachment,modelAttachmentList)
       
   238         {
       
   239             delete attachment;
       
   240         }
       
   241 
       
   242     delete pluginLoader;
       
   243 
       
   244     return retValue;
   164 }
   245 }
   165 
   246 
   166 // -----------------------------------------------------------------------------
   247 // -----------------------------------------------------------------------------
   167 // MmsConformanceCheck::onDialogInsertMedia
   248 // MmsConformanceCheck::onDialogInsertMedia
   168 // -----------------------------------------------------------------------------
   249 // -----------------------------------------------------------------------------