• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • core
nepomukhandler.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2 
3  Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
4  Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 */
11 #include "nepomukhandler.h"
12 
13 #include "transfer.h"
14 #include "transfergroup.h"
15 #include "kget.h"
16 #include "nepomukcontroller.h"
17 #include "verifier.h"
18 
19 #include <Nepomuk2/Variant>
20 #include <Nepomuk2/Tag>
21 #include <Soprano/Vocabulary/RDF>
22 #include <Nepomuk2/Vocabulary/NDO>
23 #include <Nepomuk2/Vocabulary/NFO>
24 #include <Nepomuk2/Vocabulary/NIE>
25 
26 using namespace Nepomuk2::Vocabulary;
27 
28 NepomukHandler::NepomukHandler(Transfer *transfer)
29  : QObject(transfer),
30  m_transfer(transfer)
31 {
32 }
33 
34 NepomukHandler::~NepomukHandler()
35 {
36 }
37 
38 KFileItemList NepomukHandler::fileItems() const
39 {
40  KFileItemList fileItems;
41  foreach (const KUrl &destination, m_transfer->files()) {
42  fileItems << KFileItem(KFileItem::Unknown, KFileItem::Unknown, destination, true);
43  }
44  return fileItems;
45 }
46 
47 void NepomukHandler::setProperties(const QList<QPair<QUrl, Nepomuk2::Variant> > &properties, const QList<KUrl> &files)
48 {
49  QList<KUrl> usedFiles = (files.isEmpty() ? m_transfer->files() : files);
50  QList<QUrl> fileUrls;
51 
52  foreach(const KUrl &usedFile, usedFiles) {
53  fileUrls.push_back(usedFile);
54  }
55 
56  KGet::nepomukController()->setProperties(fileUrls, properties);
57 }
58 
59 void NepomukHandler::saveFileProperties()
60 {
61  QList<QUrl> destinations;
62 
63  foreach(const KUrl &url, m_transfer->files()) {
64  destinations.push_back(url);
65  }
66 
67  const QUrl src = m_transfer->source();
68  const QUrl srcType = (src.isLocalFile() ? NFO::FileDataObject() : NFO::RemoteDataObject());
69  Nepomuk2::Resource srcFileRes(src);
70 
71  srcFileRes.setProperty(Soprano::Vocabulary::RDF::type(), srcType);
72 
73  foreach (const QUrl &destination, destinations) {
74  //set all the properties
75  Nepomuk2::Resource destinationRes(destination);
76  QList<QPair<QUrl, Nepomuk2::Variant> > properties;
77  properties.append(qMakePair(NDO::copiedFrom(), Nepomuk2::Variant(srcFileRes.uri())));
78 
79  Verifier *verifier = m_transfer->verifier(destination);
80  if (verifier) {
81  const QList<Checksum> checksums = verifier->availableChecksums();
82  QList<Nepomuk2::Variant> hashes;
83  foreach (const Checksum &checksum, checksums) {
84  QString hashType = Verifier::cleanChecksumType(checksum.first);
85  const QString hash = checksum.second;
86  if (!hashType.isEmpty() && !hash.isEmpty()) {
87  Nepomuk2::Resource hashRes(hash, NFO::FileHash());
88  hashRes.addProperty(NFO::hashAlgorithm(), hashType);
89  hashRes.addProperty(NFO::hashValue(), hash);
90  hashRes.setLabel(hashType);
91  hashes << hashRes;
92  }
93  }
94  if (!hashes.isEmpty()) {
95  properties.append(qMakePair(NFO::hasHash(), Nepomuk2::Variant(hashes)));
96  }
97  }
98 
99  KGet::nepomukController()->setProperties(QList<QUrl>() << destinationRes.uri() , properties);
100  }
101 
102  //set the tags of the group
103  KGet::nepomukController()->addTags(destinations, m_transfer->group()->tags());
104 
105  /*Nepomuk::Resource downloadEventRes(QUrl(), Nepomuk::Vocabulary::NDO::DownloadEvent());
106  downloadEventRes.addProperty(Nepomuk::Vocabulary::NUAO::involves(), m_res);
107  downloadEventRes.addProperty(Nepomuk::Vocabulary::NUAO::start(), m_downloadJobStartTime);*/
108 }
109 
110 void NepomukHandler::deinit()
111 {
112  KGet::nepomukController()->removeResource(m_transfer->files());
113 }
114 
115 #include "nepomukhandler.moc"
Transfer::source
const KUrl & source() const
Definition: transfer.h:148
Verifier::availableChecksums
QList< Checksum > availableChecksums() const
Returns all set checksums.
Definition: verifier.cpp:324
Checksum
QPair< QString, QString > Checksum
Definition: verifier.h:36
NepomukHandler::saveFileProperties
void saveFileProperties()
Definition: nepomukhandler.cpp:59
NepomukHandler::setProperties
void setProperties(const QList< QPair< QUrl, Nepomuk2::Variant > > &properties, const QList< KUrl > &files=QList< KUrl >())
Sets properties to a list of files, if the list is empty m_destinations is used.
Definition: nepomukhandler.cpp:47
nepomukhandler.h
Transfer::group
TransferGroup * group() const
The owner group.
Definition: transfer.h:257
NepomukHandler::NepomukHandler
NepomukHandler(Transfer *transfer)
Definition: nepomukhandler.cpp:28
QObject
NepomukHandler::fileItems
KFileItemList fileItems() const
Definition: nepomukhandler.cpp:38
transfergroup.h
verifier.h
nepomukcontroller.h
NepomukHandler::deinit
void deinit()
Removes the resource if the isValid() is false.
Definition: nepomukhandler.cpp:110
Verifier::cleanChecksumType
static QString cleanChecksumType(const QString &type)
Cleans the checksum type, that it should match the official name, i.e.
Definition: verifier.cpp:269
Transfer::files
virtual QList< KUrl > files() const
Definition: transfer.h:154
Verifier
Definition: verifier.h:68
kget.h
transfer.h
Transfer::verifier
virtual Verifier * verifier(const KUrl &file)
Definition: transfer.h:283
NepomukHandler::~NepomukHandler
virtual ~NepomukHandler()
Definition: nepomukhandler.cpp:34
Transfer
Definition: transfer.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal