mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-27 03:30:20 +00:00
Make it possible to open URLs on the command-line again
by removing much cruft and using the shiny new QUrl::fromUserInput(2 args), but since that requires Qt 5.4, also include a copy here if Qt is too "old". Reviewed-By: Albert Makes-Happy: Lukas
This commit is contained in:
parent
e28dbc6c00
commit
d98b4d9200
|
@ -12,7 +12,9 @@
|
||||||
// qt/kde includes
|
// qt/kde includes
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QRegExp>
|
#include <QFileInfo>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
#include <QtCore/qcommandlineparser.h>
|
#include <QtCore/qcommandlineparser.h>
|
||||||
|
|
||||||
namespace ShellUtils
|
namespace ShellUtils
|
||||||
|
@ -35,30 +37,21 @@ FileExistFunc qfileExistFunc()
|
||||||
|
|
||||||
QUrl urlFromArg( const QString& _arg, FileExistFunc exist_func, const QString& pageArg )
|
QUrl urlFromArg( const QString& _arg, FileExistFunc exist_func, const QString& pageArg )
|
||||||
{
|
{
|
||||||
/*
|
// ## TODO remove exist_func
|
||||||
Rationale for the small "cut-and-paste" work being done below:
|
#if QT_VERSION >= 0x050400
|
||||||
KCmdLineArgs::makeURL() (used by ::url() encodes any # into the URL itself,
|
QUrl url = QUrl::fromUserInput(_arg, QDir::currentPath());
|
||||||
so we have to find it manually and build up the URL by taking its ref,
|
#else
|
||||||
if any.
|
// Code from QUrl::fromUserInput(QString, QString)
|
||||||
*/
|
QUrl url = QUrl::fromUserInput(_arg);
|
||||||
QString arg = _arg;
|
QUrl testUrl = QUrl(_arg, QUrl::TolerantMode);
|
||||||
arg.replace( QRegExp( "^file:/{1,3}"), "/" );
|
if (testUrl.isRelative() && !QDir::isAbsolutePath(_arg)) {
|
||||||
if ( arg != _arg )
|
QFileInfo fileInfo(QDir::current(), _arg);
|
||||||
{
|
if (fileInfo.exists())
|
||||||
arg = QString::fromUtf8( QByteArray::fromPercentEncoding( arg.toUtf8() ) );
|
url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
|
||||||
}
|
}
|
||||||
QUrl url = QUrl::fromUserInput( arg.toUtf8() );
|
|
||||||
int sharpPos = -1;
|
#endif
|
||||||
if ( !url.isLocalFile() || !exist_func( url.toLocalFile() ) )
|
if ( !pageArg.isEmpty() )
|
||||||
{
|
|
||||||
sharpPos = arg.lastIndexOf( QLatin1Char( '#' ) );
|
|
||||||
}
|
|
||||||
if ( sharpPos != -1 )
|
|
||||||
{
|
|
||||||
url = QUrl::fromUserInput( arg.left( sharpPos ).toUtf8() );
|
|
||||||
url.setFragment( arg.mid( sharpPos + 1 ) );
|
|
||||||
}
|
|
||||||
else if ( !pageArg.isEmpty() )
|
|
||||||
{
|
{
|
||||||
url.setFragment( pageArg );
|
url.setFragment( pageArg );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue