]>
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 <QtCore/QEvent>
27 #include <QtGui/QLabel>
28 #include <QtGui/QGridLayout>
29 #include <QtGui/QTextEdit>
32 #include <nepomuk/kmetadatatagwidget.h>
33 #include <nepomuk/resourcemanager.h>
34 #include <nepomuk/resource.h>
35 #include <nepomuk/variant.h>
36 #include <nepomuk/kratingwidget.h>
37 #include <nepomuk/global.h>
41 bool MetaDataWidget::metaDataAvailable()
44 return !Nepomuk::ResourceManager::instance()->init();
51 class MetaDataWidget::Private
55 void loadComment(const QString
& comment
);
57 QMap
<KUrl
, Nepomuk::Resource
> files
;
59 QTextEdit
* editComment
;
60 KRatingWidget
* ratingWidget
;
61 Nepomuk::TagWidget
* tagWidget
;
66 void MetaDataWidget::Private::loadComment(const QString
& comment
)
68 editComment
->blockSignals(true);
69 if (comment
.isEmpty()) {
70 editComment
->setFontItalic(true);
71 editComment
->setText(i18nc("@info:tooltip", "Click to add comment..."));
73 editComment
->setFontItalic(false);
74 editComment
->setText(comment
);
76 editComment
->blockSignals(false);
81 MetaDataWidget::MetaDataWidget(QWidget
* parent
) :
86 d
->editComment
= new QTextEdit(this);
87 d
->ratingWidget
= new KRatingWidget(this);
88 d
->tagWidget
= new Nepomuk::TagWidget(this);
89 connect(d
->ratingWidget
, SIGNAL(ratingChanged(unsigned int)), this, SLOT(slotRatingChanged(unsigned int)));
90 connect(d
->editComment
, SIGNAL(textChanged()), this, SLOT(slotCommentChanged()));
92 QVBoxLayout
* lay
= new QVBoxLayout(this);
94 QHBoxLayout
* hbox
= new QHBoxLayout
;
95 hbox
->addWidget(new QLabel(i18nc("@label:slider", "Rating:"), this));
97 hbox
->addWidget(d
->ratingWidget
);
99 lay
->addWidget(d
->editComment
);
100 hbox
= new QHBoxLayout
;
101 hbox
->addWidget(new QLabel(i18nc("@label:textbox", "Tags:"), this));
102 hbox
->addWidget(d
->tagWidget
, 1);
103 lay
->addLayout(hbox
);
105 d
->editComment
->installEventFilter(this);
106 d
->editComment
->viewport()->installEventFilter(this);
113 MetaDataWidget::~MetaDataWidget()
119 void MetaDataWidget::setFile(const KUrl
& url
)
127 void MetaDataWidget::setFiles(const KUrl::List
& urls
)
130 // FIXME: replace with KMetaData::File once we have it again
133 QList
<Nepomuk::Resource
> fileRes
;
134 Q_FOREACH( KUrl url
, urls
) {
135 Nepomuk::Resource
file( url
.url(), Nepomuk::NFO::File() );
136 // file.setLocation(url.url());
137 d
->files
.insert( url
, file
);
138 fileRes
.append( file
);
141 d
->ratingWidget
->rating() != file
.rating() ) {
142 d
->ratingWidget
->setRating( 0 ); // reset rating
145 d
->ratingWidget
->setRating( file
.rating() );
149 d
->editComment
->toPlainText() != file
.description() ) {
150 d
->loadComment( QString() );
153 d
->loadComment( file
.description() );
157 d
->tagWidget
->setTaggedResources(fileRes
);
162 void MetaDataWidget::slotCommentChanged()
165 for ( QMap
<KUrl
, Nepomuk::Resource
>::iterator it
= d
->files
.begin();
166 it
!= d
->files
.end(); ++it
) {
167 it
.value().setDescription(d
->editComment
->toPlainText());
173 void MetaDataWidget::slotRatingChanged(unsigned int rating
)
176 for ( QMap
<KUrl
, Nepomuk::Resource
>::iterator it
= d
->files
.begin();
177 it
!= d
->files
.end(); ++it
) {
178 it
.value().setRating(rating
);
184 bool MetaDataWidget::eventFilter(QObject
* obj
, QEvent
* event
)
187 if (obj
== d
->editComment
->viewport() || obj
== d
->editComment
) {
188 if (event
->type() == QEvent::FocusOut
) {
189 // make sure the info text is displayed again
190 d
->loadComment(d
->editComment
->toPlainText());
191 } else if (event
->type() == QEvent::FocusIn
) {
192 d
->editComment
->setFontItalic(false);
193 if (!d
->files
.isEmpty() && d
->files
.begin().value().description().isEmpty()) {
194 d
->editComment
->setText(QString());
200 return QWidget::eventFilter(obj
, event
);
203 #include "metadatawidget.moc"