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
remotes/origin/KDE/4.1
Pino Toscano 18 years ago
parent 169df555d5
commit 612d40aad9
  1. 23
      generators/comicbook/unrar.cpp

@ -15,6 +15,7 @@
#include <kdebug.h> #include <kdebug.h>
#include <kglobal.h> #include <kglobal.h>
#include <kstandarddirs.h>
#include <ktempdir.h> #include <ktempdir.h>
#include "unrarflavours.h" #include "unrarflavours.h"
@ -25,15 +26,16 @@ struct UnrarHelper
~UnrarHelper(); ~UnrarHelper();
UnrarFlavour *kind; UnrarFlavour *kind;
QString unrarPath;
}; };
K_GLOBAL_STATIC( UnrarHelper, helper ) K_GLOBAL_STATIC( UnrarHelper, helper )
UnrarHelper::UnrarHelper() static UnrarFlavour* detectUnrar( const QString &unrarPath )
: kind( 0 )
{ {
UnrarFlavour* kind = 0;
QProcess proc; QProcess proc;
proc.start( "unrar", QStringList() << "--version" ); proc.start( unrarPath, QStringList() << "--version" );
bool ok = proc.waitForFinished( -1 ); bool ok = proc.waitForFinished( -1 );
Q_UNUSED( ok ) Q_UNUSED( ok )
const QStringList lines = QString::fromLocal8Bit( proc.readAllStandardOutput() ).split( "\n", QString::SkipEmptyParts ); const QStringList lines = QString::fromLocal8Bit( proc.readAllStandardOutput() ).split( "\n", QString::SkipEmptyParts );
@ -44,6 +46,18 @@ UnrarHelper::UnrarHelper()
else if ( lines.first().startsWith( "unrar " ) ) else if ( lines.first().startsWith( "unrar " ) )
kind = new FreeUnrarFlavour(); 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 ) if ( !kind )
{ {
@ -52,7 +66,8 @@ UnrarHelper::UnrarHelper()
} }
else else
{ {
kDebug() << "detected:" << kind->name(); unrarPath = path;
kDebug() << "detected:" << path << "(" << kind->name() << ")";
} }
} }

Loading…
Cancel
Save