-rw-r--r-- | microkde/kdecore/klocale.cpp | 39 | ||||
-rw-r--r-- | microkde/kdecore/klocale.h | 14 |
2 files changed, 29 insertions, 24 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp index d77e251..9d7e60b 100644 --- a/microkde/kdecore/klocale.cpp +++ b/microkde/kdecore/klocale.cpp @@ -83,13 +83,13 @@ KLocale::KLocale() : mCalendarSystem( 0 ) mWeekStartsMonday = true; mHourF24Format = true; - mIntDateFormat = 0; + mIntDateFormat = Default; mLanguage = 0; mDateFormat = "%a %Y %b %d"; mDateFormatShort = "%Y-%m-%d"; mTimeZoneList << i18n ("-11:00 US/Samoa") << i18n ("-10:00 US/Hawaii") << i18n ("-09:00 US/Alaska") @@ -136,18 +136,18 @@ void KLocale::setHore24Format ( bool b ) mHourF24Format = b; } void KLocale::setWeekStartMonday( bool b ) { mWeekStartsMonday = b; } -int KLocale::getIntDateFormat( ) +KLocale::IntDateFormat KLocale::getIntDateFormat( ) { - return mIntDateFormat ; + return mIntDateFormat; } -void KLocale::setIntDateFormat( int i ) +void KLocale::setIntDateFormat( KLocale::IntDateFormat i ) { mIntDateFormat = i; } void KLocale::setLanguage( int i ) { mLanguage = i; @@ -238,15 +238,15 @@ QString KLocale::formatTime(const QTime &pTime, bool includeSecs) const } QString ret( buffer, index ); delete [] buffer; return ret; } -QString KLocale::formatDate(const QDate &pDate, bool shortFormat) const +QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const { - const QString rst = shortFormat?dateFormatShort():dateFormat(); + const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); // I'm rather safe than sorry QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; unsigned int index = 0; bool escape = false; @@ -641,41 +641,44 @@ QString KLocale::monthName(int i,bool shortName) const QString KLocale::country() const { return QString::null; } -QString KLocale::dateFormat() const -{ +QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const +{ + const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; + if ( QApplication::desktop()->width() < 480 ) { - if ( mIntDateFormat == 0 ) + if ( dformat == Default ) return "%a %d %b %Y"; - else if ( mIntDateFormat == 1 ) + else if ( dformat == Format1 ) return "%a %b %d %Y"; - else if ( mIntDateFormat == 2 ) + else if ( dformat == ISODate ) return "%a %Y %b %d"; } else { - if ( mIntDateFormat == 0 ) + if ( dformat == Default ) return "%A %d %B %Y"; - else if ( mIntDateFormat == 1 ) + else if ( dformat == Format1 ) return "%A %B %d %Y"; - else if ( mIntDateFormat == 2 ) + else if ( dformat == ISODate ) return "%A %Y %B %d"; } return mDateFormat ; } -QString KLocale::dateFormatShort() const +QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const { + const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; - if ( mIntDateFormat == 0 ) + if ( dformat == Default ) return "%d.%m.%Y"; - else if ( mIntDateFormat == 1 ) + else if ( dformat == Format1 ) return "%m.%d.%Y"; - else if ( mIntDateFormat == 2 ) + else if ( dformat == ISODate ) // = Qt::ISODate return "%Y-%m-%d"; return mDateFormatShort ; } diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h index 7470cd2..f6c0253 100644 --- a/microkde/kdecore/klocale.h +++ b/microkde/kdecore/klocale.h @@ -38,13 +38,15 @@ class KLocale QString negativeSign() const; QString translate( const char *index ) const; QString translate( const char *index, const char *fallback) const; - QString formatDate(const QDate &pDate, bool shortFormat = false) const; + enum IntDateFormat { Undefined=-1, Default=0, Format1=1, ISODate=2, Userdefined=3 }; + + QString formatDate(const QDate &pDate, bool shortFormat = false, IntDateFormat intIntDateFormat = Undefined) const; QString formatTime(const QTime &pTime, bool includeSecs = false) const; QString formatDateTime(const QDateTime &pDateTime) const; QString formatDateTime(const QDateTime &pDateTime, bool shortFormat, bool includeSecs = false) const; @@ -58,23 +60,23 @@ class KLocale QString weekDayName(int,bool=false) const; QString monthName(int,bool=false) const; QString country() const; - QString dateFormat() const; - QString dateFormatShort() const; + QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; + QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; QString timeFormat() const; void insertCatalogue ( const QString & ); KCalendarSystem *calendar(); void setHore24Format ( bool ); void setWeekStartMonday( bool ); - void setIntDateFormat( int ); - int getIntDateFormat( ); + void setIntDateFormat( IntDateFormat ); + IntDateFormat getIntDateFormat( ); void setLanguage( int ); void setDateFormat( QString ); void setDateFormatShort( QString ); QString m_decimalSymbol; QString m_thousandsSeparator; @@ -92,13 +94,13 @@ class KLocale private: QTime readTime(const QString &str, bool seconds, bool *ok) const; QDate readDate(const QString &str, bool shortFormat, bool *ok) const; KCalendarSystem *mCalendarSystem; bool mWeekStartsMonday; bool mHourF24Format; - int mIntDateFormat; + IntDateFormat mIntDateFormat; int mLanguage; QString mDateFormat; QString mDateFormatShort; QStringList mTimeZoneList; bool daylightEnabled; int mDaylightTZoffset; |