[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: kppplogview enhancements
From:       Mikolaj Machowski <mikmach () wp ! pl>
Date:       2003-05-10 19:03:21
[Download RAW message or body]

On Wed, Apr 30, 2003 at 03:16:44PM +0300, Andras Mantia wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> Not so long ago I've patched the log viewer that you can select a part of the 
> list and it will show the sum for selection. Very useful if accounting period 
> starts in the middle of the month. Please patch the current version and send 
> the new patch to the list. If there are no objections, I will gladly commit 
> to the CVS.

OK. Here are updated patches against KDE snap from 2.05.

m.

["monthly.cpp.diff" (text/plain)]

--- ../logview.orig/monthly.cpp	2003-05-10 19:40:56.000000000 +0200
+++ monthly.cpp	2003-05-10 20:52:41.000000000 +0200
@@ -21,6 +21,7 @@
 #include <qpainter.h>
 #include <qcombobox.h>
 #include <qfile.h>
+#include <qheader.h>
 
 #include <kcalendarsystem.h>
 #include <klocale.h>
@@ -41,6 +42,22 @@
   else
     result = i18n("%1 MB").arg(KGlobal::locale()->formatNumber((float)bytes / 1024.0 \
/ 1024.0, 1));  }
+ 
+static void formatBytesMonth(int 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;
@@ -55,6 +72,37 @@
         .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:
@@ -72,6 +120,7 @@
 			  int column, int width, int alignment );
 
     virtual QString key(int, bool) const;
+
     LogInfo *li;
 };
 
@@ -81,10 +130,10 @@
   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);
-  }
+  //if(!li) {
+   // p->drawLine(0, 0, width, 0);
+    //p->drawLine(0, 2, width, 2);
+  //}
 }
 
 QString LogListItem::key(int c, bool ascending) const
@@ -141,14 +190,54 @@
   lv->setColumnAlignment(7, AlignRight);
   lv->setAllColumnsShowFocus(true);
   lv->setShowSortIndicator(true);
-  lv->setItemMargin(2);
+  lv->setItemMargin(1);
   lv->setSorting(1);
-  lv->setMinimumWidth(320);
-  lv->setMinimumHeight(200);
+  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("Day"));
+  lv2->addColumn(i18n("From"));
+  lv2->addColumn(i18n("Until"));
+  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->setColumnAlignment(5, AlignRight);
+  lv2->setColumnAlignment(6, AlignRight);
+  lv2->setColumnAlignment(7, AlignRight);
+  lv2->setAllColumnsShowFocus(true);
+  lv2->setShowSortIndicator(true);
+  lv2->setItemMargin(2);
+  lv2->setMinimumWidth(180);
+  lv2->setMaximumHeight(25);
+  lv2->header()->hide();
+
+  lv3 = new KListView(this);
+  lv3->addColumn(i18n("Duration"));
+  lv3->addColumn(i18n("Costs"));
+  lv3->addColumn(i18n("Bytes In"));
+  lv3->addColumn(i18n("Bytes Out"));
+  lv3->setColumnAlignment(0, AlignRight);
+  lv3->setColumnAlignment(1, AlignRight);
+  lv3->setColumnAlignment(2, AlignRight);
+  lv3->setColumnAlignment(3, AlignRight);
+  lv3->setAllColumnsShowFocus(true);
+  lv3->setShowSortIndicator(true);
+  lv3->setItemMargin(2);
+  lv3->setMinimumWidth(250);
+  lv3->setMaximumWidth(600);
+  lv3->setMaximumHeight(25);
+  lv3->header()->hide();
+
   title = new QLabel("X", this);
   QFont f = title->font();
   f.setPointSize(f.pointSize() + 2);
@@ -156,6 +245,15 @@
   title->setFont(f);
   title->setFixedHeight(title->sizeHint().height()*2);
 
+  estimates = new QLabel(i18n("Monthly estimates:"), this);
+  QFont f2 = estimates->font();
+  f2.setPointSize(f2.pointSize() + 1);
+  f2.setBold(TRUE);
+  estimates->setFont(f2);
+  estimates->setFixedHeight(estimates->sizeHint().height());
+  estimates->setAlignment( AlignLeft );
+  //estimates->setFixedWidth(200);
+
   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 @@ -189,14 +287,24 @@
 void MonthlyWidget::layoutWidget() {
   if(tl)
     delete tl;
-  tl = new QVBoxLayout(this, 10, 10);
-  tl->addWidget(title);
-  tl->addWidget(cboConnections, 1);	// add the combo box
-
-  QHBoxLayout *l1 = new QHBoxLayout;
-  tl->addLayout(l1, 1);
-  l1->addWidget(lv, 1);
-  l1->addWidget(bbox);
+  tl = new QVBoxLayout(this, 5, 5);
+
+  QGridLayout *g1 = new QGridLayout;
+  tl->addLayout(g1);
+
+  g1 = new QGridLayout(tl, 3, 2);
+  g1->addColSpacing(1, 400);
+
+  g1->addMultiCellWidget(title, 0, 0, 0, 1, AlignLeft);
+  g1->addWidget(cboConnections, 0, 1, AlignRight);
+
+  g1->addMultiCellWidget(lv, 1, 1, 0, 1, AlignRight);
+  g1->addWidget(bbox, 1, 2);
+
+  g1->addMultiCellWidget(lv2, 2, 2, 0, 1, AlignRight);
+
+  g1->addMultiCellWidget(estimates, 3, 3, 0, 1, AlignLeft);
+  g1->addWidget(lv3, 3, 1, AlignRight);
 
   tl->activate();
 }
@@ -216,6 +324,11 @@
   int duration = 0;
   lv->clear();
   selectionItem = 0L;
+  lv2->clear();
+  lv3->clear();
+
+  const KCalendarSystem * calendar = KGlobal::locale()->calendar();
+  QDate startDate = periodeFirst();
 
   for(int i = 0; i < (int)logList.count(); i++) {
     LogInfo *li = logList.at(i);
@@ -312,14 +425,39 @@
 			   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, lv,
+    (void) new LogListItem(0, lv2,
 			   i18n("%n connection", "%n connections", count),
 			   QString::null, QString::null, QString::null,
 			   s_duration, s_costs, _bin, _bout);
+
+	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 LogListItem(0, lv3,
+			   m_duration, m_costs, m_bin, m_bout,
+			   QString::null, QString::null, QString::null, QString::null);
+	}
   }
 
-  const KCalendarSystem * calendar = KGlobal::locale()->calendar();
-  QDate startDate = periodeFirst();
   QString t;
   if(lv->childCount() > 0) {
     exportBttn->setEnabled(true); // export possibility
@@ -372,7 +510,7 @@
     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 +    if \
(KMessageBox::Continue!=KMessageBox::warningContinueCancel(0, i18n("A document with \
this name already exists."), i18n("Overwrite file?"), i18n("&Overwrite") /*, true*/)) \
{ // no  return;
     }
   }
@@ -470,9 +608,36 @@
       // 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;
 


["monthly.h.diff" (text/plain)]

--- ../logview.orig/monthly.h	2003-05-10 19:40:56.000000000 +0200
+++ monthly.h	2003-05-10 19:45:00.000000000 +0200
@@ -68,11 +68,16 @@
   QComboBox *cboConnections;
   KButtonBox *bbox;
   QListView *lv;
+  QListView *lv2;
+  QListView *lv3;
   LogListItem* selectionItem;
   QLabel *title;
+  QLabel *estimates;
   QPushButton *next, *prev, *today, *exportBttn;
   QValueList<QString> lstConnections;
   QVBoxLayout *tl;
+  QGridLayout *g1;
+  QDateTime *dt;
 };
 
 #endif


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic