2 * kPPP: A pppd front end for the KDE project
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
9 * This file was contributed by Mario Weilguni <mweilguni@sime.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #ifndef __RULESET__H__
28 #define __RULESET__H__
31 #include <qdatetime.h>
34 // this structure is used to save
50 // this class is used for loading and parsing of rules
53 /// create an empty rule
56 /// gcc needs a destructor (otherwise compiler error)
59 /// returns the name of the ruleset
62 /** Load a ruleset from a file. If an error occurs,
63 * returns the linenumber the error was in,
64 * otherwise 0. If the file could not be opened,
67 int load(const QString
&filename
);
69 /// returns the currency symbol
70 QString
currencySymbol() const;
72 /** returns a string representation of the
73 * of a doubleingpoint number using the
76 QString
currencyString(double val
) const;
78 /// sets the start time -- must be called when the connection has bee established
79 void setStartTime(const QDateTime
&dt
);
81 /// returns the "per-connection" costs
82 double perConnectionCosts() const;
84 /** returns the minimum number of costs (some
85 * phony companies have this
87 double minimumCosts() const;
89 /// returns the currently valid rule settings
90 void getActiveRule(const QDateTime
&dt
, double connect_time
, double &costs
, double &len
);
92 /// checks if a rulefile is ok (no parse errors...)
93 static int checkRuleFile(const QString
&);
96 /** converts an english name of a day to integer,
97 * beginning with monday=0 .. sunday=6
99 int dayNameToInt(const char *s
);
101 /// returns the date of easter-sunday for a year
102 static QDate
get_easter(int year
);
104 /// add a rule to this ruleset
105 void addRule(RULE r
);
107 /// parses on entry of the "on(...)" fields
108 bool parseEntry(RULE
&ret
, QString s
, int year
);
110 /// parses the "on(...)" fields
111 bool parseEntries(QString s
, int year
,
113 double costs
, double len
, double after
);
115 /// parses the "between(...)" time fields
116 bool parseTime(QTime
&t1
, QTime
&t2
, QString s
);
118 /// parses the "use(...)" fields
119 bool parseRate(double &costs
, double &len
, double &after
, QString s
);
121 /// parses a whole line
122 bool parseLine(const QString
&line
);
124 /// returns midnight time (00:00:00.000)
125 QTime
midnight() const;
127 /// returns the last valid time BEFORE midnight
128 QTime
beforeMidnight() const;
132 QString _currency_symbol
;
134 int _currency_digits
;
135 double default_costs
;
136 double _minimum_costs
;
139 bool have_flat_init_costs
;
140 double flat_init_duration
;
141 double flat_init_costs
;