[Openvas-commits] r7147 - in trunk/gsa-desktop: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Mar 26 17:20:09 CET 2010
Author: raimund
Date: 2010-03-26 17:20:09 +0100 (Fri, 26 Mar 2010)
New Revision: 7147
Added:
trunk/gsa-desktop/src/gsa_desktop_ui.cpp
trunk/gsa-desktop/src/gsa_desktop_ui.h
Modified:
trunk/gsa-desktop/ChangeLog
Log:
* src/gsa_desktop_ui.cpp, src/gsa_desktop_ui.h: New.
Modified: trunk/gsa-desktop/ChangeLog
===================================================================
--- trunk/gsa-desktop/ChangeLog 2010-03-26 14:26:56 UTC (rev 7146)
+++ trunk/gsa-desktop/ChangeLog 2010-03-26 16:20:09 UTC (rev 7147)
@@ -1,3 +1,7 @@
+2010-03-26 Raimund Renkert <raimund.renkert at intevation.de>
+
+ * src/gsa_desktop_ui.cpp, src/gsa_desktop_ui.h: New.
+
2010-03-26 Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
First code. All developed by
Added: trunk/gsa-desktop/src/gsa_desktop_ui.cpp
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_ui.cpp 2010-03-26 14:26:56 UTC (rev 7146)
+++ trunk/gsa-desktop/src/gsa_desktop_ui.cpp 2010-03-26 16:20:09 UTC (rev 7147)
@@ -0,0 +1,906 @@
+/**
+ * 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 "gsa_desktop_ui.h"
+
+/**
+ * @file gsa_desktop_ui.cpp
+ * @brief The GSA-Desktop main ui
+ *
+ * This file contains the design for GSA-Desktop mainwindow and holds the used
+ * dialogs.
+ */
+
+/**
+ * @brief Set up the mainwindow
+ *
+ * Creates the mainwindow and the nessesary delegates for the taskview.
+ * Configures the signal/slot connections for userinteraction
+ */
+gsa_desktop_ui::gsa_desktop_ui()
+{
+ setupUi (this);
+
+ //Dialogs
+ login = new dlg_login ();
+ about = new dlg_about ();
+
+ //Models
+ taskModel = new model_task ();
+
+ //Delegates
+ taskProgress = new delegate_progress ();
+ trendIcon = new delegate_trend ();
+ threatIcon = new delegate_threat ();
+
+ //Timer
+ progressUpdateTimer = new QTimer();
+
+ //create and modify UI
+ createUpdateWidget ();
+ createToolBars();
+ createStatusBar();
+ createConnections();
+ modifyWidgets();
+
+ //Initialization
+ selectedTask = -1;
+}
+
+
+gsa_desktop_ui::~gsa_desktop_ui ()
+{
+}
+
+
+/**
+ * @brief Creates and configures Toolbars
+ */
+void
+gsa_desktop_ui::createToolBars ()
+{
+ QToolBar *toolRefresh = addToolBar (tr ("Refresh Bar"));
+ QSizePolicy sizePolicy1 (QSizePolicy::Expanding, QSizePolicy::Expanding);
+ sizePolicy1.setHorizontalStretch (30);
+ sizePolicy1.setVerticalStretch (30);
+ sizePolicy1.setHeightForWidth (toolBar->sizePolicy ().hasHeightForWidth ());
+ toolRefresh->setSizePolicy (sizePolicy1);
+ toolRefresh->setMinimumSize (QSize(0, 0));
+ toolRefresh->setSizeIncrement (QSize(28, 28));
+ toolRefresh->setBaseSize (QSize (28, 28));
+ toolRefresh->setIconSize (QSize (18, 18));
+ toolRefresh->setToolButtonStyle (Qt::ToolButtonTextUnderIcon);
+ toolRefresh->addAction (actionRefresh);
+ toolRefresh->addSeparator ();
+ this->addToolBar (Qt::TopToolBarArea, toolBar);
+
+ QIcon icon;
+ icon.addPixmap (QPixmap (QString::fromUtf8 (":/img/refresh.png")),
+ QIcon::Normal, QIcon::Off);
+
+ tb_startUpdate = new QToolButton ();
+ tb_startUpdate->setObjectName (QString::fromUtf8 ("tb_startUpdate"));
+ tb_startUpdate->setEnabled (true);
+ tb_startUpdate->setGeometry (QRect (220, 2, 26, 26));
+ tb_startUpdate->setIcon (icon);
+
+#ifndef QT_NO_TOOLTIP
+ tb_startUpdate->setToolTip (QApplication::translate ("MainWindow",
+ "Start Updates", 0, QApplication::UnicodeUTF8));
+#endif // QT_NO_TOOLTIP
+
+ tb_startUpdate->setText (QApplication::translate ("MainWindow", "...", 0,
+ QApplication::UnicodeUTF8));
+
+ actionRun->setDisabled (true);
+ actionStop->setDisabled (true);
+ actionDelete->setDisabled (true);
+ actionRefresh->setDisabled (true);
+ actionLogout->setDisabled (true);
+ tb_set_refresh->setDisabled (true);
+
+ menuAdministration->setEnabled (false);
+ menuConfiguration->setEnabled (false);
+ actionContents->setVisible (false);
+ actionReport->setVisible (false);
+ actionCreate_Task->setVisible (false);
+
+#ifdef UPCOMING_FEATURES
+ menuAdministration->setEnabled (true);
+ menuConfiguration->setEnabled (true);
+ actionContents->setVisible (true);
+ actionReport->setVisible (true);
+ actionCreate_Task->setVisible (true);
+#endif
+}
+
+
+/**
+ * @brief Creates and configures the statusbar
+ */
+void
+gsa_desktop_ui::createStatusBar ()
+{
+ la_stat_update = new QLabel ();
+ la_stat_update->setObjectName (QString::fromUtf8 ("la_prog_update"));
+ la_stat_update->setGeometry (QRect(500, 2, 58, 26));
+ la_stat_update->setText (QApplication::translate ("MainWindow",
+ "Refresh interval:" , 0,
+ QApplication::UnicodeUTF8));
+ la_val_update = new QLabel ();
+ la_val_update->setObjectName (QString::fromUtf8 ("la_prog_update"));
+ la_val_update->setGeometry (QRect (500, 2, 58, 26));
+ la_val_update->setText (QApplication::translate ("MainWindow",
+ "<b>manual</b>", 0, QApplication::UnicodeUTF8));
+
+ statusBar ()->addPermanentWidget (la_stat_update);
+ statusBar ()->addPermanentWidget (la_val_update);
+
+}
+
+
+/**
+ * @brief Creates and configures the update widget
+ */
+void
+gsa_desktop_ui::createUpdateWidget ()
+{
+ dockWidgetContents_update = new QWidget ();
+
+ //Label
+ la_update = new QLabel (dockWidgetContents_update);
+ la_update->setObjectName (QString::fromUtf8 ("la_update"));
+ la_update->setGeometry (QRect (10, 0, 88, 30));
+ la_update->setText (QApplication::translate ("MainWindow",
+ "Refresh Interval:", 0, QApplication::UnicodeUTF8));
+
+ la_sec = new QLabel (dockWidgetContents_update);
+ la_sec->setObjectName (QString::fromUtf8 ("la_sec"));
+ la_sec->setGeometry (QRect (184, 2, 48, 26));
+ la_sec->setText (QApplication::translate ("MainWindow", " sec", 0,
+ QApplication::UnicodeUTF8));
+
+ la_prog_update = new QLabel ();
+ la_prog_update->setObjectName (QString::fromUtf8 ("la_prog_update"));
+ la_prog_update->setGeometry (QRect (500, 2, 58, 26));
+ la_prog_update->setText (QApplication::translate ("MainWindow",
+ "Next Refresh: " ,0, QApplication::UnicodeUTF8));
+
+ //Spinbox
+ sb_update = new QSpinBox (dockWidgetContents_update);
+ sb_update->setObjectName (QString::fromUtf8 ("sb_update"));
+ sb_update->setGeometry (QRect (110, 2, 63, 26));
+ sb_update->setMinimum (0);
+ sb_update->setMaximum (60);
+ sb_update->setSingleStep (10);
+ sb_update->setValue (0);
+ sb_update->setMaximumSize (40, 30);
+
+ //Toolbutton
+ tb_set_refresh = new QToolButton (dockWidgetContents_update);
+ tb_set_refresh->setObjectName (QString::fromUtf8 ("tb_set_refresh"));
+ tb_set_refresh->setEnabled (true);
+ tb_set_refresh->setMinimumHeight (26);
+ tb_set_refresh->setText (QApplication::translate ("MainWindow",
+ "Apply Interval", 0, QApplication::UnicodeUTF8));
+
+ tb_stop_refresh = new QToolButton (dockWidgetContents_update);
+ tb_stop_refresh->setObjectName (QString::fromUtf8 ("tb_stop_refresh"));
+ tb_stop_refresh->setEnabled (false);
+ tb_stop_refresh->setMinimumHeight(26);
+ tb_stop_refresh->setText (QApplication::translate ("MainWindow",
+ "Stop Interval", 0, QApplication::UnicodeUTF8));
+
+ //Progressbar
+ pbar_update = new QProgressBar ();
+ pbar_update->setObjectName(QString::fromUtf8 ("pbar_update"));
+ pbar_update->setGeometry (QRect(560, 4, 118, 23));
+ pbar_update->setValue (0);
+ pbar_update->setAlignment (Qt::AlignCenter);
+ pbar_update->setInvertedAppearance (false);
+ pbar_update->setTextDirection (QProgressBar::TopToBottom);
+ pbar_update->setMaximumHeight (14);
+ pbar_update->setMinimumWidth (100);
+ pbar_update->setMaximumWidth (140);
+ pbar_update->setFormat (QApplication::translate ("MainWindow", "manual", 0,
+ QApplication::UnicodeUTF8));
+#ifndef QT_NO_TOOLTIP
+ pbar_update->setToolTip (QApplication::translate ("MainWindow",
+ "Refresh Progress", 0, QApplication::UnicodeUTF8));
+#endif // QT_NO_TOOLTIP
+
+ //Dockwidget
+ dw_update = new QDockWidget (this);
+ QSizePolicy sizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
+ sizePolicy.setHorizontalStretch (0);
+ sizePolicy.setVerticalStretch (0);
+ dw_update->setSizePolicy (sizePolicy);
+ sizePolicy.setHeightForWidth (dw_update->sizePolicy ().hasHeightForWidth ());
+ dw_update->setObjectName (QString::fromUtf8 ("dw_update"));
+ dw_update->setAutoFillBackground (true);
+ dw_update->setFloating (false);
+ dw_update->setFeatures (QDockWidget::DockWidgetFloatable|
+ QDockWidget::DockWidgetMovable|
+ QDockWidget::DockWidgetClosable);
+ dw_update->setAllowedAreas (Qt::AllDockWidgetAreas);
+ dw_update->setMinimumSize (QSize (40, 50));
+ dw_update->setContextMenuPolicy (Qt::NoContextMenu);
+ dw_update->setWindowTitle (QApplication::translate ("MainWindow",
+ "Refresh Settings", 0, QApplication::UnicodeUTF8));
+ dw_update->setWidget (dockWidgetContents_update);
+
+
+ //Dockwidgetcontent
+ dockWidgetContents_update->setObjectName (QString::fromUtf8
+ ("dockWidgetContents_update"));
+
+ //Dockwidgetlayout
+ updateLayout = new QGridLayout (dockWidgetContents_update);
+ updateLayout->setObjectName (QString::fromUtf8 ("updateLayout"));
+ updateLayout->addWidget (la_update,0,0,1,2);
+ updateLayout->addWidget (la_sec,0,3,1,1);
+ updateLayout->addWidget (pbar_update,3,2,1,2);
+ updateLayout->addWidget (sb_update,0,2,1,1);
+ 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);
+ updateLayout->setRowStretch (0,0);
+ updateLayout->setRowStretch (1,0);
+ updateLayout->setRowStretch (2,1);
+ updateLayout->setRowStretch (3,0);
+ updateLayout->setColumnStretch (0,0);
+ updateLayout->setColumnStretch (1,0);
+ updateLayout->setColumnStretch (2,0);
+ updateLayout->setColumnStretch (3,0);
+ updateLayout->setColumnStretch (4,1);
+
+ this->addDockWidget (static_cast<Qt::DockWidgetArea> (1), dw_update);
+ dw_update->hide ();
+}
+
+
+/**
+ * @brief Configures signal/slot connections
+ */
+void
+gsa_desktop_ui::createConnections ()
+{
+ connect (actionQuit, SIGNAL (triggered (bool)),this, SLOT (close ()));
+ connect (actionLogin, SIGNAL (triggered (bool)), this,
+ SLOT (login_dlg ()));
+ connect (login, SIGNAL (accepted ()), this, SLOT (loginData ()));
+ connect (actionLogout, SIGNAL (triggered (bool)), this, SLOT (logout ()));
+ connect (actionRefresh, SIGNAL (triggered (bool)), this,
+ SLOT (refresh_once ()));
+ connect (login, SIGNAL (sig_profile_selected (QString)), this,
+ SLOT (profile_update (QString)));
+ connect (login, SIGNAL (sig_save_profile (QString, omp_credentials&)), this,
+ SLOT (profile_save (QString, omp_credentials&)));
+ connect (login, SIGNAL (sig_remove_profile (QString)), this,
+ SLOT (profile_remove (QString)));
+ connect (progressUpdateTimer, SIGNAL (timeout()), this,
+ SLOT (progress_timeout ()));
+ connect (actionRun, SIGNAL (triggered (bool)), this, SLOT (task_start ()));
+ connect (actionStop, SIGNAL (triggered (bool)), this, SLOT (task_stop ()));
+ connect (actionDelete, SIGNAL (triggered (bool)), this,
+ SLOT (task_delete ()));
+ connect (actionAbout, SIGNAL (triggered (bool)), this,
+ SLOT (about_dlg ()));
+ connect (actionRefresh_settings, SIGNAL (triggered (bool)), this,
+ SLOT (refresh_dw ()));
+ connect (tb_set_refresh, SIGNAL (released ()), this, SLOT (refresh ()));
+ connect (tb_stop_refresh, SIGNAL (released ()), this,
+ SLOT (refresh_manualstop ()));
+}
+
+
+/**
+ * @brief Modifies Widgets and configures signal/slot connections
+ *
+ * Modifies the taskview, to set up the header and connects signal/slots for
+ * taskselection and contextmenu
+ */
+void
+gsa_desktop_ui::modifyWidgets ()
+{
+ //Tableview
+ tw_tasks->setModel (taskModel);
+ tw_tasks->setItemDelegateForColumn (1, taskProgress);
+ tw_tasks->setItemDelegateForColumn (5, threatIcon);
+ tw_tasks->setItemDelegateForColumn (6, trendIcon);
+ tw_tasks->verticalHeader ()->setVisible (false);
+ tw_tasks->horizontalHeader ()->setHighlightSections (false);
+ tw_tasks->horizontalHeader ()->setResizeMode (QHeaderView::Fixed);
+ tw_tasks->horizontalHeader ()->setResizeMode (0, QHeaderView::Stretch);
+ tw_tasks->setColumnWidth (0, 120);
+ tw_tasks->setColumnWidth (1, 120);
+ tw_tasks->setColumnWidth (2, 60);
+ tw_tasks->setColumnWidth (3, 160);
+ tw_tasks->setColumnWidth (4, 160);
+ tw_tasks->setColumnWidth (5, 66);
+ tw_tasks->setColumnWidth (6, 60);
+ tw_tasks->horizontalHeader ()->setMinimumSectionSize (75);
+ tw_tasks->setContextMenuPolicy (Qt::CustomContextMenu);
+
+ connect (tw_tasks->selectionModel (),
+ SIGNAL (currentChanged (const QModelIndex&, const QModelIndex &)),
+ this, SLOT (task_selectionchanged (const QModelIndex &,
+ const QModelIndex &)));
+ connect (tw_tasks, SIGNAL (customContextMenuRequested (const QPoint &)),
+ this, SLOT (task_contextmenu (const QPoint &)));
+}
+
+/**
+ * @brief SLOT to get the logindata from the logindialog
+ *
+ * Emits sig_credentials (...)
+ */
+void
+gsa_desktop_ui::loginData ()
+{
+ int val = login->result ();
+ if (val == QDialog::Accepted)
+ {
+ QString *q = new QString ("Please enter: \n");
+ bool *test= false, error = false;
+ if (login->getAddress () == NULL)
+ {
+ q->append (" - Serveraddress \n");
+ error = true;
+ }
+ if (login->getPort () == NULL)
+ {
+ q->append (" - Serverport \n");
+ error = true;
+ }
+ if (login->getUsername () == NULL)
+ {
+ q->append (" - Username \n");
+ error = true;
+ }
+ if (login->getPassword () == NULL)
+ {
+ q->append (" - Password \n");
+ error = true;
+ }
+ if (error)
+ {
+ QMessageBox::question (this, tr ("Connection failed..."),
+ *q, tr ("&Ok"), QString (), 0, 1 );
+ return;
+ }
+ else
+ {
+ emit sig_credentials(login->getAddress (),
+ login->getPort ().toInt (test, 10),
+ login->getUsername (), login->getPassword ());
+
+ //modify UI
+ QString statustext (tr ("Logged in as: <b>%1</b> at <b>%2:%3</b>")
+ .arg (login->getUsername ())
+ .arg (login->getAddress ())
+ .arg (login->getPort ()));
+ statuslabel = new QLabel ();
+ statuslabel->setFrameShape (QLabel::NoFrame);
+ statuslabel->setText (statustext);
+ statusbar->addWidget (statuslabel);
+ actionRefresh->setDisabled (false);
+ tb_set_refresh->setDisabled(false);
+ actionLogout->setDisabled (false);
+ actionLogin->setDisabled (true);
+ }
+ }
+}
+
+
+/**
+ * @brief SLOT that removes all Tasks, deletes logindata and disables buttons
+ */
+void
+gsa_desktop_ui::logout ()
+{
+ taskModel->removeTasks ();
+ selectedTask = -1;
+ statusbar->removeWidget (statuslabel);
+ emit sig_logout ();
+
+ //modify UI
+ actionRun->setDisabled (true);
+ actionStop->setDisabled (true);
+ actionDelete->setDisabled (true);
+ actionRefresh->setDisabled (true);
+ actionLogout->setDisabled (true);
+ actionLogin->setDisabled (false);
+ tb_set_refresh->setDisabled (true);
+}
+
+
+/**
+ * @brief SLOT that is used to refresh the taskview
+ *
+ * Emits sig_req_status () to start a taskupdate.
+ */
+void
+gsa_desktop_ui::refresh ()
+{
+ updateInterval = sb_update->value ();
+ if (updateInterval == 0)
+ {
+ la_val_update->setText (QApplication::translate ("MainWindow",
+ "<b>manual</b>",0 , QApplication::UnicodeUTF8));
+ pbar_update->setFormat (QApplication::translate ("MainWindow", "manual",
+ 0, QApplication::UnicodeUTF8));
+ tb_stop_refresh->setDisabled (true);
+ emit sig_stop_taskupdate ();
+ }
+ else
+ {
+ tb_stop_refresh->setEnabled (true);
+ la_val_update->setText (QApplication::translate ("MainWindow",
+ "<b>%1 seconds </b>",0 ,
+ QApplication::UnicodeUTF8).arg (updateInterval));
+ tb_stop_refresh->setDisabled (false);
+ emit sig_req_status (updateInterval);
+ }
+}
+
+
+/**
+ * @brief SLOT that is used to refresh the taskview once
+ *
+ * Emits sig_req_status () to start a taskupdate.
+ */
+void
+gsa_desktop_ui::refresh_once ()
+{
+ emit sig_req_status (0);
+}
+
+
+/**
+ * @brief SLOT that is used to start or stop the taskview update
+ *
+ * Emits sig_req_status_toggle () to start or stop a taskupdate.
+ */
+void
+gsa_desktop_ui::refresh_toggle ()
+{
+ updateInterval = sb_update->value ();
+ if (updateInterval > 0)
+ emit sig_req_status_toggle (sb_update->value ());
+}
+
+
+/**
+ * @brief SLOT that manipulates UI if task update is stopped
+ */
+void
+gsa_desktop_ui::refresh_stop ()
+{
+ progressUpdateTimer->stop ();
+ pbar_update->setValue (0);
+}
+
+
+/**
+ * @brief SLOT to stop all task updates
+ *
+ * Emits sig_stop_taskupdate ()
+ */
+void
+gsa_desktop_ui::refresh_manualstop ()
+{
+ la_val_update->setText (QApplication::translate ("MainWindow",
+ "<b>manual</b>", 0,
+ QApplication::UnicodeUTF8));
+ pbar_update->setFormat (QApplication::translate ("MainWindow", "manual",
+ 0, QApplication::UnicodeUTF8));
+ sb_update->setValue(0);
+ tb_stop_refresh->setDisabled (true);
+ emit sig_stop_taskupdate ();
+}
+
+
+/**
+ * @brief Getter
+ *
+ * @return The model containing the tasks
+ */
+model_task*
+gsa_desktop_ui::getTableModel ()
+{
+ return taskModel;
+}
+
+
+/**
+ * @brief SLOT that starts the login dialog
+ *
+ * Emits sig_login_dlg ()
+ */
+void
+gsa_desktop_ui::login_dlg ()
+{
+ emit sig_login_dlg ();
+ login->exec ();
+}
+
+
+/**
+ * @brief SLOT that starts the about dialog
+ */
+void
+gsa_desktop_ui::about_dlg ()
+{
+ about->exec ();
+}
+
+
+/**
+ * @brief SLOT that starts the update dockwidget
+ */
+void
+gsa_desktop_ui::refresh_dw ()
+{
+ dw_update->show ();
+}
+
+
+/**
+ * @brief SLOT to set the profile data to the login dialog combobar
+ *
+ * @param name: Profile name
+ * @param position: Position in the combobar
+ */
+void
+gsa_desktop_ui::setProfiletoCB (QString name, int position)
+{
+ login->setProfile (name, position);
+}
+
+
+/**
+ * @brief SLOT to update the login dialog profile data
+ *
+ * Emits sig_update_profile (...)
+ *
+ * @param name: Profile name
+ */
+void
+gsa_desktop_ui::profile_update (QString name)
+{
+ emit sig_update_profile (name);
+}
+
+
+/**
+ * @brief Setter
+ *
+ * Sets profile data to the login dialog textfields
+ *
+ * @param crd: logindata
+ */
+void
+gsa_desktop_ui::setProfileData (omp_credentials &crd)
+{
+ login->setAddress (crd.getServerAddress ());
+ login->setPort (crd.getServerPort ());
+ login->setUsername (crd.getUserName ());
+}
+
+
+/**
+ * @brief SLOT to save the currently shown logindata of the logindialog
+ *
+ * Emits sig_save_profile (...)
+ *
+ * @param name: Profilename
+ * @param crd: logindata
+ */
+void
+gsa_desktop_ui::profile_save (QString name, omp_credentials& crd)
+{
+ emit sig_save_profile (name, crd);
+}
+
+
+/**
+ * @brief SLOT to remove currently shown profile of the logindialog
+ *
+ * Emits sig_remove_profile (...)
+ *
+ * @param name: Profilename
+ */
+void
+gsa_desktop_ui::profile_remove (QString name)
+{
+ emit sig_remove_profile (name);
+}
+
+
+/**
+ * @brief SLOT to update the progessbar connected to the taskupdate
+ */
+void
+gsa_desktop_ui::progress_timeout ()
+{
+ int p = pbar_update->value ();
+ pbar_update->setValue ( ++p );
+ int format_value = pbar_update->maximum () - p;
+ QString form;
+ form.setNum (format_value);
+ form.append (tr (" sec"));
+ pbar_update->setFormat (form);
+}
+
+
+/**
+ * @brief SLOT to synchronize the progressbar with taskupdates
+ */
+void
+gsa_desktop_ui::taskupdate_triggered ()
+{
+ pbar_update->setValue (0);
+ pbar_update->setMaximum (updateInterval);
+ QString form;
+ form.setNum (updateInterval);
+ form.append (tr (" sec"));
+ pbar_update->setFormat (form);
+ progressUpdateTimer->start (1000);
+}
+
+
+/**
+ * @brief SLOT to save the previous selected task on update
+ */
+void
+gsa_desktop_ui::taskupdate_started ()
+{
+ omp_entity_status *ent = new omp_entity_status ();
+ if (selectedTask >= 0)
+ {
+ ent = taskModel->getTask (selectedTask);
+ taskModel->setSelectedTask (ent->getId ());
+ }
+ else
+ {
+ taskModel->setSelectedTask ("");
+ }
+}
+
+
+/**
+ * @brief SLOT to select the previous saved task
+ */
+void gsa_desktop_ui::taskupdate_finished ()
+{
+ //get index of selected task, if no task selected set first as selected
+ int ndx = taskModel->getTask (taskModel->getSelectedTask ());
+ if (taskModel->rowCount () == 0)
+ {
+ return;
+ }
+ if (ndx < 0)
+ {
+ ndx = 0;
+ }
+
+ //prepare selection range, row = index, all columns
+ QModelIndex start;
+ QModelIndex end;
+ start = taskModel->index (ndx, 0, QModelIndex ());
+ end = taskModel->index (ndx, 6, QModelIndex ());
+ QItemSelection sel (start, end);
+
+ //set selection
+ tw_tasks->selectionModel ()->select (sel, QItemSelectionModel::Select);
+ task_selectionchanged (QModelIndex (), QModelIndex ());
+}
+
+
+/**
+ * @brief SLOT that saves the id of the selected task and manipulates the UI
+ *
+ * @param newindex: new selected index
+ * @param oldindex: previous selected index
+ */
+void
+gsa_desktop_ui::task_selectionchanged (const QModelIndex &newindex,
+ const QModelIndex &oldindex)
+{
+ int row = -1;
+ if (newindex.row () < 0 && selectedTask <= 0)
+ {
+ selectedTask = 0;
+ row = 0;
+ }
+ else if (newindex.row () < 0 && selectedTask > 0)
+ {
+ row = selectedTask;
+ }
+ else
+ {
+ row = newindex.row ();
+ selectedTask = newindex.row ();
+ }
+ omp_entity_status *ent = new omp_entity_status ();
+ ent = taskModel->getTask (row);
+ 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)
+ {
+ actionRun->setEnabled (false);
+ actionStop->setEnabled (false);
+ }
+ if (ent->getStatus () == omp_entity_status::TASK_ACTIVE)
+ {
+ actionRun->setEnabled (false);
+ actionStop->setEnabled (true);
+ }
+ actionDelete->setEnabled (true);
+}
+
+/**
+ * @brief SLOT to start runnig a task
+ */
+void
+gsa_desktop_ui::task_start ()
+{
+ omp_entity_status *ent = new omp_entity_status ();
+ if (selectedTask >= 0)
+ {
+ ent = taskModel->getTask(selectedTask);
+ if (ent->getStatus () == omp_entity_status::TASK_NEW ||
+ ent->getStatus () == omp_entity_status::TASK_DONE ||
+ ent->getStatus () == omp_entity_status::TASK_STOPPED)
+ {
+ emit sig_start_task (ent->getId ());
+ emit sig_req_status (0);
+ if (sb_update->value () > 0)
+ {
+ refresh();
+ }
+ actionRun->setDisabled (true);
+ }
+ }
+ else
+ {
+ QMessageBox::information (NULL,tr ("Status Error"),
+ tr ("No Task selected!"));
+ }
+}
+
+
+/**
+ * @brief SLOT to stop a running task
+ */
+void
+gsa_desktop_ui::task_stop ()
+{
+ omp_entity_status *ent = new omp_entity_status ();
+ if (selectedTask >= 0)
+ {
+ ent = taskModel->getTask (selectedTask);
+ if (ent->getStatus () == omp_entity_status::TASK_ACTIVE)
+ {
+ emit sig_stop_task (ent->getId ());
+ emit sig_req_status (0);
+ if (sb_update->value () > 0)
+ {
+ refresh ();
+ }
+ }
+ }
+ else
+ {
+ QMessageBox::information (NULL,tr ("Status Error"),
+ tr ("No Task selected!"));
+ }
+ }
+
+
+/**
+ * @brief SLOT to delete currently selected task
+ *
+ * Emits sig_delete_task (...) to delete the task
+ * Emits sig_req_status (...) to refresh the taskview
+ */
+void
+gsa_desktop_ui::task_delete ()
+{
+ omp_entity_status *ent = new omp_entity_status ();
+ if (selectedTask >= 0)
+ {
+ ent = taskModel->getTask (selectedTask);
+ int ret = QMessageBox::warning (this, tr ("Delete?"),
+ QString (tr ("Do you really want delete"
+ " the Task :<b>%1</b>"))
+ .arg (ent->getName ()),
+ QMessageBox::Yes, QMessageBox::No);
+ switch (ret)
+ {
+ case QMessageBox::Yes:
+ {
+ emit sig_delete_task (ent->getId ());
+ emit sig_req_status (0);
+ return;
+ }
+ case QMessageBox::No:
+ {
+ return;
+ }
+ default:
+ {
+ return;
+ }
+ }
+ }
+ else
+ {
+ QMessageBox::information (NULL,tr ("Status Error"),
+ tr ("No Task selected!"));
+ }
+}
+
+
+/**
+ * @brief SLOT to show the context menu for the task view
+ *
+ * @param position: Position of the cursor
+ */
+void
+gsa_desktop_ui::task_contextmenu (const QPoint &position)
+{
+ QMenu menu (this);
+ if (tw_tasks->indexAt (position).isValid ())
+ {
+ QPoint p (position.x (), position.y () + 22);
+ QAction *name = new QAction (this);
+ QString n (tr ("Task: "));
+ n.append (taskModel->getTask (selectedTask)->getName ());
+ QFont f = name->font ();
+ f.setBold (true);
+ name->setFont (f);
+ name->setText (n);
+ name->setEnabled (false);
+ menu.addAction (name);
+ menu.addSeparator ();
+ menu.addAction (actionRun);
+ menu.addAction (actionStop);
+ menu.addSeparator ();
+ menu.addAction (actionDelete);
+ menu.exec (tw_tasks->mapToGlobal (p));
+ }
+}
\ No newline at end of file
Added: trunk/gsa-desktop/src/gsa_desktop_ui.h
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_ui.h 2010-03-26 14:26:56 UTC (rev 7146)
+++ trunk/gsa-desktop/src/gsa_desktop_ui.h 2010-03-26 16:20:09 UTC (rev 7147)
@@ -0,0 +1,203 @@
+/**
+ * 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 gsa_desktop_ui.h
+ * @brief Protos and data structures for GSA-Desktop UI
+ */
+
+#ifndef GSA_DESKTOP_UI_H
+#define GSA_DESKTOP_UI_H
+
+#include <QtGui>
+
+#include "ui_gsa_desktop_mainwindow.h"
+#include "dlg_login.h"
+#include "omp_credentials.h"
+#include "model_task.h"
+#include "delegate_progress.h"
+#include "delegate_trend.h"
+#include "delegate_threat.h"
+#include "dlg_about.h"
+
+class gsa_desktop_ui : public QMainWindow , private Ui::MainWindow
+{
+ Q_OBJECT
+
+ signals:
+/**
+ * @brief SIGNAL sending the logindata
+ *
+ * @param : Serveraddress
+ * @param : Serverport
+ * @param : Username
+ * @param : Password
+ */
+ void sig_credentials (QString, int, QString, QString);
+
+/**
+ * @brief SIGNAL to request a statusupdate
+ *
+ * @param : interval between two updates
+ */
+ void sig_req_status (int);
+
+/**
+ * @brief SIGNAL to request a statusupdate (with toggle)
+ *
+ * @param : interval between two updates
+ */
+ void sig_req_status_toggle (int);
+
+/**
+ * @brief SIGNAL indicating that the logindialog starts
+ */
+ void sig_login_dlg ();
+
+/**
+ * @brief SIGNAL emitted on logout
+ */
+ void sig_logout ();
+
+/**
+ * @brief SIGNAL emitted to update the data in the logindialog
+ */
+ void sig_update_profile (QString);
+
+/**
+ * @brief SIGNAL to stop a taskupdate
+ */
+ void sig_stop_taskupdate ();
+
+/**
+ * @brief SIGNAL to save the current profile
+ */
+ void sig_save_profile (QString, omp_credentials&);
+
+/**
+ * @brief SIGNAL to remove the current profile
+ */
+ void sig_remove_profile (QString);
+
+/**
+ * @brief SIGNAL to start the task identified by id
+ *
+ * @param : Taskid
+ */
+ void sig_start_task (QString);
+
+/**
+ * @brief SIGNAL to stop the task identified by id
+ *
+ * @param : Taskid
+ */
+ void sig_stop_task (QString);
+
+/**
+ * @brief SIGNAL to delete the task identified by id
+ *
+ * @param : Taskid
+ */
+ void sig_delete_task (QString);
+
+ public:
+ gsa_desktop_ui ();
+ ~gsa_desktop_ui ();
+
+ model_task *getTableModel ();
+
+ void setProfiletoCB (QString name, int position);
+ void setProfileData (omp_credentials &crd);
+
+ public slots:
+ void logout ();
+ void login_dlg ();
+
+
+ private slots:
+ void about_dlg ();
+
+ void loginData ();
+
+ void refresh ();
+ void refresh_once ();
+ void refresh_toggle ();
+ void refresh_stop ();
+ void refresh_manualstop ();
+ void refresh_dw ();
+
+ void profile_update (QString name);
+ void profile_save (QString name, omp_credentials &crd);
+ void profile_remove (QString name);
+
+ void taskupdate_triggered ();
+ void taskupdate_started ();
+ void taskupdate_finished ();
+
+ void progress_timeout ();
+
+ void task_start ();
+ void task_stop ();
+ void task_delete ();
+ void task_contextmenu (const QPoint &);
+ void task_selectionchanged (const QModelIndex &newindex,
+ const QModelIndex &oldindex);
+
+ private:
+ QLabel *la_update;
+ QSpinBox *sb_update;
+ QLabel *la_sec;
+ QToolButton *tb_startUpdate;
+ QProgressBar *pbar_update;
+ QLabel *la_prog_update;
+ QDockWidget *dw_update;
+ QWidget *dockWidgetContents_update;
+ QGridLayout *updateLayout;
+ QToolButton *tb_set_refresh;
+ QToolButton *tb_stop_refresh;
+ QLabel *la_stat_update;
+ QLabel *la_val_update;
+
+ int updateInterval;
+ bool lock;
+
+ dlg_login *login;
+ dlg_about *about;
+ omp_credentials *credentials;
+ int selectedTask;
+
+ QLabel *statuslabel;
+ model_task *taskModel;
+ delegate_progress *taskProgress;
+ delegate_trend *trendIcon;
+ delegate_threat *threatIcon;
+
+ QTimer *progressUpdateTimer;
+
+ void createToolBars ();
+ void createStatusBar ();
+ void createUpdateWidget ();
+ void createConnections ();
+ void modifyWidgets ();
+ };
+#endif
\ No newline at end of file
More information about the Openvas-commits
mailing list