]>
cloud.milkyroute.net Git - dolphin.git/blob - src/metadatawidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2007 by Sebastian Trueg <trueg@kde.org> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "metadatawidget.h"
22 #include <config-kmetadata.h>
26 #include <QtGui/QLabel>
27 #include <QtGui/QGridLayout>
28 #include <QtGui/QTextEdit>
31 #include <kmetadata/kmetadatatagwidget.h>
32 #include <kmetadata/resourcemanager.h>
33 #include <kmetadata/resource.h>
34 #include <kmetadata/variant.h>
35 #include <kmetadata/kratingwidget.h>
38 // FIXME: these should be replaced by using KMetaData::File once it is available again
39 static const char* s_nfoFile
= "http://ont.semanticdesktop.org/2007/03/22/nfo#File";
40 static const char* s_nfoFileUrl
= "http://ont.semanticdesktop.org/2007/03/22/nfo#fileUrl";
43 bool MetaDataWidget::metaDataAvailable()
46 return !Nepomuk::KMetaData::ResourceManager::instance()->init();
53 class MetaDataWidget::Private
57 void loadComment(const QString
& comment
);
61 Nepomuk::KMetaData::Resource file
;
63 QTextEdit
* editComment
;
64 KRatingWidget
* ratingWidget
;
65 Nepomuk::KMetaData::TagWidget
* tagWidget
;
69 void MetaDataWidget::Private::loadComment(const QString
& comment
)
71 editComment
->blockSignals(true);
72 if (comment
.isEmpty()) {
73 editComment
->setFontItalic(true);
74 editComment
->setText(i18n("Click to add comment..."));
76 editComment
->setFontItalic(false);
77 editComment
->setText(comment
);
79 editComment
->blockSignals(false);
83 MetaDataWidget::MetaDataWidget(QWidget
* parent
) :
88 d
->editComment
= new QTextEdit(this);
89 d
->ratingWidget
= new KRatingWidget(this);
90 d
->tagWidget
= new Nepomuk::KMetaData::TagWidget(this);
91 connect(d
->ratingWidget
, SIGNAL(ratingChanged(int)), this, SLOT(slotRatingChanged(int)));
92 connect(d
->editComment
, SIGNAL(textChanged()), this, SLOT(slotCommentChanged()));
94 QVBoxLayout
* lay
= new QVBoxLayout(this);
96 QHBoxLayout
* hbox
= new QHBoxLayout
;
97 hbox
->addWidget(new QLabel(i18n("Rating:"), this));
99 hbox
->addWidget(d
->ratingWidget
);
100 lay
->addLayout(hbox
);
101 lay
->addWidget(d
->editComment
);
102 hbox
= new QHBoxLayout
;
103 hbox
->addWidget(new QLabel(i18n("Tags:"), this));
104 hbox
->addWidget(d
->tagWidget
, 1);
105 lay
->addLayout(hbox
);
107 d
->editComment
->installEventFilter(this);
108 d
->editComment
->viewport()->installEventFilter(this);
115 MetaDataWidget::~MetaDataWidget()
121 void MetaDataWidget::setFile(const KUrl
& url
)
123 #ifdef HAVE_KMETADATA
124 // FIXME: replace with KMetaData::File once we have it again
126 d
->file
= Nepomuk::KMetaData::Resource(url
.url(), s_nfoFile
);
127 d
->ratingWidget
->setRating(d
->file
.rating());
128 d
->tagWidget
->setTaggedResource(d
->file
);
129 d
->loadComment(d
->file
.description());
134 void MetaDataWidget::setFiles(const KUrl::List
& urls
)
136 #ifdef HAVE_KMETADATA
137 // FIXME: support multiple files
138 setFile(urls
.first());
143 void MetaDataWidget::slotCommentChanged()
145 #ifdef HAVE_KMETADATA
146 if (d
->editComment
->toPlainText() != d
->file
.description()) {
147 // d->file.setLocation(url.url());
148 d
->file
.setProperty(s_nfoFileUrl
, d
->fileUrl
.url());
149 d
->file
.setDescription(d
->editComment
->toPlainText());
155 void MetaDataWidget::slotRatingChanged(int rating
)
157 #ifdef HAVE_KMETADATA
158 if (rating
!= d
->file
.rating()) {
159 // d->file.setLocation(url.url());
160 d
->file
.setProperty(s_nfoFileUrl
, d
->fileUrl
.url());
161 d
->file
.setRating(rating
);
167 bool MetaDataWidget::eventFilter(QObject
* obj
, QEvent
* event
)
169 #ifdef HAVE_KMETADATA
170 if (obj
== d
->editComment
->viewport() || obj
== d
->editComment
) {
171 if (event
->type() == QEvent::FocusOut
) {
172 // make sure the info text is displayed again
173 d
->loadComment(d
->editComment
->toPlainText());
174 } else if (event
->type() == QEvent::FocusIn
) {
175 d
->editComment
->setFontItalic(false);
176 if (d
->file
.description().isEmpty()) {
177 d
->editComment
->setText(QString());
183 return QWidget::eventFilter(obj
, event
);
186 #include "metadatawidget.moc"