1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-03-23 19:57:21 +01:00

Methods for retrieving edited interface data. Comment is now textedit.

This commit is contained in:
Roman Bovsunivskiy 2009-11-07 03:18:38 +00:00
parent 9750dea494
commit 5d85d366ab
7 changed files with 84 additions and 12 deletions

View File

@ -27,3 +27,13 @@ void AddressEditor::changeEvent(QEvent *e)
break;
}
}
QPair<QString, QString> AddressEditor::getEditedData()
{
return qMakePair(this->m_ui->address->text(), this->m_ui->netmask->text());
}
libfwbuilder::Address* AddressEditor::getAddress()
{
return this->address;
}

View File

@ -14,6 +14,8 @@ class AddressEditor : public QWidget {
public:
AddressEditor(QWidget *parent, libfwbuilder::Address *address);
~AddressEditor();
QPair<QString, QString> getEditedData();
libfwbuilder::Address* getAddress();
protected:
void changeEvent(QEvent *e);

View File

@ -11,7 +11,7 @@ InterfaceEditor::InterfaceEditor(QWidget *parent, libfwbuilder::Interface *inter
m_ui->setupUi(this);
this->m_ui->name->setText(interface->getName().c_str());
this->m_ui->label->setText(interface->getLabel().c_str());
this->m_ui->comment->setText(interface->getComment().c_str());
this->m_ui->comment->setPlainText(interface->getComment().c_str());
while ( this->m_ui->tabWidget->count() ) this->m_ui->tabWidget->removeTab(0);
libfwbuilder::FWObjectTypedChildIterator adriter = interface->findByType(libfwbuilder::IPv4::TYPENAME);
for ( ; adriter != adriter.end(); ++adriter )
@ -41,3 +41,22 @@ void InterfaceEditor::nameEdited(QString newname)
{
interface->setName(newname.toStdString());
}
libfwbuilder::Interface* InterfaceEditor::getInterface()
{
return this->interface;
}
EditedInterfaceData InterfaceEditor::getInterfaceData()
{
EditedInterfaceData res;
res.name = this->m_ui->name->text();
res.label = this->m_ui->label->text();
res.comment = this->m_ui->comment->toPlainText();
for ( int i = 0; i < this->m_ui->tabWidget->count(); i++ )
{
AddressEditor *addr = dynamic_cast<AddressEditor*>(this->m_ui->tabWidget->widget(i));
res.addresses[addr->getAddress()] = addr->getEditedData();
}
return res;
}

View File

@ -8,6 +8,7 @@
#include "platforms.h"
#include "AddressEditor.h"
#include "newFirewallDialog.h"
#include <QtGui/QWidget>
@ -22,6 +23,8 @@ class InterfaceEditor : public QWidget {
public:
InterfaceEditor(QWidget *parent, libfwbuilder::Interface *interface);
~InterfaceEditor();
libfwbuilder::Interface* getInterface();
EditedInterfaceData getInterfaceData();
protected:
void changeEvent(QEvent *e);

View File

@ -44,7 +44,20 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="comment"/>
<widget class="QPlainTextEdit" name="comment">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="plainText">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
@ -66,17 +79,17 @@
<connections>
<connection>
<sender>name</sender>
<signal>textChanged(QString)</signal>
<signal>textEdited(QString)</signal>
<receiver>InterfaceEditor</receiver>
<slot>nameEdited(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>187</x>
<y>27</y>
<x>140</x>
<y>31</y>
</hint>
<hint type="destinationlabel">
<x>10</x>
<y>80</y>
<x>6</x>
<y>69</y>
</hint>
</hints>
</connection>

View File

@ -356,6 +356,11 @@ void newFirewallDialog::getInterfacesViaSNMP()
#endif
}
bool interfaceCompare(libfwbuilder::Interface *first, libfwbuilder::Interface *second)
{
return first->getName() < second->getName();
}
bool newFirewallDialog::appropriate(const int page) const
{
int p = page;
@ -511,17 +516,28 @@ void newFirewallDialog::showPage(const int page)
setFinishEnabled( 5, true );
while ( this->m_dialog->interfaces->count() )
this->m_dialog->interfaces->removeTab(0);
QList<Interface*> interfaces;
FWObjectTypedChildIterator intiter = currentTemplate->findByType(Interface::TYPENAME);
for ( ; intiter != intiter.end(); ++intiter )
{
Interface *intr = Interface::cast(*intiter);
if (intr != NULL)
m_dialog->interfaces->addTab(new InterfaceEditor(this->m_dialog->interfaces, intr), intr->getName().c_str());
}
interfaces.append(Interface::cast(*intiter));
sort(interfaces.begin(), interfaces.end(), interfaceCompare);
foreach(Interface* intr, interfaces)
m_dialog->interfaces->addTab(new InterfaceEditor(this->m_dialog->interfaces, intr), intr->getName().c_str());
}
}
}
QMap<Interface*, EditedInterfaceData> newFirewallDialog::getEditedTemplateInterfaces()
{
QMap<Interface*, EditedInterfaceData> res;
for ( int i = 0; i < m_dialog->interfaces->count(); i++ )
{
InterfaceEditor *intEditor = dynamic_cast<InterfaceEditor*>(m_dialog->interfaces->widget(i));
res[intEditor->getInterface()] = intEditor->getInterfaceData();
}
return res;
}
void newFirewallDialog::fillInterfaceSLList()
{

View File

@ -48,6 +48,14 @@ class QTreeWidgetItem;
class QTimer;
class QTextEdit;
struct EditedInterfaceData
{
QString name;
QString label;
QString comment;
QMap<libfwbuilder::Address*, QPair<QString, QString> > addresses;
};
class newFirewallDialog : public QDialog, public FakeWizard
{
Q_OBJECT;
@ -85,6 +93,7 @@ class newFirewallDialog : public QDialog, public FakeWizard
void showPage(const int page); //it was "selected(QString)"
bool validateAddressAndMask(const QString &addr,const QString &netm);
QMap<libfwbuilder::Interface*, EditedInterfaceData> getEditedTemplateInterfaces();
public slots:
virtual void addInterface();