diff -r 238255e8b033 -r 84d9eb65b26f messagingapp/msgui/unifiedviewer/src/univiewerbodywidget.cpp --- a/messagingapp/msgui/unifiedviewer/src/univiewerbodywidget.cpp Fri Apr 16 14:56:15 2010 +0300 +++ b/messagingapp/msgui/unifiedviewer/src/univiewerbodywidget.cpp Mon May 03 12:29:07 2010 +0300 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -32,32 +33,35 @@ #include #include -#include "debugtraces.h" -#include "univiewertextitem.h" +#include +#include +#include +#include "univiewertextitem.h" +#include "msgmediautil.h" // LOCAL CONSTANTS -const QString AUDIO_ICON("qtg_mono_audio.svg"); +const QString AUDIO_ICON("qtg_mono_audio"); + +// Localization +#define LOC_TITLE hbTrId("txt_messaging_title_messaging") //--------------------------------------------------------------- //UniViewerBodyWidget::UniViewerBodyWidget // @see header file //--------------------------------------------------------------- UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : - HbWidget(parent), mHasText(false), mTextItem(0), mIconItem(0), mAudioItem(0) + HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0), + mIconItem(0), mAudioItem(0) { - //This is permanent item in the widget - mTextItem = new UniViewerTextItem(this); - HbStyle::setItemName(mTextItem, "textItem"); - //Gesture filter for the image gestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this); gestureFilter->setLongpressAnimation(true); HbGesture *gesture = new HbGesture(HbGesture::longpress, 20); gestureFilter->addGesture(gesture); connect(gesture, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF))); - - connect(mTextItem,SIGNAL(sendMessage(const QString&)), - this, SIGNAL(sendMessage(const QString&))); + // Signal mapper for opening media files + mSignalMapper = new QSignalMapper(this); + connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &))); } //--------------------------------------------------------------- @@ -74,6 +78,7 @@ //--------------------------------------------------------------- void UniViewerBodyWidget::setImage(QString imagefile) { + setHasPixmap(true); //create image item instance if (!mIconItem) { mIconItem = new HbIconItem(this); @@ -82,6 +87,11 @@ QPixmap pixmap(imagefile); mIconItem->setIcon(HbIcon(pixmap)); + + // TODO + // Implementation for short tap action is unclear + // Connect to signal mapper + this->repolish(); } @@ -98,8 +108,14 @@ QFileInfo fileInfo(audiofile); mAudioItem->setIcon(HbIcon(AUDIO_ICON)); mAudioItem->setText(fileInfo.baseName()); - mAudioItem->setAdditionalText("00:00"); + MsgMediaUtil mediaUtil; + mAudioItem->setAdditionalText(mediaUtil.mediaDuration(audiofile)); mAudioItem->setTextAlignment(Qt::AlignLeft); + + // Connect to signal mapper with file name + mSignalMapper->setMapping(mAudioItem, audiofile); + connect(mAudioItem, SIGNAL(clicked()), mSignalMapper, SLOT(map())); + this->repolish(); } @@ -113,6 +129,145 @@ } //--------------------------------------------------------------- +//UniViewerBodyWidget::setTextContent +// @see header file +//--------------------------------------------------------------- +void UniViewerBodyWidget::setTextContent(QString text) +{ + setHasText(true); + + if (!mTextItem) { + mTextItem = new UniViewerTextItem(this); + HbStyle::setItemName(mTextItem, "textItem"); + connect(mTextItem, SIGNAL(sendMessage(const QString&)), this, + SIGNAL(sendMessage(const QString&))); + } + text.replace(QChar::ParagraphSeparator, QChar::LineSeparator); + text.replace('\r', QChar::LineSeparator); + mTextItem->setText(text); + this->repolish(); +} + +//--------------------------------------------------------------- +//UniViewerBodyWidget::setTextContent +// @see header file +//--------------------------------------------------------------- +void UniViewerBodyWidget::setSlideCounter(QString &slideCounter) +{ + if (!mSlideCounter) { + mSlideCounter = new HbTextItem(this); + HbStyle::setItemName(mSlideCounter, "slideCounter"); + } + + mSlideCounter->setText(slideCounter); + this->repolish(); +} + +//--------------------------------------------------------------- +// UniViewerBodyWidget::setHasText +// @see header file +//--------------------------------------------------------------- +void UniViewerBodyWidget::setHasText(bool text) +{ + mHasText = text; +} + +//--------------------------------------------------------------- +// UniViewerBodyWidget::hasText +// @see header file +//--------------------------------------------------------------- +bool UniViewerBodyWidget::hasText() +{ + return mHasText; +} + +//--------------------------------------------------------------- +// UniViewerBodyWidget::setHasPixmap +// @see header file +//--------------------------------------------------------------- +void UniViewerBodyWidget::setHasPixmap(bool pixmap) +{ + mHasPixmap = pixmap; +} + +//--------------------------------------------------------------- +// UniViewerBodyWidget::hasPixmap +// @see header file +//--------------------------------------------------------------- +bool UniViewerBodyWidget::hasPixmap() +{ + return mHasPixmap; +} + +//--------------------------------------------------------------- +// UniViewerBodyWidget::setSlideContents +// @see header file +//--------------------------------------------------------------- +void UniViewerBodyWidget::setSlideContents(UniMessageInfoList objList, QString slideString) +{ + if (!slideString.isEmpty()) { + setSlideCounter(slideString); + } + + int count = objList.count(); + for (int a = 0; a < count; ++a) { + UniMessageInfo* info = objList.at(a); + QString type = info->mimetype(); + + if (type.contains("text")) { + QFile file(info->path()); + if (file.open(QIODevice::ReadOnly)) + { + QString textContent(file.readAll()); + setTextContent(textContent); + } + + } + else if (type.contains("video")) { + setVideo(info->path()); + } + else if (type.contains("audio")) { + setAudio(info->path()); + } + else if (type.contains("image")) { + setImage(info->path()); + } + + delete info; + } +} + +//--------------------------------------------------------------- +//UniViewerBodyWidget :: clearContent +// @see header file +//--------------------------------------------------------------- +void UniViewerBodyWidget::clearContent() +{ + // delete the temp items(pixmap) & clear permanent items(text) + if (mIconItem) { + mIconItem->setParent(NULL); + delete mIconItem; + mIconItem = NULL; + } + + if (mAudioItem) { + mAudioItem->setParent(NULL); + delete mAudioItem; + mAudioItem = NULL; + } + + if (mTextItem) { + mTextItem->setParent(NULL); + delete mTextItem; + mTextItem = NULL; + } + + setHasText(false); + setHasPixmap(false); + repolish(); +} + +//--------------------------------------------------------------- //UniViewerBodyWidget::resizeEvent // @see header file //--------------------------------------------------------------- @@ -129,6 +284,7 @@ qreal chromeHeight = 0.0; qreal toolbarHeight = 0.0; qreal iconSize = 0.0; + qreal unitSize = HbDeviceProfile::profile(mIconItem).unitValue(); style()->parameter("hb-param-screen-width", screenWidth); style()->parameter("hb-param-screen-height", screenHeight); style()->parameter("hb-param-margin-gene-left", leftMargin); @@ -141,10 +297,13 @@ qreal maxHeight = 0.0; if (mainWindow->orientation() == Qt::Horizontal) { + qreal temp; + temp = screenWidth; + screenWidth = screenHeight; + screenHeight = temp; if (mIconItem) { if (mHasText) { - maxWidth = (screenWidth / 2) - leftMargin - - HbDeviceProfile::profile(mIconItem).unitValue(); + maxWidth = (screenWidth / 2) - leftMargin - unitSize; } else { maxWidth = screenWidth - leftMargin - rightMargin; @@ -192,10 +351,8 @@ widthToSet = heightToSet * (imageWidth / imageHeight); } - mIconItem->setMinimumWidth(widthToSet); - mIconItem->setMinimumHeight(heightToSet); - mIconItem->setMaximumWidth(widthToSet); - mIconItem->setMaximumHeight(heightToSet); + mIconItem->setPreferredWidth(widthToSet); + mIconItem->setPreferredHeight(heightToSet); } } } @@ -206,6 +363,7 @@ //--------------------------------------------------------------- void UniViewerBodyWidget::longPressed(QPointF position) { + HbMenu* menu = new HbMenu; menu->addAction(tr("Open"), this, SLOT(openMedia())); menu->addAction(tr("View details"), this, SLOT(viewDetails())); @@ -219,7 +377,63 @@ //--------------------------------------------------------------- void UniViewerBodyWidget::openMedia() { - //open corresponding viewer app. +} + +//--------------------------------------------------------------- +//UniViewerBodyWidget::openMedia +// @see header file +//--------------------------------------------------------------- +void UniViewerBodyWidget::openMedia(const QString& fileName) +{ + XQSharableFile sf; + XQAiwRequest* request = 0; + + if (!sf.open(fileName)) { + return; + } + + // Get handlers + XQApplicationManager appManager; + QList fileHandlers = appManager.list(sf); + if (fileHandlers.count() > 0) { + XQAiwInterfaceDescriptor d = fileHandlers.first(); + request = appManager.create(sf, d); + + if (!request) { + sf.close(); + return; + } + } + else { + sf.close(); + return; + } + + // Result handlers + connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); + connect(request, SIGNAL(requestError(const QVariant&)), this, + SLOT(handleError(const QVariant&))); + + request->setEmbedded(true); + request->setSynchronous(true); + + // Fill args + QList args; + args << qVariantFromValue(sf); + request->setArguments(args); + + // Fill headers + QString key("WindowTitle"); + QVariant value(QString(LOC_TITLE)); + XQRequestInfo info; + info.setInfo(key, value); + request->setInfo(info); + + request->send(); + + // Cleanup + sf.close(); + delete request; } //--------------------------------------------------------------- @@ -232,88 +446,21 @@ } //--------------------------------------------------------------- -//UniViewerBodyWidget::setTextContent +// UniViewerBodyWidget :: handleOk // @see header file //--------------------------------------------------------------- -void UniViewerBodyWidget::setTextContent(QString text) +void UniViewerBodyWidget::handleOk(const QVariant& result) { - text.replace('\n', QChar::LineSeparator); - mTextItem->setText(text); - setHasText(true); -} - -//--------------------------------------------------------------- -// UniViewerBodyWidget::hasText -// @see header file -//--------------------------------------------------------------- -bool UniViewerBodyWidget::hasText() -{ - return mHasText; -} - -//--------------------------------------------------------------- -// UniViewerBodyWidget::setHasText -// @see header file -//--------------------------------------------------------------- -void UniViewerBodyWidget::setHasText(bool text) -{ - mHasText = text; + Q_UNUSED(result) } //--------------------------------------------------------------- -// UniViewerBodyWidget::setSlideContents +// UniViewerBodyWidget :: handleError // @see header file //--------------------------------------------------------------- -void UniViewerBodyWidget::setSlideContents(UniMessageInfoList objList, QString slideString) +void UniViewerBodyWidget::handleError(int errorCode, const QString& errorMessage) { - Q_UNUSED(slideString) - - int count = objList.count(); - - for (int a = 0; a < count; ++a) { - UniMessageInfo* info = objList.at(a); - QString type = info->mimetype(); - - if (type.contains("video")) { - setVideo(info->path()); - } - else if (type.contains("audio")) { - setAudio(info->path()); - } - if (type.contains("image")) { - setImage(info->path()); - } - else if (type.contains("text")) { - QFile file(info->path()); - file.open(QIODevice::ReadOnly); - QString textContent(file.readAll()); - setTextContent(textContent); - } - delete info; - } + Q_UNUSED(errorMessage) + Q_UNUSED(errorCode) } - -//--------------------------------------------------------------- -//UniViewerBodyWidget :: clearContent -// @see header file -//--------------------------------------------------------------- -void UniViewerBodyWidget::clearContent() -{ - // delete the temp items(pixmap) & clear permanent items(text) - if (mIconItem) { - mIconItem->setParent(NULL); - delete mIconItem; - mIconItem = NULL; - } - - if (mAudioItem) { - mAudioItem->setParent(NULL); - delete mAudioItem; - mAudioItem = NULL; - } - - mTextItem->setText(QString()); - setHasText(false); -} - // EOF