summaryrefslogtreecommitdiffabout
path: root/microkde/kdecore/klocale.cpp
Side-by-side diff
Diffstat (limited to 'microkde/kdecore/klocale.cpp') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdecore/klocale.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index 1d8ae9f..dd310fa 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -1,100 +1,101 @@
#include <qregexp.h>
#include <qapplication.h>
+#include <QDesktopWidget>
#include "kdebug.h"
#include "kcalendarsystemgregorian.h"
#include "klocale.h"
#include <qstringlist.h>
//#define COLLECT_TRANSLATION
-QDict<QString> *mLocaleDict = 0;
-void setLocaleDict( QDict<QString> * dict )
+Q3Dict<QString> *mLocaleDict = 0;
+void setLocaleDict( Q3Dict<QString> * dict )
{
mLocaleDict = dict;
}
#ifdef COLLECT_TRANSLATION
QStringList missingTrans;
QStringList existingTrans1;
QStringList existingTrans2;
void addMissing(const char *text)
{
QString mis ( text );
if ( !missingTrans.contains( mis ) )
missingTrans.append(mis);
}
void addExist(const char *text,QString trans )
{
//return;
QString mis ( text );
if ( !existingTrans1.contains( mis ) ) {
existingTrans1.append(mis);
existingTrans2.append(trans);
}
}
#include <qfile.h>
-#include <qtextstream.h>
+#include <q3textstream.h>
#include <qtextcodec.h>
#endif
void dumpMissing()
{
#ifdef COLLECT_TRANSLATION
QString fileName = "/tmp/usernewtrans.txt";
QFile file( fileName );
- if (!file.open( IO_WriteOnly ) ) {
+ if (!file.open( QIODevice::WriteOnly ) ) {
return ;
}
- QTextStream ts( &file );
+ Q3TextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
int i;
for ( i = 0; i< missingTrans.count(); ++i ) {
QString text = missingTrans[i].replace( QRegExp("\n"),"\\n" );
ts << "{ \""<<text<< "\",\""<< text <<"\" },\n";
}
file.close();
{
QString fileName = "/tmp/usertrans.txt";
QFile file( fileName );
- if (!file.open( IO_WriteOnly ) ) {
+ if (!file.open( QIODevice::WriteOnly ) ) {
return ;
}
- QTextStream ts( &file );
+ Q3TextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
int i;
for ( i = 0; i< existingTrans1.count(); ++i ) {
QString text = existingTrans1[i].replace( QRegExp("\n"),"\\n" );
QString text2 = existingTrans2[i].replace( QRegExp("\n"),"\\n" );
ts << "{ \""<<text<< "\",\""<< text2 <<"\" },\n";
}
file.close();
}
#endif
}
QString i18n(const char *text)
{
if ( ! mLocaleDict ) {
#ifdef COLLECT_TRANSLATION
addMissing( text );
#endif
return QString( text );
}
else {
QString* ret = mLocaleDict->find(QString(text)) ;
@@ -446,49 +447,49 @@ QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat
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,
IntDateFormat intIntDateFormat) const
{
QString format("%1 %2");
if ( intIntDateFormat == Default )
format = "%1 %2";
else if ( intIntDateFormat == Format1 )
format = "%1 %2";
- else if ( intIntDateFormat == ISODate )
+ else if ( intIntDateFormat == Qt::ISODate )
format = "%1T%2";
QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat ))
.arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat ));
//qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() );
return res;
}
QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const
{
return formatDateTime(pDateTime, true, 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
@@ -506,49 +507,49 @@ QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) con
int year = QDate::currentDate().year();
uint strpos = 0;
uint fmtpos = 0;
while (fmt.length() > fmtpos || str.length() > strpos)
{
if ( !(fmt.length() > fmtpos && str.length() > strpos) )
goto error;
QChar c = fmt.at(fmtpos++);
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++;
c = fmt.at(fmtpos++);
- switch (c)
+ switch (c.unicode())
{
case 'a':
case 'A':
// this will just be ignored
{ // Cristian Tache: porting to Win: Block added because of "j" redefinition
for (int j = 1; j < 8; j++) {
QString s = weekDayName(j, c == 'a').lower();
int len = s.length();
if (str.mid(strpos, len) == s)
strpos += len;
}
break;
}
case 'b':
case 'B':
{ // Cristian Tache: porting to Win: Block added because of "j" redefinition
for (int j = 1; j < 13; j++) {
QString s = monthName(j, c == 'b').lower();
int len = s.length();
if (str.mid(strpos, len) == s) {
month = j;
strpos += len;
}
}
@@ -617,49 +618,49 @@ QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
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++;
c = Format.at(Formatpos++);
- switch (c)
+ switch (c.unicode())
{
case 'p':
{
QString s;
s = i18n("pm").lower();
int len = s.length();
if (str.mid(strpos, len) == s)
{
pm = true;
strpos += len;
}
else
{
s = i18n("am").lower();
len = s.length();
if (str.mid(strpos, len) == s) {
pm = false;
strpos += len;
}
else
goto error;
}
}
break;
@@ -713,49 +714,49 @@ QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
// The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime.
}
QDateTime KLocale::readDateTime(const QString &intstr,
IntDateFormat intIntDateFormat,
bool* ok) const
{
bool ok1, ok2;
// AT the moment we can not read any other format then ISODate
if ( intIntDateFormat != ISODate )
{
qDebug("KLocale::readDateTime, only ISODate is supported.");
return QDateTime();
}
int pos = intstr.find("T");
QString date = intstr.left(pos);
QString time = intstr.mid(pos+1);
QString dformat = dateFormat(intIntDateFormat);
QString tformat = timeFormat(intIntDateFormat);
QDate m_date = readDate(date, dformat, &ok1);
- QTime m_time = readTime(time, tformat, &ok2);
+ QTime m_time = readTime(time, !tformat.isEmpty(), &ok2);
QDateTime m_dt;
if (ok)
{
if ((ok1 == false) || (ok2 == false))
*ok = false;
else
*ok = true;
}
//only set values if both operations returned true.
if ((ok1 == true) && (ok2 == true))
{
m_dt.setDate(m_date);
m_dt.setTime(m_time);
}
//qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2);
return m_dt;
}
QDate KLocale::readDate(const QString &intstr,
IntDateFormat intIntDateFormat,