~neon/kdenetwork/trunk

« back to all changes in this revision

Viewing changes to kppp/accounting.h

  • Committer: uwolfer
  • Date: 2013-06-08 10:12:41 UTC
  • Revision ID: svn-v4:283d02a7-25f6-0310-bc7c-ecb5cbfe19da:trunk/KDE/kdenetwork:1357331
kdenetwork has moved to Git

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
35
 
class PPPStats;
36
 
 
37
 
/////////////////////////////////////////////////////////////////////////////
38
 
//
39
 
// Accounting base class
40
 
//
41
 
/////////////////////////////////////////////////////////////////////////////
42
 
class AccountingBase : public QObject {
43
 
  Q_OBJECT
44
 
public:
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
 
 
54
 
public slots:
55
 
  virtual void slotStart() {}
56
 
  virtual void slotStop() {}
57
 
 
58
 
signals:
59
 
  void changed(QString total, QString session);
60
 
 
61
 
protected:
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
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);
76
 
};
77
 
 
78
 
 
79
 
/////////////////////////////////////////////////////////////////////////////
80
 
//
81
 
// Accounting based on ruleset files
82
 
//
83
 
/////////////////////////////////////////////////////////////////////////////
84
 
class Accounting : public AccountingBase {
85
 
  Q_OBJECT
86
 
public:
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
 
 
95
 
private:
96
 
  virtual void timerEvent(QTimerEvent *t);
97
 
 
98
 
public slots:
99
 
  virtual void slotStart();
100
 
  virtual void slotStop();
101
 
 
102
 
signals:
103
 
  void changed(QString total, QString session);
104
 
 
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;
113
 
};
114
 
 
115
 
 
116
 
/////////////////////////////////////////////////////////////////////////////
117
 
//
118
 
// Accounting based on executable files
119
 
//
120
 
/////////////////////////////////////////////////////////////////////////////
121
 
class ExecutableAccounting : public AccountingBase {
122
 
  Q_OBJECT
123
 
public:
124
 
  explicit ExecutableAccounting(PPPStats *st, QObject *parent = 0);
125
 
 
126
 
  virtual bool loadRuleSet(const QString & );
127
 
  virtual bool running() const;
128
 
 
129
 
public slots:
130
 
  virtual void slotStart();
131
 
  virtual void slotStop();
132
 
 
133
 
private slots:
134
 
  void gotData(K3Process *proc, char *buffer, int buflen);
135
 
 
136
 
signals:
137
 
  void changed(QString total, QString session);
138
 
 
139
 
private:
140
 
  K3Process *proc;
141
 
  QString currency;
142
 
  QString provider;
143
 
  PPPStats *stats;
144
 
};
145
 
 
146
 
#endif