Fix mainshelltest (and as a side-effect docdata saving)

Try fixing mainshelltest: one more passes now

QUrl is not automatically exposed to DBus so the DBus call would fail.
Changed the parameter to QString instead so that DBus invocation works.

mainshelltest: set QStandardPaths to test mode

Parse command line flags with a single dash as a long option

Unlike KCmdLineArgs QCommandLineParser treats options starting with a
single minus as multiple short options by default.

Previously okular -unique would fail with the following error:
Unknown options: u, n, i, q, u, e.

Also changed mainshelltest to use two dashes in case this behaviour
should change in the future.

mainshelltest failures have been reduced from 15 to 4 by this commit.

Fix docdata saving and added a warning message if it fails

If the ~/.local/okular/docdata directory didn't exist previously
creating the docdata file would fail as there are missing paths.

It seems that KStandardDirs used to create the okular/docdata directory
automatically, with QStandardPaths we have to create it manually.

mainshelltest is down to one failed test now

Fix final test case in mainshelltest

as we call QProcess::terminate the exit code will not be 0

REVIEW: 126192
frameworks
Alex Richardson 10 years ago committed by Albert Astals Cid
parent 37d5623102
commit 1b2de0d1d0
  1. 5
      autotests/mainshelltest.cpp
  2. 37
      core/document.cpp
  3. 2
      shell/main.cpp
  4. 2
      shell/okular_main.cpp
  5. 4
      shell/shell.cpp
  6. 2
      shell/shell.h

@ -12,6 +12,7 @@
#include <qprintdialog.h> #include <qprintdialog.h>
#include <qwidget.h> #include <qwidget.h>
#include <qtabwidget.h> #include <qtabwidget.h>
#include <QStandardPaths>
#include <kconfiggroup.h> #include <kconfiggroup.h>
#include "../shell/okular_main.h" #include "../shell/okular_main.h"
@ -108,6 +109,7 @@ Shell *findShell(Shell *ignore = 0)
void MainShellTest::initTestCase() void MainShellTest::initTestCase()
{ {
QStandardPaths::setTestModeEnabled(true);
// Don't pollute people's okular settings // Don't pollute people's okular settings
Okular::Settings::instance( QStringLiteral("mainshelltest") ); Okular::Settings::instance( QStringLiteral("mainshelltest") );
@ -331,8 +333,7 @@ void MainShellTest::testShell()
QCOMPARE(p.state(), QProcess::Running); QCOMPARE(p.state(), QProcess::Running);
p.terminate(); p.terminate();
p.waitForFinished(); p.waitForFinished();
QCOMPARE(p.exitCode(), 0); QVERIFY(p.state() != QProcess::Running);
// It opened on a new process, so no change for us // It opened on a new process, so no change for us
QCOMPARE(s->m_tabs.count(), 1); QCOMPARE(s->m_tabs.count(), 1);
QCOMPARE(part->url().url(), QString("file://%1").arg(paths[0])); QCOMPARE(part->url().url(), QString("file://%1").arg(paths[0]));

@ -55,6 +55,7 @@
#include <KFormat> #include <KFormat>
#include <KLocalizedString> #include <KLocalizedString>
#include <KPluginMetaData> #include <KPluginMetaData>
#include <Kdelibs4Migration>
// local includes // local includes
#include "action.h" #include "action.h"
@ -1209,8 +1210,13 @@ void DocumentPrivate::saveDocumentInfo() const
return; return;
QFile infoFile( m_xmlFileName ); QFile infoFile( m_xmlFileName );
if (infoFile.open( QIODevice::WriteOnly | QIODevice::Truncate) ) qCDebug(OkularCoreDebug) << "About to save document info to" << m_xmlFileName;
if (!infoFile.open( QIODevice::WriteOnly | QIODevice::Truncate))
{ {
qCWarning(OkularCoreDebug) << "Failed to open docdata file" << m_xmlFileName;
return;
}
// 1. Create DOM // 1. Create DOM
QDomDocument doc( QStringLiteral("documentInfo") ); QDomDocument doc( QStringLiteral("documentInfo") );
QDomProcessingInstruction xmlPi = doc.createProcessingInstruction( QDomProcessingInstruction xmlPi = doc.createProcessingInstruction(
@ -1288,7 +1294,6 @@ void DocumentPrivate::saveDocumentInfo() const
QTextStream os( &infoFile ); QTextStream os( &infoFile );
os.setCodec( "UTF-8" ); os.setCodec( "UTF-8" );
os << xml; os << xml;
}
infoFile.close(); infoFile.close();
} }
@ -2213,18 +2218,32 @@ Document::~Document()
QString DocumentPrivate::docDataFileName(const QUrl &url, qint64 document_size) QString DocumentPrivate::docDataFileName(const QUrl &url, qint64 document_size)
{ {
QString fn = url.fileName(); QString fn = url.fileName();
fn = QString::number( document_size ) + '.' + fn + ".xml"; fn = QString::number( document_size ) + '.' + fn + ".xml";
QString newokular = "okular/docdata/" + fn; QString docdataDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
QString newokularfile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + newokular ; + QStringLiteral("/okular/docdata");
if ( !QFile::exists( newokularfile ) ) // make sure that the okular/docdata/ directory exists (probably this used to be handled by KStandardDirs)
if (!QFileInfo::exists(docdataDir))
{ {
QString oldkpdf = "kpdf/" + fn; qCDebug(OkularCoreDebug) << "creating docdata folder" << docdataDir;
QString oldkpdffile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + oldkpdf ; QDir().mkpath(docdataDir);
if ( QFile::exists( oldkpdffile ) ) }
QString newokularfile = docdataDir + QLatin1Char('/') + fn;
// we don't want to accidentally migrate old files when running unit tests
if (!QFile::exists( newokularfile ) && !QStandardPaths::isTestModeEnabled())
{
// see if an KDE4 file still exists
static Kdelibs4Migration k4migration;
QString oldfile = k4migration.locateLocal("data", QStringLiteral("okular/docdata/") + fn);
if (oldfile.isEmpty())
{
oldfile = k4migration.locateLocal("data", QStringLiteral("kpdf/") + fn);
}
if ( !oldfile.isEmpty() && QFile::exists( oldfile ) )
{ {
// ### copy or move? // ### copy or move?
if ( !QFile::copy( oldkpdffile, newokularfile ) ) if ( !QFile::copy( oldfile, newokularfile ) )
return QString(); return QString();
} }
} }

@ -42,6 +42,8 @@ int main(int argc, char** argv)
QCommandLineParser parser; QCommandLineParser parser;
KAboutData::setApplicationData(aboutData); KAboutData::setApplicationData(aboutData);
// The KDE4 version accepted flags such as -unique with a single dash -> preserve compatibility
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
parser.addVersionOption(); parser.addVersionOption();
parser.addHelpOption(); parser.addHelpOption();
aboutData.setupCommandLine(&parser); aboutData.setupCommandLine(&parser);

@ -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);
if ( shell->openDocument( ShellUtils::urlFromArg(paths[i], ShellUtils::qfileExistFunc(), page), serializedOptions) ) if ( shell->openDocument( ShellUtils::urlFromArg(paths[i], ShellUtils::qfileExistFunc(), page).url(), serializedOptions) )
{ {
++i; ++i;
} }

@ -167,7 +167,7 @@ Shell::~Shell()
// Open a new document if we have space for it // Open a new document if we have space for it
// This can hang if called on a unique instance and openUrl pops a messageBox // This can hang if called on a unique instance and openUrl pops a messageBox
bool Shell::openDocument( const QUrl& url, const QString &serializedOptions ) bool Shell::openDocument( const QString& urlString, const QString &serializedOptions )
{ {
if( m_tabs.size() <= 0 ) if( m_tabs.size() <= 0 )
return false; return false;
@ -182,7 +182,7 @@ bool Shell::openDocument( const QUrl& url, const QString &serializedOptions )
return false; return false;
} }
openUrl( url, serializedOptions ); openUrl( QUrl( urlString, QUrl::StrictMode) , serializedOptions );
return true; return true;
} }

@ -69,7 +69,7 @@ public:
public slots: public slots:
Q_SCRIPTABLE Q_NOREPLY void tryRaise(); Q_SCRIPTABLE Q_NOREPLY void tryRaise();
Q_SCRIPTABLE bool openDocument(const QUrl &url, const QString &serializedOptions = QString() ); Q_SCRIPTABLE bool openDocument(const QString &urlString, const QString &serializedOptions = QString() );
Q_SCRIPTABLE bool canOpenDocs( int numDocs, int desktop ); Q_SCRIPTABLE bool canOpenDocs( int numDocs, int desktop );
protected: protected:

Loading…
Cancel
Save