diff --git a/src/gui/FWWindow.h b/src/gui/FWWindow.h index 06473928f..2e9b6f537 100644 --- a/src/gui/FWWindow.h +++ b/src/gui/FWWindow.h @@ -166,7 +166,7 @@ public slots: ~FWWindow(); QMdiArea* getMdiArea () {return m_space;} RCS * getRCS(); - + static int printFirewallFromFile (QString fileName, QString firewallName, QString outputFileName); libfwbuilder::FWObject* getVisibleFirewalls(); void load(QWidget *dialogs_parent,RCS *rcs); void load(QWidget *dialogs_parent); diff --git a/src/gui/FWWindowPrint.cpp b/src/gui/FWWindowPrint.cpp index 0ac07b880..6a9b980a9 100644 --- a/src/gui/FWWindowPrint.cpp +++ b/src/gui/FWWindowPrint.cpp @@ -977,3 +977,190 @@ void FWWindow::filePrint() } +int FWWindow::printFirewallFromFile (QString fileName, QString firewallName, QString outputFileName) +{ + if (outputFileName=="") + { + outputFileName = "print.pdf"; + } + if (firewallName=="") + { + return -1; + } + if (fileName=="") + { + return -1; + } + FWObjectDatabase * objdb = new FWObjectDatabase(); + QPrinter *printer = new QPrinter(QPrinter::HighResolution); + objdb->load(fileName.toLatin1().constData(), NULL,librespath); + FWObject* obj = objdb->findObjectByName(Firewall::TYPENAME,firewallName.toAscii().data()); + if (obj!=NULL) + { + int pageWidth = 0; + int pageHeight = 0; + bool fullPage = false; + + float margin = 0; + int resolution = 150; + bool printHeader = true; + bool printLegend = true; + bool printObjects = true; + bool newPageForSection = false; + int tableResolution = 2; // 50%, 75%, 100%, 150%, 200%, default 100% + + if (!st->getStr("PrintSetup/newPageForSection").isEmpty()) + newPageForSection = st->getBool("PrintSetup/newPageForSection"); + + if (!st->getStr("PrintSetup/printHeader").isEmpty()) + printHeader = st->getBool("PrintSetup/printHeader"); + + if (!st->getStr("PrintSetup/printLegend").isEmpty()) + printLegend = st->getBool("PrintSetup/printLegend"); + + if (!st->getStr("PrintSetup/printObjects").isEmpty()) + printObjects = st->getBool("PrintSetup/printObjects"); + + if (!st->getStr("PrintSetup/tableResolution").isEmpty()) + tableResolution = st->getInt("PrintSetup/tableResolution"); + + switch (tableResolution) + { + case 0: resolution = 300; break; + case 1: resolution = 225; break; + case 2: resolution = 150; break; + case 3: resolution = 100; break; + case 4: resolution = 75; break; + } + + st->getPrinterOptions(printer,pageWidth,pageHeight); + + printer->setResolution(resolution); + printer->setFullPage(fullPage); + printer->setOutputFileName (outputFileName); + int fromPage = 1; + int toPage = 9999; + + + QString headerText = fileName; //mw->printHeader(); + printerStream pr(printer,margin,printHeader,headerText,NULL); + + pr.setFromTo(fromPage,toPage); + + if ( !pr.begin()) + { + return -1; + } + + int leftMargin = printer->paperRect().left() - printer->pageRect().left(); + int topMargin = printer->paperRect().top() - printer->pageRect().top(); + + if (fwbdebug) + { + qDebug("Margins: %d,%d",leftMargin,topMargin); + } + +// int ppdCounter = 1; + printFirewall(obj,pr,NULL,newPageForSection, NULL); + + if (printLegend) + { + if (fwbdebug) qDebug("******** Legend"); + + if (newPageForSection) + { + pr.flushPage(); + pr.beginPage(); // resets yPos + } else + pr.printText("\n"); + + pr.printText(tr("Legend")); + pr.printText(" "); + + QTableWidget legendTbl(1,2); + legendTbl.resize(pr.getWorkspaceWidth(), + pr.getWorkspaceHeight()); + legendTbl.setSizePolicy( QSizePolicy( (QSizePolicy::Policy)7, + (QSizePolicy::Policy)7) ); + legendTbl.setShowGrid(false); + legendTbl.setFrameStyle(QFrame::NoFrame | QFrame::Plain); + + legendTbl.horizontalHeader()->hide(); + legendTbl.verticalHeader()->hide(); + //legendTbl.setTopMargin(0); + //legendTbl.setLeftMargin(0); + + legendTbl.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + legendTbl.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + + string icon_path="/FWBuilderResources/Type/"; + int row=0; + int col=0; + + QPixmap pm; + + QPixmap bfr(32,32); + QPainter bfrp(&bfr); + + for (int i=0; !legendList[i].isEmpty(); ++i,++i) + { + if (row>=legendTbl.rowCount()) legendTbl.insertRow(row); + + QString typeName=legendList[i]; + QString objName=legendList[i+1]; + + if (typeName==CustomService::TYPENAME) + { + col++; + row=0; + } + + if (fwbdebug) + qDebug("Legend table: row=%d col=%d %s %s", + row,col,typeName.toAscii().constData(),objName.toAscii().constData()); + +// pm.load( Resources::global_res->getResourceStr( +// icon_path+string(typeName.toLatin1().constData())+"/icon").c_str() ); + + QString icn = ":/Icons/"+typeName+"/icon"; + QPixmap pm; + if ( ! QPixmapCache::find( icn, pm) ) + { + pm.load( icn ); + QPixmapCache::insert( icn, pm); + } + + bfrp.fillRect(0,0,32,32,QColor(Qt::white)); + bfrp.drawPixmap(4,4,pm); + + QTableWidgetItem *itm = new QTableWidgetItem; + itm->setIcon(QIcon(bfr)); + itm->setText(objName); + legendTbl.setItem(row, col, itm); + + row++; + } + + legendTbl.resizeColumnToContents(0); + legendTbl.resizeColumnToContents(1); + + for (int i=0; i om_selected_objects = - m_project->getCurrentObjectTree()->getSelectedObjects(); + if (m_project!=NULL) // For printing without creating ProjectPanel + om_selected_objects = m_project->getCurrentObjectTree()->getSelectedObjects(); if (mwSelObj==NULL && om_selected_objects.size()!=0) mwSelObj = om_selected_objects.front(); @@ -3500,8 +3501,10 @@ void RuleSetView::negateRE() QVector RuleSetView::getAllMdiProjectPanel () { QVector ret ; - QList subWindowList = mw->getMdiArea()->subWindowList(); - if (m_project->getRCS()==NULL) + QList subWindowList ; + if (mw!=NULL) + subWindowList = mw->getMdiArea()->subWindowList(); + if (m_project == NULL || m_project->getRCS()==NULL) return ret ; ret.push_back (m_project); QString fileName = m_project->getRCS()->getFileName(); diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 456c63ba8..93dd4c886 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -344,6 +344,8 @@ int main( int argc, char ** argv ) objid=""; fwbdebug=0; safemode=false; + bool pparam=false; + QString pparamValue=""; if(fwbdebug) qDebug("main()"); @@ -575,6 +577,9 @@ int main( int argc, char ** argv ) case 'g': gui_experiment1 = true; break; + case 'p': + pparam=true ; + pparamValue=optarg; } if ( (argc-1)==optind) @@ -613,6 +618,11 @@ int main( int argc, char ** argv ) #ifdef ELC registered=init2(argv0, "Firewall Builder","fwb_gui","FirewallBuilder/2.1",true,true); #endif + if (pparam) + { + FWWindow::printFirewallFromFile(filename,pparamValue,objid); + return 0; + } string full_res_path = respath+FS_SEPARATOR+"resources.xml";