[Openvas-commits] r7986 - in trunk/gsa-desktop: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Jun 9 18:24:06 CEST 2010
Author: raimund
Date: 2010-06-09 18:24:05 +0200 (Wed, 09 Jun 2010)
New Revision: 7986
Added:
trunk/gsa-desktop/src/delegate_date_time.cpp
trunk/gsa-desktop/src/delegate_date_time.h
trunk/gsa-desktop/src/model_omp_entity.cpp
trunk/gsa-desktop/src/model_omp_entity.h
trunk/gsa-desktop/src/omp_update_entity.cpp
trunk/gsa-desktop/src/omp_update_entity.h
Removed:
trunk/gsa-desktop/src/model_schedule.cpp
trunk/gsa-desktop/src/model_schedule.h
trunk/gsa-desktop/src/model_task.cpp
trunk/gsa-desktop/src/model_task.h
trunk/gsa-desktop/src/omp_entity_schedule.h
trunk/gsa-desktop/src/omp_entity_status.h
trunk/gsa-desktop/src/omp_update_schedules.cpp
trunk/gsa-desktop/src/omp_update_schedules.h
trunk/gsa-desktop/src/omp_update_status.cpp
trunk/gsa-desktop/src/omp_update_status.h
Modified:
trunk/gsa-desktop/ChangeLog
trunk/gsa-desktop/src/delegate_icon.cpp
trunk/gsa-desktop/src/delegate_icon.h
trunk/gsa-desktop/src/delegate_progress.cpp
trunk/gsa-desktop/src/delegate_progress.h
trunk/gsa-desktop/src/delegate_threat.cpp
trunk/gsa-desktop/src/delegate_threat.h
trunk/gsa-desktop/src/delegate_trend.cpp
trunk/gsa-desktop/src/delegate_trend.h
trunk/gsa-desktop/src/dock_table.cpp
trunk/gsa-desktop/src/dock_table.h
trunk/gsa-desktop/src/gsa_desktop_control.cpp
trunk/gsa-desktop/src/gsa_desktop_control.h
trunk/gsa-desktop/src/gsa_desktop_mainwindow.ui
trunk/gsa-desktop/src/gsa_desktop_ui.cpp
trunk/gsa-desktop/src/gsa_desktop_ui.h
trunk/gsa-desktop/src/omp_connector.cpp
trunk/gsa-desktop/src/omp_connector.h
trunk/gsa-desktop/src/omp_update.cpp
trunk/gsa-desktop/src/omp_update.h
trunk/gsa-desktop/src/src.pro
Log:
Change omp request and model concept. Requests to the openvas-manager
are in one thread now. The thread converts the requested omp entities to dom
elements and adds them to the model.
* src/omp_update_status.h, src/omp_update_status.cpp,
src/omp_update_schedules.h, src/omp_update_schedules.cpp: Removed. Replaced by
src/omp_update_entity.h, src/omp_update_entity.cpp.
* src/omp_update_entity.h, src/omp_update_entity.cpp: New.
* src/model_task.h, src/model_task.cpp, src/model_schedule.h,
src/model_schedule.cpp: Removed. Replaced by src/model_omp_entity.h,
src/model_omp_entity.cpp.
* src/model_omp_entity.h, src/model_omp_entity.cpp: New.
* src/omp_entity_status.h, src/omp_entity_schedule.h: Removed. Entities are
stored in dom elements.
* src/delegate_date_time.h, src/delegate_date_time.cpp: New. Modifies Date
and times for durations and periods, functions moved from
omp_update_schedule, omp_update_status.
* src/delegate_progress.h, src/delegate_progress.cpp, src/delegate_trend.h
src/delegate_trend.cpp, src/delegate_icon.h, src/delegate_icon.cpp: Updated
the used model and entities.
* src/delegate_threat.h, src/delegate_threat.cpp: Updated the used model and
entities. Added threat calculation, moved from omp_update_status.
* src/gsa_dektop_ui.cpp (gsa_desktop_ui, modifyWidgets): Added Widget, model
and delegate_date_time to display schedules.
(gsa_desktop_ui, createConnections, refresh, refresh_stop)
(refresh_manualstop, taskupdate_finished): Added Timer to take the time
between updates.
(logout): Remove entites from schedule model.
(task_selectionchanged, task_start, task_stop, task_delete, task_contextmenu):
Changed to fit new model.
(schedule_dw): New.
* src/gsa_desktop_control.cpp (createConnections): Added schedules request.
(request_schedules): New.
* src/omp_connector.cpp (omp_connector, getStatus, stopTaskUpdates)
(taskUpdateRunning, taskupdate_finished): Updated to fit new update concept.
(getSchedules): New.
* src/omp_update.cpp (omp_update): Changed mutex initialization.
* src/omp_update.h: Added variable to show if an update is in progress,
updated prototypes.
* src/gsa_desktop_control.h, src/gsa_desktop_ui.h, src/omp_connector.h: Updated
prototypes.
* src/gsa_desktop_mainwindow.ui: Changed height, added new menu "view".
* src/src.pro: Removed old header and source files, added new files. Added
Windows libraries for cross compilation.
Modified: trunk/gsa-desktop/ChangeLog
===================================================================
--- trunk/gsa-desktop/ChangeLog 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/ChangeLog 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,3 +1,65 @@
+2010-06-09 Raimund Renkert <raimund.renkert at intevation.de>
+
+ Change omp request and model concept. Requests to the openvas-manager
+ are in one thread now. The thread converts the requested omp entities to dom
+ elements and adds them to the model.
+
+ * src/omp_update_status.h, src/omp_update_status.cpp,
+ src/omp_update_schedules.h, src/omp_update_schedules.cpp: Removed. Replaced by
+ src/omp_update_entity.h, src/omp_update_entity.cpp.
+
+ * src/omp_update_entity.h, src/omp_update_entity.cpp: New.
+
+ * src/model_task.h, src/model_task.cpp, src/model_schedule.h,
+ src/model_schedule.cpp: Removed. Replaced by src/model_omp_entity.h,
+ src/model_omp_entity.cpp.
+
+ * src/model_omp_entity.h, src/model_omp_entity.cpp: New.
+
+ * src/omp_entity_status.h, src/omp_entity_schedule.h: Removed. Entities are
+ stored in dom elements.
+
+ * src/delegate_date_time.h, src/delegate_date_time.cpp: New. Modifies Date
+ and times for durations and periods, functions moved from
+ omp_update_schedule, omp_update_status.
+
+ * src/delegate_progress.h, src/delegate_progress.cpp, src/delegate_trend.h
+ src/delegate_trend.cpp, src/delegate_icon.h, src/delegate_icon.cpp: Updated
+ the used model and entities.
+
+ * src/delegate_threat.h, src/delegate_threat.cpp: Updated the used model and
+ entities. Added threat calculation, moved from omp_update_status.
+
+ * src/gsa_dektop_ui.cpp (gsa_desktop_ui, modifyWidgets): Added Widget, model
+ and delegate_date_time to display schedules.
+ (gsa_desktop_ui, createConnections, refresh, refresh_stop)
+ (refresh_manualstop, taskupdate_finished): Added Timer to take the time
+ between updates.
+ (logout): Remove entites from schedule model.
+ (task_selectionchanged, task_start, task_stop, task_delete, task_contextmenu):
+ Changed to fit new model.
+ (schedule_dw): New.
+
+ * src/gsa_desktop_control.cpp (createConnections): Added schedules request.
+ (request_schedules): New.
+
+ * src/omp_connector.cpp (omp_connector, getStatus, stopTaskUpdates)
+ (taskUpdateRunning, taskupdate_finished): Updated to fit new update concept.
+ (getSchedules): New.
+
+ * src/omp_update.cpp (omp_update): Changed mutex initialization.
+
+ * src/omp_update.h: Added variable to show if an update is in progress,
+ updated prototypes.
+
+ * src/gsa_desktop_control.h, src/gsa_desktop_ui.h, src/omp_connector.h: Updated
+ prototypes.
+
+ * src/gsa_desktop_mainwindow.ui: Changed height, added new menu "view".
+
+ * src/src.pro: Removed old header and source files, added new files. Added
+ Windows libraries for cross compilation.
+
2010-05-21 Raimund Renkert <raimund.renkert at intevation.de>
* src/omp_update_schedules.h, src/omp_update_schedules.cpp,
Added: trunk/gsa-desktop/src/delegate_date_time.cpp
===================================================================
--- trunk/gsa-desktop/src/delegate_date_time.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_date_time.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -0,0 +1,364 @@
+/**
+ * Copyright:
+ * Copyright (C) 2010 by Greenbone Networks GmbH
+ *
+ * Authors:
+ * Raimund Renkert <raimund.renkert at intevation.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "delegate_date_time.h"
+
+/**
+ * @file delegate_icon.cpp
+ * @brief Delegate for icons.
+ *
+ * Used for painting the icons in widgets like tableview, treeview, etc.
+ */
+
+delegate_date_time::delegate_date_time ()
+{
+}
+
+delegate_date_time::~delegate_date_time()
+{
+}
+
+
+/**
+ * @brief New implemented paintfunction.
+ *
+ * Implementation to paint an icon in a view widget.
+ *
+ * @param painter Painter to draw the icon
+ * @param option Styleoptions
+ * @param index viewindex
+ */
+void
+delegate_date_time::paint (QPainter* painter,
+ const QStyleOptionViewItem& option,
+ const QModelIndex& index) const
+{
+ model_omp_entity * model = (model_omp_entity*) index.model ();
+
+ if (model == 0)
+ {
+ QStyledItemDelegate::paint (painter, option, index);
+ return;
+ }
+ QColor c;
+ QStyleOptionViewItem opts (option);
+ QDomElement pItem = model->getEntity (index.row ());
+ if (!pItem.isNull ())
+ {
+ if (option.state & QStyle::State_Selected)
+ {
+ if (!(option.state & QStyle::State_Active))
+ {
+ painter->fillRect (option.rect,
+ option.palette.color
+ (QPalette::Inactive,
+ QPalette::Highlight));
+ c = option.palette.color (QPalette::Inactive,
+ QPalette::HighlightedText);
+ }
+ else
+ {
+ painter->fillRect (option.rect,
+ option.palette.color (QPalette::Active,
+ QPalette::Highlight));
+ c = option.palette.color (QPalette::Active,
+ QPalette::HighlightedText);
+ }
+ }
+ opts.palette.setColor (QPalette::HighlightedText, c);
+ bool *ok = false;
+ QString temp = model->getValue (pItem, model->getHeader (index.column ()));
+ if (model->getHeader (index.column ()).compare ("duration") == 0)
+ {
+ qlonglong nbr = temp.toLongLong (ok, 10);
+ long time = nbr;
+ time /= 3600;
+ long hour = time % 24;
+ time /= 24;
+ long day = time % 7;
+ time /= 7;
+ long week = time;
+ QString s;
+ if (hour == 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (hour, 10)
+ + " hour"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (hour > 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (hour, 10)
+ + " hours"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (day == 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (day, 10)
+ + " day"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (day > 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (day, 10)
+ + " days"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (week == 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (week, 10)
+ + " week"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (week > 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (week, 10)
+ + " weeks"),
+ QPalette::HighlightedText);
+ return;
+ }
+ }
+ if (model->getHeader (index.column ()).compare ("period") == 0)
+ {
+ qlonglong nbr = temp.toLongLong (ok, 10);
+ if (nbr != 0)
+ {
+ long time = nbr;
+ time /= 3600;
+ long hour = time % 24;
+ time /= 24;
+ long day = time % 7;
+ time /= 7;
+ long week = time;
+ QString s;
+ if (hour == 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (hour, 10)
+ + " hour"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (hour > 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ opts.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (hour, 10)
+ + " hours"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (day == 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (day, 10)
+ + " day"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (day > 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (day, 10)
+ + " days"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (week == 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (week, 10)
+ + " week"),
+ QPalette::HighlightedText);
+ return;
+ }
+ else if (week > 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (week, 10)
+ + " weeks"),
+ QPalette::HighlightedText);
+ return;
+ }
+ }
+ else
+ {
+ temp = model->getValue (pItem, "period_months");
+ nbr = temp.toLongLong (ok, 10);
+ QString s;
+ if (nbr == 1 )
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (nbr, 10)
+ + " month"),
+ QPalette::HighlightedText);
+ return;
+ }
+ if (nbr > 1)
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ QString
+ (s.setNum (nbr, 10)
+ + " months"),
+ QPalette::HighlightedText);
+ return;
+ }
+ }
+ }
+ if (model->getHeader (index.column ()).contains ("timestamp"))
+ {
+ QApplication::style ()->drawItemText(painter,
+ option.rect,
+ Qt::AlignVCenter,
+ opts.palette,
+ true,
+ modifyDate (temp),
+ QPalette::HighlightedText);
+ return;
+ }
+ }
+ QStyledItemDelegate::paint (painter, option, index);
+}
+
+
+/**
+ * @brief Date modification
+ *
+ * Reads the date from the given string and returns month, day and year in a
+ * new string
+ *
+ * @param date ompdate as string.
+ **/
+QString
+delegate_date_time::modifyDate (QString date) const
+{
+ if (date.length()>0)
+ {
+ QStringList cleaned = date.split (" ");
+ 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();
+
+ QDateTime d = QDateTime::fromString (cleaned.join("."),
+ "ddd.MMM.d.hh:mm:ss.yyyy");
+ QString day;
+ if (d.date ().day () <= 9)
+ day = tr (" %1").arg (d.date ().day ());
+ else
+ day = tr ("%1").arg (d.date ().day ());
+ return tr ("%1 %2 %3").arg
+ (d.date ().shortMonthName (d.date ().month ()))
+ .arg(day)
+ .arg(d.date().year());
+ }
+ else
+ {
+ return "";
+ }
+}
+
Added: trunk/gsa-desktop/src/delegate_date_time.h
===================================================================
--- trunk/gsa-desktop/src/delegate_date_time.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_date_time.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -0,0 +1,60 @@
+/**
+ * Copyright:
+ * Copyright (C) 2010 by Greenbone Networks GmbH
+ *
+ * Authors:
+ * Raimund Renkert <raimund.renkert at intevation.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+/**
+ * @file delegate_icon.h
+ * @brief Protos and data structures for delegate_icon.
+ */
+
+#ifndef DELEGATE_DATE_TIME_H
+#define DELEGATE_DATE_TIME_H
+
+#include <QtGui>
+
+#include "model_omp_entity.h"
+
+class delegate_date_time : public QStyledItemDelegate
+{
+ Q_OBJECT
+
+ private:
+ QString modifyDate (QString date) const;
+ public:
+ delegate_date_time ();
+ ~delegate_date_time ();
+
+ /**
+ * @brief new implemented sizeHint (..), returning the size of the delegate
+ */
+ QSize sizeHint (const QStyleOptionViewItem&, const QModelIndex&) const
+ {
+ return QSize (16,16);
+ }
+
+ void paint (QPainter* painter, const QStyleOptionViewItem& option,
+ const QModelIndex& index) const;
+
+ void setFormat (QString);
+};
+#endif
+
Modified: trunk/gsa-desktop/src/delegate_icon.cpp
===================================================================
--- trunk/gsa-desktop/src/delegate_icon.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_icon.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -55,7 +55,7 @@
{
if ( index.column () == 1 )
{
- model_task * model = (model_task*) index.model ();
+ model_omp_entity * model = (model_omp_entity*) index.model ();
if (model == 0)
{
@@ -64,9 +64,9 @@
}
QStyleOptionButton opts;
- omp_entity_status * pItem = model->getTask (index.row ());
+ QDomElement pItem = model->getEntity (index.row ());
- if (pItem != NULL)
+ if (!pItem.isNull ())
{
if (option.state & QStyle::State_Selected)
{
@@ -87,7 +87,7 @@
opts.iconSize = QSize (16, 16);
opts.state = QStyle::State_Enabled;
- if (pItem->getScheduleId () != "")
+ if (model->getAttr (pItem, "task schedule id") != "")
{
opts.icon.addPixmap
(QPixmap (QString::fromUtf8 (":/img/scheduled.png")),
@@ -103,4 +103,5 @@
}
}
QStyledItemDelegate::paint (painter, option, index);
-}
\ No newline at end of file
+}
+
Modified: trunk/gsa-desktop/src/delegate_icon.h
===================================================================
--- trunk/gsa-desktop/src/delegate_icon.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_icon.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -31,8 +31,7 @@
#include <QtGui>
-#include "omp_entity_status.h"
-#include "model_task.h"
+#include "model_omp_entity.h"
class delegate_icon : public QStyledItemDelegate
{
@@ -54,3 +53,4 @@
const QModelIndex& index) const;
};
#endif
+
Modified: trunk/gsa-desktop/src/delegate_progress.cpp
===================================================================
--- trunk/gsa-desktop/src/delegate_progress.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_progress.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -56,7 +56,7 @@
{
if (index.column () == 2)
{
- model_task * model = (model_task*) index.model ();
+ model_omp_entity * model = (model_omp_entity*) index.model ();
if (model == 0)
{
@@ -65,9 +65,9 @@
}
QStyleOptionProgressBarV2 opts;
- omp_entity_status * pItem = model->getTask (index.row ());
+ QDomElement pItem = model->getEntity (index.row ());
- if (pItem != NULL)
+ if (!pItem.isNull ())
{
if (option.state & QStyle::State_Selected)
{
@@ -91,93 +91,64 @@
opts.maximum = 100;
opts.minimum = 0;
opts.palette.setColor (QPalette::HighlightedText, QColor (0,0,0));
-
- switch (pItem->getStatus ())
+ QString tmp = model->getValue (pItem, "status");
+ if (tmp.compare ("New") == 0 )
{
- case omp_entity_status::TASK_NEW:
- {
- opts.text = QString ("New");
- opts.progress = 100;
- opts.palette.setColor (QPalette::Highlight,
- QColor (155,207,113));
- QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
- &opts, painter);
- return;
- }
- case omp_entity_status::TASK_DELREQUESTED:
- {
- opts.text = QString ("Delete Requested");
- opts.progress = 100;
- opts.palette.setColor (QPalette::Highlight,
- QColor (239,187,37));
- QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
- &opts, painter);
- return;
- }
- case omp_entity_status::TASK_ERROR:
- {
- opts.text = QString ("Internal Error");
- opts.progress = 100;
- opts.palette.setColor (QPalette::Highlight,
- QColor (255,81,67));
- QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
- &opts, painter);
- return;
- }
- case omp_entity_status::TASK_STOPREQUESTED:
- {
- opts.text = QString ("Stop Requested");
- opts.progress = 100;
- opts.palette.setColor (QPalette::Highlight,
- QColor (239,187,37));
- QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
- &opts, painter);
- return;
- }
- case omp_entity_status::TASK_DONE:
- {
- opts.text = QString ("Done");
- opts.progress = 100;
- opts.palette.setColor (QPalette::Highlight,
- QColor (89,169,205));
- QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
- &opts, painter);
- return;
- }
- case omp_entity_status::TASK_REQUESTED:
- {
- opts.text = QString ("Requested");
- opts.progress = 100;
- opts.palette.setColor (QPalette::Highlight,
- QColor (239,187,37));
- QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
- &opts, painter);
- return;
- }
- case omp_entity_status::TASK_STOPPED:
- {
- opts.text = QString ("Stopped");
- opts.progress = 100;
- opts.palette.setColor (QPalette::Highlight,
- QColor (239,187,37));
- QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
- &opts, painter);
- return;
- }
- case omp_entity_status::TASK_ACTIVE:
- {
- opts.text = QString ("%1%").arg (pItem->getProgress ());;
- opts.progress = pItem->getProgress ();
- opts.palette.setColor (QPalette::Highlight,
- QColor (21,209,58));
- QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
- &opts, painter);
- return;
- }
- default:
- break;
+ opts.text = QString ("New");
+ opts.progress = 100;
+ opts.palette.setColor (QPalette::Highlight,
+ QColor (155,207,113));
+ QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
+ &opts, painter);
+ return;
}
+ else if (tmp.compare ("Delete Requested") == 0 ||
+ tmp.compare ("Stop Requested") == 0 ||
+ tmp.compare ("Requested") == 0 ||
+ tmp.compare ("Stopped") == 0)
+ {
+ opts.text = QString (tmp);
+ opts.progress = 100;
+ opts.palette.setColor (QPalette::Highlight,
+ QColor (239,187,37));
+ QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
+ &opts, painter);
+ return;
+ }
+ else if (tmp.compare ("Internal Error") == 0)
+ {
+ opts.text = QString (tmp);
+ opts.progress = 100;
+ opts.palette.setColor (QPalette::Highlight,
+ QColor (255,81,67));
+ QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
+ &opts, painter);
+ return;
+ }
+ else if (tmp.compare ("Done") == 0)
+ {
+ opts.text = QString ("Done");
+ opts.progress = 100;
+ opts.palette.setColor (QPalette::Highlight,
+ QColor (89,169,205));
+ QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
+ &opts, painter);
+ return;
+ }
+ else if (tmp.compare ("Running") == 0)
+ {
+ QString s = model->getValue (pItem, "progress");
+ opts.text = QString ("%1%").arg (s);
+ bool *ok = false;
+ opts.progress = s.toInt (ok, 10);
+ opts.palette.setColor (QPalette::Highlight,
+ QColor (21,209,58));
+ QApplication::style ()->drawControl (QStyle::CE_ProgressBar,
+ &opts, painter);
+ return;
+ }
}
}
QStyledItemDelegate::paint (painter, option, index);
-}
\ No newline at end of file
+}
+
Modified: trunk/gsa-desktop/src/delegate_progress.h
===================================================================
--- trunk/gsa-desktop/src/delegate_progress.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_progress.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -31,8 +31,7 @@
#include <QtGui>
-#include "omp_entity_status.h"
-#include "model_task.h"
+#include "model_omp_entity.h"
class delegate_progress : public QStyledItemDelegate
{
@@ -53,4 +52,5 @@
void paint (QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const;
};
-#endif
\ No newline at end of file
+#endif
+
Modified: trunk/gsa-desktop/src/delegate_threat.cpp
===================================================================
--- trunk/gsa-desktop/src/delegate_threat.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_threat.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -56,7 +56,7 @@
{
if (index.column() == 6)
{
- model_task * model = (model_task*) index.model ();
+ model_omp_entity * model = (model_omp_entity*) index.model ();
if (model == 0)
{
@@ -65,9 +65,9 @@
}
QStyleOptionButton opts;
- omp_entity_status * pItem = model->getTask (index.row ());
+ QDomElement pItem = model->getEntity (index.row ());
- if (pItem != NULL)
+ if (!pItem.isNull ())
{
if (option.state & QStyle::State_Selected)
{
@@ -88,9 +88,17 @@
opts.iconSize = QSize (58, 16);
opts.state = QStyle::State_Enabled;
- switch (pItem->getThreat ())
+ bool *ok = false;
+ QString s = model->getValue (pItem, "messages hole");
+ int t_hole = s.toInt (ok, 10);
+ s = model->getValue (pItem, "messages warning");
+ int t_warn = s.toInt (ok, 10);
+ s = model->getValue (pItem, "messages low");
+ int t_low = s.toInt (ok, 10);
+ int threat = delegate_threat::calcThreat (t_hole, t_warn, t_low);
+ switch (threat)
{
- case omp_entity_status::THREAT_HIGH:
+ case 0:
{
opts.icon.addPixmap
(QPixmap (QString::fromUtf8 (":/img/high_big.png")),
@@ -99,7 +107,7 @@
(QStyle::CE_PushButtonLabel, &opts, painter);
return;
}
- case omp_entity_status::THREAT_MEDIUM:
+ case 1:
{
opts.icon.addPixmap
(QPixmap (QString::fromUtf8 (":/img/medium_big.png")),
@@ -108,7 +116,7 @@
(QStyle::CE_PushButtonLabel, &opts, painter);
return;
}
- case omp_entity_status::THREAT_LOW:
+ case 2:
{
opts.icon.addPixmap
(QPixmap (QString::fromUtf8 (":/img/low_big.png")),
@@ -117,7 +125,7 @@
(QStyle::CE_PushButtonLabel, &opts, painter);
return;
}
- case omp_entity_status::THREAT_NONE:
+ case -1:
{
opts.icon.addPixmap
(QPixmap (QString::fromUtf8 (":/img/none_big.png")),
@@ -132,4 +140,35 @@
}
}
QStyledItemDelegate::paint (painter, option, index);
-}
\ No newline at end of file
+}
+
+/**
+ * @brief Threatcalculation
+ *
+ * Calculates the enumeration for the threat
+ *
+ * @param hole: number of holes for a task
+ * @param warning: number of warnings for a task
+ * @param info: number of infos for a task
+ */
+int
+delegate_threat::calcThreat (int hole, int warning, int info)
+{
+ if (hole > 0)
+ {
+ return 0;
+ }
+ else if (warning > 0)
+ {
+ return 1;
+ }
+ else if (info > 0)
+ {
+ return 2;
+ }
+ else
+ {
+ return -1;
+ }
+}
+
Modified: trunk/gsa-desktop/src/delegate_threat.h
===================================================================
--- trunk/gsa-desktop/src/delegate_threat.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_threat.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -31,13 +31,16 @@
#include <QtGui>
-#include "omp_entity_status.h"
-#include "model_task.h"
+#include "model_omp_entity.h"
class delegate_threat : public QStyledItemDelegate
{
Q_OBJECT
+ private:
+ static int calcThreat (int hole, int warning, int info);
+
+
public:
delegate_threat ();
~delegate_threat ();
@@ -53,4 +56,5 @@
void paint (QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const;
};
-#endif
\ No newline at end of file
+#endif
+
Modified: trunk/gsa-desktop/src/delegate_trend.cpp
===================================================================
--- trunk/gsa-desktop/src/delegate_trend.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_trend.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -56,7 +56,7 @@
{
if ( index.column () == 7 )
{
- model_task * model = (model_task*) index.model ();
+ model_omp_entity * model = (model_omp_entity*) index.model ();
if (model == 0)
{
@@ -65,9 +65,9 @@
}
QStyleOptionButton opts;
- omp_entity_status * pItem = model->getTask (index.row ());
+ QDomElement pItem = model->getEntity (index.row ());
- if (pItem != NULL)
+ if (!pItem.isNull ())
{
if (option.state & QStyle::State_Selected)
{
@@ -88,63 +88,58 @@
opts.iconSize = QSize (16, 16);
opts.state = QStyle::State_Enabled;
- switch (pItem->getTrend ())
+ QString s = model->getValue (pItem, "trend");
+ if (s. compare ("up") == 0)
{
- case omp_entity_status::TREND_LVLINCREASED:
- {
- opts.icon.addPixmap
- (QPixmap (QString::fromUtf8 (":/img/trend_up.png")),
- QIcon::Normal, QIcon::On);
- QApplication::style ()->drawControl
- (QStyle::CE_PushButtonLabel, &opts, painter);
- return;
- }
- case omp_entity_status::TREND_NBRINCREASED:
- {
- opts.icon.addPixmap
- (QPixmap (QString::fromUtf8 (":/img/trend_more.png")),
- QIcon::Normal, QIcon::On);
- QApplication::style ()->drawControl
- (QStyle::CE_PushButtonLabel, &opts, painter);
-
- return;
- }
- case omp_entity_status::TREND_NOCHANGE:
- {
- opts.icon.addPixmap
- (QPixmap (QString::fromUtf8 (":/img/trend_nochange.png")),
- QIcon::Normal, QIcon::On);
- QApplication::style ()->drawControl
- (QStyle::CE_PushButtonLabel, &opts, painter);
-
- return;
- }
- case omp_entity_status::TREND_NBRDECREASED:
- {
- opts.icon.addPixmap
- (QPixmap (QString::fromUtf8 (":/img/trend_less.png")),
- QIcon::Normal, QIcon::On);
- QApplication::style ()->drawControl
- (QStyle::CE_PushButtonLabel, &opts, painter);
- return;
- }
- case omp_entity_status::TREND_LVLDECREASED:
- {
- opts.icon.addPixmap
- (QPixmap (QString::fromUtf8 (":/img/trend_down.png")),
- QIcon::Active, QIcon::On);
- QApplication::style ()->drawControl
- (QStyle::CE_PushButtonLabel, &opts, painter);
- return;
- }
- case omp_entity_status::TREND_NONE:
- {
- return;
- }
- default:
- break;
+ opts.icon.addPixmap
+ (QPixmap (QString::fromUtf8 (":/img/trend_up.png")),
+ QIcon::Normal, QIcon::On);
+ QApplication::style ()->drawControl
+ (QStyle::CE_PushButtonLabel, &opts, painter);
+ return;
}
+ else if (s.compare ("more") == 0)
+ {
+ opts.icon.addPixmap
+ (QPixmap (QString::fromUtf8 (":/img/trend_more.png")),
+ QIcon::Normal, QIcon::On);
+ QApplication::style ()->drawControl
+ (QStyle::CE_PushButtonLabel, &opts, painter);
+ return;
+ }
+ else if (s.compare ("same") == 0)
+ {
+ opts.icon.addPixmap
+ (QPixmap (QString::fromUtf8 (":/img/trend_nochange.png")),
+ QIcon::Normal, QIcon::On);
+ QApplication::style ()->drawControl
+ (QStyle::CE_PushButtonLabel, &opts, painter);
+ return;
+ }
+ else if (s.compare ("less") == 0)
+ {
+ opts.icon.addPixmap
+ (QPixmap (QString::fromUtf8 (":/img/trend_less.png")),
+ QIcon::Normal, QIcon::On);
+ QApplication::style ()->drawControl
+ (QStyle::CE_PushButtonLabel, &opts, painter);
+ return;
+ }
+ else if (s.compare ("down") == 0)
+ {
+ opts.icon.addPixmap
+ (QPixmap (QString::fromUtf8 (":/img/trend_down.png")),
+ QIcon::Active, QIcon::On);
+ QApplication::style ()->drawControl
+ (QStyle::CE_PushButtonLabel, &opts, painter);
+ return;
+ }
+ else
+ {
+ return;
+ }
}
}
QStyledItemDelegate::paint (painter, option, index);
-}
\ No newline at end of file
+}
+
Modified: trunk/gsa-desktop/src/delegate_trend.h
===================================================================
--- trunk/gsa-desktop/src/delegate_trend.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/delegate_trend.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -31,8 +31,7 @@
#include <QtGui>
-#include "omp_entity_status.h"
-#include "model_task.h"
+#include "model_omp_entity.h"
class delegate_trend : public QStyledItemDelegate
{
@@ -53,4 +52,5 @@
void paint (QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const;
};
-#endif
\ No newline at end of file
+#endif
+
Modified: trunk/gsa-desktop/src/dock_table.cpp
===================================================================
--- trunk/gsa-desktop/src/dock_table.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/dock_table.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -75,4 +75,4 @@
dock_table::getTable ()
{
return tw_table;
-}
\ No newline at end of file
+}
Modified: trunk/gsa-desktop/src/dock_table.h
===================================================================
--- trunk/gsa-desktop/src/dock_table.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/dock_table.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -31,7 +31,7 @@
#include <QtGui>
#include "ui_dock_table.h"
-#include "model_schedule.h"
+//#include "model_schedule.h"
class dock_table : public QDockWidget, private Ui::dock_table
{
Modified: trunk/gsa-desktop/src/gsa_desktop_control.cpp
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_control.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/gsa_desktop_control.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -29,9 +29,9 @@
* and its omp functionality. It contains the omp-controller, the
* configuration and the main view * components
*/
+
#include "gsa_desktop_control.h"
-
/**
* @brief Creates a new GSA-Desktop controller
*
@@ -62,8 +62,7 @@
SLOT (request_statustoggle (int)));
connect (mainwin, SIGNAL (sig_req_status (int)), this,
SLOT (request_status (int)));
- connect (mainwin, SIGNAL (sig_req_schedule ()), this,
- SLOT (request_schedules ()));
+ connect (mainwin, SIGNAL (sig_req_schedules ()), this, SLOT (request_schedules ()));
connect (mainwin, SIGNAL (sig_login_dlg ()), this, SLOT (login ()));
connect (mainwin, SIGNAL (sig_logout ()), this, SLOT (logout ()));
connect (mainwin, SIGNAL (sig_update_profile (QString)), this,
@@ -245,27 +244,6 @@
/**
- * @brief SLOT that starts a schedule update-request
- *
- * A schedule update is requested
- *
- */
-void gsa_desktop_control::request_schedules ()
- {
- if(this->connector == NULL)
- {
- // if no connector is set, set an error-information
- QMessageBox::information (NULL, tr ("Login Error"),
- tr ("Please login first!"));
- }
- else
- {
- this->connector->getSchedules(mainwin->getScheduleModel());
- }
- }
-
-
-/**
* @brief SLOT that starts a statusupdate-request
*
* A status update for the task widget is requested, 0 as parameter starts a
@@ -299,6 +277,26 @@
/**
+ * @brief SLOT that starts a schedulesupdate-request
+ *
+ * An update for the schedules widget is requested
+ */
+void
+gsa_desktop_control::request_schedules ()
+{
+ if (this->connector == NULL)
+ {
+ // if no connector is set, set an error-information
+ QMessageBox::information (NULL, tr ("Login Error"),
+ tr ("Please login first!"));
+ }
+ else
+ {
+ this->connector->getSchedules (mainwin->getScheduleModel ());
+ }
+}
+
+/**
* @brief SLOT that stops frequently running updates
*
* The status update for the task widget is stopped.
Modified: trunk/gsa-desktop/src/gsa_desktop_control.h
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_control.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/gsa_desktop_control.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -57,8 +57,8 @@
void profile_remove (QString name);
void request_status (int);
+ void request_schedules ();
void request_statustoggle (int);
- void request_schedules ();
void taskupdate_failed (int);
void taskupdate_stop ();
Modified: trunk/gsa-desktop/src/gsa_desktop_mainwindow.ui
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_mainwindow.ui 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/gsa_desktop_mainwindow.ui 2010-06-09 16:24:05 UTC (rev 7986)
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>810</width>
- <height>590</height>
+ <width>800</width>
+ <height>600</height>
</rect>
</property>
<property name="sizePolicy" >
@@ -41,8 +41,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>810</width>
- <height>25</height>
+ <width>800</width>
+ <height>26</height>
</rect>
</property>
<widget class="QMenu" name="menuFile" >
@@ -160,7 +160,7 @@
<string>View</string>
</property>
<addaction name="actionLogging" />
- <addaction name="actionSchedule" />
+ <addaction name="actionSchedules" />
</widget>
<addaction name="menuFile" />
<addaction name="menuTask" />
@@ -547,16 +547,11 @@
<string>Logging</string>
</property>
</action>
- <action name="actionSchedule" >
+ <action name="actionSchedules" >
<property name="text" >
<string>Schedules</string>
</property>
</action>
- <action name="actionTargets" >
- <property name="text" >
- <string>Targets</string>
- </property>
- </action>
</widget>
<resources>
<include location="img/images.qrc" />
Modified: trunk/gsa-desktop/src/gsa_desktop_ui.cpp
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_ui.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/gsa_desktop_ui.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -47,26 +47,40 @@
logging->hide ();
logLvl = 0;
- schedule = new dock_table ();
+ schedules = new dock_table ();
+ this->addDockWidget (Qt::BottomDockWidgetArea, schedules);
//Dialogs
login = new dlg_login ();
about = new dlg_about ();
//Models
- taskModel = new model_task ();
- scheduleModel = new model_schedule ();
+ taskModel = new model_omp_entity ();
+ taskModel->addHeader ("Name", "name");
+ taskModel->addHeader ("", "schedule");
+ taskModel->addHeader ("Status", "status");
+ taskModel->addHeader ("Reports", "report_count finished");
+ taskModel->addHeader ("First", "first_report report timestamp");
+ taskModel->addHeader ("Last", "last_report report timestamp");
+ taskModel->addHeader ("Threat", "messages");
+ taskModel->addHeader ("Trend", "trend");
- schedule->setModel (scheduleModel);
+ scheduleModel = new model_omp_entity ();
+ scheduleModel->addHeader ("Name","name");
+ scheduleModel->addHeader ("First Run", "first_time");
+ scheduleModel->addHeader ("Next Run", "next_time");
+ scheduleModel->addHeader ("Period", "period");
+ scheduleModel->addHeader ("Duration", "duration");
//Delegates
taskProgress = new delegate_progress ();
trendIcon = new delegate_trend ();
threatIcon = new delegate_threat ();
icon = new delegate_icon ();
-
+ date_time = new delegate_date_time ();
//Timer
progressUpdateTimer = new QTimer();
+ intervalTimer = new QTimer ();
//create and modify UI
createUpdateWidget ();
@@ -75,6 +89,7 @@
createConnections();
modifyWidgets();
+ updateInterval = 0;
}
@@ -267,7 +282,6 @@
updateLayout->addWidget (tb_set_refresh, 1,0,1,2);
updateLayout->addWidget (la_prog_update, 3,0,1,2);
updateLayout->addWidget (tb_stop_refresh, 1,2,1,2);
-
updateLayout->setRowMinimumHeight (0, 25);
updateLayout->setRowMinimumHeight (1, 25);
updateLayout->setRowMinimumHeight (3, 25);
@@ -307,6 +321,7 @@
SLOT (profile_remove (QString)));
connect (progressUpdateTimer, SIGNAL (timeout()), this,
SLOT (progress_timeout ()));
+ connect (intervalTimer, SIGNAL (timeout ()), this, SLOT (refresh_once ()));
connect (actionRun, SIGNAL (triggered (bool)), this, SLOT (task_start ()));
connect (actionStop, SIGNAL (triggered (bool)), this, SLOT (task_stop ()));
connect (actionDelete, SIGNAL (triggered (bool)), this,
@@ -321,12 +336,8 @@
connect (actionLogging, SIGNAL (triggered (bool)), this, SLOT (log_dw ()));
connect (logging, SIGNAL (sig_log_lvl (double)), this,
SLOT (log_level_changed (double)));
- connect (actionSchedule, SIGNAL (triggered (bool)), this,
- SLOT (schedule_dw ()));
- connect (dw_tasks, SIGNAL (visibilityChanged (bool)), this,
- SLOT (focus_task (bool)));
- connect (schedule, SIGNAL (visibilityChanged (bool)), this,
- SLOT (focus_schedule (bool)));
+ connect (actionSchedules, SIGNAL (triggered (bool)), this,
+ SLOT (schedule_dw()));
}
@@ -339,14 +350,15 @@
void
gsa_desktop_ui::modifyWidgets ()
{
- //Dockwidgets
- schedule->setWindowTitle ("Schedules");
- QMainWindow::tabifyDockWidget (dw_tasks, schedule);
+ schedules->setWindowTitle ("Schedules");
+ QMainWindow::tabifyDockWidget (dw_tasks, schedules);
+ schedules->setModel (scheduleModel);
dw_tasks->raise ();
- //Tableview schedules
- QTableView *tw_schedules = schedule->getTable ();
+ QTableView *tw_schedules = schedules->getTable ();
+ tw_schedules->setItemDelegateForColumn (4, date_time);
+ tw_schedules->setItemDelegateForColumn (3, date_time);
tw_schedules->horizontalHeader ()->setResizeMode (QHeaderView::Fixed);
tw_schedules->horizontalHeader ()->setResizeMode (0, QHeaderView::Stretch);
tw_schedules->setColumnWidth (0, 120);
@@ -354,12 +366,17 @@
tw_schedules->setColumnWidth (2, 150);
tw_schedules->setColumnWidth (3, 80);
tw_schedules->setColumnWidth (4, 80);
+ tw_schedules->verticalHeader ()->setVisible (false);
+ tw_schedules->horizontalHeader ()->setHighlightSections (false);
tw_schedules->horizontalHeader ()->setMinimumSectionSize (75);
- //Tableview tasks
+
+ //Tableview
tw_tasks->setModel (taskModel);
tw_tasks->setItemDelegateForColumn (1, icon);
tw_tasks->setItemDelegateForColumn (2, taskProgress);
+ tw_tasks->setItemDelegateForColumn (4, date_time);
+ tw_tasks->setItemDelegateForColumn (5, date_time);
tw_tasks->setItemDelegateForColumn (6, threatIcon);
tw_tasks->setItemDelegateForColumn (7, trendIcon);
tw_tasks->verticalHeader ()->setVisible (false);
@@ -370,8 +387,8 @@
tw_tasks->setColumnWidth (1, 22);
tw_tasks->setColumnWidth (2, 120);
tw_tasks->setColumnWidth (3, 60);
- tw_tasks->setColumnWidth (4, 160);
- tw_tasks->setColumnWidth (5, 160);
+ tw_tasks->setColumnWidth (4, 150);
+ tw_tasks->setColumnWidth (5, 150);
tw_tasks->setColumnWidth (6, 66);
tw_tasks->setColumnWidth (7, 60);
@@ -386,6 +403,7 @@
this, SLOT (task_contextmenu (const QPoint &)));
}
+
/**
* @brief SLOT to get the logindata from the logindialog
*
@@ -444,8 +462,8 @@
void
gsa_desktop_ui::logout ()
{
- taskModel->removeTasks ();
-
+ taskModel->removeEntities ();
+ scheduleModel->removeEntities ();
refresh_manualstop();
statusbar->removeWidget(statuslabel);
emit sig_stop_taskupdate();
@@ -496,7 +514,9 @@
(updateInterval));
tb_stop_refresh->setDisabled (false);
- emit sig_req_status (updateInterval);
+ emit sig_req_status (0);
+ intervalTimer->start (updateInterval*1000);
+ progressUpdateTimer->start (1000);
}
}
@@ -534,6 +554,8 @@
gsa_desktop_ui::refresh_stop ()
{
progressUpdateTimer->stop ();
+ intervalTimer->stop ();
+ updateInterval = 0;
pbar_update->setValue (0);
}
@@ -552,6 +574,8 @@
pbar_update->setFormat (QApplication::translate ("MainWindow", "manual",
0, QApplication::UnicodeUTF8));
sb_update->setValue(0);
+ progressUpdateTimer->stop ();
+ intervalTimer->stop ();
tb_stop_refresh->setDisabled (true);
emit sig_stop_taskupdate ();
}
@@ -562,7 +586,7 @@
*
* @return The model containing the tasks
*/
-model_task*
+model_omp_entity*
gsa_desktop_ui::getTableModel ()
{
return taskModel;
@@ -574,7 +598,7 @@
*
* @return The model containing the schedules
*/
-model_schedule*
+model_omp_entity*
gsa_desktop_ui::getScheduleModel ()
{
return scheduleModel;
@@ -694,6 +718,10 @@
int p = pbar_update->value ();
pbar_update->setValue ( ++p );
int format_value = pbar_update->maximum () - p;
+ if (format_value <= 0)
+ {
+ format_value = 0;
+ }
QString form;
form.setNum (format_value);
form.append (tr (" sec"));
@@ -713,7 +741,6 @@
form.setNum (updateInterval);
form.append (tr (" sec"));
pbar_update->setFormat (form);
- progressUpdateTimer->start (1000);
}
@@ -746,7 +773,6 @@
QWidget *viewport = tw_tasks->viewport ();
viewport->update ();
-
//get index of selected task, if no task selected set first as selected
int ndx;
QModelIndexList selected = tw_tasks->selectionModel ()->selectedRows (0);
@@ -770,10 +796,16 @@
start = taskModel->index (ndx, 0, QModelIndex ());
end = taskModel->index (ndx, 7, QModelIndex ());
QItemSelection sel (start, end);
-
//set selection
tw_tasks->selectionModel ()->select (sel, QItemSelectionModel::Select);
task_selectionchanged (QModelIndex (), QModelIndex ());
+ if (updateInterval > 0)
+ {
+ progressUpdateTimer->stop ();
+ progressUpdateTimer->start (1000);
+ intervalTimer->stop ();
+ intervalTimer->start (updateInterval*1000);
+ }
}
@@ -787,52 +819,51 @@
gsa_desktop_ui::task_selectionchanged (const QModelIndex &newindex,
const QModelIndex &oldindex)
{
- if (tw_tasks->hasFocus())
+ int row = -1;
+ QModelIndexList selected = tw_tasks->selectionModel ()->selectedRows (0);
+ if (newindex.row () >= 0 )
{
- QModelIndexList selected = tw_tasks->selectionModel ()->selectedRows (0);
- int row = -1;
- if (newindex.row () >= 0 )
- {
- row = newindex.row ();
- }
- else if (newindex.row () < 0 && selected.at (0).row () > 0)
- {
- row = selected.at (0).row ();
- }
- else
- {
- row = 0;
- }
+ row = newindex.row ();
+ }
+ else if (newindex.row () < 0 && selected.at (0).row () > 0)
+ {
+ row = selected.at (0).row ();
+ }
+ else
+ {
+ row = 0;
+ }
+ QDomNode ent = taskModel->getEntity (row);
+ if (ent.isNull ())
+ {
+ return;
+ }
+ QString stat = taskModel->getValue (ent.toElement (), "status");
+ if (stat.compare ("New") == 0 ||
+ stat.compare ("Done") == 0 ||
+ stat.compare ("Stopped") == 0)
+ {
+ actionRun->setEnabled (true);
+ actionStop->setEnabled (false);
+ }
- omp_entity_status *ent = new omp_entity_status ();
- ent = taskModel->getTask (row);
+ if (stat.compare ("Delete Requested") == 0 ||
+ stat.compare ("Error") == 0 ||
+ stat.compare ("Stop Requested") == 0||
+ stat.compare ("Requested") == 0 ||
+ taskModel->getAttr (ent.toElement (), "task schedule id") != "")
+ {
+ actionRun->setEnabled (false);
+ actionStop->setEnabled (false);
+ }
- if (ent->getStatus () == omp_entity_status::TASK_NEW ||
- ent->getStatus () == omp_entity_status::TASK_DONE ||
- ent->getStatus () == omp_entity_status::TASK_STOPPED)
- {
- actionRun->setEnabled (true);
- actionStop->setEnabled (false);
- }
-
- if (ent->getStatus () == omp_entity_status::TASK_DELREQUESTED ||
- ent->getStatus () == omp_entity_status::TASK_ERROR ||
- ent->getStatus () == omp_entity_status::TASK_STOPREQUESTED ||
- ent->getStatus () == omp_entity_status::TASK_REQUESTED ||
- ent->getScheduleId () != "")
- {
- actionRun->setEnabled (false);
- actionStop->setEnabled (false);
- }
-
- if (ent->getStatus () == omp_entity_status::TASK_ACTIVE)
- {
- actionRun->setEnabled (false);
- actionStop->setEnabled (true);
- }
-
- actionDelete->setEnabled (true);
+ if (stat.compare ("Running") == 0)
+ {
+ actionRun->setEnabled (false);
+ actionStop->setEnabled (true);
}
+
+ actionDelete->setEnabled (true);
}
/**
@@ -841,16 +872,17 @@
void
gsa_desktop_ui::task_start ()
{
- omp_entity_status *ent = new omp_entity_status ();
+ QDomNode ent;
QModelIndexList selected = tw_tasks->selectionModel ()->selectedRows (0);
if (selected.size() != 0)
{
- ent = taskModel->getTask(selected.at(0).row());
- if (ent->getStatus () == omp_entity_status::TASK_NEW ||
- ent->getStatus () == omp_entity_status::TASK_DONE ||
- ent->getStatus () == omp_entity_status::TASK_STOPPED)
+ ent = taskModel->getEntity (selected.at(0).row());
+ QString stat = taskModel->getValue (ent.toElement (), "status");
+ if (stat.compare ("New") == 0 ||
+ stat.compare ("Done") == 0 ||
+ stat.compare ("Stopped") == 0)
{
- emit sig_start_task (ent->getId ());
+ emit sig_start_task (taskModel->getAttr (ent.toElement (), "task id"));
emit sig_req_status (0);
if (sb_update->value () > 0)
{
@@ -873,14 +905,15 @@
void
gsa_desktop_ui::task_stop ()
{
- omp_entity_status *ent = new omp_entity_status ();
+ QDomNode ent;
QModelIndexList selected = tw_tasks->selectionModel ()->selectedRows (0);
if (selected.size() != 0)
{
- ent = taskModel->getTask (selected.at (0).row ());
- if (ent->getStatus () == omp_entity_status::TASK_ACTIVE)
+ ent = taskModel->getEntity (selected.at (0).row ());
+ QString stat = taskModel->getValue (ent.toElement (), "status");
+ if (stat.compare ("Running") == 0)
{
- emit sig_stop_task (ent->getId ());
+ emit sig_stop_task (taskModel->getAttr (ent.toElement (), "task id"));
emit sig_req_status (0);
if (sb_update->value () > 0)
{
@@ -905,30 +938,31 @@
void
gsa_desktop_ui::task_delete ()
{
- omp_entity_status *ent = new omp_entity_status ();
+ QDomNode ent;
QModelIndexList selected = tw_tasks->selectionModel ()->selectedRows (0);
if (selected.size() != 0)
{
- ent = taskModel->getTask (selected.at (0).row ());
+ ent = taskModel->getEntity (selected.at (0).row ());
int ret = QMessageBox::warning (this, tr ("Delete?"),
QString (tr ("Do you really want delete"
" the Task :<b>%1</b>"))
- .arg (ent->getName ()),
+ .arg (taskModel->getValue
+ (ent.toElement (), "name")),
QMessageBox::Yes, QMessageBox::No);
switch (ret)
{
- case QMessageBox::Yes:
+ case QMessageBox::Yes:
{
- taskModel->removeTask (ent->getId ());
- emit sig_delete_task (ent->getId ());
+ taskModel->removeEntity (selected.at (0).row ());
+ emit sig_delete_task (taskModel->getAttr (ent.toElement (), "task id"));
emit sig_req_status (0);
return;
}
- case QMessageBox::No:
+ case QMessageBox::No:
{
return;
}
- default:
+ default:
{
return;
}
@@ -959,7 +993,8 @@
QPoint p (position.x (), position.y () + 22);
QAction *name = new QAction (this);
QString n (tr ("Task: "));
- n.append (taskModel->getTask(selected.at (0).row ())->getName ());
+ QDomNode node = taskModel->getEntity (selected. at (0).row ());
+ n.append (taskModel->getValue (node.toElement (), "name"));
QFont f = name->font ();
f.setBold (true);
name->setFont (f);
@@ -1011,51 +1046,12 @@
/**
- * @brief SLOT called when task dockwidget visiblility changed.
+ * @brief SLOT to show schedules widget
*
- * Disables run, stop and delete buttons if focus == false, calls
- * task_selectionchanged if focus == true.
- *
- * @param focus: visible or not.
*/
void
-gsa_desktop_ui::focus_task (bool focus)
-{
- if (focus == false)
- {
- actionRun->setEnabled (false);
- actionStop->setEnabled (false);
- actionDelete->setEnabled (false);
- }
- else
- {
- tw_tasks->setFocus();
- if (taskModel->rowCount () != 0)
- task_selectionchanged (QModelIndex (), QModelIndex ());
- }
-}
-
-/**
- * @brief SLOT to show schedule widget.
- *
- */
-void
gsa_desktop_ui::schedule_dw ()
{
- schedule->show();
+ schedules->show ();
}
-
-/**
- * @brief SLOT called when schedule dockwidget visiblility changed.
- *
- * @param focus: visible or not.
- */
-void
-gsa_desktop_ui::focus_schedule (bool focus)
-{
- if (focus == true)
- {
- emit sig_req_schedule();
- }
-}
Modified: trunk/gsa-desktop/src/gsa_desktop_ui.h
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_ui.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/gsa_desktop_ui.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -34,11 +34,12 @@
#include "ui_gsa_desktop_mainwindow.h"
#include "dlg_login.h"
#include "omp_credentials.h"
-#include "model_task.h"
+#include "model_omp_entity.h"
#include "delegate_progress.h"
#include "delegate_trend.h"
#include "delegate_threat.h"
#include "delegate_icon.h"
+#include "delegate_date_time.h"
#include "dock_logging.h"
#include "dock_table.h"
#include "dlg_about.h"
@@ -64,14 +65,8 @@
* @param : interval between two updates
*/
void sig_req_status (int);
-
+ void sig_req_schedules ();
/**
- * @brief SIGNAL to request a scheduleupdate
- *
- */
- void sig_req_schedule ();
-
-/**
* @brief SIGNAL to request a statusupdate (with toggle)
*
* @param : interval between two updates
@@ -133,9 +128,8 @@
gsa_desktop_ui ();
~gsa_desktop_ui ();
- model_task *getTableModel ();
- model_schedule *getScheduleModel ();
-
+ model_omp_entity *getTableModel ();
+ model_omp_entity *getScheduleModel ();
void setProfiletoCB (QString name, int position);
void setProfileData (omp_credentials &crd);
@@ -158,8 +152,6 @@
void refresh_manualstop ();
void refresh_dw ();
void log_dw ();
- void schedule_dw ();
-
void log_level_changed (double lvl);
void profile_update (QString name);
@@ -171,6 +163,7 @@
void taskupdate_finished ();
void progress_timeout ();
+ void schedule_dw ();
void task_start ();
void task_stop ();
@@ -178,8 +171,6 @@
void task_contextmenu (const QPoint &);
void task_selectionchanged (const QModelIndex &newindex,
const QModelIndex &oldindex);
- void focus_task (bool);
- void focus_schedule (bool);
private:
QLabel *la_update;
@@ -200,26 +191,28 @@
bool lock;
int logLvl;
- dock_table *schedule;
dock_logging *logging;
+ dock_table *schedules;
dlg_login *login;
dlg_about *about;
omp_credentials *credentials;
QLabel *statuslabel;
- model_task *taskModel;
- model_schedule *scheduleModel;
+ model_omp_entity *taskModel;
+ model_omp_entity *scheduleModel;
delegate_progress *taskProgress;
delegate_trend *trendIcon;
delegate_threat *threatIcon;
delegate_icon *icon;
+ delegate_date_time *date_time;
QTimer *progressUpdateTimer;
-
+ QTimer *intervalTimer;
void createToolBars ();
void createStatusBar ();
void createUpdateWidget ();
void createConnections ();
void modifyWidgets ();
};
-#endif
\ No newline at end of file
+#endif
+
Added: trunk/gsa-desktop/src/model_omp_entity.cpp
===================================================================
--- trunk/gsa-desktop/src/model_omp_entity.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/model_omp_entity.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -0,0 +1,472 @@
+/**
+ * Copyright:
+ * Copyright (C) 2010 by Greenbone Networks GmbH
+ *
+ * Authors:
+ * Raimund Renkert <raimund.renkert at intevation.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "model_omp_entity.h"
+
+/**
+ * @file model_omp_entity.cpp
+ * @brief Model for a Tableview containing the data in an xml format.
+ *
+ * Implements the QAbstractTableModel.
+ * Provides functionality for adding and removing entities from the model.
+ */
+
+model_omp_entity::model_omp_entity ()
+{
+}
+
+
+model_omp_entity::~model_omp_entity ()
+{
+}
+
+
+/**
+ * @brief New implemented flags
+ *
+ * @param index: Index of the item in the model
+ */
+Qt::ItemFlags
+model_omp_entity::flags (const QModelIndex &index) const
+{
+ if (!index.isValid ())
+ return Qt::ItemIsSelectable;
+
+ return QAbstractTableModel::flags (index) | Qt::ItemIsSelectable;
+}
+
+
+/**
+ * @brief new implemented rowCount.
+ *
+ * @param parent index of the parent in the model.
+ *
+ * @return size of the contentlist.
+ */
+int
+model_omp_entity::rowCount (const QModelIndex &parent) const
+{
+ return s_Content.count ();
+}
+
+
+/**
+ * @brief new implemented columnCount.
+ *
+ * @param parent: Index of the parent in the model
+ *
+ * @return Size of header list.
+ */
+int
+model_omp_entity::columnCount (const QModelIndex &parent) const
+{
+ return s_HeaderData.count ();
+}
+
+
+/**
+ * @brief new implemented data ().
+ *
+ * @param index index of the item in the model
+ * @param role itemrole, look at the qt-doc for more information
+ *
+ * @return data of the item selected by index
+ */
+QVariant
+model_omp_entity::data (const QModelIndex &index, int role) const
+{
+ if (!index.isValid ())
+ return QVariant ();
+
+ if (index.row () >= s_Content.size () || index.row () < 0)
+ return QVariant();
+ if (role == Qt::DisplayRole)
+ {
+ int i = 1;
+ QStringList list = s_HeaderOmp.at (index.column ()).split (" ");
+ QDomElement node = s_Content.at (index.row ());
+
+ QDomNode child = node.firstChildElement (list.at (0));
+ while (!child.isNull () && i < list.size ())
+ {
+ child = child.firstChildElement (list.at (i));
+ i++;
+ }
+ QDomElement child_q = child.toElement ();
+ QString temp = child_q.text ();
+ if (temp != NULL)
+ return temp;
+ else
+ return QVariant ();
+ }
+ return QVariant ();
+}
+
+
+/**
+ * @brief new implemented headerdata.
+ *
+ * @param section current position of the header
+ * @param orientation orientation of the header (horizontal/vertical)
+ * @param role headerrole
+ *
+ * @return title of the header columns
+ */
+QVariant
+model_omp_entity::headerData (int section, Qt::Orientation orientation,
+ int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant ();
+
+ if (orientation == Qt::Horizontal)
+ {
+ return s_HeaderData.at (section);
+ }
+ return QVariant ();
+}
+
+
+/**
+ * @brief Add an entity to the model.
+ *
+ * @param entity, containing the data.
+ */
+int
+model_omp_entity::addEntity (QDomElement ent, int pos)
+{
+ mutex.lock ();
+ if (pos >= s_Content.size ())
+ {
+ beginInsertRows (QModelIndex (), s_Content.size (),
+ s_Content.size ());
+ s_Content.insert (pos, ent);
+ endInsertRows ();
+ mutex.unlock ();
+ return 0;
+ }
+ QDomElement temp = s_Content[pos].toElement () ;
+ QDomElement node = ent.toElement ();
+ if (!node.isNull () && !temp.isNull ())
+ {
+ if (node.nodeName ().compare (temp.nodeName ()) == 0)
+ {
+ if (node.text ().compare (temp.text ()) != 0 ||
+ compareAttributes (node, temp) != 0)
+ {
+ s_Content[pos].clear ();
+ s_Content[pos] = node.cloneNode (true).toElement ();
+ mutex.unlock ();
+ return 0;
+ }
+ QDomNodeList list1 = node.childNodes ();
+ QDomNodeList list2 = temp.childNodes ();
+ if (list1.size () != list2.size ())
+ {
+ s_Content[pos].clear ();
+ s_Content[pos] = node.cloneNode (true).toElement ();
+ mutex.unlock ();
+ return 0;
+ }
+ }
+ else
+ {
+ mutex.unlock ();
+ return 0;
+ }
+ }
+ if (!node.isNull () && temp.isNull ())
+ {
+ beginInsertRows (QModelIndex (), s_Content.size (),
+ s_Content.size ());
+ s_Content.insert (pos, ent);
+ endInsertRows ();
+ }
+
+ mutex.unlock ();
+ return 0;
+}
+
+
+/**
+ * @brief Compares XML-Attributes of the given nodes.
+ *
+ * @param node XML node.
+ * @param compare XML node to compare with.
+ *
+ * @return 0 if attributes are equal, else -1.
+ */
+int
+model_omp_entity::compareAttributes (QDomElement node, QDomElement compare)
+{
+ if (!node.isNull () && !compare.isNull ())
+ {
+ if (node.hasAttributes () && compare.hasAttributes ())
+ {
+ QDomNamedNodeMap nodeList = node.attributes ();
+ QDomNamedNodeMap compareList = compare.attributes ();
+ for (int i = 0;i < nodeList.size (); i++)
+ {
+ if (nodeList.item (i).nodeValue ().compare
+ (compareList.item (i).nodeValue ()) != 0)
+ {
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+
+/**
+ * @brief Remove an entity from the model by name and value.
+ *
+ * @param name Name of the entity that should be deleted.
+ * @param value Text of the entity.
+ *
+ * @return 0 if Entity successfully removed, -1 if entity not found.
+ */
+int
+model_omp_entity::removeEntity (QString name, QString value)
+{
+ int i = 0;
+ while (i < s_Content.size ())
+ {
+ int ndx = this->getEntityIndex (name, value);
+
+ if (ndx >= 0 )
+ {
+ removeRows (i, 1, QModelIndex ());
+ return 0;
+ }
+ }
+ return -1;
+}
+
+
+/**
+ * @brief Remove an entity from the model identified by complete entity.
+ *
+ * @param ent the entity that should be deleted.
+ */
+int
+model_omp_entity::removeEntity (QDomElement ent)
+{
+ int i = 0;
+
+ while (i < s_Content.size ())
+ {
+ QDomElement temp = s_Content.at (i);
+
+ if (temp == ent)
+ {
+ removeRows (i, 1, QModelIndex ());
+ return 0;
+ }
+ i++;
+ }
+ return -1;
+}
+
+
+/**
+ * @brief Remove an entity by index.
+ *
+ * @param ndx index of the entity.
+ */
+int
+model_omp_entity::removeEntity (int ndx)
+{
+ removeRows (ndx, 1, QModelIndex ());
+ return 0;
+}
+
+
+/**
+ * @brief Remove all tasks from the model.
+ */
+void
+model_omp_entity::removeEntities ()
+{
+ removeRows (0, s_Content.size (), QModelIndex ());
+}
+
+
+/**
+ * @brief Remove multiple rows from the model
+ *
+ * @param position first row
+ * @param rows rowcount
+ * @param index look at qt-doc for more information
+ */
+bool
+model_omp_entity::removeRows (int position, int rows,
+ const QModelIndex &index)
+{
+ beginRemoveRows (QModelIndex (), position, position+rows-1);
+
+ for (int row = 0; row < rows; ++row)
+ {
+ s_Content.removeAt (position);
+ }
+ endRemoveRows ();
+
+ return true;
+}
+
+
+/**
+ * @brief Getter
+ *
+ * @param index the index of the taskitem.
+ *
+ * @return if index is valid the selected task, else NULL.
+ */
+QDomElement
+model_omp_entity::getEntity (int index)
+{
+ QDomElement *node = new QDomElement ();
+ if ((index < 0) || (index >= s_Content.size ()))
+ {
+ node = NULL;
+ return *node;
+ }
+ return s_Content [index];
+}
+
+
+/**
+* @brief Get Taskindex in contentlist by id.
+*
+* @param id id of the task.
+*
+* @return index of the task in contentlist if found, else -1.
+*/
+int
+model_omp_entity::getEntityIndex (QString name, QString value)
+{
+ for (int i = 0; i < s_Content.size (); i++)
+ {
+ if (value.compare (getValue (s_Content.at (i), name)) == 0)
+ return i;
+ }
+ return -1;
+}
+
+
+/**
+* @brief Get the Value of a XML node.
+*
+* @param ent XML element.
+* @param name name of the entity, identified by a list of the parent element
+* names, seperated by space.
+*
+* @return Value of the XML node.
+*/
+QString
+model_omp_entity::getValue (QDomElement ent, QString name)
+{
+ int i = 1;
+ QStringList list = name.split (" ");
+ QDomElement node = ent.firstChildElement (list.at (0)).toElement ();
+ while (!node.isNull () && i < list.size())
+ {
+ node = node.firstChildElement (list.at (i)).toElement ();
+ i++;
+ }
+ QDomElement temp = node;
+ if (temp.hasChildNodes ())
+ {
+ QString s = temp.text ();
+ s.replace (temp.lastChild ().toElement ().text (), "");
+ return s;
+ }
+ return node.text ();
+}
+
+
+/**
+* @brief Get an Attribute from a XML node.
+*
+* @param ent XML element.
+* @param attr name of the attribute, identified by a list of the parent element
+* names and the attribute name, seperated by space.
+*
+* @return Value of the attribute.
+*/
+QString
+model_omp_entity::getAttr (QDomElement ent, QString attr)
+{
+ int i = 1;
+ QStringList list = attr.split (" ");
+ QDomElement node = ent;
+ while (!node.isNull () && i < list.size()-1)
+ {
+ node = node.firstChildElement (list.at (i)).toElement ();
+ i++;
+ }
+ if (node.hasAttributes ())
+ {
+ QDomNamedNodeMap nodeList = node.attributes ();
+ if (nodeList.contains (list.at (i)))
+ {
+ return nodeList.namedItem (list.at (i)).nodeValue ();
+ }
+ }
+ return NULL;
+}
+
+
+/**
+* @brief Add a Header to the table.
+*
+* @param displayname name that is shown in the table view header.
+* @param ompName name of the omp element containing the data for this row.
+*
+*/
+void
+model_omp_entity::addHeader (QString displayName, QString ompName)
+{
+ s_HeaderData.append (displayName);
+ s_HeaderOmp.append (ompName);
+}
+
+
+/**
+* @brief Get the omp header for a specified row.
+*
+* @param ndx index of the row.
+*
+* @return omp header string.
+*/
+QString
+model_omp_entity::getHeader (int ndx)
+{
+ return s_HeaderOmp[ndx];
+}
+
Added: trunk/gsa-desktop/src/model_omp_entity.h
===================================================================
--- trunk/gsa-desktop/src/model_omp_entity.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/model_omp_entity.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -0,0 +1,81 @@
+/**
+ * Copyright:
+ * Copyright (C) 2010 by Greenbone Networks GmbH
+ *
+ * Authors:
+ * Raimund Renkert <raimund.renkert at intevation.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+/**
+ * @file model_task.h
+ * @brief Protos and data structures for model_task.
+ */
+
+#ifndef MODEL_OMP_ENTITY_H
+#define MODEL_OMP_ENTITY_H
+
+#include <QtGui>
+#include <qdom.h>
+#include <glib.h>
+#include <openvas/omp/xml.h>
+#include <openvas/omp/omp.h>
+#include <openvas_server.h>
+
+class model_omp_entity : public QAbstractTableModel
+{
+ Q_OBJECT
+
+ public:
+ model_omp_entity ();
+ ~model_omp_entity ();
+
+ virtual Qt::ItemFlags flags (const QModelIndex &index) const;
+
+ virtual int rowCount (const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount (const QModelIndex &parent = QModelIndex()) const;
+
+ virtual QVariant data (const QModelIndex &index,
+ int role = Qt::DisplayRole) const;
+ virtual QVariant headerData (int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+
+ int addEntity (QDomElement ent, int pos);
+ int removeEntity (QString name, QString value);
+ int removeEntity (QDomElement ent);
+ int removeEntity (int ndx);
+ void removeEntities ();
+
+ QDomElement getEntity (int index);
+ int getEntityIndex (QString name, QString value);
+ QString getValue (QDomElement ent, QString name);
+ QString getAttr (QDomElement ent, QString attr);
+
+ int compareAttributes (QDomElement node, QDomElement comp);
+ bool removeRows (int position, int rows, const QModelIndex &index);
+
+ void addHeader (QString displayName, QString ompName);
+ QString getHeader (int ndx);
+
+ private:
+ QList<QDomElement> s_Content;
+ QStringList m_headers;
+ QList<QString> s_HeaderData;
+ QList<QString> s_HeaderOmp;
+ QMutex mutex;
+};
+#endif
Deleted: trunk/gsa-desktop/src/model_schedule.cpp
===================================================================
--- trunk/gsa-desktop/src/model_schedule.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/model_schedule.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,392 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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 "model_schedule.h"
-
-/**
- * @file model_schedule.cpp
- * @brief Model for the Tableview containing the schedules.
- *
- * Implements the QAbstractTableModel to store schedules.
- * Provides functionality for adding and removing a schedule from the model,
- * getting schedules by taskid and getting scheduleid by index.
- */
-
-model_schedule::model_schedule()
-{
-}
-
-
-model_schedule::~model_schedule()
-{
-}
-
-
-/**
- * @brief New implemented flags
- *
- * @param index: Index of the item in the model
- */
-Qt::ItemFlags
-model_schedule::flags (const QModelIndex &index) const
-{
- if (!index.isValid ())
- return Qt::ItemIsSelectable;
-
- return QAbstractTableModel::flags (index) | Qt::ItemIsSelectable;
-}
-
-
-/**
- * @brief new implemented rowCount.
- *
- * @param parent index of the parent in the model.
- *
- * @return size of the contentlist.
- */
-int
-model_schedule::rowCount (const QModelIndex &parent) const
-{
- return s_Content.count ();
-}
-
-
-/**
- * @brief new implemented columnCount.
- *
- * @param parent: index of the parent in the model
- *
- * @return todo
- */
-int
-model_schedule::columnCount (const QModelIndex &parent) const
-{
- return 5;
-}
-
-
-/**
- * @brief new implemented data ().
- *
- * @param index index of the item in the model
- * @param role itemrole, look at the qt-doc for more information
- *
- * @return data of the item selected by the index
- */
-QVariant
-model_schedule::data (const QModelIndex &index, int role) const
-{
- if (!index.isValid ())
- return QVariant ();
-
- if (index.row () >= s_Content.size () || index.row () < 0)
- return QVariant();
-
- if (role == Qt::DisplayRole)
- {
- omp_entity_schedule *ent = s_Content.at (index.row ());
- switch (index.column ())
- {
- case (0): return ent->getName ();
- case (1): return ent->getFirstTime ();
- case (2): return ent->getNextTime ();
- case (3):
- {
- if (ent->getPeriod () != 0)
- {
- long time = ent->getPeriod ();
- time /= 3600;
- long hour = time % 24;
- time /= 24;
- long day = time % 7;
- time /= 7;
- long week = time;
-
- QString s;
- if (hour == 1)
- return s.setNum (hour, 10) + " hour";
- else if (hour > 1)
- return s.setNum (hour, 10) + " hours";
- else if (day == 1)
- return s.setNum (day, 10) + " day";
- else if (day > 1)
- return s.setNum (day, 10) + " days";
- else if (week == 1)
- return s.setNum (week, 10) + " week";
- else if (week > 1)
- return s.setNum (week, 10) + " weeks";
-
-
- }
- else
- {
- QString s;
- if (ent->getPeriodMonth () == 1)
- return s.setNum (ent->getPeriodMonth (), 10) + " month";
- if (ent->getPeriodMonth () > 1)
- return s.setNum (ent->getPeriodMonth (), 10) + " months";
- }
- }
- case (4):
- {
- long time = ent->getDuration ();
- time /= 3600;
- long hour = time % 24;
- time /= 24;
- long day = time % 7;
- time /= 7;
- long week = time;
-
- QString s;
- if (hour == 1)
- return s.setNum (hour, 10) + " hour";
- else if (hour > 1)
- return s.setNum (hour, 10) + " hours";
- else if (day == 1)
- return s.setNum (day, 10) + " day";
- else if (day > 1)
- return s.setNum (day, 10) + " days";
- else if (week == 1)
- return s.setNum (week, 10) + " week";
- else if (week > 1)
- return s.setNum (week, 10) + " weeks";
-
- }
- default: return QVariant ();
- }
- }
- return QVariant ();
-}
-
-
-/**
- * @brief new implemented headerdata.
- *
- * @param section current position of the header
- * @param orientation orientation of the header (horizontal/vertical)
- * @param role headerrole
- *
- * @return title of the scheduleview header
- */
-QVariant
-model_schedule::headerData (int section, Qt::Orientation orientation,
- int role) const
-{
- if (role != Qt::DisplayRole)
- return QVariant ();
-
- if (orientation == Qt::Horizontal)
- {
- switch (section)
- {
- case 0: return tr ("Name");
- case 1: return tr ("First Run");
- case 2: return tr ("Next Run");
- case 3: return tr ("Period");
- case 4: return tr ("Duration");
- default: return QVariant ();
- }
- }
- return QVariant ();
-}
-
-
-/**
- * @brief Add a schedule to the model.
- *
- * @param ent Scheduleentity, containing the data for a schedule
- */
-void
-model_schedule::addSchedule (omp_entity_schedule *ent, int pos)
-{
- bool found = false;
-
- if (s_Content.size () == 0)
- {
-
- beginInsertRows (QModelIndex (), s_Content.size (), s_Content.size ());
- s_Content.insert (pos, ent);
- endInsertRows ();
- }
-
- for (int i = 0; i < s_Content.size (); i++)
- {
- omp_entity_schedule *entity = s_Content.at(i);
- if (entity->getId ().compare (ent->getId ()) == 0)
- {
- found = true;
- if (i != pos)
- {
- removeRows (i, 1, QModelIndex ());
- beginInsertRows (QModelIndex (), s_Content.size (),
- s_Content.size ());
- s_Content.insert (pos, ent);
- endInsertRows ();
- }
- break;
- }
- }
- if (!found)
- {
- beginInsertRows (QModelIndex (), s_Content.size (), s_Content.size ());
- s_Content.insert (pos, ent);
- endInsertRows ();
- return;
- }
- return;
-
-}
-
-
-/**
- * @brief Remove a schedule from the model by id.
- *
- * @param id Scheduleid, the schedule that should be deleted
- */
-void
-model_schedule::removeSchedule (QString id)
-{
- bool found = false;
- int i = 0;
-
- while (i < s_Content.size () && !found)
- {
- omp_entity_schedule *ent = s_Content.at (i);
- if (ent->getId () == id)
- {
- found = true;
- }
- i++;
- }
-
- if (found)
- {
- --i;
- removeRows (i, 1, QModelIndex ());
- }
- else
- {
- qDebug () << "Schedule not found!; in removeSchedule ()";
- }
-}
-
-
-/**
- * @brief Remove a schedule from the model identified by complete entity.
- *
- * @param ent Scheduleentity, the schedule that should be deleted.
- */
-void
-model_schedule::removeSchedule (omp_entity_schedule *ent)
-{
- bool found = false;
- int i = 0;
-
- while (i < s_Content.size () && !found)
- {
- omp_entity_schedule *temp = s_Content.at (i);
-
- if (ent->getId () == temp->getId ())
- {
- found = true;
- }
- i++;
- }
-
- if (found)
- {
- --i;
- removeRows(i, 1, QModelIndex ());
- }
- else
- {
- qDebug () << "Schedule not found!; in removeSchedule ()";
- }
-}
-
-
-/**
- * @brief Remove all schedules from the model.
- */
-void
-model_schedule::removeSchedules ()
-{
- removeRows (0, s_Content.size (), QModelIndex ());
-}
-
-
-/**
- * @brief Remove multiple rows from the model
- *
- * @param position first row
- * @param rows rowcount
- * @param index look at qt-doc for more information
- */
-bool
-model_schedule::removeRows (int position, int rows,
- const QModelIndex &index)
-{
- beginRemoveRows (QModelIndex (), position, position+rows-1);
-
- for (int row = 0; row < rows; ++row)
- {
- s_Content.removeAt (position);
- }
- endRemoveRows ();
- return true;
-}
-
-
-/**
- * @brief Getter
- *
- * @param index the index of the scheduleitem.
- *
- * @return if index is valid the selected schedule, else NULL.
- */
-omp_entity_schedule *
-model_schedule::getSchedule (int index)
-{
- if ((index < 0) || (index >= s_Content.size ()))
- return NULL;
- return s_Content [index];
-}
-
-
-/**
-* @brief Get Scheduleindex in contentlist by id.
-*
-* @param id id of the schedule.
-*
-* @return index of the schedule in contentlist if found, else -1.
-*/
-int
-model_schedule::getSchedule (QString id)
-{
- for (int i = 0; i < s_Content.size (); i++)
- {
- if (id.compare (s_Content.at (i)->getId ()) == 0)
- return i;
- }
- return -1;
-}
\ No newline at end of file
Deleted: trunk/gsa-desktop/src/model_schedule.h
===================================================================
--- trunk/gsa-desktop/src/model_schedule.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/model_schedule.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,75 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- */
-
-/**
- * @file model_schedule.h
- * @brief Protos and data structures for model_schedule.
- */
-
-#ifndef MODEL_SCHEDULE_H
-#define MODEL_SCHEDULE_H
-
-#include <QtGui>
-
-#include "omp_entity_schedule.h"
-
-class model_schedule : public QAbstractTableModel
-{
- Q_OBJECT
-
- public:
- model_schedule ();
- ~model_schedule ();
-
- virtual Qt::ItemFlags flags (const QModelIndex &index) const;
-
- virtual int rowCount (const QModelIndex &parent = QModelIndex()) const;
- virtual int columnCount (const QModelIndex &parent = QModelIndex()) const;
-
- virtual QVariant data (const QModelIndex &index,
- int role = Qt::DisplayRole) const;
- virtual QVariant headerData (int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
-
- void addSchedule (omp_entity_schedule *ent, int pos);
- void removeSchedule (QString id);
- void removeSchedule (omp_entity_schedule *ent);
- void removeSchedules ();
-
- omp_entity_schedule * getSchedule (int index);
- int getSchedule (QString id);
-
- bool removeRows (int position, int rows, const QModelIndex &index);
-
- /**
- * @brief Getter/Setter for modelcontent
- */
- CLASS_OBJECT_PROPERTY (QList <omp_entity_schedule *> , Content);
-
- private:
- QList<omp_entity_schedule *> s_Content;
- QStringList m_headers;
-
-};
-
-#endif
Deleted: trunk/gsa-desktop/src/model_task.cpp
===================================================================
--- trunk/gsa-desktop/src/model_task.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/model_task.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,341 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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 "model_task.h"
-
-/**
- * @file model_task.cpp
- * @brief Model for the Tableview containing the status of tasks.
- *
- * Implements the QAbstractTableModel to store statusdata for tasks.
- * Provides functionality for adding and removing a task from the model,
- * getting taskindex by taskid and getting taskid by index.
- */
-
-model_task::model_task ()
-{
-}
-
-
-model_task::~model_task ()
-{
-}
-
-/**
- * @brief New implemented flags
- *
- * @param index: Index of the item in the model
- */
-Qt::ItemFlags
-model_task::flags (const QModelIndex &index) const
-{
- if (!index.isValid ())
- return Qt::ItemIsSelectable;
-
- return QAbstractTableModel::flags (index) | Qt::ItemIsSelectable;
-}
-
-/**
- * @brief new implemented rowCount.
- *
- * @param parent index of the parent in the model.
- *
- * @return size of the contentlist.
- */
-int
-model_task::rowCount (const QModelIndex &parent) const
-{
- return s_Content.count ();
-}
-
-/**
- * @brief new implemented columnCount.
- *
- * @param parent: index of the parent in the model
- *
- * @return constant 7, columns of the taskview
- */
-int
-model_task::columnCount (const QModelIndex &parent) const
-{
- return 8;
-}
-
-
-/**
- * @brief new implemented data ().
- *
- * @param index index of the item in the model
- * @param role itemrole, look at the qt-doc for more information
- *
- * @return data of the item selected by the index
- */
-QVariant
-model_task::data (const QModelIndex &index, int role) const
-{
- if (!index.isValid ())
- return QVariant ();
-
- if (index.row () >= s_Content.size () || index.row () < 0)
- return QVariant();
-
- if (role == Qt::DisplayRole)
- {
- omp_entity_status *ent = s_Content.at (index.row ());
- switch (index.column ())
- {
- case (0): return ent->getName ();
- case (1): return ent->getScheduleId ();
- case (2): return ent->getStatus ();
- case (3): return ent->getReportCount ();
- case (4): return ent->getFirstReport ();
- case (5): return ent->getLastReport ();
- case (6): return ent->getThreat ();
- case (7): return ent->getTrend ();
- default: return QVariant ();
- }
- }
- return QVariant ();
-}
-
-
-/**
- * @brief new implemented headerdata.
- *
- * @param section current position of the header
- * @param orientation orientation of the header (horizontal/vertical)
- * @param role headerrole
- *
- * @return title of the taskviewheader
- */
-QVariant
-model_task::headerData (int section, Qt::Orientation orientation,
- int role) const
-{
- if (role != Qt::DisplayRole)
- return QVariant ();
-
- if (orientation == Qt::Horizontal)
- {
- switch (section)
- {
- case 0: return tr ("Name");
- case 1: return tr ("");
- case 2: return tr ("Status");
- case 3: return tr ("Reports");
- case 4: return tr ("First");
- case 5: return tr ("Last");
- case 6: return tr ("Threat");
- case 7: return tr ("Trend");
- default: return QVariant ();
- }
- }
- return QVariant ();
-}
-
-
-/**
- * @brief Add a task to the model.
- *
- * @param ent taskentity, containing the data for a task
- */
-void
-model_task::addTask (omp_entity_status *ent, int pos)
-{
- bool found = false;
-
- if (s_Content.size () == 0)
- {
- beginInsertRows (QModelIndex (), s_Content.size (), s_Content.size ());
- s_Content.insert (pos, ent);
- endInsertRows ();
- }
-
- for (int i = 0; i < s_Content.size(); i++)
- {
- omp_entity_status *entity = s_Content.at(i);
- if (entity->getId().compare(ent->getId()) == 0)
- {
- found = true;
- if (i != pos)
- {
- removeRows (i, 1, QModelIndex ());
- beginInsertRows (QModelIndex (), s_Content.size (),
- s_Content.size ());
- s_Content.insert (pos, ent);
- endInsertRows ();
- }
-
- entity->setReportCount (ent->getReportCount ());
- entity->setStatus (ent->getStatus ());
- entity->setThreat (ent->getThreat ());
- entity->setTrend (ent->getTrend ());
- entity->setFirstReport (ent->getFirstReport ());
- entity->setLastReport (ent->getLastReport ());
- entity->setProgress (ent->getProgress ());
-
- break;
- }
- }
- if (!found)
- {
- beginInsertRows (QModelIndex (), s_Content.size (), s_Content.size ());
- s_Content.insert (pos, ent);
- endInsertRows ();
- return;
- }
-
- return;
-}
-
-
-
-/**
- * @brief Remove a task from the model by id.
- *
- * @param id Taskid, the task that should be deleted
- */
-void
-model_task::removeTask (QString id)
-{
- bool found = false;
- int i = 0;
-
- while (i < s_Content.size () && !found)
- {
- omp_entity_status *ent = s_Content.at (i);
- if (ent->getId () == id)
- {
- found = true;
- }
- i++;
- }
-
- if (found)
- {
- --i;
- removeRows (i, 1, QModelIndex ());
- }
- else
- {
- qDebug () << "Task not found!; in removeTask ()";
- }
-}
-
-/**
- * @brief Remove a task from the model identified by complete entity.
- *
- * @param ent Taskentity, the task that should be deleted.
- */
-void
-model_task::removeTask (omp_entity_status *ent)
-{
- bool found = false;
- int i = 0;
-
- while (i < s_Content.size () && !found)
- {
- omp_entity_status *temp = s_Content.at (i);
-
- if (ent->getId () == temp->getId ())
- {
- found = true;
- }
- i++;
- }
-
- if (found)
- {
- --i;
- removeRows(i, 1, QModelIndex ());
- }
- else
- {
- qDebug () << "Task not found!; in removeTask ()";
- }
-}
-
-/**
- * @brief Remove all tasks from the model.
- */
-void
-model_task::removeTasks ()
-{
- removeRows (0, s_Content.size (), QModelIndex ());
-}
-
-
-/**
- * @brief Remove multiple rows from the model
- *
- * @param position first row
- * @param rows rowcount
- * @param index look at qt-doc for more information
- */
-bool
-model_task::removeRows (int position, int rows,
- const QModelIndex &index)
-{
- beginRemoveRows (QModelIndex (), position, position+rows-1);
-
- for (int row = 0; row < rows; ++row)
- {
- s_Content.removeAt (position);
- }
- endRemoveRows ();
-}
-
-
-/**
- * @brief Getter
- *
- * @param index the index of the taskitem.
- *
- * @return if index is valid the selected task, else NULL.
- */
-omp_entity_status *
-model_task::getTask (int index)
-{
- if ((index < 0) || (index >= s_Content.size ()))
- return NULL;
- return s_Content [index];
-}
-
-
-/**
-* @brief Get Taskindex in contentlist by id.
-*
-* @param id id of the task.
-*
-* @return index of the task in contentlist if found, else -1.
-*/
-int
-model_task::getTask (QString id)
-{
- for (int i = 0; i < s_Content.size (); i++)
- {
- if (id.compare (s_Content.at (i)->getId ()) == 0)
- return i;
- }
- return -1;
-}
\ No newline at end of file
Deleted: trunk/gsa-desktop/src/model_task.h
===================================================================
--- trunk/gsa-desktop/src/model_task.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/model_task.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,74 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- */
-
-/**
- * @file model_task.h
- * @brief Protos and data structures for model_task.
- */
-
-#ifndef MODEL_TASK_H
-#define MODEL_TASK_H
-
-#include <QtGui>
-
-#include "omp_entity_status.h"
-
-class model_task : public QAbstractTableModel
-{
- Q_OBJECT
-
- public:
- model_task ();
- ~model_task ();
-
- virtual Qt::ItemFlags flags (const QModelIndex &index) const;
-
- virtual int rowCount (const QModelIndex &parent = QModelIndex()) const;
- virtual int columnCount (const QModelIndex &parent = QModelIndex()) const;
-
- virtual QVariant data (const QModelIndex &index,
- int role = Qt::DisplayRole) const;
- virtual QVariant headerData (int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
-
- void addTask (omp_entity_status *ent, int pos);
- void removeTask (QString id);
- void removeTask (omp_entity_status *ent);
- void removeTasks ();
-
- omp_entity_status * getTask (int index);
- int getTask (QString id);
-
- bool removeRows (int position, int rows, const QModelIndex &index);
-
- /**
- * @brief Getter/Setter for modelcontent
- */
- CLASS_OBJECT_PROPERTY (QList <omp_entity_status *>, Content);
-
- private:
- QList<omp_entity_status *> s_Content;
- QStringList m_headers;
-
-};
-#endif
Modified: trunk/gsa-desktop/src/omp_connector.cpp
===================================================================
--- trunk/gsa-desktop/src/omp_connector.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_connector.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -38,11 +38,12 @@
*/
omp_connector::omp_connector ()
{
- updater = new QList <omp_update_status*> ();
+ updater = new omp_update_entity ();
helper = new omp_update_helper ();
+ updater->setHelper (helper);
commands = new omp_commands ();
this->credentials = NULL;
-
+ updater->running = true;
connect (helper, SIGNAL (sig_trigger_update ()), this,
SLOT (taskupdate_triggred ()));
connect (helper, SIGNAL (sig_started_update ()), this,
@@ -82,6 +83,11 @@
this->credentials->setPassword (pwd);
commands->setCredentials (addr, port, name, pwd);
+ updater->setCredentials (this->credentials->getServerAddress (),
+ this->credentials->getServerPort (),
+ this->credentials->getUserName (),
+ this->credentials->getPassword ());
+
}
/**
@@ -110,7 +116,7 @@
* @param model model containing the updated data.
*/
void
-omp_connector::getStatus (int interval, model_task *model)
+omp_connector::getStatus (int interval, model_omp_entity *model)
{
if (this->credentials == NULL)
{
@@ -119,34 +125,13 @@
}
else
{
- omp_update_status *newupdater = new omp_update_status ();
- newupdater->setCredentials (this->credentials->getServerAddress (),
- this->credentials->getServerPort (),
- this->credentials->getUserName (),
- this->credentials->getPassword ());
- newupdater->setModel (model);
- newupdater->setHelper (helper);
- newupdater->startUpdate (0);
- updater->append (newupdater);
-
- if (interval > 0)
- {
- newupdater->startUpdate (interval);
- }
- newupdater->start ();
+ updater->update ("status", model);
}
}
-/**
- * @brief Starts an updaterequest in a new updaterthread.
- *
- * Starts the Updater requesting schedules.
- *
- * @param model model containing the updated data.
- */
void
-omp_connector::getSchedules (model_schedule *model)
+omp_connector::getSchedules (model_omp_entity *model)
{
if (this->credentials == NULL)
{
@@ -155,18 +140,10 @@
}
else
{
- omp_update_schedules *schedule = new omp_update_schedules();
- schedule->setHelper (helper);
- schedule->setModel (model);
- schedule->setCredentials (this->credentials->getServerAddress (),
- this->credentials->getServerPort (),
- this->credentials->getUserName (),
- this->credentials->getPassword ());
- schedule->start();
+ updater->update ("schedules", model);
}
}
-
/**
* @brief Removes logindata from the connector.
*/
@@ -225,10 +202,6 @@
void
omp_connector::stopTaskUpdates ()
{
- for (int i = 0; i < updater->size (); i++ )
- {
- updater->at (i)->stopUpdate ();
- }
emit sig_stopped_taskupdate ();
}
@@ -241,12 +214,9 @@
bool
omp_connector::taskUpdateRunning ()
{
- for (int i = 0; i <= updater->size (); i++ )
+ if (updater->running)
{
- if (!updater->at (i)->running)
- {
- return true;
- }
+ return true;
}
return false;
}
@@ -289,14 +259,6 @@
void
omp_connector::taskupdate_finished ()
{
- // cleanup list
- for (int i = 0; i < updater->size (); i++ )
- {
- if (!updater->at (i)->running && !updater->at (i)->isRunning ())
- {
- updater->removeAt (i);
- }
- }
emit sig_finished_taskupdate ();
}
@@ -317,4 +279,4 @@
omp_connector::log (QString msg, int prio)
{
emit sig_log(msg, prio);
-}
\ No newline at end of file
+}
Modified: trunk/gsa-desktop/src/omp_connector.h
===================================================================
--- trunk/gsa-desktop/src/omp_connector.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_connector.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -32,8 +32,7 @@
#include <QObject>
#include "omp_credentials.h"
#include "omp_commands.h"
-#include "omp_update_status.h"
-#include "omp_update_schedules.h"
+#include "omp_update_entity.h"
#include "omp_update_helper.h"
class omp_connector : public QObject
@@ -73,7 +72,7 @@
private:
omp_credentials *credentials;
- QList <omp_update_status *> *updater;
+ omp_update_entity *updater;
omp_update_helper *helper;
omp_commands *commands;
@@ -95,10 +94,10 @@
bool taskUpdateRunning ();
void stopTaskUpdates ();
- void getStatus (int interval, model_task *model);
- void getSchedules (model_schedule *model);
+ void getStatus (int interval, model_omp_entity *model);
+ void getSchedules (model_omp_entity *model);
int startTask (QString id);
int stopTask (QString id);
int deleteTask (QString id);
};
-#endif
\ No newline at end of file
+#endif
Deleted: trunk/gsa-desktop/src/omp_entity_schedule.h
===================================================================
--- trunk/gsa-desktop/src/omp_entity_schedule.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_entity_schedule.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,66 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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 OMP_ENTITY_SCHEDULE_H
-#define OMP_ENTITY_SCHEDULE_H
-
-#include <QObject>
-#include <QString>
-#include "entity_defines.h"
-
-/**
- * @file omp_entity_schedule.h
- * @brief Contains one schedule
- *
- * This entity contains all data for one schedule
- */
-class omp_entity_schedule : public QObject
-{
-
- Q_OBJECT
- public:
- omp_entity_schedule(){}
- ~omp_entity_schedule(){}
-
- CLASS_OBJECT_PROPERTY (QString, Name);
- CLASS_OBJECT_PROPERTY (QString, Id);
- CLASS_OBJECT_PROPERTY (qlonglong, Period);
- CLASS_OBJECT_PROPERTY (QString, NextTime);
- CLASS_OBJECT_PROPERTY (QString, FirstTime);
- CLASS_OBJECT_PROPERTY (qlonglong, Duration);
- CLASS_OBJECT_PROPERTY (int, PeriodMonth);
- CLASS_OBJECT_PROPERTY (int, InUse);
- CLASS_OBJECT_PROPERTY (QString, Comment);
-
- private:
- QString s_Name;
- QString s_Id;
- qlonglong s_Period;
- QString s_NextTime;
- QString s_FirstTime;
- qlonglong s_Duration;
- int s_PeriodMonth;
- int s_InUse;
- QString s_Comment;
-};
-
-#endif
Deleted: trunk/gsa-desktop/src/omp_entity_status.h
===================================================================
--- trunk/gsa-desktop/src/omp_entity_status.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_entity_status.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,101 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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 OMP_STATUS_ENTITY_H
-#define OMP_STATUS_ENTITY_H
-
-#include <QObject>
-#include <QString>
-#include "entity_defines.h"
-
-/**
- * @file omp_entity_status.h
- * @brief Contains one Task and its status
- *
- * This entity contains all statusdata for one task using enums for status,
- * trend and threat.
- */
-
-class omp_entity_status : public QObject
-{
- Q_OBJECT
-
- public:
- omp_entity_status (){}
- ~omp_entity_status (){}
-
- enum Status
- {
- TASK_NEW,
- TASK_REQUESTED,
- TASK_DELREQUESTED,
- TASK_STOPREQUESTED,
- TASK_STOPPED,
- TASK_ERROR,
- TASK_DONE,
- TASK_ACTIVE,
- };
-
- enum Trend
- {
- TREND_LVLINCREASED,
- TREND_NBRINCREASED,
- TREND_NOCHANGE,
- TREND_NBRDECREASED,
- TREND_LVLDECREASED,
- TREND_NONE,
- };
-
- enum Threat
- {
- THREAT_HIGH,
- THREAT_MEDIUM,
- THREAT_LOW,
- THREAT_NONE,
- };
-
-
- CLASS_OBJECT_PROPERTY (QString, Name);
- CLASS_OBJECT_PROPERTY (QString, Id);
- CLASS_OBJECT_PROPERTY (int, Progress);
- CLASS_OBJECT_PROPERTY (Status, Status);
- CLASS_OBJECT_PROPERTY (int, ReportCount);
- CLASS_OBJECT_PROPERTY (QString, FirstReport);
- CLASS_OBJECT_PROPERTY (QString, LastReport);
- CLASS_OBJECT_PROPERTY (Threat, Threat);
- CLASS_OBJECT_PROPERTY (Trend, Trend);
- CLASS_OBJECT_PROPERTY (QString, ScheduleId);
-
- private:
- QString s_Name;
- QString s_Id;
- Status s_Status;
- int s_Progress;
- int s_ReportCount;
- QString s_FirstReport;
- QString s_LastReport;
- Threat s_Threat;
- Trend s_Trend;
- QString s_ScheduleId;
-};
-
-#endif
Modified: trunk/gsa-desktop/src/omp_update.cpp
===================================================================
--- trunk/gsa-desktop/src/omp_update.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_update.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -35,14 +35,13 @@
omp_update::omp_update ()
{
- mutex = new QMutex ();
+ QMutex mutex ();
interval = 0;
running = false;
}
omp_update::~omp_update ()
{
- free (mutex);
free (credentials);
}
Modified: trunk/gsa-desktop/src/omp_update.h
===================================================================
--- trunk/gsa-desktop/src/omp_update.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_update.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -50,12 +50,12 @@
protected:
omp_update_helper *helper;
-
+ int updating;
public:
omp_update ();
~omp_update ();
- QMutex *mutex;
+ QMutex mutex;
int interval;
bool running;
@@ -73,4 +73,4 @@
int connectToServer (const QString &addr, int port);
};
-#endif
\ No newline at end of file
+#endif
Added: trunk/gsa-desktop/src/omp_update_entity.cpp
===================================================================
--- trunk/gsa-desktop/src/omp_update_entity.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_update_entity.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -0,0 +1,233 @@
+/**
+ * Copyright:
+ * Copyright (C) 2010 by Greenbone Networks GmbH
+ *
+ * Authors:
+ * Raimund Renkert <raimund.renkert at intevation.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "omp_update_entity.h"
+
+/**
+ * @file omp_update_entity.cpp
+ * @brief Thread to update omp entites.
+ *
+ * Implements the functionality to update omp entities.
+ * Inherits basic omp- and threadfunctionalty from omp_updater
+ */
+
+omp_update_entity::omp_update_entity ()
+{
+ updating = 0;
+}
+
+
+omp_update_entity::~omp_update_entity ()
+{
+}
+
+/**
+ * @brief Starting point for the thread
+ *
+ * Starts an update for an omp entity.
+ */
+void
+omp_update_entity::run ()
+{
+ helper->log (tr ("Update: Thread started."), 5);
+ while (true)
+ {
+ while (!queue.empty ())
+ {
+ if (!this->running)
+ {
+ helper->log (tr ("Terminating update thread."), 5);
+ mutex.unlock();
+ return;
+ }
+ if (queue.contains ("status"))
+ {
+ mutex.lock ();
+ updating = 1;
+ model_omp_entity *m = queue["status"];
+ mutex.unlock ();
+ updateTasks (m);
+ mutex.lock ();
+ queue.remove ("status");
+ updating = 0;
+ mutex.unlock ();
+ }
+ else if (queue.contains ("schedules"))
+ {
+ mutex.lock ();
+ updating = 1;
+ mutex.unlock ();
+ updateSchedules (queue["schedules"]);
+ mutex.lock ();
+ queue.remove ("schedules");
+ updating = 0;
+ mutex.unlock ();
+ }
+ }
+ updateStop.wait (&mutex);
+ }
+}
+
+
+/**
+ * @brief Takes an updaterequest, and starts the thread.
+ *
+ * @param type Update type.
+ * @param m model for the requested update.
+ *
+ * @return 0
+ */
+int
+omp_update_entity::update (QString type, model_omp_entity *m)
+{
+ queue.insert (type, m);
+ startUpdate ();
+ return 0;
+}
+
+
+/**
+ * @brief Starts the thread.
+ *
+ */
+void
+omp_update_entity::startUpdate ()
+{
+ if (!queue.empty ())
+ {
+ if (!this->isRunning ())
+ {
+ this->start ();
+ }
+ else
+ {
+ updateStop.wakeOne ();
+ }
+ }
+}
+
+
+/**
+ * @brief Updates the task status.
+ *
+ * Gets the task status from the manager, converts to QDomElement and adds
+ * the entities to the model.
+ *
+ * @param m Model for the omp entities.
+ *
+ * @return 0 on success, else -1.
+ */
+int
+omp_update_entity::updateTasks (model_omp_entity *m)
+{
+ entity_t status = NULL;
+ int errLine, errCol;
+ QString errMsg;
+ int ret = this->connectToServer (this->credentials->getServerAddress (),
+ this->credentials->getServerPort ());
+ if (ret == 0)
+ {
+ omp_get_status (&session, NULL, 0, &status);
+ unsigned int i = 0;
+
+ if (status == NULL)
+ return -1;
+
+ GString* response= new GString ();
+ print_entity_to_string (status, response);
+ QDomDocument *doc = new QDomDocument ();
+ QDomNodeList taskList;
+ QString qResponse (response->str);
+ doc->setContent (qResponse, true, &errMsg, &errLine, &errCol);
+ taskList = doc->elementsByTagName ("task");
+ while (i < taskList.length ())
+ {
+ mutex.lock ();
+ m->addEntity (taskList.item (i).toElement (), i);
+ mutex.unlock ();
+ i++;
+ }
+ helper->finishedupdate();
+ helper->triggerupdate();
+ openvas_server_close (this->socket, session);
+ free_entity (status);
+ return 0;
+ }
+ return -1;
+}
+
+
+/**
+ * @brief Updates the Schedules list.
+ *
+ * Gets the Schedules list form the manager, converts to QDomElement and adds
+ * the entities to the model.
+ *
+ * @param m Model for the omp entities.
+ *
+ * @return 0 on success, else -1.
+ */
+int
+omp_update_entity::updateSchedules (model_omp_entity *m)
+{
+ entity_t schedules = NULL;
+ int errLine, errCol;
+ QString errMsg;
+ int ret = this->connectToServer (this->credentials->getServerAddress (),
+ this->credentials->getServerPort ());
+ if (ret == 0)
+ {
+ if (openvas_server_send (&session, "<get_schedules"
+ " details=\"1\""
+ " sort_field=\"name\""
+ " sort_order=\"ascending\"/>") == -1)
+ {
+ return -1;
+ }
+ if (read_entity (&session, &schedules)) return -1;
+
+ unsigned int i = 0;
+
+ if (schedules == NULL)
+ return -1;
+
+ GString* response= new GString ();
+ print_entity_to_string (schedules, response);
+ QDomDocument *doc = new QDomDocument ();
+ QDomNodeList domList;
+ QString qResponse (response->str);
+ doc->setContent (qResponse, true, &errMsg, &errLine, &errCol);
+ domList = doc->elementsByTagName ("schedule");
+ while (i < domList.length ())
+ {
+ mutex.lock ();
+ m->addEntity (domList.item (i).toElement (), i);
+ mutex.unlock ();
+ i++;
+ }
+ openvas_server_close (this->socket, session);
+ free_entity (schedules);
+ return 0;
+ }
+ return -1;
+}
Added: trunk/gsa-desktop/src/omp_update_entity.h
===================================================================
--- trunk/gsa-desktop/src/omp_update_entity.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_update_entity.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -0,0 +1,58 @@
+/**
+ * Copyright:
+ * Copyright (C) 2010 by Greenbone Networks GmbH
+ *
+ * Authors:
+ * Raimund Renkert <raimund.renkert at intevation.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+/**
+ * @file omp_update_status.h
+ * @brief Protos and data structures for omp_update_status.
+ */
+#ifndef OMP_UPDATE_ENTITY_H
+#define OMP_UPDATE_ENTITY_H
+
+#include <QtGui>
+#include <qdom.h>
+
+#include "omp_update.h"
+#include "omp_update_helper.h"
+#include "model_omp_entity.h"
+
+class omp_update_entity : public omp_update
+{
+ private:
+ QWaitCondition updateStop;
+
+ model_omp_entity *model;
+ QString updateType;
+ QMap <QString, model_omp_entity*> queue;
+
+ void startUpdate ();
+ int updateTasks (model_omp_entity *m);
+ int updateSchedules (model_omp_entity *m);
+
+ public:
+ omp_update_entity ();
+ ~omp_update_entity ();
+
+ virtual void run ();
+ int update (QString type, model_omp_entity* model);
+};
+#endif
Deleted: trunk/gsa-desktop/src/omp_update_schedules.cpp
===================================================================
--- trunk/gsa-desktop/src/omp_update_schedules.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_update_schedules.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,260 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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 "omp_update_schedules.h"
-
-/**
- * @file omp_update_status.cpp
- * @brief Thread to update the taskstatus
- *
- * Implements the functionality to update the schedules.
- * Inherits basic omp- and threadfunctionalty from omp_updater
- */
-
-omp_update_schedules::omp_update_schedules ()
-{
- schedules = NULL;
-}
-
-
-omp_update_schedules::~omp_update_schedules ()
-{
-}
-
-
-/**
- * @brief Starting point for the thread
- *
- * Starts an update for the schedules.
- * Sends the signals sig_started_update (), sig_finished_update () and
- * sig_trigger_update () through the helper omp_update_helper.
- */
-void
-omp_update_schedules::run ()
-{
- mutex->lock ();
- helper->log (tr ("Schedule update: Thread started"), 4);
-
- while (true)
- {
- int ret = this->connectToServer (this->credentials->getServerAddress (),
- this->credentials->getServerPort ());
-
- if (ret == 0)
- {
- helper->log (tr ("Schedule update: running..."), 5);
-
- if (openvas_server_send (&session, "<get_schedules"
- " details=\"1\""
- " sort_field=\"name\""
- " sort_order=\"ascending\"/>") == -1)
- {
- return;
- }
- if (read_entity (&session, &schedules)) return;
-
- update ();
- helper->log (tr ("Schedule update: finished"), 5);
- openvas_server_close (this->socket, session);
- }
- else
- {
- helper->log (tr ("Schedule update: Connection failed: %1").arg (ret),
- 4);
- helper->log (tr ("Schedule update: Terminating thread."), 5);
- return;
- }
- if (!this->running)
- {
- helper->log (tr ("Schedule update: Terminating thread."), 5);
- mutex->unlock();
- return;
- }
- QThread::sleep (interval);
- if (!this->running)
- {
- helper->log (tr ("Schedule update: Terminating thread."), 5);
- mutex->unlock();
- return;
- }
- }
-}
-
-/**
- * @brief Setter
- *
- * Sets the Model in which the statusdata should be stored in
- *
- * @param m: Model for statusdataview
- */
-void
-omp_update_schedules::setModel (model_schedule *m)
-{
- model = m;
-}
-
-/**
- * @brief Taskstatus update
- *
- * This function extracts the statusdata of the OpenVAS Manager response and
- * sets it to the given model.
- *
- * @return 0 on success, -1 on error.
- */
-int
-omp_update_schedules::update ()
-{
- int i = 0;
- entity_t schedule;
-
- if (schedules == NULL)
- {
- helper->log (tr ("Schedule request failed!"), 1);
- return -1;
- }
- entities_t schedules_m = schedules->entities;
-
- while (schedule = first_entity (schedules_m))
- {
- if (strcmp (entity_name (schedule), "schedule") == 0)
- {
-
- omp_entity_schedule *ent = new omp_entity_schedule ();
- entity_t entity;
- const char *id, *name, *comment, *first_time, *next_time, *period,
- *period_month, *duration, *inUse;
- bool *ok = false;
-
- id = entity_attribute (schedule, "id");
- ent->setId (id);
- //Get the Schedulename, set to unkown if empty
- entity = entity_child (schedule, "name");
- if (entity == NULL)
- {
- ent->setName ("unknown");
- }
- else
- {
- name = entity_text (entity);
- ent->setName (name);
- }
-
- //Get comment, set to "" if empty
- entity = entity_child (schedule, "comment");
- if (entity == NULL)
- {
- ent->setComment ("");
- }
- else
- {
- comment = entity_text (entity);
- QString c (comment);
- ent->setComment (c);
- }
-
- //Get first time
- entity = entity_child (schedule, "first_time");
- if (entity == NULL)
- {
- ent->setFirstTime ("");
- }
- else
- {
- first_time = entity_text (entity);
- QString t (first_time);
- ent->setFirstTime (t);
- }
-
- //Get next time
- entity = entity_child (schedule, "next_time");
- if (entity == NULL)
- {
- ent->setNextTime ("");
- }
- else
- {
- next_time = entity_text (entity);
- QString t (next_time);
- ent->setNextTime (t);
- }
-
- //Get period
- entity = entity_child (schedule, "period");
- if (entity == NULL)
- {
- ent->setPeriod (0);
- }
- else
- {
- period = entity_text (entity);
- QString t (period);
- ent->setPeriod (t.toLongLong (ok, 10));
- }
-
- //Get period month
- entity = entity_child (schedule, "period_months");
- if (entity == NULL)
- {
- ent->setPeriodMonth (0);
- }
- else
- {
- period_month = entity_text (entity);
- QString t (period_month);
- ent->setPeriodMonth (t.toInt (ok, 10));
-
- }
-
- //Get duration
- entity = entity_child (schedule, "duration");
- if (entity == NULL)
- {
- ent->setDuration (0);
- }
- else
- {
- duration = entity_text (entity);
- QString t (duration);
- ent->setDuration (t.toLongLong (ok, 10));
- }
-
- //Get in_use
- entity = entity_child (schedule, "in_use");
- if (entity == NULL)
- {
- ent->setInUse (0);
- }
- else
- {
- inUse = entity_text (entity);
- QString t (inUse);
- ent->setInUse (t.toInt (ok, 10));
- }
-
- model->addSchedule (ent, i);
- i++;
- }
- schedules_m = next_entities (schedules_m);
- }
- return 0;
-}
Deleted: trunk/gsa-desktop/src/omp_update_schedules.h
===================================================================
--- trunk/gsa-desktop/src/omp_update_schedules.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_update_schedules.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,53 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- */
-
-/**
- * @file omp_update_schedules.h
- * @brief Protos and data structures for omp_update_schedules.
- */
-
-#ifndef OMP_UPDATE_SCHEDULES_H
-#define OMP_UPDATE_SCHEDULES_H
-
-#include "omp_update.h"
-#include "omp_update_schedules.h"
-#include "model_schedule.h"
-
-class omp_update_schedules : public omp_update
-{
- private:
- model_schedule *model;
-
- entity_t schedules;
-
- public:
- omp_update_schedules();
-
- ~omp_update_schedules();
-
- void setModel (model_schedule *model);
- virtual void run ();
- int update ();
-};
-
-#endif
Deleted: trunk/gsa-desktop/src/omp_update_status.cpp
===================================================================
--- trunk/gsa-desktop/src/omp_update_status.cpp 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_update_status.cpp 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,414 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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 "omp_update_status.h"
-
-/**
- * @file omp_update_status.cpp
- * @brief Thread to update the taskstatus
- *
- * Implements the functionality to update the taskstatus.
- * Inherits basic omp- and threadfunctionalty from omp_updater
- */
-
-omp_update_status::omp_update_status ()
-{
-}
-
-
-omp_update_status::~omp_update_status ()
-{
-}
-
-/**
- * @brief Starting point for the thread
- *
- * Starts an update for the taskstatus and repeats in a userdefined interval.
- * Sends the signals sig_started_update (), sig_finished_update () and
- * sig_trigger_update () through the helper omp_update_helper.
- */
-void
-omp_update_status::run ()
-{
- mutex->lock ();
-
- helper->log (tr ("Task update: Thread started."), 5);
-
- while (true)
- {
- helper->startedupdate();
- int ret = this->connectToServer (this->credentials->getServerAddress (),
- this->credentials->getServerPort ());
- if (ret == 0)
- {
- omp_get_status (& (session), NULL, 0, &status);
- helper->log (tr ("Update running..."), 6);
- update ();
- helper->log (tr ("Update finished!"), 6);
- openvas_server_close (this->socket, session);
- }
- else
- {
- helper->log (tr ("Connection failed: %1").arg (ret), 4);
- helper->failedupdate (ret);
- helper->log (tr ("Terminating update thread."), 5);
- return;
- }
- if (!this->running)
- {
- helper->log (tr ("Terminating update thread."), 5);
- helper->finishedupdate();
- mutex->unlock();
- return;
- }
- helper->finishedupdate();
- helper->triggerupdate();
- QThread::sleep (interval);
- if (!this->running)
- {
- helper->log (tr ("Terminating update thread."), 5);
- mutex->unlock();
- return;
- }
- }
-}
-
-/**
- * @brief Setter
- *
- * Sets the Model in which the statusdata should be stored in
- *
- * @param m: Model for statusdataview
- */
-void
-omp_update_status::setModel (model_task *m)
-{
- model = m;
-}
-
-
-/**
- * @brief Taskstatus update
- *
- * This function extracts the statusdata of the OpenVAS Manager response and
- * sets it to the given model.
- *
- * @return 0
- */
-int
-omp_update_status::update()
-{
- int i = 0;
- entity_t task;
- entities_t tasks = status->entities;
-
- while (task = first_entity (tasks))
- {
- if(strcmp (entity_name (task), "task") == 0)
- {
- omp_entity_status *ent = new omp_entity_status ();
- entity_t entity;
- const char *id, *name, *stat, *progress, *report_count,
- *first_report, *last_report, *trend, *schedule, *threat;
- bool *ok = false;
-
- id = entity_attribute (task, "id");
- ent->setId (id);
-
- //Get the Taskname, set to unkown if empty
- entity = entity_child (task, "name");
- if (entity == NULL)
- {
- ent->setName ("unknown");
- }
- else
- {
- name = entity_text (entity);
- ent->setName (name);
- }
-
- //Get the Taskstatus, set to TASK_ERROR if empty
- entity = entity_child (task, "status");
- if (entity == NULL)
- {
- ent->setStatus (omp_entity_status::TASK_ERROR);
- }
- else
- {
- stat = entity_text (entity);
- if (strcmp (stat, "Delete Requested") == 0)
- {
- ent->setStatus (omp_entity_status::TASK_DELREQUESTED);
- }
- else if (strcmp (stat, "Done") == 0)
- {
- ent->setStatus (omp_entity_status::TASK_DONE);
- }
- else if (strcmp (stat, "New") == 0)
- {
- ent->setStatus (omp_entity_status::TASK_NEW);
- }
- else if (strcmp (stat, "Requested") == 0)
- {
- ent->setStatus (omp_entity_status::TASK_REQUESTED);
- }
- else if (strcmp (stat, "Running") == 0)
- {
- ent->setStatus (omp_entity_status::TASK_ACTIVE);
- }
- else if (strcmp (stat, "Stop Requested") == 0)
- {
- ent->setStatus (omp_entity_status::TASK_STOPREQUESTED);
- }
- else if (strcmp (stat, "Stopped") == 0)
- {
- ent->setStatus (omp_entity_status::TASK_STOPPED);
- }
- else if (strcmp (stat, "Internal Error") == 0)
- {
- ent->setStatus (omp_entity_status::TASK_ERROR);
- }
- else
- {
- ent->setStatus (omp_entity_status::TASK_ERROR);
- }
- }
-
- //Get Taskprogress, set to -1 if empty
- entity = entity_child (task, "progress");
- if (entity == NULL)
- {
- ent->setProgress (-1);
- }
- else
- {
- progress = entity_text (entity);
- QString p (progress);
- int pint = p.toInt(ok, 10);
- if (pint > -1)
- {
- ent->setProgress (pint);
- }
- else
- {
- ent->setProgress (-1);
- }
- }
-
- //Get Reportcount, set to 0 if empty
- entity_t report_c = entity_child (task, "report_count");
- if (report_c == NULL)
- {
- ent->setReportCount (0);
- }
- else
- {
- entity = entity_child (report_c, "finished");
- if (entity == NULL)
- {
- ent->setReportCount (0);
- }
- else
- {
- report_count = entity_text (entity);
- QString rc (report_count);
- bool *ok = false;
- ent->setReportCount ( rc.toInt(ok, 10));
- }
- }
-
- //get Timestamp of first report
- entity = entity_child (task, "first_report");
- if (entity == NULL)
- {
- ent->setFirstReport ("");
- }
- else
- {
- entity_t report = entity_child (entity, "report");
- entity_t time = entity_child (report, "timestamp");
- if (time == NULL)
- {
- ent->setFirstReport ("");
- }
- else
- {
- first_report = entity_text (time);
- QString t (first_report);
- ent->setFirstReport (t);
- }
- }
-
- //Get Timestamp of last report
- entity = entity_child (task, "last_report");
- if (entity == NULL)
- {
- ent->setFirstReport ("");
- }
- else
- {
- entity_t report = entity_child (entity, "report");
- entity_t time = entity_child (report, "timestamp");
- if (time == NULL)
- {
- ent->setFirstReport ("");
- }
- else
- {
- last_report = entity_text (time);
- QString t (last_report);
- ent->setLastReport (t);
- }
- }
-
- //Get Trend, set to TREND_NONE if empty
- entity = entity_child (task, "trend");
- if (entity == NULL)
- {
- ent->setTrend (omp_entity_status::TREND_NONE);
- }
- else
- {
- trend = entity_text (entity);
- if (strcmp (trend, "same") == 0)
- {
- ent->setTrend (omp_entity_status::TREND_NOCHANGE);
- }
- else if (strcmp (trend, "more") == 0)
- {
- ent->setTrend (omp_entity_status::TREND_NBRINCREASED);
- }
- else if (strcmp (trend, "up") == 0)
- {
- ent->setTrend (omp_entity_status::TREND_LVLINCREASED);
- }
- else if (strcmp (trend, "less") == 0)
- {
- ent->setTrend (omp_entity_status::TREND_NBRDECREASED);
- }
- else if (strcmp (trend, "down") == 0)
- {
- ent->setTrend (omp_entity_status::TREND_LVLDECREASED);
- }
- else
- {
- ent->setTrend (omp_entity_status::TREND_NONE);
- }
- }
-
- //Get ScheduleId
- entity = entity_child (task, "schedule");
- if (entity == NULL)
- {
- ent->setFirstReport ("");
- }
- else
- {
- schedule = entity_attribute (entity, "id");
- ent->setScheduleId (schedule);
- }
-
-
- //Get Taskthreat, set to NONE if empty
- entity = entity_child (task, "messages");
- if (entity == NULL)
- {
- ent->setThreat (omp_entity_status::THREAT_NONE);
- }
- else
- {
- int t_hole = 0, t_warn = 0, t_low = 0;
-
- entity_t hole = entity_child (entity, "hole");
- if (hole == NULL)
- {
- ent->setThreat (omp_entity_status::THREAT_NONE);
- }
- else
- {
- threat = entity_text (hole);
- QString t (threat);
- t_hole = t.toInt (ok, 10);
- }
-
- entity_t warn = entity_child (entity, "warning");
- if (warn == NULL)
- {
- ent->setThreat (omp_entity_status::THREAT_NONE);
- }
- else
- {
- threat = entity_text (warn);
- QString t (threat);
- t_warn = t.toInt (ok, 10);
- }
- entity_t low = entity_child (entity, "low");
- if (low == NULL)
- {
- ent->setThreat (omp_entity_status::THREAT_NONE);
- }
- else
- {
- threat = entity_text (low);
- QString t (threat);
- t_low = t.toInt (ok, 10);
- }
- ent->setThreat (calcThreat(t_hole, t_warn, t_low));
- }
- model->addTask(ent, i);
- i++;
- }
- tasks = next_entities (tasks);
- }
- return 0;
-}
-
-/**
- * @brief Threatcalculation
- *
- * Calculates the enumeration for the threat
- *
- * @param hole: number of holes for a task
- * @param warning: number of warnings for a task
- * @param info: number of infos for a task
- */
-omp_entity_status::Threat
-omp_update_status::calcThreat (int hole, int warning, int info)
-{
- if (hole > 0)
- {
- return omp_entity_status::THREAT_HIGH;
- }
- else if (warning > 0)
- {
- return omp_entity_status::THREAT_MEDIUM;
- }
- else if (info > 0)
- {
- return omp_entity_status::THREAT_LOW;
- }
- else
- {
- return omp_entity_status::THREAT_NONE;
- }
-}
\ No newline at end of file
Deleted: trunk/gsa-desktop/src/omp_update_status.h
===================================================================
--- trunk/gsa-desktop/src/omp_update_status.h 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/omp_update_status.h 2010-06-09 16:24:05 UTC (rev 7986)
@@ -1,56 +0,0 @@
-/**
- * Copyright:
- * Copyright (C) 2010 by Greenbone Networks GmbH
- *
- * Authors:
- * Raimund Renkert <raimund.renkert at intevation.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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.
- */
-
-/**
- * @file omp_update_status.h
- * @brief Protos and data structures for omp_update_status.
- */
-#ifndef OMP_UPDATE_STATUS_H
-#define OMP_UPDATE_STATUS_H
-
-#include <QtGui>
-
-#include "omp_update.h"
-#include "omp_update_helper.h"
-#include "model_task.h"
-#include "omp_entity_status.h"
-
-class omp_update_status : public omp_update
-{
- private:
- model_task *model;
-
- entity_t status;
-
- omp_entity_status::Threat calcThreat (int hole, int warning, int info);
-
- public:
- omp_update_status ();
- ~omp_update_status ();
-
- void setModel (model_task *model);
-
- virtual void run ();
- int update ();
-};
-#endif
\ No newline at end of file
Modified: trunk/gsa-desktop/src/src.pro
===================================================================
--- trunk/gsa-desktop/src/src.pro 2010-06-09 16:07:24 UTC (rev 7985)
+++ trunk/gsa-desktop/src/src.pro 2010-06-09 16:24:05 UTC (rev 7986)
@@ -5,7 +5,11 @@
DEPENDPATH += . img
if ($${CROSS_ENV}) {
CROSS_ENV = /usr/
+ WIN_LIB = ""
}
+else {
+ WIN_LIB = -lintl -liconv -lpthread -lgthread-2.0
+}
if ($${INCLUDE_DIR}) {
INCLUDE_DIR = /usr/local/include
}
@@ -19,7 +23,7 @@
LIBS += -L$${LIB_DIR} \
-L$${CROSS_ENV}/lib -lopenvas_misc \
-lopenvas_base -lopenvas_omp -lgpg-error -lglib-2.0 -lgnutls \
- -lgcrypt
+ -lgcrypt $${WIN_LIB}
# Input
HEADERS += gsa_desktop_cfg.h \
gsa_desktop_control.h \
@@ -27,24 +31,21 @@
entity_defines.h \
omp_connector.h \
omp_credentials.h \
- omp_entity_status.h \
- omp_entity_schedule.h \
omp_commands.h \
omp_basic.h \
omp_update_helper.h \
omp_update.h \
- omp_update_status.h \
- omp_update_schedules.h \
+ omp_update_entity.h \
delegate_progress.h \
- model_task.h \
- model_schedule.h \
+ model_omp_entity.h \
delegate_threat.h \
delegate_trend.h \
delegate_icon.h \
+ delegate_date_time.h \
gsa_desktop_ui.h \
dlg_about.h \
- dock_logging.h \
- dock_table.h
+ dock_table.h \
+ dock_logging.h
FORMS += dlg_login.ui gsa_desktop_mainwindow.ui \
dlg_about.ui dock_logging.ui dock_table.ui
SOURCES += gsa_desktop_cfg.cpp \
@@ -55,19 +56,18 @@
omp_credentials.cpp \
omp_update_helper.cpp \
omp_update.cpp \
- omp_update_status.cpp \
- omp_update_schedules.cpp \
+ omp_update_entity.cpp \
delegate_progress.cpp \
- model_task.cpp \
- model_schedule.cpp \
+ model_omp_entity.cpp \
delegate_threat.cpp \
delegate_trend.cpp \
delegate_icon.cpp \
+ delegate_date_time.cpp \
gsa_desktop_ui.cpp \
omp_commands.cpp \
omp_basic.cpp \
dlg_about.cpp \
- dock_logging.cpp \
- dock_table.cpp
+ dock_table.cpp \
+ dock_logging.cpp
RESOURCES += img/images.qrc
TRANSLATIONS = translations/gsa_desktop_de.ts
More information about the Openvas-commits
mailing list