messagingapp/msgui/msguiutils/src/mmsconformancecheck.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 38 4e4b6adb1024
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    19 #include "mmsconformancecheck.h"
    19 #include "mmsconformancecheck.h"
    20 
    20 
    21 #include <MmsConformance.h>
    21 #include <MmsConformance.h>
    22 #include <centralrepository.h>
    22 #include <centralrepository.h>
    23 #include <mmsconst.h>
    23 #include <mmsconst.h>
    24 #include <msgmediainfo.h>
    24 #include <MsgMediaInfo.h>
    25 #include <fileprotectionresolver.h>
    25 #include <fileprotectionresolver.h>
    26 
    26 
    27 #include <MsgMediaResolver.h>
    27 #include <MsgMediaResolver.h>
    28 #include <DRMHelper.h>
    28 #include <DRMHelper.h>
    29 #include <MmsEngineInternalCRKeys.h>
    29 #include <MmsEngineInternalCRKeys.h>
    30 #include <hbmessagebox.h>
    30 #include <hbmessagebox.h>
    31 #include <hbnotificationdialog>
    31 #include <HbNotificationDialog>
       
    32 #include <hbaction.h>
    32 
    33 
    33 #include "unidatamodelloader.h"
    34 #include "unidatamodelloader.h"
    34 #include "unidatamodelplugininterface.h"
    35 #include "unidatamodelplugininterface.h"
    35 #include "unieditorgenutils.h" // This is needed for KDefaultMaxSize
    36 #include "UniEditorGenUtils.h" // This is needed for KDefaultMaxSize
    36 #include "s60qconversions.h"
    37 #include <xqconversions.h>
    37 #include "debugtraces.h"
    38 #include "debugtraces.h"
    38 
    39 
    39 //DEFINES
    40 //DEFINES
    40 #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.")
    41 #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")
    42 #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?")
    43 // -----------------------------------------------------------------------------
    45 // -----------------------------------------------------------------------------
    44 // MmsConformanceCheck::MmsConformanceCheck
    46 // MmsConformanceCheck::MmsConformanceCheck
    45 // -----------------------------------------------------------------------------
    47 // -----------------------------------------------------------------------------
    46 //
    48 //
    47 MmsConformanceCheck::MmsConformanceCheck()
    49 MmsConformanceCheck::MmsConformanceCheck()
    48 {
    50 {
    49     QDEBUG_WRITE("MmsConformanceCheck::MmsConformanceCheck start");
    51     QDEBUG_WRITE("MmsConformanceCheck::MmsConformanceCheck start");
    50 
    52 
    51     TRAP_IGNORE(        
    53     TRAP_IGNORE(
    52         CRepository* repository = CRepository::NewL(KCRUidMmsEngine);
    54         CRepository* repository = CRepository::NewL(KCRUidMmsEngine);
    53     CleanupStack::PushL(repository);
    55     CleanupStack::PushL(repository);
    54 
    56 
    55     //Fetch and set creation mode
    57     //Fetch and set creation mode
    56     TInt creationMode = EMmsCreationModeRestricted;
    58     TInt creationMode = EMmsCreationModeRestricted;
    60     //Fetch and set max mms composition size
    62     //Fetch and set max mms composition size
    61     TInt maxSize = KDefaultMaxSize;
    63     TInt maxSize = KDefaultMaxSize;
    62     repository->Get( KMmsEngineMaximumSendSize, maxSize );
    64     repository->Get( KMmsEngineMaximumSendSize, maxSize );
    63     iMaxMmsSize = maxSize;
    65     iMaxMmsSize = maxSize;
    64 
    66 
    65     CleanupStack::PopAndDestroy(repository);        
    67     CleanupStack::PopAndDestroy(repository);
    66     );
    68     );
    67 
    69 
    68     QDEBUG_WRITE("MmsConformanceCheck::MmsConformanceCheck end");
    70     QDEBUG_WRITE("MmsConformanceCheck::MmsConformanceCheck end");
    69 }
    71 }
    70 
    72 
    83 //
    85 //
    84 int MmsConformanceCheck::checkModeForInsert(const QString& file,
    86 int MmsConformanceCheck::checkModeForInsert(const QString& file,
    85     bool showNote)
    87     bool showNote)
    86 {
    88 {
    87     QDEBUG_WRITE("MmsConformanceCheck::CheckModeForInsert start");
    89     QDEBUG_WRITE("MmsConformanceCheck::CheckModeForInsert start");
    88     HBufC* filePath = S60QConversions::qStringToS60Desc(file);
    90     HBufC* filePath = XQConversions::qStringToS60Desc(file);
    89     if (filePath)
    91     if (filePath)
    90     {
    92     {
    91         CleanupStack::PushL(filePath);
    93         CleanupStack::PushL(filePath);
    92 
    94 
    93         CMmsConformance* mmsConformance = CMmsConformance::NewL();
    95         CMmsConformance* mmsConformance = CMmsConformance::NewL();
    94         mmsConformance->CheckCharacterSet(EFalse);
    96         mmsConformance->CheckCharacterSet(EFalse);
    95         
    97 
    96         CleanupStack::PushL(mmsConformance);
    98         CleanupStack::PushL(mmsConformance);
    97         
    99 
    98         CMsgMediaResolver* mediaResolver = CMsgMediaResolver::NewL();     
   100         CMsgMediaResolver* mediaResolver = CMsgMediaResolver::NewL();
    99         mediaResolver->SetCharacterSetRecognition(EFalse);
   101         mediaResolver->SetCharacterSetRecognition(EFalse);
   100         
   102 
   101         CleanupStack::PushL(mediaResolver);
   103         CleanupStack::PushL(mediaResolver);
   102         
   104 
   103         RFile fileHandle = mediaResolver->FileHandleL(*filePath);
   105         RFile fileHandle = mediaResolver->FileHandleL(*filePath);
   104         CleanupClosePushL(fileHandle);
   106         CleanupClosePushL(fileHandle);
   105 
   107 
   106         CMsgMediaInfo* info = mediaResolver->CreateMediaInfoL(fileHandle);
   108         CMsgMediaInfo* info = mediaResolver->CreateMediaInfoL(fileHandle);
   107         mediaResolver->ParseInfoDetailsL(info,fileHandle);
   109         mediaResolver->ParseInfoDetailsL(info,fileHandle);
   108         
   110 
   109         TMmsConformance conformance = mmsConformance->MediaConformance(*info);
   111         TMmsConformance conformance = mmsConformance->MediaConformance(*info);
   110         TUint32 confStatus = conformance.iConfStatus;
   112         iConfStatus = conformance.iConfStatus;
   111 
   113 
   112         CleanupStack::PopAndDestroy(4);
   114         CleanupStack::PopAndDestroy(4);
   113 
   115 
   114         
   116 
   115         // 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
   116         if (iCreationMode != EMmsCreationModeRestricted)
   118         if (iCreationMode != EMmsCreationModeRestricted)
   117         {
   119         {
   118             TInt i = EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded
   120             TInt i = EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded
   119                     | EMmsConfNokTooBig;
   121                     | EMmsConfNokTooBig;
   120             TInt j = ~ (EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded
   122             TInt j = ~ (EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded
   121                     | EMmsConfNokTooBig);
   123                     | EMmsConfNokTooBig);
   122 
   124 
   123             // If user answers yes to Guided mode confirmation query he/she moves to free mode
   125             // If user answers yes to Guided mode confirmation query he/she moves to free mode
   124             if ( (confStatus & i) && ! (confStatus & j))
   126             if ( (iConfStatus & i) && ! (iConfStatus & j))
   125             {
   127             {
   126                 if (iCreationMode == EMmsCreationModeFree || info->Protection()
   128                 if (iCreationMode == EMmsCreationModeFree || info->Protection()
   127                         & EFileProtSuperDistributable)
   129                         & EFileProtSuperDistributable)
   128                 {
   130                 {
   129                     // SuperDistribution not checked here
   131                     // SuperDistribution not checked here
   130                     // Mask "FreeModeOnly" and "ScalingNeeded" away in free mode
   132                     // Mask "FreeModeOnly" and "ScalingNeeded" away in free mode
   131                     confStatus &= ~EMmsConfNokFreeModeOnly;
   133                     iConfStatus &= ~EMmsConfNokFreeModeOnly;
   132                     confStatus &= ~EMmsConfNokScalingNeeded;
   134                     iConfStatus &= ~EMmsConfNokScalingNeeded;
   133                 }
   135                 }
   134                 else if (showNote && launchEditorQuery())
   136                 else if (showNote)
   135                 {
   137                 {
   136                     // Query accepted.
   138                     HbMessageBox::question(INSERT_QUERY_CONFRM, this,
   137                     // Mask "FreeModeOnly" and "ScalingNeeded" away in free mode
   139                                            SLOT(onDialogInsertMedia(HbAction*)),
   138                     confStatus &= ~EMmsConfNokFreeModeOnly;
   140                                            HbMessageBox::Yes | HbMessageBox::No);
   139                     confStatus &= ~EMmsConfNokScalingNeeded;
       
   140                 }
   141                 }
   141                 else
   142                 else
   142                 {
   143                 {
   143                     //query not accepted. Stop insertion.
   144                     //query not accepted. Stop insertion.
   144                     return EInsertQueryAbort;
   145                     return EInsertQueryAbort;
   145                 }
   146                 }
   146             }
   147             }
   147         }
   148         }
   148         else if (confStatus & EMmsConfNokDRM || confStatus
   149         else if (iConfStatus & EMmsConfNokDRM || iConfStatus
   149                 & EMmsConfNokNotEnoughInfo || confStatus
   150                 & EMmsConfNokNotEnoughInfo || iConfStatus
   150                 & EMmsConfNokNotSupported || confStatus
   151                 & EMmsConfNokNotSupported || iConfStatus
   151                 & EMmsConfNokFreeModeOnly || confStatus & EMmsConfNokCorrupt)
   152                 & EMmsConfNokFreeModeOnly || iConfStatus & EMmsConfNokCorrupt)
   152         {
   153         {
   153             // Sanity check
   154             // Sanity check
   154             // "Not conformant" assumed if check fails.
   155             // "Not conformant" assumed if check fails.
   155             if(showNote)
   156             if(showNote)
   156             {
   157             {
   157                 showPopup(INSERT_ERROR);
   158                 // For protected objects.
       
   159                 if (EFileProtNoProtection != info->Protection())
       
   160                 {
       
   161                     showPopup(INSERT_PROTECTED_ERROR);
       
   162                 }
       
   163                 else
       
   164                 {
       
   165                     showPopup(INSERT_ERROR);
       
   166                 }
   158             }
   167             }
   159 
   168 
   160             return EInsertNotSupported;
   169             return EInsertNotSupported;
   161         }
   170         }
   162         delete info;
   171         delete info;
   172 bool MmsConformanceCheck::validateMsgForForward(int messageId)
   181 bool MmsConformanceCheck::validateMsgForForward(int messageId)
   173 {
   182 {
   174     UniDataModelLoader* pluginLoader = new UniDataModelLoader();
   183     UniDataModelLoader* pluginLoader = new UniDataModelLoader();
   175     UniDataModelPluginInterface* pluginInterface =
   184     UniDataModelPluginInterface* pluginInterface =
   176             pluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
   185             pluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
   177     pluginInterface->setMessageId(messageId);
   186     int id = pluginInterface->setMessageId(messageId);
   178 
   187 
   179     //Check if slide count is greater than 1
   188     //Check if invalid id and slide count is greater than 1
   180     if (pluginInterface->slideCount() > 1)
   189     if ( ( id <= 0 ) ||
       
   190          (pluginInterface->slideCount() > 1) )
   181     {
   191     {
   182         delete pluginLoader;
   192         delete pluginLoader;
   183         return false;
   193         return false;
   184     }
   194     }
   185 
   195 
   186     //Check if message size is inside max mms composition limits 
   196     //Check if message size is inside max mms composition limits
   187     if (pluginInterface->messageSize() > iMaxMmsSize)
   197     if (pluginInterface->messageSize() > iMaxMmsSize)
   188     {
   198     {
       
   199         delete pluginLoader;
   189         return false;
   200         return false;
   190     }
   201     }
   191 
   202 
   192     //If there is restricted content then return false
   203     //If there is restricted content then return false
   193     UniMessageInfoList slideContentList = pluginInterface->slideContent(0);
   204     UniMessageInfoList slideContentList = pluginInterface->slideContent(0);
   209         }
   220         }
   210 
   221 
   211     if (!retValue)
   222     if (!retValue)
   212     {
   223     {
   213         delete pluginLoader;
   224         delete pluginLoader;
   214 
       
   215         return false;
   225         return false;
   216     }
   226     }
   217 
   227 
   218     UniMessageInfoList modelAttachmentList = pluginInterface->attachmentList();
   228     UniMessageInfoList modelAttachmentList = pluginInterface->attachmentList();
   219 
   229 
   231         {
   241         {
   232             delete attachment;
   242             delete attachment;
   233         }
   243         }
   234 
   244 
   235     delete pluginLoader;
   245     delete pluginLoader;
   236 
       
   237     return retValue;
   246     return retValue;
   238 }
   247 }
   239 
   248 
   240 // ---------------------------------------------------------
   249 // -----------------------------------------------------------------------------
   241 // MmsConformanceCheck::launchEditorQuery
   250 // MmsConformanceCheck::onDialogInsertMedia
   242 // ---------------------------------------------------------
   251 // -----------------------------------------------------------------------------
   243 //
   252 //
   244 bool MmsConformanceCheck::launchEditorQuery()
   253 void MmsConformanceCheck::onDialogInsertMedia(HbAction* action)
   245 {
   254 {
   246     return HbMessageBox::question(INSERT_QUERY_CONFRM);
   255     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   256     if (action == dlg->actions().at(0)) {
       
   257         // Query accepted.
       
   258         // Mask "FreeModeOnly" and "ScalingNeeded" away in free mode
       
   259         iConfStatus &= ~EMmsConfNokFreeModeOnly;
       
   260         iConfStatus &= ~EMmsConfNokScalingNeeded;
       
   261     }
       
   262 
   247 }
   263 }
   248 
   264 
   249 // -----------------------------------------------------------------------------
   265 // -----------------------------------------------------------------------------
   250 // MmsConformanceCheck::showPopup
   266 // MmsConformanceCheck::showPopup
   251 // -----------------------------------------------------------------------------
   267 // -----------------------------------------------------------------------------