Contact cannot be a null ptr, and it is accessed before anyway. Disscussed with kedge.
[kdenetwork.git] / kppp / ruleset.h
blob71146bc6440e17465a8fe455eb473a6404734bf6
1 /* -*- C++ -*-
2 * kPPP: A pppd front end for the KDE project
4 * $Id$
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
9 * This file was contributed by Mario Weilguni <mweilguni@sime.com>
10 * Thanks Mario !
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>
32 #include <qstring.h>
33 #include <QVector>
34 // this structure is used to save
35 // accounting rules
36 typedef struct {
37 int type;
38 double costs;
39 double len;
40 double after;
41 QTime from, until;
42 struct {
43 QDate from, until;
44 } date;
45 struct {
46 int from, until;
47 } weekday;
48 } RULE;
50 // this class is used for loading and parsing of rules
51 class RuleSet {
52 public:
53 /// create an empty rule
54 RuleSet();
56 /// gcc needs a destructor (otherwise compiler error)
57 ~RuleSet() {}
59 /// returns the name of the ruleset
60 QString name() const;
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,
65 * returns -1
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
74 * currency-settings
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 &);
95 protected:
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,
112 QTime t1, QTime t2,
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;
130 protected:
131 QString _name;
132 QString _currency_symbol;
133 QDateTime starttime;
134 int _currency_digits;
135 double default_costs;
136 double _minimum_costs;
137 double default_len;
138 double pcf;
139 bool have_flat_init_costs;
140 double flat_init_duration;
141 double flat_init_costs;
143 QVector<RULE> rules;
146 #endif