mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
* don't show the "Add Tags..." and "Add Comments..." links for the meta data inside a tooltip
* minor cleanup of thread-interface to allow a proper sorting/merging on client side svn path=/trunk/KDE/kdebase/apps/; revision=1047662
This commit is contained in:
parent
6d0ddb92fd
commit
36ae0b6185
9 changed files with 143 additions and 72 deletions
|
@ -29,6 +29,7 @@
|
|||
|
||||
KCommentWidget::KCommentWidget(QWidget* parent) :
|
||||
QWidget(parent),
|
||||
m_readOnly(false),
|
||||
m_label(0),
|
||||
m_comment()
|
||||
{
|
||||
|
@ -51,11 +52,22 @@ KCommentWidget::~KCommentWidget()
|
|||
|
||||
void KCommentWidget::setText(const QString& comment)
|
||||
{
|
||||
QString text;
|
||||
if (comment.isEmpty()) {
|
||||
m_label->setText("<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>");
|
||||
if (m_readOnly) {
|
||||
text = "-";
|
||||
} else {
|
||||
m_label->setText("<p>" + comment + " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>");
|
||||
text = "<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>";
|
||||
}
|
||||
} else {
|
||||
if (m_readOnly) {
|
||||
text = comment;
|
||||
} else {
|
||||
text = "<p>" + comment + " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>";
|
||||
}
|
||||
}
|
||||
|
||||
m_label->setText(text);
|
||||
m_comment = comment;
|
||||
}
|
||||
|
||||
|
@ -64,6 +76,17 @@ QString KCommentWidget::text() const
|
|||
return m_comment;
|
||||
}
|
||||
|
||||
void KCommentWidget::setReadOnly(bool readOnly)
|
||||
{
|
||||
m_readOnly = readOnly;
|
||||
setText(m_comment);
|
||||
}
|
||||
|
||||
bool KCommentWidget::isReadOnly() const
|
||||
{
|
||||
return m_readOnly;
|
||||
}
|
||||
|
||||
void KCommentWidget::slotLinkActivated(const QString& link)
|
||||
{
|
||||
KDialog dialog(this, Qt::Dialog);
|
||||
|
|
|
@ -39,6 +39,14 @@ public:
|
|||
void setText(const QString& comment);
|
||||
QString text() const;
|
||||
|
||||
/**
|
||||
* If set to true, the comment cannot be changed by the user.
|
||||
* Per default read-only is disabled.
|
||||
*/
|
||||
// TODO: provide common interface class for metadatawidgets
|
||||
void setReadOnly(bool readOnly);
|
||||
bool isReadOnly() const;
|
||||
|
||||
signals:
|
||||
void commentChanged(const QString& comment);
|
||||
|
||||
|
@ -46,6 +54,7 @@ private slots:
|
|||
void slotLinkActivated(const QString& link);
|
||||
|
||||
private:
|
||||
bool m_readOnly;
|
||||
QLabel* m_label;
|
||||
QString m_comment;
|
||||
};
|
||||
|
|
|
@ -24,15 +24,13 @@
|
|||
#include <kglobal.h>
|
||||
#include <klocale.h>
|
||||
|
||||
#include <nepomuk/variant.h>
|
||||
#include <nepomuk/resource.h>
|
||||
|
||||
KLoadMetaDataThread::KLoadMetaDataThread() :
|
||||
m_rating(0),
|
||||
m_comment(),
|
||||
m_tags(),
|
||||
m_metaInfoLabels(),
|
||||
m_metaInfoValues(),
|
||||
m_items(),
|
||||
m_files(),
|
||||
m_urls(),
|
||||
m_canceled(false)
|
||||
|
@ -95,17 +93,16 @@ void KLoadMetaDataThread::run()
|
|||
if (first && (m_urls.count() == 1)) {
|
||||
// TODO: show shared meta information instead
|
||||
// of not showing anything on multiple selections
|
||||
QHash<QUrl, Nepomuk::Variant> properties = file.properties();
|
||||
QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
|
||||
while (it != properties.constEnd()) {
|
||||
QHash<QUrl, Nepomuk::Variant> variants = file.properties();
|
||||
QHash<QUrl, Nepomuk::Variant>::const_iterator it = variants.constBegin();
|
||||
while (it != variants.constEnd()) {
|
||||
Nepomuk::Types::Property prop(it.key());
|
||||
if (settings.readEntry(prop.name(), true)) {
|
||||
// TODO #1: use Nepomuk::formatValue(res, prop) if available
|
||||
// instead of it.value().toString()
|
||||
// TODO #2: using tunedLabel() is a workaround for KDE 4.3 (4.4?) until
|
||||
// we get translated labels
|
||||
m_metaInfoLabels.append(tunedLabel(prop.label()));
|
||||
m_metaInfoValues.append(formatValue(it.value()));
|
||||
Item item;
|
||||
item.name = prop.name();
|
||||
item.label = tunedLabel(prop.label());
|
||||
item.value = formatValue(it.value());
|
||||
m_items.append(item);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
@ -130,14 +127,9 @@ QList<Nepomuk::Tag> KLoadMetaDataThread::tags() const
|
|||
return m_tags;
|
||||
}
|
||||
|
||||
QList<QString> KLoadMetaDataThread::metaInfoLabels() const
|
||||
QList<KLoadMetaDataThread::Item> KLoadMetaDataThread::items() const
|
||||
{
|
||||
return m_metaInfoLabels;
|
||||
}
|
||||
|
||||
QList<QString> KLoadMetaDataThread::metaInfoValues() const
|
||||
{
|
||||
return m_metaInfoValues;
|
||||
return m_items;
|
||||
}
|
||||
|
||||
QMap<KUrl, Nepomuk::Resource> KLoadMetaDataThread::files() const
|
||||
|
@ -169,26 +161,19 @@ QString KLoadMetaDataThread::tunedLabel(const QString& label) const
|
|||
return tunedLabel + ':';
|
||||
}
|
||||
|
||||
|
||||
// This is a short hack until we have a proper formatting facility in Nepomuk
|
||||
// here we simply handle the most common formatting situations that do not look nice
|
||||
// when using Nepomuk::Variant::toString()
|
||||
QString KLoadMetaDataThread::formatValue(const Nepomuk::Variant& value)
|
||||
{
|
||||
if (value.isDateTime()) {
|
||||
return KGlobal::locale()->formatDateTime(value.toDateTime(), KLocale::FancyLongDate);
|
||||
}
|
||||
else if (value.isResource()) {
|
||||
} else if (value.isResource()) {
|
||||
return value.toResource().genericLabel();
|
||||
}
|
||||
else if (value.isResourceList()) {
|
||||
QStringList ll;
|
||||
} else if (value.isResourceList()) {
|
||||
QStringList list;
|
||||
foreach(const Nepomuk::Resource& res, value.toResourceList()) {
|
||||
ll << res.genericLabel();
|
||||
list << res.genericLabel();
|
||||
}
|
||||
return ll.join(QLatin1String(";\n"));
|
||||
}
|
||||
else {
|
||||
return list.join(QLatin1String(";\n"));
|
||||
} else {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define DISABLE_NEPOMUK_LEGACY
|
||||
#include <nepomuk/property.h>
|
||||
#include <nepomuk/tag.h>
|
||||
#include <nepomuk/variant.h>
|
||||
|
||||
#include <kurl.h>
|
||||
#include <QList>
|
||||
|
@ -36,6 +37,13 @@ class KLoadMetaDataThread : public QThread
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct Item
|
||||
{
|
||||
QString name;
|
||||
QString label;
|
||||
QString value;
|
||||
};
|
||||
|
||||
KLoadMetaDataThread();
|
||||
virtual ~KLoadMetaDataThread();
|
||||
|
||||
|
@ -62,8 +70,7 @@ public:
|
|||
int rating() const;
|
||||
QString comment() const;
|
||||
QList<Nepomuk::Tag> tags() const;
|
||||
QList<QString> metaInfoLabels() const;
|
||||
QList<QString> metaInfoValues() const;
|
||||
QList<Item> items() const;
|
||||
QMap<KUrl, Nepomuk::Resource> files() const;
|
||||
|
||||
private slots:
|
||||
|
@ -71,21 +78,16 @@ private slots:
|
|||
|
||||
private:
|
||||
/**
|
||||
* Assures that the settings for the meta information
|
||||
* are initialized with proper default values.
|
||||
*/
|
||||
void initMetaInfoSettings(KConfigGroup& group);
|
||||
|
||||
/**
|
||||
* Temporary helper method for KDE 4.3 as we currently don't get
|
||||
* translated labels for Nepmok literals: Replaces camelcase labels
|
||||
* Temporary helper method there is a way to get translated
|
||||
* labels for Nepmok literals: Replaces camelcase labels
|
||||
* like "fileLocation" by "File Location:".
|
||||
*/
|
||||
QString tunedLabel(const QString& label) const;
|
||||
|
||||
/**
|
||||
* Temporary helper method which tries to pretty print
|
||||
* values.
|
||||
* Temporary helper method until there is a proper formatting facility in Nepomuk.
|
||||
* Here we simply handle the most common formatting situations that do not look nice
|
||||
* when using Nepomuk::Variant::toString().
|
||||
*/
|
||||
QString formatValue(const Nepomuk::Variant& value);
|
||||
|
||||
|
@ -93,8 +95,7 @@ private:
|
|||
int m_rating;
|
||||
QString m_comment;
|
||||
QList<Nepomuk::Tag> m_tags;
|
||||
QList<QString> m_metaInfoLabels;
|
||||
QList<QString> m_metaInfoValues;
|
||||
QList<Item> m_items;
|
||||
QMap<KUrl, Nepomuk::Resource> m_files;
|
||||
|
||||
KUrl::List m_urls;
|
||||
|
|
|
@ -102,7 +102,8 @@ public:
|
|||
*/
|
||||
void startChangeDataJob(KJob* job);
|
||||
|
||||
bool m_isSizeVisible;
|
||||
bool m_sizeVisible;
|
||||
bool m_readOnly;
|
||||
MetaDataTypes m_visibleDataTypes;
|
||||
QList<KFileItem> m_fileItems;
|
||||
QList<Row> m_rows;
|
||||
|
@ -131,7 +132,8 @@ private:
|
|||
};
|
||||
|
||||
KMetaDataWidget::Private::Private(KMetaDataWidget* parent) :
|
||||
m_isSizeVisible(true),
|
||||
m_sizeVisible(true),
|
||||
m_readOnly(false),
|
||||
m_visibleDataTypes(TypeData | SizeData | ModifiedData | OwnerData |
|
||||
PermissionsData | RatingData | TagsData | CommentData),
|
||||
m_fileItems(),
|
||||
|
@ -288,12 +290,12 @@ void KMetaDataWidget::Private::updateRowsVisibility()
|
|||
(m_visibleDataTypes & KMetaDataWidget::TypeData) &&
|
||||
settings.readEntry("type", true));
|
||||
|
||||
// Cache in m_isSizeVisible whether the size should be shown. This
|
||||
// Cache in m_sizeVisible whether the size should be shown. This
|
||||
// is necessary as the size is temporary hidden when the target
|
||||
// file item is a directory.
|
||||
m_isSizeVisible = (m_visibleDataTypes & KMetaDataWidget::SizeData) &&
|
||||
m_sizeVisible = (m_visibleDataTypes & KMetaDataWidget::SizeData) &&
|
||||
settings.readEntry("size", true);
|
||||
setRowVisible(m_sizeInfo, m_isSizeVisible);
|
||||
setRowVisible(m_sizeInfo, m_sizeVisible);
|
||||
|
||||
setRowVisible(m_modifiedInfo,
|
||||
(m_visibleDataTypes & KMetaDataWidget::ModifiedData) &&
|
||||
|
@ -339,31 +341,28 @@ void KMetaDataWidget::Private::slotLoadingFinished()
|
|||
const int rowCount = m_rows.count();
|
||||
Q_ASSERT(rowCount >= index);
|
||||
|
||||
Q_ASSERT(m_loadMetaDataThread->metaInfoLabels().count() == m_loadMetaDataThread->metaInfoValues().count());
|
||||
const int metaInfoCount = m_loadMetaDataThread->metaInfoLabels().count();
|
||||
for (int i = 0; i < metaInfoCount; ++i) {
|
||||
const QList<QString> metaInfoLabels = m_loadMetaDataThread->metaInfoLabels();
|
||||
const QList<QString> metaInfoValues = m_loadMetaDataThread->metaInfoValues();
|
||||
const QList<KLoadMetaDataThread::Item> items = m_loadMetaDataThread->items();
|
||||
foreach (const KLoadMetaDataThread::Item& item, items) {
|
||||
if (index < rowCount) {
|
||||
// adjust texts of the current row
|
||||
m_rows[index].label->setText(metaInfoLabels[i]);
|
||||
m_rows[index].label->setText(item.label);
|
||||
QLabel* infoValueLabel = qobject_cast<QLabel*>(m_rows[index].infoWidget);
|
||||
Q_ASSERT(infoValueLabel != 0);
|
||||
infoValueLabel->setText(metaInfoValues[i]);
|
||||
infoValueLabel->setText(item.value);
|
||||
} else {
|
||||
// create new row
|
||||
QLabel* infoLabel = new QLabel(metaInfoLabels[i], q);
|
||||
QLabel* infoValue = new QLabel(metaInfoValues[i], q);
|
||||
QLabel* infoLabel = new QLabel(item.label, q);
|
||||
QLabel* infoValue = new QLabel(item.value, q);
|
||||
addRow(infoLabel, infoValue);
|
||||
}
|
||||
++index;
|
||||
}
|
||||
if (metaInfoCount > 0) {
|
||||
if (items.count() > 0) {
|
||||
--index;
|
||||
}
|
||||
|
||||
// remove rows that are not needed anymore
|
||||
for (int i = rowCount - 1; i > index; --i) {
|
||||
for (int i = m_rows.count() - 1; i > index; --i) {
|
||||
delete m_rows[i].label;
|
||||
delete m_rows[i].infoWidget;
|
||||
m_rows.pop_back();
|
||||
|
@ -452,7 +451,7 @@ void KMetaDataWidget::setItem(const KFileItem& item)
|
|||
} else {
|
||||
d->m_typeInfo->setText(item.mimeComment());
|
||||
d->m_sizeInfo->setText(KIO::convertSize(item.size()));
|
||||
d->setRowVisible(d->m_sizeInfo, d->m_isSizeVisible);
|
||||
d->setRowVisible(d->m_sizeInfo, d->m_sizeVisible);
|
||||
}
|
||||
d->m_modifiedInfo->setText(KGlobal::locale()->formatDateTime(item.time(KFileItem::ModificationTime), KLocale::FancyLongDate));
|
||||
d->m_ownerInfo->setText(item.user());
|
||||
|
@ -469,7 +468,7 @@ void KMetaDataWidget::setItems(const KFileItemList& items)
|
|||
// calculate the size of all items and show this
|
||||
// information to the user
|
||||
d->m_sizeLabel->setText(i18nc("@label", "Total Size:"));
|
||||
d->setRowVisible(d->m_sizeInfo, d->m_isSizeVisible);
|
||||
d->setRowVisible(d->m_sizeInfo, d->m_sizeVisible);
|
||||
|
||||
quint64 totalSize = 0;
|
||||
foreach (const KFileItem& item, items) {
|
||||
|
@ -525,6 +524,21 @@ KFileItemList KMetaDataWidget::items() const
|
|||
return d->m_fileItems;
|
||||
}
|
||||
|
||||
void KMetaDataWidget::setReadOnly(bool readOnly)
|
||||
{
|
||||
d->m_readOnly = readOnly;
|
||||
#ifdef HAVE_NEPOMUK
|
||||
// TODO: encapsulate this code as part of a metadata-model for KDE 4.5
|
||||
d->m_taggingWidget->setReadOnly(readOnly);
|
||||
d->m_commentWidget->setReadOnly(readOnly);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool KMetaDataWidget::isReadOnly() const
|
||||
{
|
||||
return d->m_readOnly;
|
||||
}
|
||||
|
||||
void KMetaDataWidget::setVisibleDataTypes(MetaDataTypes data)
|
||||
{
|
||||
d->m_visibleDataTypes = data;
|
||||
|
|
|
@ -99,6 +99,13 @@ public:
|
|||
|
||||
KFileItemList items() const;
|
||||
|
||||
/**
|
||||
* If set to true, data like comment, tag or rating cannot be changed by the user.
|
||||
* Per default read-only is disabled.
|
||||
*/
|
||||
void setReadOnly(bool readOnly);
|
||||
bool isReadOnly() const;
|
||||
|
||||
/**
|
||||
* Specifies which kind of data types should be shown (@see KMetaDataWidget::Data).
|
||||
* Example: metaDataWidget->setVisibleDataTypes(KMetaDataWidget::TypeData | KMetaDataWidget::ModifiedData);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
KTaggingWidget::KTaggingWidget(QWidget* parent) :
|
||||
QWidget(parent),
|
||||
m_readOnly(false),
|
||||
m_label(0),
|
||||
m_tags(),
|
||||
m_tagsText()
|
||||
|
@ -63,11 +64,21 @@ void KTaggingWidget::setTags(const QList<Nepomuk::Tag>& tags)
|
|||
first = false;
|
||||
}
|
||||
|
||||
QString text;
|
||||
if (m_tagsText.isEmpty()) {
|
||||
m_label->setText("<a href=\"addTags\">" + i18nc("@label", "Add Tags...") + "</a>");
|
||||
if (m_readOnly) {
|
||||
text = "-";
|
||||
} else {
|
||||
m_label->setText("<p>" + m_tagsText + " <a href=\"changeTags\">" + i18nc("@label", "Change...") + "</a></p>");
|
||||
text = "<a href=\"addTags\">" + i18nc("@label", "Add Tags...") + "</a>";
|
||||
}
|
||||
} else {
|
||||
if (m_readOnly) {
|
||||
text = m_tagsText;
|
||||
} else {
|
||||
text = "<p>" + m_tagsText + " <a href=\"changeTags\">" + i18nc("@label", "Change...") + "</a></p>";
|
||||
}
|
||||
}
|
||||
m_label->setText(text);
|
||||
}
|
||||
|
||||
QList<Nepomuk::Tag> KTaggingWidget::tags() const
|
||||
|
@ -75,6 +86,17 @@ QList<Nepomuk::Tag> KTaggingWidget::tags() const
|
|||
return m_tags;
|
||||
}
|
||||
|
||||
void KTaggingWidget::setReadOnly(bool readOnly)
|
||||
{
|
||||
m_readOnly = readOnly;
|
||||
setTags(m_tags);
|
||||
}
|
||||
|
||||
bool KTaggingWidget::isReadOnly() const
|
||||
{
|
||||
return m_readOnly;
|
||||
}
|
||||
|
||||
void KTaggingWidget::slotLinkActivated(const QString& link)
|
||||
{
|
||||
Q_UNUSED(link);
|
||||
|
|
|
@ -39,6 +39,14 @@ public:
|
|||
void setTags(const QList<Nepomuk::Tag>& tags);
|
||||
QList<Nepomuk::Tag> tags() const;
|
||||
|
||||
/**
|
||||
* If set to true, the tags cannot be changed by the user.
|
||||
* Per default read-only is disabled.
|
||||
*/
|
||||
// TODO: provide common interface class for metadatawidgets
|
||||
void setReadOnly(bool readOnly);
|
||||
bool isReadOnly() const;
|
||||
|
||||
signals:
|
||||
void tagsChanged(const QList<Nepomuk::Tag>& tags);
|
||||
|
||||
|
@ -46,6 +54,7 @@ private slots:
|
|||
void slotLinkActivated(const QString& link);
|
||||
|
||||
private:
|
||||
bool m_readOnly;
|
||||
QLabel* m_label;
|
||||
QList<Nepomuk::Tag> m_tags;
|
||||
QString m_tagsText;
|
||||
|
|
|
@ -250,6 +250,7 @@ QWidget* ToolTipManager::createTipContent(const QPixmap& pixmap) const
|
|||
KMetaDataWidget* metaDataWidget = new KMetaDataWidget(tipContent);
|
||||
metaDataWidget->setItem(m_item);
|
||||
metaDataWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
metaDataWidget->setReadOnly(true);
|
||||
|
||||
QHBoxLayout* tipLayout = new QHBoxLayout(tipContent);
|
||||
tipLayout->setMargin(0);
|
||||
|
|
Loading…
Reference in a new issue