]>
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-nepomuk.h>
26 #include <QtGui/QLabel>
27 #include <QtGui/QGridLayout>
28 #include <QtGui/QTextEdit>
31 #include <nepomuk/kmetadatatagwidget.h>
32 #include <nepomuk/resourcemanager.h>
33 #include <nepomuk/resource.h>
34 #include <nepomuk/variant.h>
35 #include <nepomuk/kratingwidget.h>
36 #include <nepomuk/global.h>
40 bool MetaDataWidget::metaDataAvailable()
43 return !Nepomuk::ResourceManager::instance()->init();
50 class MetaDataWidget::Private
54 void loadComment(const QString
& comment
);
56 QMap
<KUrl
, Nepomuk::Resource
> files
;
58 QTextEdit
* editComment
;
59 KRatingWidget
* ratingWidget
;
60 Nepomuk::TagWidget
* tagWidget
;
65 void MetaDataWidget::Private::loadComment(const QString
& comment
)
67 editComment
->blockSignals(true);
68 if (comment
.isEmpty()) {
69 editComment
->setFontItalic(true);
70 editComment
->setText(i18n("Click to add comment..."));
72 editComment
->setFontItalic(false);
73 editComment
->setText(comment
);
75 editComment
->blockSignals(false);
80 MetaDataWidget::MetaDataWidget(QWidget
* parent
) :
85 d
->editComment
= new QTextEdit(this);
86 d
->ratingWidget
= new KRatingWidget(this);
87 d
->tagWidget
= new Nepomuk::TagWidget(this);
88 connect(d
->ratingWidget
, SIGNAL(ratingChanged(unsigned int)), this, SLOT(slotRatingChanged(unsigned int)));
89 connect(d
->editComment
, SIGNAL(textChanged()), this, SLOT(slotCommentChanged()));
91 QVBoxLayout
* lay
= new QVBoxLayout(this);
93 QHBoxLayout
* hbox
= new QHBoxLayout
;
94 hbox
->addWidget(new QLabel(i18n("Rating:"), this));
96 hbox
->addWidget(d
->ratingWidget
);
98 lay
->addWidget(d
->editComment
);
99 hbox
= new QHBoxLayout
;
100 hbox
->addWidget(new QLabel(i18n("Tags:"), this));
101 hbox
->addWidget(d
->tagWidget
, 1);
102 lay
->addLayout(hbox
);
104 d
->editComment
->installEventFilter(this);
105 d
->editComment
->viewport()->installEventFilter(this);
112 MetaDataWidget::~MetaDataWidget()
118 void MetaDataWidget::setFile(const KUrl
& url
)
126 void MetaDataWidget::setFiles(const KUrl::List
& urls
)
129 // FIXME: replace with KMetaData::File once we have it again
132 QList
<Nepomuk::Resource
> fileRes
;
133 Q_FOREACH( KUrl url
, urls
) {
134 Nepomuk::Resource
file( url
.url(), Nepomuk::NFO::File() );
135 // file.setLocation(url.url());
136 d
->files
.insert( url
, file
);
137 fileRes
.append( file
);
140 d
->ratingWidget
->rating() != file
.rating() ) {
141 d
->ratingWidget
->setRating( 0 ); // reset rating
144 d
->ratingWidget
->setRating( file
.rating() );
148 d
->editComment
->toPlainText() != file
.description() ) {
149 d
->loadComment( QString() );
152 d
->loadComment( file
.description() );
156 d
->tagWidget
->setTaggedResources(fileRes
);
161 void MetaDataWidget::slotCommentChanged()
164 for ( QMap
<KUrl
, Nepomuk::Resource
>::iterator it
= d
->files
.begin();
165 it
!= d
->files
.end(); ++it
) {
166 it
.value().setDescription(d
->editComment
->toPlainText());
172 void MetaDataWidget::slotRatingChanged(unsigned int rating
)
175 for ( QMap
<KUrl
, Nepomuk::Resource
>::iterator it
= d
->files
.begin();
176 it
!= d
->files
.end(); ++it
) {
177 it
.value().setRating(rating
);
183 bool MetaDataWidget::eventFilter(QObject
* obj
, QEvent
* event
)
186 if (obj
== d
->editComment
->viewport() || obj
== d
->editComment
) {
187 if (event
->type() == QEvent::FocusOut
) {
188 // make sure the info text is displayed again
189 d
->loadComment(d
->editComment
->toPlainText());
190 } else if (event
->type() == QEvent::FocusIn
) {
191 d
->editComment
->setFontItalic(false);
192 if (!d
->files
.isEmpty() && d
->files
.begin().value().description().isEmpty()) {
193 d
->editComment
->setText(QString());
199 return QWidget::eventFilter(obj
, event
);
202 #include "metadatawidget.moc"