Store the state of the builtin annotations in a new config key

Using the new configuration key BuiltinAnnotationTools instead of AnnotationTools, we avoid any conflicts in the configuration files due to the fact that the key AnnotationTools had a different meaning in the previous versions of Okular. In particular we avoid the critical problem that the actions in the UI do not match the actual annotation tools. The conflict may happen if the kconf_update script is not executed for some reason (e.g. okular running from flatpack).

BUG: 425354
FIXED-IN: 1.11.1
This commit is contained in:
Simone Gaiarin 2020-08-25 10:16:10 +02:00
parent 1c7c7275e1
commit 10d92fbeda
4 changed files with 28 additions and 22 deletions

View File

@ -79,9 +79,9 @@
</code>
<default code="true">drawingTools</default>
</entry>
<entry key="AnnotationTools" type="StringList">
<entry key="BuiltinAnnotationTools" type="StringList">
<code>
QStringList annotationTools;
QStringList builtinAnnotationTools;
// load the default tool list from the 'xml tools definition' file
QFile infoFile( QStandardPaths::locate(QStandardPaths::GenericDataLocation, "okular/tools.xml") );
if ( infoFile.exists() &amp;&amp; infoFile.open( QIODevice::ReadOnly ) )
@ -90,7 +90,7 @@
if ( doc.setContent( &amp;infoFile ) )
{
QDomElement toolsDefinition = doc.elementsByTagName("annotatingTools").item( 0 ).toElement();
// create the annotationTools list from the XML dom tree
// create the builtinAnnotationTools list from the XML dom tree
QDomNode toolDescription = toolsDefinition.firstChild();
while ( toolDescription.isElement() )
{
@ -100,7 +100,7 @@
QDomDocument temp;
temp.appendChild( temp.importNode( toolElement, true) );
// add each &lt;tool&gt;...&lt;/tool&gt; as XML string
annotationTools &lt;&lt; temp.toString(-1);
builtinAnnotationTools &lt;&lt; temp.toString(-1);
}
toolDescription = toolDescription.nextSibling();
}
@ -115,7 +115,7 @@
qWarning() &lt;&lt; "Unable to open AnnotatingTools XML definition";
}
</code>
<default code="true">annotationTools</default>
<default code="true">builtinAnnotationTools</default>
</entry>
<entry key="QuickAnnotationTools" type="StringList">
<code>

View File

@ -6,3 +6,9 @@ Id=annotation-toolbar
File=okularpartrc
Group=Reviews
Key=AnnotationTools,QuickAnnotationTools
#Remove key that stored the state of the bultin annotation tools (now stored in BuiltinAnnoationTools)
Id=builtin-annotations
File=okularpartrc
Group=Reviews
RemoveKey=AnnotationTools

View File

@ -719,7 +719,7 @@ PageViewAnnotator::PageViewAnnotator(PageView *parent, Okular::Document *storage
, m_pageView(parent)
, m_actionHandler(nullptr)
, m_engine(nullptr)
, m_toolsDefinition(nullptr)
, m_builtinToolsDefinition(nullptr)
, m_quickToolsDefinition(nullptr)
, m_continuousMode(true)
, m_constrainRatioAndAngle(false)
@ -732,9 +732,9 @@ PageViewAnnotator::PageViewAnnotator(PageView *parent, Okular::Document *storage
void PageViewAnnotator::reparseConfig()
{
// Read tool list from configuration. It's a list of XML <tool></tool> elements
if (!m_toolsDefinition)
m_toolsDefinition = new AnnotationTools();
m_toolsDefinition->setTools(Okular::Settings::annotationTools());
if (!m_builtinToolsDefinition)
m_builtinToolsDefinition = new AnnotationTools();
m_builtinToolsDefinition->setTools(Okular::Settings::builtinAnnotationTools());
if (!m_quickToolsDefinition)
m_quickToolsDefinition = new AnnotationTools();
@ -972,7 +972,7 @@ void PageViewAnnotator::selectTool(int toolID)
}
// for the selected tool create the Engine
QDomElement toolElement = m_toolsDefinition->tool(toolID);
QDomElement toolElement = m_builtinToolsDefinition->tool(toolID);
if (!toolElement.isNull()) {
// parse tool properties
QDomElement engineElement = toolElement.firstChildElement(QStringLiteral("engine"));
@ -1268,7 +1268,7 @@ void PageViewAnnotator::setTextToolsEnabled(bool enabled)
void PageViewAnnotator::saveAnnotationTools()
{
Okular::Settings::setAnnotationTools(m_toolsDefinition->toStringList());
Okular::Settings::setBuiltinAnnotationTools(m_builtinToolsDefinition->toStringList());
Okular::Settings::setQuickAnnotationTools(m_quickToolsDefinition->toStringList());
Okular::Settings::self()->save();
}
@ -1278,8 +1278,8 @@ int PageViewAnnotator::setQuickTool(int favToolID)
int toolId = -1;
QDomElement favToolElement = m_quickToolsDefinition->tool(favToolID);
if (!favToolElement.isNull()) {
toolId = m_toolsDefinition->findToolId(favToolElement.attribute(QStringLiteral("type")));
if (m_toolsDefinition->updateTool(favToolElement, toolId))
toolId = m_builtinToolsDefinition->findToolId(favToolElement.attribute(QStringLiteral("type")));
if (m_builtinToolsDefinition->updateTool(favToolElement, toolId))
saveAnnotationTools();
}
return toolId;
@ -1287,7 +1287,7 @@ int PageViewAnnotator::setQuickTool(int favToolID)
QDomElement PageViewAnnotator::builtinTool(int toolID)
{
return m_toolsDefinition->tool(toolID);
return m_builtinToolsDefinition->tool(toolID);
}
QDomElement PageViewAnnotator::quickTool(int toolID)
@ -1297,7 +1297,7 @@ QDomElement PageViewAnnotator::quickTool(int toolID)
QDomElement PageViewAnnotator::currentEngineElement()
{
return m_toolsDefinition->tool(m_lastToolID).firstChildElement(QStringLiteral("engine"));
return m_builtinToolsDefinition->tool(m_lastToolID).firstChildElement(QStringLiteral("engine"));
}
QDomElement PageViewAnnotator::currentAnnotationElement()
@ -1354,7 +1354,7 @@ void PageViewAnnotator::setAnnotationFont(const QFont &font)
void PageViewAnnotator::addToQuickAnnotations()
{
QDomElement sourceToolElement = m_toolsDefinition->tool(m_lastToolID);
QDomElement sourceToolElement = m_builtinToolsDefinition->tool(m_lastToolID);
if (sourceToolElement.isNull())
return;
@ -1374,7 +1374,7 @@ void PageViewAnnotator::addToQuickAnnotations()
void PageViewAnnotator::slotAdvancedSettings()
{
QDomElement toolElement = m_toolsDefinition->tool(m_lastToolID);
QDomElement toolElement = m_builtinToolsDefinition->tool(m_lastToolID);
EditAnnotToolDialog t(nullptr, toolElement, true);
if (t.exec() != QDialog::Accepted)
@ -1382,7 +1382,7 @@ void PageViewAnnotator::slotAdvancedSettings()
QDomElement toolElementUpdated = t.toolXml().documentElement();
int toolID = toolElement.attribute(QStringLiteral("id")).toInt();
m_toolsDefinition->updateTool(toolElementUpdated, toolID);
m_builtinToolsDefinition->updateTool(toolElementUpdated, toolID);
saveAnnotationTools();
selectTool(m_lastToolID);
}

View File

@ -44,12 +44,12 @@ class PageView;
* to this class that performs a rough visual representation of what the
* annotation will become when finished.
*
* m_toolsDefinition is a AnnotationTools object that wraps a DOM object that
* m_builtinToolsDefinition is a AnnotationTools object that wraps a DOM object that
* contains Annotations/Engine association for the items placed in the toolbar.
* The XML is parsed after selecting a toolbar item, in which case an Ann is
* initialized with the values in the XML and an engine is created to handle
* that annotation. m_toolsDefinition is created in reparseConfig according to
* user configuration. m_toolsDefinition is updated (and saved to disk) (1) each
* that annotation. m_builtinToolsDefinition is created in reparseConfig according to
* user configuration. m_builtinToolsDefinition is updated (and saved to disk) (1) each
* time a property of an annotation (color, font, etc) is changed by the user,
* and (2) each time a "quick annotation" is selected, in which case the properties
* of the selected quick annotation are written over those of the corresponding
@ -149,7 +149,7 @@ private:
PageView *m_pageView;
AnnotationActionHandler *m_actionHandler;
AnnotatorEngine *m_engine;
AnnotationTools *m_toolsDefinition;
AnnotationTools *m_builtinToolsDefinition;
AnnotationTools *m_quickToolsDefinition;
bool m_continuousMode;
bool m_constrainRatioAndAngle;