Commit ee2ef4b0 authored by Albert Astals Cid's avatar Albert Astals Cid

Merge remote-tracking branch 'origin/release/20.08'

parents 4f3d1db5 a73012a9
Pipeline #26943 passed with stage
in 9 minutes and 11 seconds
......@@ -389,6 +389,7 @@ if(BUILD_DESKTOP)
set(okularpart_SRCS
${okularpart_conf_SRCS}
part.cpp
xmlgui_helper.cpp
extensions.cpp
ui/embeddedfilesdialog.cpp
ui/annotationactionhandler.cpp
......
......@@ -117,6 +117,7 @@
#include "ui/signaturepanel.h"
#include "ui/thumbnaillist.h"
#include "ui/toc.h"
#include "xmlgui_helper.h"
#include <memory>
#ifdef OKULAR_KEEP_FILE_OPEN
......@@ -351,6 +352,13 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args)
Okular::Settings::instance(configFilePath);
// In part.rc 47 we introduced a new mandatory toolbar that kxmlgui doesn't know how to merge properly
// so unfortunately we have to remove any customized part.rc that is older than 47
const QStringList files = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kxmlgui5/okular/part.rc"));
for (const QString &file : files) {
removeRCFileIfVersionSmallerThan(file, 47);
}
numberOfParts++;
if (numberOfParts == 1) {
m_registerDbusName = QStringLiteral("/okular");
......
/***************************************************************************
* Copyright (C) 2020 by Albert Astals Cid <aacid@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "xmlgui_helper.h"
#include <QDebug>
#include <QFile>
// Copied from KXmlGuiVersionHandler::findVersionNumber :/
static QString findVersionNumber(const QString &xml)
{
enum { ST_START, ST_AFTER_OPEN, ST_AFTER_GUI, ST_EXPECT_VERSION, ST_VERSION_NUM } state = ST_START;
const int length = xml.length();
for (int pos = 0; pos < length; pos++) {
switch (state) {
case ST_START:
if (xml[pos] == QLatin1Char('<')) {
state = ST_AFTER_OPEN;
}
break;
case ST_AFTER_OPEN: {
// Jump to gui..
const int guipos = xml.indexOf(QLatin1String("gui"), pos, Qt::CaseInsensitive);
if (guipos == -1) {
return QString(); // Reject
}
pos = guipos + 2; // Position at i, so we're moved ahead to the next character by the ++;
state = ST_AFTER_GUI;
break;
}
case ST_AFTER_GUI:
state = ST_EXPECT_VERSION;
break;
case ST_EXPECT_VERSION: {
const int verpos = xml.indexOf(QLatin1String("version"), pos, Qt::CaseInsensitive);
if (verpos == -1) {
return QString(); // Reject
}
pos = verpos + 7; // strlen("version") is 7
while (xml.at(pos).isSpace()) {
++pos;
}
if (xml.at(pos++) != QLatin1Char('=')) {
return QString(); // Reject
}
while (xml.at(pos).isSpace()) {
++pos;
}
state = ST_VERSION_NUM;
break;
}
case ST_VERSION_NUM: {
int endpos;
for (endpos = pos; endpos < length; endpos++) {
const ushort ch = xml[endpos].unicode();
if (ch >= QLatin1Char('0') && ch <= QLatin1Char('9')) {
continue; // Number..
}
if (ch == QLatin1Char('"')) { // End of parameter
break;
} else { // This shouldn't be here..
endpos = length;
}
}
if (endpos != pos && endpos < length) {
const QString matchCandidate = xml.mid(pos, endpos - pos); // Don't include " ".
return matchCandidate;
}
state = ST_EXPECT_VERSION; // Try to match a well-formed version..
break;
} // case..
} // switch
} // for
return QString();
}
namespace Okular
{
void removeRCFileIfVersionSmallerThan(const QString &filePath, int version)
{
QFile f(filePath);
if (f.open(QIODevice::ReadOnly)) {
const QByteArray contents = f.readAll();
f.close();
const QString fileVersion = findVersionNumber(contents);
if (fileVersion.toInt() < version) {
QFile::remove(filePath);
}
}
}
}
/***************************************************************************
* Copyright (C) 2020 by Albert Astals Cid <aacid@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <QString>
namespace Okular
{
void removeRCFileIfVersionSmallerThan(const QString &filePath, int version);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment