1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-06-25 02:19:37 +02:00

Task 6 finished

This commit is contained in:
2008-02-29 16:39:51 +00:00
parent b3ae89db0f
commit a431cf2a15
16 changed files with 1647 additions and 1037 deletions

View File

@@ -0,0 +1,112 @@
/*
Firewall Builder
Copyright (C) 2003 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
$Id: AskLibForCopyDialog.cpp,v 1.164 2007/07/07 05:39:34 vkurland Exp $
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 "fwbuilder_ph.h"
#include "AskLibForCopyDialog.h"
#include "FWBSettings.h"
using namespace std;
using namespace libfwbuilder;
FWObject *AskLibForCopyDialog::askLibForCopyDialog( QWidget *parent,
libfwbuilder::FWObjectDatabase *db, libfwbuilder::FWObject *curr)
{
AskLibForCopyDialog dlg(parent, db, curr);
if ( dlg.exec() == QDialog::Accepted )
return dlg.getChoosenLib();
return 0;
}
AskLibForCopyDialog::~AskLibForCopyDialog()
{
delete m_dialog;
}
AskLibForCopyDialog::AskLibForCopyDialog( QWidget *parent, FWObjectDatabase *db,
libfwbuilder::FWObject *curr):
QDialog(parent), m_db(db), m_curr(curr)
{
m_dialog = new Ui::asklibforcopydialog_q;
m_dialog->setupUi(this);
loadObjects();
}
void AskLibForCopyDialog::loadObjects()
{
FWObject *firstUserLib=NULL;
list<FWObject*> ll = m_db->getByType( Library::TYPENAME );
int ind = 0;
for (FWObject::iterator i=ll.begin(); i!=ll.end(); i++)
{
FWObject *lib = (*i);
if ((lib->getId()==DELETED_LIB &&
! st->getBool("UI/ShowDeletedObjects"))||
lib->getId() == STANDARD_LIB ||
lib->getId() == TEMPLATE_LIB)
continue;
int ind = addLib( lib );
if (m_curr == lib)
m_dialog->libs->setCurrentIndex(ind);
}
}
int AskLibForCopyDialog::addLib( FWObject *lib)
{
QString newlibname = QString::fromUtf8(lib->getName().c_str());
int N = m_dialog->libs->count();
int idx = 0;
vector<FWObject*>::iterator i1=idxToLibs.begin();
//vector<QTreeWidget*>::iterator i2=idxToTrees.begin();
for ( ; idx<N; ++idx,++i1)
if ( m_dialog->libs->itemText(idx) > newlibname ) break;
string icn=":/Icons/"+lib->getTypeName()+"/icon-tree";
//Resources::global_res->getObjResourceStr(lib,"icon-tree").c_str();
QPixmap pm;
if ( ! QPixmapCache::find( icn.c_str(), pm) )
{
pm.load( icn.c_str() );
QPixmapCache::insert( icn.c_str(), pm);
}
m_dialog->libs->insertItem( idx, pm, newlibname);
// idx=libs->count()-1;
m_dialog->libs->setCurrentIndex(idx);
idxToLibs.insert(i1,lib);
}
FWObject *AskLibForCopyDialog::getChoosenLib()
{
int ind = m_dialog->libs->currentIndex();
if (0 <= ind)
return idxToLibs[ind];
return 0;
}

View File

@@ -0,0 +1,61 @@
/*
Firewall Builder
Copyright (C) 2003 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
$Id: AskLibForCopyDialog.h,v 1.58 2007/01/08 02:11:48 vkurland Exp $
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 __ASKLIBFORCOPYDIALOG_H_
#define __ASKLIBFORCOPYDIALOG_H_
#include "config.h"
#include "global.h"
#include <ui_asklibforcopydialog_q.h>
namespace libfwbuilder{
class FWObject;
class FWObjectDatabase;
}
class AskLibForCopyDialog : public QDialog {
Q_OBJECT
private:
libfwbuilder::FWObjectDatabase *m_db;
std::vector<libfwbuilder::FWObject*> idxToLibs;
libfwbuilder::FWObject *m_curr;
Ui::asklibforcopydialog_q *m_dialog;
int getIdxForLib(libfwbuilder::FWObject* lib);
void loadObjects();
int addLib( libfwbuilder::FWObject *lib);
libfwbuilder::FWObject *getChoosenLib();
public:
AskLibForCopyDialog( QWidget *parent, libfwbuilder::FWObjectDatabase *db,
libfwbuilder::FWObject *curr = 0);
~AskLibForCopyDialog();
static libfwbuilder::FWObject *askLibForCopyDialog( QWidget *parent,
libfwbuilder::FWObjectDatabase *db, libfwbuilder::FWObject *curr = 0);
};
#endif

View File

@@ -877,6 +877,12 @@ void FWWindow::hideEvent( QHideEvent *ev)
QMainWindow::hideEvent(ev);
}
void FWWindow::back()
{
if (activeProject())
activeProject()->back();
}
void FWWindow::newObject()
{
if (activeProject())

View File

@@ -138,6 +138,7 @@ class FWWindow : public QMainWindow {
virtual void pasteRuleAbove();
virtual void pasteRuleBelow();
virtual void back();
virtual void newObject();
virtual void lockObject();
virtual void unlockObject();

View File

@@ -114,6 +114,7 @@
#include <iostream>
#include <algorithm>
#include "AskLibForCopyDialog.h"
using namespace std;
using namespace libfwbuilder;
@@ -2413,7 +2414,7 @@ FWObject* ObjectManipulator::createObject(FWObject *parent,
lib->getId()==DELETED_LIB ||
lib->isReadOnly() )
{
if (i>=m_objectManipulator->libs->count())
if (i >= m_objectManipulator->libs->count())
{
lib=getCurrentLib();
break;
@@ -2427,6 +2428,19 @@ FWObject* ObjectManipulator::createObject(FWObject *parent,
return actuallyCreateObject(parent,objType,objName,copyFrom);
}
FWObject* ObjectManipulator::copyObj2Tree(const QString &objType, const QString &objName,
libfwbuilder::FWObject *copyFrom)
{
if (!validateDialog()) return NULL;
FWObject *lib = AskLibForCopyDialog::askLibForCopyDialog(m_project, m_project->db());;
if (!lib)
return 0;
FWObject *parent=m_project->getStandardSlotForObject(lib, objType);
return actuallyCreateObject(parent, objType, objName, copyFrom);
}
FWObject* ObjectManipulator::actuallyCreateObject(FWObject *parent,
const QString &objType,
const QString &objName,
@@ -2445,6 +2459,7 @@ FWObject* ObjectManipulator::actuallyCreateObject(FWObject *parent,
parent->add(nobj);
insertSubtree(allItems[parent], nobj);
m_project->db()->setDirty(true);
return nobj;
}

View File

@@ -55,6 +55,7 @@ namespace libfwbuilder
class Firewall;
class Library;
}
class HistoryItem {
ObjectTreeViewItem *itm;
QString objId;
@@ -161,6 +162,8 @@ public slots:
const QString &objType,
const QString &objName,
libfwbuilder::FWObject *copyFrom=NULL);
libfwbuilder::FWObject * copyObj2Tree(const QString &objType, const QString &objName,
libfwbuilder::FWObject *copyFrom);
void newLibrary();
void newObject();

View File

@@ -334,7 +334,7 @@ void ObjectTreeView::updateTreeItems()
void ObjectTreeView::startDrag(Qt::DropActions supportedActions)
{
if (fwbdebug) qDebug("ObjectTreeView::dragObject");
qDebug("ObjectTreeView::dragObject"); // !!!!!
QTreeWidgetItem *ovi = currentItem();
ObjectTreeViewItem *otvi=dynamic_cast<ObjectTreeViewItem*>(ovi);
@@ -453,17 +453,15 @@ void ObjectTreeView::startDrag(Qt::DropActions supportedActions)
void ObjectTreeView::dragEnterEvent( QDragEnterEvent *ev)
{
ev->setAccepted( ev->mimeData()->hasFormat(FWObjectDrag::FWB_MIME_TYPE) );
ev->setAccepted(ev->mimeData()->hasFormat(FWObjectDrag::FWB_MIME_TYPE) );
ev->setDropAction(Qt::MoveAction);
}
void ObjectTreeView::dragMoveEvent( QDragMoveEvent *ev)
{
bool acceptE = false;
if (ev->mimeData()->hasFormat(FWObjectDrag::FWB_MIME_TYPE))
{
{
int hy;
// hy=header()->height(); // if header is shown
@@ -474,12 +472,16 @@ void ObjectTreeView::dragMoveEvent( QDragMoveEvent *ev)
ObjectTreeViewItem *otvi=dynamic_cast<ObjectTreeViewItem*>(ovi);
if (otvi==NULL)
{
qDebug("dragMoveEvent %d", acceptE);// !!!!!
ev->setAccepted(acceptE);
return;
}
FWObject *trobj = otvi->getFWObject();
qDebug("Group::cast(trobj)!=NULL %d", Group::cast(trobj)!=NULL);// !!!!!
qDebug("!m_project->isSystem(trobj) %d", !m_project->isSystem(trobj));// !!!!!
qDebug("!trobj->isReadOnly() %d", !trobj->isReadOnly());// !!!!!
/* the tree can accept drop only if it goes into a group and if that group
* validates the object and tree is not read-only
*/
@@ -489,6 +491,7 @@ void ObjectTreeView::dragMoveEvent( QDragMoveEvent *ev)
)
{
acceptE = true;
qDebug("dragMoveEvent %d", acceptE);// !!!!!
Group *g = Group::cast(trobj);
list<FWObject*> dragol;
@@ -542,10 +545,9 @@ void ObjectTreeView::dropEvent(QDropEvent *ev)
)
{
Group *g=Group::cast(trobj);
item_before_drag_started=NULL;
list<FWObject*> dragol;
if (FWObjectDrag::decode(ev, dragol))
{
for (list<FWObject*>::iterator i=dragol.begin();
@@ -555,7 +557,8 @@ void ObjectTreeView::dropEvent(QDropEvent *ev)
assert(dragobj!=NULL);
/* check for duplicates */
string cp_id=dragobj->getId();
const string cp_id=dragobj->getId();
qDebug("dropEvent allowed %s", cp_id.c_str());// !!!!!
list<FWObject*>::iterator j;
for(j=g->begin(); j!=g->end(); ++j)
{
@@ -567,7 +570,9 @@ void ObjectTreeView::dropEvent(QDropEvent *ev)
cp_id==ref->getPointerId()) return;
}
g->addRef(dragobj);
QString n=QString::fromUtf8(dragobj->getName().c_str());
m_project->copyObj2Tree(dragobj->getTypeName().c_str(), n, dragobj);
//g->addRef(dragobj);
}
clearSelection();

View File

@@ -1226,6 +1226,13 @@ libfwbuilder::FWObject* ProjectPanel::createObject(libfwbuilder::FWObject *paren
return m_panel->om->createObject(parent, objType, objName, copyFrom);
}
FWObject* ProjectPanel::copyObj2Tree(const QString &objType, const QString &objName,
FWObject *copyFrom)
{
return m_panel->om->copyObj2Tree(objType, objName, copyFrom);
}
void ProjectPanel::moveObject(libfwbuilder::FWObject *target,
libfwbuilder::FWObject *obj)
{

View File

@@ -101,6 +101,7 @@ public:
void loadObjects(libfwbuilder::FWObjectDatabase *db);
void clearObjects();
libfwbuilder::FWObjectDatabase* db() { return objdb; }
bool hasObject(libfwbuilder::FWObject* obj) { return objdb->findInIndex(obj->getId()); };
//wrapers for some ObjectManipulator functions
libfwbuilder::FWObject* getOpened();
@@ -115,6 +116,10 @@ public:
const QString &objName,
libfwbuilder::FWObject *copyFrom=NULL);
libfwbuilder::FWObject* copyObj2Tree(const QString &objType,
const QString &objName,
libfwbuilder::FWObject *copyFrom=NULL);
void moveObject(libfwbuilder::FWObject *target,
libfwbuilder::FWObject *obj);

View File

@@ -2506,12 +2506,23 @@ void RuleSetView::deleteObject(int row, int col, FWObject *obj)
m_project->findObjectWidget->reset();
}
bool RuleSetView::insertObjectFromOther(int row, int col, FWObject *obj)
{
QString n=QString::fromUtf8(obj->getName().c_str());
if (!m_project->hasObject(obj))
{
obj = m_project->copyObj2Tree(obj->getTypeName().c_str(), n, obj);
if (!obj) return false;
}
return insertObject(row, col, obj);
}
bool RuleSetView::insertObject(int row, int col, FWObject *obj)
{
if (fwbdebug)
qDebug("RuleSetView::insertObject -- insert object %s",
obj->getName().c_str());
if (!isTreeReadWrite(this,ruleset)) return false;
if (getColType(col)!=Object && getColType(col)!=Time) return false;
@@ -3002,15 +3013,14 @@ void RuleSetView::dropEvent( QDropEvent *ev)
if (ev->source()!=this)
{
insertObject(row,col,dragobj);
insertObjectFromOther(row, col, dragobj);
} else
{
clearSelection();
if (ev->keyboardModifiers() & Qt::ControlModifier)
{
insertObject(row,col,dragobj); //copy
changeCurrentCell(row, col, true);
if (insertObject(row,col,dragobj)) //copy
changeCurrentCell(row, col, true);
}
else //move
{

View File

@@ -144,7 +144,7 @@ class RuleSetView : public QTableView
friend class RuleDelegate;
Q_OBJECT
public slots:
void selectionChanged(const QItemSelection&, const QItemSelection&);
void restoreSelection(bool same_widget);
@@ -431,6 +431,7 @@ private:
QString chooseIcon(QString icn);
bool showCommentTip(QPoint pos, QHelpEvent *he);
void drawComment(QPainter &p, int row, int col, const QRect &cr);
bool insertObjectFromOther(int row, int col, libfwbuilder::FWObject *obj);
};

View File

@@ -0,0 +1,80 @@
<ui version="4.0" >
<class>asklibforcopydialog_q</class>
<widget class="QDialog" name="asklibforcopydialog_q" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>221</width>
<height>127</height>
</rect>
</property>
<property name="windowTitle" >
<string>Copying</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Object will be copied to library:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="libs" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>asklibforcopydialog_q</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>asklibforcopydialog_q</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -118,8 +118,9 @@ HEADERS += ../../config.h \
FindWhereUsedWidget.h \
ConfirmDeleteObjectDialog.h \
FakeWizard.h \
AskLibForCopyDialog.h \
FWBAboutDialog.h \
fwbuilder_ph.h
fwbuilder_ph.h
SOURCES += ProjectPanel.cpp \
FWWindow.cpp \
@@ -223,8 +224,9 @@ SOURCES += ProjectPanel.cpp \
MetricEditorPanel.cpp \
FindWhereUsedWidget.cpp \
ConfirmDeleteObjectDialog.cpp \
FakeWizard.cpp
FakeWizard.cpp \
AskLibForCopyDialog.cpp
FORMS = FWBMainWindow_q.ui \
execdialog_q.ui \
customservicedialog_q.ui \
@@ -294,7 +296,8 @@ FORMS = FWBMainWindow_q.ui \
metriceditorpanel_q.ui \
findwhereusedwidget_q.ui \
confirmdeleteobjectdialog_q.ui\
projectpanel_q.ui
projectpanel_q.ui\
asklibforcopydialog_q.ui
contains( HAVE_ANTLR_RUNTIME, 1 ){
INCLUDEPATH += $$ANTLR_INCLUDEPATH

View File

@@ -132,7 +132,7 @@ static QString objid;
QApplication *app = NULL;
FWWindow *mw = NULL;
FWBSettings *st = NULL;
int fwbdebug = 1;
int fwbdebug = 0;
bool safemode = false;
bool registered = false;
bool gui_experiment1 = false;
@@ -342,7 +342,7 @@ int main( int argc, char ** argv )
filename="";
objid="";
fwbdebug=1;
fwbdebug=0;
safemode=false;
if(fwbdebug)
@@ -646,7 +646,7 @@ int main( int argc, char ** argv )
if (fwbdebug) qDebug("loading translation for the current locale ...");
QString local = QLocale::system().name();
QString local = "en_US";//QLocale::system().name();
QTranslator translator(0);
translator.load(QLatin1String("fwbuilder_") +
QString(local), localepath.c_str());