#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;
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();
if (QGalleryResultSet *resultSet = queryRequest->resultSet()) {
QLabel *fileName = new QLabel;
layout->addRow(tr("File Name"), fileName);
new MetaDataBinding(fileName, "text", resultSet, QDocumentGallery::fileName, this);
QLabel *mimeType = new QLabel;
layout->addRow(tr("Type"), mimeType);
new MetaDataBinding(mimeType, "text", resultSet, QDocumentGallery::mimeType, this);
QLabel *path = new QLabel;
layout->addRow(tr("Path"), path);
new MetaDataBinding(path, "text", resultSet, QDocumentGallery::path, this);
QLabel *size = new QLabel;
layout->addRow(tr("Size"), size);
new MetaDataBinding(size, "text", resultSet, QDocumentGallery::fileSize, this);
QDateTimeEdit *lastModified = new QDateTimeEdit;
lastModified->setReadOnly(true);
layout->addRow(tr("Modified"), lastModified);
new MetaDataBinding(
lastModified, "dateTime", resultSet, QDocumentGallery::lastModified, this);
QDateTimeEdit *lastAccessed = new QDateTimeEdit;
lastAccessed->setReadOnly(true);
layout->addRow(tr("Accessed"), lastAccessed);
new MetaDataBinding(
lastAccessed, "dateTime", resultSet, QDocumentGallery::lastAccessed, this);
setLayout(layout);
if (queryRequest->state() == QGalleryAbstractRequest::Active)
connect(queryRequest, SIGNAL(finished()), this, SLOT(queryRequestFinished()));
else if (queryRequest->state() == QGalleryAbstractRequest::Finished)
queryRequestFinished();
}
}
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()
{
itemRequest = new QGalleryItemRequest(documentGallery, this);
itemRequest->setItemId(queryRequest->itemId());
itemRequest->setPropertyNames(QStringList()
<< QDocumentGallery::title
<< QDocumentGallery::artist
<< QDocumentGallery::albumTitle
<< QDocumentGallery::albumArtist
<< QDocumentGallery::genre
<< QDocumentGallery::duration);
itemRequest->execute();
if (QGalleryResultSet *resultSet = itemRequest->resultSet()) {
QFormLayout *layout = static_cast<QFormLayout *>(QWidget::layout());
QLabel *title = new QLabel;
layout->addRow(tr("Title"), title);
new MetaDataBinding(title, "text", resultSet, QDocumentGallery::title, this);
QLabel *artist = new QLabel;
layout->addRow(tr("Artist"), artist);
new MetaDataBinding(artist, "text", resultSet, QDocumentGallery::artist, this);
QLabel *album = new QLabel;
layout->addRow(tr("Album"), album);
new MetaDataBinding(album, "text", resultSet, QDocumentGallery::albumTitle, this);
QLabel *albumArtist = new QLabel;
layout->addRow(tr("Album Artist"), albumArtist);
new MetaDataBinding(albumArtist, "text", resultSet, QDocumentGallery::albumArtist, this);
QLabel *genre = new QLabel;
layout->addRow(tr("Genre"), genre);
new MetaDataBinding(genre, "text", resultSet, QDocumentGallery::genre, this);
QLabel *duration = new QLabel;
layout->addRow(tr("Duration"), duration);
new MetaDataBinding(duration, "text", resultSet, QDocumentGallery::duration, this);
}
}
void DocumentPropertiesWidget::requestDocumentProperties()
{
itemRequest = new QGalleryItemRequest(documentGallery, this);
itemRequest->setItemId(queryRequest->itemId());
itemRequest->setPropertyNames(QStringList()
<< QDocumentGallery::title
<< QDocumentGallery::author
<< QDocumentGallery::pageCount);
itemRequest->execute();
if (QGalleryResultSet *resultSet = itemRequest->resultSet()) {
QFormLayout *layout = static_cast<QFormLayout *>(QWidget::layout());
QLabel *title = new QLabel;
layout->addRow(tr("Title"), title);
new MetaDataBinding(title, "text", resultSet, QDocumentGallery::title, this);
QLabel *author = new QLabel;
layout->addRow(tr("Author"), author);
new MetaDataBinding(author, "text", resultSet, QDocumentGallery::author, this);
QLabel *pageCount = new QLabel;
layout->addRow(tr("Page Count"), pageCount);
new MetaDataBinding(pageCount, "text", resultSet, QDocumentGallery::pageCount, this);
}
}
void DocumentPropertiesWidget::requestImageProperties()
{
itemRequest = new QGalleryItemRequest(documentGallery, this);
itemRequest->setItemId(queryRequest->itemId());
itemRequest->setPropertyNames(QStringList()
<< QDocumentGallery::title
<< QDocumentGallery::width
<< QDocumentGallery::height
<< QDocumentGallery::keywords);
itemRequest->execute();
if (QGalleryResultSet *resultSet = itemRequest->resultSet()) {
QFormLayout *layout = static_cast<QFormLayout *>(QWidget::layout());
QLabel *title = new QLabel;
layout->addRow(tr("Title"), title);
new MetaDataBinding(title, "text", resultSet, QDocumentGallery::title, this);
QLabel *width = new QLabel;
layout->addRow(tr("Width"), width);
new MetaDataBinding(width, "text", resultSet, QDocumentGallery::width, this);
QLabel *height = new QLabel;
layout->addRow(tr("Height"), height);
new MetaDataBinding(height, "text", resultSet, QDocumentGallery::height, this);
QLabel *keywords = new QLabel;
layout->addRow(tr("Keywords"), keywords);
new MetaDataBinding(keywords, "text", resultSet, QDocumentGallery::keywords, this);
}
}
void DocumentPropertiesWidget::requestVideoProperties()
{
itemRequest = new QGalleryItemRequest(documentGallery, this);
itemRequest->setItemId(queryRequest->itemId());
itemRequest->setPropertyNames(QStringList()
<< QDocumentGallery::title
<< QDocumentGallery::width
<< QDocumentGallery::height
<< QDocumentGallery::duration);
itemRequest->execute();
if (QGalleryResultSet *resultSet = itemRequest->resultSet()) {
QFormLayout *layout = static_cast<QFormLayout *>(QWidget::layout());
QLabel *title = new QLabel;
layout->addRow(tr("Title"), title);
new MetaDataBinding(title, "text", resultSet, QDocumentGallery::title, this);
QLabel *width = new QLabel;
layout->addRow(tr("Width"), width);
new MetaDataBinding(width, "text", resultSet, QDocumentGallery::width, this);
QLabel *height = new QLabel;
layout->addRow(tr("Height"), height);
new MetaDataBinding(height, "text", resultSet, QDocumentGallery::height, this);
QLabel *duration = new QLabel;
layout->addRow(tr("Duration"), duration);
new MetaDataBinding(duration, "text", resultSet, QDocumentGallery::duration, this);
}
}