From 4b265a7de653c13310d79dc58e240ae6dbfac5e1 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 11 Jul 2010 11:27:04 +0000 Subject: [PATCH] convert to use of TimeStamp git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@555 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/dialogs/customerdlg.cpp | 2 +- src/dialogs/eventedit.cpp | 10 ++-- src/iface/msinterface.cpp | 8 +++- src/misc/misc.cpp | 107 ++++++++++++++++++++++++------------------ src/misc/misc.h | 56 ++++++++++++++-------- src/mwin/eventstab.cpp | 8 ++- src/mwin/orderstab.cpp | 7 ++- src/mwin/overview.cpp | 1 + src/wext/MOEvent.cpp | 1 - src/wext/MOOrder.cpp | 28 ++++-------- src/wext/MOOrder.h | 13 +---- 11 files changed, 133 insertions(+), 108 deletions(-) diff --git a/src/dialogs/customerdlg.cpp b/src/dialogs/customerdlg.cpp index 2ef4d9d..5c766c7 100644 --- a/src/dialogs/customerdlg.cpp +++ b/src/dialogs/customerdlg.cpp @@ -640,7 +640,7 @@ MAddressDialog::MAddressDialog(QWidget*parent,MOAddress addr) setLayout(vl=new QVBoxLayout); vl->addLayout(fl=new QFormLayout,0); if(m_addr.isValid()) - fl->addRow(tr("Last used:"),new QLabel(QDateTime::fromTime_t(m_addr.lastused()).toString())); + fl->addRow(tr("Last used:"),new QLabel(MLocalFormat().formatDateTime(m_addr.lastused()))); fl->addRow(tr("Name:"),m_name=new QLineEdit(m_addr.name())); fl->addRow(tr("Address:"),m_addr1=new QLineEdit(m_addr.addr1())); fl->addRow(tr("Address:"),m_addr2=new QLineEdit(m_addr.addr2())); diff --git a/src/dialogs/eventedit.cpp b/src/dialogs/eventedit.cpp index a325345..9a145f1 100644 --- a/src/dialogs/eventedit.cpp +++ b/src/dialogs/eventedit.cpp @@ -12,6 +12,8 @@ #include "eventedit.h" +#include "tzdata.h" + #include #include #include @@ -100,8 +102,8 @@ MEventEditor::MEventEditor(QWidget*pw,qint64 id) starttime->setDateTime(tt); endtime->setDateTime(tt.addSecs(3600)); }else{//valid event: use the date and time from event - starttime->setDateTime(QDateTime::fromTime_t(event.start())); - endtime->setDateTime(QDateTime::fromTime_t(event.end())); + starttime->setDateTime(TimeStamp(event.start())); + endtime->setDateTime(TimeStamp(event.end())); } gl->addWidget(lab=new QLabel(tr("Room/Place:")),++lctr,0); @@ -169,8 +171,8 @@ void MEventEditor::writeBack() { //copy contents to event event.settitle(title->text()); - event.setstart(starttime->dateTime().toTime_t()); - event.setend(endtime->dateTime().toTime_t()); + event.setstart(TimeStamp(starttime->dateTime(),true).toUnix()); + event.setend(TimeStamp(endtime->dateTime(),true).toUnix()); event.setiscancelled(cancelcheck->isChecked()); event.setcancelreason(cancelreason->text()); event.setdescription(description->toPlainText()); diff --git a/src/iface/msinterface.cpp b/src/iface/msinterface.cpp index e26a6e0..1315fb9 100644 --- a/src/iface/msinterface.cpp +++ b/src/iface/msinterface.cpp @@ -168,13 +168,19 @@ void MSInterface::initialize() lang.toAscii().data(), gl.errorType().toAscii().data(), gl.errorString().toAscii().data()); - goto script; + //go to fallback + gl=MTGetLanguage::query("C","qm"); + if(gl.hasError()){ + qDebug("MSInterface: cannot retrieve language 'C', giving up on languages."); + goto script; + } } servertranslation=gl.getfile().value(); QTranslator *trn=new QTranslator(this); trn->load((const uchar*)servertranslation.data(),servertranslation.size()); qApp->installTranslator(trn); qDebug("MSInterface: successfully loaded server language %s",lang.toAscii().data()); + MLocalFormat::setDefaultFormat(gl.getformats().value()); } //TODO: retrieve scripts script: ; diff --git a/src/misc/misc.cpp b/src/misc/misc.cpp index 6206874..98956f4 100644 --- a/src/misc/misc.cpp +++ b/src/misc/misc.cpp @@ -12,8 +12,12 @@ #include "misc.h" +#include + #include +#include "MOServerFormat.h" + #include #include @@ -97,6 +101,7 @@ MLocalFormat::MLocalFormat(int) { m_moneydecimals=2; m_thousanddigits=3; + m_timezone="UTC"; //set defaults setWeekDays();setShortWeekDays(); setMonths();setShortMonths(); @@ -116,6 +121,7 @@ MLocalFormat::MLocalFormat(const MOServerFormat& s) setMoneyFormat(s.currencysymbol(),s.moneydecimals(),s.moneynegative()); setNumberFormat(s.decimaldot().value().at(0),s.thousandseparator().value().at(0),s.thousanddigits().value()); setAP(s.amtext(),s.pmtext()); + setTimeZone(s.timezone()); } @@ -123,6 +129,7 @@ MLocalFormat::MLocalFormat(const MOServerFormat& s) void MLocalFormat::setDefaultFormat(const MLocalFormat& f) { defaultformat=f; + TimeStamp::setDefaultZone(f.m_timezone); } @@ -151,6 +158,7 @@ MLocalFormat& MLocalFormat::operator=(const MLocalFormat&f) m_am=f.m_am; m_pm=f.m_pm; m_moneyneg=f.m_moneyneg; + m_timezone=f.m_timezone; return *this; } @@ -160,13 +168,13 @@ void MLocalFormat::setWeekDays(const QStringList&w) { if(w.size()==0){ m_day=QStringList() + <=1 && t<=12)out+="am"; else out+="pm"; break; } case 'P':{ - int t=time.time().hour(); + int t=time.hour(); if(t>=1 && t<=12)out+="AM"; else out+="PM"; break; } - case 't':case 'T':{ + case 't':out+=time.zoneAbbreviation();break; + case 'T':{ //get diff from UTC - int d=time.secsTo(time.toUTC())/60; + int d=time.offsetFromUTC()/60; //west(-) or east(+)? QString t; if(d<0){t="+";d*=-1;}else t="-"; @@ -388,6 +410,7 @@ QString MLocalFormat::formatDateTime(const QDateTime&time,QString format)const out+=t; break; } + case 'o':out+=m_timezone;break; // % sign case '%':out+="%";break; //mistakes @@ -404,14 +427,10 @@ QString MLocalFormat::formatDateTime(const QDateTime&time,QString format)const //return result return out; } + QString MLocalFormat::formatDateTime(qint64 time,QString format)const { - return formatDateTime(unix2localTime(time),format); -} -QDateTime MLocalFormat::unix2localTime(qint64 time)const -{ - //TODO: use proper time zones - return QDateTime::fromTime_t(time); + return formatDateTime(TimeStamp(time,m_timezone),format); } QString MLocalFormat::formatNumber(qint64 n)const @@ -617,13 +636,9 @@ QRegExp MLocalFormat::moneyRegExp(bool allownegative,bool allowcurrency)const return QRegExp(r); } -qint64 MLocalFormat::localTime2unix(QDateTime ) const -{ -//TODO!! -} - -void MLocalFormat::setTimeZone(QString olsenname) +void MLocalFormat::setTimeZone(QString olsonname) { -//TODO!! + if(TimeStamp::loadZone(olsonname)) + m_timezone=olsonname; } diff --git a/src/misc/misc.h b/src/misc/misc.h index 673e294..1671376 100644 --- a/src/misc/misc.h +++ b/src/misc/misc.h @@ -18,7 +18,8 @@ #include #include -#include "MOServerFormat.h" +class TimeStamp; +class MOServerFormat; /**converts special HTML characters into harmless &-codes, so the text can be included*/ QString htmlize(QString str); @@ -76,6 +77,8 @@ time values can be formatted with the following variables: %%p"am" or "pm" according to current time, this is the one set with setAP %%P"AM" or "PM" according to current time, this is toUpper executed on the one set with setAP %%TISO timezone as +/-hhmm (eg. -0100 or +0100) - does not work reliably on all systems +%%ttimezone as abbreviation - the abbreviation comes from the background time zone DB and is not globally unique (eg. "CET") +%%otimezone as Olson name (eg. "Europe/Berlin") Any occurrence of "%%" will be translated to a literal "%" sign. @@ -100,9 +103,9 @@ class MLocalFormat /**copies a formatter object*/ virtual MLocalFormat& operator=(const MLocalFormat&); - /**overrides the full names of week days, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Monday*/ + /**overrides the full names of week days, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday*/ virtual void setWeekDays(const QStringList&l=QStringList()); - /**overrides the short week day names, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Monday (Mon)*/ + /**overrides the short week day names, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday (Sun)*/ virtual void setShortWeekDays(const QStringList&l=QStringList()); /**overrides the full names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January*/ @@ -126,36 +129,53 @@ class MLocalFormat virtual void setAP(QString am="--",QString pm="--"); /**overrides the local time zone - \param olsenname the name of the local timezone in olsen notation, eg. "Europe/Berlin" - \param transitions a list of time transitions, if missing the system attempts to locate the transition DB itself*/ - virtual void setTimeZone(QString olsenname); + \param olsenname the name of the local timezone in Olson notation, eg. "Europe/Berlin"*/ + virtual void setTimeZone(QString olsonname); + + /**returns the currently set time zone of this formatter*/ + virtual QString timeZone()const{return m_timezone;} /**overrides the formatting to be non-localized, numbers use decimal dot and no thousand separator, no currency symbol and "-" as negative sign; otherwise things stay the same; this is a helper for the shortcut methods like cent2str*/ virtual void setNonLocalized(); /**formats a date according to the given format, if none is given, the translation default is used - \param date a QDate used as input, it is assumed to be local, even if Qt sais it is UTC - \param format a format string as specified by QDate::toString */ + \param date a QDate used as input, it is assumed to be local + \param format a format string */ virtual QString formatDate(const QDate&date,QString format=QString())const; /**formats a date according to the given format, if none is given, the translation default is used - \param date a unix timestamp, it is converted to local time*/ + \param date a unix timestamp, it is converted to the local time of this local format object + \param format a format string */ virtual QString formatDate(qint64 date,QString format=QString())const; + /**formats a date according to the given format, if none is given, the translation default is used + \param date a timestamp, it is converted to the local time of this local format object + \param format a format string */ + virtual QString formatDate(const TimeStamp& date,QString format=QString())const; /**formats a time according to the given format, if none is given, the translation default is used - \param time a QTime used as input - \param format a format string as specified by QTime::toString */ + \param time a QTime used as input, it is assumed to be local + \param format a format string */ virtual QString formatTime(const QTime&time,QString format=QString())const; /**formats a time according to the given format, if none is given, the translation default is used - \param time a unix timestamp, it is converted to local time*/ + \param time a unix timestamp, it is converted to local time + \param format a format string */ virtual QString formatTime(qint64 time,QString format=QString())const; + /**formats a time according to the given format, if none is given, the translation default is used + \param time a timestamp, it is converted to the local time of this local format object + \param format a format string */ + virtual QString formatTime(const TimeStamp& time,QString format=QString())const; /**formats a date and time according to the given format, if none is given, the translation default is used - \param time a QDateTime used as input + \param time a QDateTime used as input, it is assumed to be local \param format a format string as specified by QDateTime::toString */ virtual QString formatDateTime(const QDateTime&time,QString format=QString())const; /**formats a date and time according to the given format, if none is given, the translation default is used - \param time a unix timestamp, it is converted to local time*/ + \param time a unix timestamp, it is converted to local time + \param format a format string as specified by QDateTime::toString */ virtual QString formatDateTime(qint64 time,QString format=QString())const; + /**formats a date and time according to the given format, if none is given, the translation default is used + \param time a TimeStamp used as input, it is converted to the local time of this local format object + \param format a format string as specified by QDateTime::toString */ + virtual QString formatDateTime(const TimeStamp&time,QString format=QString())const; /**formats an integer number*/ @@ -220,16 +240,10 @@ class MLocalFormat QRegExp moneyRegExp(bool allownegative=false,bool allowcurrency=false)const; protected: QStringList m_day,m_sday,m_month,m_smonth; - QString m_currency,m_am,m_pm,m_moneyneg; + QString m_currency,m_am,m_pm,m_moneyneg,m_timezone; QChar m_decimal,m_thousand; int m_moneydecimals,m_thousanddigits; - /** \internal helper to convert a unix timestamp to local time*/ - virtual QDateTime unix2localTime(qint64)const; - - /** \internal helper to convert a local timestamp to unix time*/ - virtual qint64 localTime2unix(QDateTime)const; - /** \internal constructs the default object from the translation*/ MLocalFormat(int); /** \internal default format*/ diff --git a/src/mwin/eventstab.cpp b/src/mwin/eventstab.cpp index c966fe9..51f9ceb 100644 --- a/src/mwin/eventstab.cpp +++ b/src/mwin/eventstab.cpp @@ -20,6 +20,8 @@ #include "eventstab.h" +#include "tzdata.h" + #include #include #include @@ -113,7 +115,7 @@ void MEventsTab::updateEvents() } QListevl=gae.getevents(); //calculate max age - QDateTime now=QDateTime::currentDateTime().addDays(-1); + TimeStamp now=TimeStamp::now(); bool showveryold=false; bool showold; if(showoldevents)showold=showoldevents->isChecked(); @@ -123,7 +125,7 @@ void MEventsTab::updateEvents() set.beginGroup("profiles/"+profilekey); int maxage=set.value("maxeventage", 0).toInt(); if(maxage==0)showveryold=true; - now=now.addDays(-maxage); + now.addDays(-maxage); } //fill model eventmodel->clear(); @@ -131,7 +133,7 @@ void MEventsTab::updateEvents() eventmodel->setHorizontalHeaderLabels(QStringList()<insertRow(j); diff --git a/src/mwin/orderstab.cpp b/src/mwin/orderstab.cpp index 731495f..b275390 100644 --- a/src/mwin/orderstab.cpp +++ b/src/mwin/orderstab.cpp @@ -20,6 +20,8 @@ #include "orderstab.h" +#include "tzdata.h" + #include #include #include @@ -109,7 +111,8 @@ qint64 MOrdersTab::oldestOrderStamp(int age) //zero means no limit if(age<=0)return 0; //calculate - return QDateTime::currentDateTime().addDays(-age).toTime_t(); + TimeStamp ts=TimeStamp::now();ts.addDays(-age); + return ts.toUnix(); } //helper: finds out whether an order should be printed. @@ -179,7 +182,7 @@ void MOrdersTab::orderSinceDate() d.setLayout(vl=new QVBoxLayout); vl->addWidget(new QLabel(tr("Please select the date and time:"))); QDateTimeEdit*dte; - vl->addWidget(dte=new QDateTimeEdit(QDateTime::fromTime_t(oldestOrderStamp()))); + vl->addWidget(dte=new QDateTimeEdit(TimeStamp(oldestOrderStamp()).toDateTime())); dte->setDisplayFormat(tr("ddd MMMM d yyyy, h:mm ap","time format")); dte->setCalendarPopup(true); vl->addSpacing(10);vl->addStretch(1); diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index 00c8616..b7e57a2 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -25,6 +25,7 @@ #include "overview.h" #include "centbox.h" +#include "tzdata.h" #include #include diff --git a/src/wext/MOEvent.cpp b/src/wext/MOEvent.cpp index f0e24d3..1e858b6 100644 --- a/src/wext/MOEvent.cpp +++ b/src/wext/MOEvent.cpp @@ -13,7 +13,6 @@ #include "MOEvent.h" #include -#include #include #include diff --git a/src/wext/MOOrder.cpp b/src/wext/MOOrder.cpp index 211f007..75d010c 100644 --- a/src/wext/MOOrder.cpp +++ b/src/wext/MOOrder.cpp @@ -60,49 +60,39 @@ bool MOOrder::isSent()const return status()!=Placed; } -QDateTime MOOrder::orderDateTime() +TimeStamp MOOrder::orderDateTime() { - if(ordertime().value()==0)return QDateTime(); - return QDateTime::fromTime_t(ordertime()); + if(ordertime().value()==0)return TimeStamp(); + return TimeStamp(ordertime()); } QString MOOrder::orderDateTimeStr() { if(ordertime().value()==0)return ""; - return QDateTime::fromTime_t(ordertime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd hh:mm ap","date/time format")); -} - -QDate MOOrder::orderDate() -{ - return QDateTime::fromTime_t(ordertime()).date(); + return unix2dateTime(ordertime()); } QString MOOrder::orderDateStr() { if(ordertime().value()==0)return ""; - return QDateTime::fromTime_t(ordertime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd","date format")); + return unix2date(ordertime()); } -QDateTime MOOrder::sentDateTime() +TimeStamp MOOrder::sentDateTime() { - return QDateTime::fromTime_t(senttime()); + return TimeStamp(senttime()); } QString MOOrder::sentDateTimeStr() { if(senttime().value()==0)return ""; - return QDateTime::fromTime_t(senttime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd hh:mm ap","date/time format")); -} - -QDate MOOrder::sentDate() -{ - return QDateTime::fromTime_t(senttime()).date(); + return unix2dateTime(senttime()); } QString MOOrder::sentDateStr() { if(senttime().value()==0)return ""; - return QDateTime::fromTime_t(senttime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd","date format")); + return unix2date(senttime()); } QString MOOrder::fullInvoiceAddress(bool allowfallback)const diff --git a/src/wext/MOOrder.h b/src/wext/MOOrder.h index 36dcca5..2f6f467 100644 --- a/src/wext/MOOrder.h +++ b/src/wext/MOOrder.h @@ -16,8 +16,7 @@ #include "MOOrderAbstract.h" #include "misc.h" -#include -#include +#include "tzdata.h" /**this class represents a complete order*/ class MOOrder:public MOOrderAbstract @@ -69,26 +68,20 @@ class MOOrder:public MOOrderAbstract QString amountToRefundStr()const{return cent2str(amountToRefund());} /**return the order date+time*/ - QDateTime orderDateTime(); + TimeStamp orderDateTime(); /**returns the order date+time as string*/ QString orderDateTimeStr(); - /**returns the order date only*/ - QDate orderDate(); - /**returns the order date only as string*/ QString orderDateStr(); /**returns the shipping date+time*/ - QDateTime sentDateTime(); + TimeStamp sentDateTime(); /**returns the shipping date+time as string*/ QString sentDateTimeStr(); - /**returns the shipping date only*/ - QDate sentDate(); - /**returns the shipping date only as string*/ QString sentDateStr(); -- 1.7.2.5