Turn the annotation tools list in a configurable option

Instead of using a system-wide tools.xml file containing a list of
<tool>...</tool> elements, store each tool element as string in a
stringlist configuration option.
Note that the global tools.xml file is still needed to read the
default values.
remotes/origin/epub-qtextdoc
Fabio D'Urso 14 years ago
parent c9e5d0a0b0
commit e568f100d5
  1. 30
      conf/okular.kcfg
  2. 1
      conf/settings.kcfgc
  3. 69
      ui/pageviewannotator.cpp
  4. 5
      ui/pageviewannotator.h

@ -237,5 +237,35 @@
</code>
<default code="true">userString</default>
</entry>
<entry key="AnnotationTools" type="StringList">
<code>
QStringList annotationTools;
// load the default tool list from the 'xml tools definition' file
QFile infoFile( KStandardDirs::locate("data", "okular/tools.xml") );
if ( infoFile.exists() &amp;&amp; infoFile.open( QIODevice::ReadOnly ) )
{
QDomDocument doc;
if ( doc.setContent( &amp;infoFile ) )
{
QDomElement toolsDefinition = doc.elementsByTagName("annotatingTools").item( 0 ).toElement();
// create the annotationTools list from the XML dom tree
QDomNode toolDescription = toolsDefinition.firstChild();
while ( toolDescription.isElement() )
{
QDomElement toolElement = toolDescription.toElement();
if ( toolElement.tagName() == "tool" )
{
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);
}
toolDescription = toolDescription.nextSibling();
}
}
}
</code>
<default code="true">annotationTools</default>
</entry>
</group>
</kcfg>

@ -6,4 +6,5 @@ Mutators=true
Singleton=true
Visibility=OKULAR_EXPORT
IncludeFiles=core/okular_export.h, settings_core.h
SourceIncludeFiles=kstandarddirs.h,qdom.h
MemberVariables=dpointer

@ -621,47 +621,46 @@ void PageViewAnnotator::reparseConfig()
{
m_items.clear();
// load the tools from the 'xml tools definition' file. store the tree internally.
QFile infoFile( KStandardDirs::locate("data", "okular/tools.xml") );
if ( infoFile.exists() && infoFile.open( QIODevice::ReadOnly ) )
// Read tool list from configuration. It's a list of XML <tool></tool> elements
const QStringList userTools = Okular::Settings::annotationTools();
// Populate m_toolsDefinition
QDomDocument doc;
m_toolsDefinition = doc.createElement( "annotatingTools" );
foreach ( const QString &toolXml, userTools )
{
QDomDocument doc( "annotatingTools" );
if ( doc.setContent( &infoFile ) )
{
m_toolsDefinition = doc.elementsByTagName("annotatingTools").item( 0 ).toElement();
QDomDocument entryParser;
if ( entryParser.setContent( toolXml ) )
m_toolsDefinition.appendChild( doc.importNode( entryParser.documentElement(), true ) );
else
kWarning() << "Skipping malformed tool XML in AnnotationTools setting";
}
// create the AnnotationToolItems from the XML dom tree
QDomNode toolDescription = m_toolsDefinition.firstChild();
while ( toolDescription.isElement() )
// Create the AnnotationToolItems from the XML dom tree
QDomNode toolDescription = m_toolsDefinition.firstChild();
while ( toolDescription.isElement() )
{
QDomElement toolElement = toolDescription.toElement();
if ( toolElement.tagName() == "tool" )
{
AnnotationToolItem item;
item.id = toolElement.attribute("id").toInt();
item.text = i18n( toolElement.attribute( "name" ).toUtf8() );
item.pixmap = toolElement.attribute("pixmap");
QDomNode shortcutNode = toolElement.elementsByTagName( "shortcut" ).item( 0 );
if ( shortcutNode.isElement() )
item.shortcut = shortcutNode.toElement().text();
QDomNodeList engineNodeList = toolElement.elementsByTagName( "engine" );
if ( engineNodeList.size() > 0 )
{
QDomElement toolElement = toolDescription.toElement();
if ( toolElement.tagName() == "tool" )
{
AnnotationToolItem item;
item.id = toolElement.attribute("id").toInt();
item.text = i18n( toolElement.attribute( "name" ).toUtf8() );
item.pixmap = toolElement.attribute("pixmap");
QDomNode shortcutNode = toolElement.elementsByTagName( "shortcut" ).item( 0 );
if ( shortcutNode.isElement() )
item.shortcut = shortcutNode.toElement().text();
QDomNodeList engineNodeList = toolElement.elementsByTagName( "engine" );
if ( engineNodeList.size() > 0 )
{
QDomElement engineEl = engineNodeList.item( 0 ).toElement();
if ( !engineEl.isNull() && engineEl.hasAttribute( "type" ) )
item.isText = engineEl.attribute( "type" ) == QLatin1String( "TextSelector" );
}
m_items.push_back( item );
}
toolDescription = toolDescription.nextSibling();
QDomElement engineEl = engineNodeList.item( 0 ).toElement();
if ( !engineEl.isNull() && engineEl.hasAttribute( "type" ) )
item.isText = engineEl.attribute( "type" ) == QLatin1String( "TextSelector" );
}
m_items.push_back( item );
}
else
kWarning() << "AnnotatingTools XML file seems to be damaged";
infoFile.close();
toolDescription = toolDescription.nextSibling();
}
else
kWarning() << "Unable to open AnnotatingTools XML definition";
}
PageViewAnnotator::~PageViewAnnotator()

@ -40,11 +40,12 @@ class PageView;
* to this class that performs a rough visual representation of what the
* annotation will become when finished.
*
* "data/tools.xml" is the file that contains Annotations/Engine association
* m_toolsDefinition is a DOM object that contains Annotations/Engine association
* for the items placed in the toolbar. The XML is parsed (1) when populating
* the toolbar and (2)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.
* that annotation. m_toolsDefinition is created in reparseConfig according to
* user configuration.
*/
class PageViewAnnotator : public QObject
{

Loading…
Cancel
Save