messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 27 e4592d119491
parent 43 35b64624a9e7
equal deleted inserted replaced
35:a32b19fb291e 47:5b14749788d7
    23 #include <QFont>
    23 #include <QFont>
    24 #include <HbFrameDrawer>
    24 #include <HbFrameDrawer>
    25 #include <HbMenu>
    25 #include <HbMenu>
    26 #include <MsgMimeTypes.h>
    26 #include <MsgMimeTypes.h>
    27 #include <HbFrameItem>
    27 #include <HbFrameItem>
    28 //#include <HbGestureSceneFilter>
    28 #include <HbInstantFeedback>
    29 //#include <HbGesture>
    29 #include <HbTapGesture>
    30 #include <QGraphicsSceneMouseEvent>
    30 #include <QGraphicsSceneMouseEvent>
    31 #include <HbWidgetFeedback>
    31 #include <HbWidgetFeedback>
       
    32 #include <HbEffect>
       
    33 #include <QTimer>
    32 
    34 
    33 // USER INCLUDES
    35 // USER INCLUDES
       
    36 #include "msgcontactsutil.h"
    34 #include "msgunieditorattachment.h"
    37 #include "msgunieditorattachment.h"
    35 #include "unieditorgenutils.h"
    38 #include "UniEditorGenUtils.h"
    36 #include "s60qconversions.h"
    39 #include <xqconversions.h>
       
    40 #include "msgunieditorutils.h"
    37 
    41 
    38 // Constants
    42 // Constants
    39 #define BYTES_TO_KBYTES_FACTOR 1024
    43 #define BYTES_TO_KBYTES_FACTOR 1024
    40 #define BG_FRAME "qtg_fr_groupbox"
    44 #define BG_FRAME "qtg_fr_groupbox"
    41 
    45 
    55 HbWidget(parent),
    59 HbWidget(parent),
    56 mPath(attachmentpath),
    60 mPath(attachmentpath),
    57 mSize(filesize),
    61 mSize(filesize),
    58 mAttachmentIcon(0),
    62 mAttachmentIcon(0),
    59 mAttachmentName(0),
    63 mAttachmentName(0),
    60 //mGestureFilter(0),
    64 mMaxSmsSize(KFirstNormalSmsLength),
    61 mMaxSmsSize(KFirstNormalSmsLength)
    65 mEditorUtils(0)
    62 {
    66 {
    63         //back ground
    67     this->grabGesture(Qt::TapGesture);
    64         HbFrameItem* backGround = new HbFrameItem(this);
    68     setProperty("state", "normal");
    65         backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
    69     
    66         backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
    70     //back ground
    67         this->setBackgroundItem(backGround);        
    71     mBackGround = new HbFrameItem(this);
    68 
    72     mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
    69         mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this);
    73     mBackGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
    70         HbStyle::setItemName(mAttachmentIcon,"attachmentIcon");
    74     this->setBackgroundItem(mBackGround);        
    71 
    75 
    72         int at_size = 0;
    76     mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this);
    73         TMsgMediaType mediaType = EMsgMediaUnknown;
    77     HbStyle::setItemName(mAttachmentIcon,"attachmentIcon");
    74         UniEditorGenUtils* genUtils = new UniEditorGenUtils;
    78 
    75         TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size,
    79     int at_size = 0;
    76                                            mMimeType,mediaType));
    80     TMsgMediaType mediaType = EMsgMediaUnknown;
    77         TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); 
    81     UniEditorGenUtils* genUtils = new UniEditorGenUtils;
    78         delete genUtils;
    82     TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size,
    79         QFileInfo fileinfo(attachmentpath);
    83         mMimeType,mediaType));
    80         QString filename = fileinfo.fileName();
    84     TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); 
    81         mAttachmentName = new HbTextItem(filename,this);
    85     delete genUtils;
    82         HbStyle::setItemName(mAttachmentName,"attachmentName");
    86     QFileInfo fileinfo(attachmentpath);
    83         mAttachmentName->setElideMode(Qt::ElideRight);
    87     QString filename = fileinfo.fileName();
    84         
    88     mAttachmentName = new HbTextItem(filename,this);
    85         // for sms, pure size should be shown
    89     HbStyle::setItemName(mAttachmentName,"attachmentName");
    86         // for mms, additional mimeheader size must be included
    90     mAttachmentName->setElideMode(Qt::ElideRight);
    87         qreal displaySize = mSize;
    91 
    88         if(!isMultimediaContent())
    92     // for sms, pure size should be shown
    89         {
    93     // for mms, additional mimeheader size must be included
    90             displaySize = fileinfo.size();
    94     qreal displaySize = mSize;
    91         }
    95     if(!isMultimediaContent())
    92         int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR;
    96     {
    93         QString fileDetails;
    97         displaySize = fileinfo.size();
    94         // if size exceeds 1kb, then show kb or else only bytes
    98     }
    95         if(sizeInKb >= 1)
    99     int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR;
    96         {
   100     QString fileDetails;
    97             fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb));
   101     // if size exceeds 1kb, then show kb or else only bytes
    98         }
   102     if(sizeInKb >= 1)
    99         else
   103     {
   100         {
   104         fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb));
   101             fileDetails = QString().append(QString("(%1 B)").arg(displaySize));
   105     }
   102         }
   106     else
   103 
   107     {
   104         mAttachmentDetails = new HbTextItem(fileDetails, this);
   108         fileDetails = QString().append(QString("(%1 B)").arg(displaySize));
   105         HbStyle::setItemName(mAttachmentDetails,"attachmentDetails");
   109     }
   106         mAttachmentDetails->setElideMode(Qt::ElideNone);
   110 
   107         
   111     mAttachmentDetails = new HbTextItem(fileDetails, this);
   108         initGesture();
   112     HbStyle::setItemName(mAttachmentDetails,"attachmentDetails");
       
   113     mAttachmentDetails->setElideMode(Qt::ElideNone);
       
   114     
       
   115     HbEffect::add("attachmentWidget", "listviewitem_press", "pressed");
       
   116     HbEffect::add("attachmentWidget", "listviewitem_release", "released");
   109 }
   117 }
   110 
   118 
   111 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment()
   119 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment()
   112 {
   120 {
   113   /*  if(mGestureFilter)
       
   114         {
       
   115         removeSceneEventFilter(mGestureFilter);
       
   116         }*/
       
   117 }
   121 }
   118 
   122 
   119 const QString& MsgUnifiedEditorAttachment::path()
   123 const QString& MsgUnifiedEditorAttachment::path()
   120 {
   124 {
   121     return mPath;
   125     return mPath;
   129 const QString& MsgUnifiedEditorAttachment::mimeType()
   133 const QString& MsgUnifiedEditorAttachment::mimeType()
   130 {
   134 {
   131     return mMimeType;
   135     return mMimeType;
   132 }
   136 }
   133 
   137 
   134 void MsgUnifiedEditorAttachment::longPressed(QPointF position)
   138 void MsgUnifiedEditorAttachment::handleLongTap(QPointF position)
   135 {
   139 {
   136     HbMenu* menu = new HbMenu;
   140     HbMenu* menu = new HbMenu;
   137     menu->addAction(LOC_OPEN, this, SLOT(openAttachment()));
   141     menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
   138     menu->addAction(LOC_REMOVE, this, SLOT(removeAttachment()));
   142     menu->addAction(LOC_REMOVE, this, SLOT(handleRemove()));
   139     menu->addAction(LOC_DETAILS, this, SLOT(viewDetails()));
   143     menu->addAction(LOC_DETAILS, this, SLOT(viewDetails()));
   140     menu->setDismissPolicy(HbPopup::TapAnywhere);
   144     menu->setDismissPolicy(HbPopup::TapAnywhere);
   141     menu->setAttribute(Qt::WA_DeleteOnClose, true);
   145     menu->setAttribute(Qt::WA_DeleteOnClose, true);
   142     menu->setPreferredPos(position);
   146     menu->setPreferredPos(position);
   143     menu->show();
   147     menu->show();
   144 }
   148 }
   145 
   149 
   146 void MsgUnifiedEditorAttachment::removeAttachment()
   150 void MsgUnifiedEditorAttachment::handleRemove()
   147 {
   151 {
   148     emit deleteMe(this);
   152     emit deleteMe(this);
   149 }
   153 }
   150 
   154 
   151 void MsgUnifiedEditorAttachment::openAttachment()
   155 void MsgUnifiedEditorAttachment::handleOpen()
   152 {
   156 {
   153     //open corresponding viewer app.
   157     this->ungrabGesture(Qt::TapGesture);
       
   158     
       
   159     //open corresponding viewer app
       
   160 
       
   161     if (!mEditorUtils) 
       
   162     {
       
   163         mEditorUtils = new MsgUnifiedEditorUtils(this);
       
   164     }
       
   165     mEditorUtils->launchContentViewer(mMimeType, mPath);
       
   166     
       
   167     //fire timer to regrab gesture after some delay.
       
   168     QTimer::singleShot(300,this,SLOT(regrabGesture()));
   154 }
   169 }
   155 
   170 
   156 void MsgUnifiedEditorAttachment::viewDetails()
   171 void MsgUnifiedEditorAttachment::viewDetails()
   157 {
   172 {
   158     //open details view.
   173     //open details view.
   159 }
   174 }
   160 
   175 
   161 bool MsgUnifiedEditorAttachment::isMultimediaContent()
   176 bool MsgUnifiedEditorAttachment::isMultimediaContent()
   162 {
   177 {
   163     bool ret = true;
   178     bool ret = true;
   164     QString vcard = S60QConversions::s60Desc8ToQString(KMsgMimeVCard());
   179     QString vcard = XQConversions::s60Desc8ToQString(KMsgMimeVCard());
   165     QString vcal = S60QConversions::s60Desc8ToQString(KMsgMimeVCal());
   180     QString vcal = XQConversions::s60Desc8ToQString(KMsgMimeVCal());
   166     QString ical = S60QConversions::s60Desc8ToQString(KMsgMimeICal());
   181     QString ical = XQConversions::s60Desc8ToQString(KMsgMimeICal());
   167     if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) ||
   182     if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) ||
   168         !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) ||
   183         !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) ||
   169         !QString::compare(mMimeType, ical, Qt::CaseInsensitive) )
   184         !QString::compare(mMimeType, ical, Qt::CaseInsensitive) )
   170     {
   185     {
   171         QFileInfo fileinfo(mPath);
   186         QFileInfo fileinfo(mPath);
   179         }
   194         }
   180     }
   195     }
   181     return ret;
   196     return ret;
   182 }
   197 }
   183 
   198 
   184 void MsgUnifiedEditorAttachment::mousePressEvent(QGraphicsSceneMouseEvent *event)
   199 void MsgUnifiedEditorAttachment::gestureEvent(QGestureEvent *event)
   185 {    
   200 {
   186     HbWidgetFeedback::triggered(this, Hb::InstantPressed);
   201     HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture));
   187     
   202     if (tapGesture) {
   188     HbFrameItem* backGround = new HbFrameItem(this);
   203         switch (tapGesture->state()) {
   189     backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED);
   204         case Qt::GestureStarted:
   190     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   205         {
   191     this->setBackgroundItem(backGround); 
   206             // Trigger haptic feedback.
   192     
   207             HbInstantFeedback::play(HbFeedback::Basic);
   193     event->accept();
   208             setPressed(true);
   194 }
   209             break;
   195 
   210         }
   196 void MsgUnifiedEditorAttachment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   211         case Qt::GestureUpdated:
   197 {
   212         {
   198     HbFrameItem* backGround = new HbFrameItem(this);
   213             if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) {
   199     backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
   214                 // Handle longtap.
   200     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   215                 setPressed(false);
   201     this->setBackgroundItem(backGround);
   216                 handleLongTap(tapGesture->scenePosition());
   202     
       
   203     if(this->rect().contains(event->pos()))
       
   204         {
       
   205         HbWidgetFeedback::triggered(this, Hb::InstantClicked);
       
   206         emit clicked();
       
   207         }
       
   208     
       
   209     event->accept();    
       
   210 }
       
   211 
       
   212 void MsgUnifiedEditorAttachment::initGesture()
       
   213 {
       
   214     // Create gesture filter
       
   215  /*   mGestureFilter = new HbGestureSceneFilter( Qt::LeftButton, this );
       
   216     
       
   217     // Add gestures for longpress
       
   218     HbGesture* gestureLongpressed = new HbGesture( HbGesture::longpress,5 );
       
   219     
       
   220     mGestureFilter->addGesture( gestureLongpressed );
       
   221     
       
   222     connect( gestureLongpressed, SIGNAL(longPress(QPointF)),
       
   223              this, SLOT(longPressed(QPointF)) );
       
   224 
       
   225     //install gesture filter.
       
   226     this->installSceneEventFilter(mGestureFilter);*/
       
   227 }
       
   228 
       
   229 /*HbFeedback::InstantEffect MsgUnifiedEditorAttachment::overrideFeedback(Hb::InstantInteraction interaction) const
       
   230         {
       
   231         switch(interaction)
       
   232             {
       
   233             case Hb::InstantPressed:
       
   234             case Hb::InstantClicked:
       
   235                 return HbFeedback::Basic;
       
   236             default:
       
   237                 return HbFeedback::None;
       
   238             }
   217             }
   239         }*/
   218             break;
   240 
   219         }
       
   220         case Qt::GestureFinished:
       
   221         {
       
   222             HbInstantFeedback::play(HbFeedback::Basic);
       
   223             if (HbTapGesture::Tap == tapGesture->tapStyleHint()) {
       
   224                 // Handle short tap.
       
   225                 setPressed(false);
       
   226                 handleShortTap();
       
   227             }
       
   228             break;
       
   229         }
       
   230         case Qt::GestureCanceled:
       
   231         {
       
   232             HbInstantFeedback::play(HbFeedback::Basic);
       
   233             setPressed(false);
       
   234             break;
       
   235         }
       
   236         }
       
   237     }
       
   238     else {
       
   239         HbWidget::gestureEvent(event);
       
   240     }
       
   241 }
       
   242 
       
   243 void MsgUnifiedEditorAttachment::handleShortTap()
       
   244 {
       
   245     handleOpen();
       
   246 }
       
   247 
       
   248 void MsgUnifiedEditorAttachment::setPressed(bool pressed)
       
   249 {
       
   250     if (pressed) 
       
   251     {
       
   252         setProperty("state", "pressed");
       
   253         mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED);
       
   254         HbEffect::cancel(mBackGround, "released");
       
   255         HbEffect::start(mBackGround, "attachmentWidget", "pressed");
       
   256 
       
   257     }
       
   258     else 
       
   259     {
       
   260         setProperty("state", "normal");
       
   261         mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
       
   262         HbEffect::cancel(mBackGround, "pressed");
       
   263         HbEffect::start(mBackGround, "attachmentWidget", "released");
       
   264     }    
       
   265 }
       
   266 
       
   267 void MsgUnifiedEditorAttachment::regrabGesture()
       
   268 {
       
   269     this->grabGesture(Qt::TapGesture);
       
   270 }
   241 // EOF
   271 // EOF