• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

NepomukDaemons

folder.cpp

Go to the documentation of this file.
00001 /*
00002    Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "folder.h"
00020 #include "folderconnection.h"
00021 #include "queryservice.h"
00022 #include "qurlhash.h"
00023 
00024 #include <Soprano/Model>
00025 
00026 #include <KDebug>
00027 
00028 
00029 Nepomuk::Search::Folder::Folder( const Query& query, QObject* parent )
00030     : QObject( parent ),
00031       m_query( query ),
00032       m_initialListingDone( false ),
00033       m_storageChanged( false )
00034 {
00035     m_updateTimer.setSingleShot( true );
00036     m_updateTimer.setInterval( 2000 );
00037 
00038     m_searchCore = new SearchCore( this );
00039 
00040     connect( m_searchCore, SIGNAL( newResult( const Nepomuk::Search::Result& ) ),
00041              this, SLOT( slotSearchNewResult( const Nepomuk::Search::Result& ) ) );
00042     connect( m_searchCore, SIGNAL( scoreChanged( const Nepomuk::Search::Result& ) ),
00043              this, SLOT( slotSearchScoreChanged( const Nepomuk::Search::Result& ) ) );
00044     connect( m_searchCore, SIGNAL( finished() ),
00045              this, SLOT( slotSearchFinished() ) );
00046     connect( QueryService::instance()->mainModel(), SIGNAL( statementsAdded() ),
00047              this, SLOT( slotStorageChanged() ) );
00048     connect( QueryService::instance()->mainModel(), SIGNAL( statementsRemoved() ),
00049              this, SLOT( slotStorageChanged() ) );
00050     connect( &m_updateTimer, SIGNAL( timeout() ),
00051              this, SLOT( slotUpdateTimeout() ) );
00052 }
00053 
00054 
00055 Nepomuk::Search::Folder::~Folder()
00056 {
00057 }
00058 
00059 
00060 void Nepomuk::Search::Folder::update()
00061 {
00062     if ( !m_searchCore->isActive() ) {
00063         // run the search and forward signals to all connections that requested it
00064         m_searchCore->query( m_query );
00065     }
00066 }
00067 
00068 
00069 QList<Nepomuk::Search::Result> Nepomuk::Search::Folder::entries() const
00070 {
00071     return m_results.values();
00072 }
00073 
00074 
00075 bool Nepomuk::Search::Folder::initialListingDone() const
00076 {
00077     return m_initialListingDone;
00078 }
00079 
00080 
00081 void Nepomuk::Search::Folder::slotSearchNewResult( const Nepomuk::Search::Result& result )
00082 {
00083     if ( m_initialListingDone ) {
00084         m_newResults.insert( result.resourceUri(), result );
00085         if ( !m_results.contains( result.resourceUri() ) ) {
00086             emit newEntries( QList<Result>() << result );
00087         }
00088     }
00089     else {
00090         m_results.insert( result.resourceUri(), result );
00091         emit newEntries( QList<Result>() << result );
00092     }
00093 }
00094 
00095 
00096 void Nepomuk::Search::Folder::slotSearchScoreChanged( const Nepomuk::Search::Result& )
00097 {
00098     if ( m_initialListingDone ) {
00099 #warning FIXME: handle scoreChanged
00100     }
00101     else {
00102 
00103     }
00104 }
00105 
00106 
00107 void Nepomuk::Search::Folder::slotSearchFinished()
00108 {
00109     if ( m_initialListingDone ) {
00110         // inform about removed items
00111         foreach( const Result& result, m_results ) {
00112             if ( !m_newResults.contains( result.resourceUri() ) ) {
00113                 emit entriesRemoved( QList<QUrl>() << result.resourceUri() );
00114             }
00115         }
00116 
00117         // reset
00118         m_results = m_newResults;
00119         m_newResults.clear();
00120     }
00121     else {
00122         m_initialListingDone = true;
00123         emit finishedListing();
00124     }
00125 
00126     // make sure we do not update again right away
00127     m_updateTimer.start();
00128 }
00129 
00130 
00131 void Nepomuk::Search::Folder::slotStorageChanged()
00132 {
00133     if ( !m_updateTimer.isActive() && !m_searchCore->isActive() ) {
00134         update();
00135     }
00136     else {
00137         m_storageChanged = true;
00138     }
00139 }
00140 
00141 
00142 // if there was a change in the nepomuk store we update
00143 void Nepomuk::Search::Folder::slotUpdateTimeout()
00144 {
00145     if ( m_storageChanged && !m_searchCore->isActive() ) {
00146         m_storageChanged = false;
00147         update();
00148     }
00149 }
00150 
00151 
00152 void Nepomuk::Search::Folder::addConnection( FolderConnection* conn )
00153 {
00154     Q_ASSERT( conn != 0 );
00155     Q_ASSERT( !m_connections.contains( conn ) );
00156 
00157     m_connections.append( conn );
00158 }
00159 
00160 
00161 void Nepomuk::Search::Folder::removeConnection( FolderConnection* conn )
00162 {
00163     Q_ASSERT( conn != 0 );
00164     Q_ASSERT( m_connections.contains( conn ) );
00165 
00166     m_connections.removeAll( conn );
00167 
00168     if ( m_connections.isEmpty() ) {
00169         kDebug() << "Folder unused. Deleting.";
00170         deleteLater();
00171     }
00172 }
00173 
00174 
00175 QList<Nepomuk::Search::FolderConnection*> Nepomuk::Search::Folder::openConnections() const
00176 {
00177     return m_connections;
00178 }
00179 
00180 #include "folder.moc"

NepomukDaemons

Skip menu "NepomukDaemons"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal