1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-03-23 11:47:24 +01:00

see #2135 Editing table objects

This commit is contained in:
Vadim Kurland 2011-02-23 19:28:22 -08:00
parent 222ff26e14
commit 25fa09d626
9 changed files with 457 additions and 126 deletions

View File

@ -1,3 +1,12 @@
2011-02-23 vadim <vadim@netcitadel.com>
* AddressTableEditor.cpp (save): fixes #2135 "Editing table
objects". Dialog of the AddressTable object now offers button
"Edit" that lets the user edit address table file. This only
works if the file is located on the same machine where the GUI
is running, so it is probably most useful for compile time
objects.
2011-02-22 Vadim Kurland <vadim@netcitadel.com>
* configlets/linux24/shell_functions: see #2130 "unnecessary

View File

@ -28,7 +28,7 @@
#include "utils.h"
#include "ProjectPanel.h"
#include "AddressTableDialog.h"
#include "SimpleTextView.h"
#include "AddressTableEditor.h"
#include "FWBSettings.h"
#include "FWWindow.h"
#include "FWCmdChange.h"
@ -169,33 +169,10 @@ void AddressTableDialog::browse()
m_dialog->filename->setFocus(Qt::OtherFocusReason);
}
}
void AddressTableDialog::preview( void )
void AddressTableDialog::editFile( void )
{
SimpleTextView tv(this);
tv.setName(m_dialog->obj_name->text());
QFile f;
QTextStream ts;
QString filePath = m_dialog->filename->text();
if (QDir::isRelativePath(filePath))
f.setFileName(getFileDir(mw->getCurrentFileName()) + "/" + filePath);
else
f.setFileName(filePath);
if (f.exists())
{
if(f.open(QIODevice::ReadOnly ))
{
ts.setDevice(&f);
tv.setText(ts.readAll());
f.close();
}
}
else
{
tv.setText("File not found.");
}
tv.exec();
AddressTableEditor editor(this, filePath);
editor.exec(); // its modal dialog
}

View File

@ -51,7 +51,7 @@ public slots:
virtual void loadFWObject(libfwbuilder::FWObject *obj);
virtual void validate(bool*);
virtual void browse();
virtual void preview( void );
virtual void editFile( void );
virtual void getHelpName(QString*);
};

View File

@ -0,0 +1,150 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that 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.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../../config.h"
#include "global.h"
#include "AddressTableEditor.h"
#include "FWBSettings.h"
#include <qmessagebox.h>
#include <qtextedit.h>
#include <qpushbutton.h>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QCloseEvent>
#include <QtDebug>
using namespace std;
AddressTableEditor::AddressTableEditor(QWidget *parent,
const QString &file_name,
const QString &title) : QDialog(parent)
{
this->file_name = file_name;
m_dialog = new Ui::AddressTableEditor_q;
m_dialog->setupUi(static_cast<QDialog*>(this));
if (!title.isEmpty()) setWindowTitle(title);
QFile rf(file_name);
if (rf.exists())
{
m_dialog->editor->setPlainText(
QObject::tr("File %1 not found").arg(file_name)
);
}
QFileInfo fi(file_name);
if ( ! fi.isWritable())
{
QMessageBox::critical(
this, "Firewall Builder",
tr("The file is read-only, you can't save the changes."),
tr("&Continue"), QString::null, QString::null, 0, 0 );
m_dialog->editor->setReadOnly(true);
m_dialog->ok_button->hide();
m_dialog->cancel_button->setText(tr("Close"));
}
if (rf.open(QIODevice::ReadOnly))
{
original_data = rf.readAll();
m_dialog->editor->setPlainText(original_data);
rf.close();
} else
{
m_dialog->editor->setPlainText(rf.errorString());
}
}
AddressTableEditor::~AddressTableEditor()
{
delete m_dialog;
}
void AddressTableEditor::save()
{
QString tmp_file_name = file_name + ".tmp";
QFile wf(tmp_file_name);
if (wf.open(QIODevice::WriteOnly) &&
wf.write(m_dialog->editor->toPlainText().toAscii().constData()) >= 0)
{
wf.close();
QFile old_file(file_name);
if (old_file.remove() && wf.rename(tmp_file_name, file_name))
{
QDialog::accept();
return;
} else
QMessageBox::critical(
this,"Firewall Builder",
tr("Can not rename file %1 to %2: %3")
.arg(tmp_file_name).arg(file_name).arg(wf.errorString()),
"&Continue", QString::null, QString::null, 0, 1 );
} else
QMessageBox::critical(
this,"Firewall Builder",
tr("Can not open temporary file '%1' to save the data: %2")
.arg(tmp_file_name).arg(wf.errorString()),
"&Continue", QString::null, QString::null, 0, 1 );
}
void AddressTableEditor::closeEvent(QCloseEvent* ev)
{
if (m_dialog->editor->toPlainText() != original_data)
{
switch (
QMessageBox::critical(
this, "Firewall Builder",
tr("Dialog contains modified data. Do you want to save it?"),
tr("&Save"), tr("&Discard"), tr("&Cancel"),
0, // enter: button 0
2 )) // escape: button 2
{
case 0:
save();
QDialog::closeEvent(ev);
break;
case 1:
QDialog::closeEvent(ev);
break;
case 2:
ev->ignore();
return;
}
}
QDialog::closeEvent(ev);
}

View File

@ -0,0 +1,52 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that 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.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __ADDRESSTABLEEDITOR_H__
#define __ADDRESSTABLEEDITOR_H__
#include "../../config.h"
#include <ui_addresstableeditor_q.h>
class AddressTableEditor : public QDialog
{
Q_OBJECT;
QString file_name;
QString original_data;
public:
Ui::AddressTableEditor_q *m_dialog;
AddressTableEditor(QWidget *parent,
const QString &file_name,
const QString &title="");
~AddressTableEditor();
protected:
virtual void closeEvent(QCloseEvent *ev);
public slots:
virtual void save();
};
#endif

View File

@ -1,7 +1,8 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressTableDialog_q</class>
<widget class="QWidget" name="AddressTableDialog_q" >
<property name="geometry" >
<widget class="QWidget" name="AddressTableDialog_q">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
@ -9,74 +10,74 @@
<height>264</height>
</rect>
</property>
<property name="baseSize" >
<property name="baseSize">
<size>
<width>500</width>
<height>500</height>
</size>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Address Table</string>
</property>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="QFrame" name="frame7" >
<property name="frameShape" >
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QFrame" name="frame7">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow" >
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QGridLayout" >
<item rowspan="2" row="0" column="0" >
<widget class="QFrame" name="frame10" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Fixed" >
<layout class="QGridLayout">
<item row="0" column="0" rowspan="2">
<widget class="QFrame" name="frame10">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<property name="minimumSize">
<size>
<width>350</width>
<height>16</height>
</size>
</property>
<property name="maximumSize" >
<property name="maximumSize">
<size>
<width>350</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape" >
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow" >
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QGridLayout" >
<property name="spacing" >
<layout class="QGridLayout">
<property name="spacing">
<number>12</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="textLabel1" >
<property name="text" >
<item row="0" column="0">
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Name:</string>
</property>
<property name="wordWrap" >
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2" >
<widget class="QLineEdit" name="obj_name" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="obj_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>200</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
@ -84,51 +85,51 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="2" >
<widget class="QRadioButton" name="r_compiletime" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="r_compiletime">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<property name="text">
<string>Compile Time</string>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QRadioButton" name="r_runtime" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<item row="1" column="2">
<widget class="QRadioButton" name="r_runtime">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<property name="text">
<string>Run Time</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3" >
<widget class="QLabel" name="textLabel2_2" >
<property name="text" >
<item row="2" column="0" colspan="3">
<widget class="QLabel" name="textLabel2_2">
<property name="text">
<string>File name:</string>
</property>
<property name="wordWrap" >
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3" >
<widget class="QLineEdit" name="filename" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
<item row="3" column="0" colspan="3">
<widget class="QLineEdit" name="filename">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
@ -136,40 +137,40 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="3" >
<layout class="QHBoxLayout" >
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QPushButton" name="BrowseButton" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<widget class="QPushButton" name="BrowseButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<property name="toolTip">
<string>Browse</string>
</property>
<property name="text" >
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="previewButton" >
<property name="text" >
<string>Preview</string>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
@ -179,15 +180,15 @@
</item>
</layout>
</item>
<item row="5" column="1" colspan="2" >
<item row="5" column="1" colspan="2">
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>307</width>
<height>16</height>
@ -198,43 +199,43 @@
</layout>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLabel" name="textLabel2" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
<item row="0" column="1">
<widget class="QLabel" name="textLabel2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<property name="text">
<string>Comment:</string>
</property>
<property name="wordWrap" >
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="TextEditWidget" name="comment" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<item row="1" column="1">
<widget class="TextEditWidget" name="comment">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>100</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize" >
<property name="maximumSize">
<size>
<width>16777215</width>
<height>180</height>
</size>
</property>
<property name="tabChangesFocus" >
<property name="tabChangesFocus">
<bool>true</bool>
</property>
</widget>
@ -257,11 +258,11 @@
<tabstop>r_runtime</tabstop>
<tabstop>filename</tabstop>
<tabstop>BrowseButton</tabstop>
<tabstop>previewButton</tabstop>
<tabstop>editButton</tabstop>
<tabstop>comment</tabstop>
</tabstops>
<resources>
<include location="MainRes.qrc" />
<include location="MainRes.qrc"/>
</resources>
<connections>
<connection>
@ -270,11 +271,11 @@
<receiver>AddressTableDialog_q</receiver>
<slot>changed()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
@ -286,11 +287,11 @@
<receiver>AddressTableDialog_q</receiver>
<slot>changed()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
@ -302,11 +303,11 @@
<receiver>AddressTableDialog_q</receiver>
<slot>changed()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
@ -318,11 +319,11 @@
<receiver>AddressTableDialog_q</receiver>
<slot>changed()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
@ -334,11 +335,11 @@
<receiver>AddressTableDialog_q</receiver>
<slot>changed()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
@ -350,31 +351,34 @@
<receiver>AddressTableDialog_q</receiver>
<slot>browse()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>previewButton</sender>
<sender>editButton</sender>
<signal>clicked()</signal>
<receiver>AddressTableDialog_q</receiver>
<slot>preview()</slot>
<slot>editFile()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>editFile()</slot>
</slots>
</ui>

View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressTableEditor_q</class>
<widget class="QDialog" name="AddressTableEditor_q">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>592</width>
<height>344</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="windowTitle">
<string>Script Editor</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>11</number>
</property>
<item row="0" column="0" colspan="4">
<widget class="QTextEdit" name="editor">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="ok_button">
<property name="text">
<string>Save</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="cancel_button">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="Line" name="line6">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>editor</tabstop>
<tabstop>ok_button</tabstop>
<tabstop>cancel_button</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>ok_button</sender>
<signal>clicked()</signal>
<receiver>AddressTableEditor_q</receiver>
<slot>save()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>cancel_button</sender>
<signal>clicked()</signal>
<receiver>AddressTableEditor_q</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>save()</slot>
</slots>
</ui>

View File

@ -1065,7 +1065,9 @@ bool instDialog::getInstOptions(Firewall *fw, bool cancelAllVisible)
{
// In non-batch mode installer options from the dialog
// overwrite options set in the fw object itself.
instOptionsDialog *inst_opt_dlg = new instOptionsDialog(this, &cnf, cancelAllVisible);
instOptionsDialog *inst_opt_dlg = new instOptionsDialog(
this, &cnf, cancelAllVisible);
int resultCode = inst_opt_dlg->exec();
// 0 - rejected
// 1 - accepted

View File

@ -48,6 +48,7 @@ HEADERS += ../../config.h \
DialogData.h \
SimpleTextEditor.h \
SimpleIntEditor.h \
AddressTableEditor.h \
FWBSettings.h \
FWBTree.h \
RCS.h \
@ -227,6 +228,7 @@ SOURCES += ProjectPanel.cpp \
DialogData.cpp \
SimpleTextEditor.cpp \
SimpleIntEditor.cpp \
AddressTableEditor.cpp \
FWBSettings.cpp \
FWBTree.cpp \
RCS.cpp \
@ -416,6 +418,7 @@ FORMS = FWBMainWindow_q.ui \
procurveacladvanceddialog_q.ui \
simpletexteditor_q.ui \
simpleinteditor_q.ui \
addresstableeditor_q.ui \
aboutdialog_q.ui \
libexport_q.ui \
ruleoptionsdialog_q.ui \