mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 18:35:37 +00:00
Merge remote-tracking branch 'origin/Applications/16.12'
This commit is contained in:
commit
ed4a9f42f4
|
@ -23,6 +23,16 @@ static const QUrl makeUrlFromCwd( const QString& u, const QString& ref = QString
|
|||
return url;
|
||||
}
|
||||
|
||||
static bool fileExist_always_Func( const QString& )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fileExist_never_Func( const QString& )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class ShellTest
|
||||
: public QObject
|
||||
{
|
||||
|
@ -42,28 +52,39 @@ void ShellTest::initTestCase()
|
|||
void ShellTest::testUrlArgs_data()
|
||||
{
|
||||
QTest::addColumn<QString>( "arg" );
|
||||
QTest::addColumn<bool>( "exists" );
|
||||
QTest::addColumn<QUrl>( "resUrl" );
|
||||
|
||||
// local files
|
||||
QTest::newRow( "foo.pdf, exist" )
|
||||
<< "foo.pdf"
|
||||
<< true
|
||||
<< makeUrlFromCwd( QStringLiteral("foo.pdf") );
|
||||
QTest::newRow( "foo.pdf, !exist" )
|
||||
<< "foo.pdf"
|
||||
<< false
|
||||
<< makeUrlFromCwd( QStringLiteral("foo.pdf") );
|
||||
QTest::newRow( "foo#bar.pdf, exist" )
|
||||
<< "foo#bar.pdf"
|
||||
<< true
|
||||
<< makeUrlFromCwd( QStringLiteral("foo#bar.pdf") );
|
||||
QTest::newRow( "foo#bar.pdf, !exist" )
|
||||
<< "foo#bar.pdf"
|
||||
<< makeUrlFromCwd( QStringLiteral("foo#bar.pdf") );
|
||||
<< false
|
||||
<< makeUrlFromCwd( QStringLiteral("foo"), QStringLiteral("bar.pdf") );
|
||||
QTest::newRow( "foo.pdf#anchor, !exist" )
|
||||
<< "foo.pdf#anchor"
|
||||
<< false
|
||||
<< makeUrlFromCwd( QStringLiteral("foo.pdf"), QStringLiteral("anchor") );
|
||||
QTest::newRow( "#207461" )
|
||||
<< "file:///tmp/file%20with%20spaces.pdf"
|
||||
<< true
|
||||
<< QUrl( QStringLiteral("file:///tmp/file%20with%20spaces.pdf") );
|
||||
|
||||
// non-local files
|
||||
QTest::newRow( "http://kde.org/foo.pdf" )
|
||||
<< "http://kde.org/foo.pdf"
|
||||
<< true
|
||||
<< QUrl( QStringLiteral("http://kde.org/foo.pdf") );
|
||||
// make sure we don't have a fragment
|
||||
QUrl hashInName( QStringLiteral("http://kde.org") );
|
||||
|
@ -72,28 +93,33 @@ void ShellTest::testUrlArgs_data()
|
|||
QVERIFY( hashInName.fragment().isEmpty() );
|
||||
QTest::newRow( "http://kde.org/foo#bar.pdf" )
|
||||
<< "http://kde.org/foo#bar.pdf"
|
||||
<< true
|
||||
<< hashInName;
|
||||
QUrl withAnchor( QStringLiteral("http://kde.org/foo.pdf") );
|
||||
withAnchor.setFragment( QStringLiteral("anchor") );
|
||||
QTest::newRow( "http://kde.org/foo.pdf#anchor" )
|
||||
<< "http://kde.org/foo.pdf#anchor"
|
||||
<< true
|
||||
<< withAnchor;
|
||||
QTest::newRow( "#207461" )
|
||||
<< "http://homepages.inf.ed.ac.uk/mef/file%20with%20spaces.pdf"
|
||||
<< true
|
||||
<< QUrl( QStringLiteral("http://homepages.inf.ed.ac.uk/mef/file%20with%20spaces.pdf") );
|
||||
QUrl openOnPage3 = QUrl( QStringLiteral("http://itzsimpl.info/lectures/CG/L2-transformations.pdf") );
|
||||
openOnPage3.setFragment( QStringLiteral("3") );
|
||||
QTest::newRow( "RR124738" )
|
||||
<< "http://itzsimpl.info/lectures/CG/L2-transformations.pdf#3"
|
||||
<< true
|
||||
<< openOnPage3;
|
||||
}
|
||||
|
||||
void ShellTest::testUrlArgs()
|
||||
{
|
||||
QFETCH( QString, arg );
|
||||
QFETCH( bool, exists );
|
||||
QFETCH( QUrl, resUrl );
|
||||
qDebug() << "Expected url:" << resUrl << "path =" << resUrl.path() << "fragment =" << resUrl.fragment();
|
||||
QUrl url = ShellUtils::urlFromArg( arg );
|
||||
QUrl url = ShellUtils::urlFromArg( arg, exists ? fileExist_always_Func : fileExist_never_Func );
|
||||
QCOMPARE( url, resUrl );
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,7 @@
|
|||
#include <QtGui/QImage>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtPrintSupport/QPrinter>
|
||||
#if QT_VERSION >= 0x040500
|
||||
#include <QtGui/QTextDocumentWriter>
|
||||
#endif
|
||||
|
||||
#include "action.h"
|
||||
#include "annotations.h"
|
||||
|
@ -476,14 +474,12 @@ Okular::ExportFormat::List TextDocumentGenerator::exportFormats( ) const
|
|||
if ( formats.isEmpty() ) {
|
||||
formats.append( Okular::ExportFormat::standardFormat( Okular::ExportFormat::PlainText ) );
|
||||
formats.append( Okular::ExportFormat::standardFormat( Okular::ExportFormat::PDF ) );
|
||||
#if QT_VERSION >= 0x040500
|
||||
if ( QTextDocumentWriter::supportedDocumentFormats().contains( "ODF" ) ) {
|
||||
formats.append( Okular::ExportFormat::standardFormat( Okular::ExportFormat::OpenDocumentText ) );
|
||||
}
|
||||
if ( QTextDocumentWriter::supportedDocumentFormats().contains( "HTML" ) ) {
|
||||
formats.append( Okular::ExportFormat::standardFormat( Okular::ExportFormat::HTML ) );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return formats;
|
||||
|
@ -515,7 +511,6 @@ bool TextDocumentGenerator::exportTo( const QString &fileName, const Okular::Exp
|
|||
out << d->mDocument->toPlainText();
|
||||
|
||||
return true;
|
||||
#if QT_VERSION >= 0x040500
|
||||
} else if ( format.mimeType().name() == QLatin1String( "application/vnd.oasis.opendocument.text" ) ) {
|
||||
QTextDocumentWriter odfWriter( fileName, "odf" );
|
||||
|
||||
|
@ -524,7 +519,6 @@ bool TextDocumentGenerator::exportTo( const QString &fileName, const Okular::Exp
|
|||
QTextDocumentWriter odfWriter( fileName, "html" );
|
||||
|
||||
return odfWriter.write( d->mDocument );
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -79,17 +79,7 @@ bool KIMGIOGenerator::loadDocumentInternal(const QByteArray & fileData, const QS
|
|||
// Apply transformations dictated by Exif metadata
|
||||
KExiv2Iface::KExiv2 exifMetadata;
|
||||
if ( exifMetadata.loadFromData( fileData ) ) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && QT_VERSION < QT_VERSION_CHECK(5, 4, 2)
|
||||
// Qt 5.4 (up to 5.4.1) rotates jpeg images automatically with no way of disabling it
|
||||
// See https://bugreports.qt.io/browse/QTBUG-37946
|
||||
// and https://codereview.qt-project.org/#/c/98013/
|
||||
// and https://codereview.qt-project.org/#/c/110668/
|
||||
if (reader.format() != QByteArrayLiteral("jpeg")) {
|
||||
exifMetadata.rotateExifQImage( m_img, exifMetadata.getImageOrientation() );
|
||||
}
|
||||
#else
|
||||
exifMetadata.rotateExifQImage(m_img, exifMetadata.getImageOrientation());
|
||||
#endif
|
||||
}
|
||||
|
||||
pagesVector.resize( 1 );
|
||||
|
|
|
@ -2066,10 +2066,8 @@ XpsGenerator::XpsGenerator( QObject *parent, const QVariantList &args )
|
|||
// 1) QFontDatabase says so
|
||||
// 2) Qt >= 4.4.0 (see Trolltech task ID: 169502)
|
||||
// 3) Qt >= 4.4.2 (see Trolltech task ID: 215090)
|
||||
#if QT_VERSION >= 0x040402
|
||||
if ( QFontDatabase::supportsThreadedFontRendering() )
|
||||
setFeature( Threaded );
|
||||
#endif
|
||||
userMutex();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ static bool attachUniqueInstance(const QStringList &paths, const QString &serial
|
|||
return false;
|
||||
|
||||
const QString page = ShellUtils::page(serializedOptions);
|
||||
iface.call(QStringLiteral("openDocument"), ShellUtils::urlFromArg(paths[0], page).url(), serializedOptions);
|
||||
iface.call(QStringLiteral("openDocument"), ShellUtils::urlFromArg(paths[0], ShellUtils::qfileExistFunc(), page).url(), serializedOptions);
|
||||
if (!ShellUtils::noRaise(serializedOptions)) {
|
||||
iface.call(QStringLiteral("tryRaise"));
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ static bool attachExistingInstance(const QStringList &paths, const QString &seri
|
|||
{
|
||||
// Page only makes sense if we are opening one file
|
||||
const QString page = ShellUtils::page(serializedOptions);
|
||||
path = ShellUtils::urlFromArg(arg, page).url();
|
||||
path = ShellUtils::urlFromArg(arg, ShellUtils::qfileExistFunc(), page).url();
|
||||
}
|
||||
|
||||
// Returns false if it can't fit another document
|
||||
|
@ -166,7 +166,7 @@ Status main(const QStringList &paths, const QString &serializedOptions)
|
|||
{
|
||||
// Page only makes sense if we are opening one file
|
||||
const QString page = ShellUtils::page(serializedOptions);
|
||||
const QUrl url = ShellUtils::urlFromArg(paths[i], page);
|
||||
const QUrl url = ShellUtils::urlFromArg(paths[i], ShellUtils::qfileExistFunc(), page);
|
||||
if ( shell->openDocument( url, serializedOptions) )
|
||||
{
|
||||
++i;
|
||||
|
|
|
@ -20,31 +20,32 @@
|
|||
namespace ShellUtils
|
||||
{
|
||||
|
||||
QUrl urlFromArg( const QString& _arg, const QString& pageArg )
|
||||
namespace detail
|
||||
{
|
||||
|
||||
bool qfileExistFunc( const QString& fileName )
|
||||
{
|
||||
return QFile::exists( fileName );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FileExistFunc qfileExistFunc()
|
||||
{
|
||||
return detail::qfileExistFunc;
|
||||
}
|
||||
|
||||
QUrl urlFromArg( const QString& _arg, FileExistFunc exist_func, const QString& pageArg )
|
||||
{
|
||||
#if QT_VERSION >= 0x050400
|
||||
QUrl url = QUrl::fromUserInput(_arg, QDir::currentPath(), QUrl::AssumeLocalFile);
|
||||
#else
|
||||
// Code from QUrl::fromUserInput(QString, QString)
|
||||
QUrl url = QUrl::fromUserInput(_arg);
|
||||
QUrl testUrl = QUrl(_arg, QUrl::TolerantMode);
|
||||
if (testUrl.isRelative() && !QDir::isAbsolutePath(_arg)) {
|
||||
QFileInfo fileInfo(QDir::current(), _arg);
|
||||
if (fileInfo.exists())
|
||||
url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
|
||||
}
|
||||
#endif
|
||||
if ( url.isLocalFile() ) {
|
||||
// make sure something like /tmp/foo#bar.pdf is treated as a path name (default)
|
||||
// but something like /tmp/foo.pdf#bar is foo.pdf plus an anchor "bar"
|
||||
const QString path = url.path();
|
||||
int hashIndex = path.lastIndexOf( QLatin1Char ( '#' ) );
|
||||
int lastDotIndex = path.lastIndexOf( QLatin1Char ( '.' ) );
|
||||
// make sure that we don't change the path if .pdf comes after the #
|
||||
if ( hashIndex != -1 && hashIndex > lastDotIndex) {
|
||||
if ( hashIndex != -1 && !exist_func(path) ) {
|
||||
url.setPath( path.left( hashIndex ) );
|
||||
url.setFragment( path.mid( hashIndex + 1 ) );
|
||||
qDebug() << "Added fragment to url:" << url.path() << url.fragment();
|
||||
}
|
||||
} else if ( !url.fragment().isEmpty() ) {
|
||||
// make sure something like http://example.org/foo#bar.pdf is treated as a path name
|
||||
|
|
|
@ -19,7 +19,10 @@ class QCommandLineParser;
|
|||
namespace ShellUtils
|
||||
{
|
||||
|
||||
QUrl urlFromArg(const QString& _arg, const QString& pageArg = QString() );
|
||||
typedef bool (*FileExistFunc)( const QString& fileName );
|
||||
|
||||
FileExistFunc qfileExistFunc();
|
||||
QUrl urlFromArg(const QString& _arg, FileExistFunc exist_func, const QString& pageArg = QString() );
|
||||
QString serializeOptions(const QCommandLineParser &args);
|
||||
QString serializeOptions(bool startInPresentation, bool showPrintDialog, bool unique, bool noRaise, const QString &page);
|
||||
bool unserializeOptions(const QString &serializedOptions, bool *presentation, bool *print, bool *unique, bool *noraise, QString *page);
|
||||
|
|
Loading…
Reference in a new issue