28 #include <QGridLayout>
35 #include <config-kio.h>
36 #ifndef KIO_NO_NEPOMUK
37 #define DISABLE_NEPOMUK_LEGACY
42 #include <QSpacerItem>
47 class KFileMetaDataWidget::Private
64 void initMetaInfoSettings();
71 void updateFileItemRowsVisibility();
75 void slotLoadingFinished();
77 void slotDataChangeStarted();
78 void slotDataChangeFinished();
80 #ifndef KIO_NO_NEPOMUK
87 bool hasNepomukUris()
const;
91 #ifndef KIO_NO_NEPOMUK
102 #ifndef KIO_NO_NEPOMUK
108 initMetaInfoSettings();
110 #ifndef KIO_NO_NEPOMUK
114 connect(m_provider, SIGNAL(loadingFinished()), q, SLOT(slotLoadingFinished()));
115 connect(m_provider, SIGNAL(urlActivated(
KUrl)), q, SIGNAL(urlActivated(
KUrl)));
119 KFileMetaDataWidget::Private::~Private()
123 void KFileMetaDataWidget::Private::initMetaInfoSettings()
125 const int currentVersion = 3;
129 if (
config.group(
"Misc").readEntry(
"version", 0) < currentVersion) {
134 config.deleteGroup(
"Show");
137 static const char*
const disabledProperties[] = {
138 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment",
139 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize",
140 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#depends",
141 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf",
142 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified",
143 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType",
144 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent",
145 "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url",
146 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#averageBitrate",
147 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#channels",
148 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName",
149 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#apertureValue",
150 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureBiasValue",
151 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureTime",
152 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#flash",
153 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLength",
154 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLengthIn35mmFilm",
155 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings",
156 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#make",
157 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode",
158 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#model",
159 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation",
160 "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance",
161 "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#description",
162 "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#hasTag",
163 "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#lastModified",
164 "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#numericRating",
165 "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
167 "kfileitem#permissions",
171 for (
int i = 0; disabledProperties[i] != 0; ++i) {
172 settings.
writeEntry(disabledProperties[i],
false);
176 config.group(
"Misc").writeEntry(
"version", currentVersion);
180 void KFileMetaDataWidget::Private::deleteRows()
182 foreach (
const Row& row, m_rows) {
189 void KFileMetaDataWidget::Private::slotLoadingFinished()
191 #ifndef KIO_NO_NEPOMUK
194 if (!hasNepomukUris()) {
196 emit q->metaDataRequestFinished(m_provider->items());
200 if (m_gridLayout == 0) {
202 m_gridLayout->setMargin(0);
203 m_gridLayout->setSpacing(q->fontMetrics().height() / 4);
212 while (it != data.
end()) {
214 if (!settings.
readEntry(uriString,
true) ||
215 !Nepomuk::Types::Property(it.
key()).userVisible()) {
226 foreach (
const KUrl& key, keys) {
227 const Nepomuk::Variant value = data[key];
228 QString itemLabel = m_provider->label(key);
233 label->
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
240 QWidget* valueWidget = m_provider->createValueWidget(key, value, q);
243 m_gridLayout->addWidget(label, rowIndex, 0, Qt::AlignRight);
244 const int spacerWidth =
QFontMetrics(q->font()).size(Qt::TextSingleLine,
" ").
width();
245 m_gridLayout->addItem(
new QSpacerItem(spacerWidth, 1), rowIndex, 1);
246 m_gridLayout->addWidget(valueWidget, rowIndex, 2, Qt::AlignLeft);
251 row.value = valueWidget;
259 #ifndef KIO_NO_NEPOMUK
260 emit q->metaDataRequestFinished(m_provider->items());
264 void KFileMetaDataWidget::Private::slotLinkActivated(
const QString&
link)
266 const KUrl url(link);
268 emit q->urlActivated(url);
272 void KFileMetaDataWidget::Private::slotDataChangeStarted()
274 q->setEnabled(
false);
277 void KFileMetaDataWidget::Private::slotDataChangeFinished()
282 #ifndef KIO_NO_NEPOMUK
294 QString key = m_provider->group(uri);
295 key += m_provider->label(uri);
306 list.
append(mapIt.value());
313 bool KFileMetaDataWidget::Private::hasNepomukUris()
const
315 foreach (
const KFileItem& fileItem, m_provider->items()) {
337 #ifndef KIO_NO_NEPOMUK
338 d->m_provider->setItems(items);
344 #ifndef KIO_NO_NEPOMUK
345 return d->m_provider->items();
353 #ifndef KIO_NO_NEPOMUK
354 d->m_provider->setReadOnly(readOnly);
360 #ifndef KIO_NO_NEPOMUK
361 return d->m_provider->isReadOnly();
369 if (d->m_gridLayout == 0) {
374 int leftWidthMax = 0;
375 int rightWidthMax = 0;
376 int rightWidthAverage = 0;
377 foreach (
const Private::Row& row, d->m_rows) {
378 const QWidget* valueWidget = row.value;
379 const int rightWidth = valueWidget->
sizeHint().width();
380 rightWidthAverage += rightWidth;
381 if (rightWidth > rightWidthMax) {
382 rightWidthMax = rightWidth;
385 const int leftWidth = row.label->sizeHint().width();
386 if (leftWidth > leftWidthMax) {
387 leftWidthMax = leftWidth;
394 if (d->m_rows.count() > 1) {
395 rightWidthAverage /= d->m_rows.count();
396 if (rightWidthMax > rightWidthAverage * 2) {
397 rightWidthMax = rightWidthAverage * 2;
402 int height = d->m_gridLayout->margin() * 2 + d->m_gridLayout->spacing() * (d->m_rows.count() - 1);
403 foreach (
const Private::Row& row, d->m_rows) {
404 const QWidget* valueWidget = row.value;
405 const int rowHeight = qMax(row.label->heightForWidth(leftWidthMax),
410 const int width = d->m_gridLayout->margin() * 2 + leftWidthMax +
411 d->m_gridLayout->spacing() + rightWidthMax;
413 return QSize(width, height);
421 #include "kfilemetadatawidget.moc"
QString & append(QChar ch)
KUrl nepomukUri() const
Returns the resource URI to be used for Nepomuk annotations.
const Key key(const T &value) const
QString label(StandardShortcut id)
const_iterator constBegin() const
void setAlignment(QFlags< Qt::AlignmentFlag >)
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KSharedConfigPtr config()
void append(const T &value)
const_iterator constEnd() const
const_iterator constEnd() const
List of KFileItems, which adds a few helper methods to QList.
CopyJob * link(const KUrl &src, const KUrl &destDir, JobFlags flags=DefaultFlags)
Create a link.
QFuture< void > map(Sequence &sequence, MapFunction function)
iterator erase(iterator pos)
int width(const QString &text, int len) const
const_iterator constBegin() const
iterator insert(const Key &key, const T &value)
T readEntry(const QString &key, const T &aDefault) const
void setWordWrap(bool on)
A KFileItem is a generic class to handle a file, local or remote.
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.