diff --git a/conf/okular.kcfg b/conf/okular.kcfg
index 4a2aaf308..ac82028c7 100644
--- a/conf/okular.kcfg
+++ b/conf/okular.kcfg
@@ -237,5 +237,35 @@
userString
+
+
+ QStringList annotationTools;
+ // load the default tool list from the 'xml tools definition' file
+ QFile infoFile( KStandardDirs::locate("data", "okular/tools.xml") );
+ if ( infoFile.exists() && infoFile.open( QIODevice::ReadOnly ) )
+ {
+ QDomDocument doc;
+ if ( doc.setContent( &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 <tool>...</tool> as XML string
+ annotationTools << temp.toString(-1);
+ }
+ toolDescription = toolDescription.nextSibling();
+ }
+ }
+ }
+
+ annotationTools
+
diff --git a/conf/settings.kcfgc b/conf/settings.kcfgc
index 5e2ec95f8..9f2109ff2 100644
--- a/conf/settings.kcfgc
+++ b/conf/settings.kcfgc
@@ -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
diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp
index 9cf6adb0f..f53931243 100644
--- a/ui/pageviewannotator.cpp
+++ b/ui/pageviewannotator.cpp
@@ -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 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()
diff --git a/ui/pageviewannotator.h b/ui/pageviewannotator.h
index 078e0de14..50c4af737 100644
--- a/ui/pageviewannotator.h
+++ b/ui/pageviewannotator.h
@@ -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
{