File indexing completed on 2024-04-28 16:21:24

0001 /* This file is part of the KDE project
0002    Copyright (C) 2001 Laurent Montel <montel@kde.org>
0003              (C) 2000 Torben Weis <weis@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "Localization.h"
0022 
0023 #include <QDomDocument>
0024 
0025 using namespace Calligra::Sheets;
0026 
0027 Localization::Localization()
0028         : KLocale()
0029 {
0030 }
0031 
0032 void Localization::load(const KoXmlElement& element)
0033 {
0034     if (element.hasAttribute("weekStartsMonday")) {
0035         QString c = element.attribute("weekStartsMonday");
0036         if (c != "False") {
0037             setWeekStartDay(1 /*Monday*/);
0038         }
0039     }
0040     if (element.hasAttribute("decimalSymbol"))
0041         setDecimalSymbol(element.attribute("decimalSymbol"));
0042     if (element.hasAttribute("thousandsSeparator"))
0043         setThousandsSeparator(element.attribute("thousandsSeparator"));
0044     if (element.hasAttribute("currencySymbol"))
0045         setCurrencySymbol(element.attribute("currencySymbol"));
0046     if (element.hasAttribute("monetaryDecimalSymbol"))
0047         setMonetaryDecimalSymbol(element.attribute("monetaryDecimalSymbol"));
0048     if (element.hasAttribute("monetaryThousandsSeparator"))
0049         setMonetaryThousandsSeparator(element.attribute("monetaryThousandsSeparator"));
0050     if (element.hasAttribute("positiveSign"))
0051         setPositiveSign(element.attribute("positiveSign"));
0052     if (element.hasAttribute("negativeSign"))
0053         setNegativeSign(element.attribute("negativeSign"));
0054     if (element.hasAttribute("fracDigits"))
0055         setMonetaryDecimalPlaces(element.attribute("fracDigits").toInt());
0056     if (element.hasAttribute("positivePrefixCurrencySymbol")) {
0057         QString c = element.attribute("positivePrefixCurrencySymbol");
0058         setPositivePrefixCurrencySymbol(c == "True");
0059     }
0060     if (element.hasAttribute("negativePrefixCurrencySymbol")) {
0061         QString c = element.attribute("negativePrefixCurrencySymbol");
0062         setNegativePrefixCurrencySymbol(c == "True");
0063     }
0064     if (element.hasAttribute("positiveMonetarySignPosition"))
0065         setPositiveMonetarySignPosition((SignPosition)element.attribute("positiveMonetarySignPosition").toInt());
0066     if (element.hasAttribute("negativeMonetarySignPosition"))
0067         setNegativeMonetarySignPosition((SignPosition)element.attribute("negativeMonetarySignPosition").toInt());
0068     if (element.hasAttribute("timeFormat"))
0069         setTimeFormat(element.attribute("timeFormat"));
0070     if (element.hasAttribute("dateFormat"))
0071         setDateFormat(element.attribute("dateFormat"));
0072     if (element.hasAttribute("dateFormatShort"))
0073         setDateFormatShort(element.attribute("dateFormatShort"));
0074 }
0075 
0076 QDomElement Localization::save(QDomDocument& doc) const
0077 {
0078     QDomElement element = doc.createElement("locale");
0079 
0080     element.setAttribute("weekStartsMonday", (weekStartDay() == 1) ? "True" : "False");
0081     element.setAttribute("decimalSymbol", decimalSymbol());
0082     element.setAttribute("thousandsSeparator", thousandsSeparator());
0083     element.setAttribute("currencySymbol", currencySymbol());
0084     element.setAttribute("monetaryDecimalSymbol", monetaryDecimalSymbol());
0085     element.setAttribute("monetaryThousandsSeparator", monetaryThousandsSeparator());
0086     element.setAttribute("positiveSign", positiveSign());
0087     element.setAttribute("negativeSign", negativeSign());
0088     element.setAttribute("fracDigits", QString::number(monetaryDecimalPlaces()));
0089     element.setAttribute("positivePrefixCurrencySymbol", positivePrefixCurrencySymbol() ? "True" : "False");
0090     element.setAttribute("negativePrefixCurrencySymbol", negativePrefixCurrencySymbol() ? "True" : "False");
0091     element.setAttribute("positiveMonetarySignPosition", QString::number((int)positiveMonetarySignPosition()));
0092     element.setAttribute("negativeMonetarySignPosition", QString::number((int)negativeMonetarySignPosition()));
0093     element.setAttribute("timeFormat", timeFormat());
0094     element.setAttribute("dateFormat", dateFormat());
0095     element.setAttribute("dateFormatShort", dateFormatShort());
0096 
0097     return element;
0098 }
0099 
0100 void Localization::defaultSystemConfig()
0101 {
0102     KLocale locale("calligrasheets");
0103     setWeekStartDay(locale.weekStartDay());
0104     setDecimalSymbol(locale.decimalSymbol());
0105     setThousandsSeparator(locale.thousandsSeparator());
0106     setCurrencySymbol(locale.currencySymbol());
0107     setMonetaryDecimalSymbol(locale.monetaryDecimalSymbol());
0108     setMonetaryThousandsSeparator(locale.monetaryThousandsSeparator());
0109     setPositiveSign(locale.positiveSign());
0110     setNegativeSign(locale.negativeSign());
0111     setMonetaryDecimalPlaces(locale.monetaryDecimalPlaces());
0112     setDecimalPlaces(locale.decimalPlaces());
0113     setPositivePrefixCurrencySymbol(locale.positivePrefixCurrencySymbol());
0114     setNegativePrefixCurrencySymbol(locale.negativePrefixCurrencySymbol());
0115     setPositiveMonetarySignPosition(locale.positiveMonetarySignPosition());
0116     setNegativeMonetarySignPosition(locale.negativeMonetarySignPosition());
0117     setTimeFormat(locale.timeFormat());
0118     setDateFormat(locale.dateFormat());
0119     setDateFormatShort(locale.dateFormatShort());
0120 
0121 }
0122