• 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
nepomukcontroller.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
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 "nepomukcontroller.h"
21 
22 #include <QtCore/QFile>
23 #include <Nepomuk2/DataManagement>
24 #include <Nepomuk2/Tag>
25 #include <Nepomuk2/Variant>
26 #include <Soprano/Vocabulary/NAO>
27 
28 #include <KJob>
29 #include <KDebug>
30 
31 NepomukController::NepomukController(QObject *parent)
32  : QThread(parent)
33 {
34 }
35 
36 NepomukController::~NepomukController()
37 {
38  wait();
39 }
40 
41 void NepomukController::setProperty(const QList<QUrl> &uris, QPair<QUrl, Nepomuk2::Variant> &property, const QUrl &uriType)
42 {
43  setProperties(uris, QList<QPair<QUrl, Nepomuk2::Variant> >() << property, uriType);
44 }
45 
46 void NepomukController::setProperties(const QList<QUrl> &uris, const QList<QPair<QUrl, Nepomuk2::Variant> > &properties, const QUrl &uriType)
47 {
48  if (uris.isEmpty() || properties.isEmpty()) {
49  return;
50  }
51 
52  for(QList<QPair<QUrl, Nepomuk2::Variant> >::ConstIterator i = properties.constBegin(); i < properties.constEnd(); i++) {
53  KJob * nepomukJob = Nepomuk2::addProperty(uris, i->first, QVariantList() << i->second.variant());
54  kWarning() << nepomukJob << uris << i->first << i->second.variant();
55  connect(nepomukJob, SIGNAL(result(KJob*)), this, SLOT(nepomukError(KJob*)));
56  }
57 }
58 
59 void NepomukController::addTags(const QList<QUrl> &uris, const QList<Nepomuk2::Tag> &tags, const QUrl &uriType)
60 {
61  QVariantList tagUris;
62 
63  if (uris.isEmpty() || tags.isEmpty()) {
64  return;
65  }
66 
67  foreach(Nepomuk2::Tag tag, tags) {
68  tagUris.push_back(tag.uri());
69  }
70 
71  Nepomuk2::addProperty(uris, Soprano::Vocabulary::NAO::hasTag(), tagUris);
72 }
73 
74 void NepomukController::removeResource(const QList<KUrl> &uris)
75 {
76  QMutexLocker locker(&m_mutex);
77  m_uris << uris;
78 
79  if (!isRunning()) {
80  start();
81  }
82 }
83 
84 bool NepomukController::continueToRun()
85 {
86  QMutexLocker locker(&m_mutex);
87 
88  return !m_uris.isEmpty();
89 }
90 
91 
92 void NepomukController::run()
93 {
94  while (continueToRun()) {
95  m_mutex.lock();
96  QList<KUrl> uris = m_uris;
97  m_uris.clear();
98  m_mutex.unlock();
99 
100  foreach (const KUrl &uri, uris) {
101  if (!QFile::exists(uri.path())) {
102  Nepomuk2::Resource resource(uri, Nepomuk2::Vocabulary::NFO::FileDataObject());
103  resource.remove();
104  }
105  }
106  }
107 }
108 
109 void NepomukController::nepomukError(KJob* job)
110 {
111  kWarning() << job->errorText();
112 }
NepomukController::setProperties
void setProperties(const QList< QUrl > &uris, const QList< QPair< QUrl, Nepomuk2::Variant > > &properties, const QUrl &uriType=Nepomuk2::Vocabulary::NFO::FileDataObject())
Definition: nepomukcontroller.cpp:46
NepomukController::run
void run()
Definition: nepomukcontroller.cpp:92
NepomukController::addTags
void addTags(const QList< QUrl > &uris, const QList< Nepomuk2::Tag > &tags, const QUrl &uriType=Nepomuk2::Vocabulary::NFO::FileDataObject())
Definition: nepomukcontroller.cpp:59
QObject
NepomukController::removeResource
void removeResource(const QList< KUrl > &uris)
Removes the resources associated with uris.
Definition: nepomukcontroller.cpp:74
NepomukController::setProperty
void setProperty(const QList< QUrl > &uris, QPair< QUrl, Nepomuk2::Variant > &property, const QUrl &uriType=Nepomuk2::Vocabulary::NFO::FileDataObject())
Definition: nepomukcontroller.cpp:41
NepomukController::~NepomukController
~NepomukController()
Definition: nepomukcontroller.cpp:36
nepomukcontroller.h
NepomukController::NepomukController
NepomukController(QObject *parent=0)
Definition: nepomukcontroller.cpp:31
QThread
KJob
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