]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/zipsc/zipsc-0.4.3/gcc3.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / zipsc / zipsc-0.4.3 / gcc3.patch
1
2 #
3 # Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
4 #
5
6 --- zipsc_0.4.3/MainWindow.cpp~gcc3     2002-07-06 09:46:25.000000000 +0200
7 +++ zipsc_0.4.3/MainWindow.cpp  2004-02-20 17:23:03.000000000 +0100
8 @@ -1,476 +1,477 @@
9 -/**********************************************************************\r
10 -** Copyright (C) 2002 Walter Rawdanik.  All rights reserved.\r
11 -**\r
12 -** This file is part of zipsc application for Qtopia Environment.\r
13 -**\r
14 -** Issues:\r
15 -** Due to incomplete design of QueryResult which returns pointer instead of object, it needs to be explicitly \r
16 -** deleted after each use. Extremely error-prone and basically pain-in the ass.\r
17 -** I am still no 100% sure I completely understand Qt layouts. It seems that QComboBox grows to the size of the\r
18 -** widest string in it which causes it to go beyond the edge of the screen on Qtopia small screen.\r
19 -** The only solution I could find was to call setMaximumSize() on each with some hard coded magic number that\r
20 -** looks about right - not a good solution.\r
21 -**\r
22 -**\r
23 -** This file may be distributed and/or modified under the terms of the\r
24 -** GPL license appearing in the file LICENSE included in the\r
25 -** packaging of this file.\r
26 -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE\r
27 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
28 -**                                                        \r
29 -**********************************************************************/\r
30 -#include <qpe/qpeapplication.h>\r
31 -#include <qpe/config.h>\r
32 -#include <qpe/fileselector.h>\r
33 -#include "MainWindow.h"\r
34 -#include <stdlib.h>\r
35 -#include <stdio.h>\r
36 -#include <ctype.h>\r
37 -#include <qlayout.h> \r
38 -#include <qframe.h>\r
39 -#include <qlistbox.h>\r
40 -#include <qlabel.h>\r
41 -#include <qcombobox.h> \r
42 -#include <qwidgetstack.h>\r
43 -#include <qlineedit.h>\r
44 -#include <qpushbutton.h>\r
45 -#include <qstringlist.h> \r
46 -#include <qmessagebox.h>\r
47 -#include <qtabbar.h>\r
48 -#include <qtoolbutton.h>\r
49 -#include <qtextbrowser.h>\r
50 -#include <qspinbox.h>\r
51 -#include <qpe/menubutton.h>\r
52 -#include <qpe/qpetoolbar.h>\r
53 -#include "InputDialog.h"\r
54 -#include <qdir.h>\r
55 -#include <qfile.h>\r
56 -\r
57 -AboutDialog::AboutDialog(const QPixmap &icon,const QString &caption, const QString &t,const QString &l,QWidget *parent):QDialog(parent,0,true)\r
58 -{\r
59 -    setCaption(caption);\r
60 -\r
61 -    if ( parent )\r
62 -    {\r
63 -        setPalette(parent->palette());\r
64 -    }\r
65 -\r
66 -    setMinimumSize(220,160);\r
67 -    QGridLayout  *gl= new QGridLayout(this,2,2,4,2); \r
68 -    gl->addRowSpacing ( 0,0); \r
69 -    pix=new QLabel(this);\r
70 -    pix->setPixmap(icon);\r
71 -    gl->addWidget(pix,0,0);\r
72 -    title=new QLabel(t,this);\r
73 -    gl->addWidget(title,0,1);\r
74 -    label=new QLabel(l,this);\r
75 -    gl->addMultiCellWidget(label,1,1,0,1);  \r
76 -\r
77 -}\r
78 -\r
79 -void AboutDialog::displayAbout(const QPixmap &icon,const QString &caption,const QString &t, const QString &text, QWidget *parent)\r
80 -{\r
81 -    AboutDialog *dlg=new AboutDialog(icon,caption,t,text,parent);\r
82 -    dlg->exec();\r
83 -    delete dlg;\r
84 -}\r
85 -\r
86 -MainWindow::MainWindow( QWidget* parent, const char* name, WFlags f )\r
87 -: QMainWindow( parent, name, f )\r
88 -{\r
89 -    setCaption("zIPSC");\r
90 -\r
91 -    lColor="#f8f8f8";\r
92 -    dColor="#e8e8e8";\r
93 -    fColor="#848484";\r
94 -    memset(&n, 0, sizeof(n));\r
95 -    processType=true;\r
96 -\r
97 -    QBoxLayout *topLayout=new QVBoxLayout(this,1);      \r
98 -\r
99 -\r
100 -    //QFrame   *topFrame=new QFrame (this);\r
101 -    //topFrame->setMaximumWidth(240);\r
102 -\r
103 -    QGridLayout  *gl= new QGridLayout(this,3,6,2,2); \r
104 -    gl->addColSpacing ( 1,4);  \r
105 -\r
106 -    topLayout->addLayout(gl);\r
107 -    gl->setColStretch(0,0);\r
108 -    gl->setColStretch(2,10);\r
109 -\r
110 -    QLabel *lb=new QLabel("Address:",this);\r
111 -    gl->addWidget(lb,0,0);\r
112 -    networkAddress= new QComboBox(true,this);\r
113 -    gl->addMultiCellWidget(networkAddress,0,0,2,4);\r
114 -    go= new QPushButton("Go",this);\r
115 -    gl->addWidget(go,0,5);\r
116 -    lb=new QLabel("Type:",this);\r
117 -    gl->addWidget(lb,1,0);\r
118 -\r
119 -    addressType= new MenuButton ( this);\r
120 -    addressType->insertItem("Class A (1.x.x.x - 126.x.x.x)");\r
121 -    addressType->insertItem("Class B (128.x.x.x - 191.x.x.x)");\r
122 -    addressType->insertItem("Class C (192.x.x.x - 223.x.x.x)");\r
123 -    gl->addMultiCellWidget(addressType,1,1,2,5);\r
124 -\r
125 -    bitsLabel=new QLabel("Subnet bits:",this);   \r
126 -    gl->addWidget(bitsLabel,2,0);\r
127 -    subnetBits= new QSpinBox(this);    \r
128 -    gl->addWidget(subnetBits,2,2,AlignLeft);             \r
129 -\r
130 -    saveB=new QToolButton(this);\r
131 -    saveB->setAutoRaise(false); \r
132 -    saveB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/filesave.png_"));\r
133 -    gl->addWidget(saveB,2,3);\r
134 -    copyB=new QToolButton(this);\r
135 -    copyB->setAutoRaise(false); \r
136 -    copyB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/editcopy.png_"));\r
137 -    gl->addWidget(copyB,2,4);\r
138 -    aboutB=new QToolButton(this);\r
139 -    aboutB->setAutoRaise(false); \r
140 -    aboutB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/about.png_"));\r
141 -    gl->addWidget(aboutB,2,5);\r
142 -\r
143 -    topLayout->addSpacing(4);\r
144 -\r
145 -    int i;\r
146 -\r
147 -    switcher= new QTabBar(this); \r
148 -    switcher->setShape(QTabBar::RoundedAbove);\r
149 -\r
150 -    const char *tLabels[]={"General","Subnets/Hosts","Host","CIDR"};\r
151 -\r
152 -    for ( i=0;i<T_LAST;i++ )\r
153 -    {\r
154 -        tabValues[i]=switcher->addTab(new QTab(tLabels[i]));\r
155 -    }\r
156 -    switcher->setCurrentTab(0);\r
157 -    topLayout->addWidget(switcher);\r
158 -\r
159 -\r
160 -\r
161 -    pageView=new QWidgetStack(this);\r
162 -    for ( i=0;i<T_LAST;i++ )\r
163 -    {\r
164 -        pages[i]=new QTextBrowser(pageView);\r
165 -        pages[i]->setHScrollBarMode(QScrollView::AlwaysOff);\r
166 -        pageView->addWidget(pages[i],i);       \r
167 -    }    \r
168 -\r
169 -    topLayout->addWidget(pageView,10); \r
170 -\r
171 -\r
172 -    initVariables();    \r
173 -    showPage(GENERAL_VIEW);\r
174 -\r
175 -\r
176 -    connect(switcher,SIGNAL(selected(int)),SLOT(showPage(int)));\r
177 -    connect(networkAddress->lineEdit(),SIGNAL(returnPressed()),SLOT(goButtonClicked()));\r
178 -    connect(go,SIGNAL(clicked()),SLOT(goButtonClicked()));\r
179 -    connect(addressType,SIGNAL(selected (int)),SLOT(typeButtonPressed(int)));\r
180 -    connect(subnetBits,SIGNAL(valueChanged (int)),SLOT(bitsChanged(int)));\r
181 -    connect(saveB,SIGNAL(clicked()),SLOT(saveFile()));\r
182 -    connect(copyB,SIGNAL(clicked()),SLOT(copyText()));\r
183 -    connect(aboutB,SIGNAL(clicked()),SLOT(displayAbout()));\r
184 -\r
185 -\r
186 -}\r
187 -\r
188 -MainWindow::~MainWindow()\r
189 -{\r
190 -    saveVariables();        \r
191 -}\r
192 -\r
193 -\r
194 -void MainWindow::goButtonClicked()\r
195 -{\r
196 -    QString searchTerm=networkAddress->currentText();\r
197 -\r
198 -    if ( searchTerm.isEmpty() )\r
199 -        return;\r
200 -\r
201 -    if ( ipsc_network_init_parse_text(&n, searchTerm) < 0 )\r
202 -    {\r
203 -        QMessageBox::warning (this,"zIPSC","Incorrect network address",0); \r
204 -    }\r
205 -\r
206 -    ipsc_network_init_parse_text(&n,searchTerm);\r
207 -    updateAll();\r
208 -\r
209 -    // implement history .... if selected text already exists, delete it from the list ... if there are more than 10 items delete last used\r
210 -    QListBox *lb=networkAddress->listBox();\r
211 -\r
212 -    for ( unsigned int i=0;i<lb->count();i++ )\r
213 -    {\r
214 -        if ( searchTerm.upper()==lb->text(i).upper() )\r
215 -        {\r
216 -            lb->removeItem(i);\r
217 -            break;\r
218 -        }\r
219 -    }\r
220 -    if ( networkAddress->count()>16 )\r
221 -        networkAddress->removeItem(networkAddress->count()-1);\r
222 -    networkAddress->insertItem(searchTerm,0);\r
223 -\r
224 -    processType=false;\r
225 -    subnetBits->setValue(n.subnet_bits);    \r
226 -    addressType->select((int)(tolower(n.nclass)-'a'));\r
227 -    processType=true;\r
228 -\r
229 -}\r
230 -\r
231 -void MainWindow::typeButtonPressed(int i)\r
232 -{\r
233 -    if ( processType )\r
234 -    {\r
235 -        char cl='a'+(int)i;\r
236 -\r
237 -        ipsc_network_set_class_info(&n, cl, TRUE);\r
238 -        ipsc_network_init(&n);\r
239 -        updateAll();\r
240 -\r
241 -        QString tmp;\r
242 -        tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n));\r
243 -        networkAddress->lineEdit()->setText(tmp);\r
244 -    }\r
245 -}\r
246 -\r
247 -void MainWindow::bitsChanged(int b)\r
248 -{\r
249 -    n.subnet_bits=b;\r
250 -    ipsc_network_init(&n);\r
251 -    QString tmp;\r
252 -    tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n));\r
253 -    networkAddress->lineEdit()->setText(tmp);    \r
254 -    updateAll();\r
255 -}\r
256 -\r
257 -void MainWindow::showPage(int t)\r
258 -{\r
259 -    if ( t==CIDR_VIEW )\r
260 -    {\r
261 -        bitsLabel->setText("Supnet bits");  \r
262 -        subnetBits->setMaxValue(31);\r
263 -    }\r
264 -    else\r
265 -    {\r
266 -        bitsLabel->setText("Subnet bits");\r
267 -        subnetBits->setMaxValue(n.subnet_bits_max);\r
268 -    }\r
269 -    pageView->raiseWidget(t);\r
270 -\r
271 -}\r
272 -\r
273 -\r
274 -\r
275 -void MainWindow::updateAll()\r
276 -{\r
277 -    subnetBits->setMaxValue(n.subnet_bits_max);\r
278 -    for ( unsigned int i=0;i<T_LAST;i++ )\r
279 -        updatePage(i);\r
280 -\r
281 -}\r
282 -\r
283 -void MainWindow::updatePage(int t)\r
284 -{\r
285 -    QString text;\r
286 -\r
287 -    text.append("<qt bgcolor="+dColor+">");    \r
288 -    text.append("<table border=0 width=210>");\r
289 -\r
290 -    switch ( t )\r
291 -    {\r
292 -        case GENERAL_VIEW:           \r
293 -            updateGPage(text);\r
294 -            break;\r
295 -        case SUBNETS_VIEW:   \r
296 -            updateSPage(text);\r
297 -            break;\r
298 -        case HOST_VIEW:   \r
299 -            updateHPage(text);\r
300 -            break;\r
301 -        case CIDR_VIEW:   \r
302 -            updateCPage(text);\r
303 -            break;        \r
304 -    }\r
305 -\r
306 -    text.append("</table></html>");\r
307 -\r
308 -    pages[t]->setText(text);\r
309 -\r
310 -}\r
311 -\r
312 -void MainWindow::updateGPage(QString &s)\r
313 -{\r
314 -    s.append("<tr><td width=50%><font color="+fColor+">Subnet maximum</font></td><td width=50%><font color="+fColor+">Addresses/Subnet</font></td></tr>");\r
315 -    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString::number(n.subnet_max)+\r
316 -             "</td><td bgcolor="+lColor+" width=50%>"+QString::number(n.host_max)+"</td></tr>");\r
317 -    s.append("<tr><td width=100% colspan=2><font color="+fColor+">Bitmap (network,subnet,host)</font></td></tr>");\r
318 -    s.append("<tr><td width=100% bgcolor="+lColor+" colspan=2>"+QString(n.bitmap)+"</td></tr>");\r
319 -    s.append("<tr><td width=50%><font color="+fColor+">Class Mask</font></td><td width=50%><font color="+fColor+">Hex Class Mask</font></td></tr>");\r
320 -    QString tmp;\r
321 -    int fmask=ipsc_network_get_full_mask(&n);\r
322 -    tmp.sprintf("%X",n.mask);    \r
323 -    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.mask))+\r
324 -             "</td><td bgcolor="+lColor+" width=50%>"+tmp+"</td></tr>");    \r
325 -    s.append("<tr><td width=50%><font color="+fColor+">Full Subnet Mask</font></td><td width=50%><font color="+fColor+">Full Hex Subnet Mask</font></td></tr>");\r
326 -    tmp.sprintf("%X",fmask); \r
327 -    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize(fmask))+\r
328 -             "</td><td bgcolor="+lColor+" width=50%>"+tmp+"</td></tr>"); \r
329 -}\r
330 -\r
331 -void MainWindow::updateSPage(QString &s)\r
332 -{\r
333 -    s.append("<tr><th width=10%>Subnet</th><th width=90% >Address range</th></tr>");\r
334 -\r
335 -    unsigned int subnet_addr = n.addr;\r
336 -    QString tmp;\r
337 -\r
338 -    for ( unsigned int i = 0; i < n.subnet_max; i++ )\r
339 -    {\r
340 -        tmp.sprintf("%s - ",denumberize(subnet_addr));\r
341 -        tmp.append(denumberize((subnet_addr + n.host_max-1)));\r
342 -        if ( ipsc_host_is_on_subnet(subnet_addr,&n) )\r
343 -        {\r
344 -            tmp.append(" *");\r
345 -        }\r
346 -        s.append("<tr><td bgcolor="+lColor+" width=10%>"+ QString::number(i+1)+\r
347 -                 "</td><td bgcolor="+lColor+" width=90%>"+tmp+"</td></tr>");\r
348 -        subnet_addr += n.host_max;\r
349 -        if ( i==256 )\r
350 -        {\r
351 -            s.append("<tr><td colspan=2 bgcolor="+lColor+" width=10%>"+ QString::number(n.subnet_max-i-1)+\r
352 -                     " more subnets ...</td></tr>");\r
353 -            break;\r
354 -        }\r
355 -    }\r
356 -}\r
357 -\r
358 -void MainWindow::updateHPage(QString &s)\r
359 -{\r
360 -    unsigned int lbound = ipsc_network_get_host_subnet_first_host(&n); \r
361 -    unsigned int ubound = ipsc_network_get_host_subnet_last_host(&n);\r
362 -\r
363 -    QString tmp;\r
364 -    tmp.sprintf("%X",n.host_addr);\r
365 -    s.append("<tr><td width=50%><font color="+fColor+">IP Address</font></td><td width=50%><font color="+fColor+">Hex IP Address</font></td></tr>");\r
366 -    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.host_addr))+\r
367 -             "</td><td bgcolor="+lColor+" width=50%>"+tmp+"</td></tr>");\r
368 -    tmp.sprintf("%s - ",denumberize(lbound));\r
369 -    tmp.append(denumberize(ubound));\r
370 -    s.append("<tr><td width=100% colspan=2><font color="+fColor+">Host Allocation Range</font></td></tr>");\r
371 -    s.append("<tr><td width=100% bgcolor="+lColor+" colspan=2>"+tmp+"</td></tr>");\r
372 -    s.append("<tr><td width=50%><font color="+fColor+">Subnet Mask</font></td><td width=50%><font color="+fColor+">Subnet ID</font></td></tr>");\r
373 -    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.subnet_mask))+\r
374 -             "</td><td bgcolor="+lColor+" width=50%>"+QString(denumberize( ipsc_network_get_subnet_id(&n)))+"</td></tr>");    \r
375 -    s.append("<tr><td width=50%><font color="+fColor+">Network ID</font></td><td width=50%><font color="+fColor+">Host ID</font></td></tr>");\r
376 -    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize( ipsc_network_get_network_id(&n)))+\r
377 -             "</td><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.host_id))+"</td></tr>"); \r
378 -}\r
379 -\r
380 -void MainWindow::updateCPage(QString &s)\r
381 -{\r
382 -    QString tmp;\r
383 -\r
384 -    tmp.sprintf("%s/%d", denumberize(n.addr),ipsc_network_get_prefix_bits(&n));\r
385 -\r
386 -    s.append("<tr><td width=50%><font color="+fColor+">CIDR Notation</font></td><td width=50%><font color="+fColor+">Supernet Maximum</font></td></tr>");\r
387 -    s.append("<tr><td bgcolor="+lColor+" width=50%>"+tmp+\r
388 -             "</td><td bgcolor="+lColor+" width=50%>"+QString::number(ipsc_network_get_supernet_max(&n))+"</td></tr>");\r
389 -    tmp.sprintf("%s/%d", denumberize(n.addr), n.bits);\r
390 -    s.append("<tr><td width=50%><font color="+fColor+">Classful Network</font></td><td width=50%><font color="+fColor+">Cisco Wildcard</font></td></tr>");\r
391 -    s.append("<tr><td bgcolor="+lColor+" width=50%>"+tmp+\r
392 -             "</td><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.cisco_wildcard))+"</td></tr>");\r
393 -    tmp.sprintf("%s / ", denumberize(n.addr));\r
394 -    tmp.append(denumberize(ipsc_network_get_full_mask(&n)));\r
395 -    s.append("<tr><td width=100% colspan=2><font color="+fColor+">Route/Mask</font></td></tr>");\r
396 -    s.append("<tr><td width=100% bgcolor="+lColor+" colspan=2>"+tmp+"</td></tr>");\r
397 -    tmp.sprintf("%X / %X", n.addr,ipsc_network_get_full_mask(&n));\r
398 -    s.append("<tr><td width=100% colspan=2><font color="+fColor+">Hex Route/Mask</font></td></tr>");\r
399 -    s.append("<tr><td width=100% bgcolor="+lColor+" colspan=2>"+tmp+"</td></tr>");\r
400 -\r
401 -\r
402 -}\r
403 -\r
404 -void MainWindow::saveVariables()\r
405 -{\r
406 -    Config cfg("zIPSC");\r
407 -    cfg.setGroup("zIPSC");\r
408 -\r
409 -    QStringList ls;\r
410 -\r
411 -    for ( int i=0;i<networkAddress->count();i++ )\r
412 -    {\r
413 -        ls.append(networkAddress->text(i));\r
414 -    }\r
415 -    QString tmp;\r
416 -    tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n));    \r
417 -    cfg.writeEntry("NetAddress",tmp);\r
418 -    cfg.writeEntry("SubnetBits",(int)n.subnet_bits);\r
419 -    cfg.writeEntry("HItems",ls,'|');    \r
420 -}\r
421 -\r
422 -void MainWindow::initVariables()\r
423 -{\r
424 -    Config cfg("zIPSC");\r
425 -    cfg.setGroup("zIPSC");\r
426 -\r
427 -    networkAddress->insertStringList ( cfg.readListEntry("HItems",'|')); \r
428 -    QString net=cfg.readEntry("NetAddress","127.0.0.1/8");\r
429 -    networkAddress->lineEdit()->setText(net);    \r
430 -    ipsc_network_init_parse_text(&n,net.latin1());\r
431 -    n.subnet_bits=cfg.readNumEntry ("SubnetBits", 0 );     \r
432 -    ipsc_network_init(&n);\r
433 -    subnetBits->setMaxValue(n.subnet_bits_max);\r
434 -    subnetBits->setValue(n.subnet_bits);\r
435 -    processType=false;\r
436 -    addressType->select((int)(tolower(n.nclass)-'a'));\r
437 -    processType=true;    \r
438 -    updateAll();    \r
439 -}\r
440 -\r
441 -void MainWindow::saveFile()\r
442 -{\r
443 -    QString tmp;\r
444 -    tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n));  \r
445 -    tmp.replace(QRegExp("[./]"),"_");\r
446 -    tmp.append(".txt"); \r
447 -    QString fileName=InputDialog::getText("zIPSC","Save as ...",tmp,this);\r
448 -    if ( fileName.isEmpty() )\r
449 -        return;\r
450 -    fileName=QDir::home().absFilePath(fileName);\r
451 -    FILE *f;\r
452 -\r
453 -    if ( (f = fopen((const char *)fileName.latin1() , "a")) == NULL )\r
454 -    {\r
455 -        QMessageBox::warning (this,"zIPSC","Error creating "+ fileName +".",0);         \r
456 -        return;\r
457 -    }\r
458 -    ipsc_network_fprint_general(&n, f);\r
459 -    ipsc_network_fprint_host(&n, f);\r
460 -    ipsc_network_fprint_cidr(&n, f);\r
461 -    fclose(f);\r
462 -\r
463 -}\r
464 -\r
465 -void MainWindow::copyText()\r
466 -{\r
467 -    QTextBrowser *tb=(QTextBrowser*)pageView->visibleWidget();\r
468 -    if ( tb && tb->hasSelectedText() )\r
469 -    {\r
470 -        tb->copy();\r
471 -    }\r
472 -}\r
473 -\r
474 -void MainWindow::displayAbout()\r
475 -{\r
476 -\r
477 -    AboutDialog::displayAbout(QPixmap(QPEApplication::qpeDir()+"pics/zipsc.png"),\r
478 -                              "zIPSC","<qt><b><h2>zIPSC</h2></b></qt>",\r
479 -                              "<qt><hr>IP subnet calculator<p>Ported to Qtopia by Walter Rawdanik (zaurus@warmi.net) \r
480 -                              <p>Based on 'IPSC' (http://ipsc.sourceforge.net/software.html)<p>Licensed under GNU General Public License</qt>",                \r
481 -                                                  this);}\r
482 -\r
483 -\r
484 -                             \r
485 +/**********************************************************************
486 +** Copyright (C) 2002 Walter Rawdanik.  All rights reserved.
487 +**
488 +** This file is part of zipsc application for Qtopia Environment.
489 +**
490 +** Issues:
491 +** Due to incomplete design of QueryResult which returns pointer instead of object, it needs to be explicitly 
492 +** deleted after each use. Extremely error-prone and basically pain-in the ass.
493 +** I am still no 100% sure I completely understand Qt layouts. It seems that QComboBox grows to the size of the
494 +** widest string in it which causes it to go beyond the edge of the screen on Qtopia small screen.
495 +** The only solution I could find was to call setMaximumSize() on each with some hard coded magic number that
496 +** looks about right - not a good solution.
497 +**
498 +**
499 +** This file may be distributed and/or modified under the terms of the
500 +** GPL license appearing in the file LICENSE included in the
501 +** packaging of this file.
502 +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
503 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
504 +**                                                        
505 +**********************************************************************/
506 +#include <qpe/qpeapplication.h>
507 +#include <qpe/config.h>
508 +#include <qpe/fileselector.h>
509 +#include "MainWindow.h"
510 +#include <stdlib.h>
511 +#include <stdio.h>
512 +#include <ctype.h>
513 +#include <qlayout.h> 
514 +#include <qframe.h>
515 +#include <qlistbox.h>
516 +#include <qlabel.h>
517 +#include <qcombobox.h> 
518 +#include <qwidgetstack.h>
519 +#include <qlineedit.h>
520 +#include <qpushbutton.h>
521 +#include <qstringlist.h> 
522 +#include <qmessagebox.h>
523 +#include <qtabbar.h>
524 +#include <qtoolbutton.h>
525 +#include <qtextbrowser.h>
526 +#include <qspinbox.h>
527 +#include <qpe/menubutton.h>
528 +#include <qpe/qpetoolbar.h>
529 +#include "InputDialog.h"
530 +#include <qdir.h>
531 +#include <qfile.h>
532 +
533 +AboutDialog::AboutDialog(const QPixmap &icon,const QString &caption, const QString &t,const QString &l,QWidget *parent):QDialog(parent,0,true)
534 +{
535 +    setCaption(caption);
536 +
537 +    if ( parent )
538 +    {
539 +        setPalette(parent->palette());
540 +    }
541 +
542 +    setMinimumSize(220,160);
543 +    QGridLayout  *gl= new QGridLayout(this,2,2,4,2); 
544 +    gl->addRowSpacing ( 0,0); 
545 +    pix=new QLabel(this);
546 +    pix->setPixmap(icon);
547 +    gl->addWidget(pix,0,0);
548 +    title=new QLabel(t,this);
549 +    gl->addWidget(title,0,1);
550 +    label=new QLabel(l,this);
551 +    gl->addMultiCellWidget(label,1,1,0,1);  
552 +
553 +}
554 +
555 +void AboutDialog::displayAbout(const QPixmap &icon,const QString &caption,const QString &t, const QString &text, QWidget *parent)
556 +{
557 +    AboutDialog *dlg=new AboutDialog(icon,caption,t,text,parent);
558 +    dlg->exec();
559 +    delete dlg;
560 +}
561 +
562 +MainWindow::MainWindow( QWidget* parent, const char* name, WFlags f )
563 +: QMainWindow( parent, name, f )
564 +{
565 +    setCaption("zIPSC");
566 +
567 +    lColor="#f8f8f8";
568 +    dColor="#e8e8e8";
569 +    fColor="#848484";
570 +    memset(&n, 0, sizeof(n));
571 +    processType=true;
572 +
573 +    QBoxLayout *topLayout=new QVBoxLayout(this,1);      
574 +
575 +
576 +    //QFrame   *topFrame=new QFrame (this);
577 +    //topFrame->setMaximumWidth(240);
578 +
579 +    QGridLayout  *gl= new QGridLayout(this,3,6,2,2); 
580 +    gl->addColSpacing ( 1,4);  
581 +
582 +    topLayout->addLayout(gl);
583 +    gl->setColStretch(0,0);
584 +    gl->setColStretch(2,10);
585 +
586 +    QLabel *lb=new QLabel("Address:",this);
587 +    gl->addWidget(lb,0,0);
588 +    networkAddress= new QComboBox(true,this);
589 +    gl->addMultiCellWidget(networkAddress,0,0,2,4);
590 +    go= new QPushButton("Go",this);
591 +    gl->addWidget(go,0,5);
592 +    lb=new QLabel("Type:",this);
593 +    gl->addWidget(lb,1,0);
594 +
595 +    addressType= new MenuButton ( this);
596 +    addressType->insertItem("Class A (1.x.x.x - 126.x.x.x)");
597 +    addressType->insertItem("Class B (128.x.x.x - 191.x.x.x)");
598 +    addressType->insertItem("Class C (192.x.x.x - 223.x.x.x)");
599 +    gl->addMultiCellWidget(addressType,1,1,2,5);
600 +
601 +    bitsLabel=new QLabel("Subnet bits:",this);   
602 +    gl->addWidget(bitsLabel,2,0);
603 +    subnetBits= new QSpinBox(this);    
604 +    gl->addWidget(subnetBits,2,2,AlignLeft);             
605 +
606 +    saveB=new QToolButton(this);
607 +    saveB->setAutoRaise(false); 
608 +    saveB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/filesave.png_"));
609 +    gl->addWidget(saveB,2,3);
610 +    copyB=new QToolButton(this);
611 +    copyB->setAutoRaise(false); 
612 +    copyB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/editcopy.png_"));
613 +    gl->addWidget(copyB,2,4);
614 +    aboutB=new QToolButton(this);
615 +    aboutB->setAutoRaise(false); 
616 +    aboutB->setPixmap(QPixmap(QPEApplication::qpeDir()+"pics/zipsc/about.png_"));
617 +    gl->addWidget(aboutB,2,5);
618 +
619 +    topLayout->addSpacing(4);
620 +
621 +    int i;
622 +
623 +    switcher= new QTabBar(this); 
624 +    switcher->setShape(QTabBar::RoundedAbove);
625 +
626 +    const char *tLabels[]={"General","Subnets/Hosts","Host","CIDR"};
627 +
628 +    for ( i=0;i<T_LAST;i++ )
629 +    {
630 +        tabValues[i]=switcher->addTab(new QTab(tLabels[i]));
631 +    }
632 +    switcher->setCurrentTab(0);
633 +    topLayout->addWidget(switcher);
634 +
635 +
636 +
637 +    pageView=new QWidgetStack(this);
638 +    for ( i=0;i<T_LAST;i++ )
639 +    {
640 +        pages[i]=new QTextBrowser(pageView);
641 +        pages[i]->setHScrollBarMode(QScrollView::AlwaysOff);
642 +        pageView->addWidget(pages[i],i);       
643 +    }    
644 +
645 +    topLayout->addWidget(pageView,10); 
646 +
647 +
648 +    initVariables();    
649 +    showPage(GENERAL_VIEW);
650 +
651 +
652 +    connect(switcher,SIGNAL(selected(int)),SLOT(showPage(int)));
653 +    connect(networkAddress->lineEdit(),SIGNAL(returnPressed()),SLOT(goButtonClicked()));
654 +    connect(go,SIGNAL(clicked()),SLOT(goButtonClicked()));
655 +    connect(addressType,SIGNAL(selected (int)),SLOT(typeButtonPressed(int)));
656 +    connect(subnetBits,SIGNAL(valueChanged (int)),SLOT(bitsChanged(int)));
657 +    connect(saveB,SIGNAL(clicked()),SLOT(saveFile()));
658 +    connect(copyB,SIGNAL(clicked()),SLOT(copyText()));
659 +    connect(aboutB,SIGNAL(clicked()),SLOT(displayAbout()));
660 +
661 +
662 +}
663 +
664 +MainWindow::~MainWindow()
665 +{
666 +    saveVariables();        
667 +}
668 +
669 +
670 +void MainWindow::goButtonClicked()
671 +{
672 +    QString searchTerm=networkAddress->currentText();
673 +
674 +    if ( searchTerm.isEmpty() )
675 +        return;
676 +
677 +    if ( ipsc_network_init_parse_text(&n, searchTerm) < 0 )
678 +    {
679 +        QMessageBox::warning (this,"zIPSC","Incorrect network address",0); 
680 +    }
681 +
682 +    ipsc_network_init_parse_text(&n,searchTerm);
683 +    updateAll();
684 +
685 +    // implement history .... if selected text already exists, delete it from the list ... if there are more than 10 items delete last used
686 +    QListBox *lb=networkAddress->listBox();
687 +
688 +    for ( unsigned int i=0;i<lb->count();i++ )
689 +    {
690 +        if ( searchTerm.upper()==lb->text(i).upper() )
691 +        {
692 +            lb->removeItem(i);
693 +            break;
694 +        }
695 +    }
696 +    if ( networkAddress->count()>16 )
697 +        networkAddress->removeItem(networkAddress->count()-1);
698 +    networkAddress->insertItem(searchTerm,0);
699 +
700 +    processType=false;
701 +    subnetBits->setValue(n.subnet_bits);    
702 +    addressType->select((int)(tolower(n.nclass)-'a'));
703 +    processType=true;
704 +
705 +}
706 +
707 +void MainWindow::typeButtonPressed(int i)
708 +{
709 +    if ( processType )
710 +    {
711 +        char cl='a'+(int)i;
712 +
713 +        ipsc_network_set_class_info(&n, cl, TRUE);
714 +        ipsc_network_init(&n);
715 +        updateAll();
716 +
717 +        QString tmp;
718 +        tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n));
719 +        networkAddress->lineEdit()->setText(tmp);
720 +    }
721 +}
722 +
723 +void MainWindow::bitsChanged(int b)
724 +{
725 +    n.subnet_bits=b;
726 +    ipsc_network_init(&n);
727 +    QString tmp;
728 +    tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n));
729 +    networkAddress->lineEdit()->setText(tmp);    
730 +    updateAll();
731 +}
732 +
733 +void MainWindow::showPage(int t)
734 +{
735 +    if ( t==CIDR_VIEW )
736 +    {
737 +        bitsLabel->setText("Supnet bits");  
738 +        subnetBits->setMaxValue(31);
739 +    }
740 +    else
741 +    {
742 +        bitsLabel->setText("Subnet bits");
743 +        subnetBits->setMaxValue(n.subnet_bits_max);
744 +    }
745 +    pageView->raiseWidget(t);
746 +
747 +}
748 +
749 +
750 +
751 +void MainWindow::updateAll()
752 +{
753 +    subnetBits->setMaxValue(n.subnet_bits_max);
754 +    for ( unsigned int i=0;i<T_LAST;i++ )
755 +        updatePage(i);
756 +
757 +}
758 +
759 +void MainWindow::updatePage(int t)
760 +{
761 +    QString text;
762 +
763 +    text.append("<qt bgcolor="+dColor+">");    
764 +    text.append("<table border=0 width=210>");
765 +
766 +    switch ( t )
767 +    {
768 +        case GENERAL_VIEW:           
769 +            updateGPage(text);
770 +            break;
771 +        case SUBNETS_VIEW:   
772 +            updateSPage(text);
773 +            break;
774 +        case HOST_VIEW:   
775 +            updateHPage(text);
776 +            break;
777 +        case CIDR_VIEW:   
778 +            updateCPage(text);
779 +            break;        
780 +    }
781 +
782 +    text.append("</table></html>");
783 +
784 +    pages[t]->setText(text);
785 +
786 +}
787 +
788 +void MainWindow::updateGPage(QString &s)
789 +{
790 +    s.append("<tr><td width=50%><font color="+fColor+">Subnet maximum</font></td><td width=50%><font color="+fColor+">Addresses/Subnet</font></td></tr>");
791 +    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString::number(n.subnet_max)+
792 +             "</td><td bgcolor="+lColor+" width=50%>"+QString::number(n.host_max)+"</td></tr>");
793 +    s.append("<tr><td width=100% colspan=2><font color="+fColor+">Bitmap (network,subnet,host)</font></td></tr>");
794 +    s.append("<tr><td width=100% bgcolor="+lColor+" colspan=2>"+QString(n.bitmap)+"</td></tr>");
795 +    s.append("<tr><td width=50%><font color="+fColor+">Class Mask</font></td><td width=50%><font color="+fColor+">Hex Class Mask</font></td></tr>");
796 +    QString tmp;
797 +    int fmask=ipsc_network_get_full_mask(&n);
798 +    tmp.sprintf("%X",n.mask);    
799 +    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.mask))+
800 +             "</td><td bgcolor="+lColor+" width=50%>"+tmp+"</td></tr>");    
801 +    s.append("<tr><td width=50%><font color="+fColor+">Full Subnet Mask</font></td><td width=50%><font color="+fColor+">Full Hex Subnet Mask</font></td></tr>");
802 +    tmp.sprintf("%X",fmask); 
803 +    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize(fmask))+
804 +             "</td><td bgcolor="+lColor+" width=50%>"+tmp+"</td></tr>"); 
805 +}
806 +
807 +void MainWindow::updateSPage(QString &s)
808 +{
809 +    s.append("<tr><th width=10%>Subnet</th><th width=90% >Address range</th></tr>");
810 +
811 +    unsigned int subnet_addr = n.addr;
812 +    QString tmp;
813 +
814 +    for ( unsigned int i = 0; i < n.subnet_max; i++ )
815 +    {
816 +        tmp.sprintf("%s - ",denumberize(subnet_addr));
817 +        tmp.append(denumberize((subnet_addr + n.host_max-1)));
818 +        if ( ipsc_host_is_on_subnet(subnet_addr,&n) )
819 +        {
820 +            tmp.append(" *");
821 +        }
822 +        s.append("<tr><td bgcolor="+lColor+" width=10%>"+ QString::number(i+1)+
823 +                 "</td><td bgcolor="+lColor+" width=90%>"+tmp+"</td></tr>");
824 +        subnet_addr += n.host_max;
825 +        if ( i==256 )
826 +        {
827 +            s.append("<tr><td colspan=2 bgcolor="+lColor+" width=10%>"+ QString::number(n.subnet_max-i-1)+
828 +                     " more subnets ...</td></tr>");
829 +            break;
830 +        }
831 +    }
832 +}
833 +
834 +void MainWindow::updateHPage(QString &s)
835 +{
836 +    unsigned int lbound = ipsc_network_get_host_subnet_first_host(&n); 
837 +    unsigned int ubound = ipsc_network_get_host_subnet_last_host(&n);
838 +
839 +    QString tmp;
840 +    tmp.sprintf("%X",n.host_addr);
841 +    s.append("<tr><td width=50%><font color="+fColor+">IP Address</font></td><td width=50%><font color="+fColor+">Hex IP Address</font></td></tr>");
842 +    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.host_addr))+
843 +             "</td><td bgcolor="+lColor+" width=50%>"+tmp+"</td></tr>");
844 +    tmp.sprintf("%s - ",denumberize(lbound));
845 +    tmp.append(denumberize(ubound));
846 +    s.append("<tr><td width=100% colspan=2><font color="+fColor+">Host Allocation Range</font></td></tr>");
847 +    s.append("<tr><td width=100% bgcolor="+lColor+" colspan=2>"+tmp+"</td></tr>");
848 +    s.append("<tr><td width=50%><font color="+fColor+">Subnet Mask</font></td><td width=50%><font color="+fColor+">Subnet ID</font></td></tr>");
849 +    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.subnet_mask))+
850 +             "</td><td bgcolor="+lColor+" width=50%>"+QString(denumberize( ipsc_network_get_subnet_id(&n)))+"</td></tr>");    
851 +    s.append("<tr><td width=50%><font color="+fColor+">Network ID</font></td><td width=50%><font color="+fColor+">Host ID</font></td></tr>");
852 +    s.append("<tr><td bgcolor="+lColor+" width=50%>"+QString(denumberize( ipsc_network_get_network_id(&n)))+
853 +             "</td><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.host_id))+"</td></tr>"); 
854 +}
855 +
856 +void MainWindow::updateCPage(QString &s)
857 +{
858 +    QString tmp;
859 +
860 +    tmp.sprintf("%s/%d", denumberize(n.addr),ipsc_network_get_prefix_bits(&n));
861 +
862 +    s.append("<tr><td width=50%><font color="+fColor+">CIDR Notation</font></td><td width=50%><font color="+fColor+">Supernet Maximum</font></td></tr>");
863 +    s.append("<tr><td bgcolor="+lColor+" width=50%>"+tmp+
864 +             "</td><td bgcolor="+lColor+" width=50%>"+QString::number(ipsc_network_get_supernet_max(&n))+"</td></tr>");
865 +    tmp.sprintf("%s/%d", denumberize(n.addr), n.bits);
866 +    s.append("<tr><td width=50%><font color="+fColor+">Classful Network</font></td><td width=50%><font color="+fColor+">Cisco Wildcard</font></td></tr>");
867 +    s.append("<tr><td bgcolor="+lColor+" width=50%>"+tmp+
868 +             "</td><td bgcolor="+lColor+" width=50%>"+QString(denumberize(n.cisco_wildcard))+"</td></tr>");
869 +    tmp.sprintf("%s / ", denumberize(n.addr));
870 +    tmp.append(denumberize(ipsc_network_get_full_mask(&n)));
871 +    s.append("<tr><td width=100% colspan=2><font color="+fColor+">Route/Mask</font></td></tr>");
872 +    s.append("<tr><td width=100% bgcolor="+lColor+" colspan=2>"+tmp+"</td></tr>");
873 +    tmp.sprintf("%X / %X", n.addr,ipsc_network_get_full_mask(&n));
874 +    s.append("<tr><td width=100% colspan=2><font color="+fColor+">Hex Route/Mask</font></td></tr>");
875 +    s.append("<tr><td width=100% bgcolor="+lColor+" colspan=2>"+tmp+"</td></tr>");
876 +
877 +
878 +}
879 +
880 +void MainWindow::saveVariables()
881 +{
882 +    Config cfg("zIPSC");
883 +    cfg.setGroup("zIPSC");
884 +
885 +    QStringList ls;
886 +
887 +    for ( int i=0;i<networkAddress->count();i++ )
888 +    {
889 +        ls.append(networkAddress->text(i));
890 +    }
891 +    QString tmp;
892 +    tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n));    
893 +    cfg.writeEntry("NetAddress",tmp);
894 +    cfg.writeEntry("SubnetBits",(int)n.subnet_bits);
895 +    cfg.writeEntry("HItems",ls,'|');    
896 +}
897 +
898 +void MainWindow::initVariables()
899 +{
900 +    Config cfg("zIPSC");
901 +    cfg.setGroup("zIPSC");
902 +
903 +    networkAddress->insertStringList ( cfg.readListEntry("HItems",'|')); 
904 +    QString net=cfg.readEntry("NetAddress","127.0.0.1/8");
905 +    networkAddress->lineEdit()->setText(net);    
906 +    ipsc_network_init_parse_text(&n,net.latin1());
907 +    n.subnet_bits=cfg.readNumEntry ("SubnetBits", 0 );     
908 +    ipsc_network_init(&n);
909 +    subnetBits->setMaxValue(n.subnet_bits_max);
910 +    subnetBits->setValue(n.subnet_bits);
911 +    processType=false;
912 +    addressType->select((int)(tolower(n.nclass)-'a'));
913 +    processType=true;    
914 +    updateAll();    
915 +}
916 +
917 +void MainWindow::saveFile()
918 +{
919 +    QString tmp;
920 +    tmp.sprintf("%s/%d", denumberize(n.host_addr),ipsc_network_get_prefix_bits(&n));  
921 +    tmp.replace(QRegExp("[./]"),"_");
922 +    tmp.append(".txt"); 
923 +    QString fileName=InputDialog::getText("zIPSC","Save as ...",tmp,this);
924 +    if ( fileName.isEmpty() )
925 +        return;
926 +    fileName=QDir::home().absFilePath(fileName);
927 +    FILE *f;
928 +
929 +    if ( (f = fopen((const char *)fileName.latin1() , "a")) == NULL )
930 +    {
931 +        QMessageBox::warning (this,"zIPSC","Error creating "+ fileName +".",0);         
932 +        return;
933 +    }
934 +    ipsc_network_fprint_general(&n, f);
935 +    ipsc_network_fprint_host(&n, f);
936 +    ipsc_network_fprint_cidr(&n, f);
937 +    fclose(f);
938 +
939 +}
940 +
941 +void MainWindow::copyText()
942 +{
943 +    QTextBrowser *tb=(QTextBrowser*)pageView->visibleWidget();
944 +    if ( tb && tb->hasSelectedText() )
945 +    {
946 +        tb->copy();
947 +    }
948 +}
949 +
950 +void MainWindow::displayAbout()
951 +{
952 +
953 +    AboutDialog::displayAbout(QPixmap(QPEApplication::qpeDir()+"pics/zipsc.png"),
954 +                              "zIPSC","<qt><b><h2>zIPSC</h2></b></qt>",
955 +                              "<qt><hr>IP subnet calculator<p>Ported to Qtopia by Walter Rawdanik (zaurus@warmi.net) "
956 +                              "<p>Based on 'IPSC' (http://ipsc.sourceforge.net/software.html)<p>Licensed under GNU General Public License</qt>",
957 +                              this);
958 +}
959 +
960 +
961 +