Implemented Sankore-729 - previews images for web search results supports images, audios, videos and flash content.

Images previews is adjusted now.
Mime type detection mechanism is more common now.
preferencesAboutTextFull
Aleksei Kanash 13 years ago
parent c7abe50538
commit ea51150cbe
  1. 24
      src/board/UBBoardController.cpp
  2. 17
      src/core/UB.h
  3. 53
      src/frameworks/UBFileSystemUtils.cpp
  4. 6
      src/frameworks/UBFileSystemUtils.h
  5. 26
      src/gui/UBFeaturesWidget.cpp

@ -868,6 +868,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
if(position != -1) if(position != -1)
mimeType=mimeType.left(position); mimeType=mimeType.left(position);
UBMimeType::Enum itemMimeType = UBFileSystemUtils::mimeTypeFromString(mimeType);
if (!pSuccess) if (!pSuccess)
{ {
UBApplication::showMessage(tr("Downloading content %1 failed").arg(sourceUrl.toString())); UBApplication::showMessage(tr("Downloading content %1 failed").arg(sourceUrl.toString()));
@ -877,11 +879,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
if (!sourceUrl.toString().startsWith("file://") && !sourceUrl.toString().startsWith("uniboardTool://")) if (!sourceUrl.toString().startsWith("file://") && !sourceUrl.toString().startsWith("uniboardTool://"))
UBApplication::showMessage(tr("Download finished")); UBApplication::showMessage(tr("Download finished"));
if (mimeType == "image/jpeg" if (UBMimeType::RasterImage == itemMimeType)
|| mimeType == "image/png"
|| mimeType == "image/gif"
|| mimeType == "image/tiff"
|| mimeType == "image/bmp")
{ {
qDebug() << "accepting mime type" << mimeType << "as raster image"; qDebug() << "accepting mime type" << mimeType << "as raster image";
@ -904,7 +902,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
} }
} }
else if (mimeType == "image/svg+xml") else if (UBMimeType::VectorImage == itemMimeType)
{ {
qDebug() << "accepting mime type" << mimeType << "as vecto image"; qDebug() << "accepting mime type" << mimeType << "as vecto image";
@ -922,7 +920,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
} }
} }
else if (mimeType == "application/vnd.apple-widget") //mime type invented by us :-( else if (UBMimeType::AppleWidget == itemMimeType) //mime type invented by us :-(
{ {
qDebug() << "accepting mime type" << mimeType << "as Apple widget"; qDebug() << "accepting mime type" << mimeType << "as Apple widget";
@ -946,7 +944,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
} }
} }
else if (mimeType == "application/widget") else if (UBMimeType::W3CWidget == itemMimeType)
{ {
qDebug() << "accepting mime type" << mimeType << "as W3C widget"; qDebug() << "accepting mime type" << mimeType << "as W3C widget";
QUrl widgetUrl = sourceUrl; QUrl widgetUrl = sourceUrl;
@ -967,7 +965,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
} }
} }
else if (mimeType.startsWith("video/")) else if (UBMimeType::Video == itemMimeType)
{ {
qDebug() << "accepting mime type" << mimeType << "as video"; qDebug() << "accepting mime type" << mimeType << "as video";
@ -996,7 +994,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
} }
else if (mimeType.startsWith("audio/")) else if (UBMimeType::Audio == itemMimeType)
{ {
qDebug() << "accepting mime type" << mimeType << "as audio"; qDebug() << "accepting mime type" << mimeType << "as audio";
@ -1026,7 +1024,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
} }
else if (mimeType.startsWith("application/x-shockwave-flash")) else if (UBMimeType::Flash == itemMimeType)
{ {
qDebug() << "accepting mime type" << mimeType << "as flash"; qDebug() << "accepting mime type" << mimeType << "as flash";
@ -1073,7 +1071,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
delete eduMediaFile; delete eduMediaFile;
} }
else if (mimeType.startsWith("application/pdf")) else if (UBMimeType::PDF == itemMimeType)
{ {
qDebug() << "accepting mime type" << mimeType << "as PDF"; qDebug() << "accepting mime type" << mimeType << "as PDF";
qDebug() << "pdf data length: " << pData.size(); qDebug() << "pdf data length: " << pData.size();
@ -1097,7 +1095,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
} }
} }
else if (mimeType.startsWith("application/vnd.mnemis-uniboard-tool")) else if (UBMimeType::UniboardTool == itemMimeType)
{ {
qDebug() << "accepting mime type" << mimeType << "as Uniboard Tool"; qDebug() << "accepting mime type" << mimeType << "as Uniboard Tool";

@ -20,6 +20,23 @@
#define UB_MAX_ZOOM 15 #define UB_MAX_ZOOM 15
struct UBMimeType
{
enum Enum
{
RasterImage = 0,
VectorImage,
AppleWidget,
W3CWidget,
Video,
Audio,
Flash,
PDF,
UniboardTool,
UNKNOWN
};
};
struct UBStylusTool struct UBStylusTool
{ {
enum Enum enum Enum

@ -535,6 +535,59 @@ QString UBFileSystemUtils::fileExtensionFromMimeType(const QString& pMimeType)
} }
UBMimeType::Enum UBFileSystemUtils::mimeTypeFromString(const QString& typeString)
{
UBMimeType::Enum type = UBMimeType::UNKNOWN;
if (typeString == "image/jpeg"
|| typeString == "image/png"
|| typeString == "image/gif"
|| typeString == "image/tiff"
|| typeString == "image/bmp")
{
type = UBMimeType::RasterImage;
}
else if (typeString == "image/svg+xml")
{
type = UBMimeType::VectorImage;
}
else if (typeString == "application/vnd.apple-widget")
{
type = UBMimeType::AppleWidget;
}
else if (typeString == "application/widget")
{
type = UBMimeType::W3CWidget;
}
else if (typeString.startsWith("video/"))
{
type = UBMimeType::Video;
}
else if (typeString.startsWith("audio/"))
{
type = UBMimeType::Audio;
}
else if (typeString.startsWith("application/x-shockwave-flash"))
{
type = UBMimeType::Flash;
}
else if (typeString.startsWith("application/pdf"))
{
type = UBMimeType::PDF;
}
else if (typeString.startsWith("application/vnd.mnemis-uniboard-tool"))
{
type = UBMimeType::UniboardTool;
}
return type;
}
UBMimeType::Enum UBFileSystemUtils::mimeTypeFromUrl(const QUrl& url)
{
return mimeTypeFromString(mimeTypeFromFileName(url.toString()));
}
QString UBFileSystemUtils::getFirstExistingFileFromList(const QString& path, const QStringList& files) QString UBFileSystemUtils::getFirstExistingFileFromList(const QString& path, const QStringList& files)
{ {

@ -18,6 +18,8 @@
#include <QtCore> #include <QtCore>
#include "core/UB.h"
class QuaZipFile; class QuaZipFile;
class UBProcessingProgressListener; class UBProcessingProgressListener;
@ -57,6 +59,10 @@ class UBFileSystemUtils
static QString fileExtensionFromMimeType(const QString& pMimeType); static QString fileExtensionFromMimeType(const QString& pMimeType);
static UBMimeType::Enum mimeTypeFromString(const QString& typeString);
static UBMimeType::Enum mimeTypeFromUrl(const QUrl& url);
static QString normalizeFilePath(const QString& pFilePath); static QString normalizeFilePath(const QString& pFilePath);
static QString extension(const QString& filaname); static QString extension(const QString& filaname);

@ -359,6 +359,11 @@ void UBFeaturesWidget::onDisplayMetadata( QMap<QString,QString> metadata )
{ {
QString previewImageUrl; QString previewImageUrl;
switch (UBFileSystemUtils::mimeTypeFromUrl(QUrl(metadata["Url"])))
{
case UBMimeType::RasterImage:
case UBMimeType::VectorImage:
{
previewImageUrl = ":images/libpalette/loading.png"; previewImageUrl = ":images/libpalette/loading.png";
if (!imageGatherer) if (!imageGatherer)
@ -368,6 +373,20 @@ void UBFeaturesWidget::onDisplayMetadata( QMap<QString,QString> metadata )
// We send here the request and store its reply in order to be able to cancel it if needed // We send here the request and store its reply in order to be able to cancel it if needed
imageGatherer->get(QUrl(metadata["Url"]), QPoint(0,0), QSize(), false); imageGatherer->get(QUrl(metadata["Url"]), QPoint(0,0), QSize(), false);
} break;
case UBMimeType::Audio:
{
previewImageUrl = ":images/libpalette/soundIcon.svg";
}break;
case UBMimeType::Video:
{
previewImageUrl = ":images/libpalette/movieIcon.svg";
}break;
case UBMimeType::Flash:
{
previewImageUrl = ":images/libpalette/FlashIcon.svg";
}break;
}
UBFeature feature( QString(), QPixmap(previewImageUrl), QString(), metadata["Url"], FEATURE_ITEM ); UBFeature feature( QString(), QPixmap(previewImageUrl), QString(), metadata["Url"], FEATURE_ITEM );
feature.setMetadata( metadata ); feature.setMetadata( metadata );
@ -380,6 +399,12 @@ void UBFeaturesWidget::onDisplayMetadata( QMap<QString,QString> metadata )
void UBFeaturesWidget::onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground) void UBFeaturesWidget::onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground)
{ {
Q_UNUSED(id);
Q_UNUSED(pSuccess);
Q_UNUSED(isBackground);
Q_UNUSED(pSize);
Q_UNUSED(pPos);
QImage img; QImage img;
img.loadFromData(pData); img.loadFromData(pData);
QPixmap pix = QPixmap::fromImage(img); QPixmap pix = QPixmap::fromImage(img);
@ -776,6 +801,7 @@ void UBFeatureProperties::setOrigPixmap(QPixmap &pix)
void UBFeatureProperties::setThumbnail(QPixmap &pix) void UBFeatureProperties::setThumbnail(QPixmap &pix)
{ {
mpThumbnail->setPixmap(pix.scaledToWidth(THUMBNAIL_WIDTH)); mpThumbnail->setPixmap(pix.scaledToWidth(THUMBNAIL_WIDTH));
adaptSize();
} }
void UBFeatureProperties::adaptSize() void UBFeatureProperties::adaptSize()

Loading…
Cancel
Save