Back to index

scribus-ng  1.3.4.dfsg+svn20071115
prefsreader.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2004 by Riku Leino                                      *
00009  *   tsoots@gmail.com                                                      *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #include "prefsreader.h"
00028 
00029 PrefsReader::PrefsReader(ContextMap *appContexts, ContextMap *pluginContexts)
00030 {
00031        aContexts = appContexts;
00032        pContexts = pluginContexts;
00033        inApp = false;
00034        rowIndex = 0;
00035        colIndex = 0;
00036        inTable = false;
00037 }
00038 
00039 bool PrefsReader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs)
00040 {
00041        if (name == "context")
00042        {
00043               for (int i = 0; i < attrs.count(); ++i)
00044                      if (attrs.localName(i) == "name")
00045                             currentContext = new PrefsContext(attrs.value(i));
00046        }
00047        else if (name == "level")
00048        {
00049               bool found = false;
00050               for (int i = 0; i < attrs.count(); ++i)
00051                      if ((attrs.localName(i) == "name") && (attrs.value(i) == "application"))
00052                             found = true;
00053               inApp = found;
00054        }
00055        else if (name == "attribute")
00056        {
00057               QString key = "";
00058               QString value = "";
00059               for (int i = 0; i < attrs.count(); ++i)
00060               {
00061                      if (attrs.localName(i) == "key")
00062                             key = attrs.value(i);
00063                      else if (attrs.localName(i) == "value")
00064                             value = attrs.value(i);
00065               }
00066               currentContext->set(key, value);
00067        }
00068        else if (name == "table")
00069        {
00070               for (int i = 0; i < attrs.count(); ++i)
00071               {
00072                      if (attrs.localName(i) == "name")
00073                             currentTable = currentContext->getTable(attrs.value(i));
00074               }
00075        }
00076        else if (name == "col")
00077               inTable = true;      
00078 
00079        return true;
00080 }
00081 
00082 bool PrefsReader::characters (const QString& ch)
00083 {
00084        if (inTable)
00085               currentTable->set(rowIndex, colIndex, ch);
00086        return true;
00087 } 
00088 
00089 bool PrefsReader::endElement(const QString&, const QString&, const QString &name)
00090 {
00091        if (name == "context")
00092        {
00093               if (inApp)
00094                      (*aContexts)[currentContext->getName()] = currentContext;
00095               else
00096                      (*pContexts)[currentContext->getName()] = currentContext;
00097        }
00098        else if (name == "row")
00099        {
00100               ++rowIndex;
00101               colIndex = 0;
00102        }
00103        else if (name == "col")
00104        {
00105               ++colIndex;
00106               inTable = false;
00107        }
00108        else if (name == "table")
00109        {
00110               rowIndex = 0;
00111               colIndex = 0;
00112        }
00113        return true;
00114 }
00115 
00116 PrefsReader::~PrefsReader()
00117 {
00118 
00119 }