[Openvas-commits] r8713 - in trunk/gsa-desktop: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Aug 6 13:10:21 CEST 2010


Author: raimund
Date: 2010-08-06 13:10:21 +0200 (Fri, 06 Aug 2010)
New Revision: 8713

Modified:
   trunk/gsa-desktop/ChangeLog
   trunk/gsa-desktop/src/gsa_desktop_control.cpp
   trunk/gsa-desktop/src/gsa_desktop_control.h
   trunk/gsa-desktop/src/gsa_desktop_ui.cpp
   trunk/gsa-desktop/src/gsa_desktop_ui.h
   trunk/gsa-desktop/src/omp_commands.cpp
   trunk/gsa-desktop/src/omp_commands.h
   trunk/gsa-desktop/src/omp_connector.cpp
   trunk/gsa-desktop/src/omp_connector.h
Log:
* src/gsa_desktop_ui.cpp (createConnections): Signal/slot configuration for
delete note.
(createToolBars): Enabled delete action for notes.
(eventFilter): Added note actions to event filter.
(modifyWidgets): Donate notes table an object name, install event filter.
(note_delete, note_selectionchanged): New.

* src/gsa_desktop_control.cpp (createConnections): Signal/slot configuration
for delete note.
(note_delete): New.

* src/omp_connector.cpp (deleteNote): New.

* src/omp_commands.cpp (note_delete): New.

* src/gsa_desktop_ui.h, gsa_desktop_control.h, omp_connector.h,
omp_commands.h: Updated prototypes.



Modified: trunk/gsa-desktop/ChangeLog
===================================================================
--- trunk/gsa-desktop/ChangeLog	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/ChangeLog	2010-08-06 11:10:21 UTC (rev 8713)
@@ -1,5 +1,25 @@
 2010-08-06  Raimund Renkert <raimund.renkert at intevation.de>
 
+	* src/gsa_desktop_ui.cpp (createConnections): Signal/slot configuration for
+	delete note.
+	(createToolBars): Enabled delete action for notes.
+	(eventFilter): Added note actions to event filter.
+	(modifyWidgets): Donate notes table an object name, install event filter.
+	(note_delete, note_selectionchanged): New.
+
+	* src/gsa_desktop_control.cpp (createConnections): Signal/slot configuration
+	for delete note.
+	(note_delete): New.
+
+	* src/omp_connector.cpp (deleteNote): New.
+
+	* src/omp_commands.cpp (note_delete): New.
+
+	* src/gsa_desktop_ui.h, gsa_desktop_control.h, omp_connector.h,
+	omp_commands.h: Updated prototypes.
+
+2010-08-06  Raimund Renkert <raimund.renkert at intevation.de>
+
 	* src/gsa_desktop_ui.cpp: Resized threat column in task widget.
 
 2010-08-06  Raimund Renkert <raimund.renkert at intevation.de>

Modified: trunk/gsa-desktop/src/gsa_desktop_control.cpp
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_control.cpp	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/src/gsa_desktop_control.cpp	2010-08-06 11:10:21 UTC (rev 8713)
@@ -151,6 +151,8 @@
            this, SLOT (agent_create (QString, QString, QString, QString)));
   connect (mainwin, SIGNAL (sig_delete_agent (QString)), this,
            SLOT (agent_delete (QString)));
+  connect (mainwin, SIGNAL (sig_delete_note (QString)), this,
+           SLOT (note_delete (QString)));
 }
 
 
@@ -899,6 +901,24 @@
 
 
 /**
+ * @brief SLOT that deletes a note.
+ *
+ * Deletes a note, identified by its id.
+ *
+ * @param id Note id
+ */
+void
+gsa_desktop_control::note_delete (QString id)
+{
+  if (this->connector->deleteNote (id) != 0)
+    {
+      QMessageBox::information (NULL,tr ("Status Error"),
+                                tr ("Could not delete note!"));
+    }
+}
+
+
+/**
  * @brief SLOT to display login faults
  *
  * Displays errors that occured while trying to login.

Modified: trunk/gsa-desktop/src/gsa_desktop_control.h
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_control.h	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/src/gsa_desktop_control.h	2010-08-06 11:10:21 UTC (rev 8713)
@@ -114,6 +114,7 @@
     void agent_create (QString name, QString comment, QString installer,
                        QString signature);
     void agent_delete (QString id);
+    void note_delete (QString id);
     void log (QString msg, int prio);
 
   public:

Modified: trunk/gsa-desktop/src/gsa_desktop_ui.cpp
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_ui.cpp	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/src/gsa_desktop_ui.cpp	2010-08-06 11:10:21 UTC (rev 8713)
@@ -235,7 +235,6 @@
   notes->addSeparator ();
   notes->addActionToToolBar (actionDetails_Note);
   notes->addActionToToolBar (actionEdit_Note);
-  actionDelete_Note->setEnabled (false);
   actionDetails_Note->setEnabled (false);
   actionEdit_Note->setEnabled (false);
 
@@ -540,6 +539,8 @@
            SLOT (newAgent_dlg ()));
   connect (actionDelete_Agent, SIGNAL (triggered (bool)), this,
            SLOT (agent_delete ()));
+  connect (actionDelete_Note, SIGNAL (triggered (bool)), this,
+           SLOT (note_delete ()));
   connect (actionDetails_Target, SIGNAL (triggered (bool)), this,
            SLOT (details_dlg ()));
   connect (actionDetails_Schedule, SIGNAL (triggered (bool)), this,
@@ -662,6 +663,7 @@
   QMainWindow::tabifyDockWidget (dw_tasks, notes);
   notes->setModel (noteModel);
   QTableView *tw_notes = notes->getTable ();
+  tw_notes->setObjectName ("tw_notes");
   tw_notes->horizontalHeader ()->setResizeMode (QHeaderView::Fixed);
   tw_notes->horizontalHeader ()->setResizeMode (0, QHeaderView::Stretch);
   tw_notes->setColumnWidth (0, 150);
@@ -731,6 +733,7 @@
   tw_escalators->installEventFilter (this);
   tw_credentials->installEventFilter (this);
   tw_agents->installEventFilter (this);
+  tw_notes->installEventFilter (this);
 
   dw_tasks->raise ();
 
@@ -1531,6 +1534,55 @@
 
 
 /**
+ * @brief SLOT to delete currently selected note.
+ *
+ * Emits sig_delete_agent (...) to delete the note.
+ * Emits sig_req_agents (...) to refresh the note view.
+ */
+void
+gsa_desktop_ui::note_delete ()
+{
+  QDomNode ent;
+  QModelIndexList selected = notes->getTable ()->selectionModel ()
+                                              ->selectedRows (0);
+  if (selected.size () != 0)
+    {
+      ent = noteModel->getEntity (selected.at (0).row ());
+      int ret = QMessageBox::warning (this, tr ("Delete?"),
+                                      QString (tr ("Do you really want delete"
+                                                   " the note: <b>%1</b>"))
+                                               .arg (noteModel->getValue
+                                                     (ent.toElement (), "name")),
+                                                      QMessageBox::Yes, QMessageBox::No);
+      switch (ret)
+        {
+          case QMessageBox::Yes:
+            {
+              noteModel->removeEntity (selected.at (0).row ());
+              emit sig_delete_note (noteModel->getAttr (ent.toElement (),
+                                                         "note id"));
+              emit sig_req_notes ();
+              return;
+            }
+          case QMessageBox::No:
+            {
+              return;
+            }
+          default:
+            {
+              return;
+            }
+        }
+    }
+  else
+    {
+      QMessageBox::information (NULL,tr ("Status Error"),
+                                tr ("No note selected!"));
+    }
+}
+
+
+/**
  * @brief SLOT that starts the update dockwidget
  */
 void
@@ -2092,6 +2144,43 @@
 
 
 /**
+ * @brief SLOT to enable/disable action buttons in note widget.
+ *
+ * @param newindex: new selected index
+ * @param oldindex: previous selected index
+ */
+void
+gsa_desktop_ui::note_selectionchanged (const QModelIndex &newindex,
+                                        const QModelIndex &oldindex)
+{
+  int row = -1;
+  QModelIndexList selected = notes->getTable ()->selectionModel ()
+                                               ->selectedRows (0);
+  if (selected.empty ())
+    {
+      return;
+    }
+  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;
+    }
+  QDomNode ent = noteModel->getEntity (row);
+  if (ent.isNull ())
+    {
+      return;
+    }
+  actionDelete_Note->setEnabled (true);
+}
+
+/**
  * @brief SLOT to start runnig a task
  */
 void
@@ -2741,6 +2830,7 @@
   if (focus)
     {
       selectRow (notes->getTable (), noteModel);
+      note_selectionchanged (QModelIndex (), QModelIndex ());
       emit sig_req_notes ();
     }
 }
@@ -2833,6 +2923,9 @@
 
       if (widget->objectName ().compare ("tw_agents") == 0)
         agent_selectionchanged (QModelIndex (), QModelIndex ());
+
+      if (widget->objectName ().compare ("tw_notes") == 0)
+        note_selectionchanged (QModelIndex (), QModelIndex ());
     }
   if (e->type () == QEvent::FocusOut)
     {
@@ -2871,6 +2964,10 @@
         {
           actionDelete_Agent->setEnabled (false);
         }
+      if (widget->objectName ().compare ("tw_notes") != 0)
+        {
+          actionDelete_Note->setEnabled (false);
+        }
     }
   if (e->type () == QEvent::ToolTip)
     {

Modified: trunk/gsa-desktop/src/gsa_desktop_ui.h
===================================================================
--- trunk/gsa-desktop/src/gsa_desktop_ui.h	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/src/gsa_desktop_ui.h	2010-08-06 11:10:21 UTC (rev 8713)
@@ -184,6 +184,7 @@
     void sig_delete_credential (QString);
     void sig_create_agent (QString, QString, QString, QString);
     void sig_delete_agent (QString);
+    void sig_delete_note (QString);
 
   public:
     gsa_desktop_ui ();
@@ -281,6 +282,8 @@
                                       const QModelIndex &oldindex);
     void agent_selectionchanged (const QModelIndex &oldindex,
                                  const QModelIndex &newindex);
+    void note_selectionchanged (const QModelIndex &oldindex,
+                                const QModelIndex &newindex);
     void config_create (QString name, QString comment, QString base);
     void config_delete ();
     void target_create (QString name, QString comment, QString hosts,
@@ -302,6 +305,7 @@
     void agent_create (QString name, QString comment, QString installer,
                        QString signature);
     void agent_delete ();
+    void note_delete ();
 
   private:
     QLabel *la_update;

Modified: trunk/gsa-desktop/src/omp_commands.cpp
===================================================================
--- trunk/gsa-desktop/src/omp_commands.cpp	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/src/omp_commands.cpp	2010-08-06 11:10:21 UTC (rev 8713)
@@ -936,3 +936,37 @@
     }
 }
 
+
+/**
+ * @brief Deletes a note by id
+ *
+ * Establishes a connection to the openvas-manager using the inherited
+ * functions openConnection () and closeConnection ().
+ *
+ * @param id Note id
+ *
+ * @return 0 on success, 1 if no connection could be established, -1 on error.
+ */
+int
+omp_commands::note_delete (QString id)
+{
+  if (openConnection () == 0)
+    {
+      gnutls_session_t session = getSession ();
+      if (id.isNull ())
+        return -1;
+
+      QString temp = QString ("<delete_note note_id=\"%1\"/>").arg (id);
+      int ret =  openvas_server_sendf (&session, temp.toLatin1 ());
+      entity_t response = NULL;
+      if (read_entity (&session, &response)) return -1;
+
+      closeConnection ();
+
+      return ret;
+    }
+  else
+    {
+      return 1;
+    }
+}

Modified: trunk/gsa-desktop/src/omp_commands.h
===================================================================
--- trunk/gsa-desktop/src/omp_commands.h	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/src/omp_commands.h	2010-08-06 11:10:21 UTC (rev 8713)
@@ -80,6 +80,7 @@
     int agent_create (QString name, QString comment, QString installer,
                       QString signature);
     int agent_delete (QString id);
+    int note_delete (QString id);
 };
 #endif
 

Modified: trunk/gsa-desktop/src/omp_connector.cpp
===================================================================
--- trunk/gsa-desktop/src/omp_connector.cpp	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/src/omp_connector.cpp	2010-08-06 11:10:21 UTC (rev 8713)
@@ -599,6 +599,20 @@
 
 
 /**
+ * @brief Deletes a note.
+ *
+ * @param id Note id, note to delete.
+ *
+ * @return 0 on success, 1 if no connection could be established, -1 on error
+ */
+int
+omp_connector::deleteNote (QString id)
+{
+  return commands->note_delete (id);
+}
+
+
+/**
  * @brief Stops updating Tasks.
  *
  * Emits sig_stopped_taskupdate ().

Modified: trunk/gsa-desktop/src/omp_connector.h
===================================================================
--- trunk/gsa-desktop/src/omp_connector.h	2010-08-06 11:03:17 UTC (rev 8712)
+++ trunk/gsa-desktop/src/omp_connector.h	2010-08-06 11:10:21 UTC (rev 8713)
@@ -136,6 +136,7 @@
     int createAgent (QString name, QString comment, QString installer,
                      QString signature);
     int deleteAgent (QString id);
+    int deleteNote (QString id);
 };
 #endif
 



More information about the Openvas-commits mailing list