messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 48 4f501b74aeb1
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    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 
    47 const QString LIST_ITEM_BG_FRAME_NORMAL ("qtg_fr_list_normal");
    51 const QString LIST_ITEM_BG_FRAME_NORMAL ("qtg_fr_list_normal");
    48 const QString LIST_ITEM_BG_FRAME_PRESSED("qtg_fr_list_pressed");
    52 const QString LIST_ITEM_BG_FRAME_PRESSED("qtg_fr_list_pressed");
    49 
    53 
    50 const QString ATTACHMENT_ICON("qtg_small_attachment");
    54 const QString ATTACHMENT_ICON("qtg_small_attachment");
    51 
    55 
    52 MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& pluginPath,
    56 MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& attachmentpath,
    53                                                         const QString& attachmentpath,
       
    54                                                         const int filesize,
    57                                                         const int filesize,
    55                                                         QGraphicsItem *parent ) :
    58                                                         QGraphicsItem *parent ) :
    56 HbWidget(parent),
    59 HbWidget(parent),
    57 mPluginPath(pluginPath),
       
    58 mPath(attachmentpath),
    60 mPath(attachmentpath),
    59 mSize(filesize),
    61 mSize(filesize),
    60 mMimeType(QString()),
       
    61 mAttachmentIcon(0),
    62 mAttachmentIcon(0),
    62 mAttachmentName(0),
    63 mAttachmentName(0),
    63 mGestureFilter(0),
    64 mMaxSmsSize(KFirstNormalSmsLength),
    64 mMaxSmsSize(KFirstNormalSmsLength)
    65 mEditorUtils(0)
    65 {
    66 {
    66 #ifdef _DEBUG_TRACES_
    67     this->grabGesture(Qt::TapGesture);
    67     qDebug() << "MsgUnifiedEditorAttachment calling HbStyle::registerPlugin";
    68     setProperty("state", "normal");
    68 #endif
    69     
    69     
    70     //back ground
    70         setPluginBaseId(style()->registerPlugin(mPluginPath));
    71     mBackGround = new HbFrameItem(this);
    71 		     
    72     mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
    72         //back ground
    73     mBackGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
    73         HbFrameItem* backGround = new HbFrameItem(this);
    74     this->setBackgroundItem(mBackGround);        
    74         backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
    75 
    75         backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
    76     mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this);
    76         this->setBackgroundItem(backGround);        
    77     HbStyle::setItemName(mAttachmentIcon,"attachmentIcon");
    77 
    78 
    78         mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this);
    79     int at_size = 0;
    79         HbStyle::setItemName(mAttachmentIcon,"attachmentIcon");
    80     TMsgMediaType mediaType = EMsgMediaUnknown;
    80 
    81     UniEditorGenUtils* genUtils = new UniEditorGenUtils;
    81         int at_size = 0;
    82     TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size,
    82         TMsgMediaType mediaType = EMsgMediaUnknown;
    83         mMimeType,mediaType));
    83         UniEditorGenUtils* genUtils = new UniEditorGenUtils;
    84     TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); 
    84         TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size,
    85     delete genUtils;
    85                                            mMimeType,mediaType));
    86     QFileInfo fileinfo(attachmentpath);
    86         TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); 
    87     QString filename = fileinfo.fileName();
    87         delete genUtils;
    88     mAttachmentName = new HbTextItem(filename,this);
    88         QFileInfo fileinfo(attachmentpath);
    89     HbStyle::setItemName(mAttachmentName,"attachmentName");
    89         QString filename = fileinfo.fileName();
    90     mAttachmentName->setElideMode(Qt::ElideRight);
    90         mAttachmentName = new HbTextItem(filename,this);
    91 
    91         HbStyle::setItemName(mAttachmentName,"attachmentName");
    92     // for sms, pure size should be shown
    92         mAttachmentName->setElideMode(Qt::ElideRight);
    93     // for mms, additional mimeheader size must be included
    93         
    94     qreal displaySize = mSize;
    94         // for sms, pure size should be shown
    95     if(!isMultimediaContent())
    95         // for mms, additional mimeheader size must be included
    96     {
    96         qreal displaySize = mSize;
    97         displaySize = fileinfo.size();
    97         if(!isMultimediaContent())
    98     }
    98         {
    99     int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR;
    99             displaySize = fileinfo.size();
   100     QString fileDetails;
   100         }
   101     // if size exceeds 1kb, then show kb or else only bytes
   101         int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR;
   102     if(sizeInKb >= 1)
   102         QString fileDetails;
   103     {
   103         // if size exceeds 1kb, then show kb or else only bytes
   104         fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb));
   104         if(sizeInKb >= 1)
   105     }
   105         {
   106     else
   106             fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb));
   107     {
   107         }
   108         fileDetails = QString().append(QString("(%1 B)").arg(displaySize));
   108         else
   109     }
   109         {
   110 
   110             fileDetails = QString().append(QString("(%1 B)").arg(displaySize));
   111     mAttachmentDetails = new HbTextItem(fileDetails, this);
   111         }
   112     HbStyle::setItemName(mAttachmentDetails,"attachmentDetails");
   112 
   113     mAttachmentDetails->setElideMode(Qt::ElideNone);
   113         mAttachmentDetails = new HbTextItem(fileDetails, this);
   114     
   114         HbStyle::setItemName(mAttachmentDetails,"attachmentDetails");
   115     HbEffect::add("attachmentWidget", "listviewitem_press", "pressed");
   115         mAttachmentDetails->setElideMode(Qt::ElideNone);
   116     HbEffect::add("attachmentWidget", "listviewitem_release", "released");
   116         
       
   117         initGesture();
       
   118 }
   117 }
   119 
   118 
   120 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment()
   119 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment()
   121 {
   120 {
   122     style()->unregisterPlugin(mPluginPath);
       
   123     
       
   124     if(mGestureFilter)
       
   125         {
       
   126         removeSceneEventFilter(mGestureFilter);
       
   127         }
       
   128 }
   121 }
   129 
   122 
   130 const QString& MsgUnifiedEditorAttachment::path()
   123 const QString& MsgUnifiedEditorAttachment::path()
   131 {
   124 {
   132     return mPath;
   125     return mPath;
   140 const QString& MsgUnifiedEditorAttachment::mimeType()
   133 const QString& MsgUnifiedEditorAttachment::mimeType()
   141 {
   134 {
   142     return mMimeType;
   135     return mMimeType;
   143 }
   136 }
   144 
   137 
   145 void MsgUnifiedEditorAttachment::longPressed(QPointF position)
   138 void MsgUnifiedEditorAttachment::handleLongTap(QPointF position)
   146 {
   139 {
   147     HbMenu* menu = new HbMenu;
   140     HbMenu* menu = new HbMenu;
   148     menu->addAction(LOC_OPEN, this, SLOT(openAttachment()));
   141     menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
   149     menu->addAction(LOC_REMOVE, this, SLOT(removeAttachment()));
   142     menu->addAction(LOC_REMOVE, this, SLOT(handleRemove()));
   150     menu->addAction(LOC_DETAILS, this, SLOT(viewDetails()));
   143     menu->addAction(LOC_DETAILS, this, SLOT(viewDetails()));
   151     menu->setDismissPolicy(HbPopup::TapAnywhere);
   144     menu->setDismissPolicy(HbPopup::TapAnywhere);
   152     menu->setAttribute(Qt::WA_DeleteOnClose, true);
   145     menu->setAttribute(Qt::WA_DeleteOnClose, true);
   153     menu->setPreferredPos(position);
   146     menu->setPreferredPos(position);
   154     menu->show();
   147     menu->show();
   155 }
   148 }
   156 
   149 
   157 void MsgUnifiedEditorAttachment::removeAttachment()
   150 void MsgUnifiedEditorAttachment::handleRemove()
   158 {
   151 {
   159     emit deleteMe(this);
   152     emit deleteMe(this);
   160 }
   153 }
   161 
   154 
   162 void MsgUnifiedEditorAttachment::openAttachment()
   155 void MsgUnifiedEditorAttachment::handleOpen()
   163 {
   156 {
   164     //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()));
   165 }
   169 }
   166 
   170 
   167 void MsgUnifiedEditorAttachment::viewDetails()
   171 void MsgUnifiedEditorAttachment::viewDetails()
   168 {
   172 {
   169     //open details view.
   173     //open details view.
   170 }
   174 }
   171 
   175 
   172 bool MsgUnifiedEditorAttachment::isMultimediaContent()
   176 bool MsgUnifiedEditorAttachment::isMultimediaContent()
   173 {
   177 {
   174     bool ret = true;
   178     bool ret = true;
   175     QString vcard = S60QConversions::s60Desc8ToQString(KMsgMimeVCard());
   179     QString vcard = XQConversions::s60Desc8ToQString(KMsgMimeVCard());
   176     QString vcal = S60QConversions::s60Desc8ToQString(KMsgMimeVCal());
   180     QString vcal = XQConversions::s60Desc8ToQString(KMsgMimeVCal());
   177     QString ical = S60QConversions::s60Desc8ToQString(KMsgMimeICal());
   181     QString ical = XQConversions::s60Desc8ToQString(KMsgMimeICal());
   178     if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) ||
   182     if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) ||
   179         !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) ||
   183         !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) ||
   180         !QString::compare(mMimeType, ical, Qt::CaseInsensitive) )
   184         !QString::compare(mMimeType, ical, Qt::CaseInsensitive) )
   181     {
   185     {
   182         QFileInfo fileinfo(mPath);
   186         QFileInfo fileinfo(mPath);
   190         }
   194         }
   191     }
   195     }
   192     return ret;
   196     return ret;
   193 }
   197 }
   194 
   198 
   195 void MsgUnifiedEditorAttachment::mousePressEvent(QGraphicsSceneMouseEvent *event)
   199 void MsgUnifiedEditorAttachment::gestureEvent(QGestureEvent *event)
   196 {    
   200 {
   197     HbWidgetFeedback::triggered(this, Hb::InstantPressed);
   201     HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture));
   198     
   202     if (tapGesture) {
   199     HbFrameItem* backGround = new HbFrameItem(this);
   203         switch (tapGesture->state()) {
   200     backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED);
   204         case Qt::GestureStarted:
   201     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   205         {
   202     this->setBackgroundItem(backGround); 
   206             // Trigger haptic feedback.
   203     
   207             HbInstantFeedback::play(HbFeedback::Basic);
   204     event->accept();
   208             setPressed(true);
   205 }
   209             break;
   206 
   210         }
   207 void MsgUnifiedEditorAttachment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   211         case Qt::GestureUpdated:
   208 {
   212         {
   209     HbFrameItem* backGround = new HbFrameItem(this);
   213             if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) {
   210     backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
   214                 // Handle longtap.
   211     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   215                 setPressed(false);
   212     this->setBackgroundItem(backGround);
   216                 handleLongTap(tapGesture->scenePosition());
   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             }
   217             }
   250         }
   218             break;
   251 
   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 }
   252 // EOF
   271 // EOF