]>
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 "commentwidget.h"
24 #include <config-nepomuk.h>
28 #include <KMessageBox>
30 #include <QtCore/QEvent>
31 #include <QtGui/QLabel>
32 #include <QtGui/QGridLayout>
33 #include <QtGui/QTextEdit>
36 #include "nepomukmassupdatejob.h"
37 #include <nepomuk/kmetadatatagwidget.h>
38 #include <nepomuk/resourcemanager.h>
39 #include <nepomuk/resource.h>
40 #include <nepomuk/variant.h>
41 #include <nepomuk/kratingwidget.h>
42 #include <Soprano/Vocabulary/Xesam>
43 #include "tagcloud/resourcetaggingwidget.h"
47 bool MetaDataWidget::metaDataAvailable()
50 return !Nepomuk::ResourceManager::instance()->init();
57 class MetaDataWidget::Private
61 void loadComment(const QString
& comment
);
63 QMap
<KUrl
, Nepomuk::Resource
> files
;
65 CommentWidget
* editComment
;
66 KRatingWidget
* ratingWidget
;
67 Nepomuk::ResourceTaggingWidget
* tagWidget
;
72 void MetaDataWidget::Private::loadComment(const QString
& comment
)
74 editComment
->setComment( comment
);
79 MetaDataWidget::MetaDataWidget(QWidget
* parent
) :
84 d
->editComment
= new CommentWidget(this);
85 d
->editComment
->setFocusPolicy(Qt::ClickFocus
);
86 d
->ratingWidget
= new KRatingWidget(this);
87 d
->ratingWidget
->setAlignment( Qt::AlignCenter
);
88 d
->tagWidget
= new Nepomuk::ResourceTaggingWidget(this);
89 connect(d
->ratingWidget
, SIGNAL(ratingChanged(unsigned int)), this, SLOT(slotRatingChanged(unsigned int)));
90 connect(d
->editComment
, SIGNAL(commentChanged(const QString
&)), this, SLOT(slotCommentChanged(const QString
&)));
91 connect( d
->tagWidget
, SIGNAL( tagClicked( const Nepomuk::Tag
& ) ), this, SLOT( slotTagClicked( const Nepomuk::Tag
& ) ) );
93 QVBoxLayout
* lay
= new QVBoxLayout(this);
95 lay
->addWidget(d
->ratingWidget
);
96 lay
->addWidget(d
->editComment
);
97 QHBoxLayout
* hbox
= new QHBoxLayout
;
98 lay
->addWidget( d
->tagWidget
);
105 MetaDataWidget::~MetaDataWidget()
111 void MetaDataWidget::setFile(const KUrl
& url
)
120 void MetaDataWidget::setFiles(const KUrl::List
& urls
)
125 QList
<Nepomuk::Resource
> fileRes
;
126 Q_FOREACH( KUrl url
, urls
) {
127 Nepomuk::Resource
file( url
, Soprano::Vocabulary::Xesam::File() );
128 d
->files
.insert( url
, file
);
129 fileRes
.append( file
);
132 d
->ratingWidget
->rating() != file
.rating() ) {
133 d
->ratingWidget
->setRating( 0 ); // reset rating
136 d
->ratingWidget
->setRating( (qint32
)(file
.rating()) );
140 d
->editComment
->comment() != file
.description() ) {
141 d
->loadComment( QString() );
144 d
->loadComment( file
.description() );
148 d
->tagWidget
->setResources( fileRes
);
153 void MetaDataWidget::slotCommentChanged( const QString
& s
)
156 Nepomuk::MassUpdateJob
* job
= Nepomuk::MassUpdateJob::commentResources( d
->files
.values(), s
);
157 connect( job
, SIGNAL( result( KJob
* ) ),
158 this, SLOT( metadataUpdateDone() ) );
159 setEnabled( false ); // no updates during execution
165 void MetaDataWidget::slotRatingChanged(unsigned int rating
)
168 Nepomuk::MassUpdateJob
* job
= Nepomuk::MassUpdateJob::rateResources( d
->files
.values(), rating
);
169 connect( job
, SIGNAL( result( KJob
* ) ),
170 this, SLOT( metadataUpdateDone() ) );
171 setEnabled( false ); // no updates during execution
177 void MetaDataWidget::metadataUpdateDone()
183 bool MetaDataWidget::eventFilter(QObject
* obj
, QEvent
* event
)
185 return QWidget::eventFilter(obj
, event
);
189 void MetaDataWidget::slotTagClicked( const Nepomuk::Tag
& tag
)
193 KMessageBox::information( this, "FIXME: connect me to the dolphinmodel: tags:/" + tag
.genericLabel() );
197 #include "metadatawidget.moc"