Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GPRSedit.cpp

Go to the documentation of this file.
00001 #include <qtoolbutton.h>
00002 #include <qlistview.h>
00003 #include <qheader.h>
00004 #include <qspinbox.h>
00005 #include <qradiobutton.h>
00006 #include <qcheckbox.h>
00007 #include <qtabwidget.h>
00008 #include <qlineedit.h>
00009 #include <qlistbox.h>
00010 #include <GUIUtils.h>
00011 #include <resources.h>
00012 #include "GPRSedit.h"
00013 
00014 GPRSEdit::GPRSEdit( QWidget * Parent ) : GPRSGUI( Parent ){
00015     Routing_LV->header()->hide();
00016     Add_TB->setPixmap( NSResources->getPixmap( "add" ) );
00017     Delete_TB->setPixmap( NSResources->getPixmap( "delete" ) );
00018     Routing_LV->setColumnAlignment( 1, Qt::AlignRight );
00019 }
00020 
00021 QString GPRSEdit::acceptable( void ) {
00022     if( APN_LE->text().isEmpty() ) {
00023       return tr("APN is required");
00024     }
00025 
00026     return QString();
00027 }
00028 
00029 bool GPRSEdit::commit( GPRSData & Data ) {
00030     bool SM = 0;
00031     bool RM;
00032 
00033     TXTM( Data.APN, APN_LE, SM );
00034     TXTM( Data.User, User_LE, SM );
00035     TXTM( Data.Password, Password_LE, SM );
00036 
00037     if( AssignedByServer_CB->isChecked() ) {
00038       if( ! Data.DNS1.isEmpty() ) {
00039         SM = 1;
00040         Data.DNS1 = "";
00041       }
00042       if( ! Data.DNS2.isEmpty() ) {
00043         SM = 1;
00044         Data.DNS2 = "";
00045       }
00046     } else {
00047       TXTM( Data.DNS1, DNS1_LE, SM );
00048       TXTM( Data.DNS2, DNS2_LE, SM );
00049     }
00050 
00051     CBM( Data.DefaultGateway, DefaultGateway_RB, SM );
00052     CBM( Data.SetIfSet, SetIfSet_CB, SM );
00053 
00054     // find new routes
00055     unsigned int i;
00056 
00057     RM = 0; // routing modified
00058     QListViewItem * it = Routing_LV->firstChild();
00059     while( ! RM && it ) {
00060       for( i = 0; i < Data.Routing.count(); i ++ ) {
00061         if( it->text(0) == Data.Routing[i]->Address ) {
00062           // still exists
00063           break;
00064         }
00065       }
00066       if( i == Data.Routing.count() ) {
00067         // modified
00068         RM = 1;
00069       }
00070       it = it->nextSibling();
00071     }
00072 
00073     // find obsoleted
00074     for( i = 0; ! RM && i < Data.Routing.count(); i ++ ) {
00075       it = Routing_LV->firstChild();
00076       while( it ) {
00077         if( it->text(0) == Data.Routing[i]->Address ) {
00078           // still exists
00079           break;
00080         }
00081         it = it->nextSibling();
00082       }
00083 
00084       if( it == 0 ) {
00085         RM = 1;
00086       }
00087     }
00088 
00089     if( RM ) {
00090       unsigned int i = 0;
00091       GPRSRoutingEntry * E;
00092       // update routing table
00093       Data.Routing.resize(0);
00094       Data.Routing.resize( Routing_LV->childCount() );
00095 
00096       it = Routing_LV->firstChild();
00097       while( it ) {
00098         E = new GPRSRoutingEntry;
00099         E->Address = it->text(0);
00100         E->Mask = it->text(1).toShort();
00101         Data.Routing.insert( i, E );
00102         i ++;
00103         it = it->nextSibling();
00104       }
00105     }
00106 
00107     SBM( Data.Debug, Debug_SB, SM );
00108     return SM;
00109 }
00110 
00111 void GPRSEdit::showData( GPRSData & Data ) {
00112     STXT( Data.APN, APN_LE );
00113     STXT( Data.User, User_LE );
00114     STXT( Data.Password, Password_LE );
00115 
00116     SCB( ( Data.DNS1.isEmpty() && Data.DNS2.isEmpty() ),
00117          AssignedByServer_CB );
00118     STXT( Data.DNS1, DNS1_LE );
00119     STXT( Data.DNS2, DNS2_LE );
00120 
00121     SCB( Data.DefaultGateway, DefaultGateway_RB );
00122     SCB( (! Data.DefaultGateway), FixedGateway_RB );
00123     SCB( Data.SetIfSet, SetIfSet_CB );
00124 
00125     for( unsigned int i = 0; i < Data.Routing.count(); i ++ ) {
00126       QListViewItem * it;
00127       it = new QListViewItem( Routing_LV );
00128 
00129       it->setText( 0, Data.Routing[i]->Address );
00130       it->setText( 1, QString().setNum( Data.Routing[i]->Mask ) );
00131     }
00132 
00133     SSB( Data.Debug, Debug_SB );
00134 }
00135 
00136 void GPRSEdit::SLOT_AddRoute( void ) {
00137     QListViewItem * it, *last;
00138     QListViewItem * after = Routing_LV->firstChild();
00139     last = 0;
00140     while( after ) {
00141       if( after->isSelected() ) {
00142         break;
00143       }
00144       last = after;
00145       after = after->nextSibling();
00146     }
00147 
00148     it = new QListViewItem( Routing_LV, (after) ? after : last );
00149 
00150     it->setText( 0, Net_LE->text() );
00151     it->setText( 1, QString().setNum( Mask_SB->value() ) );
00152 }
00153 
00154 void GPRSEdit::SLOT_DeleteRoute( void ) {
00155     QListViewItem * nit;
00156     QListViewItem * it = Routing_LV->firstChild();
00157     while( it ) {
00158       nit = it->nextSibling();
00159       if( it->isSelected() ) {
00160         delete it;
00161       }
00162       it = nit;
00163     }
00164 }

Generated on Sat Nov 5 16:17:53 2005 for OPIE by  doxygen 1.4.2