summaryrefslogtreecommitdiffstats
path: root/kmrml/kmrml/kcontrol/indexcleaner.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kmrml/kmrml/kcontrol/indexcleaner.cpp
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmrml/kmrml/kcontrol/indexcleaner.cpp')
-rw-r--r--kmrml/kmrml/kcontrol/indexcleaner.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/kmrml/kmrml/kcontrol/indexcleaner.cpp b/kmrml/kmrml/kcontrol/indexcleaner.cpp
new file mode 100644
index 00000000..5f5eea93
--- /dev/null
+++ b/kmrml/kmrml/kcontrol/indexcleaner.cpp
@@ -0,0 +1,96 @@
+#include <kdebug.h>
+#include <kprocess.h>
+
+#include <kmrml_config.h>
+#include "indexcleaner.h"
+
+#include <kdeversion.h>
+#if KDE_VERSION < 306
+ #define QUOTE( x ) x
+#else
+ #define QUOTE( x ) KProcess::quote( x )
+#endif
+
+using namespace KMrmlConfig;
+
+IndexCleaner::IndexCleaner( const QStringList& dirs,
+ const KMrml::Config *config,
+ QObject *parent, const char *name )
+ : QObject( parent, name ),
+ m_dirs( dirs ),
+ m_config( config ),
+ m_process( 0L )
+{
+ m_stepSize = 100 / dirs.count();
+}
+
+IndexCleaner::~IndexCleaner()
+{
+ if ( m_process )
+ {
+ m_process->kill();
+ delete m_process;
+ m_process = 0L;
+ }
+}
+
+void IndexCleaner::start()
+{
+ startNext();
+}
+
+void IndexCleaner::slotExited( KProcess *proc )
+{
+ emit advance( m_stepSize );
+
+ if ( !proc->normalExit() )
+ kdWarning() << "Error removing old indexed directory" << endl;
+
+ m_process = 0L;
+
+ startNext();
+}
+
+void IndexCleaner::startNext()
+{
+ if ( m_dirs.isEmpty() )
+ {
+ emit advance( 100 );
+ emit finished();
+ return;
+ }
+
+#if KDE_VERSION < 306
+ m_process = new KShellProcess();
+#else
+ m_process = new KProcess();
+ m_process->setUseShell( true );
+#endif
+ connect( m_process, SIGNAL( processExited( KProcess * )),
+ SLOT( slotExited( KProcess * ) ));
+
+ QString cmd = m_config->removeCollectionCommandLine();
+
+ QString dir = m_dirs.first();
+ m_dirs.pop_front();
+
+ int index = cmd.find( "%d" );
+ if ( index != -1 )
+ cmd.replace( index, 2, QUOTE( dir ) );
+ else // no %d? What else can we do?
+ cmd.append( QString::fromLatin1(" ") + QUOTE( dir ) );
+
+ *m_process << cmd;
+
+ if ( !m_process->start() )
+ {
+ kdWarning() << "Error starting: " << cmd << endl;
+
+ delete m_process;
+ m_process = 0L;
+
+ startNext();
+ }
+}
+
+#include "indexcleaner.moc"