]> cloud.milkyroute.net Git - dolphin.git/blob - src/metadatawidget.cpp
make it compile again.
[dolphin.git] / src / metadatawidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2007 by Sebastian Trueg <trueg@kde.org> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include <config-kmetadata.h>
21
22 #include "metadatawidget.h"
23
24 #include <klocale.h>
25
26 #include <QLabel>
27 #include <QGridLayout>
28 #include <QTextEdit>
29
30 #ifdef HAVE_KMETADATA
31 #include <kmetadata/kmetadatatagwidget.h>
32 #include <kmetadata/resourcemanager.h>
33 #include <kmetadata/resource.h>
34 #include <kmetadata/kratingwidget.h>
35 #include <kmetadata/kmetadatatagwidget.h>
36 #endif
37
38
39 bool MetaDataWidget::metaDataAvailable()
40 {
41 #ifdef HAVE_KMETADATA
42 return !Nepomuk::KMetaData::ResourceManager::instance()->init();
43 #else
44 return false;
45 #endif
46 }
47
48
49 class MetaDataWidget::Private
50 {
51 public:
52 #ifdef HAVE_KMETADATA
53 void loadComment(const QString& comment)
54 {
55 editComment->blockSignals(true);
56 if (comment.isEmpty()) {
57 editComment->setFontItalic(true);
58 editComment->setText(i18n("Click to add comment..."));
59 } else {
60 editComment->setFontItalic(false);
61 editComment->setText(comment);
62 }
63 editComment->blockSignals(false);
64 }
65
66 KUrl fileUrl;
67
68 Nepomuk::KMetaData::Resource file;
69
70 QTextEdit* editComment;
71 KRatingWidget* ratingWidget;
72 Nepomuk::KMetaData::TagWidget* tagWidget;
73 #endif
74 };
75
76
77 MetaDataWidget::MetaDataWidget(QWidget* parent)
78 : QWidget(parent)
79 {
80 #ifdef HAVE_KMETADATA
81 d = new Private;
82 d->editComment = new QTextEdit(this);
83 d->tagWidget = new Nepomuk::KMetaData::TagWidget(this);
84 d->ratingWidget = new KRatingWidget(this);
85 connect(d->ratingWidget, SIGNAL(ratingChanged(int)), this, SLOT(slotRatingChanged(int)));
86 connect(d->editComment, SIGNAL(textChanged()), this, SLOT(slotCommentChanged()));
87
88 QVBoxLayout* lay = new QVBoxLayout(this);
89 lay->setMargin(0);
90 QHBoxLayout* hbox = new QHBoxLayout;
91 hbox->addWidget(new QLabel(i18n("Rating:"), this));
92 hbox->addStretch(1);
93 hbox->addWidget(d->ratingWidget);
94 lay->addLayout(hbox);
95 lay->addWidget(d->editComment);
96 hbox = new QHBoxLayout;
97 hbox->addWidget(new QLabel(i18n("Tags:"), this));
98 hbox->addWidget(d->tagWidget, 1);
99 lay->addLayout(hbox);
100
101 d->editComment->installEventFilter(this);
102 d->editComment->viewport()->installEventFilter(this);
103 #else
104 d = 0L;
105 #endif
106 }
107
108
109 MetaDataWidget::~MetaDataWidget()
110 {
111 delete d;
112 }
113
114
115 void MetaDataWidget::setFile(const KUrl& url)
116 {
117 #ifdef HAVE_KMETADATA
118 // FIXME: replace with KMetaData::File once we have it again
119 d->fileUrl = url;
120 d->file = Nepomuk::KMetaData::Resource(url.url());
121 // d->file.setLocation(url.url());
122 d->ratingWidget->setRating(d->file.getRating());
123 d->tagWidget->setTaggedResource(d->file);
124 d->loadComment(d->file.getComment());
125 #endif
126 }
127
128
129 void MetaDataWidget::setFiles(const KUrl::List urls)
130 {
131 #ifdef HAVE_KMETADATA
132 // FIXME: support multiple files
133 setFile(urls.first());
134 #endif
135 }
136
137
138 void MetaDataWidget::slotCommentChanged()
139 {
140 #ifdef HAVE_KMETADATA
141 d->file.setComment(d->editComment->toPlainText());
142 #endif
143 }
144
145
146 void MetaDataWidget::slotRatingChanged(int r)
147 {
148 #ifdef HAVE_KMETADATA
149 d->file.setRating(r);
150 #endif
151 }
152
153
154 bool MetaDataWidget::eventFilter(QObject* obj, QEvent* event)
155 {
156 #ifdef HAVE_KMETADATA
157 if (obj == d->editComment->viewport()
158 || obj == d->editComment) {
159 if (event->type() == QEvent::FocusOut) {
160 // make sure the info text is displayed again
161 d->loadComment(d->editComment->toPlainText());
162 } else if (event->type() == QEvent::FocusIn) {
163 d->editComment->setFontItalic(false);
164 if (d->file.getComment().isEmpty())
165 d->editComment->setText(QString());
166 }
167 }
168 #endif
169
170 return QWidget::eventFilter(obj, event);
171 }
172
173 #include "metadatawidget.moc"