summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--microkde/kconfig.cpp26
-rw-r--r--microkde/kconfig.h3
-rw-r--r--microkde/kdecore/klocale.cpp47
-rw-r--r--microkde/kdecore/klocale.h11
4 files changed, 74 insertions, 13 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp
index 4cbec94..ba41f6c 100644
--- a/microkde/kconfig.cpp
+++ b/microkde/kconfig.cpp
@@ -88,48 +88,67 @@ QValueList<int> KConfig::readIntListEntry( const QString & key)
return result;
}
int KConfig::readNumEntry( const QString & key, int def )
{
QString res = readEntry(key, QString::number(def ) );
bool ok = false;
int result = res.toInt(&ok);
if ( ok )
return result;
return def;
}
QString KConfig::readEntry( const QString &key, const QString &def )
{
QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key );
if ( it == mStringMap.end() ) {
return def;
}
return *it;
}
+QSize KConfig::readSizeEntry( const QString &key, QSize* def )
+{
+ QValueList<int> intlist = readIntListEntry(key);
+
+ if (intlist.count() < 2)
+ {
+ if (def)
+ return *def;
+ else
+ return QSize();
+ }
+
+ QSize ret;
+ ret.setWidth(intlist[0]);
+ ret.setHeight(intlist[1]);
+
+ return ret;
+}
+
QStringList KConfig::readListEntry( const QString &key )
{
QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key );
if ( it == mStringMap.end() ) {
return QStringList();
}
return QStringList::split(":", *it );
}
bool KConfig::readBoolEntry( const QString &key, bool def )
{
QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key );
if ( it == mBoolMap.end() ) {
return def;
}
return *it;
}
QColor KConfig::readColorEntry( const QString & e, QColor *def )
{
@@ -201,48 +220,55 @@ void KConfig::writeEntry( const QString &key, const QString &value )
void KConfig::writeEntry( const QString &key, const QStringList &value )
{
mStringMap.insert( mGroup + key, value.join(":") );
mDirty = true;
}
void KConfig::writeEntry( const QString &key, bool value)
{
mBoolMap.insert( mGroup + key, value );
mDirty = true;
}
void KConfig::writeEntry( const QString & e, const QColor & c )
{
QStringList l;
l.append( QString::number ( c.red() ) );
l.append( QString::number ( c.green() ) );
l.append( QString::number ( c.blue() ) );
writeEntry( e, l );
}
+void KConfig::writeEntry( const QString & e, const QSize & s )
+{
+ QValueList<int> intlist;
+ intlist << s.width() << s.height();
+ writeEntry( e, intlist );
+}
+
void KConfig::writeEntry( const QString & e , const QFont & f )
{
QStringList font;
font.append( f.family());
font.append( (!f.bold ()?"nonbold":"bold") );
font.append( QString::number ( f.pointSize () ) );
font.append( !f.italic ()?"nonitalic":"italic" );
writeEntry( e, font );
}
void KConfig::writeEntry( const QString &key, const QDateTime &dt )
{
mDateTimeMap.insert( mGroup + key, dt );
}
void KConfig::load()
{
QFile f( mFileName );
if ( !f.open( IO_ReadOnly ) ) {
qDebug("KConfig: could not open file %s ",mFileName.latin1() );
return;
}
diff --git a/microkde/kconfig.h b/microkde/kconfig.h
index a01b1a5..1a1038f 100644
--- a/microkde/kconfig.h
+++ b/microkde/kconfig.h
@@ -45,60 +45,61 @@ class KConfig
bool deleteGroup( const QString& group);
//US I took the following hasGroup method from a newer version from KDE.
/**
* Returns true if the specified group is known about.
*
* @param group The group to search for.
* @return Whether the group exists.
*/
bool hasGroup(const QString &group) const;
QString getFileName();
//US added method readIntListEntry
QValueList<int> readIntListEntry( const QString &);
int readNumEntry( const QString &, int def=0 );
QString readEntry( const QString &, const QString &def=QString::null );
QStringList readListEntry( const QString & );
bool readBoolEntry( const QString &, bool def=false );
QColor readColorEntry( const QString &, QColor * );
QFont readFontEntry( const QString &, QFont * );
QDateTime readDateTimeEntry( const QString &, const QDateTime *pDefault = 0 );
-
+ QSize readSizeEntry(const QString &, QSize* );
bool hasKey( const QString &);
void writeEntry( const QString &, const QValueList<int>& );
void writeEntry( const QString &, int );
void writeEntry( const QString &key , unsigned int value) { writeEntry( key, int( value ) ); }
void writeEntry( const char *key , unsigned int value) { writeEntry( QString( key ), value ); }
void writeEntry( const char *key, int value ) { writeEntry( QString( key ), value ); }
void writeEntry( const QString &, const QString & );
void writeEntry( const char *key, const QString &value ) { writeEntry( QString( key ), value ); }
void writeEntry( const QString &, const QStringList & );
void writeEntry( const QString &, bool );
void writeEntry( const char *key, bool value ) { writeEntry( QString( key ), value ); }
void writeEntry( const QString &, const QColor & );
void writeEntry( const QString &, const QFont & );
void writeEntry( const QString &, const QDateTime & );
+ void writeEntry( const QString &, const QSize & );
void deleteEntry( const QString &);
void load();
void sync();
private:
static QString mGroup;
QString mTempGroup;
QString mFileName;
QMap<QString,bool> mBoolMap;
QMap<QString,QString> mStringMap;
QMap<QString,QDateTime> mDateTimeMap;
bool mDirty;
};
#endif
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index 9d7e60b..4960b9a 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -66,48 +66,49 @@ static int readInt(const QString &str, uint &pos)
int result = 0;
for (; str.length() > pos && str.at(pos).isDigit(); pos++)
{
result *= 10;
result += str.at(pos).digitValue();
}
return result;
}
KLocale::KLocale() : mCalendarSystem( 0 )
{
m_decimalSymbol = ".";
m_positiveSign = "";
m_negativeSign = "-";
m_thousandsSeparator = ",";
mWeekStartsMonday = true;
mHourF24Format = true;
mIntDateFormat = Default;
+ mIntTimeFormat = 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")
<< i18n ("-08:00 US/Pacific")
<< i18n ("-07:00 US/Mountain")
<< i18n ("-06:00 US/Central")
<< i18n ("-05:00 US/Eastern")
<< i18n ("-04:00 Brazil/West")
<< i18n ("-03:00 Brazil/East")
<< i18n ("-02:00 Brazil/DeNoronha")
<< i18n ("-01:00 Atlantic/Azores")
<< i18n (" 00:00 Europe/London(UTC)")
<< i18n ("+01:00 Europe/Oslo(CET)")
<< i18n ("+02:00 Europe/Helsinki")
<< i18n ("+03:00 Europe/Moscow")
<< i18n ("+04:00 Indian/Mauritius")
<< i18n ("+05:00 Indian/Maldives")
<< i18n ("+06:00 Indian/Chagos")
<< i18n ("+07:00 Asia/Bangkok")
<< i18n ("+08:00 Asia/Hongkong")
<< i18n ("+09:00 Asia/Tokyo")
@@ -118,74 +119,85 @@ KLocale::KLocale() : mCalendarSystem( 0 )
<< i18n (" Local Time");
mSouthDaylight = false;
mTimeZoneOffset = 0;
daylightEnabled = false;
}
void KLocale::setDateFormat( QString s )
{
mDateFormat = s;
}
void KLocale::setDateFormatShort( QString s )
{
mDateFormatShort = s;
}
void KLocale::setHore24Format ( bool b )
{
mHourF24Format = b;
}
void KLocale::setWeekStartMonday( bool b )
{
mWeekStartsMonday = b;
}
+
KLocale::IntDateFormat KLocale::getIntDateFormat( )
{
return mIntDateFormat;
}
void KLocale::setIntDateFormat( KLocale::IntDateFormat i )
{
mIntDateFormat = i;
}
+KLocale::IntDateFormat KLocale::getIntTimeFormat( )
+{
+ return mIntTimeFormat;
+
+}
+void KLocale::setIntTimeFormat( KLocale::IntDateFormat i )
+{
+ mIntTimeFormat = i;
+}
+
void KLocale::setLanguage( int i )
{
mLanguage = i;
}
QString KLocale::translate( const char *index ) const
{
return i18n( index );
}
QString KLocale::translate( const char *, const char *fallback) const
{
return i18n( fallback );
}
-QString KLocale::formatTime(const QTime &pTime, bool includeSecs) const
+QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const
{
- const QString rst = timeFormat();
+ const QString rst = timeFormat(intIntDateFormat);
// only "pm/am" here can grow, the rest shrinks, but
// I'm rather safe than sorry
QChar *buffer = new QChar[rst.length() * 3 / 2 + 30];
uint index = 0;
bool escape = false;
int number = 0;
for ( uint format_index = 0; format_index < rst.length(); format_index++ )
{
if ( !escape )
{
if ( rst.at( format_index ).unicode() == '%' )
escape = true;
else
buffer[index++] = rst.at( format_index );
}
else
{
switch ( rst.at( format_index ).unicode() )
{
case '%':
buffer[index++] = '%';
@@ -294,58 +306,59 @@ QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat
break;
case 'd':
put_it_in( buffer, index, pDate.day() );
break;
case 'a':
put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) );
break;
case 'A':
put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) );
break;
default:
buffer[index++] = rst.at( format_index );
break;
}
escape = false;
}
}
QString ret( buffer, index );
delete [] buffer;
return ret;
}
QString KLocale::formatDateTime(const QDateTime &pDateTime,
bool shortFormat,
- bool includeSeconds) const
+ bool includeSeconds,
+ IntDateFormat intIntDateFormat) const
{
return QString( "%1 %2")
- .arg( formatDate( pDateTime.date(), shortFormat ) )
- .arg( formatTime( pDateTime.time(), includeSeconds ) );
+ .arg( formatDate( pDateTime.date(), shortFormat, intIntDateFormat ) )
+ .arg( formatTime( pDateTime.time(), includeSeconds , intIntDateFormat ) );
}
-QString KLocale::formatDateTime(const QDateTime &pDateTime) const
+QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const
{
- return formatDateTime(pDateTime, true);
+ return formatDateTime(pDateTime, true, intIntDateFormat);
}
QDate KLocale::readDate(const QString &intstr, bool* ok) const
{
QDate date;
date = readDate(intstr, true, ok);
if (date.isValid()) return date;
return readDate(intstr, false, ok);
}
QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const
{
QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace();
return readDate( intstr, fmt, ok );
}
QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const
{
//kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl;
QString str = intstr.simplifyWhiteSpace().lower();
int day = -1, month = -1;
// allow the year to be omitted if not in the format
int year = QDate::currentDate().year();
uint strpos = 0;
@@ -435,48 +448,49 @@ QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) con
if (ok) *ok = true;
return QDate(year, month, day);
}
error:
if (ok) *ok = false;
return QDate(); // invalid date
}
QTime KLocale::readTime(const QString &intstr, bool *ok) const
{
QTime _time;
_time = readTime(intstr, true, ok);
if (_time.isValid()) return _time;
return readTime(intstr, false, ok);
}
QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
{
QString str = intstr.simplifyWhiteSpace().lower();
QString Format = timeFormat().simplifyWhiteSpace();
if (!seconds)
Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null);
int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds
+
bool g_12h = false;
bool pm = false;
uint strpos = 0;
uint Formatpos = 0;
while (Format.length() > Formatpos || str.length() > strpos)
{
if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error;
QChar c = Format.at(Formatpos++);
if (c != '%')
{
if (c.isSpace())
strpos++;
else if (c != str.at(strpos++))
goto error;
continue;
}
// remove space at the begining
if (str.length() > strpos && str.at(strpos).isSpace())
strpos++;
@@ -661,53 +675,70 @@ QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const
return "%A %d %B %Y";
else if ( dformat == Format1 )
return "%A %B %d %Y";
else if ( dformat == ISODate )
return "%A %Y %B %d";
}
return mDateFormat ;
}
QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const
{
const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
if ( dformat == Default )
return "%d.%m.%Y";
else if ( dformat == Format1 )
return "%m.%d.%Y";
else if ( dformat == ISODate ) // = Qt::ISODate
return "%Y-%m-%d";
return mDateFormatShort ;
}
-QString KLocale::timeFormat() const
+QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const
{
+ const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat;
+
+ if ( tformat == Default )
if ( mHourF24Format)
return "%H:%M:%S";
+ else
return "%I:%M:%S%p";
+
+ else if ( tformat == Format1 )
+ if ( mHourF24Format)
+ return "%H:%M:%S";
+ else
+ return "%I:%M:%S%p";
+
+ else if ( tformat == ISODate ) // = Qt::ISODate
+ if ( mHourF24Format)
+ return "%H:%M:%S";
+ else
+ return "%I:%M:%S%p";
+
}
void KLocale::insertCatalogue ( const QString & )
{
}
KCalendarSystem *KLocale::calendar()
{
if ( !mCalendarSystem ) {
mCalendarSystem = new KCalendarSystemGregorian;
}
return mCalendarSystem;
}
int KLocale::timezoneOffset( QString timeZone )
{
int ret = 1001;
int index = mTimeZoneList.findIndex( timeZone );
if ( index < 24 )
ret = ( index-11 ) * 60 ;
return ret;
}
diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h
index f6c0253..153b12a 100644
--- a/microkde/kdecore/klocale.h
+++ b/microkde/kdecore/klocale.h
@@ -23,90 +23,93 @@ inline QString tr2i18n(const char* message, const char* =0) {
return i18n( message);
}
class KLocale
{
public:
KLocale();
QString formatNumber(double num, int precision = -1) const;
QString formatNumber(const QString &numStr) const;
double readNumber(const QString &numStr, bool * ok = 0) const;
QString decimalSymbol() const;
QString thousandsSeparator() const;
QString positiveSign() const;
QString negativeSign() const;
QString translate( const char *index ) const;
QString translate( const char *index, const char *fallback) 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 formatTime(const QTime &pTime, bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const;
+ QString formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat = Undefined) const;
QString formatDateTime(const QDateTime &pDateTime,
bool shortFormat,
- bool includeSecs = false) const;
+ bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const;
QDate readDate(const QString &str, bool* ok = 0) const;
QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const;
QTime readTime(const QString &str, bool* ok = 0) const;
bool use12Clock() const;
bool weekStartsMonday() const;
int weekStartDay() const;
QString weekDayName(int,bool=false) const;
QString monthName(int,bool=false) const;
QString country() const;
QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const;
QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const;
- QString timeFormat() const;
+ QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const;
void insertCatalogue ( const QString & );
KCalendarSystem *calendar();
void setHore24Format ( bool );
void setWeekStartMonday( bool );
void setIntDateFormat( IntDateFormat );
+ void setIntTimeFormat( IntDateFormat );
IntDateFormat getIntDateFormat( );
+ IntDateFormat getIntTimeFormat( );
void setLanguage( int );
void setDateFormat( QString );
void setDateFormatShort( QString );
QString m_decimalSymbol;
QString m_thousandsSeparator;
QString m_currencySymbol;
QString m_monetaryDecimalSymbol;
QString m_monetaryThousandsSeparator;
QString m_positiveSign;
QString m_negativeSign;
int timezoneOffset( QString );
QStringList timeZoneList() const;
void setDaylightSaving( bool, int , int );
int localTimeOffset(const QDateTime &);
void setTimezone( const QString &timeZone );
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;
IntDateFormat mIntDateFormat;
+ IntDateFormat mIntTimeFormat;
int mLanguage;
QString mDateFormat;
QString mDateFormatShort;
QStringList mTimeZoneList;
bool daylightEnabled;
int mDaylightTZoffset;
int mNondaylightTZoffset;
bool mSouthDaylight;
int daylightStart, daylightEnd, mTimeZoneOffset;
};
#endif