1 | /* -*- C++ -*- |
2 | * kPPP: A pppd front end for the KDE project |
3 | * |
4 | * $Id$ |
5 | * |
6 | * Copyright (C) 1997 Bernd Johannes Wuebben |
7 | * wuebben@math.cornell.edu |
8 | * |
9 | * This file was contributed by Mario Weilguni <mweilguni@sime.com> |
10 | * Thanks Mario ! |
11 | * |
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. |
16 | * |
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. |
21 | * |
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. |
25 | */ |
26 | |
27 | #ifndef __RULESET__H__ |
28 | #define __RULESET__H__ |
29 | |
30 | |
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; |
49 | |
50 | // this class is used for loading and parsing of rules |
51 | class RuleSet { |
52 | public: |
53 | /// create an empty rule |
54 | RuleSet(); |
55 | |
56 | /// gcc needs a destructor (otherwise compiler error) |
57 | ~RuleSet() {} |
58 | |
59 | /// returns the name of the ruleset |
60 | QString name() const; |
61 | |
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 |
66 | */ |
67 | int load(const QString &filename); |
68 | |
69 | /// returns the currency symbol |
70 | QString currencySymbol() const; |
71 | |
72 | /** returns a string representation of the |
73 | * of a doubleingpoint number using the |
74 | * currency-settings |
75 | */ |
76 | QString currencyString(double val) const; |
77 | |
78 | /// sets the start time -- must be called when the connection has bee established |
79 | void setStartTime(const QDateTime &dt); |
80 | |
81 | /// returns the "per-connection" costs |
82 | double perConnectionCosts() const; |
83 | |
84 | /** returns the minimum number of costs (some |
85 | * phony companies have this |
86 | */ |
87 | double minimumCosts() const; |
88 | |
89 | /// returns the currently valid rule settings |
90 | void getActiveRule(const QDateTime &dt, double connect_time, double &costs, double &len); |
91 | |
92 | /// checks if a rulefile is ok (no parse errors...) |
93 | static int checkRuleFile(const QString &); |
94 | |
95 | protected: |
96 | /** converts an english name of a day to integer, |
97 | * beginning with monday=0 .. sunday=6 |
98 | */ |
99 | int dayNameToInt(const char *s); |
100 | |
101 | /// returns the date of easter-sunday for a year |
102 | static QDate get_easter(int year); |
103 | |
104 | /// add a rule to this ruleset |
105 | void addRule(RULE r); |
106 | |
107 | /// parses on entry of the "on(...)" fields |
108 | bool parseEntry(RULE &ret, QString s, int year); |
109 | |
110 | /// parses the "on(...)" fields |
111 | bool parseEntries(QString s, int year, |
112 | QTime t1, QTime t2, |
113 | double costs, double len, double after); |
114 | |
115 | /// parses the "between(...)" time fields |
116 | bool parseTime(QTime &t1, QTime &t2, QString s); |
117 | |
118 | /// parses the "use(...)" fields |
119 | bool parseRate(double &costs, double &len, double &after, QString s); |
120 | |
121 | /// parses a whole line |
122 | bool parseLine(const QString &line); |
123 | |
124 | /// returns midnight time (00:00:00.000) |
125 | QTime midnight() const; |
126 | |
127 | /// returns the last valid time BEFORE midnight |
128 | QTime beforeMidnight() const; |
129 | |
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; |
142 | |
143 | QVector<RULE> rules; |
144 | }; |
145 | |
146 | #endif |
147 | |