summaryrefslogtreecommitdiffstats
path: root/kppp/ruleset.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kppp/ruleset.cpp')
-rw-r--r--kppp/ruleset.cpp110
1 files changed, 55 insertions, 55 deletions
diff --git a/kppp/ruleset.cpp b/kppp/ruleset.cpp
index 8366131b..723d5f2b 100644
--- a/kppp/ruleset.cpp
+++ b/kppp/ruleset.cpp
@@ -29,8 +29,8 @@
#include <math.h>
#include "ruleset.h"
-#include <qregexp.h>
-#include <qfile.h>
+#include <tqregexp.h>
+#include <tqfile.h>
#include <klocale.h>
#include <kglobal.h>
@@ -51,7 +51,7 @@ RuleSet::RuleSet() {
// this function is shamelessly stolen from pppcosts 0.5 :-)
/* calculates the easter sunday in day_of_year style */
-QDate RuleSet::get_easter(int year) {
+TQDate RuleSet::get_easter(int year) {
/* not optimized, I took the original names */
signed int a,b,m,q,w,p,n,tt,mm;
@@ -71,7 +71,7 @@ QDate RuleSet::get_easter(int year) {
{tt=p+31;
mm=3;}
- return QDate(year, mm, tt);
+ return TQDate(year, mm, tt);
}
int RuleSet::dayNameToInt(const char *s) {
@@ -86,13 +86,13 @@ int RuleSet::dayNameToInt(const char *s) {
return -1;
}
-int RuleSet::load(const QString &filename) {
+int RuleSet::load(const TQString &filename) {
flat_init_costs = 0.0;
flat_init_duration = 0;
have_flat_init_costs = false;
- QFile f(filename);
+ TQFile f(filename);
// delete old rules
rules.resize(0);
@@ -113,7 +113,7 @@ int RuleSet::load(const QString &filename) {
while(!f.atEnd()) {
// read continued lines
- QString line;
+ TQString line;
bool backslashed;
do {
int br = f.readLine(buffer, sizeof(buffer));
@@ -122,12 +122,12 @@ int RuleSet::load(const QString &filename) {
else
buffer[br] = 0;
lineno++;
- line.append(QString::fromUtf8(buffer));
+ line.append(TQString::fromUtf8(buffer));
backslashed = (line.right(1) == "\\");
} while(!f.atEnd() && backslashed);
// strip whitespace
- line = line.replace(QRegExp("[ \t\r]"), "");
+ line = line.replace(TQRegExp("[ \t\r]"), "");
// skip comment lines
if((line.left(1) == "#") || line.isEmpty())
continue;
@@ -182,22 +182,22 @@ void RuleSet::addRule(RULE r) {
}
}
-bool RuleSet::parseEntry(RULE &ret, QString s, int year) {
- if(s.contains(QRegExp("^[0-9]+/[0-9]+$"))) {
+bool RuleSet::parseEntry(RULE &ret, TQString s, int year) {
+ if(s.contains(TQRegExp("^[0-9]+/[0-9]+$"))) {
int d, m;
sscanf(s.ascii(), "%d/%d", &m, &d);
ret.type = 1;
- ret.date.from = QDate(year, m, d);
- ret.date.until = QDate(year, m, d);
+ ret.date.from = TQDate(year, m, d);
+ ret.date.until = TQDate(year, m, d);
return TRUE;
}
- if(s.contains(QRegExp("^[0-9]+\\.[0-9]+$"))) {
+ if(s.contains(TQRegExp("^[0-9]+\\.[0-9]+$"))) {
int d, m;
sscanf(s.ascii(), "%d.%d", &d, &m);
ret.type = 1;
- ret.date.from = QDate(year, m, d);
- ret.date.until = QDate(year, m, d);
+ ret.date.from = TQDate(year, m, d);
+ ret.date.until = TQDate(year, m, d);
return TRUE;
}
@@ -212,10 +212,10 @@ bool RuleSet::parseEntry(RULE &ret, QString s, int year) {
}
if(s.left(6) == "easter") {
- QDate d = get_easter(year);
+ TQDate d = get_easter(year);
int off;
bool ok = TRUE;
- QString val = s.mid(6, 1000);
+ TQString val = s.mid(6, 1000);
if(val.isEmpty())
off = 0;
else
@@ -236,8 +236,8 @@ bool RuleSet::parseEntry(RULE &ret, QString s, int year) {
-bool RuleSet::parseEntries(QString s, int year,
- QTime t1, QTime t2,
+bool RuleSet::parseEntries(TQString s, int year,
+ TQTime t1, TQTime t2,
double costs, double len, double after)
{
// special rule: on() is the same as on(monday..sunday)
@@ -246,7 +246,7 @@ bool RuleSet::parseEntries(QString s, int year,
while(s.length()) {
int pos = s.find(',');
- QString token;
+ TQString token;
if(pos == -1) {
token = s;
s = "";
@@ -259,7 +259,7 @@ bool RuleSet::parseEntries(QString s, int year,
// range
RULE r;
if(token.contains("..")) {
- QString left, right;
+ TQString left, right;
left = token.left(token.find(".."));
right = token.right(token.length()-2-left.length());
RULE lr, rr;
@@ -293,7 +293,7 @@ bool RuleSet::parseEntries(QString s, int year,
return TRUE;
}
-bool RuleSet::parseTime(QTime &t1, QTime &t2, QString s) {
+bool RuleSet::parseTime(TQTime &t1, TQTime &t2, TQString s) {
if(s.isEmpty()) {
t1 = midnight();
t2 = beforeMidnight();
@@ -309,20 +309,20 @@ bool RuleSet::parseTime(QTime &t1, QTime &t2, QString s) {
}
}
-bool RuleSet::parseRate(double &costs, double &len, double &after, QString s) {
+bool RuleSet::parseRate(double &costs, double &len, double &after, TQString s) {
after = 0;
int fields = sscanf(s.ascii(), "%lf,%lf,%lf", &costs, &len, &after);
return (fields == 2) || (fields == 3);
}
-bool RuleSet::parseLine(const QString &s) {
+bool RuleSet::parseLine(const TQString &s) {
- // ### use QRegExp::cap() instead of mid() and find()
+ // ### use TQRegExp::cap() instead of mid() and find()
// for our french friends -- Bernd
- if(s.contains(QRegExp("flat_init_costs=\\(.*"))) {
+ if(s.contains(TQRegExp("flat_init_costs=\\(.*"))) {
// parse the time fields
- QString token = s.mid(s.find("flat_init_costs=(") + 17,
+ TQString token = s.mid(s.find("flat_init_costs=(") + 17,
s.find(")")-s.find("flat_init_costs=(") - 17);
// printf("TOKEN=%s\n",token.ascii());
@@ -342,11 +342,11 @@ bool RuleSet::parseLine(const QString &s) {
}
- if(s.contains(QRegExp("on\\(.*\\)between\\(.*\\)use\\(.*\\)"))) {
+ if(s.contains(TQRegExp("on\\(.*\\)between\\(.*\\)use\\(.*\\)"))) {
// parse the time fields
- QString token = s.mid(s.find("between(") + 8,
+ TQString token = s.mid(s.find("between(") + 8,
s.find(")use")-s.find("between(") - 8);
- QTime t1, t2;
+ TQTime t1, t2;
if(!parseTime(t1, t2, token))
return FALSE;
@@ -362,7 +362,7 @@ bool RuleSet::parseLine(const QString &s) {
// parse the days
token = s.mid(s.find("on(") + 3,
s.find(")betw")-s.find("on(") - 3);
- if(!parseEntries(token, QDate::currentDate().year(),
+ if(!parseEntries(token, TQDate::currentDate().year(),
t1, t2, costs, len, after))
return FALSE;
@@ -370,23 +370,23 @@ bool RuleSet::parseLine(const QString &s) {
}
// check for the name
- if(s.contains(QRegExp("name=.*"))) {
+ if(s.contains(TQRegExp("name=.*"))) {
_name = s.right(s.length()-5);
return !_name.isEmpty();
}
// check default entry
- if(s.contains(QRegExp("default=\\(.*\\)"))) {
- QString token = s.mid(9, s.length() - 10);
+ if(s.contains(TQRegExp("default=\\(.*\\)"))) {
+ TQString token = s.mid(9, s.length() - 10);
double after;
if(parseRate(default_costs, default_len, after, token))
return TRUE;
}
// check for "minimum costs"
- if(s.contains(QRegExp("minimum_costs=.*"))) {
- QString token = s.right(s.length() - strlen("minimum_costs="));
+ if(s.contains(TQRegExp("minimum_costs=.*"))) {
+ TQString token = s.right(s.length() - strlen("minimum_costs="));
bool ok;
_minimum_costs = token.toDouble(&ok);
return ok;
@@ -398,20 +398,20 @@ bool RuleSet::parseLine(const QString &s) {
return TRUE;
}
- if(s.contains(QRegExp("currency_digits=.*"))) {
- QString token = s.mid(16, s.length() - 16);
+ if(s.contains(TQRegExp("currency_digits=.*"))) {
+ TQString token = s.mid(16, s.length() - 16);
bool ok;
_currency_digits = token.toInt(&ok);
return ok && (_currency_digits >= 0);
}
// "currency_position" is deprecated so we'll simply ignore it
- if(s.contains(QRegExp("currency_position=.*")))
+ if(s.contains(TQRegExp("currency_position=.*")))
return TRUE;
// check per connection fee
- if(s.contains(QRegExp("per_connection="))) {
- QString token = s.mid(15, s.length()-15);
+ if(s.contains(TQRegExp("per_connection="))) {
+ TQString token = s.mid(15, s.length()-15);
bool ok;
pcf = token.toDouble(&ok);
return ok;
@@ -420,13 +420,13 @@ bool RuleSet::parseLine(const QString &s) {
return FALSE;
}
-void RuleSet::setStartTime(QDateTime dt){
+void RuleSet::setStartTime(TQDateTime dt){
starttime = dt;
}
-void RuleSet::getActiveRule(QDateTime dt, double connect_time, double &costs, double &len) {
+void RuleSet::getActiveRule(TQDateTime dt, double connect_time, double &costs, double &len) {
// use default costs first
costs = default_costs;
len = default_len;
@@ -450,8 +450,8 @@ void RuleSet::getActiveRule(QDateTime dt, double connect_time, double &costs, do
{
// since rules do not have a year's entry, use the one
// from dt
- QDate from = r.date.from;
- QDate until = r.date.until;
+ TQDate from = r.date.from;
+ TQDate until = r.date.until;
from.setYMD(dt.date().year(), from.month(), from.day());
until.setYMD(dt.date().year(), until.month(), until.day());
if((from <= dt.date()) && (dt.date() <= until)) {
@@ -502,11 +502,11 @@ static double round(double d, int digits) {
}
#endif
-QString RuleSet::currencySymbol() const {
+TQString RuleSet::currencySymbol() const {
return _currency_symbol.copy();
}
-QString RuleSet::currencyString(double f) const {
+TQString RuleSet::currencyString(double f) const {
return KGlobal::locale()->formatMoney(f, _currency_symbol, _currency_digits);
}
@@ -516,7 +516,7 @@ double RuleSet::perConnectionCosts() const {
}
-QString RuleSet::name() const {
+TQString RuleSet::name() const {
return _name;
}
@@ -525,21 +525,21 @@ double RuleSet::minimumCosts() const {
return _minimum_costs;
}
-QTime RuleSet::midnight() const {
- return QTime(0, 0, 0, 0);
+TQTime RuleSet::midnight() const {
+ return TQTime(0, 0, 0, 0);
}
-QTime RuleSet::beforeMidnight() const {
- return QTime(23,59,59,999);
+TQTime RuleSet::beforeMidnight() const {
+ return TQTime(23,59,59,999);
}
-int RuleSet::checkRuleFile(const QString &rulefile) {
+int RuleSet::checkRuleFile(const TQString &rulefile) {
if(rulefile == NULL) {
fputs(i18n("kppp: no rulefile specified\n").local8Bit(), stderr);
return 1;
}
- QFile fl(rulefile);
+ TQFile fl(rulefile);
if(!fl.exists()) {
fprintf(stderr, i18n("kppp: rulefile \"%s\" not found\n").local8Bit(), rulefile.local8Bit().data());
return 1;