]>
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>
38 #include <Soprano/Vocabulary/Xesam>
42 bool MetaDataWidget::metaDataAvailable()
45 return !Nepomuk::ResourceManager::instance()->init();
52 class MetaDataWidget::Private
56 void loadComment(const QString
& comment
);
58 QMap
<KUrl
, Nepomuk::Resource
> files
;
60 QTextEdit
* editComment
;
61 KRatingWidget
* ratingWidget
;
62 Nepomuk::TagWidget
* tagWidget
;
67 void MetaDataWidget::Private::loadComment(const QString
& comment
)
69 editComment
->blockSignals(true);
70 if (comment
.isEmpty()) {
71 editComment
->setFontItalic(true);
72 editComment
->setText(i18nc("@info:tooltip", "Click to add comment..."));
74 editComment
->setFontItalic(false);
75 editComment
->setText(comment
);
77 editComment
->blockSignals(false);
82 MetaDataWidget::MetaDataWidget(QWidget
* parent
) :
87 d
->editComment
= new QTextEdit(this);
88 d
->ratingWidget
= new KRatingWidget(this);
89 d
->tagWidget
= new Nepomuk::TagWidget(this);
90 connect(d
->ratingWidget
, SIGNAL(ratingChanged(unsigned int)), this, SLOT(slotRatingChanged(unsigned int)));
91 connect(d
->editComment
, SIGNAL(textChanged()), this, SLOT(slotCommentChanged()));
93 QVBoxLayout
* lay
= new QVBoxLayout(this);
95 QHBoxLayout
* hbox
= new QHBoxLayout
;
96 hbox
->addWidget(new QLabel(i18nc("@label:slider", "Rating:"), this));
98 hbox
->addWidget(d
->ratingWidget
);
100 lay
->addWidget(d
->editComment
);
101 hbox
= new QHBoxLayout
;
102 hbox
->addWidget(new QLabel(i18nc("@label:textbox", "Tags:"), this));
103 hbox
->addWidget(d
->tagWidget
, 1);
104 lay
->addLayout(hbox
);
106 d
->editComment
->installEventFilter(this);
107 d
->editComment
->viewport()->installEventFilter(this);
114 MetaDataWidget::~MetaDataWidget()
120 void MetaDataWidget::setFile(const KUrl
& url
)
128 void MetaDataWidget::setFiles(const KUrl::List
& urls
)
131 // FIXME: replace with KMetaData::File once we have it again
134 QList
<Nepomuk::Resource
> fileRes
;
135 Q_FOREACH( KUrl url
, urls
) {
136 Nepomuk::Resource
file( url
.url(), Soprano::Vocabulary::Xesam::File() );
137 // file.setLocation(url.url());
138 d
->files
.insert( url
, file
);
139 fileRes
.append( file
);
142 d
->ratingWidget
->rating() != file
.rating() ) {
143 d
->ratingWidget
->setRating( 0 ); // reset rating
146 d
->ratingWidget
->setRating( file
.rating() );
150 d
->editComment
->toPlainText() != file
.description() ) {
151 d
->loadComment( QString() );
154 d
->loadComment( file
.description() );
158 d
->tagWidget
->setTaggedResources(fileRes
);
163 void MetaDataWidget::slotCommentChanged()
166 for ( QMap
<KUrl
, Nepomuk::Resource
>::iterator it
= d
->files
.begin();
167 it
!= d
->files
.end(); ++it
) {
168 it
.value().setDescription(d
->editComment
->toPlainText());
174 void MetaDataWidget::slotRatingChanged(unsigned int rating
)
177 for ( QMap
<KUrl
, Nepomuk::Resource
>::iterator it
= d
->files
.begin();
178 it
!= d
->files
.end(); ++it
) {
179 it
.value().setRating(rating
);
185 bool MetaDataWidget::eventFilter(QObject
* obj
, QEvent
* event
)
188 if (obj
== d
->editComment
->viewport() || obj
== d
->editComment
) {
189 if (event
->type() == QEvent::FocusOut
) {
190 // make sure the info text is displayed again
191 d
->loadComment(d
->editComment
->toPlainText());
192 } else if (event
->type() == QEvent::FocusIn
) {
193 d
->editComment
->setFontItalic(false);
194 if (!d
->files
.isEmpty() && d
->files
.begin().value().description().isEmpty()) {
195 d
->editComment
->setText(QString());
201 return QWidget::eventFilter(obj
, event
);
204 #include "metadatawidget.moc"