]>
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 <config-kmetadata.h>
22 #include "metadatawidget.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>
36 #include <kmetadata/kmetadatatagwidget.h>
39 // FIXME: these should be replaced by using KMetaData::File once it is available again
40 static const char* s_nfoFile
= "http://ont.semanticdesktop.org/2007/03/22/nfo#File";
41 static const char* s_nfoFileUrl
= "http://ont.semanticdesktop.org/2007/03/22/nfo#fileUrl";
44 bool MetaDataWidget::metaDataAvailable()
47 return !Nepomuk::KMetaData::ResourceManager::instance()->init();
54 class MetaDataWidget::Private
58 void loadComment(const QString
& comment
)
60 editComment
->blockSignals(true);
61 if (comment
.isEmpty()) {
62 editComment
->setFontItalic(true);
63 editComment
->setText(i18n("Click to add comment..."));
65 editComment
->setFontItalic(false);
66 editComment
->setText(comment
);
68 editComment
->blockSignals(false);
73 Nepomuk::KMetaData::Resource file
;
75 QTextEdit
* editComment
;
76 KRatingWidget
* ratingWidget
;
77 Nepomuk::KMetaData::TagWidget
* tagWidget
;
82 MetaDataWidget::MetaDataWidget(QWidget
* parent
)
87 d
->editComment
= new QTextEdit(this);
88 d
->tagWidget
= new Nepomuk::KMetaData::TagWidget(this);
89 d
->ratingWidget
= new KRatingWidget(this);
90 connect(d
->ratingWidget
, SIGNAL(ratingChanged(int)), this, SLOT(slotRatingChanged(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(i18n("Rating:"), this));
98 hbox
->addWidget(d
->ratingWidget
);
100 lay
->addWidget(d
->editComment
);
101 hbox
= new QHBoxLayout
;
102 hbox
->addWidget(new QLabel(i18n("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
)
122 #ifdef HAVE_KMETADATA
123 // FIXME: replace with KMetaData::File once we have it again
125 d
->file
= Nepomuk::KMetaData::Resource(url
.url(), s_nfoFile
);
126 // d->file.setLocation(url.url());
127 d
->file
.setProperty( s_nfoFileUrl
, url
.url() );
128 d
->ratingWidget
->setRating(d
->file
.rating());
129 d
->tagWidget
->setTaggedResource(d
->file
);
130 d
->loadComment(d
->file
.description());
135 void MetaDataWidget::setFiles(const KUrl::List urls
)
137 #ifdef HAVE_KMETADATA
138 // FIXME: support multiple files
139 setFile(urls
.first());
144 void MetaDataWidget::slotCommentChanged()
146 #ifdef HAVE_KMETADATA
147 d
->file
.setDescription(d
->editComment
->toPlainText());
152 void MetaDataWidget::slotRatingChanged(int r
)
154 #ifdef HAVE_KMETADATA
155 d
->file
.setRating(r
);
160 bool MetaDataWidget::eventFilter(QObject
* obj
, QEvent
* event
)
162 #ifdef HAVE_KMETADATA
163 if (obj
== d
->editComment
->viewport()
164 || obj
== d
->editComment
) {
165 if (event
->type() == QEvent::FocusOut
) {
166 // make sure the info text is displayed again
167 d
->loadComment(d
->editComment
->toPlainText());
168 } else if (event
->type() == QEvent::FocusIn
) {
169 d
->editComment
->setFontItalic(false);
170 if (d
->file
.description().isEmpty())
171 d
->editComment
->setText(QString());
176 return QWidget::eventFilter(obj
, event
);
179 #include "metadatawidget.moc"