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

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • services
  • storage
  • query
folderconnection.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2008-2010 Sebastian Trueg <trueg@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "folderconnection.h"
20 #include "folder.h"
21 #include "queryadaptor.h"
22 
23 #include "resource.h"
24 #include "result.h"
25 
26 #include <QtCore/QStringList>
27 #include <QtDBus/QDBusServiceWatcher>
28 
29 #include <KDebug>
30 #include <kdbusconnectionpool.h>
31 
32 Nepomuk2::Query::FolderConnection::FolderConnection( Folder* folder )
33  : QObject( folder ),
34  m_folder( folder )
35 {
36  m_folder->addConnection( this );
37 }
38 
39 
40 Nepomuk2::Query::FolderConnection::~FolderConnection()
41 {
42  m_folder->removeConnection( this );
43 }
44 
45 
46 void Nepomuk2::Query::FolderConnection::list()
47 {
48  kDebug();
49 
50  m_folder->disconnect( this );
51  connect( m_folder, SIGNAL( newEntries( QList<Nepomuk2::Query::Result> ) ),
52  this, SIGNAL( newEntries( QList<Nepomuk2::Query::Result> ) ) );
53  connect( m_folder, SIGNAL( entriesRemoved( QList<Nepomuk2::Query::Result> ) ),
54  this, SLOT( slotEntriesRemoved( QList<Nepomuk2::Query::Result> ) ) );
55 
56  // report cached entries
57  if ( !m_folder->entries().isEmpty() ) {
58  emit newEntries( m_folder->entries() );
59  }
60 
61  // report listing finished or connect to the folder
62  if ( m_folder->initialListingDone() ) {
63  emit finishedListing();
64  }
65  else {
66  // We do NOT connect to slotFinishedListing!
67  connect( m_folder, SIGNAL( finishedListing() ),
68  this, SIGNAL( finishedListing() ) );
69 
70  // make sure the search has actually been started
71  m_folder->update();
72  }
73 
74  // report the count or connect to the signal
75  if( m_folder->getResultCount() >= 0 ) {
76  emit resultCount( m_folder->getResultCount() );
77  }
78  else {
79  connect( m_folder, SIGNAL( resultCount( int ) ),
80  this, SIGNAL( resultCount( int ) ) );
81  }
82 }
83 
84 
85 void Nepomuk2::Query::FolderConnection::listen()
86 {
87  m_folder->disconnect( this );
88 
89  // if the folder has already finished listing it will only emit
90  // changed - exactly what we want
91  if ( m_folder->initialListingDone() ) {
92  connect( m_folder, SIGNAL( newEntries( QList<Nepomuk2::Query::Result> ) ),
93  this, SIGNAL( newEntries( QList<Nepomuk2::Query::Result> ) ) );
94  connect( m_folder, SIGNAL( entriesRemoved( QList<Nepomuk2::Query::Result> ) ),
95  this, SLOT( slotEntriesRemoved( QList<Nepomuk2::Query::Result> ) ) );
96  connect( m_folder, SIGNAL( resultCount( int ) ),
97  this, SIGNAL( resultCount( int ) ) );
98  }
99 
100  // otherwise we need to wait for it finishing the listing
101  else {
102  connect( m_folder, SIGNAL( finishedListing() ),
103  this, SLOT( slotFinishedListing() ) );
104  }
105 }
106 
107 
108 void Nepomuk2::Query::FolderConnection::slotEntriesRemoved( const QList<Nepomuk2::Query::Result>& entries )
109 {
110  QStringList uris;
111  for ( int i = 0; i < entries.count(); ++i ) {
112  uris.append( entries[i].resource().uri().toString() );
113  }
114  emit entriesRemoved( uris );
115  emit entriesRemoved( entries );
116 }
117 
118 
119 void Nepomuk2::Query::FolderConnection::slotFinishedListing()
120 {
121  // this slot is only called in listen mode. Once the listing is
122  // finished we can start listening for changes
123  connect( m_folder, SIGNAL( newEntries( QList<Nepomuk2::Query::Result> ) ),
124  this, SIGNAL( newEntries( QList<Nepomuk2::Query::Result> ) ) );
125  connect( m_folder, SIGNAL( entriesRemoved( QList<Nepomuk2::Query::Result> ) ),
126  this, SLOT( slotEntriesRemoved( QList<Nepomuk2::Query::Result> ) ) );
127 }
128 
129 
130 void Nepomuk2::Query::FolderConnection::close()
131 {
132  kDebug();
133  deleteLater();
134 }
135 
136 
137 bool Nepomuk2::Query::FolderConnection::isListingFinished() const
138 {
139  return m_folder->initialListingDone();
140 }
141 
142 
143 QString Nepomuk2::Query::FolderConnection::queryString() const
144 {
145  return m_folder->sparqlQuery();
146 }
147 
148 
149 QDBusObjectPath Nepomuk2::Query::FolderConnection::registerDBusObject( const QString& dbusClient, int id )
150 {
151  // create the query adaptor on this connection
152  ( void )new QueryAdaptor( this );
153 
154  // build the dbus object path from the id and register the connection as a Query dbus object
155  const QString dbusObjectPath = QString( "/nepomukqueryservice/query%1" ).arg( id );
156  QDBusConnection con = KDBusConnectionPool::threadConnection();
157  con.registerObject( dbusObjectPath, this );
158 
159  // watch the dbus client for unregistration for auto-cleanup
160  m_serviceWatcher = new QDBusServiceWatcher( dbusClient,
161  con,
162  QDBusServiceWatcher::WatchForUnregistration,
163  this );
164  connect( m_serviceWatcher, SIGNAL(serviceUnregistered(QString)),
165  this, SLOT(close()) );
166 
167  // finally return the dbus object path this connection can be found on
168  return QDBusObjectPath( dbusObjectPath );
169 }
170 
171 #include "folderconnection.moc"
Nepomuk2::Query::FolderConnection::queryString
QString queryString() const
Definition: folderconnection.cpp:143
Nepomuk2::Query::FolderConnection::FolderConnection
FolderConnection(Folder *parentFolder)
Definition: folderconnection.cpp:32
Nepomuk2::Query::FolderConnection::listen
void listen()
internal API used by the kio kded module to listen for changes
Definition: folderconnection.cpp:85
Nepomuk2::Query::FolderConnection::list
void list()
List all entries in the folder, used by the public kdelibs API.
Definition: folderconnection.cpp:46
QObject
Nepomuk2::Query::FolderConnection::~FolderConnection
~FolderConnection()
Definition: folderconnection.cpp:40
result.h
Nepomuk2::Query::FolderConnection::isListingFinished
bool isListingFinished() const
Definition: folderconnection.cpp:137
resource.h
folder.h
Nepomuk2::Query::FolderConnection::close
void close()
close the connection to the folder. Will delete this connection
Definition: folderconnection.cpp:130
Nepomuk2::Query::FolderConnection::registerDBusObject
QDBusObjectPath registerDBusObject(const QString &dbusClient, int id)
Definition: folderconnection.cpp:149
Nepomuk2::Query::Folder
One search folder which automatically updates itself.
Definition: folder.h:49
folderconnection.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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