Sebastian.
It turns out that you can't add seconds to a QTime which is recording the
time (via start/restart). :-( So, I landed up using the method you
suggested. I even fixed the bug you mentioned. I'm not sure whether we
should provide a notification for suspension, and even if we should I don't
think the Nepomuk::EventWatcher is the correct place. The current approach
would only provide notifications during the initial run.
However, I've provided both the versions. So, take your pick!

Does anyone think that a Notification should be shown when the indexing is
paused/resumed?

I've tested the patch, and it works perfectly. The previous version had 2
bugs - The QTime::addMsec syntax was wrong (It doesn't add them to the
current object, but returns a new QTime instance), and the one mentioned
above.

Please commit it, if you feel it's okay!

Thanks

- Vishesh Handa
Index: eventmonitor.h
===================================================================
--- eventmonitor.h	(revision 1116179)
+++ eventmonitor.h	(working copy)
@@ -42,12 +42,16 @@
         void slotPowerManagementStatusChanged( bool conserveResources );
         void slotCheckAvailableSpace();
         void slotIndexingStopped();
+        void pauseIndexing(int pauseState);
+        void resumeIndexing();
+        void slotIndexingSuspended( bool suspended );
 
     private:
         enum {
             NotPaused,
             PausedDueToPowerManagement,
-            PausedDueToAvailSpace
+            PausedDueToAvailSpace,
+            PausedCustom
         };
 
         IndexScheduler* m_indexScheduler;
@@ -57,6 +61,7 @@
         QTimer m_availSpaceTimer;
 
         QTime m_initialIndexTime;
+        QTime m_indexTime;
     };
 }
 
Index: eventmonitor.cpp
===================================================================
--- eventmonitor.cpp	(revision 1116179)
+++ eventmonitor.cpp	(working copy)
@@ -57,7 +57,7 @@
     if ( StrigiServiceConfig::self()->isInitialRun() ) {
         // TODO: add actions to this notification
 
-        m_initialIndexTime.start();
+        m_indexTime.start();
 
         // inform the user about the initial indexing
         sendEvent( "initialIndexingStarted",
@@ -70,6 +70,9 @@
         connect( m_indexScheduler, SIGNAL( indexingStopped() ),
                  this, SLOT( slotIndexingStopped() ),
                  Qt::QueuedConnection );
+                 
+        connect( m_indexScheduler, SIGNAL( indexingSuspended(bool) ),
+                 this, SLOT( slotIndexingSuspended(bool) ) );
     }
 
     slotPowerManagementStatusChanged( Solid::PowerManagement::appShouldConserveResources() );
@@ -85,16 +88,14 @@
 {
     if ( !conserveResources && m_pauseState == PausedDueToPowerManagement ) {
         kDebug() << "Resuming indexer due to power management";
-        m_pauseState = NotPaused;
-        m_indexScheduler->resume();
+        resumeIndexing();
         sendEvent( "indexingResumed", i18n("Resuming indexing of files for fast searching."), "battery-charging" );
     }
     else if ( conserveResources &&
               m_indexScheduler->isRunning() &&
               !m_indexScheduler->isSuspended() ) {
         kDebug() << "Pausing indexer due to power management";
-        m_pauseState = PausedDueToPowerManagement;
-        m_indexScheduler->suspend();
+        pauseIndexing( PausedDueToPowerManagement );
         sendEvent( "indexingSuspended", i18n("Suspending the indexing of files to preserve resources."), "battery-100" );
     }
 }
@@ -107,8 +108,7 @@
         if ( info.available() <= StrigiServiceConfig::self()->minDiskSpace() ) {
             if ( m_indexScheduler->isRunning() &&
                 !m_indexScheduler->isSuspended() ) {
-                m_pauseState = PausedDueToAvailSpace;
-                m_indexScheduler->suspend();
+                pauseIndexing( PausedDueToAvailSpace );
                 sendEvent( "indexingSuspended",
                            i18n("Disk space is running low (%1 left). Suspending indexing of files.",
                                 KIO::convertSize( info.available() ) ),
@@ -117,8 +117,7 @@
         }
         else if ( m_pauseState == PausedDueToAvailSpace ) {
             kDebug() << "Resuming indexer due to disk space";
-            m_pauseState = NotPaused;
-            m_indexScheduler->resume();
+            resumeIndexing();
             sendEvent( "indexingResumed", i18n("Resuming indexing of files for fast searching."), "drive-harddisk" );
         }
     }
@@ -133,14 +132,51 @@
 {
     // inform the user about the end of initial indexing. This will only be called once
     if ( !m_indexScheduler->isSuspended() ) {
-        kDebug() << "initial indexing took" << m_initialIndexTime.elapsed();
+        m_initialIndexTime = m_initialIndexTime.addMSecs( m_indexTime.elapsed() );
+        const QTime & t = m_initialIndexTime;
+        const int elapsed = t.hour()*60*60*1000 + t.minute()*60*1000 + t.second()*1000 + t.msec();
+        
+        kDebug() << "initial indexing took" << elapsed;
         sendEvent( "initialIndexingFinished",
                    i18nc( "@info %1 is a duration formatted using KLocale::prettyFormatDuration",
                           "Initial indexing of files for fast searching finished in %1",
-                          KGlobal::locale()->prettyFormatDuration( m_initialIndexTime.elapsed() ) ),
+                          KGlobal::locale()->prettyFormatDuration( elapsed ) ),
                    "nepomuk" );
         m_indexScheduler->disconnect( this );
     }
 }
 
+
+void Nepomuk::EventMonitor::pauseIndexing(int pauseState)
+{
+    m_pauseState = pauseState;
+    m_indexScheduler->suspend();
+
+    m_initialIndexTime = m_initialIndexTime.addMSecs( m_indexTime.elapsed() );
+}
+
+
+void Nepomuk::EventMonitor::resumeIndexing()
+{
+    m_pauseState = NotPaused;
+    m_indexScheduler->resume();
+
+    m_indexTime.restart();
+}
+
+
+void Nepomuk::EventMonitor::slotIndexingSuspended( bool suspended )
+{
+    if( suspended ) {
+        //The indexing is already paused, this meerly sets the correct state, and adjusts the timing.
+        pauseIndexing( PausedCustom );
+        sendEvent( "indexingSuspended", i18n("Suspending indexing of files."), "nepomuk" );
+    }
+    else {
+        //Again, used to set the correct state, and adjust the timing.
+        resumeIndexing();
+        sendEvent( "indexingResumed", i18n("Resuming indexing of files for fast searching."), "nepomuk" );
+    }
+}
+
 #include "eventmonitor.moc"
Index: eventmonitor.h
===================================================================
--- eventmonitor.h	(revision 1116179)
+++ eventmonitor.h	(working copy)
@@ -42,12 +42,16 @@
         void slotPowerManagementStatusChanged( bool conserveResources );
         void slotCheckAvailableSpace();
         void slotIndexingStopped();
+        void pauseIndexing(int pauseState);
+        void resumeIndexing();
+        void slotIndexingSuspended( bool suspended );
 
     private:
         enum {
             NotPaused,
             PausedDueToPowerManagement,
-            PausedDueToAvailSpace
+            PausedDueToAvailSpace,
+            PausedCustom
         };
 
         IndexScheduler* m_indexScheduler;
@@ -57,6 +61,7 @@
         QTimer m_availSpaceTimer;
 
         QTime m_initialIndexTime;
+        QTime m_indexTime;
     };
 }
 
Index: eventmonitor.cpp
===================================================================
--- eventmonitor.cpp	(revision 1116179)
+++ eventmonitor.cpp	(working copy)
@@ -57,7 +57,7 @@
     if ( StrigiServiceConfig::self()->isInitialRun() ) {
         // TODO: add actions to this notification
 
-        m_initialIndexTime.start();
+        m_indexTime.start();
 
         // inform the user about the initial indexing
         sendEvent( "initialIndexingStarted",
@@ -70,6 +70,9 @@
         connect( m_indexScheduler, SIGNAL( indexingStopped() ),
                  this, SLOT( slotIndexingStopped() ),
                  Qt::QueuedConnection );
+                 
+        connect( m_indexScheduler, SIGNAL( indexingSuspended(bool) ),
+                 this, SLOT( slotIndexingSuspended(bool) ) );
     }
 
     slotPowerManagementStatusChanged( Solid::PowerManagement::appShouldConserveResources() );
@@ -85,16 +88,14 @@
 {
     if ( !conserveResources && m_pauseState == PausedDueToPowerManagement ) {
         kDebug() << "Resuming indexer due to power management";
-        m_pauseState = NotPaused;
-        m_indexScheduler->resume();
+        resumeIndexing();
         sendEvent( "indexingResumed", i18n("Resuming indexing of files for fast searching."), "battery-charging" );
     }
     else if ( conserveResources &&
               m_indexScheduler->isRunning() &&
               !m_indexScheduler->isSuspended() ) {
         kDebug() << "Pausing indexer due to power management";
-        m_pauseState = PausedDueToPowerManagement;
-        m_indexScheduler->suspend();
+        pauseIndexing( PausedDueToPowerManagement );
         sendEvent( "indexingSuspended", i18n("Suspending the indexing of files to preserve resources."), "battery-100" );
     }
 }
@@ -107,8 +108,7 @@
         if ( info.available() <= StrigiServiceConfig::self()->minDiskSpace() ) {
             if ( m_indexScheduler->isRunning() &&
                 !m_indexScheduler->isSuspended() ) {
-                m_pauseState = PausedDueToAvailSpace;
-                m_indexScheduler->suspend();
+                pauseIndexing( PausedDueToAvailSpace );
                 sendEvent( "indexingSuspended",
                            i18n("Disk space is running low (%1 left). Suspending indexing of files.",
                                 KIO::convertSize( info.available() ) ),
@@ -117,8 +117,7 @@
         }
         else if ( m_pauseState == PausedDueToAvailSpace ) {
             kDebug() << "Resuming indexer due to disk space";
-            m_pauseState = NotPaused;
-            m_indexScheduler->resume();
+            resumeIndexing();
             sendEvent( "indexingResumed", i18n("Resuming indexing of files for fast searching."), "drive-harddisk" );
         }
     }
@@ -133,14 +132,49 @@
 {
     // inform the user about the end of initial indexing. This will only be called once
     if ( !m_indexScheduler->isSuspended() ) {
-        kDebug() << "initial indexing took" << m_initialIndexTime.elapsed();
+        m_initialIndexTime = m_initialIndexTime.addMSecs( m_indexTime.elapsed() );
+        const QTime & t = m_initialIndexTime;
+        const int elapsed = t.hour()*60*60*1000 + t.minute()*60*1000 + t.second()*1000 + t.msec();
+        
+        kDebug() << "initial indexing took" << elapsed;
         sendEvent( "initialIndexingFinished",
                    i18nc( "@info %1 is a duration formatted using KLocale::prettyFormatDuration",
                           "Initial indexing of files for fast searching finished in %1",
-                          KGlobal::locale()->prettyFormatDuration( m_initialIndexTime.elapsed() ) ),
+                          KGlobal::locale()->prettyFormatDuration( elapsed ) ),
                    "nepomuk" );
         m_indexScheduler->disconnect( this );
     }
 }
 
+
+void Nepomuk::EventMonitor::pauseIndexing(int pauseState)
+{
+    m_pauseState = pauseState;
+    m_indexScheduler->suspend();
+
+    m_initialIndexTime = m_initialIndexTime.addMSecs( m_indexTime.elapsed() );
+}
+
+
+void Nepomuk::EventMonitor::resumeIndexing()
+{
+    m_pauseState = NotPaused;
+    m_indexScheduler->resume();
+
+    m_indexTime.restart();
+}
+
+
+void Nepomuk::EventMonitor::slotIndexingSuspended( bool suspended )
+{
+    if( suspended ) {
+        //The indexing is already paused, this meerly sets the correct state, and adjusts the timing.
+        pauseIndexing( PausedCustom );
+    }
+    else {
+        //Again, used to set the correct state, and adjust the timing.
+        resumeIndexing();
+    }
+}
+
 #include "eventmonitor.moc"
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk

Reply via email to