┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2009-10-10 21:28:37 +0000
committerPeter Penz <[email protected]>2009-10-10 21:28:37 +0000
commitb786c28e0431e01c5938a824709046fa149a6977 (patch)
treecdaca1a423fac526a64d97b2bf7c450e654bb230
parenta56d2e78ce3265b66b1443a7707cf54114da7f69 (diff)
Reactivate showing of general meta information. This is also done as part of the LoadFilesThread and is no special case anymore like in the old code base.
svn path=/trunk/KDE/kdebase/apps/; revision=1033722
-rw-r--r--src/panels/information/informationpanelcontent.cpp86
-rw-r--r--src/panels/information/informationpanelcontent.h15
-rw-r--r--src/panels/information/metadatawidget.cpp299
3 files changed, 216 insertions, 184 deletions
diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp
index 1d95c0013..4ddbf6562 100644
--- a/src/panels/information/informationpanelcontent.cpp
+++ b/src/panels/information/informationpanelcontent.cpp
@@ -51,13 +51,6 @@
#include "phononwidget.h"
#include "pixmapviewer.h"
-#ifdef HAVE_NEPOMUK
-#define DISABLE_NEPOMUK_LEGACY
-#include <Nepomuk/Resource>
-#include <Nepomuk/Types/Property>
-#include <Nepomuk/Variant>
-#endif
-
/**
* Helper function for sorting items with qSort() in
* InformationPanelContent::contextMenu().
@@ -188,30 +181,6 @@ void InformationPanelContent::showItem(const KFileItem& item)
setNameLabelText(itemUrl.fileName());
}
-/* TODO: move to MetaDataWidget
- if (!item.isDir() && item.nepomukUri().isValid()) {
- KConfig config("kmetainformationrc", KConfig::NoGlobals);
- KConfigGroup settings = config.group("Show");
- initMetaInfoSettings(settings);
-
- Nepomuk::Resource res(item.url());
-
- QHash<QUrl, Nepomuk::Variant> properties = res.properties();
- QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
- while (it != properties.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 until
- // we get translated labels
- m_metaTextLabel->add(tunedLabel(prop.label()) + ':', it.value().toString());
- }
- ++it;
- }
- }
-*/
-
if (m_metaDataWidget != 0) {
m_metaDataWidget->setItem(item);
}
@@ -299,7 +268,6 @@ bool InformationPanelContent::eventFilter(QObject* obj, QEvent* event)
void InformationPanelContent::configureSettings()
{
-#ifdef HAVE_NEPOMUK
if (m_item.isNull() ||
!m_item.nepomukUri().isValid()) {
return;
@@ -333,13 +301,12 @@ void InformationPanelContent::configureSettings()
KConfig config("kmetainformationrc", KConfig::NoGlobals);
KConfigGroup settings = config.group("Show");
- initMetaInfoSettings(settings);
QList<QAction*> actions;
// Get all meta information labels that are available for
// the currently shown file item and add them to the popup.
- Nepomuk::Resource res(m_item.url());
+ /*Nepomuk::Resource res(m_item.url());
QHash<QUrl, Nepomuk::Variant> properties = res.properties();
QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin();
while (it != properties.constEnd()) {
@@ -375,7 +342,7 @@ void InformationPanelContent::configureSettings()
}
++it;
- }
+ }*/
if (!actions.isEmpty()) {
popup.addSeparator();
@@ -421,7 +388,6 @@ void InformationPanelContent::configureSettings()
}*/
showItem(m_item);
-#endif
}
void InformationPanelContent::showIcon(const KFileItem& item)
@@ -511,52 +477,4 @@ void InformationPanelContent::setNameLabelText(const QString& text)
m_nameLabel->setText(wrappedText);
}
-void InformationPanelContent::initMetaInfoSettings(KConfigGroup& group)
-{
- if (!group.readEntry("initialized", false)) {
- // The resource file is read the first time. Assure
- // that some meta information is disabled per default.
-
- static const char* disabledProperties[] = {
- "asText", "contentSize", "depth", "fileExtension",
- "fileName", "fileSize", "isPartOf", "mimetype", "name",
- "parentUrl", "plainTextContent", "sourceModified",
- "size", "url",
- 0 // mandatory last entry
- };
-
- int i = 0;
- while (disabledProperties[i] != 0) {
- group.writeEntry(disabledProperties[i], false);
- ++i;
- }
-
- // mark the group as initialized
- group.writeEntry("initialized", true);
- }
-}
-
-QString InformationPanelContent::tunedLabel(const QString& label) const
-{
- QString tunedLabel;
- const int labelLength = label.length();
- if (labelLength > 0) {
- tunedLabel.reserve(labelLength);
- tunedLabel = label[0].toUpper();
- for (int i = 1; i < labelLength; ++i) {
- if (label[i].isUpper() && !label[i - 1].isSpace() && !label[i - 1].isUpper()) {
- tunedLabel += ' ';
- tunedLabel += label[i].toLower();
- } else {
- tunedLabel += label[i];
- }
- }
- }
- return tunedLabel;
-}
-
-void InformationPanelContent::init()
-{
-}
-
#include "informationpanelcontent.moc"
diff --git a/src/panels/information/informationpanelcontent.h b/src/panels/information/informationpanelcontent.h
index 3b9fc6dc3..b39dcc70b 100644
--- a/src/panels/information/informationpanelcontent.h
+++ b/src/panels/information/informationpanelcontent.h
@@ -110,21 +110,6 @@ private:
*/
void setNameLabelText(const QString& text);
- /**
- * 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
- * like "fileLocation" by "File Location:".
- */
- QString tunedLabel(const QString& label) const;
-
- void init();
-
private:
KFileItem m_item;
diff --git a/src/panels/information/metadatawidget.cpp b/src/panels/information/metadatawidget.cpp
index 76a6769b1..30bdb904f 100644
--- a/src/panels/information/metadatawidget.cpp
+++ b/src/panels/information/metadatawidget.cpp
@@ -30,13 +30,21 @@
#include <config-nepomuk.h>
#ifdef HAVE_NEPOMUK
+ #define DISABLE_NEPOMUK_LEGACY
+
#include "commentwidget_p.h"
#include "nepomukmassupdatejob_p.h"
#include "taggingwidget_p.h"
- #include <nepomuk/kratingwidget.h>
- #include <nepomuk/resource.h>
- #include <nepomuk/tag.h>
+ #include <kconfig.h>
+ #include <kconfiggroup.h>
+
+ #include <Nepomuk/KRatingWidget>
+ #include <Nepomuk/Resource>
+ #include <Nepomuk/Tag>
+ #include <Nepomuk/Types/Property>
+ #include <Nepomuk/Variant>
+
#include <Soprano/Vocabulary/Xesam>
#include <QMutex>
#include <QThread>
@@ -55,35 +63,38 @@ public:
~Private();
void addRow(QLabel* label, QWidget* infoWidget);
+ void removeMetaInfoRows();
void setRowVisible(QWidget* infoWidget, bool visible);
void slotLoadingFinished();
- QList<Row> rows;
+ QList<Row> m_rows;
- QGridLayout* gridLayout;
+ QGridLayout* m_gridLayout;
- QLabel* typeInfo;
- QLabel* sizeLabel;
- QLabel* sizeInfo;
- QLabel* modifiedInfo;
- QLabel* ownerInfo;
- QLabel* permissionsInfo;
+ QLabel* m_typeInfo;
+ QLabel* m_sizeLabel;
+ QLabel* m_sizeInfo;
+ QLabel* m_modifiedInfo;
+ QLabel* m_ownerInfo;
+ QLabel* m_permissionsInfo;
#ifdef HAVE_NEPOMUK
- KRatingWidget* ratingWidget;
- TaggingWidget* taggingWidget;
- CommentWidget* commentWidget;
+ KRatingWidget* m_ratingWidget;
+ TaggingWidget* m_taggingWidget;
+ CommentWidget* m_commentWidget;
// shared data between the GUI-thread and
// the loader-thread (see LoadFilesThread):
- QMutex mutex;
+ QMutex m_mutex;
struct SharedData
{
int rating;
QString comment;
QList<Nepomuk::Tag> tags;
- } sharedData;
+ QList<QString> metaInfoLabels;
+ QList<QString> metaInfoValues;
+ } m_sharedData;
/**
* Loads the meta data of files and writes
@@ -93,19 +104,33 @@ public:
class LoadFilesThread : public QThread
{
public:
- LoadFilesThread(SharedData* sharedData, QMutex* mutex);
+ LoadFilesThread(SharedData* m_sharedData, QMutex* m_mutex);
virtual ~LoadFilesThread();
void loadFiles(const KUrl::List& urls);
virtual void run();
private:
- SharedData* m_sharedData;
- QMutex* m_mutex;
+ /**
+ * 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
+ * like "fileLocation" by "File Location:".
+ */
+ QString tunedLabel(const QString& label) const;
+
+ private:
+ SharedData* m_m_sharedData;
+ QMutex* m_m_mutex;
KUrl::List m_urls;
bool m_canceled;
};
- LoadFilesThread* loadFilesThread;
+ LoadFilesThread* m_loadFilesThread;
#endif
private:
@@ -113,56 +138,56 @@ private:
};
MetaDataWidget::Private::Private(MetaDataWidget* parent) :
- rows(),
- gridLayout(0),
- typeInfo(0),
- sizeLabel(0),
- sizeInfo(0),
- modifiedInfo(0),
- ownerInfo(0),
- permissionsInfo(0),
+ m_rows(),
+ m_gridLayout(0),
+ m_typeInfo(0),
+ m_sizeLabel(0),
+ m_sizeInfo(0),
+ m_modifiedInfo(0),
+ m_ownerInfo(0),
+ m_permissionsInfo(0),
#ifdef HAVE_NEPOMUK
- ratingWidget(0),
- taggingWidget(0),
- commentWidget(0),
- loadFilesThread(0),
+ m_ratingWidget(0),
+ m_taggingWidget(0),
+ m_commentWidget(0),
+ m_loadFilesThread(0),
#endif
q(parent)
{
- gridLayout = new QGridLayout(parent);
+ m_gridLayout = new QGridLayout(parent);
- typeInfo = new QLabel(parent);
- sizeLabel = new QLabel(parent);
- sizeInfo = new QLabel(parent);
- modifiedInfo = new QLabel(parent);
- ownerInfo = new QLabel(parent);
- permissionsInfo = new QLabel(parent);
+ m_typeInfo = new QLabel(parent);
+ m_sizeLabel = new QLabel(parent);
+ m_sizeInfo = new QLabel(parent);
+ m_modifiedInfo = new QLabel(parent);
+ m_ownerInfo = new QLabel(parent);
+ m_permissionsInfo = new QLabel(parent);
#ifdef HAVE_NEPOMUK
- ratingWidget = new KRatingWidget(parent);
- taggingWidget = new TaggingWidget(parent);
- commentWidget = new CommentWidget(parent);
+ m_ratingWidget = new KRatingWidget(parent);
+ m_taggingWidget = new TaggingWidget(parent);
+ m_commentWidget = new CommentWidget(parent);
#endif
- addRow(new QLabel(i18nc("@label", "Type:"), parent), typeInfo);
- addRow(sizeLabel, sizeInfo);
- addRow(new QLabel(i18nc("@label", "Modified:"), parent), modifiedInfo);
- addRow(new QLabel(i18nc("@label", "Owner:"), parent), ownerInfo);
- addRow(new QLabel(i18nc("@label", "Permissions:"), parent), permissionsInfo);
+ addRow(new QLabel(i18nc("@label", "Type:"), parent), m_typeInfo);
+ addRow(m_sizeLabel, m_sizeInfo);
+ addRow(new QLabel(i18nc("@label", "Modified:"), parent), m_modifiedInfo);
+ addRow(new QLabel(i18nc("@label", "Owner:"), parent), m_ownerInfo);
+ addRow(new QLabel(i18nc("@label", "Permissions:"), parent), m_permissionsInfo);
#ifdef HAVE_NEPOMUK
- addRow(new QLabel(i18nc("@label", "Rating:"), parent), ratingWidget);
- addRow(new QLabel(i18nc("@label", "Tags:"), parent), taggingWidget);
- addRow(new QLabel(i18nc("@label", "Comment:"), parent), commentWidget);
+ addRow(new QLabel(i18nc("@label", "Rating:"), parent), m_ratingWidget);
+ addRow(new QLabel(i18nc("@label", "Tags:"), parent), m_taggingWidget);
+ addRow(new QLabel(i18nc("@label", "Comment:"), parent), m_commentWidget);
- sharedData.rating = 0;
- loadFilesThread = new LoadFilesThread(&sharedData, &mutex);
- connect(loadFilesThread, SIGNAL(finished()), q, SLOT(slotLoadingFinished()));
+ m_sharedData.rating = 0;
+ m_loadFilesThread = new LoadFilesThread(&m_sharedData, &m_mutex);
+ connect(m_loadFilesThread, SIGNAL(finished()), q, SLOT(slotLoadingFinished()));
#endif
}
MetaDataWidget::Private::~Private()
{
#ifdef HAVE_NEPOMUK
- delete loadFilesThread;
+ delete m_loadFilesThread;
#endif
}
@@ -171,7 +196,7 @@ void MetaDataWidget::Private::addRow(QLabel* label, QWidget* infoWidget)
Row row;
row.label = label;
row.infoWidget = infoWidget;
- rows.append(row);
+ m_rows.append(row);
// use a brighter color for the label
QPalette palette = label->palette();
@@ -181,14 +206,14 @@ void MetaDataWidget::Private::addRow(QLabel* label, QWidget* infoWidget)
label->setPalette(palette);
// add the row to grid layout
- const int rowIndex = rows.count();
- gridLayout->addWidget(label, rowIndex, 0, Qt::AlignLeft);
- gridLayout->addWidget(infoWidget, rowIndex, 1, Qt::AlignRight);
+ const int rowIndex = m_rows.count();
+ m_gridLayout->addWidget(label, rowIndex, 0, Qt::AlignLeft);
+ m_gridLayout->addWidget(infoWidget, rowIndex, 1, Qt::AlignRight);
}
void MetaDataWidget::Private::setRowVisible(QWidget* infoWidget, bool visible)
{
- foreach (const Row& row, rows) {
+ foreach (const Row& row, m_rows) {
if (row.infoWidget == infoWidget) {
row.label->setVisible(visible);
row.infoWidget->setVisible(visible);
@@ -200,19 +225,51 @@ void MetaDataWidget::Private::setRowVisible(QWidget* infoWidget, bool visible)
void MetaDataWidget::Private::slotLoadingFinished()
{
#ifdef HAVE_NEPOMUK
- QMutexLocker locker(&mutex);
- ratingWidget->setRating(sharedData.rating);
- commentWidget->setText(sharedData.comment);
- taggingWidget->setTags(sharedData.tags);
+ QMutexLocker locker(&m_mutex);
+ m_ratingWidget->setRating(m_sharedData.rating);
+ m_commentWidget->setText(m_sharedData.comment);
+ m_taggingWidget->setTags(m_sharedData.tags);
+
+ // Show the remaining meta information as text. The number
+ // of required rows may very. Existing rows are reused to
+ // prevent flickering.
+ int index = 8; // TODO: don't hardcode this value here
+ const int rowCount = m_rows.count();
+ Q_ASSERT(rowCount >= index);
+
+ Q_ASSERT(m_sharedData.metaInfoLabels.count() == m_sharedData.metaInfoValues.count());
+ const int metaInfoCount = m_sharedData.metaInfoLabels.count();
+ for (int i = 0; i < metaInfoCount; ++i) {
+ if (index < rowCount) {
+ // adjust texts of the current row
+ m_rows[index].label->setText(m_sharedData.metaInfoLabels[i]);
+ QLabel* infoValueLabel = qobject_cast<QLabel*>(m_rows[index].infoWidget);
+ Q_ASSERT(infoValueLabel != 0);
+ infoValueLabel->setText(m_sharedData.metaInfoValues[i]);
+ } else {
+ // create new row
+ QLabel* infoLabel = new QLabel(m_sharedData.metaInfoLabels[i], q);
+ QLabel* infoValue = new QLabel(m_sharedData.metaInfoValues[i], q);
+ addRow(infoLabel, infoValue);
+ }
+ ++index;
+ }
+
+ // remove rows that are not needed anymore
+ for (int i = rowCount - 1; i > index; --i) {
+ delete m_rows[i].label;
+ delete m_rows[i].infoWidget;
+ m_rows.pop_back();
+ }
#endif
}
#ifdef HAVE_NEPOMUK
MetaDataWidget::Private::LoadFilesThread::LoadFilesThread(
- MetaDataWidget::Private::SharedData* sharedData,
- QMutex* mutex) :
- m_sharedData(sharedData),
- m_mutex(mutex),
+ MetaDataWidget::Private::SharedData* m_sharedData,
+ QMutex* m_mutex) :
+ m_m_sharedData(m_sharedData),
+ m_m_mutex(m_mutex),
m_urls(),
m_canceled(false)
{
@@ -228,7 +285,7 @@ MetaDataWidget::Private::LoadFilesThread::~LoadFilesThread()
void MetaDataWidget::Private::LoadFilesThread::loadFiles(const KUrl::List& urls)
{
- QMutexLocker locker(m_mutex);
+ QMutexLocker locker(m_m_mutex);
m_urls = urls;
m_canceled = false;
start();
@@ -236,14 +293,20 @@ void MetaDataWidget::Private::LoadFilesThread::loadFiles(const KUrl::List& urls)
void MetaDataWidget::Private::LoadFilesThread::run()
{
- QMutexLocker locker(m_mutex);
+ QMutexLocker locker(m_m_mutex);
const KUrl::List urls = m_urls;
locker.unlock();
+ KConfig config("kmetainformationrc", KConfig::NoGlobals);
+ KConfigGroup settings = config.group("Show");
+ initMetaInfoSettings(settings);
+
bool first = true;
unsigned int rating = 0;
QString comment;
QList<Nepomuk::Tag> tags;
+ QList<QString> metaInfoLabels;
+ QList<QString> metaInfoValues;
foreach (const KUrl& url, urls) {
if (m_canceled) {
return;
@@ -269,14 +332,80 @@ void MetaDataWidget::Private::LoadFilesThread::run()
tags = file.tags();
}
+ if (first && (urls.count() == 1)) {
+ // TODO: show shared meta informations 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()) {
+ Nepomuk::Types::Property prop(it.key());
+ if (true /*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 until
+ // we get translated labels
+ metaInfoLabels.append(tunedLabel(prop.label()));
+ metaInfoValues.append(it.value().toString());
+ }
+ ++it;
+ }
+ }
+
first = false;
}
locker.relock();
- m_sharedData->rating = rating;
- m_sharedData->comment = comment;
- m_sharedData->tags = tags;
+ m_m_sharedData->rating = rating;
+ m_m_sharedData->comment = comment;
+ m_m_sharedData->tags = tags;
+ m_m_sharedData->metaInfoLabels = metaInfoLabels;
+ m_m_sharedData->metaInfoValues = metaInfoValues;
}
+
+void MetaDataWidget::Private::LoadFilesThread::initMetaInfoSettings(KConfigGroup& group)
+{
+ if (!group.readEntry("initialized", false)) {
+ // The resource file is read the first time. Assure
+ // that some meta information is disabled per default.
+
+ static const char* disabledProperties[] = {
+ "asText", "contentSize", "depth", "fileExtension",
+ "fileName", "fileSize", "isPartOf", "mimetype", "name",
+ "parentUrl", "plainTextContent", "sourceModified",
+ "size", "url",
+ 0 // mandatory last entry
+ };
+
+ int i = 0;
+ while (disabledProperties[i] != 0) {
+ group.writeEntry(disabledProperties[i], false);
+ ++i;
+ }
+
+ // mark the group as initialized
+ group.writeEntry("initialized", true);
+ }
+}
+
+QString MetaDataWidget::Private::LoadFilesThread::tunedLabel(const QString& label) const
+{
+ QString tunedLabel;
+ const int labelLength = label.length();
+ if (labelLength > 0) {
+ tunedLabel.reserve(labelLength);
+ tunedLabel = label[0].toUpper();
+ for (int i = 1; i < labelLength; ++i) {
+ if (label[i].isUpper() && !label[i - 1].isSpace() && !label[i - 1].isUpper()) {
+ tunedLabel += ' ';
+ tunedLabel += label[i].toLower();
+ } else {
+ tunedLabel += label[i];
+ }
+ }
+ }
+ return tunedLabel + ':';
+}
+
#endif
MetaDataWidget::MetaDataWidget(QWidget* parent) :
@@ -294,18 +423,18 @@ void MetaDataWidget::setItem(const KFileItem& item)
{
// update values for "type", "size", "modified",
// "owner" and "permissions" synchronously
- d->sizeLabel->setText(i18nc("@label", "Size:"));
+ d->m_sizeLabel->setText(i18nc("@label", "Size:"));
if (item.isDir()) {
- d->typeInfo->setText(i18nc("@label", "Folder"));
- d->setRowVisible(d->sizeInfo, false);
+ d->m_typeInfo->setText(i18nc("@label", "Folder"));
+ d->setRowVisible(d->m_sizeInfo, false);
} else {
- d->typeInfo->setText(item.mimeComment());
- d->sizeInfo->setText(KIO::convertSize(item.size()));
- d->setRowVisible(d->sizeInfo, true);
+ d->m_typeInfo->setText(item.mimeComment());
+ d->m_sizeInfo->setText(KIO::convertSize(item.size()));
+ d->setRowVisible(d->m_sizeInfo, true);
}
- d->modifiedInfo->setText(item.timeString());
- d->ownerInfo->setText(item.user());
- d->permissionsInfo->setText(item.permissionsString());
+ d->m_modifiedInfo->setText(item.timeString());
+ d->m_ownerInfo->setText(item.user());
+ d->m_permissionsInfo->setText(item.permissionsString());
setItems(KFileItemList() << item);
}
@@ -315,8 +444,8 @@ void MetaDataWidget::setItems(const KFileItemList& items)
if (items.count() > 1) {
// calculate the size of all items and show this
// information to the user
- d->sizeLabel->setText(i18nc("@label", "Total Size:"));
- d->setRowVisible(d->sizeInfo, true);
+ d->m_sizeLabel->setText(i18nc("@label", "Total Size:"));
+ d->setRowVisible(d->m_sizeInfo, true);
quint64 totalSize = 0;
foreach (const KFileItem& item, items) {
@@ -324,7 +453,7 @@ void MetaDataWidget::setItems(const KFileItemList& items)
totalSize += item.size();
}
}
- d->sizeInfo->setText(KIO::convertSize(totalSize));
+ d->m_sizeInfo->setText(KIO::convertSize(totalSize));
}
#ifdef HAVE_NEPOMUK
@@ -335,7 +464,7 @@ void MetaDataWidget::setItems(const KFileItemList& items)
urls.append(url);
}
}
- d->loadFilesThread->loadFiles(urls);
+ d->m_loadFilesThread->loadFiles(urls);
#endif
}