kdecore Library API Documentation

kcalendarsystem.cpp

00001 /* 00002 Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es> 00003 Copyright (c) 2002 Hans Petter Bieker <bieker@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 // Gregorian calendar system implementation factory for creation of kde calendar 00022 // systems. 00023 // Also default gregorian and factory classes 00024 00025 #include <kglobal.h> 00026 00027 #include "kcalendarsystem.h" 00028 #include "klocale.h" 00029 00030 class KCalendarSystemPrivate 00031 { 00032 public: 00033 const KLocale * locale; 00034 }; 00035 00036 KCalendarSystem::KCalendarSystem(const KLocale * locale) 00037 : d(new KCalendarSystemPrivate) 00038 { 00039 d->locale = locale; 00040 } 00041 00042 KCalendarSystem::~KCalendarSystem() 00043 { 00044 delete d; 00045 } 00046 00047 const KLocale * KCalendarSystem::locale() const 00048 { 00049 if ( d->locale ) 00050 return d->locale; 00051 00052 return KGlobal::locale(); 00053 } 00054 00055 QString KCalendarSystem::dayString(const QDate & pDate, bool bShort) const 00056 { 00057 QString sResult; 00058 00059 sResult.setNum(day(pDate)); 00060 if (!bShort && sResult.length() == 1 ) 00061 sResult.prepend('0'); 00062 00063 return sResult; 00064 } 00065 00066 QString KCalendarSystem::monthString(const QDate & pDate, bool bShort) const 00067 { 00068 QString sResult; 00069 00070 sResult.setNum(month(pDate)); 00071 if (!bShort && sResult.length() == 1 ) 00072 sResult.prepend('0'); 00073 00074 return sResult; 00075 } 00076 00077 QString KCalendarSystem::yearString(const QDate & pDate, bool bShort) const 00078 { 00079 QString sResult; 00080 00081 sResult.setNum(year(pDate)); 00082 if (bShort && sResult.length() == 4 ) 00083 sResult = sResult.right(2); 00084 00085 return sResult; 00086 } 00087 00088 static int stringToInteger(const QString & sNum, int & iLength) 00089 { 00090 unsigned int iPos = 0; 00091 00092 int result = 0; 00093 for (; sNum.length() > iPos && sNum.at(iPos).isDigit(); iPos++) 00094 { 00095 result *= 10; 00096 result += sNum.at(iPos).digitValue(); 00097 } 00098 00099 iLength = iPos; 00100 return result; 00101 } 00102 00103 00104 int KCalendarSystem::dayStringToInteger(const QString & sNum, int & iLength) const 00105 { 00106 return stringToInteger(sNum, iLength); 00107 } 00108 00109 int KCalendarSystem::monthStringToInteger(const QString & sNum, int & iLength) const 00110 { 00111 return stringToInteger(sNum, iLength); 00112 } 00113 00114 int KCalendarSystem::yearStringToInteger(const QString & sNum, int & iLength) const 00115 { 00116 return stringToInteger(sNum, iLength); 00117 } 00118 00119 QString KCalendarSystem::weekDayName (int weekDay, bool shortName) const 00120 { 00121 if ( shortName ) 00122 switch ( weekDay ) 00123 { 00124 case 1: return locale()->translate("Monday", "Mon"); 00125 case 2: return locale()->translate("Tuesday", "Tue"); 00126 case 3: return locale()->translate("Wednesday", "Wed"); 00127 case 4: return locale()->translate("Thursday", "Thu"); 00128 case 5: return locale()->translate("Friday", "Fri"); 00129 case 6: return locale()->translate("Saturday", "Sat"); 00130 case 7: return locale()->translate("Sunday", "Sun"); 00131 } 00132 else 00133 switch ( weekDay ) 00134 { 00135 case 1: return locale()->translate("Monday"); 00136 case 2: return locale()->translate("Tuesday"); 00137 case 3: return locale()->translate("Wednesday"); 00138 case 4: return locale()->translate("Thursday"); 00139 case 5: return locale()->translate("Friday"); 00140 case 6: return locale()->translate("Saturday"); 00141 case 7: return locale()->translate("Sunday"); 00142 } 00143 00144 return QString::null; 00145 } 00146
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:43:09 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003