* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#include <config-kmetadata.h>
-
#include "metadatawidget.h"
+#include <config-kmetadata.h>
+
#include <klocale.h>
-#include <QLabel>
-#include <QGridLayout>
-#include <QTextEdit>
+#include <QtGui/QLabel>
+#include <QtGui/QGridLayout>
+#include <QtGui/QTextEdit>
#ifdef HAVE_KMETADATA
-#include <kmetadatatagwidget.h>
+#include <kmetadata/kmetadatatagwidget.h>
#include <kmetadata/resourcemanager.h>
#include <kmetadata/resource.h>
-#include <kratingwidget.h>
-#include <kmetadatatagwidget.h>
+#include <kmetadata/variant.h>
+#include <kmetadata/kratingwidget.h>
#endif
+// FIXME: these should be replaced by using KMetaData::File once it is available again
+static const char* s_nfoFile = "http://ont.semanticdesktop.org/2007/03/22/nfo#File";
+static const char* s_nfoFileUrl = "http://ont.semanticdesktop.org/2007/03/22/nfo#fileUrl";
+
bool MetaDataWidget::metaDataAvailable()
{
{
public:
#ifdef HAVE_KMETADATA
- void loadComment(const QString& comment)
- {
- editComment->blockSignals(true);
- if (comment.isEmpty()) {
- editComment->setFontItalic(true);
- editComment->setText(i18n("Click to add comment..."));
- } else {
- editComment->setFontItalic(false);
- editComment->setText(comment);
- }
- editComment->blockSignals(false);
- }
+ void loadComment(const QString& comment);
KUrl fileUrl;
#endif
};
+#ifdef HAVE_KMETADATA
+void MetaDataWidget::Private::loadComment(const QString& comment)
+{
+ editComment->blockSignals(true);
+ if (comment.isEmpty()) {
+ editComment->setFontItalic(true);
+ editComment->setText(i18n("Click to add comment..."));
+ } else {
+ editComment->setFontItalic(false);
+ editComment->setText(comment);
+ }
+ editComment->blockSignals(false);
+}
+#endif
+
-MetaDataWidget::MetaDataWidget(QWidget* parent)
- : QWidget(parent)
+MetaDataWidget::MetaDataWidget(QWidget* parent) :
+ QWidget(parent)
{
#ifdef HAVE_KMETADATA
d = new Private;
d->editComment = new QTextEdit(this);
- d->tagWidget = new Nepomuk::KMetaData::TagWidget(this);
d->ratingWidget = new KRatingWidget(this);
+ d->tagWidget = new Nepomuk::KMetaData::TagWidget(this);
connect(d->ratingWidget, SIGNAL(ratingChanged(int)), this, SLOT(slotRatingChanged(int)));
connect(d->editComment, SIGNAL(textChanged()), this, SLOT(slotCommentChanged()));
d->editComment->installEventFilter(this);
d->editComment->viewport()->installEventFilter(this);
#else
- d = 0L;
+ d = 0;
#endif
}
#ifdef HAVE_KMETADATA
// FIXME: replace with KMetaData::File once we have it again
d->fileUrl = url;
- d->file = Nepomuk::KMetaData::Resource(url.url());
-// d->file.setLocation(url.url());
- d->ratingWidget->setRating(d->file.getRating());
+ d->file = Nepomuk::KMetaData::Resource(url.url(), s_nfoFile);
+ d->ratingWidget->setRating(d->file.rating());
d->tagWidget->setTaggedResource(d->file);
- d->loadComment(d->file.getComment());
+ d->loadComment(d->file.description());
#endif
}
-void MetaDataWidget::setFiles(const KUrl::List urls)
+void MetaDataWidget::setFiles(const KUrl::List& urls)
{
#ifdef HAVE_KMETADATA
// FIXME: support multiple files
void MetaDataWidget::slotCommentChanged()
{
#ifdef HAVE_KMETADATA
- d->file.setComment(d->editComment->toPlainText());
+ if (d->editComment->toPlainText() != d->file.description()) {
+// d->file.setLocation(url.url());
+ d->file.setProperty(s_nfoFileUrl, d->fileUrl.url());
+ d->file.setDescription(d->editComment->toPlainText());
+ }
#endif
}
-void MetaDataWidget::slotRatingChanged(int r)
+void MetaDataWidget::slotRatingChanged(int rating)
{
#ifdef HAVE_KMETADATA
- d->file.setRating(r);
+ if (rating != d->file.rating()) {
+ // d->file.setLocation(url.url());
+ d->file.setProperty(s_nfoFileUrl, d->fileUrl.url());
+ d->file.setRating(rating);
+ }
#endif
}
bool MetaDataWidget::eventFilter(QObject* obj, QEvent* event)
{
#ifdef HAVE_KMETADATA
- if (obj == d->editComment->viewport()
- || obj == d->editComment) {
+ if (obj == d->editComment->viewport() || obj == d->editComment) {
if (event->type() == QEvent::FocusOut) {
// make sure the info text is displayed again
d->loadComment(d->editComment->toPlainText());
} else if (event->type() == QEvent::FocusIn) {
d->editComment->setFontItalic(false);
- if (d->file.getComment().isEmpty())
+ if (d->file.description().isEmpty()) {
d->editComment->setText(QString());
+ }
}
}
#endif