16
16
#include "nepomukcontroller.h"
17
17
#include "verifier.h"
22
#include <Soprano/Vocabulary/Xesam>
23
19
#include <Nepomuk/Variant>
24
20
#include <Nepomuk/Tag>
21
#include <Nepomuk/Vocabulary/NDO>
22
#include <Nepomuk/Vocabulary/NFO>
23
#include <Nepomuk/Vocabulary/NIE>
25
using namespace Nepomuk::Vocabulary;
26
27
NepomukHandler::NepomukHandler(Transfer *transfer)
27
28
: QObject(transfer),
53
54
const QList<KUrl> destinations = m_transfer->files();
55
QPair<QUrl, Nepomuk::Variant> property = qMakePair(Nepomuk::Vocabulary::NIE::url(), Nepomuk::Variant(m_transfer->source()));
56
KGet::nepomukController()->setProperty(QList<KUrl>() << m_transfer->source(), property, Nepomuk::Vocabulary::NFO::RemoteDataObject());
57
Nepomuk::Resource srcFileRes(m_transfer->source(), Nepomuk::Vocabulary::NFO::RemoteDataObject());
56
const KUrl src = m_transfer->source();
57
const QUrl srcType = (src.isLocalFile() ? NFO::FileDataObject() : NFO::RemoteDataObject());
58
QPair<QUrl, Nepomuk::Variant> property = qMakePair(NIE::url(), Nepomuk::Variant(src));
59
KGet::nepomukController()->setProperty(QList<KUrl>() << src, property, srcType);
60
Nepomuk::Resource srcFileRes(src, srcType);
59
62
foreach (const KUrl &destination, destinations) {
60
63
//set all the properties
61
64
QList<QPair<QUrl, Nepomuk::Variant> > properties;
62
properties.append(qMakePair(Nepomuk::Vocabulary::NIE::url(), Nepomuk::Variant(destination)));
63
properties.append(qMakePair(Nepomuk::Vocabulary::NDO::copiedFrom(), Nepomuk::Variant(srcFileRes)));
64
properties.append(qMakePair(Soprano::Vocabulary::Xesam::originURL(), Nepomuk::Variant(m_transfer->source().url())));
65
properties.append(qMakePair(NIE::url(), Nepomuk::Variant(destination)));
66
properties.append(qMakePair(NDO::copiedFrom(), Nepomuk::Variant(srcFileRes)));
66
//just adds one Hash as otherwise it would not be clear in KFileMetaDataWidget which hash belongs
68
68
Verifier *verifier = m_transfer->verifier(destination);
70
const QPair<QString, QString> checksum = verifier->availableChecksum(Verifier::Strongest);
71
QString hashType = checksum.first;
72
const QString hash = checksum.second;
73
if (!hashType.isEmpty() && !hash.isEmpty()) {
74
//use the offical names, i.e. uppercase and in the case of SHA with a '-'
75
hashType = hashType.toUpper();
76
if (hashType.contains(QRegExp("^SHA\\d+"))) {
77
hashType.insert(3, '-');
70
const QList<Checksum> checksums = verifier->availableChecksums();
71
QList<Nepomuk::Variant> hashes;
72
foreach (const Checksum &checksum, checksums) {
73
QString hashType = Verifier::cleanChecksumType(checksum.first);
74
const QString hash = checksum.second;
75
if (!hashType.isEmpty() && !hash.isEmpty()) {
76
Nepomuk::Resource hashRes(hash, NFO::FileHash());
77
hashRes.addProperty(NFO::hashAlgorithm(), hashType);
78
hashRes.addProperty(NFO::hashValue(), hash);
79
hashRes.setLabel(hashType);
79
properties.append(qMakePair(Nepomuk::Vocabulary::NFO::hashAlgorithm(), Nepomuk::Variant(hashType)));
80
properties.append(qMakePair(Nepomuk::Vocabulary::NFO::hashValue(), Nepomuk::Variant(hash)));
83
if (!hashes.isEmpty()) {
84
properties.append(qMakePair(NFO::hasHash(), Nepomuk::Variant(hashes)));