messagingapp/msgui/unifiedviewer/src/univiewerbodywidget.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 27 e4592d119491
parent 43 35b64624a9e7
equal deleted inserted replaced
35:a32b19fb291e 47:5b14749788d7
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include "univiewerbodywidget.h"
    18 #include "univiewerbodywidget.h"
    19 
    19 
       
    20 // SYSTEM INCLUDES
    20 #include <QFile>
    21 #include <QFile>
    21 #include <QFileInfo>
       
    22 #include <QPixmap>
       
    23 #include <QSignalMapper>
       
    24 
       
    25 #include <HbTextItem>
    22 #include <HbTextItem>
    26 #include <HbPushButton>
       
    27 #include <HbMenu>
       
    28 #include <HbMainWindow>
    23 #include <HbMainWindow>
    29 
    24 
    30 #include <xqaiwrequest.h>
    25 // USER INCLUDES
    31 #include <xqrequestinfo.h>
       
    32 #include <xqappmgr.h>
       
    33 
       
    34 #include "univiewertextitem.h"
    26 #include "univiewertextitem.h"
    35 #include "univiewerpixmapwidget.h"
    27 #include "univiewerpixmapwidget.h"
    36 #include "msgmediautil.h"
    28 #include "univieweraudiowidget.h"
       
    29 
    37 // LOCAL CONSTANTS
    30 // LOCAL CONSTANTS
    38 const QString AUDIO_ICON("qtg_mono_audio");
    31 const QString IMAGE_MIMETYPE("image");
    39 
    32 const QString AUDIO_MIMETYPE("audio");
    40 // Localization
    33 const QString VIDEO_MIMETYPE("video");
    41 #define LOC_TITLE   hbTrId("txt_messaging_title_messaging")
    34 const QString TEXT_MIMETYPE("text");
    42 #define LOC_OPEN    hbTrId("txt_common_menu_open")
       
    43 #define LOC_SAVE    hbTrId("txt_common_menu_save")
       
    44 
    35 
    45 //---------------------------------------------------------------
    36 //---------------------------------------------------------------
    46 //UniViewerBodyWidget::UniViewerBodyWidget
    37 //UniViewerBodyWidget::UniViewerBodyWidget
    47 // @see header file
    38 // @see header file
    48 //---------------------------------------------------------------
    39 //---------------------------------------------------------------
    49 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) :
    40 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) :
    50     HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0),
    41     HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0),
    51         mPixmapItem(0), mAudioItem(0)
    42         mPixmapItem(0), mAudioItem(0)
    52 {
    43 {
    53     this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
    44     this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    54     // Signal mapper for opening media files
       
    55     mSignalMapper = new QSignalMapper(this);
       
    56     connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &)));
       
    57 }
    45 }
    58 
    46 
    59 //---------------------------------------------------------------
    47 //---------------------------------------------------------------
    60 //UniViewerBodyWidget::~UniViewerBodyWidget
    48 //UniViewerBodyWidget::~UniViewerBodyWidget
    61 // @see header file
    49 // @see header file
    66 
    54 
    67 //---------------------------------------------------------------
    55 //---------------------------------------------------------------
    68 //UniViewerBodyWidget::setImage
    56 //UniViewerBodyWidget::setImage
    69 // @see header file
    57 // @see header file
    70 //---------------------------------------------------------------
    58 //---------------------------------------------------------------
    71 void UniViewerBodyWidget::setPixmap(QString pixmapFile)
    59 void UniViewerBodyWidget::setPixmap(UniMessageInfo *info)
    72 {
    60 {
    73     setHasPixmap(true);
    61     setHasPixmap(true);
    74     //create image item instance
    62     //create image item instance
    75     if (!mPixmapItem) {
    63     if (!mPixmapItem) {
    76         mPixmapItem = new UniViewerPixmapWidget(this);
    64         mPixmapItem = new UniViewerPixmapWidget(this);
    77         HbStyle::setItemName(mPixmapItem, "pixmap");
    65         HbStyle::setItemName(mPixmapItem, "pixmap");
    78         connect(mPixmapItem, SIGNAL(shortTap(QString)), this, SLOT(openMedia(QString)));
    66     }
    79     }
       
    80 
       
    81     mPixmapItem->hide();
    67     mPixmapItem->hide();
    82     mPixmapItem->setPixmap(pixmapFile);
    68     mPixmapItem->populate(info);
    83 
    69 
    84     this->repolish();
    70     this->repolish();
    85 }
    71 }
    86 
    72 
    87 //---------------------------------------------------------------
    73 //---------------------------------------------------------------
    88 //UniViewerBodyWidget::setAudio
    74 //UniViewerBodyWidget::setAudio
    89 // @see header file
    75 // @see header file
    90 //---------------------------------------------------------------
    76 //---------------------------------------------------------------
    91 void UniViewerBodyWidget::setAudio(QString audiofile)
    77 void UniViewerBodyWidget::setAudio(UniMessageInfo *info)
    92 {
    78 {
    93     if (!mAudioItem) {
    79     if (!mAudioItem) {
    94         mAudioItem = new HbPushButton(this);
    80         mAudioItem = new UniViewerAudioWidget(this);
    95         HbStyle::setItemName(mAudioItem, "audioItem");
    81         HbStyle::setItemName(mAudioItem, "audioItem");
    96     }
    82     }
    97     mAudioItem->hide();
    83     mAudioItem->hide();
    98     QFileInfo fileInfo(audiofile);
    84     mAudioItem->populate(info);
    99     mAudioItem->setIcon(HbIcon(AUDIO_ICON));
       
   100     mAudioItem->setText(fileInfo.baseName());
       
   101     MsgMediaUtil mediaUtil;
       
   102     mAudioItem->setAdditionalText(mediaUtil.mediaDuration(audiofile));
       
   103     mAudioItem->setTextAlignment(Qt::AlignLeft);
       
   104 
       
   105     // Connect to signal mapper with file name
       
   106     mSignalMapper->setMapping(mAudioItem, audiofile);
       
   107     connect(mAudioItem, SIGNAL(clicked()), mSignalMapper, SLOT(map()));
       
   108 
    85 
   109     this->repolish();
    86     this->repolish();
   110 }
    87 }
   111 
    88 
   112 //---------------------------------------------------------------
    89 //---------------------------------------------------------------
   113 //UniViewerBodyWidget::setVideo
    90 //UniViewerBodyWidget::setVideo
   114 // @see header file
    91 // @see header file
   115 //---------------------------------------------------------------
    92 //---------------------------------------------------------------
   116 void UniViewerBodyWidget::setVideo(QString videofile)
    93 void UniViewerBodyWidget::setVideo(UniMessageInfo *info)
   117 {
    94 {
   118     Q_UNUSED(videofile)
    95     setHasPixmap(true);
   119 }
    96     //create image item instance
   120 
    97     if (!mPixmapItem) {
   121 //---------------------------------------------------------------
    98        mPixmapItem = new UniViewerPixmapWidget(this);
   122 //UniViewerBodyWidget::setTextContent
    99        HbStyle::setItemName(mPixmapItem, "pixmap");
   123 // @see header file
   100     }
   124 //---------------------------------------------------------------
   101     mPixmapItem->hide();
   125 void UniViewerBodyWidget::setTextContent(QString text)
   102     mPixmapItem->populate(info);
       
   103     
       
   104     this->repolish();
       
   105 }
       
   106 
       
   107 //---------------------------------------------------------------
       
   108 //UniViewerBodyWidget::setText
       
   109 // @see header file
       
   110 //---------------------------------------------------------------
       
   111 void UniViewerBodyWidget::setText(QString text)
   126 {
   112 {
   127     setHasText(true);
   113     setHasText(true);
   128 
   114 
   129     if (!mTextItem) {
   115     if (!mTextItem) {
   130         mTextItem = new UniViewerTextItem(this);
   116         mTextItem = new UniViewerTextItem(this);
   138     mTextItem->setText(text);
   124     mTextItem->setText(text);
   139     this->repolish();
   125     this->repolish();
   140 }
   126 }
   141 
   127 
   142 //---------------------------------------------------------------
   128 //---------------------------------------------------------------
   143 //UniViewerBodyWidget::setTextContent
   129 // UniViewerBodyWidget::setSlideCounter
   144 // @see header file
   130 // @see header file
   145 //---------------------------------------------------------------
   131 //---------------------------------------------------------------
   146 void UniViewerBodyWidget::setSlideCounter(QString &slideCounter)
   132 void UniViewerBodyWidget::setSlideCounter(QString &slideCounter)
   147 {
   133 {
   148     if (!mSlideCounter) {
   134     if (!mSlideCounter) {
   202     }
   188     }
   203 
   189 
   204     int count = objList.count();
   190     int count = objList.count();
   205     for (int a = 0; a < count; ++a) {
   191     for (int a = 0; a < count; ++a) {
   206         UniMessageInfo* info = objList.at(a);
   192         UniMessageInfo* info = objList.at(a);
   207         QString type = info->mimetype();
   193         QString mimeType = info->mimetype();
   208 
   194 
   209         if (type.contains("text")) {
   195         if (mimeType.contains(TEXT_MIMETYPE)) {
   210             QFile file(info->path());
   196             QFile file(info->path());
   211             if (file.open(QIODevice::ReadOnly)) {
   197             if (file.open(QIODevice::ReadOnly)) {
   212                 QString textContent(file.readAll());
   198                 QString textContent(file.readAll());
   213                 setTextContent(textContent);
   199                 setText(textContent);
   214             }
   200             }
   215         }
   201         }
   216         else if (type.contains("video")) {
   202         else if (mimeType.contains(AUDIO_MIMETYPE)) {
   217             setVideo(info->path());
   203             setAudio(info);
   218         }
   204         }
   219         else if (type.contains("audio")) {
   205         else if (mimeType.contains(VIDEO_MIMETYPE)) {
   220             setAudio(info->path());
   206             setVideo(info);
   221         }
   207         }
   222         else if (type.contains("image")) {
   208         else if (mimeType.contains(IMAGE_MIMETYPE)) {
   223             setPixmap(info->path());
   209             setPixmap(info);
   224         }
   210         }
   225 
   211 
   226         delete info;
   212         delete info;
   227     }
   213     }
   228 }
   214 }
   401     szHint.rheight() = qMax(maxHeight, szHint.height());
   387     szHint.rheight() = qMax(maxHeight, szHint.height());
   402 
   388 
   403     return szHint;
   389     return szHint;
   404 }
   390 }
   405 
   391 
   406 //---------------------------------------------------------------
       
   407 //UniViewerBodyWidget::longPressed
       
   408 // @see header file
       
   409 //---------------------------------------------------------------
       
   410 void UniViewerBodyWidget::longPressed(QPointF position)
       
   411 {
       
   412 
       
   413     HbMenu* menu = new HbMenu;
       
   414     menu->setAttribute(Qt::WA_DeleteOnClose);
       
   415     menu->addAction(LOC_OPEN, this, SLOT(openMedia()));
       
   416     menu->addAction(LOC_SAVE, this, SLOT(saveMedia()));
       
   417     menu->setPreferredPos(position);
       
   418     menu->show();
       
   419 }
       
   420 
       
   421 //---------------------------------------------------------------
       
   422 //UniViewerBodyWidget::openMedia
       
   423 // @see header file
       
   424 //---------------------------------------------------------------
       
   425 void UniViewerBodyWidget::openMedia()
       
   426 {
       
   427 }
       
   428 
       
   429 //---------------------------------------------------------------
       
   430 //UniViewerBodyWidget::openMedia
       
   431 // @see header file
       
   432 //---------------------------------------------------------------
       
   433 void UniViewerBodyWidget::openMedia(const QString& fileName)
       
   434 {
       
   435     XQSharableFile sf;
       
   436     XQAiwRequest* request = 0;
       
   437 
       
   438     if (!sf.open(fileName)) {
       
   439         return;
       
   440     }
       
   441 
       
   442     // Get handlers
       
   443     XQApplicationManager appManager;
       
   444     QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf);
       
   445     if (fileHandlers.count() > 0) {
       
   446         XQAiwInterfaceDescriptor d = fileHandlers.first();
       
   447         request = appManager.create(sf, d);
       
   448 
       
   449         if (!request) {
       
   450             sf.close();
       
   451             return;
       
   452         }
       
   453     }
       
   454     else {
       
   455         sf.close();
       
   456         return;
       
   457     }
       
   458 
       
   459     // Result handlers
       
   460     connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
       
   461     connect(request, SIGNAL(requestError(const QVariant&)), this,
       
   462         SLOT(handleError(const QVariant&)));
       
   463 
       
   464     request->setEmbedded(true);
       
   465     request->setSynchronous(true);
       
   466 
       
   467     // Fill args
       
   468     QList<QVariant> args;
       
   469     args << qVariantFromValue(sf);
       
   470     request->setArguments(args);
       
   471 
       
   472     // Fill headers
       
   473     QString key("WindowTitle");
       
   474     QVariant value(QString(LOC_TITLE));
       
   475     XQRequestInfo info;
       
   476     info.setInfo(key, value);
       
   477     request->setInfo(info);
       
   478 
       
   479     request->send();
       
   480 
       
   481     // Cleanup
       
   482     sf.close();
       
   483     delete request;
       
   484 }
       
   485 
       
   486 //---------------------------------------------------------------
       
   487 //UniViewerBodyWidget::saveMedia
       
   488 // @see header file
       
   489 //---------------------------------------------------------------
       
   490 void UniViewerBodyWidget::saveMedia()
       
   491 {
       
   492 }
       
   493 
       
   494 //---------------------------------------------------------------
       
   495 // UniViewerBodyWidget :: handleOk
       
   496 // @see header file
       
   497 //---------------------------------------------------------------
       
   498 void UniViewerBodyWidget::handleOk(const QVariant& result)
       
   499 {
       
   500     Q_UNUSED(result)
       
   501 }
       
   502 
       
   503 //---------------------------------------------------------------
       
   504 // UniViewerBodyWidget :: handleError
       
   505 // @see header file
       
   506 //---------------------------------------------------------------
       
   507 void UniViewerBodyWidget::handleError(int errorCode, const QString& errorMessage)
       
   508 {
       
   509     Q_UNUSED(errorMessage)
       
   510     Q_UNUSED(errorCode)
       
   511 }
       
   512 // EOF
   392 // EOF