From 50b48aec6ddd451a6d1709c0942477b503457663 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 3 Feb 2010 02:15:56 +0000 Subject: Added abandoned KDE3 version of K3B git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/k3b@1084400 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/k3blsofwrapper.cpp | 108 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/k3blsofwrapper.cpp (limited to 'src/k3blsofwrapper.cpp') diff --git a/src/k3blsofwrapper.cpp b/src/k3blsofwrapper.cpp new file mode 100644 index 0000000..56d5d5b --- /dev/null +++ b/src/k3blsofwrapper.cpp @@ -0,0 +1,108 @@ +/* + * + * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $ + * Copyright (C) 2006 Sebastian Trueg + * + * This file is part of the K3b project. + * Copyright (C) 1998-2007 Sebastian Trueg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * See the file "COPYING" for the exact licensing terms. + */ + +#include "k3blsofwrapper.h" + +#include +#include +#include + +#include +#include + +#include +#include + +static K3bLsofWrapper::Process createProcess( const QString& name, int pid ) +{ + K3bLsofWrapper::Process p; + p.name = name; + p.pid = pid; + return p; +} + + +class K3bLsofWrapper::Private +{ +public: + QValueList apps; + QString lsofBin; +}; + + +K3bLsofWrapper::K3bLsofWrapper() +{ + d = new Private; +} + + +K3bLsofWrapper::~K3bLsofWrapper() +{ + delete d; +} + + +bool K3bLsofWrapper::checkDevice( K3bDevice::Device* dev ) +{ + d->apps.clear(); + + if( !findLsofExecutable() ) + return false; + + // run lsof + KProcess p; + K3bProcessOutputCollector out( &p ); + + // + // We use the following output form: + // p + // c + // + p << d->lsofBin << "-Fpc" << dev->blockDeviceName(); + + if( !p.start( KProcess::Block, KProcess::Stdout ) ) + return false; + + // + // now process its output + QStringList l = QStringList::split( "\n", out.output() ); + for( QStringList::iterator it = l.begin(); it != l.end(); ++it ) { + int pid = (*it).mid(1).toInt(); + QString app = (*(++it)).mid(1); + + kdDebug() << "(K3bLsofWrapper) matched: app: " << app << " pid: " << pid << endl; + + // we don't care about ourselves using the device ;) + if( pid != (int)::getpid() ) + d->apps.append( createProcess( app, pid ) ); + } + + return true; +} + + +const QValueList& K3bLsofWrapper::usingApplications() const +{ + return d->apps; +} + + +bool K3bLsofWrapper::findLsofExecutable() +{ + if( d->lsofBin.isEmpty() ) + d->lsofBin = K3b::findExe( "lsof" ); + + return !d->lsofBin.isEmpty(); +} -- cgit v1.2.3