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

NepomukDaemons

statuswidget.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE Project
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 "statuswidget.h"
00020 #include "indexscheduler.h"
00021 
00022 #include <KCMultiDialog>
00023 #include <KIcon>
00024 #include <KLocale>
00025 #include <KTitleWidget>
00026 #include <KStandardDirs>
00027 #include <KIO/NetAccess>
00028 #include <kio/directorysizejob.h>
00029 
00030 #include <Soprano/Model>
00031 #include <Soprano/QueryResultIterator>
00032 #include <Soprano/Vocabulary/Xesam>
00033 
00034 #include <QtCore/QTimer>
00035 
00036 
00037 Nepomuk::StatusWidget::StatusWidget( Soprano::Model* model, IndexScheduler* scheduler, QWidget* parent )
00038     : KDialog( parent ),
00039       m_model( model ),
00040       m_indexScheduler( scheduler ),
00041       m_connected( false ),
00042       m_updating( false ),
00043       m_updateRequested( false )
00044 {
00045     setupUi( mainWidget() );
00046 
00047     setCaption( m_title->text() );
00048     setButtons( Ok|User1 );
00049     setDefaultButton( Ok );
00050     setButtonGuiItem( User1, KGuiItem( i18n( "Configure" ), KIcon( "configure" ) ) );
00051 
00052     m_title->setPixmap( KIcon( "nepomuk" ).pixmap( 32, 32 ) );
00053 
00054     m_updateTimer.setSingleShot( true );
00055     m_updateTimer.setInterval( 10*1000 ); // do not update multiple times in 10 seconds
00056     connect( &m_updateTimer, SIGNAL( timeout() ),
00057              this, SLOT( slotUpdateTimeout() ) );
00058 
00059     connect( this, SIGNAL( user1Clicked() ),
00060              this, SLOT( slotConfigure() ) );
00061 }
00062 
00063 
00064 Nepomuk::StatusWidget::~StatusWidget()
00065 {
00066 }
00067 
00068 
00069 void Nepomuk::StatusWidget::slotUpdateStrigiStatus()
00070 {
00071     bool indexing = m_indexScheduler->isIndexing();
00072     bool suspended = m_indexScheduler->isSuspended();
00073     QString folder = m_indexScheduler->currentFolder();
00074 
00075     if ( suspended )
00076         m_labelStrigiState->setText( i18n( "File indexer is suspended" ) );
00077     else if ( indexing )
00078         m_labelStrigiState->setText( i18n( "Strigi is currently indexing files in folder %1", folder ) );
00079     else
00080         m_labelStrigiState->setText( i18n( "File indexer is idle" ) );
00081 }
00082 
00083 
00084 void Nepomuk::StatusWidget::slotUpdateStoreStatus()
00085 {
00086     if ( !m_updating && !m_updateTimer.isActive() ) {
00087         m_updating = true;
00088 
00089         // update storage size
00090         // ========================================
00091         QString path = KStandardDirs::locateLocal( "data", "nepomuk/repository/main/", false );
00092         KIO::DirectorySizeJob* job = KIO::directorySize( path );
00093         if ( KIO::NetAccess::synchronousRun( job, this ) )
00094             m_labelStoreSize->setText( KIO::convertSize( job->totalSize() ) );
00095         else
00096             m_labelStoreSize->setText( i18n( "Calculation failed" ) );
00097 
00098 
00099         // update file count
00100         // ========================================
00101         Soprano::QueryResultIterator it = m_model->executeQuery( QString( "select distinct ?r where { ?r a <%1> . }" )
00102                                                                  .arg( Soprano::Vocabulary::Xesam::File().toString() ),
00103                                                                  Soprano::Query::QueryLanguageSparql );
00104         int cnt = 0;
00105         while ( it.next() ) {
00106             // a bit of hacking to keep the GUI responsive
00107             // TODO: if we don't get aggregate functions in SPARQL soon, use a thread
00108             if ( cnt % 100 == 0 )
00109                 QApplication::processEvents();
00110             ++cnt;
00111         }
00112         m_labelFileCount->setText( i18np( "1 file in index", "%1 files in index", cnt ) );
00113 
00114         m_updating = false;
00115 
00116         // start the timer to avoid too many updates
00117         m_updateTimer.start();
00118     }
00119     else {
00120         m_updateRequested = true;
00121     }
00122 }
00123 
00124 
00125 void Nepomuk::StatusWidget::slotUpdateTimeout()
00126 {
00127     if ( m_updateRequested ) {
00128         m_updateRequested = false;
00129         slotUpdateStoreStatus();
00130     }
00131 }
00132 
00133 
00134 void Nepomuk::StatusWidget::slotConfigure()
00135 {
00136     KCMultiDialog dlg;
00137     dlg.addModule( "kcm_nepomuk" );
00138     dlg.exec();
00139 }
00140 
00141 #include <QApplication>
00142 #include <QDesktopWidget>
00143 
00144 // from kdialog.cpp since KDialog::centerOnScreen will simply do nothing on X11!
00145 static QRect screenRect( QWidget *widget, int screen )
00146 {
00147     QDesktopWidget *desktop = QApplication::desktop();
00148     KConfig gc( "kdeglobals", KConfig::NoGlobals );
00149     KConfigGroup cg(&gc, "Windows" );
00150     if ( desktop->isVirtualDesktop() &&
00151          cg.readEntry( "XineramaEnabled", true ) &&
00152          cg.readEntry( "XineramaPlacementEnabled", true ) ) {
00153 
00154         if ( screen < 0 || screen >= desktop->numScreens() ) {
00155             if ( screen == -1 )
00156                 screen = desktop->primaryScreen();
00157             else if ( screen == -3 )
00158                 screen = desktop->screenNumber( QCursor::pos() );
00159             else
00160                 screen = desktop->screenNumber( widget );
00161         }
00162 
00163         return desktop->availableGeometry( screen );
00164     } else
00165         return desktop->geometry();
00166 }
00167 
00168 void Nepomuk::StatusWidget::showEvent( QShowEvent* event )
00169 {
00170     if ( !m_connected ) {
00171         connect( m_indexScheduler, SIGNAL( indexingStarted() ),
00172                  this, SLOT( slotUpdateStrigiStatus() ) );
00173         connect( m_indexScheduler, SIGNAL( indexingStopped() ),
00174                  this, SLOT( slotUpdateStrigiStatus() ) );
00175         connect( m_indexScheduler, SIGNAL( indexingFolder(QString) ),
00176                  this, SLOT( slotUpdateStrigiStatus() ) );
00177 
00178         connect( m_model, SIGNAL( statementsAdded() ),
00179                  this, SLOT( slotUpdateStoreStatus() ) );
00180         connect( m_model, SIGNAL( statementsRemoved() ),
00181                  this, SLOT( slotUpdateStoreStatus() ) );
00182 
00183         m_connected = true;
00184     }
00185 
00186     QTimer::singleShot( 0, this, SLOT( slotUpdateStoreStatus() ) );
00187     QTimer::singleShot( 0, this, SLOT( slotUpdateStrigiStatus() ) );
00188 
00189     KDialog::showEvent( event );
00190 
00191     QRect rect = screenRect( this, -1 );
00192     move( rect.center().x() - width() / 2,
00193           rect.center().y() - height() / 2 );
00194     //KDialog::centerOnScreen( this );
00195 }
00196 
00197 
00198 void Nepomuk::StatusWidget::hideEvent( QHideEvent* event )
00199 {
00200     if ( m_connected ) {
00201         m_indexScheduler->disconnect( this );
00202         m_model->disconnect( this );
00203         m_connected = false;
00204     }
00205 
00206     KDialog::hideEvent( event );
00207 }
00208 
00209 #include "statuswidget.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