Remove dead and unused code after porting to Qt5 QUrl

frameworks
Martin T. H. Sandsmark 10 years ago
parent ab2fe5f178
commit ba1aeef06f
  1. 24
      autotests/shelltest.cpp
  2. 6
      shell/okular_main.cpp
  3. 18
      shell/shellutils.cpp
  4. 5
      shell/shellutils.h

@ -23,16 +23,6 @@ static const QUrl makeUrlFromCwd( const QString& u, const QString& ref = QString
return url; return url;
} }
static bool fileExist_always_Func( const QString& )
{
return true;
}
static bool fileExist_never_Func( const QString& )
{
return false;
}
class ShellTest class ShellTest
: public QObject : public QObject
{ {
@ -52,35 +42,28 @@ void ShellTest::initTestCase()
void ShellTest::testUrlArgs_data() void ShellTest::testUrlArgs_data()
{ {
QTest::addColumn<QString>( "arg" ); QTest::addColumn<QString>( "arg" );
QTest::addColumn<bool>( "exists" );
QTest::addColumn<QUrl>( "resUrl" ); QTest::addColumn<QUrl>( "resUrl" );
// local files // local files
QTest::newRow( "foo.pdf, exist" ) QTest::newRow( "foo.pdf, exist" )
<< "foo.pdf" << "foo.pdf"
<< true
<< makeUrlFromCwd( QStringLiteral("foo.pdf") ); << makeUrlFromCwd( QStringLiteral("foo.pdf") );
QTest::newRow( "foo.pdf, !exist" ) QTest::newRow( "foo.pdf, !exist" )
<< "foo.pdf" << "foo.pdf"
<< false
<< makeUrlFromCwd( QStringLiteral("foo.pdf") ); << makeUrlFromCwd( QStringLiteral("foo.pdf") );
QTest::newRow( "foo#bar.pdf, !exist" ) QTest::newRow( "foo#bar.pdf, !exist" )
<< "foo#bar.pdf" << "foo#bar.pdf"
<< false
<< makeUrlFromCwd( QStringLiteral("foo#bar.pdf") ); << makeUrlFromCwd( QStringLiteral("foo#bar.pdf") );
QTest::newRow( "foo.pdf#anchor, !exist" ) QTest::newRow( "foo.pdf#anchor, !exist" )
<< "foo.pdf#anchor" << "foo.pdf#anchor"
<< false
<< makeUrlFromCwd( QStringLiteral("foo.pdf"), QStringLiteral("anchor") ); << makeUrlFromCwd( QStringLiteral("foo.pdf"), QStringLiteral("anchor") );
QTest::newRow( "#207461" ) QTest::newRow( "#207461" )
<< "file:///tmp/file%20with%20spaces.pdf" << "file:///tmp/file%20with%20spaces.pdf"
<< true
<< QUrl( QStringLiteral("file:///tmp/file%20with%20spaces.pdf") ); << QUrl( QStringLiteral("file:///tmp/file%20with%20spaces.pdf") );
// non-local files // non-local files
QTest::newRow( "http://kde.org/foo.pdf" ) QTest::newRow( "http://kde.org/foo.pdf" )
<< "http://kde.org/foo.pdf" << "http://kde.org/foo.pdf"
<< true
<< QUrl( QStringLiteral("http://kde.org/foo.pdf") ); << QUrl( QStringLiteral("http://kde.org/foo.pdf") );
// make sure we don't have a fragment // make sure we don't have a fragment
QUrl hashInName( QStringLiteral("http://kde.org") ); QUrl hashInName( QStringLiteral("http://kde.org") );
@ -89,33 +72,28 @@ void ShellTest::testUrlArgs_data()
QVERIFY( hashInName.fragment().isEmpty() ); QVERIFY( hashInName.fragment().isEmpty() );
QTest::newRow( "http://kde.org/foo#bar.pdf" ) QTest::newRow( "http://kde.org/foo#bar.pdf" )
<< "http://kde.org/foo#bar.pdf" << "http://kde.org/foo#bar.pdf"
<< true
<< hashInName; << hashInName;
QUrl withAnchor( QStringLiteral("http://kde.org/foo.pdf") ); QUrl withAnchor( QStringLiteral("http://kde.org/foo.pdf") );
withAnchor.setFragment( QStringLiteral("anchor") ); withAnchor.setFragment( QStringLiteral("anchor") );
QTest::newRow( "http://kde.org/foo.pdf#anchor" ) QTest::newRow( "http://kde.org/foo.pdf#anchor" )
<< "http://kde.org/foo.pdf#anchor" << "http://kde.org/foo.pdf#anchor"
<< true
<< withAnchor; << withAnchor;
QTest::newRow( "#207461" ) QTest::newRow( "#207461" )
<< "http://homepages.inf.ed.ac.uk/mef/file%20with%20spaces.pdf" << "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( QStringLiteral("http://homepages.inf.ed.ac.uk/mef/file%20with%20spaces.pdf") );
QUrl openOnPage3 = QUrl( QStringLiteral("http://itzsimpl.info/lectures/CG/L2-transformations.pdf") ); QUrl openOnPage3 = QUrl( QStringLiteral("http://itzsimpl.info/lectures/CG/L2-transformations.pdf") );
openOnPage3.setFragment( QStringLiteral("3") ); openOnPage3.setFragment( QStringLiteral("3") );
QTest::newRow( "RR124738" ) QTest::newRow( "RR124738" )
<< "http://itzsimpl.info/lectures/CG/L2-transformations.pdf#3" << "http://itzsimpl.info/lectures/CG/L2-transformations.pdf#3"
<< true
<< openOnPage3; << openOnPage3;
} }
void ShellTest::testUrlArgs() void ShellTest::testUrlArgs()
{ {
QFETCH( QString, arg ); QFETCH( QString, arg );
QFETCH( bool, exists );
QFETCH( QUrl, resUrl ); QFETCH( QUrl, resUrl );
qDebug() << "Expected url:" << resUrl << "path =" << resUrl.path() << "fragment =" << resUrl.fragment(); qDebug() << "Expected url:" << resUrl << "path =" << resUrl.path() << "fragment =" << resUrl.fragment();
QUrl url = ShellUtils::urlFromArg( arg, exists ? fileExist_always_Func : fileExist_never_Func ); QUrl url = ShellUtils::urlFromArg( arg );
QCOMPARE( url, resUrl ); QCOMPARE( url, resUrl );
} }

@ -33,7 +33,7 @@ static bool attachUniqueInstance(const QStringList &paths, const QString &serial
return false; return false;
const QString page = ShellUtils::page(serializedOptions); const QString page = ShellUtils::page(serializedOptions);
iface.call(QStringLiteral("openDocument"), ShellUtils::urlFromArg(paths[0], ShellUtils::qfileExistFunc(), page).url(), serializedOptions); iface.call(QStringLiteral("openDocument"), ShellUtils::urlFromArg(paths[0], page).url(), serializedOptions);
if (!ShellUtils::noRaise(serializedOptions)) { if (!ShellUtils::noRaise(serializedOptions)) {
iface.call(QStringLiteral("tryRaise")); 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 // Page only makes sense if we are opening one file
const QString page = ShellUtils::page(serializedOptions); const QString page = ShellUtils::page(serializedOptions);
path = ShellUtils::urlFromArg(arg, ShellUtils::qfileExistFunc(), page).url(); path = ShellUtils::urlFromArg(arg, page).url();
} }
// Returns false if it can't fit another document // 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 // Page only makes sense if we are opening one file
const QString page = ShellUtils::page(serializedOptions); const QString page = ShellUtils::page(serializedOptions);
const QUrl url = ShellUtils::urlFromArg(paths[i], ShellUtils::qfileExistFunc(), page); const QUrl url = ShellUtils::urlFromArg(paths[i], page);
if ( shell->openDocument( url, serializedOptions) ) if ( shell->openDocument( url, serializedOptions) )
{ {
++i; ++i;

@ -20,24 +20,8 @@
namespace ShellUtils namespace ShellUtils
{ {
namespace detail QUrl urlFromArg( const QString& _arg, const QString& pageArg )
{ {
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 )
{
// ## TODO remove exist_func
#if QT_VERSION >= 0x050400 #if QT_VERSION >= 0x050400
QUrl url = QUrl::fromUserInput(_arg, QDir::currentPath(), QUrl::AssumeLocalFile); QUrl url = QUrl::fromUserInput(_arg, QDir::currentPath(), QUrl::AssumeLocalFile);
#else #else

@ -19,10 +19,7 @@ class QCommandLineParser;
namespace ShellUtils namespace ShellUtils
{ {
typedef bool (*FileExistFunc)( const QString& fileName ); QUrl urlFromArg(const QString& _arg, const QString& pageArg = QString() );
FileExistFunc qfileExistFunc();
QUrl urlFromArg( const QString& _arg, FileExistFunc exist_func, const QString& pageArg = QString() );
QString serializeOptions(const QCommandLineParser &args); QString serializeOptions(const QCommandLineParser &args);
QString serializeOptions(bool startInPresentation, bool showPrintDialog, bool unique, bool noRaise, const QString &page); 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); bool unserializeOptions(const QString &serializedOptions, bool *presentation, bool *print, bool *unique, bool *noraise, QString *page);

Loading…
Cancel
Save