[Openvas-commits] r12221 - in trunk/gsd: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 30 12:26:19 CET 2011


Author: raimund
Date: 2011-11-30 12:26:16 +0100 (Wed, 30 Nov 2011)
New Revision: 12221

Modified:
   trunk/gsd/ChangeLog
   trunk/gsd/src/delegate_date_time.cpp
   trunk/gsd/src/delegate_date_time.h
   trunk/gsd/src/dock_details.cpp
   trunk/gsd/src/gsd_mw.cpp
Log:
Parse the new timestamp format to have the same format like in GSA.

* src/gsd_mw.cpp (gsd_mw::prepareWidgets): Use item delegates in report
format table and schedule table.

* src/dock_details.cpp (dock_details_task::update): Use item delegates in task
details widget.
(dock_details_schedule::update, dock_details_note::update,
dock_details_override::update): Use new format for schedule details, note
details and override details.

* src/delegate_date_time.cpp (delegate_date_time::paint): Use the full date
format or a short format.
(delegate_date_time::modifyDate): Parse the new timestamp format.
(delegate_date_time::formatDate): New.

* src/delegate_date_time.h: Updated prototypes.



Modified: trunk/gsd/ChangeLog
===================================================================
--- trunk/gsd/ChangeLog	2011-11-30 07:28:01 UTC (rev 12220)
+++ trunk/gsd/ChangeLog	2011-11-30 11:26:16 UTC (rev 12221)
@@ -1,3 +1,23 @@
+2011-11-30  Raimund Renkert <raimund.renkert at greenbone.net>
+
+	Parse the new timestamp format to have the same format like in GSA.
+
+	* src/gsd_mw.cpp (gsd_mw::prepareWidgets): Use item delegates in report
+	format table and schedule table.
+
+	* src/dock_details.cpp (dock_details_task::update): Use item delegates in task
+	details widget.
+	(dock_details_schedule::update, dock_details_note::update,
+	dock_details_override::update): Use new format for schedule details, note
+	details and override details.
+
+	* src/delegate_date_time.cpp (delegate_date_time::paint): Use the full date
+	format or a short format.
+	(delegate_date_time::modifyDate): Parse the new timestamp format.
+	(delegate_date_time::formatDate): New.
+
+	* src/delegate_date_time.h: Updated prototypes.
+
 2011-11-29  Raimund Renkert <raimund.renkert at greenbone.net>
 
 	Updated the gsd to accept omp version 3.0.

Modified: trunk/gsd/src/delegate_date_time.cpp
===================================================================
--- trunk/gsd/src/delegate_date_time.cpp	2011-11-30 07:28:01 UTC (rev 12220)
+++ trunk/gsd/src/delegate_date_time.cpp	2011-11-30 11:26:16 UTC (rev 12221)
@@ -303,14 +303,24 @@
                 }
             }
         }
-      if (model->getHeader (index.column ()).contains ("timestamp"))
+      QString header = model->getHeader (index.column ());
+      if (header.contains ("time"))
         {
+          bool full = false;
+          if (header.contains ("first_time") ||
+              header.contains ("next_time") ||
+              model->getEntity (index.column ()).tagName ().compare ("report")
+                == 0)
+            {
+              full = true;
+            }
+          QString modDate = modifyDate(temp, full);
           QApplication::style ()->drawItemText(painter,
                                                option.rect,
                                                Qt::AlignVCenter,
                                                opts.palette,
                                                true,
-                                               modifyDate (temp),
+                                               modDate,
                                                QPalette::HighlightedText);
           return;
         }
@@ -326,60 +336,92 @@
  * new string
  *
  *  @param date ompdate as string.
+ *  @param full print out the full date.
  **/
 QString
-delegate_date_time::modifyDate (QString date) const
+delegate_date_time::modifyDate (QString date, bool full) const
 {
   if (date.length()>0)
     {
-	  QDateTime qdate;
+      QDateTime qdate;
 
-	  /* Try parse ISO format. */
-	  qdate = QDateTime::fromString (date, Qt::ISODate);
-	  if (qdate.isValid ())
-		{
-		  QString ret;
-		  QDate d;
-		  d = qdate.date ();
-		  ret = d.shortMonthName (d.month ())
-				 + " "
-				 + QString::number (d.day ())
-				 + " "
-				 + QString::number (d.year ());
+      /* Try parse ISO format. */
+      qdate = QDateTime::fromString (date, Qt::ISODate);
+      if (qdate.isValid ())
+        {
+          QString ret = "";
+          QDate d;
+          d = qdate.date ();
+          if (full)
+            {
+              QString day;
+              switch (d.dayOfWeek ())
+                {
+                  case 1: day = tr ("Mon"); break;
+                  case 2: day = tr ("Tue"); break;
+                  case 3: day = tr ("Wed"); break;
+                  case 4: day = tr ("Thu"); break;
+                  case 5: day = tr ("Fri"); break;
+                  case 6: day = tr ("Sat"); break;
+                  case 7: day = tr ("Sun"); break;
+                  default: day = "";
+                }
+              ret = day;
+            }
+          ret += " " + d.shortMonthName (d.month ())
+                     + " "
+                     + QString::number (d.day ());
+          if (full)
+            {
+              ret += " " + qdate.time ().toString ();
+            }
+          ret += " " + QString::number (d.year ());
           return ret;
-		}
-	  else
-	    {
-		  QStringList cleaned;
+        }
+      else
+        {
+          QStringList cleaned;
 
-		  /* Failed, try parse ctime format. */
-		  cleaned = date.split (" ");
-		  if (cleaned.size () < 5)
-			{
+          /* Failed, try parse ctime format. */
+          cleaned = date.split (" ");
+          if (cleaned.size () < 5)
+            {
 
-			}
-		  for (int i = 0; i < cleaned.size()-1; i++)
-			{
-			  if (cleaned[i].length() == 0)
-				{
-				  cleaned[i] = cleaned[i+1];
-				  cleaned[i+1] = "";
-				}
-			}
-		  if (cleaned.last() == "")
-			cleaned.removeLast();
-		  cleaned [3] = cleaned [4];
-		  cleaned.removeLast ();
-		  QDate d = QDate::fromString (cleaned.join(" "));
-		  QString ret = d.shortMonthName (d.month ()) + " " +
-						QString::number (d.day ()) + " " +
-						QString::number ( d.year ());
+            }
+          for (int i = 0; i < cleaned.size()-1; i++)
+            {
+              if (cleaned[i].length() == 0)
+                {
+                  cleaned[i] = cleaned[i+1];
+                  cleaned[i+1] = "";
+                }
+            }
+          if (cleaned.last() == "")
+            cleaned.removeLast();
+          cleaned [3] = cleaned [4];
+          cleaned.removeLast ();
+          QDate d = QDate::fromString (cleaned.join(" "));
+          QString ret = d.shortMonthName (d.month ()) + " " +
+                                          QString::number (d.day ()) + " " +
+                                          QString::number ( d.year ());
           return ret;
-		}
-	}
+        }
+    }
   else
     {
       return "";
     }
 }
 
+/**
+ * @brief Modifies the date string equal to the table view delegate.
+ *
+ * @param date The date string
+ * @param full Print out the full date or the short date.
+ */
+QString
+delegate_date_time::formatDate (QString date, bool full)
+{
+  return modifyDate(date, full);
+}
+

Modified: trunk/gsd/src/delegate_date_time.h
===================================================================
--- trunk/gsd/src/delegate_date_time.h	2011-11-30 07:28:01 UTC (rev 12220)
+++ trunk/gsd/src/delegate_date_time.h	2011-11-30 11:26:16 UTC (rev 12221)
@@ -39,7 +39,7 @@
   Q_OBJECT
 
   private:
-    QString modifyDate (QString date) const;
+    QString modifyDate (QString date, bool full) const;
 
   public:
     delegate_date_time ();
@@ -57,6 +57,7 @@
                 const QModelIndex& index) const;
 
     void setFormat (QString);
+    QString formatDate (QString date, bool full);
 };
 #endif
 

Modified: trunk/gsd/src/dock_details.cpp
===================================================================
--- trunk/gsd/src/dock_details.cpp	2011-11-30 07:28:01 UTC (rev 12220)
+++ trunk/gsd/src/dock_details.cpp	2011-11-30 11:26:16 UTC (rev 12221)
@@ -104,6 +104,9 @@
                              ")");
 
   delegate_threat *delegate = new delegate_threat ();
+  delegate_date_time *d_time = new delegate_date_time ();
+
+  tv_reports->setItemDelegateForColumn (0, d_time);
   tv_reports->setItemDelegateForColumn (1, delegate);
   reports->removeEntities ();
   QDomElement rep = tasks->getEntities (task, "reports report", "reports");
@@ -690,12 +693,20 @@
 
   tasks->resetFilter ();
 
+  delegate_date_time *dateDelegate = new delegate_date_time ();
+
   this->setWindowTitle ("Schedule " +
                         schedules->getValue (showElement, "name"));
   this->la_name_v->setText (schedules->getValue (showElement, "name"));
   this->la_comment_v->setText (schedules->getValue (showElement, "comment"));
-  this->la_first_time_v->setText (schedules->getValue (showElement, "first_time"));
-  this->la_next_time_v->setText (schedules->getValue (showElement, "next_time"));
+  QString first =
+    dateDelegate->formatDate (schedules->getValue (showElement, "first_time"),
+                              true);
+  this->la_first_time_v->setText (first);
+  QString next =
+    dateDelegate->formatDate (schedules->getValue (showElement, "next_time"),
+                              true);
+  this->la_next_time_v->setText (next);
   this->la_period_v->setText (schedules->getValue (showElement, "period"));
   this->la_duration_v->setText (schedules->getValue (showElement, "duration"));
   load ();
@@ -1722,12 +1733,19 @@
         }
       i++;
     }
+
+  delegate_date_time *dateDelegate = new delegate_date_time ();
+
   this->setWindowTitle ("Note " + note->getValue (elem, "nvt name"));
   this->task_id = note->getAttr (elem, "note task id");
   this->la_name_v->setText (note->getValue(elem, "nvt name"));
   this->la_oid_v->setText (note->getAttr (elem, "note nvt oid"));
-  this->la_created_v->setText (note->getValue (elem, "creation_time"));
-  this->la_modified_v->setText (note->getValue (elem, "modification_time"));
+  QString creation =
+    dateDelegate->formatDate (note->getValue (elem, "creation_time"), true);
+  this->la_created_v->setText (creation);
+  QString modification = 
+    dateDelegate->formatDate (note->getValue (elem, "modification_time"), true);
+  this->la_modified_v->setText (modification);
   this->la_hosts_v->setText (note->getValue (elem, "hosts"));
   this->la_port_v->setText (note->getValue (elem, "port"));
   this->la_threat_v->setText (note->getValue (elem, "threat"));
@@ -1866,11 +1884,18 @@
       i++;
     }
 
+  delegate_date_time *dateDelegate = new delegate_date_time ();
+
   this->setWindowTitle ("Override " + override->getValue (elem, "nvt name"));
   this->la_name_v->setText (override->getValue(elem, "nvt name"));
   this->la_oid_v->setText (override->getAttr (elem, "override nvt oid"));
-  this->la_created_v->setText (override->getValue (elem, "creation_time"));
-  this->la_modified_v->setText (override->getValue (elem, "modification_time"));
+  QString creation =
+    dateDelegate->formatDate (override->getValue (elem, "creation_time"), true);
+  this->la_created_v->setText (creation);
+  QString modification =
+    dateDelegate->formatDate (override->getValue (elem, "modification_time"),
+                              true);
+  this->la_modified_v->setText (modification);
   this->la_hosts_v->setText (override->getValue (elem, "hosts"));
   this->la_port_v->setText (override->getValue (elem, "port"));
   this->la_threat_v->setText (override->getValue (elem, "threat"));

Modified: trunk/gsd/src/gsd_mw.cpp
===================================================================
--- trunk/gsd/src/gsd_mw.cpp	2011-11-30 07:28:01 UTC (rev 12220)
+++ trunk/gsd/src/gsd_mw.cpp	2011-11-30 11:26:16 UTC (rev 12221)
@@ -339,6 +339,8 @@
   tv_schedules->setObjectName ("tv_schedules");
   tv_schedules->setItemDelegateForColumn (4, date_time);
   tv_schedules->setItemDelegateForColumn (3, date_time);
+  tv_schedules->setItemDelegateForColumn (2, date_time);
+  tv_schedules->setItemDelegateForColumn (1, date_time);
   tv_schedules->horizontalHeader ()->setResizeMode (QHeaderView::Fixed);
   tv_schedules->horizontalHeader ()->setResizeMode (0, QHeaderView::Stretch);
   tv_schedules->setColumnWidth (0, 120);
@@ -554,6 +556,7 @@
   QTableView *tv_reportformats = reportformats->getTable ();
   tv_reportformats->setObjectName ("tv_reportformats");
   tv_reportformats->setItemDelegateForColumn (5, text);
+  tv_reportformats->setItemDelegateForColumn (4, date_time);
   tv_reportformats->horizontalHeader ()->setResizeMode (QHeaderView::Fixed);
   tv_reportformats->horizontalHeader ()->setResizeMode (0, QHeaderView::Stretch);
   tv_reportformats->setColumnWidth (0, 150);



More information about the Openvas-commits mailing list