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 * This file contributed by: Mario Weilguni, <mweilguni@sime.com>
9 *
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this program; if not, write to the Free
23 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 */
25
26#ifndef __ACCOUNTING__H__
27#define __ACCOUNTING__H__
28
29#include <qobject.h>
30//Added by qt3to4:
31#include <QTimerEvent>
32#include <k3process.h>
33#include "ruleset.h"
34
35class PPPStats;
36
37/////////////////////////////////////////////////////////////////////////////
38//
39// Accounting base class
40//
41/////////////////////////////////////////////////////////////////////////////
42class AccountingBase : public QObject {
43 Q_OBJECT
44public:
45 AccountingBase(QObject *parent);
46 virtual ~AccountingBase();
47
48 virtual double total() const;
49 virtual double session() const;
50
51 virtual bool running() const { return false; }
52 virtual bool loadRuleSet(const QString & name) = 0;
53
54public slots:
55 virtual void slotStart() {}
56 virtual void slotStop() {}
57
58signals:
59 void changed(QString total, QString session);
60
61protected:
62 void logMessage(const QString &, bool = false);
63 bool saveCosts();
64 bool loadCosts();
65
66 QString LogFileName;
67 double _total, _session;
68 QString _name;
69
70 // static members
71public:
72 static void resetCosts(const QString & accountname);
73 static void resetVolume(const QString & accountname);
74 static QString getCosts(const QString & accountname);
75 static QString getAccountingFile(const QString &accountname);
76};
77
78
79/////////////////////////////////////////////////////////////////////////////
80//
81// Accounting based on ruleset files
82//
83/////////////////////////////////////////////////////////////////////////////
84class Accounting : public AccountingBase {
85 Q_OBJECT
86public:
87 Accounting(QObject *parent, PPPStats *st);
88
89 virtual double total() const;
90 virtual double session() const;
91
92 virtual bool loadRuleSet(const QString & name);
93 virtual bool running() const;
94
95private:
96 virtual void timerEvent(QTimerEvent *t);
97
98public slots:
99 virtual void slotStart();
100 virtual void slotStop();
101
102signals:
103 void changed(QString total, QString session);
104
105private:
106 int acct_timer_id;
107 int update_timer_id;
108 time_t start_time;
109 double _lastcosts;
110 double _lastlen;
111 RuleSet rules;
112 PPPStats *stats;
113};
114
115
116/////////////////////////////////////////////////////////////////////////////
117//
118// Accounting based on executable files
119//
120/////////////////////////////////////////////////////////////////////////////
121class ExecutableAccounting : public AccountingBase {
122 Q_OBJECT
123public:
124 explicit ExecutableAccounting(PPPStats *st, QObject *parent = 0);
125
126 virtual bool loadRuleSet(const QString & );
127 virtual bool running() const;
128
129public slots:
130 virtual void slotStart();
131 virtual void slotStop();
132
133private slots:
134 void gotData(K3Process *proc, char *buffer, int buflen);
135
136signals:
137 void changed(QString total, QString session);
138
139private:
140 K3Process *proc;
141 QString currency;
142 QString provider;
143 PPPStats *stats;
144};
145
146#endif
147