]>
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
);
59 QMap
<KUrl
, Nepomuk::KMetaData::Resource
> files
;
61 QTextEdit
* editComment
;
62 KRatingWidget
* ratingWidget
;
63 Nepomuk::KMetaData::TagWidget
* tagWidget
;
68 void MetaDataWidget::Private::loadComment(const QString
& comment
)
70 editComment
->blockSignals(true);
71 if (comment
.isEmpty()) {
72 editComment
->setFontItalic(true);
73 editComment
->setText(i18n("Click to add comment..."));
75 editComment
->setFontItalic(false);
76 editComment
->setText(comment
);
78 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(unsigned int)), this, SLOT(slotRatingChanged(unsigned 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
)
129 void MetaDataWidget::setFiles(const KUrl::List
& urls
)
131 #ifdef HAVE_KMETADATA
132 // FIXME: replace with KMetaData::File once we have it again
135 QList
<Nepomuk::KMetaData::Resource
> fileRes
;
136 Q_FOREACH( KUrl url
, urls
) {
137 Nepomuk::KMetaData::Resource
file( url
.url(), s_nfoFile
);
138 // file.setLocation(url.url());
139 d
->files
.insert( url
, file
);
140 fileRes
.append( file
);
143 d
->ratingWidget
->rating() != file
.rating() ) {
144 d
->ratingWidget
->setRating( 0 ); // reset rating
147 d
->ratingWidget
->setRating( file
.rating() );
151 d
->editComment
->toPlainText() != file
.description() ) {
152 d
->loadComment( QString() );
155 d
->loadComment( file
.description() );
159 d
->tagWidget
->setTaggedResources(fileRes
);
164 void MetaDataWidget::slotCommentChanged()
166 #ifdef HAVE_KMETADATA
167 for ( QMap
<KUrl
, Nepomuk::KMetaData::Resource
>::iterator it
= d
->files
.begin();
168 it
!= d
->files
.end(); ++it
) {
169 it
.value().setDescription(d
->editComment
->toPlainText());
175 void MetaDataWidget::slotRatingChanged(unsigned int rating
)
177 #ifdef HAVE_KMETADATA
178 for ( QMap
<KUrl
, Nepomuk::KMetaData::Resource
>::iterator it
= d
->files
.begin();
179 it
!= d
->files
.end(); ++it
) {
180 it
.value().setRating(rating
);
186 bool MetaDataWidget::eventFilter(QObject
* obj
, QEvent
* event
)
188 #ifdef HAVE_KMETADATA
189 if (obj
== d
->editComment
->viewport() || obj
== d
->editComment
) {
190 if (event
->type() == QEvent::FocusOut
) {
191 // make sure the info text is displayed again
192 d
->loadComment(d
->editComment
->toPlainText());
193 } else if (event
->type() == QEvent::FocusIn
) {
194 d
->editComment
->setFontItalic(false);
195 if (!d
->files
.isEmpty() && d
->files
.begin().value().description().isEmpty()) {
196 d
->editComment
->setText(QString());
202 return QWidget::eventFilter(obj
, event
);
205 #include "metadatawidget.moc"