Use a nicer way to check if rdesktop is installed.
[kdenetwork.git] / kppp / accounting.h
blob0ab82a6dcb9ed6e468c9aef2e497f2bcb0b3a3d3
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
8 * This file contributed by: Mario Weilguni, <mweilguni@sime.com>
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.
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.
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.
26 #ifndef __ACCOUNTING__H__
27 #define __ACCOUNTING__H__
29 #include <qobject.h>
30 //Added by qt3to4:
31 #include <QTimerEvent>
32 #include <k3process.h>
33 #include "ruleset.h"
35 class PPPStats;
37 /////////////////////////////////////////////////////////////////////////////
39 // Accounting base class
41 /////////////////////////////////////////////////////////////////////////////
42 class AccountingBase : public QObject {
43 Q_OBJECT
44 public:
45 AccountingBase(QObject *parent);
46 virtual ~AccountingBase();
48 virtual double total() const;
49 virtual double session() const;
51 virtual bool running() const { return false; }
52 virtual bool loadRuleSet(const QString & name) = 0;
54 public slots:
55 virtual void slotStart() {}
56 virtual void slotStop() {}
58 signals:
59 void changed(QString total, QString session);
61 protected:
62 void logMessage(const QString &, bool = false);
63 bool saveCosts();
64 bool loadCosts();
66 QString LogFileName;
67 double _total, _session;
68 QString _name;
70 // static members
71 public:
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);
79 /////////////////////////////////////////////////////////////////////////////
81 // Accounting based on ruleset files
83 /////////////////////////////////////////////////////////////////////////////
84 class Accounting : public AccountingBase {
85 Q_OBJECT
86 public:
87 Accounting(QObject *parent, PPPStats *st);
89 virtual double total() const;
90 virtual double session() const;
92 virtual bool loadRuleSet(const QString & name);
93 virtual bool running() const;
95 private:
96 virtual void timerEvent(QTimerEvent *t);
98 public slots:
99 virtual void slotStart();
100 virtual void slotStop();
102 signals:
103 void changed(QString total, QString session);
105 private:
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;
116 /////////////////////////////////////////////////////////////////////////////
118 // Accounting based on executable files
120 /////////////////////////////////////////////////////////////////////////////
121 class ExecutableAccounting : public AccountingBase {
122 Q_OBJECT
123 public:
124 explicit ExecutableAccounting(PPPStats *st, QObject *parent = 0);
126 virtual bool loadRuleSet(const QString & );
127 virtual bool running() const;
129 public slots:
130 virtual void slotStart();
131 virtual void slotStop();
133 private slots:
134 void gotData(K3Process *proc, char *buffer, int buflen);
136 signals:
137 void changed(QString total, QString session);
139 private:
140 K3Process *proc;
141 QString currency;
142 QString provider;
143 PPPStats *stats;
146 #endif