messagingapp/msgui/unifiededitor/src/msgunieditorattachmentcontainer.cpp
changeset 37 518b245aa84c
child 76 60a8a215b0ec
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
       
     1 /*
       
     2  * Copyright (c) 2009 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: attachment container class
       
    15  *
       
    16  */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <QGraphicsLinearLayout>
       
    21 #include <QFileInfo>
       
    22 #include <HbFrameItem>
       
    23 #include <HbFrameDrawer>
       
    24 
       
    25 // USER INCLUDES
       
    26 #include "msgunieditorattachmentcontainer.h"
       
    27 #include "UniEditorGenUtils.h"
       
    28 #include "msgunieditormonitor.h"
       
    29 #include "mmsconformancecheck.h"
       
    30 
       
    31 // Constants
       
    32 
       
    33 //---------------------------------------------------------------
       
    34 // MsgAttachmentContainer::MsgAttachmentContainer
       
    35 // @see header file
       
    36 //---------------------------------------------------------------
       
    37 MsgAttachmentContainer::MsgAttachmentContainer( QGraphicsItem *parent ) :
       
    38 HbWidget(parent),
       
    39 mIsMMContent(false)
       
    40 {
       
    41     mLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
       
    42     mLayout->setContentsMargins(0,0,0,0);
       
    43     mLayout->setSpacing(0);
       
    44     mMmsConformanceCheck = new MmsConformanceCheck;
       
    45 }
       
    46 
       
    47 //---------------------------------------------------------------
       
    48 // MsgAttachmentContainer::~MsgAttachmentContainer
       
    49 // @see header file
       
    50 //---------------------------------------------------------------
       
    51 MsgAttachmentContainer::~MsgAttachmentContainer()
       
    52 {
       
    53     delete mMmsConformanceCheck;
       
    54 }
       
    55 
       
    56 //---------------------------------------------------------------
       
    57 // MsgAttachmentContainer::addAttachment
       
    58 // @see header file
       
    59 //---------------------------------------------------------------
       
    60 MsgAttachmentContainer::AddAttachmentStatus 
       
    61     MsgAttachmentContainer::addAttachment(const QString& filepath)
       
    62 {
       
    63     //check for insert conformance
       
    64     if(EInsertSuccess != mMmsConformanceCheck->checkModeForInsert(filepath))
       
    65         return EAddNotSupported;
       
    66 
       
    67     int msgSize = messageSize();
       
    68     QFileInfo fileinfo(filepath);
       
    69     int fileSize = fileinfo.size() + KEstimatedMimeHeaderSize;
       
    70     
       
    71     if( (fileSize + msgSize) <= MsgUnifiedEditorMonitor::maxMmsSize())
       
    72     {
       
    73         MsgUnifiedEditorAttachment* att = new MsgUnifiedEditorAttachment(
       
    74             filepath, fileSize, this);
       
    75         if( ((mAttachmentList.count() == 0) && att->isMultimediaContent()) ||
       
    76                 ((mAttachmentList.count() == 1) && !mIsMMContent) )
       
    77         {
       
    78             mIsMMContent = true;
       
    79         }
       
    80         mAttachmentList << att;
       
    81         int index = mLayout->count();
       
    82         mLayout->insertItem(index,att);
       
    83         connect(att, SIGNAL(deleteMe(MsgUnifiedEditorAttachment*)),
       
    84             this, SLOT(deleteAttachment(MsgUnifiedEditorAttachment*)));
       
    85 
       
    86         // emit to signal that container content & size changed
       
    87         emit contentChanged();
       
    88     }
       
    89     else
       
    90     {
       
    91         return EAddSizeExceed;
       
    92     }
       
    93     return EAddSuccess;
       
    94 }
       
    95 
       
    96 //---------------------------------------------------------------
       
    97 // MsgAttachmentContainer::deleteAttachment
       
    98 // @see header file
       
    99 //---------------------------------------------------------------
       
   100 void MsgAttachmentContainer::deleteAttachment(MsgUnifiedEditorAttachment* attachment)
       
   101 {
       
   102     mAttachmentList.removeOne(attachment);
       
   103     mLayout->removeItem(attachment);
       
   104     attachment->setParent(NULL);
       
   105     delete attachment;
       
   106 
       
   107     if( ((mAttachmentList.count() == 1) && !mAttachmentList.first()->isMultimediaContent()) ||
       
   108         ((mAttachmentList.count() == 0) && mIsMMContent) )
       
   109     {
       
   110         mIsMMContent = false;
       
   111     }
       
   112 
       
   113     // emit to indicate change in container content & size
       
   114     emit contentChanged();
       
   115     if(mAttachmentList.count() == 0)
       
   116     {
       
   117         emit emptyAttachmentContainer();
       
   118     }
       
   119 }
       
   120 
       
   121 //---------------------------------------------------------------
       
   122 // MsgAttachmentContainer::count
       
   123 // @see header file
       
   124 //---------------------------------------------------------------
       
   125 int MsgAttachmentContainer::count()
       
   126 {
       
   127     return mAttachmentList.count();
       
   128 }
       
   129 
       
   130 //---------------------------------------------------------------
       
   131 // MsgAttachmentContainer::attachmentList
       
   132 // @see header file
       
   133 //---------------------------------------------------------------
       
   134 MsgUnifiedEditorAttachmentList MsgAttachmentContainer::attachmentList()
       
   135 {
       
   136     return mAttachmentList;
       
   137 }
       
   138 
       
   139 //---------------------------------------------------------------
       
   140 // MsgAttachmentContainer::containerSize
       
   141 // @see header file
       
   142 //---------------------------------------------------------------
       
   143 int MsgAttachmentContainer::containerSize()
       
   144 {
       
   145     int attCount = count();
       
   146     int containerSize = 0;
       
   147     
       
   148     for(int i=0; i<attCount; i++)
       
   149     {
       
   150         containerSize += mAttachmentList.at(i)->size();
       
   151     }
       
   152     return containerSize;
       
   153 }
       
   154 
       
   155 //---------------------------------------------------------------
       
   156 // MsgAttachmentContainer::messageSize
       
   157 // @see header file
       
   158 //---------------------------------------------------------------
       
   159 int MsgAttachmentContainer::messageSize()
       
   160 {
       
   161     return containerSize() + MsgUnifiedEditorMonitor::bodySize() + MsgUnifiedEditorMonitor::subjectSize();
       
   162 }
       
   163 
       
   164 //---------------------------------------------------------------
       
   165 // MsgAttachmentContainer::hasMMContent
       
   166 // @see header file
       
   167 //---------------------------------------------------------------
       
   168 bool MsgAttachmentContainer::hasMMContent()
       
   169 {
       
   170     return mIsMMContent;
       
   171 }
       
   172 
       
   173 //EOF
       
   174