src/hbcore/i18n/hbnumbergrpxmlreader.cpp
changeset 0 16d8024aca5e
child 6 c3690ec91ef8
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include <QTranslator>
       
    27 #include "hbnumbergrpxmlreader_p.h"
       
    28 #define NumberGroupingFile ":/i18n/hbngnormalnumbers.xml"
       
    29 
       
    30 using namespace HbNumberGrpXmlReaderHelp;
       
    31 
       
    32 HbNumberGrpXmlReader::HbNumberGrpXmlReader( int localeId )
       
    33 {
       
    34 	locale.setNum(localeId);
       
    35 	locale.insert(0, "C");
       
    36 	found = false;
       
    37 	done = false;
       
    38 	phase = 0;
       
    39 	decimal = "";
       
    40 	pattern = ""; 
       
    41 	group = "";
       
    42 
       
    43 	QFile xmlFile(NumberGroupingFile);
       
    44 
       
    45 	if ( xmlFile.exists() )	{
       
    46 		QXmlInputSource source(&xmlFile);
       
    47 		QXmlSimpleReader reader; 
       
    48 		reader.setContentHandler(this);  
       
    49 		reader.parse(source) ;
       
    50 	}	
       
    51 } 	
       
    52 
       
    53 QString HbNumberGrpXmlReader::getPattern()
       
    54 {
       
    55 	return pattern;
       
    56 }
       
    57 
       
    58 QString HbNumberGrpXmlReader::getGroup()
       
    59 {
       
    60 	return group;
       
    61 }
       
    62 
       
    63 QString HbNumberGrpXmlReader::getDecimal()
       
    64 {
       
    65 	return decimal;
       
    66 }
       
    67 
       
    68 HbNumberGrpXmlReader::HbNumberGrpXmlReader()
       
    69 {
       
    70 }
       
    71 
       
    72 HbNumberGrpXmlReader::~HbNumberGrpXmlReader()
       
    73 {
       
    74 
       
    75 }
       
    76 
       
    77 bool HbNumberGrpXmlReader::startDocument()
       
    78 {
       
    79     return true;
       
    80 }
       
    81 
       
    82 bool HbNumberGrpXmlReader::startElement( const QString &,
       
    83 				   const QString &,
       
    84 				   const QString &qName,
       
    85 				   const QXmlAttributes & )
       
    86 {
       
    87 	if ( done ) {
       
    88 		return true;
       
    89 	}
       
    90 
       
    91 	if ( found ) {		
       
    92 		if ( qName == DecimalStr ) {
       
    93 			phase = 1;
       
    94 		} else if ( qName == GroupStr ) {
       
    95 			phase = 2;
       
    96 		} else if ( qName == PatternStr ) {
       
    97 			phase = 3;
       
    98 		}
       
    99 	} else if ( locale == qName ) {
       
   100 		found = true;
       
   101 	}
       
   102     return true;	
       
   103 }
       
   104 
       
   105 bool HbNumberGrpXmlReader::characters( const QString &text )
       
   106 {  
       
   107     if ( done ) {
       
   108         return true;
       
   109     }
       
   110 
       
   111     QString tmpText;
       
   112 
       
   113 	// This little trick is needed because of limitation in XML reader
       
   114 	// XML reader doesn't read space character corretly
       
   115     if ( text.at(0).toAscii() == 32 ) {  // " "
       
   116         tmpText = " ";    
       
   117     } else {
       
   118         tmpText = text;
       
   119     }
       
   120     
       
   121     if ( found ) {
       
   122 		if ( phase == 1 ) {  //handle Decimal
       
   123 			decimal = tmpText;
       
   124 		} else if ( phase == 2 ) { // handle group
       
   125 			group = tmpText;
       
   126 		} else if ( phase == 3 ) { // handle pattern
       
   127 			 pattern = tmpText;
       
   128 		} else {}
       
   129 		
       
   130 		phase = 0;
       
   131     }
       
   132     return true;	
       
   133 }
       
   134 
       
   135 bool HbNumberGrpXmlReader::endElement( const QString &,
       
   136         const QString &,
       
   137         const QString &qName )
       
   138 {
       
   139 	if ( locale == qName ) {
       
   140 		done = true;
       
   141 	}
       
   142 
       
   143 	return true;
       
   144 }
       
   145 
       
   146 bool HbNumberGrpXmlReader::endDocument()
       
   147 {
       
   148     return true;
       
   149 }
       
   150 
       
   151