messagingapp/msgui/unifiedviewer/src/univiewerattachmentcontainer.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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "univiewerattachmentcontainer.h"
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include <QGraphicsLinearLayout>
       
    22 #include <QFileInfo>
       
    23 
       
    24 // USER INCLUDES
       
    25 #include "univiewermediawidget.h"
       
    26 #include "debugtraces.h"
       
    27 
       
    28 // LOCAL CONSTANTS
       
    29 const QString ATTACHMENT_FRAME("qtg_fr_groupbox");
       
    30 const QString ATTACHMENT_ICON("qtg_small_attachment.svg");
       
    31 
       
    32 const int KILOBYTE = 1024;
       
    33 
       
    34 //---------------------------------------------------------------
       
    35 // UniViewerAttachmentContainer :: UniViewerAttachmentContainer
       
    36 // @see header file
       
    37 //---------------------------------------------------------------
       
    38 UniViewerAttachmentContainer::UniViewerAttachmentContainer(QGraphicsItem *parent) :
       
    39     HbWidget(parent), mTotalAttachment(0), mMainLayout(NULL)
       
    40 {
       
    41     QDEBUG_WRITE("AttachmentContainer Initialized..");
       
    42     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    43     mMainLayout->setContentsMargins(0, 0, 0, 0);
       
    44     mMainLayout->setSpacing(0);
       
    45     setLayout(mMainLayout);
       
    46 }
       
    47 
       
    48 //---------------------------------------------------------------
       
    49 // UniViewerAttachmentContainer :: ~UniViewerAttachmentContainer
       
    50 // @see header file
       
    51 //---------------------------------------------------------------
       
    52 UniViewerAttachmentContainer::~UniViewerAttachmentContainer()
       
    53 {
       
    54 
       
    55 }
       
    56 
       
    57 //---------------------------------------------------------------
       
    58 // UniViewerAttachmentContainer :: addAttachmentWidget
       
    59 // @see header file
       
    60 //---------------------------------------------------------------
       
    61 void UniViewerAttachmentContainer::addAttachmentWidget(QString type, QString fileName)
       
    62 {
       
    63     Q_UNUSED(type)
       
    64 
       
    65     UniViewerMediaWidget *attachmentWidget = new UniViewerMediaWidget(this);
       
    66     mUniViewerMediaWidgetList.append(attachmentWidget);
       
    67     QFileInfo fileInfo(fileName);
       
    68 
       
    69     int fileSize = fileInfo.size();
       
    70     QString sizeString('B');
       
    71     if (fileSize > KILOBYTE) {
       
    72         // Convert to Kilobytes.
       
    73         fileSize /= KILOBYTE;
       
    74         sizeString = "Kb";
       
    75     }
       
    76 
       
    77     QString fileDetails = "(" + QString::number(fileSize) + sizeString + ")";
       
    78 
       
    79     attachmentWidget->populate(ATTACHMENT_ICON, fileInfo.fileName(), fileDetails, ATTACHMENT_FRAME);
       
    80 
       
    81     mMainLayout->addItem(attachmentWidget);
       
    82 
       
    83     mTotalAttachment++;
       
    84 }
       
    85 
       
    86 //---------------------------------------------------------------
       
    87 // UniViewerAttachmentContainer :: clearContent
       
    88 // @see header file
       
    89 //---------------------------------------------------------------
       
    90 void UniViewerAttachmentContainer::clearContent()
       
    91 {
       
    92     for (int i = 0; i < mUniViewerMediaWidgetList.count(); ++i) {
       
    93         --mTotalAttachment;
       
    94         mMainLayout->removeItem(mUniViewerMediaWidgetList[i]);
       
    95         mUniViewerMediaWidgetList[i]->setParent(NULL);
       
    96         delete mUniViewerMediaWidgetList[i];
       
    97         mUniViewerMediaWidgetList[i] = NULL;
       
    98     }
       
    99     mUniViewerMediaWidgetList.clear();
       
   100     resize(rect().width(), -1);
       
   101 }
       
   102 
       
   103 //eof