diff -r 238255e8b033 -r 84d9eb65b26f messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp --- a/messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp Fri Apr 16 14:56:15 2010 +0300 +++ b/messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp Mon May 03 12:29:07 2010 +0300 @@ -21,10 +21,14 @@ #include #include #include -#include #include #include #include +#include +#include +#include +#include +#include // USER INCLUDES #include "msgunieditorattachment.h" @@ -35,6 +39,16 @@ #define BYTES_TO_KBYTES_FACTOR 1024 #define BG_FRAME "qtg_fr_groupbox" +//Localized Constants for item specific menu +#define LOC_OPEN hbTrId("txt_common_menu_open") +#define LOC_REMOVE hbTrId("txt_common_menu_remove") +#define LOC_DETAILS hbTrId("txt_common_menu_details") + +const QString LIST_ITEM_BG_FRAME_NORMAL ("qtg_fr_list_normal"); +const QString LIST_ITEM_BG_FRAME_PRESSED("qtg_fr_list_pressed"); + +const QString ATTACHMENT_ICON("qtg_small_attachment"); + MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& pluginPath, const QString& attachmentpath, const int filesize, @@ -46,62 +60,71 @@ mMimeType(QString()), mAttachmentIcon(0), mAttachmentName(0), -mFrameItem(0) +mGestureFilter(0), +mMaxSmsSize(KFirstNormalSmsLength) { #ifdef _DEBUG_TRACES_ qDebug() << "MsgUnifiedEditorAttachment calling HbStyle::registerPlugin"; #endif - + setPluginBaseId(style()->registerPlugin(mPluginPath)); + + //back ground + HbFrameItem* backGround = new HbFrameItem(this); + backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL); + backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); + this->setBackgroundItem(backGround); - mAttachmentIcon = new HbIconItem(":/qtg_small_attachment.svg", this); + mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this); HbStyle::setItemName(mAttachmentIcon,"attachmentIcon"); - // TODO: use utility to get mimetype and size int at_size = 0; TMsgMediaType mediaType = EMsgMediaUnknown; UniEditorGenUtils* genUtils = new UniEditorGenUtils; TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size, mMimeType,mediaType)); + TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); delete genUtils; QFileInfo fileinfo(attachmentpath); QString filename = fileinfo.fileName(); mAttachmentName = new HbTextItem(filename,this); HbStyle::setItemName(mAttachmentName,"attachmentName"); mAttachmentName->setElideMode(Qt::ElideRight); - - int sizeInKb = mSize/BYTES_TO_KBYTES_FACTOR; + + // for sms, pure size should be shown + // for mms, additional mimeheader size must be included + qreal displaySize = mSize; + if(!isMultimediaContent()) + { + displaySize = fileinfo.size(); + } + int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR; QString fileDetails; - if(sizeInKb > 1) + // if size exceeds 1kb, then show kb or else only bytes + if(sizeInKb >= 1) { fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb)); } else { - fileDetails = QString().append(QString("(%1 B)").arg(mSize)); + fileDetails = QString().append(QString("(%1 B)").arg(displaySize)); } mAttachmentDetails = new HbTextItem(fileDetails, this); HbStyle::setItemName(mAttachmentDetails,"attachmentDetails"); mAttachmentDetails->setElideMode(Qt::ElideNone); - - // set underlined font - QFont underlinedFont(this->font()); - underlinedFont.setUnderline(true); - mAttachmentName->setFont(underlinedFont); - mAttachmentDetails->setFont(underlinedFont); - - mFrameItem = new HbPushButton(this); - HbStyle::setItemName(mFrameItem, "bgFrame"); - HbFrameDrawer *fd = new HbFrameDrawer(BG_FRAME, HbFrameDrawer::NinePieces); - mFrameItem->setFrameBackground(fd); - connect(mFrameItem, SIGNAL(clicked(bool)), this, SIGNAL(clicked())); - connect(mFrameItem, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF))); + + initGesture(); } MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment() { style()->unregisterPlugin(mPluginPath); + + if(mGestureFilter) + { + removeSceneEventFilter(mGestureFilter); + } } const QString& MsgUnifiedEditorAttachment::path() @@ -122,9 +145,9 @@ void MsgUnifiedEditorAttachment::longPressed(QPointF position) { HbMenu* menu = new HbMenu; - menu->addAction(tr("Open"), this, SLOT(openAttachment())); - menu->addAction(tr("Remove"), this, SLOT(removeAttachment())); - menu->addAction(tr("View details"), this, SLOT(viewDetails())); + menu->addAction(LOC_OPEN, this, SLOT(openAttachment())); + menu->addAction(LOC_REMOVE, this, SLOT(removeAttachment())); + menu->addAction(LOC_DETAILS, this, SLOT(viewDetails())); menu->setDismissPolicy(HbPopup::TapAnywhere); menu->setAttribute(Qt::WA_DeleteOnClose, true); menu->setPreferredPos(position); @@ -156,10 +179,74 @@ !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) || !QString::compare(mMimeType, ical, Qt::CaseInsensitive) ) { - // vcard, vcal are not mm content - ret = false; + QFileInfo fileinfo(mPath); + int fSize = fileinfo.size(); + + // if filesize is within sms size-limit, then + // it is not mm content, else it is mm attachment + if(fSize <= mMaxSmsSize) + { + ret = false; + } } return ret; } +void MsgUnifiedEditorAttachment::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + HbWidgetFeedback::triggered(this, Hb::InstantPressed); + + HbFrameItem* backGround = new HbFrameItem(this); + backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED); + backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); + this->setBackgroundItem(backGround); + + event->accept(); +} + +void MsgUnifiedEditorAttachment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + HbFrameItem* backGround = new HbFrameItem(this); + backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL); + backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); + this->setBackgroundItem(backGround); + + if(this->rect().contains(event->pos())) + { + HbWidgetFeedback::triggered(this, Hb::InstantClicked); + emit clicked(); + } + + event->accept(); +} + +void MsgUnifiedEditorAttachment::initGesture() +{ + // Create gesture filter + mGestureFilter = new HbGestureSceneFilter( Qt::LeftButton, this ); + + // Add gestures for longpress + HbGesture* gestureLongpressed = new HbGesture( HbGesture::longpress,5 ); + + mGestureFilter->addGesture( gestureLongpressed ); + + connect( gestureLongpressed, SIGNAL(longPress(QPointF)), + this, SLOT(longPressed(QPointF)) ); + + //install gesture filter. + this->installSceneEventFilter(mGestureFilter); +} + +HbFeedback::InstantEffect MsgUnifiedEditorAttachment::overrideFeedback(Hb::InstantInteraction interaction) const + { + switch(interaction) + { + case Hb::InstantPressed: + case Hb::InstantClicked: + return HbFeedback::Basic; + default: + return HbFeedback::NoOverride; + } + } + // EOF