From 612d40aad9cc5b35ab2c77bfe41648484eebc3da Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 19 May 2008 20:04:27 +0000 Subject: [PATCH] slightly improve the unrar detection: - move in an own function the procedure to recognize an output - try to detect first unrar-nonfree, then unrar - keep and print on console the path of the found unrary svn path=/trunk/KDE/kdegraphics/okular/; revision=809968 --- generators/comicbook/unrar.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/generators/comicbook/unrar.cpp b/generators/comicbook/unrar.cpp index 1288f0b8c..c5c7635a7 100644 --- a/generators/comicbook/unrar.cpp +++ b/generators/comicbook/unrar.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include "unrarflavours.h" @@ -25,15 +26,16 @@ struct UnrarHelper ~UnrarHelper(); UnrarFlavour *kind; + QString unrarPath; }; K_GLOBAL_STATIC( UnrarHelper, helper ) -UnrarHelper::UnrarHelper() - : kind( 0 ) +static UnrarFlavour* detectUnrar( const QString &unrarPath ) { + UnrarFlavour* kind = 0; QProcess proc; - proc.start( "unrar", QStringList() << "--version" ); + proc.start( unrarPath, QStringList() << "--version" ); bool ok = proc.waitForFinished( -1 ); Q_UNUSED( ok ) const QStringList lines = QString::fromLocal8Bit( proc.readAllStandardOutput() ).split( "\n", QString::SkipEmptyParts ); @@ -44,6 +46,18 @@ UnrarHelper::UnrarHelper() else if ( lines.first().startsWith( "unrar " ) ) kind = new FreeUnrarFlavour(); } + return kind; +} + +UnrarHelper::UnrarHelper() + : kind( 0 ) +{ + QString path = KStandardDirs::findExe( "unrar-nonfree" ); + if ( path.isEmpty() ) + path = KStandardDirs::findExe( "unrar" ); + + if ( !path.isEmpty() ) + kind = detectUnrar( path ); if ( !kind ) { @@ -52,7 +66,8 @@ UnrarHelper::UnrarHelper() } else { - kDebug() << "detected:" << kind->name(); + unrarPath = path; + kDebug() << "detected:" << path << "(" << kind->name() << ")"; } }