summaryrefslogtreecommitdiffstats
path: root/kppp/logview
diff options
context:
space:
mode:
Diffstat (limited to 'kppp/logview')
-rw-r--r--kppp/logview/Makefile.am45
-rw-r--r--kppp/logview/export.cpp276
-rw-r--r--kppp/logview/export.h201
-rw-r--r--kppp/logview/kppplogview.desktop77
-rw-r--r--kppp/logview/log.cpp129
-rw-r--r--kppp/logview/log.h40
-rw-r--r--kppp/logview/loginfo.cpp197
-rw-r--r--kppp/logview/loginfo.h63
-rw-r--r--kppp/logview/main.cpp127
-rw-r--r--kppp/logview/main.h45
-rw-r--r--kppp/logview/monthly.cpp729
-rw-r--r--kppp/logview/monthly.h80
12 files changed, 2009 insertions, 0 deletions
diff --git a/kppp/logview/Makefile.am b/kppp/logview/Makefile.am
new file mode 100644
index 00000000..e95b7c73
--- /dev/null
+++ b/kppp/logview/Makefile.am
@@ -0,0 +1,45 @@
+
+# this 10 paths are KDE specific. Use them:
+# kde_htmldir Where your docs should go to. (contains lang subdirs)
+# kde_appsdir Where your application file (.desktop) should go to.
+# kde_icondir Where your icon should go to.
+# kde_minidir Where your mini icon should go to.
+# kde_datadir Where you install application data. (Use a subdir)
+# kde_locale Where translation files should go to.(contains lang subdirs)
+# kde_cgidir Where cgi-bin executables should go to.
+# kde_confdir Where config files should go to.
+# kde_mimedir Where mimetypes should go to.
+# kde_toolbardir Where general toolbar icons should go to.
+# kde_wallpaperdir Where general wallpapers should go to.
+
+# if you use a variable *dir and have *_DATA, it will be installed by
+# make install
+xdg_apps_DATA = kppplogview.desktop
+
+EXTRA_DIST = $(xdg_apps_DATA)
+
+# set the include path for X, qt and KDE
+INCLUDES= $(all_includes)
+# claim, which subdirectories you want to install
+
+# This one gets installed
+bin_PROGRAMS = kppplogview
+
+# Which sources should be compiled for kppp.
+kppplogview_SOURCES = main.cpp loginfo.cpp log.cpp monthly.cpp export.cpp
+
+# the library search path
+kppplogview_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+
+# the libraries to link against. Be aware of the order. First the libraries,
+# that depend on the following ones.
+kppplogview_LDADD = -lm $(LIB_KDEUI) $(LIB_KFILE)
+
+# this option you can leave out. Just, if you use "make dist", you need it
+noinst_HEADERS = export.h loginfo.h log.h monthly.h main.h
+
+METASOURCES = main.moc monthly.moc export.moc
+
+messages:
+ $(XGETTEXT) *.cpp *.h -o $(podir)/kppplogview.pot
+
diff --git a/kppp/logview/export.cpp b/kppp/logview/export.cpp
new file mode 100644
index 00000000..6bbf2159
--- /dev/null
+++ b/kppp/logview/export.cpp
@@ -0,0 +1,276 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This file has been contributed by Tilo Ulbrich <TiloUlbrich@web.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "export.h"
+
+#include <qpushbutton.h>
+#include <qtextcodec.h>
+
+class Export;
+
+/***** ExportFormats *****/
+static struct {
+ int id;
+ QString name;
+ QString desc;
+ QString ext;
+ }
+
+ExportFormats [] = {
+ { 1, I18N_NOOP("CSV"),
+ I18N_NOOP("Export to a text file, using semicolons as separators.<p></p>Can be used for spreadsheet programs like <i>KSpread</i>."),
+ "csv" },
+ { 2, I18N_NOOP("HTML"),
+ I18N_NOOP("Export to a HTML Page.<p></p>Can be used for easy exchange over the <i>Internet</i>."),
+ "html" },
+ { 0, 0, 0, 0 } /* !! don't forget !! */
+};
+
+
+/***** ExportWizard *****/
+ExportWizard::ExportWizard(QWidget *parent, const QString &_date)
+ : KWizard(parent, "", true) {
+ date = _date;
+
+ filterID = 0;
+
+ setCaption(i18n("Export Wizard for kPPP Logs"));
+
+ /* format-page */
+ formatPage = new QWidget();
+ QHBoxLayout *formatLayout = new QHBoxLayout(formatPage);
+
+ typeList = new QListBox(formatPage);
+ connect(typeList, SIGNAL(highlighted(int)), SLOT (typeHighlighted(int)));
+ typeList->setMinimumSize(50, 200);
+ QToolTip::add(typeList, i18n("List with possible output formats"));
+ int i=0;
+ while (ExportFormats[i].id) { // add each format to the list
+ typeList->insertItem(i18n(ExportFormats[i].name.utf8()));
+ i++;
+ }
+
+ formatLayout->addWidget(typeList);
+ formatLayout->addSpacing(10);
+
+ typeInfo = new QLabel(formatPage);
+ typeInfo->setAlignment(Qt::AlignTop | Qt::WordBreak);
+ typeInfo->setText(i18n("<qt><b>Please choose the output format on the left side.</b></qt>"));
+ typeInfo->setMinimumSize(350, 200);
+ formatLayout->addWidget(typeInfo);
+
+ addPage(formatPage, i18n("Selection of Filetype"));
+
+
+ /* filename-page */
+ filenamePage = new QWidget();
+ QVBoxLayout *filenameLayout = new QVBoxLayout( filenamePage );
+
+ QLabel *fnLbl = new QLabel(filenamePage);
+ fnLbl->setText(i18n("Filename:"));
+ filenameLayout->addWidget(fnLbl);
+
+ fnLine = new QLineEdit(filenamePage);
+ fnLine->setText(i18n("[No file selected]"));
+ fnLine->setReadOnly(true);
+ filenameLayout->addWidget(fnLine);
+ filenameLayout->addStretch(1);
+
+ fnGet = new QPushButton(filenamePage);
+ fnGet->setText(i18n("&Select File..."));
+ fnGet->setMaximumWidth(200);
+ QToolTip::add(fnGet, i18n("Select the filename of the exported output file"));
+ filenameLayout->addWidget(fnGet);
+ connect(fnGet, SIGNAL(clicked()), SLOT(getFilename()));
+ filenameLayout->addStretch(2);
+
+ addPage(filenamePage, i18n("Selection of Filename"));
+ setNextEnabled( filenamePage, false );
+ setHelpEnabled( filenamePage, false );
+
+ setNextEnabled( formatPage, false );
+ setHelpEnabled( formatPage, false );
+}
+
+Export * ExportWizard::createExportFilter() {
+ switch (filterID) { // IDs: see data-struct ExportFormats
+ case 1 : return new CSVExport(filename, ";");
+ case 2 : return new HTMLExport(filename, date);
+ default : return NULL; // oops..
+ };
+}
+
+void ExportWizard::typeHighlighted(int index) {
+ typeInfo->setText("<qt><b>"+i18n(ExportFormats[index].name.utf8())+" " +
+ i18n("File Format") + "</b><p></p>" + i18n(ExportFormats[index].desc.utf8())
+ +"</qt>");
+ setNextEnabled(formatPage, true );
+}
+
+void ExportWizard::getFilename() {
+ int i = typeList->currentItem();
+ if ( i == -1 )
+ return;
+ // prepare filter: e.g.: HTML (*.html *.HTML)
+ QString filter = "*." + ExportFormats[i].ext + " *." + ExportFormats[i].ext.upper() + "|" +
+ i18n(ExportFormats[i].name.utf8()) + " (*." + ExportFormats[i].ext + " *." +
+ ExportFormats[i].ext.upper() + ")";
+
+ filename = KFileDialog::getSaveFileName(date + "." + ExportFormats[i].ext, filter, 0, i18n("Please Choose File"));
+ if (filename.isEmpty()) // no file selected
+ return;
+ fnLine->setText(filename);
+ setFinishEnabled(filenamePage, true);
+}
+
+void ExportWizard::reject() {
+ hide();
+ filename = QString::null;
+}
+
+void ExportWizard::accept() {
+ filterID = typeList->currentItem() + 1; // translate to ID-count in ExportFormats
+ hide();
+}
+
+
+/***** Export *****/
+Export::Export(const QString &_filename)
+ : filename(_filename),
+ buffer("")
+{
+}
+
+Export::~Export()
+{
+}
+
+bool Export::openFile() {
+ file.setName(filename);
+ return file.open(IO_WriteOnly);
+}
+
+bool Export::closeFile() {
+ bool ok = true;
+ if (file.writeBlock(buffer.local8Bit(), buffer.length())<0)
+ ok = false;
+ file.close();
+ return ok;
+}
+
+
+/***** CSVExport *****/
+CSVExport::CSVExport(const QString &filename, const QString &_separator)
+ : Export(filename),
+ separator(_separator)
+{
+}
+
+void CSVExport::addHeadline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h) {
+ // no especially style
+ addDataline(a, b, c, d, e, f, g, h);
+}
+
+void CSVExport::addDataline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h) {
+ buffer+=a + separator +
+ b + separator +
+ c + separator +
+ d + separator +
+ e + separator +
+ f + separator +
+ g + separator +
+ h + separator + "\n";
+}
+
+void CSVExport::addEmptyLine() {
+ // not needed
+}
+
+void CSVExport::setFinishCode() {
+ // not needed
+}
+
+
+/***** HTMLExport *****/
+HTMLExport::HTMLExport(const QString &filename, const QString &date)
+ : Export(filename) {
+ QString title = i18n("Connection log for %1").arg(date);
+ buffer = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
+ buffer.append("<html>\n<head>\n <title>"+title+"</title>\n");
+ buffer.append(QString::fromLatin1(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=")
+ + QTextCodec::codecForLocale()->mimeName() +
+ QString::fromLatin1("\">"));
+ buffer.append("\n</head>\n<body>\n<h1>"+title+"</h1>\n\n");
+ buffer.append("<table width=\"100%\" border=\"1\">\n");
+
+ trStartCode = "<tr>";
+ trEndCode = "</tr>\n";
+ tdStartCode = "<td>";
+ tdEndCode = "</td>";
+}
+
+void HTMLExport::addHeadline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h) {
+ // simply bold font
+ QString bak1 = tdStartCode; tdStartCode.append("<b>");
+ QString bak2 = tdEndCode; tdEndCode.prepend("</b>");
+
+ addDataline(a, b, c, d, e, f, g, h);
+
+ // reset font
+ tdStartCode = bak1;
+ tdEndCode = bak2;
+}
+
+void HTMLExport::addDataline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h) {
+ buffer+= trStartCode +
+ tdStartCode + a + tdEndCode +
+ tdStartCode + b + tdEndCode +
+ tdStartCode + c + tdEndCode +
+ tdStartCode + d + tdEndCode +
+ tdStartCode + e + tdEndCode +
+ tdStartCode + f + tdEndCode +
+ tdStartCode + g + tdEndCode +
+ tdStartCode + h + tdEndCode +
+ trEndCode;
+}
+
+void HTMLExport::addEmptyLine() {
+ addDataline("&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;");
+}
+
+void HTMLExport::setFinishCode() {
+ buffer+= "</table>\n</body>\n</html>\n";
+}
+
+#include "export.moc"
diff --git a/kppp/logview/export.h b/kppp/logview/export.h
new file mode 100644
index 00000000..306b6fc6
--- /dev/null
+++ b/kppp/logview/export.h
@@ -0,0 +1,201 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This file has been contributed by Tilo Ulbrich <TiloUlbrich@web.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef KPPPEXPORT_H
+#define KPPPEXPORT_H
+
+#include <qwidget.h>
+#include <qfile.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qlistbox.h>
+#include <qlineedit.h>
+#include <qtooltip.h>
+
+#include <kwizard.h>
+#include <klocale.h>
+#include <kfiledialog.h>
+
+class Export;
+
+/***** ExportWizard *****/
+class ExportWizard : public KWizard {
+ Q_OBJECT
+public:
+ ExportWizard(QWidget *parent, const QString &_date);
+ Export *createExportFilter();
+
+ int filterID;
+ QString filename;
+
+public slots:
+ void typeHighlighted(int);
+ void getFilename();
+
+ void accept();
+ void reject();
+
+private:
+ QWidget *formatPage;
+ QListBox *typeList;
+ QLabel *typeInfo;
+
+ QWidget *filenamePage;
+ QLineEdit *fnLine;
+ QPushButton *fnGet;
+
+ QString date;
+};
+
+
+/***** Export (abstract)*****/
+class Export {
+public:
+ Export();
+ Export(const QString &filename);
+ virtual ~Export();
+ bool openFile();
+ bool closeFile();
+ virtual void addHeadline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h) = 0;
+ virtual void addDataline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h) = 0;
+ virtual void addEmptyLine() = 0;
+ virtual void setFinishCode() = 0;
+
+protected:
+ QFile file;
+ QString filename;
+ QString buffer;
+};
+
+
+/***** CSVExport *****/
+class CSVExport : public Export {
+public:
+ CSVExport(const QString &filename, const QString &separator);
+ virtual void addHeadline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h);
+ virtual void addDataline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h);
+ virtual void addEmptyLine();
+ virtual void setFinishCode();
+
+private:
+ QString separator;
+};
+
+
+/***** HTMLExport *****/
+class HTMLExport : public Export {
+public:
+ HTMLExport(const QString &filename, const QString &date);
+ virtual void addHeadline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h);
+ virtual void addDataline(const QString &a, const QString &b,
+ const QString &c, const QString &d,
+ const QString &e, const QString &f,
+ const QString &g, const QString &h);
+ virtual void addEmptyLine();
+ virtual void setFinishCode();
+
+private:
+ QString trStartCode;
+ QString trEndCode;
+ QString tdStartCode;
+ QString tdEndCode;
+};
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/kppp/logview/kppplogview.desktop b/kppp/logview/kppplogview.desktop
new file mode 100644
index 00000000..45b0ffa6
--- /dev/null
+++ b/kppp/logview/kppplogview.desktop
@@ -0,0 +1,77 @@
+[Desktop Entry]
+Name=KPPPLogview
+Name[bn]=কে-পি-পি-পি লগভিউ
+Name[bs]=Preglednik Kppp dnevnika
+Name[de]=KPPP-Protokoll-Betrachter
+Name[el]=Προβολή καταγραφής KPPP
+Name[eo]=PPP-protokolorigardilo
+Name[fa]=نمای ثبت KPPP
+Name[he]=KPPP תצוגת רישום
+Name[is]=KPPP annálaskoðari
+Name[it]=Visualizzatore log KPPP
+Name[ja]=KPPP - ログビューア
+Name[lt]=KPPP – žurnalo žiūriklis
+Name[nb]=KPPP loggviser
+Name[ne]=के पी पी पी लग दृश्य
+Name[nn]=KPPP-loggvisar
+Name[pa]=KPPP ਲਾਗ ਦਰਸ਼ਕ
+Name[pl]=Dziennik połączeń KPPP
+Name[sk]=KPPP prehliadač záznamov
+Name[sl]=Ogled dnevnika KPPP
+Name[sv]=Kppp - Loggvisare
+Name[tr]=KPPP Kayıt Görüntüleyici
+Name[zh_TW]=KPPP - 紀錄檔檢視器
+GenericName=Internet Dial-Up Tool Log Viewer
+GenericName[be]=Аглядальнік дзённікаў KPPP
+GenericName[bg]=Преглед на журнала на KPPP
+GenericName[bn]=ইন্টারনেট ডায়াল-আপ সরঞ্জাম কার্যবিবরণী প্রদর্শক
+GenericName[bs]=Program za pregled dnevnika spajanja na Internet
+GenericName[ca]=Visor de la bitàcola de l'eina de connexió telefònica a Internet
+GenericName[cs]=Prohlížeč záznamů připojení přes vytáčenou linku
+GenericName[da]=Internet-opkaldsværktøj-logviser
+GenericName[de]=Protokoll-Betrachter für die Einwahl ins Internet
+GenericName[el]=Προβολή καταγραφής εργαλείου σύνδεσης μέσω τηλεφώνου στο διαδίκτυο
+GenericName[es]=Visor del registro de conexión telefónica a Internet
+GenericName[et]=Interneti sissehelistamise rakenduse logide näitaja
+GenericName[eu]=Internet markatzaile tresnaren erregistroaren ikusgailua
+GenericName[fa]=ابزار مشاهده‌گر ثبت شماره‌گیری اینترنت
+GenericName[fi]=Internet-yhteyden soitto-ohjelman lokin näytin
+GenericName[fr]=Afficheur de l'historique des connexion internet par modem
+GenericName[gl]=Visor de Rexistros da Ferramenta de Conexión a Internet por Teléfono
+GenericName[he]=תצוגת רישום של כלי חיוג לאינטרנט
+GenericName[hu]=Tárcsázó-napló
+GenericName[is]=Upphringisambands annálaskoðari
+GenericName[it]=Visualizzatore di log della connessione telefonica ad Internet
+GenericName[ja]=インターネットダイアルアップツール ログビューア
+GenericName[ka]=ინტერნეტი Dial-Up ხელსაწყოს ჟურნალის მხილველი
+GenericName[kk]=Телефондық желі арқылы қосылудың журналын қарау құралы
+GenericName[km]=កម្មវិធី​មើល​កំណត់ហេតុរបស់ឧបករណ៍​ដែល​តភ្ជាប់​ទៅ​អ៊ីនធឺណិត​តាម​រយៈ​ទូរស័ព្ទ​លើ​តុ
+GenericName[lt]=Interneto skambinimo priemonės žurnalo žiūriklis
+GenericName[nb]=Loggviser for verktøyet for oppringt Internet
+GenericName[nds]=Protokollkieker för Internetinwahl
+GenericName[ne]=इन्टरनेट डायल-अप उपकरण लग दर्शक
+GenericName[nl]=Logviewer voor het inbelprogramma kppp
+GenericName[nn]=Loggvisar for verktøyet for Internett-oppringing
+GenericName[pl]=Narzędzie do przeglądania dziennika programu do łączenia z Internetem
+GenericName[pt]=Visualizador de Registos da Ferramenta de Ligação à Internet
+GenericName[pt_BR]=Visualizador de Logs do KPPP
+GenericName[ro]=Jurnal conectare Internet
+GenericName[ru]=Просмотр журнала соединения с Интернетом посредством телефонной линии
+GenericName[sk]=Prehliadač záznamov nástroja pre pripojenie na internet cez modem
+GenericName[sl]=Orodje za ogled dnevnika KPPP
+GenericName[sr]=Приказивач дневника модемске везе са Интернетом
+GenericName[sr@Latn]=Prikazivač dnevnika modemske veze sa Internetom
+GenericName[sv]=Loggvisning för Internetuppringningsverktyg
+GenericName[tr]=İnternet Çevirmeli Ağ Aracı Kayıt Görüntüleyici
+GenericName[uk]=Переглядач журналу засобу дозвону в Інтернет
+GenericName[zh_CN]=Internet 拨号工具日志查看器
+GenericName[zh_HK]=互聯網撥號工具記錄檢視器
+GenericName[zh_TW]=Internet 撥號工具紀錄檢視器
+MimeType=
+Exec=kppplogview
+Icon=kppp
+Path=
+Type=Application
+Terminal=false
+X-DCOP-ServiceType=Multi
+Categories=Qt;KDE;Network;X-KDE-More;Dialup;
diff --git a/kppp/logview/log.cpp b/kppp/logview/log.cpp
new file mode 100644
index 00000000..66ff7c9c
--- /dev/null
+++ b/kppp/logview/log.cpp
@@ -0,0 +1,129 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "log.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <qprogressdialog.h>
+#include <qdir.h>
+
+#include <kapplication.h>
+#include <klocale.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
+QPtrList<LogInfo> logList;
+QProgressDialog *dlg;
+
+int loadLogs() {
+ int logsize = 0;
+
+ QString logdirname = locateLocal("data", "kppp/Log/");
+ QDir logdir(logdirname, "*.log");
+
+ kdDebug(5002) << "logdirname: " << logdirname << endl;
+
+ // get log file size
+ const QFileInfoList *list = logdir.entryInfoList();
+ QFileInfoListIterator it( *list );
+ QFileInfo *fi;
+
+ while ((fi = it.current()) != 0) {
+ logsize += fi->size();
+ ++it;
+ }
+
+ dlg = new QProgressDialog(i18n("Loading log files"),
+ QString::null,
+ logsize);
+ dlg->setProgress(0);
+
+ // load logs
+ list = logdir.entryInfoList();
+ QFileInfoListIterator it1( *list );
+
+ int retval = 0;
+ while ((fi = it1.current()) != 0) {
+ retval += loadLog(fi->absFilePath());
+ ++it1;
+ }
+
+ delete dlg;
+ return retval;
+}
+
+int loadLog(QString fname) {
+ FILE *f;
+ int warning=0;
+
+ f = fopen(QFile::encodeName(fname), "r");
+ if(f == NULL)
+ return 1;
+
+ char buffer[2048+1];
+ int lineno = 0;
+ while(fgets(buffer, sizeof(buffer), f) != NULL) {
+ ++lineno;
+ buffer[sizeof(buffer) - 1] = 0;
+
+ int slen = strlen(buffer);
+
+ // skip blank lines
+ if(slen < 10)
+ continue;
+
+ dlg->setProgress(dlg->progress() + slen);
+ kapp->processEvents();
+
+ LogInfo *li = new LogInfo(buffer);
+ if(li->error()) {
+
+ // check if the connection has been terminated abnormally
+ if(li->error() != 3) {
+ warning++;
+ kdError() << "ERROR IN FILE " << fname << " LINE " << lineno << "\"" << buffer << "\" (" << li->error() << ")" << endl;
+ delete li;
+ } else
+ logList.append(li);
+ } else
+ logList.append(li);
+ }
+
+ fclose(f);
+
+ if(warning)
+ return 2;
+ else
+ return 0;
+}
+
+int QLogList::compareItems(Item a, Item b) {
+ LogInfo *la = (LogInfo *)a;
+ LogInfo *lb = (LogInfo *)b;
+
+ if(la->from() < lb->from())
+ return -1;
+ else if(la->from() > lb->from())
+ return 1;
+ else
+ return 0;
+}
diff --git a/kppp/logview/log.h b/kppp/logview/log.h
new file mode 100644
index 00000000..74d573e5
--- /dev/null
+++ b/kppp/logview/log.h
@@ -0,0 +1,40 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __LOG__H__
+#define __LOG__H__
+
+#include "loginfo.h"
+#include <qptrlist.h>
+
+typedef QPtrList<LogInfo> QLogInfoBase;
+typedef QPtrListIterator<LogInfo> QLogInfoIterator;
+
+class QLogList : public QLogInfoBase {
+public:
+ virtual int compareItems(Item, Item);
+};
+
+extern QPtrList<LogInfo> logList;
+
+int loadLogs();
+int loadLog(QString);
+
+#endif
diff --git a/kppp/logview/loginfo.cpp b/kppp/logview/loginfo.cpp
new file mode 100644
index 00000000..1e5a089a
--- /dev/null
+++ b/kppp/logview/loginfo.cpp
@@ -0,0 +1,197 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "loginfo.h"
+#include <stdlib.h>
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <kdebug.h>
+
+char *mystrsep (char **stringp, const char *delim);
+
+LogInfo::LogInfo(QCString data) {
+ parse(data);
+}
+
+QDateTime LogInfo::from() const {
+ QDateTime tm;
+ tm.setTime_t(_from);
+ return tm;
+}
+
+QDateTime LogInfo::until() const {
+ QDateTime tm;
+ tm.setTime_t(_until);
+ return tm;
+}
+
+QString LogInfo::connectionName() const {
+ return _conname;
+}
+
+QString LogInfo::currency() const {
+ return _currency;
+}
+
+double LogInfo::sessionCosts() const {
+ return _session_cost;
+}
+
+double LogInfo::totalCosts() const {
+ return _total_cost;
+}
+
+double LogInfo::bytesIn() const {
+ return _bytes_in;
+}
+
+double LogInfo::bytesOut() const {
+ return _bytes_out;
+}
+
+double LogInfo::bytes() const {
+ if(bytesIn() == -1 || bytesOut() == -1)
+ return -1;
+ else
+ return bytesIn() + bytesOut();
+}
+
+int LogInfo::error() const {
+ return errorfield;
+}
+
+void LogInfo::parse(QCString s) {
+ errorfield = 0;
+ char *c = (char *)malloc(s.length() + 1), *csep;
+ strcpy(c, s);
+
+ // init data
+ _from = _until = 0;
+ _conname = "";
+ _currency = "";
+ _bytes_in = _bytes_out = -1;
+ _session_cost = _total_cost = -1;
+
+ // start of connection time
+ csep = c;
+ char *p = mystrsep(&csep, ":");
+ int i = 0;
+ while(i < 8 && p != 0) {
+ QString token = QString::fromLocal8Bit(p);
+
+ switch(i) {
+ case 0:
+ _from = token.toULong();
+ break;
+
+ case 1:
+ _conname = token;
+ break;
+
+ case 2:
+ _currency = token;
+ break;
+
+ case 3:
+ _until = token.toULong();
+ break;
+
+ case 4:
+ _session_cost = token.toFloat();
+ break;
+
+ case 5:
+ _total_cost = token.toFloat();
+ break;
+
+ case 6:
+ _bytes_in = token.toLong();
+ break;
+
+ case 7:
+ _bytes_out = token.toLong();
+ break;
+ }
+
+ i++;
+ p = mystrsep(&csep, ":");
+ }
+
+ free(c);
+
+ if(i == 8)
+ errorfield = 0;
+ else
+ errorfield = i+1;
+}
+
+
+int LogInfo::duration() const {
+ if( _until - _from < 0)
+ return 0;
+ else
+ return _until - _from;
+}
+
+#ifdef MYDEBUG
+void LogInfo::dump() {
+ kdDebug(5002) << "LOGINFO " << this << endl;
+ kdDebug(5002) << "connection name : " << connectionName() << endl;
+ kdDebug(5002) << "currency symbol : " << currency() << endl;
+ kdDebug(5002) << "begin : " << ctime(&_from) << endl;
+ kdDebug(5002) << "end : " << ctime(&_until) << endl;
+ kdDebug(5002) << "duration : " << (int)_until - (int)_from << " seconds" << endl;
+ kdDebug(5002) << "session cost : " << sessionCosts() << endl;
+ kdDebug(5002) << "total cost : " << totalCosts() << endl;
+ kdDebug(5002) << "bytes in : " << bytesIn() << endl;
+ kdDebug(5002) << "bytes out : " << bytesOut() << endl;
+ kdDebug(5002) << "bytes total : " << bytes() << endl;
+ kdDebug(5002) << endl;
+}
+#endif
+
+char *mystrsep (char **stringp, const char *delim) {
+ char *begin, *end;
+
+ begin = *stringp;
+ if (begin == 0L)
+ return 0L;
+
+ /* Find the end of the token. */
+ end = strpbrk (begin, delim);
+ if (end) {
+ /* Terminate the token and set *STRINGP past NUL character. */
+ *end++ = '\0';
+ *stringp = end;
+ } else
+ /* No more delimiters; this is the last token. */
+ *stringp = 0L;
+
+ return begin;
+}
+
+
diff --git a/kppp/logview/loginfo.h b/kppp/logview/loginfo.h
new file mode 100644
index 00000000..6b2e992e
--- /dev/null
+++ b/kppp/logview/loginfo.h
@@ -0,0 +1,63 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __LOGINFO__H__
+#define __LOGINFO__H__
+#define MYDEBUG
+
+#include <qdatetime.h>
+#include <qstring.h>
+#include <time.h>
+
+class LogInfo {
+public:
+ LogInfo(QCString data);
+
+ int error() const;
+
+ QDateTime from() const;
+ time_t from_t() const { return _from; }
+ QDateTime until() const;
+ int duration() const;
+ QString connectionName() const;
+ QString currency() const;
+ double sessionCosts() const;
+ double totalCosts() const;
+ double bytesIn() const;
+ double bytesOut() const;
+ double bytes() const;
+
+#ifdef MYDEBUG
+ void dump();
+#endif
+
+private:
+ void parse(QCString );
+
+ int errorfield;
+
+ time_t _from, _until;
+ QString _conname, _currency;
+ double _session_cost, _total_cost;
+ double _bytes_in, _bytes_out;
+};
+
+
+#endif
diff --git a/kppp/logview/main.cpp b/kppp/logview/main.cpp
new file mode 100644
index 00000000..4e54236c
--- /dev/null
+++ b/kppp/logview/main.cpp
@@ -0,0 +1,127 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <kapplication.h>
+#include "log.h"
+#include "monthly.h"
+#include "main.h"
+#include <klocale.h>
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <kpushbutton.h>
+#include <kstdguiitem.h>
+#include <kiconloader.h>
+
+#define F_EXIT 101
+
+
+static const char description[] =
+ I18N_NOOP("KPPP log viewer");
+
+static const char version[] = "v0.0.2";
+
+static KCmdLineOptions option[] =
+{
+ { "kppp", I18N_NOOP("Run in KPPP mode"), 0 },
+ KCmdLineLastOption
+};
+
+
+TopWidget::TopWidget() : KMainWindow(0, "") {
+ // Check command line args for "-kppp"
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ bool kpppmode = args->isSet("kppp");
+ args->clear();
+
+ setCaption(i18n("KPPP Log Viewer"));
+
+ w = new QWidget(this);
+
+ QBoxLayout *l = new QVBoxLayout(w, 5);
+
+ td = new QTabWidget(w, "");
+ mw = new MonthlyWidget(td);
+ td->addTab(mw, i18n("Monthly Log"));
+ l->addWidget(td);
+
+ // remove buttons
+ if(!kpppmode) {
+ // create menu
+ mb = new KMenuBar(this);
+ QPopupMenu *fm = new QPopupMenu;
+ fm->insertItem(SmallIcon("exit"),KStdGuiItem::quit().text(), F_EXIT);
+ mb->insertItem(i18n("&File"), fm);
+
+ mb->setAccel(CTRL + Key_Q, F_EXIT);
+ connect(mb, SIGNAL(activated(int)),
+ this, SLOT(menuCallback(int)));
+ } else {
+ mb = 0;
+ QPushButton *but = new KPushButton(KStdGuiItem::close(),w);
+ QHBoxLayout *lh = new QHBoxLayout(l);
+ lh->addStretch(10);
+ lh->addWidget(but);
+
+ connect(but, SIGNAL(clicked()),
+ kapp, SLOT(quit()));
+ }
+
+ setMinimumSize(mw->sizeHint().width() + 15,
+ mw->sizeHint().height() + 120);
+ setCentralWidget(w);
+}
+
+TopWidget::~TopWidget() {
+}
+
+void TopWidget::menuCallback(int id) {
+ switch(id) {
+ case F_EXIT:
+ exit(0);
+ break;
+ }
+}
+
+int main(int argc, char **argv) {
+ KAboutData aboutData("kppplogview", I18N_NOOP("KPPP Log Viewer"),
+ version, description, KAboutData::License_GPL,
+ I18N_NOOP("(c) 1999-2002, The KPPP Developers"));
+ aboutData.addAuthor("Bernd Wuebben",0, "wuebben@kde.org");
+ aboutData.addAuthor("Mario Weilguni",0, "");
+ aboutData.addAuthor("Harri Porten",0, "porten@kde.org");
+ KCmdLineArgs::init(argc, argv, &aboutData);
+
+ KCmdLineArgs::addCmdLineOptions( option );
+
+ KApplication a;
+
+ loadLogs();
+
+ TopWidget *w = new TopWidget;
+ w->show();
+ a.setMainWidget(w);
+
+ return a.exec();
+}
+
+#include "main.moc"
diff --git a/kppp/logview/main.h b/kppp/logview/main.h
new file mode 100644
index 00000000..eabe66df
--- /dev/null
+++ b/kppp/logview/main.h
@@ -0,0 +1,45 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __MAIN__H__
+#define __MAIN__H__
+
+#include <kmainwindow.h>
+#include <qtabwidget.h>
+#include <kmenubar.h>
+#include "monthly.h"
+
+class TopWidget : public KMainWindow {
+ Q_OBJECT
+public:
+ TopWidget();
+ ~TopWidget();
+
+private slots:
+ void menuCallback(int);
+
+private:
+ MonthlyWidget *mw;
+ KMenuBar *mb;
+ QWidget *w;
+ QTabWidget *td;
+};
+
+#endif
diff --git a/kppp/logview/monthly.cpp b/kppp/logview/monthly.cpp
new file mode 100644
index 00000000..668381e4
--- /dev/null
+++ b/kppp/logview/monthly.cpp
@@ -0,0 +1,729 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <qpainter.h>
+#include <qcombobox.h>
+#include <qfile.h>
+#include <qheader.h>
+
+#include <kcalendarsystem.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <klistview.h>
+#include <kdebug.h>
+#include <kmessagebox.h>
+
+#include "monthly.h"
+#include "export.h"
+#include <qstringlist.h>
+
+static void formatBytes(double bytes, QString &result) {
+ if(bytes < 1024)
+ result.setNum(bytes);
+ else if(bytes < 1024*1024)
+ result = i18n("%1 KB").arg(KGlobal::locale()->formatNumber((float)bytes / 1024.0, 1));
+ else
+ result = i18n("%1 MB").arg(KGlobal::locale()->formatNumber((float)bytes / 1024.0 / 1024.0, 1));
+}
+
+static void formatBytesMonth(double bytes, QString &result) {
+
+ int day, days;
+ day = QDate::currentDate().day();
+ days = QDate::currentDate().daysInMonth();
+
+ bytes = (bytes / day) * days;
+
+ if(bytes < 1024)
+ result.setNum(bytes);
+ else if(bytes < 1024*1024)
+ result = i18n("%1 KB").arg(KGlobal::locale()->formatNumber((float)bytes / 1024.0, 1));
+ else
+ result = i18n("%1 MB").arg(KGlobal::locale()->formatNumber((float)bytes / 1024.0 / 1024.0, 1));
+}
+
+static void formatDuration(int seconds, QString &result) {
+ QString sec;
+ sec.sprintf("%02d", seconds%60);
+ if(seconds < 60)
+ result = i18n("%1s").arg(sec);
+ else if(seconds < 3600)
+ result = i18n("%1m %2s").arg(seconds/60).arg(sec);
+ else
+ result = i18n("%1h %2m %3s")
+ .arg(seconds/3600)
+ .arg((seconds % 3600)/60)
+ .arg(sec);
+}
+
+static void formatDurationMonth(int seconds, QString &result) {
+
+ int day, days;
+ day = QDate::currentDate().day();
+ days = QDate::currentDate().daysInMonth();
+
+ seconds = (seconds / day) * days;
+
+ QString sec;
+ sec.sprintf("%02d", seconds%60);
+ if(seconds < 60)
+ result = i18n("%1s").arg(sec);
+ else if(seconds < 3600)
+ result = i18n("%1m %2s").arg(seconds/60).arg(sec);
+ else
+ result = i18n("%1h %2m %3s")
+ .arg(seconds/3600)
+ .arg((seconds % 3600)/60)
+ .arg(sec);
+}
+
+static void costsMonth(double costs, double &result) {
+
+ int day, days;
+ day = QDate::currentDate().day();
+ days = QDate::currentDate().daysInMonth();
+
+ result = (costs / day) * days;
+
+}
+
+class LogListItem : public QListViewItem {
+public:
+ LogListItem(LogInfo *l,
+ QListView * parent,
+ QString s1, QString s2,
+ QString s3, QString s4,
+ QString s5, QString s6,
+ QString s7, QString s8)
+ : QListViewItem(parent, s1, s2, s3, s4, s5, s6, s7, s8),
+ li(l)
+ {
+ }
+ virtual void paintCell( QPainter *p, const QColorGroup & cg,
+ int column, int width, int alignment );
+
+ virtual QString key(int, bool) const;
+
+ LogInfo *li;
+};
+
+void LogListItem::paintCell( QPainter *p, const QColorGroup & cg,
+ int column, int width, int alignment )
+{
+ QListViewItem::paintCell(p, cg, column, width, alignment);
+
+ // double line above sum
+ //if(!li) {
+ // p->drawLine(0, 0, width, 0);
+ //p->drawLine(0, 2, width, 2);
+ //}
+}
+
+QString LogListItem::key(int c, bool ascending) const
+{
+ if (!li) // we want the sum to be always at the bottom
+ return ascending ? "z" : " ";
+
+ QString k;
+ switch (c) {
+ case 0:
+ k = li->connectionName();
+ break;
+ case 1:
+ case 2:
+ case 3:
+ k.sprintf("%012u", (uint)li->from_t());
+ break;
+ case 4:
+ k.sprintf("%012d", li->duration());
+ break;
+ case 5:
+ k.sprintf("%012.2f", li->sessionCosts());
+ break;
+ case 6:
+ k.sprintf("%012f", li->bytesIn());
+ break;
+ case 7:
+ k.sprintf("%012f", li->bytesOut());
+ break;
+ }
+ return k;
+}
+
+MonthlyWidget::MonthlyWidget(QWidget *parent) :
+ QWidget(parent)
+{
+ tl = 0;
+
+ lv = new KListView(this);
+ lv->addColumn(i18n("Connection"));
+ lv->addColumn(i18n("Day"));
+ lv->addColumn(i18n("From"));
+ lv->addColumn(i18n("Until"));
+ lv->addColumn(i18n("Duration"));
+ lv->addColumn(i18n("Costs"));
+ lv->addColumn(i18n("Bytes In"));
+ lv->addColumn(i18n("Bytes Out"));
+ lv->setColumnAlignment(1, AlignRight);
+ lv->setColumnAlignment(2, AlignRight);
+ lv->setColumnAlignment(3, AlignRight);
+ lv->setColumnAlignment(4, AlignRight);
+ lv->setColumnAlignment(5, AlignRight);
+ lv->setColumnAlignment(6, AlignRight);
+ lv->setColumnAlignment(7, AlignRight);
+ lv->setAllColumnsShowFocus(true);
+ lv->setShowSortIndicator(true);
+ lv->setItemMargin(1);
+ lv->setSorting(1);
+ lv->setMinimumWidth(180);
+ lv->setMinimumHeight(280);
+ lv->setSelectionMode(QListView::Extended);
+ selectionItem = 0L;
+ connect(lv, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()));
+
+ lv2 = new KListView(this);
+ lv2->addColumn(i18n("Connection"));
+ lv2->addColumn(i18n("Duration"));
+ lv2->addColumn(i18n("Costs"));
+ lv2->addColumn(i18n("Bytes In"));
+ lv2->addColumn(i18n("Bytes Out"));
+ lv2->setColumnAlignment(1, AlignRight);
+ lv2->setColumnAlignment(2, AlignRight);
+ lv2->setColumnAlignment(3, AlignRight);
+ lv2->setColumnAlignment(4, AlignRight);
+ lv2->setAllColumnsShowFocus(true);
+ lv2->setSorting(-1);
+ lv2->setItemMargin(2);
+ lv2->setMaximumHeight(100);
+ lv2->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
+ lv2->setSelectionMode(QListView::NoSelection);
+
+ title = new QLabel("X", this);
+ QFont f = title->font();
+ f.setPointSize(f.pointSize() + 2);
+ f.setBold(TRUE);
+ title->setFont(f);
+ title->setFixedHeight(title->sizeHint().height()*2);
+
+ cboConnections = new QComboBox(false, this); // add a combo box to select connections
+ cboConnections->setMaximumWidth(200); // a resonable size
+ cboConnections->insertItem(i18n("All Connections")); // default to all connections
+ connect(cboConnections, SIGNAL(activated(int)),
+ this, SLOT(slotConnections(int)));
+
+ bbox = new KButtonBox(this, Qt::Vertical);
+ prev = bbox->addButton(i18n("&Prev Month"));
+ next = bbox->addButton(i18n("&Next Month"));
+ bbox->addStretch(1);
+ today = bbox->addButton(i18n("C&urrent Month"));
+ bbox->addStretch(1);
+ exportBttn = bbox->addButton(i18n("&Export..."));
+
+ connect(prev, SIGNAL(released()),
+ this, SLOT(prevMonth()));
+ connect(next, SIGNAL(released()),
+ this, SLOT(nextMonth()));
+ connect(today, SIGNAL(released()),
+ this, SLOT(currentMonth()));
+ connect(exportBttn, SIGNAL(clicked()),
+ this, SLOT(exportWizard()));
+
+ bbox->addStretch(8);
+ bbox->layout();
+
+ currentMonth();
+ layoutWidget();
+}
+
+void MonthlyWidget::layoutWidget() {
+ if(tl)
+ delete tl;
+
+ tl = new QGridLayout(this, 1, 1, 11, 16, "MainLayout");
+ tl->addWidget(title, 0, 0);
+ tl->addWidget(cboConnections, 0, 1);
+ QLabel *l = new QLabel(this);
+ l->setText(i18n("Statistics:"));
+ QFont f2 = l->font();
+ f2.setPointSize(f2.pointSize() + 1);
+ f2.setBold(TRUE);
+ l->setFont(f2);
+ l->setFixedHeight(l->sizeHint().height());
+ l->setAlignment( AlignLeft );
+ tl->addWidget(l, 5, 0);
+ tl->addWidget(bbox, 1, 2);
+ tl->addMultiCellWidget(lv, 1, 4, 0, 1);
+ tl->addMultiCellWidget(lv2, 6, 6, 0, 1);
+
+ tl->activate();
+}
+
+int bestlen(QWidget *w, const char *s) {
+ return w->fontMetrics().boundingRect(s).width() + 8;
+}
+
+void MonthlyWidget::plotMonth() {
+ // name of the current connection
+ QString con;
+
+ // for collecting monthly statistics
+ int count = 0;
+ double costs = 0;
+ double bin = 0, bout = 0;
+ int duration = 0;
+ lv->clear();
+ selectionItem = 0L;
+ lv2->clear();
+
+ const KCalendarSystem * calendar = KGlobal::locale()->calendar();
+ QDate startDate = periodeFirst();
+
+ for(int i = 0; i < (int)logList.count(); i++) {
+ LogInfo *li = logList.at(i);
+
+ QDate logDate = li->from().date();
+ if ( periodeFirst() <= logDate && periodeLast() >= logDate ) {
+ // get connection name for this line
+ con = li->connectionName();
+
+ // this connection name not in the list and combo box
+ if(lstConnections.findIndex(con) == -1) {
+ lstConnections.append(con);
+ cboConnections->insertItem(con);
+ }
+ // if all connections or the selected one
+ if(cboConnections->currentText() != con &&
+ cboConnections->currentItem() != 0)
+ continue;
+ count++;
+ costs += li->sessionCosts();
+ if(bin >= 0) {
+ if(li->bytesIn() < 0)
+ bin = -1;
+ else
+ bin += li->bytesIn();
+ }
+
+ if(bout >= 0) {
+ if(li->bytesOut() < 0)
+ bout = -1;
+ else
+ bout += li->bytesOut();
+ }
+
+ duration += li->from().secsTo(li->until());
+
+ QString _bin, _bout, b;
+ if(li->bytesIn() >= 0)
+ formatBytes(li->bytesIn(), _bin);
+ else
+ _bin = i18n("n/a");
+
+ if(li->bytesOut() >= 0)
+ formatBytes(li->bytesOut(), _bout);
+ else
+ _bout = i18n("n/a");
+
+ if(li->bytes() > 0)
+ formatBytes(li->bytes(), b);
+ else
+ b = i18n("n/a");
+
+ QString day;
+ day.sprintf("%2d", li->from().date().day());
+
+ QString s_duration;
+ formatDuration(li->from().secsTo(li->until()),
+ s_duration);
+
+ QString s_lifrom, s_liuntil, s_costs;
+ s_lifrom = KGlobal::locale()->formatTime(li->from().time(), false);
+ s_liuntil = KGlobal::locale()->formatTime(li->until().time(), false);
+ s_costs = KGlobal::locale()->formatMoney(li->sessionCosts());
+
+ (void) new LogListItem(li, lv, con, day, s_lifrom, s_liuntil, s_duration, s_costs, _bin, _bout);
+ }
+ }
+
+ if(count) {
+ QString _bin, _bout, _b;
+
+ if(bin < 0)
+ _bin = i18n("n/a");
+ else
+ formatBytes(bin, _bin);
+
+ if(bout < 0)
+ _bout = i18n("n/a");
+ else
+ formatBytes(bout, _bout);
+
+ if(bin < 0 || bout < 0)
+ _b = i18n("n/a");
+ else
+ formatBytes(bout + bin, _b);
+
+ QString s_duration;
+ formatDuration(duration,
+ s_duration);
+
+ QString s_costs(KGlobal::locale()->formatMoney(costs, QString::null, 2));
+
+ selectionItem = new LogListItem(0, lv2,
+ i18n("Selection (%n connection)", "Selection (%n connections)", 0),
+ QString::null, QString::null, QString::null,
+ QString::null, QString::null, QString::null, QString::null);
+ (void) new LogListItem(0, lv2,
+ i18n("%n connection", "%n connections", count),
+ s_duration, s_costs, _bin, _bout, QString::null, QString::null, QString::null);
+
+ const KCalendarSystem * calendar = KGlobal::locale()->calendar();
+
+ if(calendar->month(periodeFirst()) == calendar->month(QDate::currentDate())) {
+
+ QString m_bin, m_bout;
+
+ if(bin < 0)
+ _bin = i18n("n/a");
+ else
+ formatBytesMonth(bin, m_bin);
+
+ if(bout < 0)
+ _bout = i18n("n/a");
+ else
+ formatBytesMonth(bout, m_bout);
+
+ QString m_duration;
+ formatDurationMonth(duration, m_duration);
+
+ costsMonth(costs, costs);
+ QString m_costs(KGlobal::locale()->formatMoney(costs, QString::null, 2));
+
+ (void) new QListViewItem(lv2, selectionItem,
+ i18n("Monthly estimates"), m_duration, m_costs, m_bin, m_bout,
+ QString::null, QString::null, QString::null);
+ }
+ }
+
+ QString t;
+ if(lv->childCount() > 0) {
+ exportBttn->setEnabled(true); // export possibility
+ t = i18n("Connection log for %1 %2")
+ .arg(calendar->monthName(startDate))
+ .arg(calendar->year(startDate));
+ } else {
+ exportBttn->setEnabled(false); // nothing to export
+ t = i18n("No connection log for %1 %2 available")
+ .arg(calendar->monthName(startDate))
+ .arg(calendar->year(startDate));
+ }
+
+ title->setText(t);
+}
+
+void MonthlyWidget::slotConnections(int) {
+ plotMonth();
+}
+
+void MonthlyWidget::nextMonth() {
+ m_periodeFirst = KGlobal::locale()->calendar()->addMonths(m_periodeFirst, 1);
+
+ plotMonth();
+}
+
+void MonthlyWidget::prevMonth() {
+ m_periodeFirst = KGlobal::locale()->calendar()->addMonths(m_periodeFirst, -1);
+
+ plotMonth();
+}
+
+void MonthlyWidget::currentMonth() {
+ const KCalendarSystem * calendar = KGlobal::locale()->calendar();
+ QDate dt = QDate::currentDate();
+ calendar->setYMD(m_periodeFirst, calendar->year(dt), calendar->month(dt), 1);
+
+ plotMonth();
+}
+
+void MonthlyWidget::exportWizard() {
+ const KCalendarSystem * calendar = KGlobal::locale()->calendar();
+ QString date = QString::fromLatin1("%1-%2") // e.g.: June-2001
+ .arg(calendar->monthName(periodeFirst()))
+ .arg(calendar->year(periodeFirst()));
+
+ ExportWizard *wizard = new ExportWizard(0, date);
+ wizard->exec();
+ if (wizard->filename.isEmpty()) { // wizard aborted...
+ return;
+ }
+ if (QFile::exists(wizard->filename)) { // overwrite?
+ if (KMessageBox::Continue!=KMessageBox::warningContinueCancel(0, i18n("A document with this name already exists."), i18n("Overwrite file?"), i18n("&Overwrite") /*, true*/)) { // no
+ return;
+ }
+ }
+
+ // open file
+ Export *exportIFace = wizard->createExportFilter();
+ if (exportIFace == NULL) { // error
+ return;
+ }
+
+ if (!exportIFace->openFile()) { // error opening
+ KMessageBox::sorry(0, i18n("An error occurred while trying to open this file"), i18n("Sorry"), true);
+ delete exportIFace;
+ return; // abort...
+ }
+
+ // start writing data
+ exportIFace->addHeadline(i18n("Connection"), i18n("Day"), i18n("From"), i18n("Until"),
+ i18n("Duration"), i18n("Costs"), i18n("Bytes In"), i18n("Bytes Out") );
+
+ // name of the current connection
+ QString con;
+
+ // for collecting monthly statistics
+ int count = 0;
+ double costs = 0;
+ double bin = 0, bout = 0;
+ int duration = 0;
+
+ for(int i = 0; i < (int)logList.count(); i++) {
+ LogInfo *li = logList.at(i);
+
+ QDate logDate = li->from().date();
+ if (periodeFirst() <= logDate && periodeLast() >= logDate ) {
+ // get connection name for this line
+ con = li->connectionName();
+
+ // this connection name not in the list and combo box
+ if(lstConnections.findIndex(con) == -1) {
+ lstConnections.append(con);
+ cboConnections->insertItem(con);
+ }
+ // if all connections or the selected one
+ if(cboConnections->currentText() != con &&
+ cboConnections->currentItem() != 0)
+ continue;
+
+ count++;
+ costs += li->sessionCosts();
+ if(bin >= 0) {
+ if(li->bytesIn() < 0)
+ bin = -1;
+ else
+ bin += li->bytesIn();
+ }
+
+ if(bout >= 0) {
+ if(li->bytesOut() < 0)
+ bout = -1;
+ else
+ bout += li->bytesOut();
+ }
+
+ duration += li->from().secsTo(li->until());
+
+ QString _bin, _bout, b;
+ if(li->bytesIn() >= 0)
+ formatBytes(li->bytesIn(), _bin);
+ else
+ _bin = i18n("n/a");
+
+ if(li->bytesOut() >= 0)
+ formatBytes(li->bytesOut(), _bout);
+ else
+ _bout = i18n("n/a");
+
+ if(li->bytes() > 0)
+ formatBytes(li->bytes(), b);
+ else
+ b = i18n("n/a");
+
+ QString day;
+ day.sprintf("%2d", li->from().date().day());
+ QString con = li->connectionName();
+
+ QString s_duration;
+ formatDuration(li->from().secsTo(li->until()),
+ s_duration);
+
+ QString s_lifrom, s_liuntil, s_costs;
+ s_lifrom = KGlobal::locale()->formatTime(li->from().time(), false);
+ s_liuntil = KGlobal::locale()->formatTime(li->until().time(), false);
+ s_costs = KGlobal::locale()->formatMoney(li->sessionCosts());
+
+ // call export method
+ exportIFace->addDataline(con, day, s_lifrom, s_liuntil, s_duration,
+ s_costs, _bin, _bout);
+
+ }
+ }
+
+ if(calendar->month(periodeFirst()) == calendar->month(QDate::currentDate())) {
+
+ QString m_bin, m_bout;
+ if(bin < 0)
+ m_bin = i18n("n/a");
+ else
+ formatBytesMonth(bin, m_bin);
+
+ if(bout < 0)
+ m_bout = i18n("n/a");
+ else
+ formatBytesMonth(bout, m_bout);
+
+ QString m_duration;
+ formatDurationMonth(duration, m_duration);
+
+ costsMonth(costs, costs);
+ QString m_costs(KGlobal::locale()->formatMoney(costs, QString::null, 2));
+
+ QString datetime = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime(), true);
+
+ exportIFace->addEmptyLine();
+ exportIFace->addDataline(i18n("Monthly estimates (%1)").arg(datetime),
+ QString::null, QString::null, QString::null, m_duration, m_costs, m_bin, m_bout);
+ }
+
+ if(count) {
+ QString _bin, _bout, _b;
+
+ if(bin < 0)
+ _bin = i18n("n/a");
+ else
+ formatBytes(bin, _bin);
+
+ if(bout < 0)
+ _bout = i18n("n/a");
+ else
+ formatBytes(bout, _bout);
+
+ if(bin < 0 || bout < 0)
+ _b = i18n("n/a");
+ else
+ formatBytes(bout + bin, _b);
+
+ QString s_duration;
+ formatDuration(duration,
+ s_duration);
+
+ QString s_costs(KGlobal::locale()->formatMoney(costs, QString::null, 2));
+
+ // call export methods
+ exportIFace->addEmptyLine();
+ exportIFace->addDataline(i18n("%n connection", "%n connections", count), QString::null, QString::null, QString::null, s_duration,
+ s_costs, _bin, _bout);
+ exportIFace->setFinishCode();
+
+ // write buffer to file and close file
+ if (!exportIFace->closeFile()) {
+ KMessageBox::sorry(0, i18n("An error occurred while trying to write to this file."), i18n("Sorry"), true);
+ delete exportIFace;
+ return;
+ }
+
+ }
+ delete exportIFace;
+}
+
+QDate MonthlyWidget::periodeFirst() const
+{
+ return m_periodeFirst;
+}
+
+QDate MonthlyWidget::periodeLast() const
+{
+ const KCalendarSystem * calendar = KGlobal::locale()->calendar();
+
+ // One month minus one day
+ return calendar->addDays(calendar->addMonths(m_periodeFirst, 1), -1);
+}
+
+void MonthlyWidget::slotSelectionChanged()
+{
+ if (selectionItem)
+ {
+ int count = 0;
+ double costs = 0;
+ double bin = 0, bout = 0;
+ int duration = 0;
+ LogListItem *item;
+ LogInfo *li;
+ QListViewItemIterator it(lv);
+ while ( it.current() )
+ {
+ item = dynamic_cast<LogListItem*>(it.current());
+ if ( item && item->isSelected() && item->li)
+ {
+ li = item->li;
+ costs += li->sessionCosts();
+ if(bin >= 0) {
+ if(li->bytesIn() < 0)
+ bin = -1;
+ else
+ bin += li->bytesIn();
+ }
+
+ if(bout >= 0) {
+ if(li->bytesOut() < 0)
+ bout = -1;
+ else
+ bout += li->bytesOut();
+ }
+
+ duration += li->from().secsTo(li->until());
+ count++;
+ }
+ ++it;
+ }
+ if(count)
+ {
+ QString _bin, _bout, _b;
+
+ if(bin < 0)
+ _bin = i18n("n/a");
+ else
+ formatBytes(bin, _bin);
+
+ if(bout < 0)
+ _bout = i18n("n/a");
+ else
+ formatBytes(bout, _bout);
+
+ if(bin < 0 || bout < 0)
+ _b = i18n("n/a");
+ else
+ formatBytes(bout + bin, _b);
+
+ QString s_duration;
+ formatDuration(duration,
+ s_duration);
+
+ QString s_costs(KGlobal::locale()->formatMoney(costs, QString::null, 2));
+ selectionItem->setText(0, i18n("Selection (%n connection)", "Selection (%n connections)", count));
+ selectionItem->setText(1, s_duration);
+ selectionItem->setText(2, s_costs);
+ selectionItem->setText(3, _bin);
+ selectionItem->setText(4, _bout);
+ }
+ }
+}
+
+#include "monthly.moc"
diff --git a/kppp/logview/monthly.h b/kppp/logview/monthly.h
new file mode 100644
index 00000000..2a3cefc8
--- /dev/null
+++ b/kppp/logview/monthly.h
@@ -0,0 +1,80 @@
+/*
+ * kPPPlogview: a accounting log system for kPPP
+ *
+ * Copyright (C) 1998 Mario Weilguni <mweilguni@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+
+#ifndef __MONTHLY__H__
+#define __MONTHLY__H__
+
+#include "log.h"
+#include <qwidget.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qpushbutton.h>
+#include <qvaluelist.h>
+#include <qdatetime.h>
+
+#include <kbuttonbox.h>
+
+class KListView;
+class QComboBox;
+class LogListItem;
+
+class MonthlyWidget : public QWidget {
+ Q_OBJECT
+public:
+ MonthlyWidget(QWidget *parent = 0);
+
+private slots:
+ void prevMonth();
+ void nextMonth();
+ void currentMonth();
+ void slotConnections(int);
+ void exportWizard();
+ void slotSelectionChanged();
+
+private:
+ void layoutWidget();
+ void plotMonth();
+
+ /**
+ * Returns the first day in the period
+ */
+ QDate periodeFirst() const;
+ /**
+ * Returns the last day in the period
+ */
+ QDate periodeLast() const;
+
+ QDate m_periodeFirst; // First day in month
+ //int _month, _year;
+
+ QComboBox *cboConnections;
+ KButtonBox *bbox;
+ KListView *lv;
+ KListView *lv2;
+ LogListItem* selectionItem;
+ QLabel *title;
+ QPushButton *next, *prev, *today, *exportBttn;
+ QValueList<QString> lstConnections;
+ QGridLayout *tl;
+ QDateTime *dt;
+};
+
+#endif