PreferencesParser.cpp

Go to the documentation of this file.
00001 #include "PreferencesParser.h"
00002 
00003 PreferencesParser::PreferencesParser() :
00004     quizLength( Util::getDefaultQuizLength() ), interfaceLanguage( QString( "en" ) ), digraphEnabled( false ), 
00005         quizButtonsHidden( false ), altInTermListShown( false ),
00006             firstLanguage( QString( "en" ) ), testLanguage( QString( "ja" ) ), 
00007                 labelsFontFamily( Util::getDefaultLabelsFontFamily() ), labelsFontSizeModifier( Util::getDefaultLabelsFontSizeModifier() ),
00008                     fontFamily( Util::getDefaultFontFamily() ), fontSizeModifier( Util::getDefaultFontSizeModifier() ), 
00009                         languageFilterEnabled( true ) {
00010 }
00011 
00012 bool PreferencesParser::startElement( const QString&, const QString&, const QString& qname, const QXmlAttributes& attribs ) {
00013     if( qname == QString( "preferences" ) ) {
00014         bool isQuizLengthValid;
00015         int tempQuizLength = attribs.value( QString( "quizLength" ) ).toInt( &isQuizLengthValid, 10 );
00016         if( isQuizLengthValid )
00017             quizLength = tempQuizLength;
00018 
00019         // We ignore the revealSeq attribute voluntarily.  This way, the revealing sequences will contain the intial values.
00020 
00021         QString tempLanguageFilterEnabled = attribs.value( QString( "languageFilteredEnabled" ) );
00022         if( QString( "false" ) == tempLanguageFilterEnabled ) 
00023             languageFilterEnabled = false;
00024 
00025         QString tempInterfaceLanguage = attribs.value( QString( "interfaceLanguage" ) );
00026         if( tempInterfaceLanguage )
00027             interfaceLanguage = tempInterfaceLanguage;
00028 
00029         QString tempDigraphEnabled = attribs.value( QString( "digraph" ) );
00030         if( QString( "true" ) == tempDigraphEnabled )
00031             digraphEnabled = true;
00032 
00033         QString tempQuizButtonsHidden = attribs.value( QString( "quizButtonsHidden" ) );
00034         if( QString( "true" ) == tempQuizButtonsHidden )
00035             quizButtonsHidden = true;
00036 
00037         QString tempAltInTermListShown = attribs.value( QString( "altInTermListShown" ) );
00038         if( QString( "true" ) == tempAltInTermListShown )
00039             altInTermListShown = true;
00040 
00041         QString tempFirstLanguage = attribs.value( QString( "firstLanguage" ) );
00042         if( tempFirstLanguage )
00043             firstLanguage = ( tempFirstLanguage.length() == 0 ? QString::null : tempFirstLanguage );
00044 
00045         QString tempTestLanguage = attribs.value( QString( "testLanguage" ) );
00046         if( tempTestLanguage )
00047             testLanguage = ( tempTestLanguage.length() == 0 ? QString::null : tempTestLanguage );
00048 
00049         QStringList studyLanguageList( QStringList::split( QString( "," ), attribs.value( QString( "studyLanguages" ) ) ) );
00050         for( QStringList::ConstIterator it = studyLanguageList.begin(); it != studyLanguageList.end(); it++ ) {
00051             QString language( *it );
00052             studyLanguages.append( language );
00053         }
00054 
00055         QStringList closedFolderList( QStringList::split( QString( "," ), attribs.value( QString( "closedFolders" ) ) ) );
00056         for( QStringList::ConstIterator it = closedFolderList.begin(); it != closedFolderList.end(); it++ ) {
00057             bool isFolderIdValid;
00058             int tempFolderId = (*it).toInt( &isFolderIdValid, 10 );
00059             if( isFolderIdValid )
00060                 closedFolders.append( tempFolderId );
00061         }
00062 
00063         QString tempLabelsFontFamily = attribs.value( QString( "labelsFontName" ) );
00064         if( tempLabelsFontFamily )
00065             labelsFontFamily = tempLabelsFontFamily;
00066 
00067         bool isLabelsFontSizeModifierValid;
00068         int tempLabelsFontSizeModifier = attribs.value( QString( "labelsFontSize" ) ).toInt( &isLabelsFontSizeModifierValid, 10 );
00069         if( isLabelsFontSizeModifierValid )
00070             labelsFontSizeModifier = tempLabelsFontSizeModifier;
00071 
00072         QString tempFontFamily = attribs.value( QString( "fontName" ) );
00073         if( tempFontFamily )
00074             fontFamily = tempFontFamily;
00075 
00076         bool isFontSizeModifierValid;
00077         int tempFontSizeModifier = attribs.value( QString( "fontSize" ) ).toInt( &isFontSizeModifierValid, 10 );
00078         if( isFontSizeModifierValid )
00079             fontSizeModifier = tempFontSizeModifier;
00080     }
00081     else if( qname == QString( "fontOverride" ) ) {
00082         QString tempLang( attribs.value( QString( "language" ) ) );
00083 
00084         if( tempLang ) {
00085             QString tempFontFamily = attribs.value( QString( "fontName" ) );
00086             if( tempFontFamily )
00087                 fontOverrideFamilies[ tempLang ] = tempFontFamily;
00088 
00089             bool isFontSizeModifierValid;
00090             int tempFontSizeModifier = attribs.value( QString( "fontSize" ) ).toInt( &isFontSizeModifierValid, 10 );
00091             if( isFontSizeModifierValid )
00092                 fontOverrideSizes[ tempLang ] = tempFontSizeModifier; 
00093         }
00094     }
00095     else if( qname == QString( "accel" ) ) {
00096         QString tempActionId = attribs.value( QString( "action" ) );
00097 
00098         bool isActionValid = false;
00099         int tempAction = -1;
00100         for( int i = 0; i < ACTION_COUNT; i++ ) {
00101             if( tempActionId == actionId[ i ] ) {
00102                 isActionValid = true;
00103                 tempAction = i;
00104                 break;
00105             }
00106         }
00107         if( isActionValid ) {
00108             bool isKeyValid;
00109             int tempKey = attribs.value( QString( "key" ) ).toInt( &isKeyValid, 10 );
00110 
00111             if( isKeyValid )
00112                 accel[ tempAction ] = tempKey;
00113         }
00114     }
00115     return( true );
00116 }
00117 
00118 int PreferencesParser::getQuizLength() const {
00119     return( quizLength );
00120 }
00121 
00122 int PreferencesParser::getRevealingSequenceCount() const {
00123     return( sequences.count() );
00124 }
00125 
00126 Sequence PreferencesParser::getRevealingSequenceAt( int index ) {
00127     return( sequences[ index ] );
00128 }
00129 
00130 QString PreferencesParser::getInterfaceLanguage() const {
00131     return( interfaceLanguage );
00132 }
00133 
00134 bool PreferencesParser::isDigraphEnabled() const {
00135     return( digraphEnabled );
00136 }
00137 
00138 bool PreferencesParser::areQuizButtonsHidden() const {
00139     return( quizButtonsHidden );
00140 }
00141 
00142 bool PreferencesParser::isAltInTermListShown() const {
00143     return( altInTermListShown );
00144 }
00145 
00146 QString PreferencesParser::getFirstLanguage() const {
00147     return( firstLanguage );
00148 }
00149 
00150 QValueList<QString> PreferencesParser::getStudyLanguages() const {
00151     return( studyLanguages );
00152 }
00153 
00154 QString PreferencesParser::getTestLanguage() const {
00155     return( testLanguage );
00156 }
00157 
00158 QString PreferencesParser::getLabelsFontFamily() const {
00159     return( labelsFontFamily );
00160 }
00161 
00162 int PreferencesParser::getLabelsFontSizeModifier() const {
00163     return( labelsFontSizeModifier );
00164 }
00165 
00166 QString PreferencesParser::getFontFamily() const {
00167     return( fontFamily );
00168 }
00169 
00170 int PreferencesParser::getFontSizeModifier() const {
00171     return( fontSizeModifier );
00172 }
00173 
00174 QString PreferencesParser::getFontOverrideFamily( const QString& language ) const {
00175     return( fontOverrideFamilies[ language ] );
00176 }
00177 
00178 int PreferencesParser::getFontOverrideSize( const QString& language ) const {
00179     return( fontOverrideSizes[ language ] );
00180 }
00181 
00182 bool PreferencesParser::isFontOverrideFamilyDefined( const QString& language ) const {
00183     return( fontOverrideFamilies.contains( language ) );
00184 }
00185 
00186 bool PreferencesParser::isFontOverrideSizeDefined( const QString& language ) const {
00187     return( fontOverrideSizes.contains( language ) );
00188 }
00189 
00190 bool PreferencesParser::isLanguageFilterEnabled() const {
00191     return( languageFilterEnabled );
00192 }
00193 
00194 QValueList<int> PreferencesParser::getClosedFolders() const {
00195     return( closedFolders );
00196 }
00197 
00198 QMap<int,int> PreferencesParser::getAccelerators() const {
00199     return( accel );
00200 }

Generated on Sun Mar 1 17:30:47 2009 for toMOTko by  doxygen 1.5.6