[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdenetwork/kget
From: Matthias Fuchs <mat69 () gmx ! net>
Date: 2011-05-04 10:05:49
Message-ID: 20110504100549.94515AC85F () svn ! kde ! org
[Download RAW message or body]
SVN commit 1230357 by mfuchs:
Improves Nepomuk handling by adding more properties and by using the correct \
ontologies.
M +12 -10 core/nepomukhandler.cpp
M +26 -3 core/verifier.cpp
M +14 -1 core/verifier.h
M +52 -12 ui/metalinkcreator/metalinker.cpp
M +1 -0 ui/metalinkcreator/metalinker.h
--- trunk/KDE/kdenetwork/kget/core/nepomukhandler.cpp #1230356:1230357
@@ -65,23 +65,25 @@
properties.append(qMakePair(NIE::url(), Nepomuk::Variant(destination)));
properties.append(qMakePair(NDO::copiedFrom(), \
Nepomuk::Variant(srcFileRes)));
- //just adds one Hash as otherwise it would not be clear in \
KFileMetaDataWidget which hash belongs
- //to which algorithm
Verifier *verifier = m_transfer->verifier(destination);
if (verifier) {
- const QPair<QString, QString> checksum = \
verifier->availableChecksum(Verifier::Strongest);
- QString hashType = checksum.first;
+ const QList<Checksum> checksums = verifier->availableChecksums();
+ QList<Nepomuk::Variant> hashes;
+ foreach (const Checksum &checksum, checksums) {
+ QString hashType = Verifier::cleanChecksumType(checksum.first);
const QString hash = checksum.second;
if (!hashType.isEmpty() && !hash.isEmpty()) {
- //use the offical names, i.e. uppercase and in the case of SHA with \
a '-'
- hashType = hashType.toUpper();
- if (hashType.contains(QRegExp("^SHA\\d+"))) {
- hashType.insert(3, '-');
+ Nepomuk::Resource hashRes(hash, NFO::FileHash());
+ hashRes.addProperty(NFO::hashAlgorithm(), hashType);
+ hashRes.addProperty(NFO::hashValue(), hash);
+ hashRes.setLabel(hashType);
+ hashes << hashRes;
}
- properties.append(qMakePair(NFO::hashAlgorithm(), \
Nepomuk::Variant(hashType)));
- properties.append(qMakePair(NFO::hashValue(), \
Nepomuk::Variant(hash))); }
+ if (!hashes.isEmpty()) {
+ properties.append(qMakePair(NFO::hasHash(), \
Nepomuk::Variant(hashes))); }
+ }
KGet::nepomukController()->setProperties(QList<KUrl>() << destination, \
properties); }
--- trunk/KDE/kdenetwork/kget/core/verifier.cpp #1230356:1230357
@@ -593,6 +593,16 @@
return false;
}
+QString Verifier::cleanChecksumType(const QString &type)
+{
+ QString hashType = type.toUpper();
+ if (hashType.contains(QRegExp("^SHA\\d+"))) {
+ hashType.insert(3, '-');
+ }
+
+ return hashType;
+}
+
bool Verifier::isVerifyable() const
{
return QFile::exists(m_dest.pathOrUrl()) && m_model->rowCount();
@@ -633,9 +643,9 @@
return checksumTypes;
}
-QPair<QString, QString> Verifier::availableChecksum(Verifier::ChecksumStrength \
strength) const +Checksum Verifier::availableChecksum(Verifier::ChecksumStrength \
strength) const {
- QPair<QString, QString> pair;
+ Checksum pair;
//check if there is at least one entry
QModelIndex index = m_model->index(0, 0);
@@ -659,6 +669,19 @@
return pair;
}
+QList<Checksum> Verifier::availableChecksums() const
+{
+ QList<Checksum> checksums;
+
+ for (int i = 0; i < m_model->rowCount(); ++i) {
+ const QString type = m_model->index(i, \
VerificationModel::Type).data().toString(); + const QString hash = \
m_model->index(i, VerificationModel::Checksum).data().toString(); + checksums \
<< qMakePair(type, hash); + }
+
+ return checksums;
+}
+
QPair<QString, PartialChecksums*> \
Verifier::availablePartialChecksum(Verifier::ChecksumStrength strength) const {
QPair<QString, PartialChecksums*> pair;
@@ -697,7 +720,7 @@
QString checksum;
if (row == -1) {
- QPair<QString, QString> pair = \
availableChecksum(static_cast<Verifier::ChecksumStrength>(Settings::checksumStrength()));
+ Checksum pair = \
availableChecksum(static_cast<Verifier::ChecksumStrength>(Settings::checksumStrength()));
type = pair.first;
checksum = pair.second;
} else if ((row >= 0) && (row < m_model->rowCount())) {
--- trunk/KDE/kdenetwork/kget/core/verifier.h #1230356:1230357
@@ -47,6 +47,8 @@
class VerificationResult;
}
+typedef QPair<QString, QString> Checksum;
+
class VerificationThread : public QThread
{
Q_OBJECT
@@ -247,6 +249,12 @@
static bool isChecksum(const QString &type, const QString &checksum);
/**
+ * Cleans the checksum type, that it should match the official name, i.e. \
upper case + * e.g. SHA-1 instead of sha1
+ */
+ static QString cleanChecksumType(const QString &type);
+
+ /**
* Creates the checksum type of the file dest
* @param abortPtr makes it possible to abort the calculation of the \
checksum from another thread
*/
@@ -313,9 +321,14 @@
* sha384 > sha256 .... < (sha512 preferred)
* If the category does not match then any checksum is taken
*/
- QPair<QString, QString> availableChecksum(ChecksumStrength strength) const;
+ Checksum availableChecksum(ChecksumStrength strength) const;
/**
+ * Returns all set checksums
+ */
+ QList<Checksum> availableChecksums() const;
+
+ /**
* Returns a PartialChecksum and a type
* @param strength the strength the checksum-type should have;
* weak is md5 > md4 > ... (md5 preferred), strong is sha1 > ripmed160 >
--- trunk/KDE/kdenetwork/kget/ui/metalinkcreator/metalinker.cpp #1230356:1230357
@@ -30,6 +30,13 @@
#ifdef HAVE_NEPOMUK
#include <Nepomuk/Variant>
+#include <Nepomuk/Vocabulary/NCO>
+#include <Nepomuk/Vocabulary/NIE>
+#include <Nepomuk/Vocabulary/NFO>
+#include <Soprano/Vocabulary/NAO>
+
+using namespace Nepomuk::Vocabulary;
+using namespace Soprano::Vocabulary;
#endif //HAVE_NEPOMUK
const QString KGetMetalink::Metalink::KGET_DESCRIPTION = QString(QString("KGet/") + \
"2." + QString::number(KDE_VERSION_MINOR) + '.' + \
QString::number(KDE_VERSION_RELEASE)); @@ -245,21 +252,49 @@
QList<QPair<QUrl, Nepomuk::Variant> > KGetMetalink::CommonData::properties() const
{
//TODO what to do with identity?
- //TODO what uri for logo?
- //TODO what uri for publisher-url?
QList<QPair<QUrl, Nepomuk::Variant> > data;
- HandleMetalink::addProperty(&data, \
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie/#version", \
version);
- HandleMetalink::addProperty(&data, \
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie/#description", \
description);
- if (oses.count()) {
- HandleMetalink::addProperty(&data, \
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#OperatingSystem", \
oses.first());//TODO support all set oses! + HandleMetalink::addProperty(&data, \
NIE::version(), version); + HandleMetalink::addProperty(&data, NIE::description(), \
description); +
+ QList<Nepomuk::Resource> osResources;
+ foreach (const QString &os, oses) {
+ Nepomuk::Resource osRes(os, NFO::OperatingSystem());
+ osRes.setProperty(NIE::title(), os);
+ osResources << osRes;
}
- if (languages.count()) {
- HandleMetalink::addProperty(&data, \
"http://www.semanticdesktop.org/ontologies/nie/#language", languages.first());//TODO \
support all set languages! + if (!osResources.isEmpty()) {
+ data << qMakePair(NAO::isRelated(), Nepomuk::Variant(osResources));
}
- HandleMetalink::addProperty(&data, \
"http://www.semanticdesktop.org/ontologies/2007/03/22/nco/#publisher", \
publisher.name);
- HandleMetalink::addProperty(&data, \
"http://www.semanticdesktop.org/ontologies/nie/#copyright", copyright);
+ if (!logo.isEmpty()) {
+ Nepomuk::Resource logoRes(logo, NFO::RemoteDataObject());
+ logoRes.addType(NAO::Symbol());
+ data << qMakePair(NAO::hasSymbol(), Nepomuk::Variant(logoRes));
+ }
+
+ QList<Nepomuk::Variant> langVariants;
+ foreach (const QString &language, languages) {
+ langVariants << language;
+ }
+ if (langVariants.count()) {
+ data << qMakePair(NIE::language(), Nepomuk::Variant(langVariants));
+ }
+
+ if (!publisher.name.isEmpty()) {
+ Nepomuk::Resource res(publisher.name, NCO::OrganizationContact());
+ res.setLabel(publisher.name);
+ res.addProperty(NCO::fullname(), publisher.name);
+ if (!publisher.url.isEmpty()) {
+ Nepomuk::Resource website(publisher.url, NFO::Website());
+ website.addProperty(NIE::url(), publisher.url);
+ res.addProperty(NCO::websiteUrl(), website);
+ }
+ data << qMakePair(NCO::publisher(), Nepomuk::Variant(res));
+ }
+
+ HandleMetalink::addProperty(&data, NIE::copyright(), copyright);
+
return data;
}
#endif //HAVE_NEPOMUK
@@ -1287,9 +1322,14 @@
#ifdef HAVE_NEPOMUK
void KGetMetalink::HandleMetalink::addProperty(QList<QPair<QUrl, Nepomuk::Variant> > \
*data, const QByteArray &uriBa, const QString &value) {
- if (data && !uriBa.isEmpty() && !value.isEmpty())
+ if (!uriBa.isEmpty()) {
+ addProperty(data, QUrl::fromEncoded(uriBa, QUrl::StrictMode), value);
+ }
+}
+
+void KGetMetalink::HandleMetalink::addProperty(QList<QPair<QUrl, Nepomuk::Variant> > \
*data, const QUrl &uri, const QString &value) {
- const QUrl uri = QUrl::fromEncoded(uriBa, QUrl::StrictMode);
+ if (data && !uri.isEmpty() && !value.isEmpty()) {
(*data) << qMakePair(uri, Nepomuk::Variant(value));
}
}
--- trunk/KDE/kdenetwork/kget/ui/metalinkcreator/metalinker.h #1230356:1230357
@@ -408,6 +408,7 @@
* Convenience method to add Strings to the data
*/
static void addProperty(QList<QPair<QUrl, Nepomuk::Variant> > *data, const \
QByteArray &uriBa, const QString &value); + static void \
addProperty(QList<QPair<QUrl, Nepomuk::Variant> > *data, const QUrl &uri, const \
QString &value); #endif //HAVE_NEPOMUK
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic