diff -r e7aa27f58ae1 -r 578830873419 emailuis/nmailui/src/nmattachmentlist.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emailuis/nmailui/src/nmattachmentlist.cpp Fri Apr 16 14:51:52 2010 +0300 @@ -0,0 +1,215 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Class for handling the attachment list +* +*/ + +#include "nmuiheaders.h" + +/*! + \class NmAttachmentList + \brief Class for handling the attachment list +*/ + +/*! + Constructor +*/ +NmAttachmentList::NmAttachmentList(NmAttachmentListWidget *listWidget) +: mListWidget(listWidget) +{ + updateLayout(); +} + +/*! + Destructor +*/ +NmAttachmentList::~NmAttachmentList() +{ + clearList(); +} + +/*! + Insert new list item. Returns the count of the attachment in list +*/ +int NmAttachmentList::insertAttachment( + const QString &fullFileName, + const QString &fileSize, + const NmId &attachmentPartId) +{ + QString displayName = fullNameToDisplayName(fullFileName); + mFullFileName.append(fullFileName); + mDisplayFileName.append(displayName); + mAttachmentPartId.append(attachmentPartId); + mFileSize.append(fileSize); + mListWidget->insertAttachment(count() - 1, displayName, createSizeString(fileSize)); + updateLayout(); + return count() - 1; +} + +/*! + Set attachmentPartId of the list item. Because there can be several attachments with + same filename, function will search the one which nmid is not set. +*/ +void NmAttachmentList::setAttachmentPartId(const QString fullFileName, const NmId &attachmentPartId) +{ + for (int i=0; iremoveAttachment(arrayIndex); + // Remove from data structure + mFullFileName.removeAt(arrayIndex); + mDisplayFileName.removeAt(arrayIndex); + mAttachmentPartId.removeAt(arrayIndex); + updateLayout(); + } +} + +/*! + Remove attachment which have same fullFileName from list +*/ +void NmAttachmentList::removeAttachment(const QString &fullFileName) +{ + for (int i=0; i=0; --i) { + // Remove from UI + mListWidget->removeAttachment(i); + // Remove from data structure + mFullFileName.removeAt(i); + mDisplayFileName.removeAt(i); + mAttachmentPartId.removeAt(i); + updateLayout(); + } +} + +/*! + Return attachment list widget +*/ +NmAttachmentListWidget* NmAttachmentList::listWidget() +{ + return mListWidget; +} + +/*! + Return attachment count +*/ +int NmAttachmentList::count() +{ + return mFullFileName.count(); +} + +/*! + Return attachment part id +*/ +NmId NmAttachmentList::nmIdByIndex(int listIndex) +{ + return mAttachmentPartId.at(listIndex); +} + +/*! + Return array index of attachment +*/ +int NmAttachmentList::indexByNmId(const NmId &id) +{ + for (int i=0; isetMaximumHeight(count() * 29); + QTimer::singleShot(1, this, SLOT(delayedLayoutChangeInfo())); +} + +/*! + Send delayed signal about attachment list layout change +*/ +void NmAttachmentList::delayedLayoutChangeInfo() +{ + emit attachmentListLayoutChanged(); +}