messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
    19 #include "debugtraces.h"
    19 #include "debugtraces.h"
    20 #include <HbTextItem>
    20 #include <HbTextItem>
    21 #include <HbIconItem>
    21 #include <HbIconItem>
    22 #include <QFileInfo>
    22 #include <QFileInfo>
    23 #include <QFont>
    23 #include <QFont>
    24 #include <HbPushButton>
       
    25 #include <HbFrameDrawer>
    24 #include <HbFrameDrawer>
    26 #include <HbMenu>
    25 #include <HbMenu>
    27 #include <MsgMimeTypes.h>
    26 #include <MsgMimeTypes.h>
       
    27 #include <HbFrameItem>
       
    28 #include <HbGestureSceneFilter>
       
    29 #include <HbGesture>
       
    30 #include <QGraphicsSceneMouseEvent>
       
    31 #include <HbWidgetFeedback>
    28 
    32 
    29 // USER INCLUDES
    33 // USER INCLUDES
    30 #include "msgunieditorattachment.h"
    34 #include "msgunieditorattachment.h"
    31 #include "unieditorgenutils.h"
    35 #include "unieditorgenutils.h"
    32 #include "s60qconversions.h"
    36 #include "s60qconversions.h"
    33 
    37 
    34 // Constants
    38 // Constants
    35 #define BYTES_TO_KBYTES_FACTOR 1024
    39 #define BYTES_TO_KBYTES_FACTOR 1024
    36 #define BG_FRAME "qtg_fr_groupbox"
    40 #define BG_FRAME "qtg_fr_groupbox"
       
    41 
       
    42 //Localized Constants for item specific menu
       
    43 #define LOC_OPEN    hbTrId("txt_common_menu_open")
       
    44 #define LOC_REMOVE  hbTrId("txt_common_menu_remove")
       
    45 #define LOC_DETAILS hbTrId("txt_common_menu_details")
       
    46 
       
    47 const QString LIST_ITEM_BG_FRAME_NORMAL ("qtg_fr_list_normal");
       
    48 const QString LIST_ITEM_BG_FRAME_PRESSED("qtg_fr_list_pressed");
       
    49 
       
    50 const QString ATTACHMENT_ICON("qtg_small_attachment");
    37 
    51 
    38 MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& pluginPath,
    52 MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& pluginPath,
    39                                                         const QString& attachmentpath,
    53                                                         const QString& attachmentpath,
    40                                                         const int filesize,
    54                                                         const int filesize,
    41                                                         QGraphicsItem *parent ) :
    55                                                         QGraphicsItem *parent ) :
    44 mPath(attachmentpath),
    58 mPath(attachmentpath),
    45 mSize(filesize),
    59 mSize(filesize),
    46 mMimeType(QString()),
    60 mMimeType(QString()),
    47 mAttachmentIcon(0),
    61 mAttachmentIcon(0),
    48 mAttachmentName(0),
    62 mAttachmentName(0),
    49 mFrameItem(0)
    63 mGestureFilter(0),
       
    64 mMaxSmsSize(KFirstNormalSmsLength)
    50 {
    65 {
    51 #ifdef _DEBUG_TRACES_
    66 #ifdef _DEBUG_TRACES_
    52     qDebug() << "MsgUnifiedEditorAttachment calling HbStyle::registerPlugin";
    67     qDebug() << "MsgUnifiedEditorAttachment calling HbStyle::registerPlugin";
    53 #endif
    68 #endif
    54 
    69     
    55         setPluginBaseId(style()->registerPlugin(mPluginPath));
    70         setPluginBaseId(style()->registerPlugin(mPluginPath));
    56 
    71 		     
    57         mAttachmentIcon = new HbIconItem(":/qtg_small_attachment.svg", this);
    72         //back ground
       
    73         HbFrameItem* backGround = new HbFrameItem(this);
       
    74         backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
       
    75         backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
    76         this->setBackgroundItem(backGround);        
       
    77 
       
    78         mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this);
    58         HbStyle::setItemName(mAttachmentIcon,"attachmentIcon");
    79         HbStyle::setItemName(mAttachmentIcon,"attachmentIcon");
    59 
    80 
    60         // TODO: use utility to get mimetype and size
       
    61         int at_size = 0;
    81         int at_size = 0;
    62         TMsgMediaType mediaType = EMsgMediaUnknown;
    82         TMsgMediaType mediaType = EMsgMediaUnknown;
    63         UniEditorGenUtils* genUtils = new UniEditorGenUtils;
    83         UniEditorGenUtils* genUtils = new UniEditorGenUtils;
    64         TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size,
    84         TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size,
    65                                            mMimeType,mediaType));
    85                                            mMimeType,mediaType));
       
    86         TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); 
    66         delete genUtils;
    87         delete genUtils;
    67         QFileInfo fileinfo(attachmentpath);
    88         QFileInfo fileinfo(attachmentpath);
    68         QString filename = fileinfo.fileName();
    89         QString filename = fileinfo.fileName();
    69         mAttachmentName = new HbTextItem(filename,this);
    90         mAttachmentName = new HbTextItem(filename,this);
    70         HbStyle::setItemName(mAttachmentName,"attachmentName");
    91         HbStyle::setItemName(mAttachmentName,"attachmentName");
    71         mAttachmentName->setElideMode(Qt::ElideRight);
    92         mAttachmentName->setElideMode(Qt::ElideRight);
    72 
    93         
    73         int sizeInKb = mSize/BYTES_TO_KBYTES_FACTOR;
    94         // for sms, pure size should be shown
       
    95         // for mms, additional mimeheader size must be included
       
    96         qreal displaySize = mSize;
       
    97         if(!isMultimediaContent())
       
    98         {
       
    99             displaySize = fileinfo.size();
       
   100         }
       
   101         int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR;
    74         QString fileDetails;
   102         QString fileDetails;
    75         if(sizeInKb > 1)
   103         // if size exceeds 1kb, then show kb or else only bytes
       
   104         if(sizeInKb >= 1)
    76         {
   105         {
    77             fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb));
   106             fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb));
    78         }
   107         }
    79         else
   108         else
    80         {
   109         {
    81             fileDetails = QString().append(QString("(%1 B)").arg(mSize));
   110             fileDetails = QString().append(QString("(%1 B)").arg(displaySize));
    82         }
   111         }
    83 
   112 
    84         mAttachmentDetails = new HbTextItem(fileDetails, this);
   113         mAttachmentDetails = new HbTextItem(fileDetails, this);
    85         HbStyle::setItemName(mAttachmentDetails,"attachmentDetails");
   114         HbStyle::setItemName(mAttachmentDetails,"attachmentDetails");
    86         mAttachmentDetails->setElideMode(Qt::ElideNone);
   115         mAttachmentDetails->setElideMode(Qt::ElideNone);
    87 
   116         
    88         // set underlined font
   117         initGesture();
    89         QFont underlinedFont(this->font());
       
    90         underlinedFont.setUnderline(true);
       
    91         mAttachmentName->setFont(underlinedFont);
       
    92         mAttachmentDetails->setFont(underlinedFont);
       
    93 
       
    94         mFrameItem = new HbPushButton(this);
       
    95         HbStyle::setItemName(mFrameItem, "bgFrame");
       
    96         HbFrameDrawer *fd = new HbFrameDrawer(BG_FRAME, HbFrameDrawer::NinePieces);
       
    97         mFrameItem->setFrameBackground(fd);
       
    98         connect(mFrameItem, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
       
    99         connect(mFrameItem, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF)));
       
   100 }
   118 }
   101 
   119 
   102 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment()
   120 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment()
   103 {
   121 {
   104     style()->unregisterPlugin(mPluginPath);
   122     style()->unregisterPlugin(mPluginPath);
       
   123     
       
   124     if(mGestureFilter)
       
   125         {
       
   126         removeSceneEventFilter(mGestureFilter);
       
   127         }
   105 }
   128 }
   106 
   129 
   107 const QString& MsgUnifiedEditorAttachment::path()
   130 const QString& MsgUnifiedEditorAttachment::path()
   108 {
   131 {
   109     return mPath;
   132     return mPath;
   120 }
   143 }
   121 
   144 
   122 void MsgUnifiedEditorAttachment::longPressed(QPointF position)
   145 void MsgUnifiedEditorAttachment::longPressed(QPointF position)
   123 {
   146 {
   124     HbMenu* menu = new HbMenu;
   147     HbMenu* menu = new HbMenu;
   125     menu->addAction(tr("Open"), this, SLOT(openAttachment()));
   148     menu->addAction(LOC_OPEN, this, SLOT(openAttachment()));
   126     menu->addAction(tr("Remove"), this, SLOT(removeAttachment()));
   149     menu->addAction(LOC_REMOVE, this, SLOT(removeAttachment()));
   127     menu->addAction(tr("View details"), this, SLOT(viewDetails()));
   150     menu->addAction(LOC_DETAILS, this, SLOT(viewDetails()));
   128     menu->setDismissPolicy(HbPopup::TapAnywhere);
   151     menu->setDismissPolicy(HbPopup::TapAnywhere);
   129     menu->setAttribute(Qt::WA_DeleteOnClose, true);
   152     menu->setAttribute(Qt::WA_DeleteOnClose, true);
   130     menu->setPreferredPos(position);
   153     menu->setPreferredPos(position);
   131     menu->show();
   154     menu->show();
   132 }
   155 }
   154     QString ical = S60QConversions::s60Desc8ToQString(KMsgMimeICal());
   177     QString ical = S60QConversions::s60Desc8ToQString(KMsgMimeICal());
   155     if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) ||
   178     if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) ||
   156         !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) ||
   179         !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) ||
   157         !QString::compare(mMimeType, ical, Qt::CaseInsensitive) )
   180         !QString::compare(mMimeType, ical, Qt::CaseInsensitive) )
   158     {
   181     {
   159         // vcard, vcal are not mm content
   182         QFileInfo fileinfo(mPath);
   160         ret = false;
   183         int fSize = fileinfo.size();
       
   184         
       
   185         // if filesize is within sms size-limit, then
       
   186         // it is not mm content, else it is mm attachment
       
   187         if(fSize <= mMaxSmsSize)
       
   188         {
       
   189             ret = false;
       
   190         }
   161     }
   191     }
   162     return ret;
   192     return ret;
   163 }
   193 }
   164 
   194 
       
   195 void MsgUnifiedEditorAttachment::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   196 {    
       
   197     HbWidgetFeedback::triggered(this, Hb::InstantPressed);
       
   198     
       
   199     HbFrameItem* backGround = new HbFrameItem(this);
       
   200     backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED);
       
   201     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   202     this->setBackgroundItem(backGround); 
       
   203     
       
   204     event->accept();
       
   205 }
       
   206 
       
   207 void MsgUnifiedEditorAttachment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   208 {
       
   209     HbFrameItem* backGround = new HbFrameItem(this);
       
   210     backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
       
   211     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   212     this->setBackgroundItem(backGround);
       
   213     
       
   214     if(this->rect().contains(event->pos()))
       
   215         {
       
   216         HbWidgetFeedback::triggered(this, Hb::InstantClicked);
       
   217         emit clicked();
       
   218         }
       
   219     
       
   220     event->accept();    
       
   221 }
       
   222 
       
   223 void MsgUnifiedEditorAttachment::initGesture()
       
   224 {
       
   225     // Create gesture filter
       
   226     mGestureFilter = new HbGestureSceneFilter( Qt::LeftButton, this );
       
   227     
       
   228     // Add gestures for longpress
       
   229     HbGesture* gestureLongpressed = new HbGesture( HbGesture::longpress,5 );
       
   230     
       
   231     mGestureFilter->addGesture( gestureLongpressed );
       
   232     
       
   233     connect( gestureLongpressed, SIGNAL(longPress(QPointF)),
       
   234              this, SLOT(longPressed(QPointF)) );
       
   235 
       
   236     //install gesture filter.
       
   237     this->installSceneEventFilter(mGestureFilter);
       
   238 }
       
   239 
       
   240 HbFeedback::InstantEffect MsgUnifiedEditorAttachment::overrideFeedback(Hb::InstantInteraction interaction) const
       
   241         {
       
   242         switch(interaction)
       
   243             {
       
   244             case Hb::InstantPressed:
       
   245             case Hb::InstantClicked:
       
   246                 return HbFeedback::Basic;
       
   247             default:
       
   248                 return HbFeedback::NoOverride;
       
   249             }
       
   250         }
       
   251 
   165 // EOF
   252 // EOF