]> Git trees. - libqmvoc.git/commitdiff
Applied a patch from carsten to improve the loading of glossaries and slightly edited...
authorPino Toscano <pino@kde.org>
Mon, 4 Jul 2005 11:14:45 +0000 (11:14 +0000)
committerPino Toscano <pino@kde.org>
Mon, 4 Jul 2005 11:14:45 +0000 (11:14 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=431446

kdeeduui/kdeeduglossary.cpp
kdeeduui/kdeeduglossary.h

index cf86b6a6f3437050d85a0184e0ec64c1421483f9..fad0048ed77940cbbba2c8f7a849004943995d8c 100644 (file)
 #include <qstringlist.h>
 #include <qtoolbutton.h>
 
-bool Glossary::loadLayout( QDomDocument &questionDocument, const QString& path, const QString& filename )
+bool Glossary::loadLayout( QDomDocument &questionDocument, const KURL& url )
 {
-        KURL url;
-        url.setPath( path );
-               url.setFileName( filename );
-
         QFile layoutFile( url.path() );
 
         if (!layoutFile.exists())
@@ -56,6 +52,22 @@ bool Glossary::loadLayout( QDomDocument &questionDocument, const QString& path,
         return true;
 }
 
+Glossary* Glossary::readFromXML( const KURL& url )
+{
+       QDomDocument doc( "document" );
+
+       Glossary *glossary = new Glossary();
+
+       if ( glossary->loadLayout( doc, url ) )
+       {
+               QValueList<GlossaryItem*> itemList;
+               itemList = glossary->readItems( doc );
+               glossary->setItemlist( itemList );
+       }
+
+       return glossary;
+}
+
 QValueList<GlossaryItem*> Glossary::readItems( QDomDocument &itemDocument )
 {
        QValueList<GlossaryItem*> list;
index 7f5aeaaf0f158d876fe063c450a4fe14ed4a79b1..63e9543011101ab48abbde513585a32c80019934 100644 (file)
@@ -68,17 +68,26 @@ class Glossary
                QString name()const{
                        return m_name;
                }
-               
+
+               void setItemlist( QValueList<GlossaryItem*> list ){
+                       m_itemlist = list;
+               }
+
                /**
-                * @param path The path where to look for the file
-                * @param filename The file to be loaded
-                * @return true if the file was successfully loaded
+                * Read a glossary from an XML file.
+                *
+                * @param url The path of the file to load
+                *
+                * @return a pointer to the loaded glossary. Even in case of
+                *         error, this won't return 0 but an empty Glossary.
                 */
-               bool loadLayout( QDomDocument&, const QString& path, const QString& filename );
+               static Glossary* readFromXML( const KURL& url );
        
        private:
                QValueList<GlossaryItem*> readItems( QDomDocument &itemDocument );
                
+               bool loadLayout( QDomDocument&, const KURL& url );
+               
                QValueList<GlossaryItem*> m_itemlist;
                
                QString m_name;