#include "documentpropertieswidget.h"
#include "metadatabinding.h"
#include <qdocumentgallery.h>
#include <qgalleryitemrequest.h>
#include <qgalleryqueryrequest.h>
#include <qgalleryresultset.h>
#include <QtGui>
#include <qaction.h>
DocumentPropertiesWidget::DocumentPropertiesWidget(
const QFileInfo &file, QDocumentGallery *gallery, QWidget *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
, documentGallery(gallery)
, queryRequest(0)
, itemRequest(0)
{
QAction* doneAction = new QAction(tr("Done"), this);
doneAction->setSoftKeyRole(QAction::PositiveSoftKey);
connect(doneAction, SIGNAL(triggered()), parent, SLOT(close()));
addAction(doneAction);
QFormLayout *layout = new QFormLayout;
setLayout(layout);
queryRequest = new QGalleryQueryRequest(documentGallery, this);
queryRequest->setRootType(QDocumentGallery::File);
queryRequest->setFilter(QDocumentGallery::filePath == file.absoluteFilePath());
queryRequest->setPropertyNames(QStringList()
<< QDocumentGallery::fileName
<< QDocumentGallery::mimeType
<< QDocumentGallery::path
<< QDocumentGallery::fileSize
<< QDocumentGallery::lastModified
<< QDocumentGallery::lastAccessed);
queryRequest->execute();
resultSet = queryRequest->resultSet();
if (resultSet) {
addTextPropertyRow("File Name", QDocumentGallery::fileName);
addTextPropertyRow("Type", QDocumentGallery::mimeType);
addTextPropertyRow("Path", QDocumentGallery::path);
addTextPropertyRow("Size", QDocumentGallery::fileSize);
addTimePropertyRow("Modified", QDocumentGallery::lastModified);
addTimePropertyRow("Accessed", QDocumentGallery::lastAccessed);
if (queryRequest->state() == QGalleryAbstractRequest::Active)
connect(queryRequest, SIGNAL(finished()), this, SLOT(queryRequestFinished()));
else if (queryRequest->state() == QGalleryAbstractRequest::Finished)
queryRequestFinished();
}
}
void DocumentPropertiesWidget::addTextPropertyRow(const char *rowTitle,
const QString &propertyName)
{
QLineEdit *propertyValue = new QLineEdit;
propertyValue->setReadOnly(true);
addRowWithTitleAndValue(rowTitle, propertyValue);
new MetaDataBinding(propertyValue, "text", resultSet, propertyName, this);
}
void DocumentPropertiesWidget::addRowWithTitleAndValue(
const char *rowTitle, QWidget *propertyValue)
{
QLineEdit *title = new QLineEdit(tr(rowTitle));
title->setReadOnly(true);
QFormLayout *layout = static_cast<QFormLayout *> (this->layout());
layout->addRow(title, propertyValue);
}
void DocumentPropertiesWidget::addTimePropertyRow(
const char *rowTitle, const QString &propertyName)
{
QDateTimeEdit *propertyValue = new QDateTimeEdit;
propertyValue->setReadOnly(true);
addRowWithTitleAndValue(rowTitle, propertyValue);
new MetaDataBinding(propertyValue, "dateTime", resultSet, propertyName, this);
}
void DocumentPropertiesWidget::queryRequestFinished()
{
if (queryRequest->seek(0)) {
if (queryRequest->itemType() == QDocumentGallery::Audio)
requestAudioProperties();
else if (queryRequest->itemType() == QDocumentGallery::Video)
requestVideoProperties();
else if (queryRequest->itemType() == QDocumentGallery::Image)
requestImageProperties();
else if (queryRequest->itemType() == QDocumentGallery::Document)
requestDocumentProperties();
}
}
void DocumentPropertiesWidget::requestAudioProperties()
{
makeItemRequestForProperties(QStringList()
<< QDocumentGallery::title
<< QDocumentGallery::artist
<< QDocumentGallery::albumTitle
<< QDocumentGallery::albumArtist
<< QDocumentGallery::genre
<< QDocumentGallery::duration);
resultSet = itemRequest->resultSet();
if (resultSet) {
addTextPropertyRow("Title", QDocumentGallery::title);
addTextPropertyRow("Artist", QDocumentGallery::artist);
addTextPropertyRow("Album", QDocumentGallery::albumTitle);
addTextPropertyRow("Album Artist", QDocumentGallery::albumArtist);
addTextPropertyRow("Genre", QDocumentGallery::genre);
addTextPropertyRow("Duration", QDocumentGallery::duration);
}
}
void DocumentPropertiesWidget::makeItemRequestForProperties(const QStringList &propertyNames)
{
itemRequest = new QGalleryItemRequest(documentGallery, this);
itemRequest->setItemId(queryRequest->itemId());
itemRequest->setPropertyNames(propertyNames);
itemRequest->execute();
}
void DocumentPropertiesWidget::requestDocumentProperties()
{
makeItemRequestForProperties(QStringList()
<< QDocumentGallery::title
<< QDocumentGallery::author
<< QDocumentGallery::pageCount);
resultSet = itemRequest->resultSet();
if (resultSet) {
addTextPropertyRow("Title", QDocumentGallery::title);
addTextPropertyRow("Author", QDocumentGallery::author);
addTextPropertyRow("Page Count", QDocumentGallery::pageCount);
}
}
void DocumentPropertiesWidget::requestImageProperties()
{
makeItemRequestForProperties(QStringList()
<< QDocumentGallery::title
<< QDocumentGallery::width
<< QDocumentGallery::height
<< QDocumentGallery::keywords);
resultSet = itemRequest->resultSet();
if (resultSet) {
addTextPropertyRow("Title", QDocumentGallery::title);
addTextPropertyRow("Width", QDocumentGallery::width);
addTextPropertyRow("Height", QDocumentGallery::height);
addTextPropertyRow("Keywords", QDocumentGallery::keywords);
}
}
void DocumentPropertiesWidget::requestVideoProperties()
{
makeItemRequestForProperties(QStringList()
<< QDocumentGallery::title
<< QDocumentGallery::width
<< QDocumentGallery::height
<< QDocumentGallery::duration);
resultSet = itemRequest->resultSet();
if (resultSet) {
addTextPropertyRow("Title", QDocumentGallery::title);
addTextPropertyRow("Width", QDocumentGallery::width);
addTextPropertyRow("Height", QDocumentGallery::height);
addTextPropertyRow("Duration", QDocumentGallery::duration);
}
}