more checks for operations on ruleset objects in Deleted Objects; properly synchronizing main menu Edit and Window

This commit is contained in:
Vadim Kurland
2008-09-11 06:15:11 +00:00
parent e850aa6b59
commit 5b7eb9c493
6 changed files with 154 additions and 98 deletions
+11
View File
@@ -1,5 +1,16 @@
2008-09-10 Vadim Kurland <vadim@vk.crocodile.org>
* RuleSetView.cpp (RuleSetView::pasteRuleAbove): More checks for
operations with rules and ruleset on the deleted Policy or NAT
object. User should not be able to change anything in rule set
object that has been deleted because it does not have parent
firewall object.
* FWWindow.cpp (FWWindow::prepareEditMenu): more fixes for bug
#2100415: "cannot re-create or clone Routing object". Properly
synchronizing main menu Edit to make sure user can not delete
Ruleset objects.
* instDialog.cpp (instDialog::initiateCopy): fixed bug (no #): if
the name of the plink.exe program was specified in upper case in
Preferences dialog, built-in installer failed to provide correct
+88 -63
View File
@@ -195,16 +195,22 @@ FWWindow::FWWindow() : QMainWindow(), // QMainWindow(NULL, Qt::Desktop),
connect( m_mainWindow->findAction, SIGNAL( triggered() ),
this, SLOT(search()) );
connect( m_mainWindow->editMenu, SIGNAL (aboutToShow() ),
this, SLOT( prepareEditMenu() ));
connect( m_mainWindow->ObjectMenu, SIGNAL (aboutToShow() ),
this, SLOT( prepareObjectMenu() ));
connect( m_mainWindow->fileMenu, SIGNAL (aboutToShow() ),
this, SLOT( prepareFileMenu() ));
connect( m_mainWindow->menuWindow, SIGNAL (aboutToShow() ),
this, SLOT( prepareWindowsMenu() ));
connect( m_space, SIGNAL(subWindowActivated (QMdiSubWindow *)),
this, SLOT(changeActiveSubwindow()));
recreateWindowsMenu();
prepareWindowsMenu();
disableActions(false);
// findObject->setMinimumSize( QSize( 0, 0 ) );
@@ -362,7 +368,7 @@ void FWWindow::fileOpen()
proj->loadState(true);
proj.release();
}
recreateWindowsMenu();
//prepareWindowsMenu();
}
void FWWindow::loadFile(const QString &filename)
@@ -375,7 +381,7 @@ void FWWindow::loadFile(const QString &filename)
proj->loadState(true);
proj.release();
}
recreateWindowsMenu();
//prepareWindowsMenu();
}
void FWWindow::fileClose()
@@ -393,7 +399,7 @@ void FWWindow::fileClose()
if (fwbdebug) qDebug("subWindowList().size()=%d",
m_space->subWindowList().size());
recreateWindowsMenu();
//prepareWindowsMenu();
}
void FWWindow::fileSave()
@@ -882,10 +888,32 @@ void FWWindow::unlockObject()
if (activeProject()) activeProject()->unlockObject();
}
void FWWindow::prepareEditMenu()
{
if (!activeProject()) return;
bool dupMenuItem=true;
bool moveMenuItem=true;
bool copyMenuItem=true;
bool pasteMenuItem=true;
bool delMenuItem=true;
bool newMenuItem=true;
bool inDeletedObjects = false;
activeProject()->m_panel->om->getMenuState(
false,
dupMenuItem,moveMenuItem,copyMenuItem,pasteMenuItem,
delMenuItem,newMenuItem,inDeletedObjects);
m_mainWindow->editCopyAction->setEnabled(copyMenuItem);
m_mainWindow->editDeleteAction->setEnabled(delMenuItem);
m_mainWindow->editCutAction->setEnabled(delMenuItem);
m_mainWindow->editPasteAction->setEnabled(pasteMenuItem);
}
void FWWindow::prepareObjectMenu()
{
if (!activeProject())
return;
if (!activeProject())return;
ObjectTreeView* otv = activeProject()->getCurrentObjectTree();
m_mainWindow->ObjectUnlockAction->setEnabled(otv->isUnlockable());
m_mainWindow->ObjectLockAction->setEnabled(otv->isLockable());
@@ -930,6 +958,59 @@ void FWWindow::prepareFileMenu()
m_mainWindow->fileSaveAsAction->setEnabled(true);
}
void FWWindow::prepareWindowsMenu()
{
windowsPainters.clear();
windowsTitles.clear();
m_mainWindow->menuWindow->clear();
QAction * close = m_mainWindow->menuWindow->addAction ("Close");
QAction * closeAll = m_mainWindow->menuWindow->addAction ("Close All");
QAction * title = m_mainWindow->menuWindow->addAction ("Tile");
QAction * cascade = m_mainWindow->menuWindow->addAction ("Cascade");
QAction * next = m_mainWindow->menuWindow->addAction ("Next");
QAction * previous = m_mainWindow->menuWindow->addAction ("Previous");
QAction * minimize = m_mainWindow->menuWindow->addAction ("Minimize");
QAction * maximize = m_mainWindow->menuWindow->addAction ("Maximize");
m_mainWindow->menuWindow->addSeparator ();
connect(minimize, SIGNAL(triggered()), this, SLOT(minimize()));
connect(maximize, SIGNAL(triggered()), this, SLOT(maximize()));
connect(close, SIGNAL(triggered()),m_space, SLOT(closeActiveSubWindow()));
connect(closeAll, SIGNAL(triggered()),m_space, SLOT(closeAllSubWindows()));
connect(title, SIGNAL(triggered()), m_space, SLOT(tileSubWindows()));
connect(cascade, SIGNAL(triggered()), m_space, SLOT(cascadeSubWindows()));
connect(next, SIGNAL(triggered()),m_space, SLOT(activateNextSubWindow()));
connect(previous, SIGNAL(triggered()),m_space, SLOT(activatePreviousSubWindow()));
QList<QMdiSubWindow *> subWindowList = getMdiArea()->subWindowList();
QActionGroup * ag = new QActionGroup ( this );
ag->setExclusive ( true );
for (int i = 0 ; i < subWindowList.size();i++)
{
windowsPainters.push_back (subWindowList[i]);
ProjectPanel * pp = dynamic_cast<ProjectPanel *>(
subWindowList[i]->widget());
if (pp!=NULL)
{
if (pp->isClosing())
continue ;
QString text = pp->getFileName ();
windowsTitles.push_back(text);
if (text=="")
text = "[Noname]";
QAction * act = m_mainWindow->menuWindow->addAction (text);
ag->addAction(act);
act->setCheckable ( true );
if (subWindowList[i]==m_space->activeSubWindow ())
act->setChecked(true);
connect(act, SIGNAL(triggered()),
this, SLOT(selectActiveSubWindow()));
}
}
}
void FWWindow::setupAutoSave()
{
@@ -1522,63 +1603,7 @@ void FWWindow::maximize ()
st->setInt("Window/maximized", 1);
}
void FWWindow::recreateWindowsMenu ()
{
windowsPainters.clear();
windowsTitles.clear();
m_mainWindow->menuWindow->clear();
QAction * close = m_mainWindow->menuWindow->addAction ("Close");
QAction * closeAll = m_mainWindow->menuWindow->addAction ("Close All");
QAction * title = m_mainWindow->menuWindow->addAction ("Tile");
QAction * cascade = m_mainWindow->menuWindow->addAction ("Cascade");
QAction * next = m_mainWindow->menuWindow->addAction ("Next");
QAction * previous = m_mainWindow->menuWindow->addAction ("Previous");
QAction * minimize = m_mainWindow->menuWindow->addAction ("Minimize");
QAction * maximize = m_mainWindow->menuWindow->addAction ("Maximize");
m_mainWindow->menuWindow->addSeparator ();
connect(minimize, SIGNAL(triggered()), this, SLOT(minimize()));
connect(maximize, SIGNAL(triggered()), this, SLOT(maximize()));
connect(close, SIGNAL(triggered()),m_space, SLOT(closeActiveSubWindow()));
connect(closeAll, SIGNAL(triggered()),m_space, SLOT(closeAllSubWindows()));
connect(title, SIGNAL(triggered()), m_space, SLOT(tileSubWindows()));
connect(cascade, SIGNAL(triggered()), m_space, SLOT(cascadeSubWindows()));
connect(next, SIGNAL(triggered()),m_space, SLOT(activateNextSubWindow()));
connect(previous, SIGNAL(triggered()),m_space, SLOT(activatePreviousSubWindow()));
QList<QMdiSubWindow *> subWindowList = getMdiArea()->subWindowList();
QActionGroup * ag = new QActionGroup ( this );
ag->setExclusive ( true );
for (int i = 0 ; i < subWindowList.size();i++)
{
windowsPainters.push_back (subWindowList[i]);
ProjectPanel * pp = dynamic_cast<ProjectPanel *>(
subWindowList[i]->widget());
if (pp!=NULL)
{
if (pp->isClosing())
continue ;
QString text = pp->getFileName ();
windowsTitles.push_back(text);
if (text=="")
text = "[Noname]";
QAction * act = m_mainWindow->menuWindow->addAction (text);
ag->addAction(act);
act->setCheckable ( true );
if (subWindowList[i]==m_space->activeSubWindow ())
act->setChecked(true);
connect(act, SIGNAL(triggered()),
this, SLOT(selectActiveSubWindow()));
}
}
}
void FWWindow::changeActiveSubwindow ( )
{
recreateWindowsMenu();
}
void FWWindow::changeActiveSubwindow() {}
void FWWindow::updateTreeFont ()
{
+2 -1
View File
@@ -84,7 +84,6 @@ class FWWindow : public QMainWindow {
public:
ProjectPanel* activeProject();
void recreateWindowsMenu ();
void updateWindowTitle ();
QVector <QString> windowsTitles;
QVector <QMdiSubWindow*> windowsPainters;
@@ -158,8 +157,10 @@ public slots:
virtual void lockObject();
virtual void unlockObject();
virtual void prepareEditMenu();
virtual void prepareObjectMenu();
virtual void prepareFileMenu();
virtual void prepareWindowsMenu ();
virtual void toolsDiscoveryDruid();
virtual void closeAuxiliaryPanel();
+3 -19
View File
@@ -1179,7 +1179,6 @@ void ObjectManipulator::contextMenuRequested(const QPoint &pos)
if (newID1) newID1->setEnabled(newMenuItem);
if (newID2) newID2->setEnabled(newMenuItem);
// if (inDeletedObjects) movID->setText( tr("Undelete...") );
popup->exec( objTreeView->mapToGlobal( pos ) );
@@ -1229,7 +1228,9 @@ void ObjectManipulator::getMenuState(bool haveMoveTargets,
else
{
FWObject *fw = obj->getParent();
assert(Firewall::cast(fw)!=NULL);
// fw can be NULL if this ruleset is in the Deleted objects
// library
if (fw==NULL) return;
list<FWObject*> child_objects = fw->getByType(obj->getTypeName());
if (child_objects.size()==1) delMenuItem = false;
}
@@ -2456,23 +2457,6 @@ void ObjectManipulator::selectionChanged(QTreeWidgetItem *cur)
currentObj = obj;
bool dupMenuItem=true;
bool moveMenuItem=true;
bool copyMenuItem=true;
bool pasteMenuItem=true;
bool delMenuItem=true;
bool newMenuItem=true;
bool inDeletedObjects = false;
getMenuState(false,
dupMenuItem,moveMenuItem,copyMenuItem,pasteMenuItem,
delMenuItem,newMenuItem,inDeletedObjects);
mw->m_mainWindow->editCopyAction->setEnabled(copyMenuItem);
mw->m_mainWindow->editDeleteAction->setEnabled(delMenuItem);
mw->m_mainWindow->editCutAction->setEnabled(copyMenuItem);
mw->m_mainWindow->editPasteAction->setEnabled(pasteMenuItem);
active=true;
info();
-3
View File
@@ -1009,7 +1009,6 @@ void ProjectPanel::startupLoad()
qDebug("open object %s",show_obj->getName().c_str());
}
}
mw->recreateWindowsMenu();
}
@@ -1292,12 +1291,10 @@ void ProjectPanel::closeEvent( QCloseEvent * ev)
qDebug("ProjectPanel::closeEvent main window houskeeping tasks");
mw->updateWindowTitle();
mw->recreateWindowsMenu();
QTimer::singleShot( 0, mw, SLOT(projectWindowClosed()) );
if (fwbdebug) qDebug("ProjectPanel::closeEvent all done");
// emit closed();
}
QString ProjectPanel::getFileName()
+50 -12
View File
@@ -741,7 +741,8 @@ Firewall* RuleSetView::getFirewall()
{
FWObject *f=ruleset;
while (f!=NULL && !Firewall::isA(f)) f=f->getParent();
assert(f!=NULL);
// f can be NULL if user is looking at deleted ruleset which is a child
// of the library DeletedObjects
return Firewall::cast(f);
}
@@ -1209,17 +1210,20 @@ void RuleSetView::iinit()
supports_rule_options =false;
supports_time =false;
try {
supports_logging=
if (f)
{
try {
supports_logging=
Resources::getTargetCapabilityBool(f->getStr("platform"),
"logging_in_policy");
supports_rule_options=
"logging_in_policy");
supports_rule_options=
Resources::getTargetCapabilityBool(f->getStr("platform"),
"options_in_policy");
supports_time=
"options_in_policy");
supports_time=
Resources::getTargetCapabilityBool(f->getStr("platform"),
"supports_time");
} catch (FWException &ex) { }
"supports_time");
} catch (FWException &ex) { }
}
update();
@@ -2038,7 +2042,10 @@ QSize RuleSetView::drawIconInRule(QPainter &p, int x, int y, RuleElement *re, FW
QString RuleSetView::getPlatform()
{
return getFirewall()->getStr("platform").c_str();
FWObject *f = getFirewall();
if (f)
return f->getStr("platform").c_str();
return "";
}
@@ -2284,6 +2291,7 @@ void RuleSetView::insertRule()
{
// if (!hasFocus()) return; // <-- can insert rule even if does not have focus
if (!isTreeReadWrite(this,ruleset)) return;
if (getFirewall()==NULL) return;
changingRules = true;
if (firstSelectedRow > -1)
@@ -2541,8 +2549,9 @@ void RuleSetView::openObjectInTree(FWObject *obj)
if (gui_experiment1) return;
FWObject *oo = obj;
if (obj==NULL || Rule::cast(obj)!=NULL)
oo = getFirewall();
if (obj==NULL || Rule::cast(obj)!=NULL) oo = getFirewall();
if (oo==NULL) return;
selectedObject=oo;
mw->info(oo);
@@ -2756,6 +2765,7 @@ void RuleSetView::removeFromGroup (int row, int count)
void RuleSetView::contextMenu(int row, int col, const QPoint &pos)
{
if (getFirewall()==NULL) return;
if (col > 0)
setCurrentCell(row,col);
@@ -3284,6 +3294,8 @@ void RuleSetView::setRuleColor(const QString &c)
void RuleSetView::changeAction(PolicyRule::Action act)
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;
if ( currentRow()!=-1 && currentColumn()!=-1 )
@@ -3386,6 +3398,8 @@ void RuleSetView::changeActionToBranch()
void RuleSetView::changeDitection(PolicyRule::Direction dir)
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;
if ( currentRow()!=-1 && currentColumn()!=-1 )
@@ -3418,6 +3432,8 @@ void RuleSetView::changeDirectionToBoth()
void RuleSetView::changeLogToOn()
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;
if ( currentRow()!=-1 && currentColumn()!=-1 )
@@ -3431,6 +3447,8 @@ void RuleSetView::changeLogToOn()
void RuleSetView::changeLogToOff()
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;
if ( currentRow()!=-1 && currentColumn()!=-1 )
@@ -3476,6 +3494,8 @@ void RuleSetView::deleteSelectedObject()
void RuleSetView::deleteObject(int row, int col, FWObject *obj)
{
if (getFirewall()==NULL) return;
RuleElement *re = getRE(row,col);
if (re==NULL || re->isAny()) return;
int id = obj->getId();
@@ -3512,6 +3532,8 @@ void RuleSetView::deleteObject(int row, int col, FWObject *obj)
bool RuleSetView::insertObject(int row, int col, FWObject *obj)
{
if (getFirewall()==NULL) return false;
if (fwbdebug)
qDebug("RuleSetView::insertObject -- insert object %s",
obj->getName().c_str());
@@ -3611,6 +3633,8 @@ void RuleSetView::pasteObject()
void RuleSetView::negateRE()
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;
if ( currentRow()!=-1 && currentColumn()!=-1 )
@@ -3660,6 +3684,8 @@ void RuleSetView::editRE()
void RuleSetView::keyPressEvent( QKeyEvent* ev )
{
if (getFirewall()==NULL) return;
m_project->selectRules();
RuleElement *re;
@@ -4058,6 +4084,8 @@ void RuleSetView::dropEvent(QDropEvent *ev)
void RuleSetView::removeRule()
{
if (getFirewall()==NULL) return;
if (!hasFocus()) return;
if (!isTreeReadWrite(this,ruleset)) return;
/* we call removeRule in a loop. Set flag changingRules to true to prevent
@@ -4116,6 +4144,8 @@ void RuleSetView::removeRule()
void RuleSetView::addRuleAfterCurrent()
{
if (getFirewall()==NULL) return;
if (!hasFocus()) return;
if (!isTreeReadWrite(this,ruleset)) return;
@@ -4128,6 +4158,8 @@ void RuleSetView::addRuleAfterCurrent()
void RuleSetView::moveRule()
{
if (getFirewall()==NULL) return;
if (!hasFocus()) return;
int selectionSize = lastSelectedRow - firstSelectedRow + 1;
@@ -4315,6 +4347,8 @@ void RuleSetView::cutRule()
void RuleSetView::pasteRuleAbove()
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;
/*int firstSelectedRow=-1;
@@ -4351,6 +4385,8 @@ void RuleSetView::pasteRuleAbove()
void RuleSetView::pasteRuleBelow()
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;
/*int firstSelectedRow=-1;
@@ -4396,6 +4432,7 @@ void RuleSetView::pasteRuleBelow()
void RuleSetView::enableRule()
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;
if ( firstSelectedRow!=-1 )
@@ -4415,6 +4452,7 @@ void RuleSetView::enableRule()
void RuleSetView::disableRule()
{
if (getFirewall()==NULL) return;
if (!isTreeReadWrite(this,ruleset)) return;