# # Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher # --- zipsc_0.4.3/MainWindow.cpp~gcc3 2002-07-06 09:46:25.000000000 +0200 +++ zipsc_0.4.3/MainWindow.cpp 2004-02-20 17:23:03.000000000 +0100 @@ -1,476 +1,477 @@ -/********************************************************************** -** Copyright (C) 2002 Walter Rawdanik. All rights reserved. -** -** This file is part of zipsc application for Qtopia Environment. -** -** Issues: -** Due to incomplete design of QueryResult which returns pointer instead of object, it needs to be explicitly -** deleted after each use. Extremely error-prone and basically pain-in the ass. -** I am still no 100% sure I completely understand Qt layouts. It seems that QComboBox grows to the size of the -** widest string in it which causes it to go beyond the edge of the screen on Qtopia small screen. -** The only solution I could find was to call setMaximumSize() on each with some hard coded magic number that -** looks about right - not a good solution. -** -** -** This file may be distributed and/or modified under the terms of the -** GPL license appearing in the file LICENSE included in the -** packaging of this file. -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -**********************************************************************/ -#include -#include -#include -#include "MainWindow.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "InputDialog.h" -#include -#include - -AboutDialog::AboutDialog(const QPixmap &icon,const QString &caption, const QString &t,const QString &l,QWidget *parent):QDialog(parent,0,true) -{ - setCaption(caption); - - if ( parent ) - { - setPalette(parent->palette()); - } - - setMinimumSize(220,160); - QGridLayout *gl= new QGridLayout(this,2,2,4,2); - gl->addRowSpacing ( 0,0); - pix=new QLabel(this); - pix->setPixmap(icon); - gl->addWidget(pix,0,0); - title=new QLabel(t,this); - gl->addWidget(title,0,1); - label=new QLabel(l,this); - gl->addMultiCellWidget(label,1,1,0,1); - -} - -void AboutDialog::displayAbout(const QPixmap &icon,const QString &caption,const QString &t, const QString &text, QWidget *parent) -{ - AboutDialog *dlg=new AboutDialog(icon,caption,t,text,parent); - dlg->exec(); - delete dlg; -} - -MainWindow::MainWindow( QWidget* parent, const char* name, WFlags f ) -: QMainWindow( parent, name, f ) -{ - setCaption("zIPSC"); - - lColor="#f8f8f8"; - dColor="#e8e8e8"; - fColor="#848484"; - memset(&n, 0, sizeof(n)); - processType=true; - - QBoxLayout *topLayout=new QVBoxLayout(this,1); - - - //QFrame *topFrame=new QFrame (this); - //topFrame->setMaximumWidth(240); - - QGridLayout *gl= new QGridLayout(this,3,6,2,2); - gl->addColSpacing ( 1,4); - - topLayout->addLayout(gl); - gl->setColStretch(0,0); - gl->setColStretch(2,10); - - QLabel *lb=new QLabel("Address:",this); - gl->addWidget(lb,0,0); - networkAddress= new QComboBox(true,this); - gl->addMultiCellWidget(networkAddress,0,0,2,4); - go= new QPushButton("Go",this); - gl->addWidget(go,0,5); - lb=new QLabel("Type:",this); - gl->addWidget(lb,1,0); - - addressType= new MenuButton ( this); - addressType->insertItem("Class A (1.x.x.x - 126.x.x.x)"); - addressType->insertItem("Class B (128.x.x.x - 191.x.x.x)"); - addressType->insertItem("Class C (192.x.x.x - 223.x.x.x)"); - gl->addMultiCellWidget(addressType,1,1,2,5); - - bitsLabel=new QLabel("Subnet bits:",this); - gl->addWidget(bitsLabel,2,0); - subnetBits= new QSpinBox(this); - gl->addWidget(subnetBits,2,2,AlignLeft); - - saveB=new QToolButton(this); - saveB->setAutoRaise(false); - saveB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/filesave.png_")); - gl->addWidget(saveB,2,3); - copyB=new QToolButton(this); - copyB->setAutoRaise(false); - copyB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/editcopy.png_")); - gl->addWidget(copyB,2,4); - aboutB=new QToolButton(this); - aboutB->setAutoRaise(false); - aboutB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/about.png_")); - gl->addWidget(aboutB,2,5); - - topLayout->addSpacing(4); - - int i; - - switcher= new QTabBar(this); - switcher->setShape(QTabBar::RoundedAbove); - - const char *tLabels[]={"General","Subnets/Hosts","Host","CIDR"}; - - for ( i=0;iaddTab(new QTab(tLabels[i])); - } - switcher->setCurrentTab(0); - topLayout->addWidget(switcher); - - - - pageView=new QWidgetStack(this); - for ( i=0;isetHScrollBarMode(QScrollView::AlwaysOff); - pageView->addWidget(pages[i],i); - } - - topLayout->addWidget(pageView,10); - - - initVariables(); - showPage(GENERAL_VIEW); - - - connect(switcher,SIGNAL(selected(int)),SLOT(showPage(int))); - connect(networkAddress->lineEdit(),SIGNAL(returnPressed()),SLOT(goButtonClicked())); - connect(go,SIGNAL(clicked()),SLOT(goButtonClicked())); - connect(addressType,SIGNAL(selected (int)),SLOT(typeButtonPressed(int))); - connect(subnetBits,SIGNAL(valueChanged (int)),SLOT(bitsChanged(int))); - connect(saveB,SIGNAL(clicked()),SLOT(saveFile())); - connect(copyB,SIGNAL(clicked()),SLOT(copyText())); - connect(aboutB,SIGNAL(clicked()),SLOT(displayAbout())); - - -} - -MainWindow::~MainWindow() -{ - saveVariables(); -} - - -void MainWindow::goButtonClicked() -{ - QString searchTerm=networkAddress->currentText(); - - if ( searchTerm.isEmpty() ) - return; - - if ( ipsc_network_init_parse_text(&n, searchTerm) < 0 ) - { - QMessageBox::warning (this,"zIPSC","Incorrect network address",0); - } - - ipsc_network_init_parse_text(&n,searchTerm); - updateAll(); - - // implement history .... if selected text already exists, delete it from the list ... if there are more than 10 items delete last used - QListBox *lb=networkAddress->listBox(); - - for ( unsigned int i=0;icount();i++ ) - { - if ( searchTerm.upper()==lb->text(i).upper() ) - { - lb->removeItem(i); - break; - } - } - if ( networkAddress->count()>16 ) - networkAddress->removeItem(networkAddress->count()-1); - networkAddress->insertItem(searchTerm,0); - - processType=false; - subnetBits->setValue(n.subnet_bits); - addressType->select((int)(tolower(n.nclass)-'a')); - processType=true; - -} - -void MainWindow::typeButtonPressed(int i) -{ - if ( processType ) - { - char cl='a'+(int)i; - - ipsc_network_set_class_info(&n, cl, TRUE); - ipsc_network_init(&n); - updateAll(); - - QString tmp; - tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n)); - networkAddress->lineEdit()->setText(tmp); - } -} - -void MainWindow::bitsChanged(int b) -{ - n.subnet_bits=b; - ipsc_network_init(&n); - QString tmp; - tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n)); - networkAddress->lineEdit()->setText(tmp); - updateAll(); -} - -void MainWindow::showPage(int t) -{ - if ( t==CIDR_VIEW ) - { - bitsLabel->setText("Supnet bits"); - subnetBits->setMaxValue(31); - } - else - { - bitsLabel->setText("Subnet bits"); - subnetBits->setMaxValue(n.subnet_bits_max); - } - pageView->raiseWidget(t); - -} - - - -void MainWindow::updateAll() -{ - subnetBits->setMaxValue(n.subnet_bits_max); - for ( unsigned int i=0;i"); - text.append(""); - - switch ( t ) - { - case GENERAL_VIEW: - updateGPage(text); - break; - case SUBNETS_VIEW: - updateSPage(text); - break; - case HOST_VIEW: - updateHPage(text); - break; - case CIDR_VIEW: - updateCPage(text); - break; - } - - text.append("
"); - - pages[t]->setText(text); - -} - -void MainWindow::updateGPage(QString &s) -{ - s.append("Subnet maximumAddresses/Subnet"); - s.append(""+QString::number(n.subnet_max)+ - ""+QString::number(n.host_max)+""); - s.append("Bitmap (network,subnet,host)"); - s.append(""+QString(n.bitmap)+""); - s.append("Class MaskHex Class Mask"); - QString tmp; - int fmask=ipsc_network_get_full_mask(&n); - tmp.sprintf("%X",n.mask); - s.append(""+QString(denumberize(n.mask))+ - ""+tmp+""); - s.append("Full Subnet MaskFull Hex Subnet Mask"); - tmp.sprintf("%X",fmask); - s.append(""+QString(denumberize(fmask))+ - ""+tmp+""); -} - -void MainWindow::updateSPage(QString &s) -{ - s.append("SubnetAddress range"); - - unsigned int subnet_addr = n.addr; - QString tmp; - - for ( unsigned int i = 0; i < n.subnet_max; i++ ) - { - tmp.sprintf("%s - ",denumberize(subnet_addr)); - tmp.append(denumberize((subnet_addr + n.host_max-1))); - if ( ipsc_host_is_on_subnet(subnet_addr,&n) ) - { - tmp.append(" *"); - } - s.append(""+ QString::number(i+1)+ - ""+tmp+""); - subnet_addr += n.host_max; - if ( i==256 ) - { - s.append(""+ QString::number(n.subnet_max-i-1)+ - " more subnets ..."); - break; - } - } -} - -void MainWindow::updateHPage(QString &s) -{ - unsigned int lbound = ipsc_network_get_host_subnet_first_host(&n); - unsigned int ubound = ipsc_network_get_host_subnet_last_host(&n); - - QString tmp; - tmp.sprintf("%X",n.host_addr); - s.append("IP AddressHex IP Address"); - s.append(""+QString(denumberize(n.host_addr))+ - ""+tmp+""); - tmp.sprintf("%s - ",denumberize(lbound)); - tmp.append(denumberize(ubound)); - s.append("Host Allocation Range"); - s.append(""+tmp+""); - s.append("Subnet MaskSubnet ID"); - s.append(""+QString(denumberize(n.subnet_mask))+ - ""+QString(denumberize( ipsc_network_get_subnet_id(&n)))+""); - s.append("Network IDHost ID"); - s.append(""+QString(denumberize( ipsc_network_get_network_id(&n)))+ - ""+QString(denumberize(n.host_id))+""); -} - -void MainWindow::updateCPage(QString &s) -{ - QString tmp; - - tmp.sprintf("%s/%d", denumberize(n.addr),ipsc_network_get_prefix_bits(&n)); - - s.append("CIDR NotationSupernet Maximum"); - s.append(""+tmp+ - ""+QString::number(ipsc_network_get_supernet_max(&n))+""); - tmp.sprintf("%s/%d", denumberize(n.addr), n.bits); - s.append("Classful NetworkCisco Wildcard"); - s.append(""+tmp+ - ""+QString(denumberize(n.cisco_wildcard))+""); - tmp.sprintf("%s / ", denumberize(n.addr)); - tmp.append(denumberize(ipsc_network_get_full_mask(&n))); - s.append("Route/Mask"); - s.append(""+tmp+""); - tmp.sprintf("%X / %X", n.addr,ipsc_network_get_full_mask(&n)); - s.append("Hex Route/Mask"); - s.append(""+tmp+""); - - -} - -void MainWindow::saveVariables() -{ - Config cfg("zIPSC"); - cfg.setGroup("zIPSC"); - - QStringList ls; - - for ( int i=0;icount();i++ ) - { - ls.append(networkAddress->text(i)); - } - QString tmp; - tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n)); - cfg.writeEntry("NetAddress",tmp); - cfg.writeEntry("SubnetBits",(int)n.subnet_bits); - cfg.writeEntry("HItems",ls,'|'); -} - -void MainWindow::initVariables() -{ - Config cfg("zIPSC"); - cfg.setGroup("zIPSC"); - - networkAddress->insertStringList ( cfg.readListEntry("HItems",'|')); - QString net=cfg.readEntry("NetAddress","127.0.0.1/8"); - networkAddress->lineEdit()->setText(net); - ipsc_network_init_parse_text(&n,net.latin1()); - n.subnet_bits=cfg.readNumEntry ("SubnetBits", 0 ); - ipsc_network_init(&n); - subnetBits->setMaxValue(n.subnet_bits_max); - subnetBits->setValue(n.subnet_bits); - processType=false; - addressType->select((int)(tolower(n.nclass)-'a')); - processType=true; - updateAll(); -} - -void MainWindow::saveFile() -{ - QString tmp; - tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n)); - tmp.replace(QRegExp("[./]"),"_"); - tmp.append(".txt"); - QString fileName=InputDialog::getText("zIPSC","Save as ...",tmp,this); - if ( fileName.isEmpty() ) - return; - fileName=QDir::home().absFilePath(fileName); - FILE *f; - - if ( (f = fopen((const char *)fileName.latin1() , "a")) == NULL ) - { - QMessageBox::warning (this,"zIPSC","Error creating "+ fileName +".",0); - return; - } - ipsc_network_fprint_general(&n, f); - ipsc_network_fprint_host(&n, f); - ipsc_network_fprint_cidr(&n, f); - fclose(f); - -} - -void MainWindow::copyText() -{ - QTextBrowser *tb=(QTextBrowser*)pageView->visibleWidget(); - if ( tb && tb->hasSelectedText() ) - { - tb->copy(); - } -} - -void MainWindow::displayAbout() -{ - - AboutDialog::displayAbout(QPixmap(QPEApplication::qpeDir()+"pics/zipsc.png"), - "zIPSC","

zIPSC

", - "
IP subnet calculator

Ported to Qtopia by Walter Rawdanik (zaurus@warmi.net) -

Based on 'IPSC' (http://ipsc.sourceforge.net/software.html)

Licensed under GNU General Public License", - this);} - - - +/********************************************************************** +** Copyright (C) 2002 Walter Rawdanik. All rights reserved. +** +** This file is part of zipsc application for Qtopia Environment. +** +** Issues: +** Due to incomplete design of QueryResult which returns pointer instead of object, it needs to be explicitly +** deleted after each use. Extremely error-prone and basically pain-in the ass. +** I am still no 100% sure I completely understand Qt layouts. It seems that QComboBox grows to the size of the +** widest string in it which causes it to go beyond the edge of the screen on Qtopia small screen. +** The only solution I could find was to call setMaximumSize() on each with some hard coded magic number that +** looks about right - not a good solution. +** +** +** This file may be distributed and/or modified under the terms of the +** GPL license appearing in the file LICENSE included in the +** packaging of this file. +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ +#include +#include +#include +#include "MainWindow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "InputDialog.h" +#include +#include + +AboutDialog::AboutDialog(const QPixmap &icon,const QString &caption, const QString &t,const QString &l,QWidget *parent):QDialog(parent,0,true) +{ + setCaption(caption); + + if ( parent ) + { + setPalette(parent->palette()); + } + + setMinimumSize(220,160); + QGridLayout *gl= new QGridLayout(this,2,2,4,2); + gl->addRowSpacing ( 0,0); + pix=new QLabel(this); + pix->setPixmap(icon); + gl->addWidget(pix,0,0); + title=new QLabel(t,this); + gl->addWidget(title,0,1); + label=new QLabel(l,this); + gl->addMultiCellWidget(label,1,1,0,1); + +} + +void AboutDialog::displayAbout(const QPixmap &icon,const QString &caption,const QString &t, const QString &text, QWidget *parent) +{ + AboutDialog *dlg=new AboutDialog(icon,caption,t,text,parent); + dlg->exec(); + delete dlg; +} + +MainWindow::MainWindow( QWidget* parent, const char* name, WFlags f ) +: QMainWindow( parent, name, f ) +{ + setCaption("zIPSC"); + + lColor="#f8f8f8"; + dColor="#e8e8e8"; + fColor="#848484"; + memset(&n, 0, sizeof(n)); + processType=true; + + QBoxLayout *topLayout=new QVBoxLayout(this,1); + + + //QFrame *topFrame=new QFrame (this); + //topFrame->setMaximumWidth(240); + + QGridLayout *gl= new QGridLayout(this,3,6,2,2); + gl->addColSpacing ( 1,4); + + topLayout->addLayout(gl); + gl->setColStretch(0,0); + gl->setColStretch(2,10); + + QLabel *lb=new QLabel("Address:",this); + gl->addWidget(lb,0,0); + networkAddress= new QComboBox(true,this); + gl->addMultiCellWidget(networkAddress,0,0,2,4); + go= new QPushButton("Go",this); + gl->addWidget(go,0,5); + lb=new QLabel("Type:",this); + gl->addWidget(lb,1,0); + + addressType= new MenuButton ( this); + addressType->insertItem("Class A (1.x.x.x - 126.x.x.x)"); + addressType->insertItem("Class B (128.x.x.x - 191.x.x.x)"); + addressType->insertItem("Class C (192.x.x.x - 223.x.x.x)"); + gl->addMultiCellWidget(addressType,1,1,2,5); + + bitsLabel=new QLabel("Subnet bits:",this); + gl->addWidget(bitsLabel,2,0); + subnetBits= new QSpinBox(this); + gl->addWidget(subnetBits,2,2,AlignLeft); + + saveB=new QToolButton(this); + saveB->setAutoRaise(false); + saveB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/filesave.png_")); + gl->addWidget(saveB,2,3); + copyB=new QToolButton(this); + copyB->setAutoRaise(false); + copyB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/editcopy.png_")); + gl->addWidget(copyB,2,4); + aboutB=new QToolButton(this); + aboutB->setAutoRaise(false); + aboutB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/about.png_")); + gl->addWidget(aboutB,2,5); + + topLayout->addSpacing(4); + + int i; + + switcher= new QTabBar(this); + switcher->setShape(QTabBar::RoundedAbove); + + const char *tLabels[]={"General","Subnets/Hosts","Host","CIDR"}; + + for ( i=0;iaddTab(new QTab(tLabels[i])); + } + switcher->setCurrentTab(0); + topLayout->addWidget(switcher); + + + + pageView=new QWidgetStack(this); + for ( i=0;isetHScrollBarMode(QScrollView::AlwaysOff); + pageView->addWidget(pages[i],i); + } + + topLayout->addWidget(pageView,10); + + + initVariables(); + showPage(GENERAL_VIEW); + + + connect(switcher,SIGNAL(selected(int)),SLOT(showPage(int))); + connect(networkAddress->lineEdit(),SIGNAL(returnPressed()),SLOT(goButtonClicked())); + connect(go,SIGNAL(clicked()),SLOT(goButtonClicked())); + connect(addressType,SIGNAL(selected (int)),SLOT(typeButtonPressed(int))); + connect(subnetBits,SIGNAL(valueChanged (int)),SLOT(bitsChanged(int))); + connect(saveB,SIGNAL(clicked()),SLOT(saveFile())); + connect(copyB,SIGNAL(clicked()),SLOT(copyText())); + connect(aboutB,SIGNAL(clicked()),SLOT(displayAbout())); + + +} + +MainWindow::~MainWindow() +{ + saveVariables(); +} + + +void MainWindow::goButtonClicked() +{ + QString searchTerm=networkAddress->currentText(); + + if ( searchTerm.isEmpty() ) + return; + + if ( ipsc_network_init_parse_text(&n, searchTerm) < 0 ) + { + QMessageBox::warning (this,"zIPSC","Incorrect network address",0); + } + + ipsc_network_init_parse_text(&n,searchTerm); + updateAll(); + + // implement history .... if selected text already exists, delete it from the list ... if there are more than 10 items delete last used + QListBox *lb=networkAddress->listBox(); + + for ( unsigned int i=0;icount();i++ ) + { + if ( searchTerm.upper()==lb->text(i).upper() ) + { + lb->removeItem(i); + break; + } + } + if ( networkAddress->count()>16 ) + networkAddress->removeItem(networkAddress->count()-1); + networkAddress->insertItem(searchTerm,0); + + processType=false; + subnetBits->setValue(n.subnet_bits); + addressType->select((int)(tolower(n.nclass)-'a')); + processType=true; + +} + +void MainWindow::typeButtonPressed(int i) +{ + if ( processType ) + { + char cl='a'+(int)i; + + ipsc_network_set_class_info(&n, cl, TRUE); + ipsc_network_init(&n); + updateAll(); + + QString tmp; + tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n)); + networkAddress->lineEdit()->setText(tmp); + } +} + +void MainWindow::bitsChanged(int b) +{ + n.subnet_bits=b; + ipsc_network_init(&n); + QString tmp; + tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n)); + networkAddress->lineEdit()->setText(tmp); + updateAll(); +} + +void MainWindow::showPage(int t) +{ + if ( t==CIDR_VIEW ) + { + bitsLabel->setText("Supnet bits"); + subnetBits->setMaxValue(31); + } + else + { + bitsLabel->setText("Subnet bits"); + subnetBits->setMaxValue(n.subnet_bits_max); + } + pageView->raiseWidget(t); + +} + + + +void MainWindow::updateAll() +{ + subnetBits->setMaxValue(n.subnet_bits_max); + for ( unsigned int i=0;i"); + text.append(""); + + switch ( t ) + { + case GENERAL_VIEW: + updateGPage(text); + break; + case SUBNETS_VIEW: + updateSPage(text); + break; + case HOST_VIEW: + updateHPage(text); + break; + case CIDR_VIEW: + updateCPage(text); + break; + } + + text.append("
"); + + pages[t]->setText(text); + +} + +void MainWindow::updateGPage(QString &s) +{ + s.append("Subnet maximumAddresses/Subnet"); + s.append(""+QString::number(n.subnet_max)+ + ""+QString::number(n.host_max)+""); + s.append("Bitmap (network,subnet,host)"); + s.append(""+QString(n.bitmap)+""); + s.append("Class MaskHex Class Mask"); + QString tmp; + int fmask=ipsc_network_get_full_mask(&n); + tmp.sprintf("%X",n.mask); + s.append(""+QString(denumberize(n.mask))+ + ""+tmp+""); + s.append("Full Subnet MaskFull Hex Subnet Mask"); + tmp.sprintf("%X",fmask); + s.append(""+QString(denumberize(fmask))+ + ""+tmp+""); +} + +void MainWindow::updateSPage(QString &s) +{ + s.append("SubnetAddress range"); + + unsigned int subnet_addr = n.addr; + QString tmp; + + for ( unsigned int i = 0; i < n.subnet_max; i++ ) + { + tmp.sprintf("%s - ",denumberize(subnet_addr)); + tmp.append(denumberize((subnet_addr + n.host_max-1))); + if ( ipsc_host_is_on_subnet(subnet_addr,&n) ) + { + tmp.append(" *"); + } + s.append(""+ QString::number(i+1)+ + ""+tmp+""); + subnet_addr += n.host_max; + if ( i==256 ) + { + s.append(""+ QString::number(n.subnet_max-i-1)+ + " more subnets ..."); + break; + } + } +} + +void MainWindow::updateHPage(QString &s) +{ + unsigned int lbound = ipsc_network_get_host_subnet_first_host(&n); + unsigned int ubound = ipsc_network_get_host_subnet_last_host(&n); + + QString tmp; + tmp.sprintf("%X",n.host_addr); + s.append("IP AddressHex IP Address"); + s.append(""+QString(denumberize(n.host_addr))+ + ""+tmp+""); + tmp.sprintf("%s - ",denumberize(lbound)); + tmp.append(denumberize(ubound)); + s.append("Host Allocation Range"); + s.append(""+tmp+""); + s.append("Subnet MaskSubnet ID"); + s.append(""+QString(denumberize(n.subnet_mask))+ + ""+QString(denumberize( ipsc_network_get_subnet_id(&n)))+""); + s.append("Network IDHost ID"); + s.append(""+QString(denumberize( ipsc_network_get_network_id(&n)))+ + ""+QString(denumberize(n.host_id))+""); +} + +void MainWindow::updateCPage(QString &s) +{ + QString tmp; + + tmp.sprintf("%s/%d", denumberize(n.addr),ipsc_network_get_prefix_bits(&n)); + + s.append("CIDR NotationSupernet Maximum"); + s.append(""+tmp+ + ""+QString::number(ipsc_network_get_supernet_max(&n))+""); + tmp.sprintf("%s/%d", denumberize(n.addr), n.bits); + s.append("Classful NetworkCisco Wildcard"); + s.append(""+tmp+ + ""+QString(denumberize(n.cisco_wildcard))+""); + tmp.sprintf("%s / ", denumberize(n.addr)); + tmp.append(denumberize(ipsc_network_get_full_mask(&n))); + s.append("Route/Mask"); + s.append(""+tmp+""); + tmp.sprintf("%X / %X", n.addr,ipsc_network_get_full_mask(&n)); + s.append("Hex Route/Mask"); + s.append(""+tmp+""); + + +} + +void MainWindow::saveVariables() +{ + Config cfg("zIPSC"); + cfg.setGroup("zIPSC"); + + QStringList ls; + + for ( int i=0;icount();i++ ) + { + ls.append(networkAddress->text(i)); + } + QString tmp; + tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n)); + cfg.writeEntry("NetAddress",tmp); + cfg.writeEntry("SubnetBits",(int)n.subnet_bits); + cfg.writeEntry("HItems",ls,'|'); +} + +void MainWindow::initVariables() +{ + Config cfg("zIPSC"); + cfg.setGroup("zIPSC"); + + networkAddress->insertStringList ( cfg.readListEntry("HItems",'|')); + QString net=cfg.readEntry("NetAddress","127.0.0.1/8"); + networkAddress->lineEdit()->setText(net); + ipsc_network_init_parse_text(&n,net.latin1()); + n.subnet_bits=cfg.readNumEntry ("SubnetBits", 0 ); + ipsc_network_init(&n); + subnetBits->setMaxValue(n.subnet_bits_max); + subnetBits->setValue(n.subnet_bits); + processType=false; + addressType->select((int)(tolower(n.nclass)-'a')); + processType=true; + updateAll(); +} + +void MainWindow::saveFile() +{ + QString tmp; + tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n)); + tmp.replace(QRegExp("[./]"),"_"); + tmp.append(".txt"); + QString fileName=InputDialog::getText("zIPSC","Save as ...",tmp,this); + if ( fileName.isEmpty() ) + return; + fileName=QDir::home().absFilePath(fileName); + FILE *f; + + if ( (f = fopen((const char *)fileName.latin1() , "a")) == NULL ) + { + QMessageBox::warning (this,"zIPSC","Error creating "+ fileName +".",0); + return; + } + ipsc_network_fprint_general(&n, f); + ipsc_network_fprint_host(&n, f); + ipsc_network_fprint_cidr(&n, f); + fclose(f); + +} + +void MainWindow::copyText() +{ + QTextBrowser *tb=(QTextBrowser*)pageView->visibleWidget(); + if ( tb && tb->hasSelectedText() ) + { + tb->copy(); + } +} + +void MainWindow::displayAbout() +{ + + AboutDialog::displayAbout(QPixmap(QPEApplication::qpeDir()+"pics/zipsc.png"), + "zIPSC","

zIPSC

", + "
IP subnet calculator

Ported to Qtopia by Walter Rawdanik (zaurus@warmi.net) " + "

Based on 'IPSC' (http://ipsc.sourceforge.net/software.html)

Licensed under GNU General Public License", + this); +} + + +