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