Simplified the clickable resource metadata display. This also fixes a bug where sometimes resources are not displayed at all

svn path=/trunk/KDE/kdebase/apps/; revision=1052237
This commit is contained in:
Sebastian Trueg 2009-11-21 09:33:37 +00:00
parent 83e8cdf8fb
commit ccd9a32988
3 changed files with 9 additions and 34 deletions

View file

@ -23,6 +23,7 @@
#include <kconfiggroup.h> #include <kconfiggroup.h>
#include <kglobal.h> #include <kglobal.h>
#include <klocale.h> #include <klocale.h>
#include <kdebug.h>
#include <nepomuk/resource.h> #include <nepomuk/resource.h>
@ -100,11 +101,7 @@ void KLoadMetaDataThread::run()
Item item; Item item;
item.name = prop.name(); item.name = prop.name();
item.label = tunedLabel(prop.label()); item.label = tunedLabel(prop.label());
if (it.value().isResource() || it.value().isResourceList()) { item.value = formatValue(it.value());
item.resources = it.value().toResourceList();
} else {
item.value = formatValue(it.value());
}
m_items.append(item); m_items.append(item);
} }
++it; ++it;
@ -168,14 +165,14 @@ QString KLoadMetaDataThread::formatValue(const Nepomuk::Variant& value)
{ {
if (value.isDateTime()) { if (value.isDateTime()) {
return KGlobal::locale()->formatDateTime(value.toDateTime(), KLocale::FancyLongDate); return KGlobal::locale()->formatDateTime(value.toDateTime(), KLocale::FancyLongDate);
} else if (value.isResource()) { } else if (value.isResource() || value.isResourceList()) {
return value.toResource().genericLabel(); QStringList links;
} else if (value.isResourceList()) {
QStringList list;
foreach(const Nepomuk::Resource& res, value.toResourceList()) { foreach(const Nepomuk::Resource& res, value.toResourceList()) {
list << res.genericLabel(); links << QString::fromLatin1("<a href=\"%1\">%2</a>")
.arg(KUrl(res.resourceUri()).url())
.arg(res.genericLabel());
} }
return list.join(QLatin1String(";\n")); return QLatin1String("<p>") + links.join(QLatin1String(";\n"));
} else { } else {
return value.toString(); return value.toString();
} }

View file

@ -42,7 +42,6 @@ public:
QString name; QString name;
QString label; QString label;
QString value; QString value;
QList<Nepomuk::Resource> resources;
}; };
KLoadMetaDataThread(); KLoadMetaDataThread();

View file

@ -108,12 +108,6 @@ public:
* Merges items like 'width' and 'height' as one item. * Merges items like 'width' and 'height' as one item.
*/ */
QList<KLoadMetaDataThread::Item> mergedItems(const QList<KLoadMetaDataThread::Item>& items); QList<KLoadMetaDataThread::Item> mergedItems(const QList<KLoadMetaDataThread::Item>& items);
/**
* Returns a (clickable) text for the given item, that can be used for
* the information value widget.
*/
QString labelText(const KLoadMetaDataThread::Item& item) const;
#endif #endif
bool m_sizeVisible; bool m_sizeVisible;
@ -372,7 +366,7 @@ void KMetaDataWidget::Private::slotLoadingFinished()
} else { } else {
// create new row // create new row
QLabel* infoLabel = new QLabel(item.label, q); QLabel* infoLabel = new QLabel(item.label, q);
QLabel* infoValue = new QLabel(labelText(item), q); QLabel* infoValue = new QLabel(item.value, q);
connect(infoValue, SIGNAL(linkActivated(QString)), connect(infoValue, SIGNAL(linkActivated(QString)),
q, SLOT(slotLinkActivated(QString))); q, SLOT(slotLinkActivated(QString)));
addRow(infoLabel, infoValue); addRow(infoLabel, infoValue);
@ -503,21 +497,6 @@ QList<KLoadMetaDataThread::Item>
return mergedItems; return mergedItems;
} }
QString KMetaDataWidget::Private::labelText(const KLoadMetaDataThread::Item& item) const
{
if (item.resources.isEmpty()) {
return item.value;
}
QStringList links;
foreach(const Nepomuk::Resource& res, item.resources) {
links << QString::fromLatin1("<a href=\"%1\">%2</a>")
.arg(KUrl(res.resourceUri()).url())
.arg(res.genericLabel());
}
return QLatin1String("<p>") + links.join(QLatin1String(";\n"));
}
#endif #endif
KMetaDataWidget::KMetaDataWidget(QWidget* parent) : KMetaDataWidget::KMetaDataWidget(QWidget* parent) :