175 files changed, 2751 insertions, 1934 deletions
diff --git a/noncore/applets/zkbapplet/zkbapplet.control b/noncore/applets/zkbapplet/zkbapplet.control index 4e03c26..08b540f 100644 --- a/noncore/applets/zkbapplet/zkbapplet.control +++ b/noncore/applets/zkbapplet/zkbapplet.control @@ -1,10 +1,10 @@ Package: zkbapplet Files: plugins/applets/libzkbapplet.so* pics/zkb-disabled.png share/zkb/*.xml bin/keyz-cfg apps/Settings/keyz-cfg.desktop pics/keyz-cfg.png share/zkb/zkb.xml.sample Priority: optional Section: opie/applets Maintainer: Rajko Albrecht <alwin@handhelds.org> Architecture: arm Depends: task-opie-minimal Description: ZKB Applet and configuration program Obsoletes: keyz-cfg -Version: 0.6.0$EXTRAVERSION +Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/apps/confedit/opie-confeditor.control b/noncore/apps/confedit/opie-confeditor.control index 00a05da..b49aad3 100644 --- a/noncore/apps/confedit/opie-confeditor.control +++ b/noncore/apps/confedit/opie-confeditor.control @@ -1,9 +1,9 @@ Package: opie-confeditor Files: bin/confedit apps/Settings/confedit.desktop pics/confedit/confedit.png plugins/application/libconfedit.so* Priority: optional Section: opie/settings Maintainer: Patrick S. Vogt <tille@handhelds.org> Architecture: arm -Version: $QPE_VERSION-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, libopiecore2 Description: An enditor for the ~/Settings/*.conf files diff --git a/noncore/apps/dagger/opie-dagger.control b/noncore/apps/dagger/opie-dagger.control index 4ded1f2..cfb45be 100644 --- a/noncore/apps/dagger/opie-dagger.control +++ b/noncore/apps/dagger/opie-dagger.control @@ -1,9 +1,9 @@ Package: opie-dagger Files: plugins/application/libdagger.so* bin/dagger pics/dagger apps/Applications/dagger.desktop Priority: optional Section: opie/applications Depends: task-opie-minimal, libopiecore2, libopieui2 Architecture: arm Maintainer: Dan Williams (drw@handhelds.org) Description: A Bible study program utilizing the Sword library. -Version: 0.9.1$EXTRAVERSION +Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/apps/opie-bartender/opie-bartender.control b/noncore/apps/opie-bartender/opie-bartender.control index 045c68e..29ad0ba 100644 --- a/noncore/apps/opie-bartender/opie-bartender.control +++ b/noncore/apps/opie-bartender/opie-bartender.control @@ -1,10 +1,10 @@ Files: plugins/applications/libbartender.so* bin/bartender apps/Applications/bartender.desktop etc/bartender/drinkdb.txt Priority: optional Package: opie-bartender Section: opie/applications Maintainer: L.J. Potter <lpotter@trolltech.com> Architecture: arm -Version: $QPE_VERSION-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal Description: Bartender drink receipe database lookup, and blood alcohol estimator. diff --git a/noncore/apps/opie-console/opie-console-embedix.control b/noncore/apps/opie-console/opie-console-embedix.control index cf27554..e902d0e 100644 --- a/noncore/apps/opie-console/opie-console-embedix.control +++ b/noncore/apps/opie-console/opie-console-embedix.control @@ -1,10 +1,10 @@ Package: opie-console Files: bin/opie-console apps/Applications/opie-console.desktop pics/console/* share/opie-console/* Priority: optional Section: opie/applications Maintainer: Opie Team <opie@handhelds.org> Architecture: arm -Version: 0.6-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: qpe-base, libopiecore2, libopieui2, opie-console-help-en, lrzsz, opie-keytabs License: GPL Description: Opie terminal app diff --git a/noncore/apps/opie-console/opie-console.control b/noncore/apps/opie-console/opie-console.control index e924b79..b64898b 100644 --- a/noncore/apps/opie-console/opie-console.control +++ b/noncore/apps/opie-console/opie-console.control @@ -1,10 +1,10 @@ Package: opie-console Files: bin/opie-console apps/Applications/opie-console.desktop pics/console/* Priority: optional Section: opie/applications Maintainer: Opie Team <opie@handhelds.org> Architecture: arm -Version: 0.6-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: qpe-base, libopiecore2, libopieui2, opie-console-help-en, lrzsz, opie-keytabs License: GPL Description: Opie terminal app diff --git a/noncore/apps/opie-gutenbrowser/opie-gutenbrowser.control b/noncore/apps/opie-gutenbrowser/opie-gutenbrowser.control index 47fbcdf..bc0283e 100644 --- a/noncore/apps/opie-gutenbrowser/opie-gutenbrowser.control +++ b/noncore/apps/opie-gutenbrowser/opie-gutenbrowser.control @@ -1,11 +1,11 @@ Package: opie-gutenbrowser Files: bin/gutenbrowser apps/Applications/gutenbrowser.desktop etc/gutenbrowser/* pics/gutenbrowser/* plugins/application/libgutenbrowser.so* Priority: optional Section: opie Maintainer: ljp <lpotter@trolltech.com> Source: opie.handhelds.org Architecture: arm -Version: $QPE_VERSION-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: ftplib, libopiecore2, libopieui2 Description: Etext read for the Project Gutenberg. diff --git a/noncore/games/bounce/opie-bounce.control b/noncore/games/bounce/opie-bounce.control index dfd1bf0..0513958 100644 --- a/noncore/games/bounce/opie-bounce.control +++ b/noncore/games/bounce/opie-bounce.control @@ -1,11 +1,11 @@ Package: opie-bounce Files: plugins/application/libbounce.so* bin/bounce apps/Games/bounce.desktop pics/bounce/*.png -Version: 0.6-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, libopiecore2 Priority: optional Section: opie/games Maintainer: Martin Imobersteg <imm@gmx.ch> Architecture: arm License: GPL Description: bounce A JezzGame like game for Qtopia. diff --git a/noncore/games/buzzword/opie-buzzword.control b/noncore/games/buzzword/opie-buzzword.control index 3316445..f76a2c2 100644 --- a/noncore/games/buzzword/opie-buzzword.control +++ b/noncore/games/buzzword/opie-buzzword.control @@ -1,11 +1,11 @@ Package: opie-buzzword Files: plugins/application/libbuzzword.so* bin/buzzword apps/Games/buzzword.desktop pics/buzzword/buzzword.png share/buzzword/buzzwords -Version: 1.1-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal,libopiecore2 Priority: optional Section: opie/games Maintainer: Martin Imobersteg <imm@gmx.ch> Architecture: arm License: GPL Description: BuzzWord A BuzzWord Bingo for the Opie environment. diff --git a/noncore/games/kbill/opie-kbill.control b/noncore/games/kbill/opie-kbill.control index 3299b93..cf12bca 100644 --- a/noncore/games/kbill/opie-kbill.control +++ b/noncore/games/kbill/opie-kbill.control @@ -1,13 +1,13 @@ Package: opie-kbill Files: bin/kbill apps/Games/kbill.desktop pics/kbill/* Priority: optional Section: opie/games Maintainer: Mark Westcott <mark@houseoffish.org> Architecture: arm -Version: 0.8-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal License: GPL Description: The famous hit Bill game Hit Bill as hard as you can before he infects your network with a wannabe OS. diff --git a/noncore/games/kcheckers/opie-kcheckers.control b/noncore/games/kcheckers/opie-kcheckers.control index 5bd03ae..e7c20d3 100644 --- a/noncore/games/kcheckers/opie-kcheckers.control +++ b/noncore/games/kcheckers/opie-kcheckers.control @@ -1,10 +1,10 @@ Package: opie-kcheckers Files: plugins/application/libkcheckers.so* bin/kcheckers apps/Games/kcheckers.desktop pics/kcheckers Priority: optional Section: opie/games Maintainer: leseb <prudhomme@laposte.net> Architecture: arm -Version: 0.3-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, libopiecore2 Description: The game of Checkers A game for the Opie environment. diff --git a/noncore/games/kpacman/opie-kpacman.control b/noncore/games/kpacman/opie-kpacman.control index 68487ec..97120aa 100644 --- a/noncore/games/kpacman/opie-kpacman.control +++ b/noncore/games/kpacman/opie-kpacman.control @@ -1,11 +1,11 @@ Package: opie-kpacman Files: plugins/applications/libkpacman.so* bin/kpacman apps/Games/kpacman.desktop pics/kpacman/kpacman.png share/kpacman -Version: 0.3.1-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal Priority: optional Section: opie/games Maintainer: Catalin Climov <catalin@climov.com> Architecture: arm License: GPL Description: Kpacman A Pacman clone for Qtopia. diff --git a/noncore/games/tetrix/ohighscoredlg.cpp b/noncore/games/tetrix/ohighscoredlg.cpp index 8d8079e..66f4917 100644 --- a/noncore/games/tetrix/ohighscoredlg.cpp +++ b/noncore/games/tetrix/ohighscoredlg.cpp @@ -1,199 +1,206 @@ /*************************************************************************** begin : January 2003 copyright : ( C ) 2003 by Carsten Niehaus email : cniehaus@handhelds.org **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * ( at your option ) any later version. * * * **************************************************************************/ #include <qdialog.h> #include <qlayout.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qstring.h> +#include <qlist.h> #include <qhbox.h> #include <qvbox.h> #include <qlabel.h> #include <qlistview.h> #include <qlineedit.h> #include "ohighscoredlg.h" -OHighscore::OHighscore( int score , int playerLevel ) +OHighscore::OHighscore( int score , int playerLevel ) : playerData() { pLevel = playerLevel; getList(); checkIfItIsANewhighscore( score ); + playerData.setAutoDelete( TRUE ); } OHighscore::~OHighscore() { - std::list<t_playerData*>::iterator deleteIterator = playerData.begin(); - for ( ; deleteIterator != playerData.end() ; deleteIterator++ ) - { - delete ( *deleteIterator ); - } } void OHighscore::getList() { Config cfg ( "tetrix" ); cfg.setGroup( QString::number( 1 ) ); lowest = cfg.readNumEntry( "Points" ); playerData.clear(); int rest = 1; //for the filling up later for ( int i = 1 ; i < 11 ; i++ ) { if ( cfg.hasGroup( QString::number( i ) ) ) { cfg.setGroup( QString::number( i ) ); int temp = cfg.readNumEntry( "Points" ); t_playerData *pPlayerData = new t_playerData; pPlayerData->sName = cfg.readEntry( "Name" ); pPlayerData->points = temp; pPlayerData->level = cfg.readNumEntry( "Level" ); - playerData.push_back( pPlayerData ); + playerData.append( pPlayerData ); if ( (temp < lowest) ) lowest = temp; rest++; } } //now I fill up the rest of the list if ( rest < 11 ) //only go in this loop if there are less than //10 highscoreentries { lowest = 0; for ( ; rest < 11 ; rest++ ) { t_playerData *pPlayerData = new t_playerData; pPlayerData->sName = tr( "empty"); pPlayerData->points = 0; pPlayerData->level = 0; - playerData.push_back( pPlayerData ); + playerData.append( pPlayerData ); } } } void OHighscore::checkIfItIsANewhighscore( int points) { if ( points > lowest ) isNewhighscore = true; else isNewhighscore = false; } void OHighscore::insertData( QString name , int punkte , int playerLevel ) { Config cfg ( "tetrix" ); + t_playerData * Run; + int index = 0; int entryNumber = 1; - std::list<t_playerData*>::iterator insertIterator = playerData.begin(); - while ( insertIterator != playerData.end() ) - { - if ( punkte > ( *insertIterator )->points ) + + for ( Run=playerData.first(); + Run != 0; + index ++, Run=playerData.next() ) { + + if ( punkte > Run->points ) { t_playerData* temp = new t_playerData; temp->sName = name; temp->points = punkte; temp->level = playerLevel; - playerData.insert( insertIterator , temp ); + + playerData.insert( index, temp ); //now we have to delete the last entry - insertIterator = playerData.end(); - insertIterator--; -//X delete *insertIterator; //memleak? - playerData.erase( insertIterator ); + playerData.remove( playerData.count() ); ///////////////////////////////////////// //this block just rewrites the highscore - insertIterator = playerData.begin(); - while ( insertIterator != playerData.end() ) - { + for ( t_playerData * Run2=playerData.first(); + Run2 != 0; + Run2=playerData.next() ) { cfg.setGroup( QString::number( entryNumber ) ); - cfg.writeEntry( "Name" , ( *insertIterator )->sName ); - cfg.writeEntry( "Points" , ( *insertIterator )->points ); - cfg.writeEntry( "Level" , ( *insertIterator )->level ); + cfg.writeEntry( "Name" , Run2->sName ); + cfg.writeEntry( "Points" , Run2->points ); + cfg.writeEntry( "Level" , Run2->level ); entryNumber++; - insertIterator++; } //////////////////////////////////////// return; } - insertIterator++; } } QString OHighscore::getName() { QString name; QDialog *d = new QDialog ( this, 0, true ); d->setCaption( tr( "Enter your name!" )); QLineEdit *ed = new QLineEdit ( d ); ( new QVBoxLayout ( d, 3, 3 ))->addWidget ( ed ); ed->setFocus ( ); if ( d->exec() == QDialog::Accepted ) { name = ed->text(); } //delete d; return name; } OHighscoreDialog::OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name, bool modal) : QDialog(parent, name, modal) { hs_ = highscore; setCaption( tr( "Highscores" ) ); vbox_layout = new QVBoxLayout( this, 4 , 4 ); list = new QListView( this ); list->setSorting( -1 ); list->addColumn( tr( "#" )); list->addColumn( tr( "Name" )); list->addColumn( tr( "Points" )); list->addColumn( tr( "Level" )); createHighscoreListView(); vbox_layout->addWidget( list ); QPEApplication::showDialog( this ); } void OHighscoreDialog::createHighscoreListView() { int pos = 10; int points_ = 0; int level_ = 0; + QListViewItem * Prev = 0; - std::list<t_playerData*>::reverse_iterator iListe = hs_->playerData.rbegin(); - - for ( ; iListe != hs_->playerData.rend() ; ++iListe ) + for ( t_playerData * Run = hs_->playerData.first(); + Run != 0; + Run=hs_->playerData.next() ) { - QListViewItem *item = new QListViewItem( list ); + QListViewItem *item; + + if( Prev ) { + // after previous + item = new QListViewItem( list, Prev ); + Prev = item; + } else { + item = new QListViewItem( list ); + + } item->setText( 0 , QString::number( pos ) ); //number - item->setText( 1 , ( *iListe )->sName ); //name - if ( ( *iListe )->points == -1 ) + item->setText( 1 , Run->sName ); //name + if ( Run->points == -1 ) points_ = 0; - else points_ = ( *iListe )->points; - if ( ( *iListe )->level == -1 ) + else points_ = Run->points; + if ( Run->level == -1 ) level_ = 0; - else level_ = ( *iListe )->level; + else level_ = Run->level; item->setText( 2 , QString::number( points_ ) ); //points item->setText( 3 , QString::number( level_ ) ); //level pos--; } } diff --git a/noncore/games/tetrix/ohighscoredlg.h b/noncore/games/tetrix/ohighscoredlg.h index fdbe623..845e639 100644 --- a/noncore/games/tetrix/ohighscoredlg.h +++ b/noncore/games/tetrix/ohighscoredlg.h @@ -1,97 +1,96 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * ( at your option ) any later version. * * * **************************************************************************/ class QWidget; class QVBoxLayout; class QListView; #include <qdialog.h> -#include <list> +#include <qlist.h> -using namespace std; - -struct t_playerData +class t_playerData { + +public : + QString sName; int points; int level; }; class OHighscore : public QWidget { Q_OBJECT public: /* *An OHighscore-Object contains all Points, level and playernames sorted in a stl::vector */ OHighscore( int , int ); ~OHighscore(); /* * is true if the player did a new highscore */ bool isNewhighscore; /* * this inserts the new entry at the correct position */ void insertData( QString , int , int ); - list<t_playerData*> playerData; + QList<t_playerData> playerData; /* * As Qt/e does not support QInputDialog I did that code myself */ QString getName(); private: - list<t_playerData*>::iterator iPlayerData; - /* * the lowest score in the highscorelist */ int lowest; /* * the level of the highscore */ int pLevel; /* * get all scores in a vector and give "lowest" a value */ void getList(); /* * sets the bool if the current score is in the top10 */ void checkIfItIsANewhighscore( int ); }; class OHighscoreDialog : public QDialog { Q_OBJECT public: OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name = 0, bool modal = true ); private: OHighscore *hs_; QVBoxLayout *vbox_layout; /* * this method creates the QListView with all data */ void createHighscoreListView(); QListView *list; }; diff --git a/noncore/games/tetrix/tetrix.pro b/noncore/games/tetrix/tetrix.pro index 580a542..96f452f 100644 --- a/noncore/games/tetrix/tetrix.pro +++ b/noncore/games/tetrix/tetrix.pro @@ -1,22 +1,22 @@ CONFIG = qt warn_on quick-app HEADERS = gtetrix.h \ qtetrix.h \ qtetrixb.h \ tpiece.h \ ohighscoredlg.h SOURCES = main.cpp \ gtetrix.cpp \ qtetrix.cpp \ qtetrixb.cpp \ tpiece.cpp \ ohighscoredlg.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe -lopiecore2 -lstdc++ +LIBS += -lqpe -lopiecore2 INTERFACES = TARGET = tetrix include( $(OPIEDIR)/include.pro ) diff --git a/noncore/multimedia/camera/opie-camera.control b/noncore/multimedia/camera/opie-camera.control index d9eaab8..5171050 100644 --- a/noncore/multimedia/camera/opie-camera.control +++ b/noncore/multimedia/camera/opie-camera.control @@ -1,10 +1,10 @@ Package: opie-camera Files: lib/libcamera.* bin/camera bin/capture pics/camera apps/Applications/camera.desktop Priority: optional Section: opie/multimedia Maintainer: Michael 'Mickey' Lauer <mickeyl@Vanille.de> Architecture: arm -Version: 1.0.1 +Version: $QPE_VERSION$EXTRAVERSION Depends: libqpe1, libopiecore2, libopieui2 Description: A Camera Application A Camera Application to use with the Sharp CE-AG06. diff --git a/noncore/multimedia/opieplayer2/opie-mediaplayer2-codecs.control b/noncore/multimedia/opieplayer2/opie-mediaplayer2-codecs.control index 1d0fbfb..f4cbc41 100644 --- a/noncore/multimedia/opieplayer2/opie-mediaplayer2-codecs.control +++ b/noncore/multimedia/opieplayer2/opie-mediaplayer2-codecs.control @@ -1,10 +1,10 @@ Package: opie-mediaplayer2-codecs Files: root/usr/lib/libao.so* root/usr/lib/libogg* root/usr/lib/libvorbisidec.so* root/usr/lib/libxine.so* root/usr/lib/xine/* Section: ;ibs Essential: no Priority: optional -Version: 0.7-$SUB_VERSION.3 +Version: $QPE_VERSION$EXTRAVERSION Architecture: arm Maintainer: Maximilian Reiss <harlekin@handhelds.org> Depends: libc6 (>= 2.1), opie-mediaplayer2 Description: Codecs for opieplayer 2 diff --git a/noncore/multimedia/opieplayer2/opie-mediaplayer2.control b/noncore/multimedia/opieplayer2/opie-mediaplayer2.control index af6bb01..78cfa8b 100644 --- a/noncore/multimedia/opieplayer2/opie-mediaplayer2.control +++ b/noncore/multimedia/opieplayer2/opie-mediaplayer2.control @@ -1,11 +1,11 @@ Package: opie-mediaplayer2 Files: plugins/application/libopieplayer2.so* bin/opieplayer2 apps/Applications/opieplayer2.desktop pics/opieplayer2/add_to_playlist.png pics/opieplayer2/cut.png pics/opieplayer2/delete.png pics/opieplayer2/down.png pics/opieplayer2/loop.png pics/opieplayer2/MPEGPlayer.png pics/opieplayer2/musicfile.png pics/opieplayer2/playlist2.png pics/opieplayer2/play.png pics/opieplayer2/remove_from_playlist.png pics/opieplayer2/shuffle.png pics/opieplayer2/up.png pics/opieplayer2/videofile.png Priority: optional Section: opie/multimedia Maintainer: L.J.Potter <ljp@llornkcor.com>, Maximilian Reiss <harlekin@handhelds.org> Architecture: arm -Depends: task-opie-minimal, libopie1, zlib1g, opie-mediaplayer2-skin-default | opie-mediaplayer2-skin-default-landscape , libxine1 | opie-mediaplayer2-codecs +Depends: task-opie-minimal, libopiecore2, libopieui2, libqtaux2, libz1, opie-mediaplayer2-skin-default | opie-mediaplayer2-skin-default-landscape , libxine1 | opie-mediaplayer2-codecs Description: The Opie media player The mediaplayer for Opie. It plays mp3, mpeg, wav, ogg, quicktime, divx and more. Also it is streaming capable. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/multimedia/powerchord/opie-powerchord.control b/noncore/multimedia/powerchord/opie-powerchord.control index 39d926b..4b5bc88 100644 --- a/noncore/multimedia/powerchord/opie-powerchord.control +++ b/noncore/multimedia/powerchord/opie-powerchord.control @@ -1,10 +1,10 @@ Files: plugins/applications/libpowerchord.so* bin/powerchord apps/Applications/powerchord.desktop pics/powerchord share/powerchord Priority: optional Section: opie/multimedia Maintainer: Camilo Mesias <camilo@mesias.co.uk>, ljp <lpotter@trolltech.com> Architecture: arm -Version: 0.0.8 +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal Description: Guitar Chord generator application Allows naming of chords using base note and key. Fretboard diagrams are produced illustrating ways to play the chord. diff --git a/noncore/net/mail/libetpanstuff/libetpan.control b/noncore/net/mail/libetpanstuff/libetpan.control index 2b5b354..b664157 100644 --- a/noncore/net/mail/libetpanstuff/libetpan.control +++ b/noncore/net/mail/libetpanstuff/libetpan.control @@ -1,10 +1,10 @@ Package: libetpan Files: usr/lib/libetpan* Priority: optional Section: system Maintainer: Rajko Albrecht <alwin@handhelds.org> Architecture: arm -Version: 0.33pre-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: libssl0.9.7 Description: libetpan mail/news library - A version of libetpan patched for Opies mailing app License: LGPL diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.control b/noncore/net/mail/libmailwrapper/libmailwrapper.control index ec55bb3..3491d67 100644 --- a/noncore/net/mail/libmailwrapper/libmailwrapper.control +++ b/noncore/net/mail/libmailwrapper/libmailwrapper.control @@ -1,10 +1,10 @@ Package: libmailwrapper Files: lib/libmailwrapper.so* Priority: optional Section: libs Maintainer: Rajko Albrecht <alwin@handhelds.org>, Juergen Graf <jgf@handhelds.org>, Maximilian Reiß <harlekin@handhelds.org> Architecture: arm -Version: 0.6-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, libopiecore2, libopieui2, libetpan (>= 0.33pre) Description: wrapper lib needed by Opie's mailer License: LGPL diff --git a/noncore/net/mail/opie-mail.control b/noncore/net/mail/opie-mail.control index 698aaa7..e3b18b3 100644 --- a/noncore/net/mail/opie-mail.control +++ b/noncore/net/mail/opie-mail.control @@ -1,10 +1,10 @@ Package: opie-mail Files: plugins/application/libopiemail.so* bin/opiemail apps/1Pim/opiemail.desktop pics/mail/*.png Priority: optional Section: opie/pim Maintainer: Rajko Albrecht <alwin@handhelds.org>, Juergen Graf <jgf@handhelds.org>, Maximilian Reiß <harlekin@handhelds.org> Architecture: arm -Version: 0.6-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, libopiecore2, libopieui2, libopiemm2, libopiedb2, libmailwrapper (>= 0.6), libssl Description: Opie's mail and news client (POP3, IMAP and NNTP) License: LGPL diff --git a/noncore/net/mail/taskbarapplet/opie-mailapplet.control b/noncore/net/mail/taskbarapplet/opie-mailapplet.control index f9822a5..c838e0b 100644 --- a/noncore/net/mail/taskbarapplet/opie-mailapplet.control +++ b/noncore/net/mail/taskbarapplet/opie-mailapplet.control @@ -1,10 +1,10 @@ Package: opie-mailapplet Files: plugins/applets/libmailapplet.so* Priority: optional Section: opie/applets Maintainer: Rajko Albrecht <alwin@handhelds.org>, Juergen Graf <jgf@handhelds.org>, Maximilian Reiß <harlekin@handhelds.org> Architecture: arm -Version: 0.5-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, libopiecore2, opie-mail Description: A Biff-like mailchecker License: LGPL diff --git a/noncore/net/opieirc/opie-irc.control b/noncore/net/opieirc/opie-irc.control index b9f20f0..195b5ff 100644 --- a/noncore/net/opieirc/opie-irc.control +++ b/noncore/net/opieirc/opie-irc.control @@ -1,9 +1,9 @@ Package: opie-irc Files: plugins/application/libopieirc.so* bin/opieirc pics/opieirc apps/Applications/opieirc.desktop help/en/html/opieirc.html help/en/html/opieirc Priority: optional Section: opie/applications Maintainer: Wenzel Jakob <root@wazlaf.de> Architecture: arm -Depends: task-opie-minimal, libopie1 +Depends: task-opie-minimal, libopiecore2, libopieui2, libqtaux2 Description: The Opie IRC client lets you chat on your favorite IRC server using your handheld computer Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/net/opierdesktop/opie-rdesktop.control b/noncore/net/opierdesktop/opie-rdesktop.control index a8726e0..2a9d415 100644 --- a/noncore/net/opierdesktop/opie-rdesktop.control +++ b/noncore/net/opierdesktop/opie-rdesktop.control @@ -1,9 +1,9 @@ Package: opie-rdesktop Files: bin/ordesktop pics/opierdesktop apps/Applications/ordesktop.desktop Priority: optional Section: opie/applications Maintainer: Michael 'Mickey' Lauer <mickeyl@handhelds.org> Architecture: arm -Version: 1.2.0-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal Description: Remote Desktop Protocol (RDP) Client diff --git a/noncore/net/opietooth/blue-pin/main.cc b/noncore/net/opietooth/blue-pin/main.cc index 1ab1f2e..dbe5b41 100644 --- a/noncore/net/opietooth/blue-pin/main.cc +++ b/noncore/net/opietooth/blue-pin/main.cc @@ -1,12 +1,11 @@ #include <stdio.h> #include <stdlib.h> #include <qpe/qpeapplication.h> #include <opie2/oapplicationfactory.h> #include "pindlg.h" using namespace Opie::Core; OPIE_EXPORT_APP( OApplicationFactory<OpieTooth::PinDlg> ) - diff --git a/noncore/net/opietooth/blue-pin/opie-bluepin.control b/noncore/net/opietooth/blue-pin/opie-bluepin.control index 7147975..e9aa683 100644 --- a/noncore/net/opietooth/blue-pin/opie-bluepin.control +++ b/noncore/net/opietooth/blue-pin/opie-bluepin.control @@ -1,10 +1,10 @@ Package: opie-bluepin Files: plugins/application/libbluepin.so* bin/bluepin Priority: optional Section: opie/applications Maintainer: Holger Freyther <zecke@handhelds.org> Architecture: arm -Version: 0.3.4-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal License: GPL Description: Bluetooth pin application diff --git a/noncore/net/opietooth/blue-pin/pindlgbase.ui b/noncore/net/opietooth/blue-pin/pindlgbase.ui index 889a25e..6784de7 100644 --- a/noncore/net/opietooth/blue-pin/pindlgbase.ui +++ b/noncore/net/opietooth/blue-pin/pindlgbase.ui @@ -1,274 +1,274 @@ <!DOCTYPE UI><UI> <class>PinDlgBase</class> <author>zecke</author> <widget> <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>Form1</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>258</width> + <width>254</width> <height>245</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Please enter pin</string> </property> <vbox> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>txtStatus</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string></string> - </property> - <property stdset="1"> - <name>textFormat</name> - <enum>RichText</enum> - </property> - </widget> <spacer> <property> <name>name</name> <cstring>Spacer4_2</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>txtStatus</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string></string> + </property> + <property stdset="1"> + <name>textFormat</name> + <enum>RichText</enum> + </property> + </widget> + <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout6</cstring> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel3</cstring> </property> <property stdset="1"> <name>text</name> <string>Please enter PIN:</string> </property> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout5</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>lnePin</cstring> </property> <property stdset="1"> <name>echoMode</name> <enum>Password</enum> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer4</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Fixed</enum> </property> <property> <name>sizeHint</name> <size> <width>21</width> <height>20</height> </size> </property> </spacer> </hbox> </widget> <widget> <class>QCheckBox</class> <property stdset="1"> <name>name</name> <cstring>ckbPin</cstring> </property> <property stdset="1"> <name>text</name> <string>Save pin</string> </property> </widget> </vbox> </widget> <spacer> <property> <name>name</name> <cstring>Spacer5</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout7</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <spacer> <property> <name>name</name> <cstring>Spacer1</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Fixed</enum> </property> <property> <name>sizeHint</name> <size> <width>30</width> <height>20</height> </size> </property> </spacer> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>PushButton1</cstring> </property> <property stdset="1"> <name>text</name> <string>&Ok</string> </property> </widget> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>PushButton2</cstring> </property> <property stdset="1"> <name>text</name> <string>&Cancel</string> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer2</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Fixed</enum> </property> <property> <name>sizeHint</name> <size> <width>16</width> <height>20</height> </size> </property> </spacer> </hbox> </widget> </vbox> </widget> <connections> <connection> <sender>PushButton1</sender> <signal>clicked()</signal> <receiver>Form1</receiver> <slot>accept()</slot> </connection> <connection> <sender>PushButton2</sender> <signal>clicked()</signal> <receiver>Form1</receiver> <slot>reject()</slot> </connection> </connections> </UI> diff --git a/noncore/net/opietooth/lib/libopietooth1.control b/noncore/net/opietooth/lib/libopietooth1.control index 20e4b76..9bc9572 100644 --- a/noncore/net/opietooth/lib/libopietooth1.control +++ b/noncore/net/opietooth/lib/libopietooth1.control @@ -1,10 +1,10 @@ Package: libopietooth1 Files: lib/libopietooth1.so* Priority: optional Section: libs Maintainer: Maximilian Reiß <max.reiss@gmx.de> Architecture: arm Replaces: libopietooth -Depends: libqte2 (>=2.3.4), libopie1, task-bluez +Depends: libqte2 (>=2.3.4), libopiecore2, task-bluez Description: Opie bluetooth library Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/net/opietooth/manager/opie-bluetoothmanager.control b/noncore/net/opietooth/manager/opie-bluetoothmanager.control index 4fe1e06..89ab698 100644 --- a/noncore/net/opietooth/manager/opie-bluetoothmanager.control +++ b/noncore/net/opietooth/manager/opie-bluetoothmanager.control @@ -1,10 +1,10 @@ Package: opie-bluetoothmanager Files: plugins/application/libbluetooth-manager.so* bin/bluetooth-manager apps/Settings/bluetooth-manager.desktop pics/opietooth/* Priority: optional Section: opie/settings Maintainer: Maximilian Reiß <max.reiss@gmx.de> Architecture: arm -Version: 0.5.4-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, libopietooth1, opie-bluepin License: GPL Description: Bluetooth Manager application diff --git a/noncore/net/wellenreiter/opie-wellenreiter.control b/noncore/net/wellenreiter/opie-wellenreiter.control index e7bc25d..7dc9c22 100644 --- a/noncore/net/wellenreiter/opie-wellenreiter.control +++ b/noncore/net/wellenreiter/opie-wellenreiter.control @@ -1,10 +1,10 @@ Package: opie-wellenreiter Files: bin/wellenreiter pics/wellenreiter apps/Applications/wellenreiter.desktop Priority: optional Section: opie/applications Maintainer: Michael 'Mickey' Lauer <mickeyl@handhelds.org> Architecture: arm -Version: 1.0.3-cvs -Depends: libqpe1, libpcap0 (>=0.7.2), libopiecore2, libopienet2, libopieui2 +Version: $QPE_VERSION$EXTRAVERSION +Depends: libqpe1, libpcap0.8 (>=0.7.2), libopiecore2, libopienet2, libopieui2 Description: A WaveLAN Network Monitor A WaveLAN Network Monitor/Sniffer for the Opie Environment. diff --git a/noncore/securityplugins/blueping/bluepingplugin.control b/noncore/securityplugins/blueping/bluepingplugin.control index 0339996..62562f7 100644 --- a/noncore/securityplugins/blueping/bluepingplugin.control +++ b/noncore/securityplugins/blueping/bluepingplugin.control @@ -1,11 +1,11 @@ Package: opie-multiauth-bluepingplugin Files: plugins/security/libmultiauthbluepingplugin.so* pics/security/bluepingplugin.png root/etc/suspend-scripts/S50bluetooth Priority: optional Section: opie/settings Maintainer: Clement Seveillac <clement@nist.gov> Architecture: arm -Version: 0.0.2.7 +Version: $QPE_VERSION$EXTRAVERSION Depends: libopiecore2, opie-security, bluez-utils (<= 2.3rel-hh5) Description: Blueping plugin for opie-security authentication. This is a bluetooth-based authentication plugin (you need to have another Bluetooth device around to use it). diff --git a/noncore/securityplugins/dummy/dummyplugin.control b/noncore/securityplugins/dummy/dummyplugin.control index 0ab2491..b4cc5e2 100644 --- a/noncore/securityplugins/dummy/dummyplugin.control +++ b/noncore/securityplugins/dummy/dummyplugin.control @@ -1,11 +1,11 @@ Package: opie-multiauth-dummyplugin Files: plugins/security/libmultiauthdummyplugin.so* pics/security/dummyplugin.png Priority: optional Section: opie/settings Maintainer: Clement Seveillac <clement@nist.gov> Architecture: arm -Version: 0.0.2.3 +Version: $QPE_VERSION$EXTRAVERSION Depends: libopiecore2, opie-security Description: Dummy plugin for opie-security authentication. This is a very simple authentication plugin (you just have to press a button basically), for demonstration purpose. diff --git a/noncore/securityplugins/notice/notice.control b/noncore/securityplugins/notice/notice.control index 8b8c7cd..091ce74 100644 --- a/noncore/securityplugins/notice/notice.control +++ b/noncore/securityplugins/notice/notice.control @@ -1,11 +1,11 @@ Package: opie-multiauth-noticeplugin Files: plugins/security/libmultiauthnoticeplugin.so* pics/security/noticeplugin.png pics/security/noticeplugin_small.png Priority: optional Section: opie/settings Maintainer: Clement Seveillac <clement@nist.gov> Architecture: arm -Version: 0.0.1.6 +Version: $QPE_VERSION$EXTRAVERSION Depends: libopiecore2, opie-security Description: Notice plugin for opie-security authentication. It allows you to display e.g. a notice from your legal departement. diff --git a/noncore/securityplugins/pin/pin.control b/noncore/securityplugins/pin/pin.control index 3709d08..51c3f08 100644 --- a/noncore/securityplugins/pin/pin.control +++ b/noncore/securityplugins/pin/pin.control @@ -1,11 +1,11 @@ Package: opie-multiauth-pinplugin Files: plugins/security/libmultiauthpinplugin.so* pics/security/pinplugin.png Priority: optional Section: opie/settings Maintainer: Clement Seveillac <clement@nist.gov> Architecture: arm -Version: 0.0.2.6 +Version: $QPE_VERSION$EXTRAVERSION Depends: libopiecore2, opie-security Description: PIN plugin for opie-security authentication. Simple PIN-based authentication plugin (replicate the functionality Qtopia has, or Opie used to have, without plugins). diff --git a/noncore/settings/networksettings2/activatevpn.cpp b/noncore/settings/networksettings2/activatevpn.cpp index 2bdef0a..b75e623 100644 --- a/noncore/settings/networksettings2/activatevpn.cpp +++ b/noncore/settings/networksettings2/activatevpn.cpp @@ -1,53 +1,47 @@ #include <qlistview.h> #include <qheader.h> #include <resources.h> #include "activatevpn.h" class MyCheckListItem : public QCheckListItem { public : MyCheckListItem( NodeCollection * N, QListView * V ); NodeCollection * NC; }; MyCheckListItem::MyCheckListItem( NodeCollection * N, QListView * V ): QCheckListItem( V, N->name() ) { NC = N; } ActivateVPN::ActivateVPN( void ) : ActivateVPNGUI( 0, 0, TRUE ), NSD() { QCheckListItem * CI; - printf( "%d\n", __LINE__ ); VPN_LV->clear(); VPN_LV->header()->hide(); - printf( "%d\n", __LINE__ ); for( QDictIterator<NodeCollection> it(NSResources->connections()); it.current(); ++it ) { - printf( "%d\n", __LINE__ ); if( it.current()->triggeredBy( "vpn" ) ) { - printf( "%d\n", __LINE__ ); CI = new MyCheckListItem( it.current(), VPN_LV ); - printf( "%d\n", __LINE__ ); } - printf( "%d\n", __LINE__ ); } } ActivateVPN::~ActivateVPN( void ) { } void ActivateVPN::SLOT_ChangedVPNSetting( QListViewItem * I ) { MyCheckListItem * MI = (MyCheckListItem *)I; printf( "%s : %d\n", MI->text(0).latin1(), MI->isOn() ); } diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth.pro b/noncore/settings/networksettings2/bluetooth/bluetooth.pro index 8170d46..2e3b5bb 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth.pro +++ b/noncore/settings/networksettings2/bluetooth/bluetooth.pro @@ -1,22 +1,26 @@ TEMPLATE = lib CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/plugins/networksettings2 -HEADERS = bluetooth_NN.h \ +HEADERS = bluetoothBNEP_NN.h \ bluetoothBNEP_NNI.h \ + bluetoothRFCOMM_NN.h \ bluetoothRFCOMM_NNI.h \ bluetoothBNEPedit.h \ + bluetoothRFCOMMrun.h \ bluetoothRFCOMMedit.h -SOURCES = bluetooth_NN.cpp \ +SOURCES = bluetoothBNEP_NN.cpp \ bluetoothBNEP_NNI.cpp \ + bluetoothRFCOMM_NN.cpp \ bluetoothRFCOMM_NNI.cpp \ bluetoothBNEPedit.cpp \ bluetoothBNEPrun.cpp \ + bluetoothRFCOMMrun.cpp \ bluetoothRFCOMMedit.cpp -INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 -DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 -LIBS += -lqpe +INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 ../opietooth2 +DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 ../opietooth2 +LIBS += -lqpe -lopietooth2 INTERFACES = bluetoothBNEPGUI.ui bluetoothRFCOMMGUI.ui TARGET = bluetooth VERSION = 1.0.0 include( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp index 398dcdc..42b2515 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp @@ -1,42 +1,42 @@ #include "bluetoothBNEPedit.h" #include "bluetoothBNEP_NNI.h" -#include "bluetooth_NN.h" +#include "bluetoothBNEP_NN.h" ABluetoothBNEP::ABluetoothBNEP( BluetoothBNEPNetNode * PNN ) : ANetNodeInstance( PNN ), Data() { GUI = 0; RT = 0; Data.AllowAll = 1; } void ABluetoothBNEP::setSpecificAttribute( QString & S, QString & A ) { if( S == "bdaddress" ) { Data.BDAddress << A; } else if ( S == "allowall" ) { Data.AllowAll = 1; } } void ABluetoothBNEP::saveSpecificAttribute( QTextStream & TS ) { TS << "allowall=" << Data.AllowAll << endl; for ( QStringList::Iterator it = Data.BDAddress.begin(); it != Data.BDAddress.end(); ++it ) { TS << "bdaddress=" << (*it) << endl; } } QWidget * ABluetoothBNEP::edit( QWidget * parent ) { GUI = new BluetoothBNEPEdit( parent ); GUI->showData( Data ); return GUI; } QString ABluetoothBNEP::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ABluetoothBNEP::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h index 03c6903..f52a2c5 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h @@ -1,11 +1,14 @@ #ifndef BLUETOOTHBNEP_DATA_H #define BLUETOOTHBNEP_DATA_H #include <qstringlist.h> -typedef struct BluetoothBNEPData { +class BluetoothBNEPData { + +public : + bool AllowAll; QStringList BDAddress; -} BluetoothBNEPData_t; +}; #endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp index 24e4b7b..9d4ae97 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp @@ -1,249 +1,161 @@ #include <qfile.h> #include <qfileinfo.h> #include <qtextstream.h> #include <resources.h> #include "bluetoothBNEPrun.h" -QDict<QString> * BluetoothBNEPRun::PANConnections = 0; - -void BluetoothBNEPRun::detectState( NodeCollection * NC ) { - // unavailable : no card found - // available : card found and assigned to us or free - // up : card found and assigned to us and up - QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); - System & Sys = NSResources->system(); - InterfaceInfo * Run; - QFile F( S ); - - Log(("Detecting for %s\n", NC->name().latin1() )); - - if( F.open( IO_ReadOnly ) ) { - // could open file -> read interface and assign - QString X; - bool accepted = 0; - QTextStream TS(&F); - X = TS.readLine(); - Log(("%s exists : %s\n", S.latin1(), X.latin1() )); - // find interface - if( handlesInterface( X ) ) { - - Log(("Handles interface %s, PANC %p\n", X.latin1(), PANConnections )); - if( PANConnections == 0 ) { - // load connections that are active - // format : bnep0 00:60:57:02:71:A2 PANU - FILE * OutputOfCmd = popen( "pand --show", "r" ) ; - - PANConnections = new QDict<QString>; - - if( OutputOfCmd ) { - char ch; - // could fork - // read all data - QString Line = ""; - while( 1 ) { - if( fread( &ch, 1, 1, OutputOfCmd ) < 1 ) { - // eof - break; - } - if( ch == '\n' || ch == '\r' ) { - if( ! Line.isEmpty() ) { - if( Line.startsWith( "bnep" ) ) { - QStringList SL = QStringList::split( " ", Line ); - Log(("Detected PAN %s %s\n", - SL[0].latin1(), SL[1].latin1() )); - PANConnections->insert( SL[0], new QString(SL[1])); - } - Line=""; - } - } else { - Line += ch; +BluetoothBNEPRun::BluetoothBNEPRun( ANetNodeInstance * NNI, + BluetoothBNEPData & D ) : + RuntimeInfo( NNI ), + Data( D), + Pat( "bnep[0-6]" ) { + OT = 0; } + +BluetoothBNEPRun::~BluetoothBNEPRun( void ) { + if( OT ) { + OTGateway::releaseOTGateway(); } } - pclose( OutputOfCmd ); - } +State_t BluetoothBNEPRun::detectState( void ) { - // check if this runtime allows connection to node - if( ! Data.AllowAll ) { - // has addresses - for ( QStringList::Iterator it = Data.BDAddress.begin(); - ! accepted && it != Data.BDAddress.end(); - ++ it ) { - for( QDictIterator<QString> it2( *(PANConnections) ); - it2.current(); - ++ it2 ) { - if( X == it2.currentKey() && - (*it) == *(it2.current()) - ) { - // found - Log(("%s accepts connections to %s\n", - NC->name().latin1(), - it2.current()->latin1() )); - accepted = 1; - break; - } - } - } - } else { - Log(("%s accepts any connection\n", NC->name().latin1() )); - // accept any - accepted = 1; - } + /* - if( accepted ) { - // matches and is allowed for this node - for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); - It.current(); - ++It ) { - Run = It.current(); - if( X == Run->Name ) { - Log(("%s Assigned %p\n", NC->name().latin1(), Run )); - Run->assignNode( netNode() ); - assignInterface( Run ); - NC->setCurrentState( IsUp ); - return; - } - } - } - } - } + need to detect - Log(("Assigned %p\n", assignedInterface() )); - if( ( Run = assignedInterface() ) ) { - // we already have an interface assigned -> still present ? - if( ! Run->IsUp ) { - // usb is still free -> keep assignment - NC->setCurrentState( Available ); - return; - } // else interface is up but NOT us -> some other profile - } - - // nothing (valid) assigned to us - assignInterface( 0 ); - - // find possible interface - for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); - It.current(); - ++It ) { - Run = It.current(); - - Log(("%s %d %d=%d %d\n", - Run->Name.latin1(), - handlesInterface( Run->Name ), - Run->CardType, ARPHRD_ETHER, - ! Run->IsUp )); - - if( handlesInterface( Run->Name ) && - Run->CardType == ARPHRD_ETHER && - ! Run->IsUp - ) { - Log(("Released(OFF)\n" )); - // proper type, and Not UP -> free - NC->setCurrentState( Off ); - return; + 1. for any PAN connection that is found if that + PAN is connected. + + if it is connected it is not available (since we do + not manage IP settings and we are called to detect + the state we knwo that we do not have an UP connection) + + 2. if it not connected and we allow any connection we + are available or if that PAN connection is to a device + with a correct address + + 3. if it is not connected and the address do not match or + we do not accept any address, we are Unavailable but + not DOWN. I.e a new connection could perhaps be created + + */ + + if( ! OT ) { + OT = OTGateway::getOTGateway(); } + + if( ! OT->isEnabled() ) { + return Unavailable; } - // no free found - Log(("None available\n" )); - NC->setCurrentState( Unavailable ); + // if there is a PAN connection that is UP but not + // yet configured (no ifup) the we are available + return ( hasFreePANConnection() ) ? Available : Unknown; } -bool BluetoothBNEPRun::setState( NodeCollection * NC, Action_t A, bool ) { +QString BluetoothBNEPRun::setMyState( NodeCollection * NC, Action_t A, bool ) { - // we only handle activate and deactivate - switch( A ) { - case Activate : - { - if( NC->currentState() != Off ) { - return 0; - } - InterfaceInfo * N = getInterface(); - if( ! N ) { - // no interface available - NC->setCurrentState( Unavailable ); - return 0; + if( A == Activate ) { + if( hasFreePANConnection( 1 ) ) { + // we have now an assignedinterface + } else { + return QString("TODO : Start PAND"); } - // because we were OFF the interface - // we get back is NOT assigned - N->assignNode( netNode() ); - assignInterface( N ); - Log(("Assing %p\n", N )); + + Log(( "Assigned interface" )); NC->setCurrentState( Available ); - return 1; - } - case Deactivate : - if( NC->currentState() == IsUp ) { - // bring down first - if( ! connection()->setState( Down ) ) - // could not ... - return 0; - } else if( NC->currentState() != Available ) { - return 1; + + return QString(); } - assignedInterface()->assignNode( 0 ); // release - assignInterface( 0 ); + + if( A == Deactivate ) { + // nothing to do NC->setCurrentState( Off ); - return 1; - default : - // FT - break; + return QString(); } - return 0; + return QString(); } -bool BluetoothBNEPRun::canSetState( State_t Curr , Action_t A ) { - // we only handle up down activate and deactivate - switch( A ) { - case Activate : - { // at least available - if( Curr == Available ) { - return 1; +bool BluetoothBNEPRun::handlesInterface( const QString & S ) { + return Pat.match( S ) >= 0; } - // or we can make one available - InterfaceInfo * N = getInterface(); - if( ! N || N->assignedNode() != 0 ) { - // non available or assigned - return 0; + +bool BluetoothBNEPRun::handlesInterface( InterfaceInfo * I ) { + return handlesInterface( I->Name ); } - return 1; + +bool BluetoothBNEPRun::hasFreePANConnection( bool Grab ) { + + if( ! OT ) { + OT = OTGateway::getOTGateway(); } - case Deactivate : - return ( Curr >= Available ); - default : - // FT + + // load PAN connections + OTPANConnection * C; + InterfaceInfo * Run; + InterfaceInfo * Candidate = 0; // reuse this interface + PANConnectionVector Conns = OT->getPANConnections(); + System & Sys = NSResources->system(); + bool IsValid; + + for( unsigned int i = 0; + i < Conns.count(); + i ++ ) { + C = Conns[i]; + + if( Data.AllowAll ) { + // we allow all + IsValid = 1; + } else { + // is this PAN connection connecting to a Peer + // we allow ? + IsValid = 0; + for ( QStringList::Iterator it = Data.BDAddress.begin(); + it != Data.BDAddress.end(); + ++ it ) { + if( C->ConnectedTo == (*it) ) { + // this is a connection we could accept + IsValid = 1; break; } - return 0; + } } -// get interface that is free or assigned to us -InterfaceInfo * BluetoothBNEPRun::getInterface( void ) { + if( ! IsValid ) { + Log(("%s to %s not acceptable\n", + C->Device.latin1(), + C->ConnectedTo.latin1() )); + // don't bother checking this address + // it is not acceptable + continue; + } - System & S = NSResources->system(); - InterfaceInfo * best = 0, * Run; + // is this PAN connection available to us ? + Run = Sys.findInterface( C->Device ); - for( QDictIterator<InterfaceInfo> It(S.interfaces()); - It.current(); - ++It ) { - Run = It.current(); - if( handlesInterface( Run->Name ) && - Run->CardType == ARPHRD_ETHER - ) { - // this is a bluetooth card - if( Run->assignedNode() == netNode() ) { - // assigned to us - return Run; - } else if( Run->assignedNode() == 0 ) { - // free - best = Run; + if( Run && Run->IsUp ) { + // this PAN connection is up + Log(("%s acceptable but unavailable\n", + C->Device.latin1() )); + // find others + continue; } + + // we at least have a possible interface + if( ! Candidate ) { + Candidate = Run; } } - return best; // can be 0 + + if( Candidate ) { + if ( Grab ) { + netNode()->connection()->assignInterface( Candidate ); + } + return 1; } -bool BluetoothBNEPRun::handlesInterface( const QString & S ) { - return Pat.match( S ) >= 0; + // no free PAN + return 0; } + diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h index ce03cbb..a05a7a2 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h @@ -1,34 +1,35 @@ -#include <asdevice.h> +#include <netnode.h> #include "bluetoothBNEPdata.h" -class BluetoothBNEPRun : public AsDevice { +#include <OTGateway.h> +using namespace Opietooth2; + +class BluetoothBNEPRun : public RuntimeInfo { public : BluetoothBNEPRun( ANetNodeInstance * NNI, - BluetoothBNEPData & D ) : - AsDevice( NNI ), - Data( D), - Pat( "bnep[0-6]" ) - { } + BluetoothBNEPData & D ); + virtual ~BluetoothBNEPRun( void ); + + // i am a device + virtual RuntimeInfo * device( void ) + { return this; } - virtual AsDevice * asDevice( void ) - { return (AsDevice *)this; } + bool handlesInterface( const QString & ); + bool handlesInterface( InterfaceInfo * ); - virtual AsDevice * device( void ) - { return asDevice(); } + State_t detectState( void ); protected : - void detectState( NodeCollection * ); - bool setState( NodeCollection * , Action_t, bool ); - bool canSetState( State_t , Action_t ); - bool handlesInterface( const QString & ); + QString setMyState( NodeCollection * , Action_t, bool ); private : - InterfaceInfo * getInterface( void ); + bool hasFreePANConnection( bool Grab = 0 ); + BluetoothBNEPData & Data; - static QDict<QString> * PANConnections; + OTGateway * OT; QRegExp Pat; }; diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMGUI.ui b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMGUI.ui index 2754a70..7f6565a 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMGUI.ui +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMGUI.ui @@ -1,131 +1,331 @@ <!DOCTYPE UI><UI> <class>BluetoothRFCOMMGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>BluetoothRFCOMM_FRM</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>283</width> - <height>199</height> + <width>488</width> + <height>604</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Bluetooth-rfcomm</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> - <number>2</number> + <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>2</number> + <number>3</number> </property> <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel5_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Selected devices with gprs capability</string> + </property> + <property stdset="1"> + <name>alignment</name> + <set>WordBreak|AlignVCenter|AlignLeft</set> + </property> + <property> + <name>wordwrap</name> + </property> + </widget> + <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout4</cstring> + <cstring>Layout8</cstring> + </property> + <property> + <name>layoutSpacing</name> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>3</number> </property> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel4</cstring> + <cstring>TextLabel5</cstring> </property> <property stdset="1"> <name>text</name> - <string>Name</string> + <string>Address</string> </property> </widget> <widget> <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>Name_LE</cstring> + <cstring>Address_LE</cstring> + </property> + </widget> + <widget> + <class>QToolButton</class> + <property stdset="1"> + <name>name</name> + <cstring>FindDevice_TB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>...</string> </property> </widget> </hbox> </widget> <widget> + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout7</cstring> + </property> + <property> + <name>layoutSpacing</name> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>3</number> + </property> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Channel</string> + </property> + </widget> + <widget> + <class>QSpinBox</class> + <property stdset="1"> + <name>name</name> + <cstring>Channel_SB</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>minValue</name> + <number>1</number> + </property> + </widget> + <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel3</cstring> + <cstring>TextLabel2_2</cstring> </property> <property stdset="1"> <name>text</name> - <string>Description</string> + <string>Name</string> </property> </widget> <widget> - <class>QMultiLineEdit</class> + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>Description_LE</cstring> + <cstring>Name_LBL</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Box</enum> </property> + <property stdset="1"> + <name>indent</name> + <number>0</number> + </property> + </widget> + </hbox> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout5</cstring> </property> + <property> + <name>layoutSpacing</name> + </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>3</number> </property> <widget> - <class>QCheckBox</class> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel7</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>text</name> + <string>Addresses</string> + </property> + <property stdset="1"> + <name>alignment</name> + <set>AlignVCenter|AlignLeft</set> + </property> + <property> + <name>vAlign</name> + </property> + </widget> + <widget> + <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>Automatic_CB</cstring> + <cstring>Add_TB</cstring> </property> <property stdset="1"> <name>text</name> - <string>Start automatically</string> + <string>...</string> </property> </widget> <widget> - <class>QCheckBox</class> + <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>Confirm_CB</cstring> + <cstring>Remove_TB</cstring> </property> <property stdset="1"> <name>text</name> - <string>Confirm before start</string> + <string>...</string> </property> </widget> </hbox> </widget> + <widget> + <class>QListView</class> + <column> + <property> + <name>text</name> + <string>Name</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Channel</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Address</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <property stdset="1"> + <name>name</name> + <cstring>Addresses_LV</cstring> + </property> + <property stdset="1"> + <name>allColumnsShowFocus</name> + <bool>true</bool> + </property> + </widget> </vbox> </widget> +<connections> + <connection> + <sender>Add_TB</sender> + <signal>clicked()</signal> + <receiver>BluetoothRFCOMM_FRM</receiver> + <slot>SLOT_AddServer()</slot> + </connection> + <connection> + <sender>Remove_TB</sender> + <signal>clicked()</signal> + <receiver>BluetoothRFCOMM_FRM</receiver> + <slot>SLOT_RemoveServer()</slot> + </connection> + <connection> + <sender>FindDevice_TB</sender> + <signal>clicked()</signal> + <receiver>BluetoothRFCOMM_FRM</receiver> + <slot>SLOT_FindDevice()</slot> + </connection> + <slot access="public">SLOT_AddServer()</slot> + <slot access="public">SLOT_RemoveServer()</slot> + <slot access="public">SLOT_FindDevice()</slot> +</connections> </UI> diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp index 7ec8288..d19386e 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp @@ -1,30 +1,49 @@ #include "bluetoothRFCOMMedit.h" #include "bluetoothRFCOMM_NNI.h" -#include "bluetooth_NN.h" +#include "bluetoothRFCOMM_NN.h" -ABluetoothRFCOMM::ABluetoothRFCOMM( BluetoothRFCOMMNetNode * PNN ) : ANetNodeInstance( PNN ) { +ABluetoothRFCOMM::ABluetoothRFCOMM( BluetoothRFCOMMNetNode * PNN ) : + ANetNodeInstance( PNN ), Data() { + Data.Devices.setAutoDelete( TRUE ); GUI = 0; RT = 0; } -void ABluetoothRFCOMM::setSpecificAttribute( QString & , QString & ) { +void ABluetoothRFCOMM::setSpecificAttribute( QString & A, QString & V) { + + if( A == "bdaddress" ) { + Data.Devices.resize( Data.Devices.size() + 1 ); + Data.Devices.insert( Data.Devices.size() - 1, new RFCOMMChannel); + Data.Devices[ Data.Devices.size() - 1 ]->BDAddress = V; + } else if ( A == "channel" ) { + Data.Devices[ Data.Devices.size() - 1 ]->Channel = V.toLong(); + } else if ( A == "name" ) { + Data.Devices[ Data.Devices.size() - 1 ]->Name = V; + } } -void ABluetoothRFCOMM::saveSpecificAttribute( QTextStream & ) { +void ABluetoothRFCOMM::saveSpecificAttribute( QTextStream & TS ) { + for( unsigned int i = 0 ; + i < Data.Devices.count(); + i ++ ) { + TS << "bdaddress=" << Data.Devices[i]->BDAddress << endl; + TS << "name=" << quote( Data.Devices[i]->Name ) << endl; + TS << "channel=" << Data.Devices[i]->Channel << endl; + } } QWidget * ABluetoothRFCOMM::edit( QWidget * parent ) { GUI = new BluetoothRFCOMMEdit( parent ); GUI->showData( Data ); return GUI; } QString ABluetoothRFCOMM::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ABluetoothRFCOMM::commit( void ) { if( GUI->commit( Data ) ) setModified( 1 ); } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMdata.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMdata.h index 18f0d38..14cfeb0 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMdata.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMdata.h @@ -1,18 +1,22 @@ #ifndef BLUETOOTHRFCOMM_DATA_H #define BLUETOOTHRFCOMM_DATA_H #include <qstring.h> +#include <qvector.h> -typedef struct BluetoothRFCOMMData { - QString Device; - QString LockFile; - long Speed; - short Parity; - short DataBits; - short StopBits; - bool HardwareControl; - bool SoftwareControl; +class RFCOMMChannel { -} BluetoothRFCOMMData_t; +public : + QString BDAddress; + QString Name; + int Channel; +}; + +class BluetoothRFCOMMData { + +public : + + QVector<RFCOMMChannel> Devices; +}; #endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp index d3ddab4..7cac13f 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp @@ -1,18 +1,156 @@ +#include <qlistview.h> +#include <qdialog.h> +#include <qlabel.h> +#include <qlineedit.h> +#include <qtoolbutton.h> +#include <qcheckbox.h> +#include <qspinbox.h> +#include <OTPeer.h> +#include <OTGateway.h> +#include <Opietooth.h> +#include <resources.h> #include <GUIUtils.h> #include "bluetoothRFCOMMedit.h" +using namespace Opietooth2; + +class PeerLBI : public QListViewItem { + +public : + + PeerLBI( OTPeer * P, int Ch, QListView * LV ) : QListViewItem( LV ) { + Peer = P; + Channel = Ch; + + setText( 0, (P->name().isEmpty()) ? + P->address().toString() : + P->name() ); + QString S; + S.setNum( Ch ); + setText( 1, S ); + setText( 2, P->address().toString() ); + } + ~PeerLBI( ) { + } + + inline int channel( void ) const + { return Channel; } + inline OTPeer * peer( void ) const + { return Peer; } + + int Channel; + OTPeer * Peer; +}; + BluetoothRFCOMMEdit::BluetoothRFCOMMEdit( QWidget * Parent ) : BluetoothRFCOMMGUI( Parent ){ + Modified = 0; + OT = OTGateway::getOTGateway(); + + Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); + Remove_TB->setPixmap( NSResources->getPixmap( "remove" ) ); + FindDevice_TB->setPixmap( NSResources->getPixmap( "Devices/bluetooth" ) ); + Addresses_LV->setColumnAlignment( 1, Qt::AlignRight ); +} +BluetoothRFCOMMEdit::~BluetoothRFCOMMEdit( void ) { + OTGateway::releaseOTGateway(); } QString BluetoothRFCOMMEdit::acceptable( void ) { return QString(); } +bool BluetoothRFCOMMEdit::commit( BluetoothRFCOMMData & Data ) { + int ct = 0; + PeerLBI * I; + + if( Modified ) { + QListViewItem * it = Addresses_LV->firstChild(); + + Data.Devices.resize( 0 ); + while( it ) { + + ct ++; + Data.Devices.resize( ct ); + I = (PeerLBI * )it; + + Data.Devices.insert( ct-1, new RFCOMMChannel ); + + Data.Devices[ct-1]->BDAddress = I->peer()->address().toString(); + Data.Devices[ct-1]->Name = I->peer()->name(); + Data.Devices[ct-1]->Channel = I->channel(); + + it = it->nextSibling(); + } + } + + return Modified; +} + void BluetoothRFCOMMEdit::showData( BluetoothRFCOMMData & Data ) { + + OTPeer * P; + + for( unsigned int i = 0; + i < Data.Devices.count(); + i ++ ) { + P = new OTPeer( OT ); + P->setAddress( OTDeviceAddress( Data.Devices[i]->BDAddress ) ); + P->setName( Data.Devices[i]->Name ); + + new PeerLBI( P, Data.Devices[i]->Channel, Addresses_LV ); + } + Modified = 0; } -bool BluetoothRFCOMMEdit::commit( BluetoothRFCOMMData & Data ) { - return 0; +void BluetoothRFCOMMEdit::SLOT_AddServer( void ) { + QListViewItem * it = Addresses_LV->firstChild(); + + while( it ) { + // check address + if( it->text(2) == Address_LE->text() ) { + // already in table + return; + } + it = it->nextSibling(); + } + + // new server + Modified = 1; + OTPeer * P = new OTPeer( OT ); + P->setAddress( OTDeviceAddress( Address_LE->text() ) ); + P->setName( Name_LBL->text() ); + new PeerLBI( P, Channel_SB->value(), Addresses_LV ); + + Address_LE->setText(""); + Name_LBL->setText(""); + Channel_SB->setValue(1); +} + +void BluetoothRFCOMMEdit::SLOT_RemoveServer( void ) { + + QListViewItem * it = Addresses_LV->firstChild(); + + while( it ) { + // check address + if( it->isSelected() ) { + delete it; + Modified = 1; + return; + } + it = it->nextSibling(); + } +} + +void BluetoothRFCOMMEdit::SLOT_FindDevice( void ) { + OTPeer * Peer; + int Channel; + + // find device in Opietooth + if( OTScan::getDevice( Peer, Channel, OT ) == QDialog::Accepted ) { + Address_LE->setText( Peer->address().toString() ); + Name_LBL->setText( Peer->name() ); + Channel_SB->setValue( Channel ); + } } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.h index 14a6d64..9ad8f2a 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.h @@ -1,13 +1,27 @@ #include "bluetoothRFCOMMdata.h" #include "bluetoothRFCOMMGUI.h" +#include <Opietooth.h> +using namespace Opietooth2; + class BluetoothRFCOMMEdit : public BluetoothRFCOMMGUI { public : BluetoothRFCOMMEdit( QWidget * parent ); + virtual ~BluetoothRFCOMMEdit( void ); QString acceptable( void ); void showData( BluetoothRFCOMMData & Data ); bool commit( BluetoothRFCOMMData & Data ); + + bool Modified; + OTGateway * OT; + +public slots : + + void SLOT_AddServer( void ); + void SLOT_RemoveServer( void ); + void SLOT_FindDevice( void ); + }; diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h index 65fd686..24e3dae 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h @@ -1,28 +1,33 @@ -#include <asline.h> +#include <netnode.h> #include "bluetoothRFCOMMdata.h" -class BluetoothRFCOMMRun : public AsLine { +#include <OTGateway.h> +using namespace Opietooth2; + +class BluetoothRFCOMMRun : public RuntimeInfo { public : BluetoothRFCOMMRun( ANetNodeInstance * NNI, - BluetoothRFCOMMData & Data ) : AsLine( NNI ) - { } + BluetoothRFCOMMData & D ) : RuntimeInfo( NNI ) + { DeviceNr = -1; Data = &D; OT = 0; } + virtual ~BluetoothRFCOMMRun( void ); - virtual AsLine * asLine( void ) - { return (AsLine *)this; } + virtual RuntimeInfo * line( void ) + { return this; } + virtual QString deviceFile( void ); - virtual QString deviceFile( void ) - { return QString( "/dev/rfcomm..." ); } + State_t detectState( void ); protected : - void detectState( NodeCollection * ) - { } + QString setMyState( NodeCollection * , Action_t, bool ); - bool setState( NodeCollection * , Action_t, bool ) - { return 0; } +private : - bool canSetState( State_t , Action_t ) - { return 0; } + int deviceNrOfConnection( void ); + RFCOMMChannel * getChannel( void ); + BluetoothRFCOMMData * Data; + Opietooth2::OTGateway * OT; + int DeviceNr; // cached from detection }; diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp index 443a627..9be6b16 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp @@ -1,115 +1,120 @@ #include "bluetooth_NN.h" #include "bluetoothBNEP_NNI.h" #include "bluetoothRFCOMM_NNI.h" // // // BLUETOOTH PAN/NAP node // // static const char * BluetoothBNEPNeeds[] = { 0 }; +static const char * BluetoothBNEPProvides[] = + { "device", + 0 + }; + /** * Constructor, find all of the possible interfaces */ BluetoothBNEPNetNode::BluetoothBNEPNetNode() : ANetNode(tr("Bluetooth PAN/NAP")) { InstanceCount = 7; // default } /** * Delete any interfaces that we own. */ BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){ } const QString BluetoothBNEPNetNode::nodeDescription(){ return tr("\ <p>Sets up a bluetooth link using the bluetooth Network profile.</p>\ <p>Use this to connect two computing devices.</p>\ " ); } ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { return new ABluetoothBNEP( this ); } const char ** BluetoothBNEPNetNode::needs( void ) { return BluetoothBNEPNeeds; } -const char * BluetoothBNEPNetNode::provides( void ) { - return "device"; +const char ** BluetoothBNEPNetNode::provides( void ) { + return BluetoothBNEPProvides; } QString BluetoothBNEPNetNode::genNic( long nr ) { QString S; return S.sprintf( "bnep%ld", nr ); } void BluetoothBNEPNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { InstanceCount = V.toLong(); } } void BluetoothBNEPNetNode::saveSpecificAttribute( QTextStream & TS) { TS << "interfacecount=" << InstanceCount << endl; } // // // BLUETOOTH RFCOMM // // static const char * BluetoothRFCOMMNeeds[] = { 0 }; BluetoothRFCOMMNetNode::BluetoothRFCOMMNetNode() : ANetNode( tr("Bluetooth serial link") ) { } BluetoothRFCOMMNetNode::~BluetoothRFCOMMNetNode(){ } const QString BluetoothRFCOMMNetNode::nodeDescription(){ return tr("\ <p>Sets up a bluetooth link using the bluetooth serial profile.</p>\ <p>Use this to connect to a GSM.</p>\ " ); } ANetNodeInstance * BluetoothRFCOMMNetNode::createInstance( void ) { return new ABluetoothRFCOMM( this ); } const char ** BluetoothRFCOMMNetNode::needs( void ) { return BluetoothRFCOMMNeeds; } const char * BluetoothRFCOMMNetNode::provides( void ) { return "line"; } void BluetoothRFCOMMNetNode::setSpecificAttribute( QString &, QString & ) { } void BluetoothRFCOMMNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new BluetoothBNEPNetNode() ); PNN.append( new BluetoothRFCOMMNetNode() ); } } diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h index 4d6a3c1..b93342e 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h @@ -1,66 +1,66 @@ #ifndef BLUETOOTH_NETNODE_H #define BLUETOOTH_NETNODE_H #include "netnode.h" class ABluetoothBNEP; class BluetoothBNEPNetNode : public ANetNode { Q_OBJECT public: BluetoothBNEPNetNode(); virtual ~BluetoothBNEPNetNode(); virtual QString genNic( long ); virtual long instanceCount( void ) { return InstanceCount; } virtual const QString pixmapName() { return "Devices/bluetooth"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); virtual const char ** needs( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); // number of interfaces for this device long InstanceCount; }; class BluetoothRFCOMMNetNode : public ANetNode { Q_OBJECT public: BluetoothRFCOMMNetNode(); virtual ~BluetoothRFCOMMNetNode(); virtual const QString pixmapName() { return "Devices/bluetooth"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/bluetooth/config.in b/noncore/settings/networksettings2/bluetooth/config.in index 6968ac8..398cff1 100644 --- a/noncore/settings/networksettings2/bluetooth/config.in +++ b/noncore/settings/networksettings2/bluetooth/config.in @@ -1,4 +1,4 @@ config NS2BT boolean "opie-networksettings2plugin-bluetooth (set up BLUETOOTH)" default "n" if NS2 - depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH diff --git a/noncore/settings/networksettings2/bluetooth/opie-networksettings2plugin-bluetooth.control b/noncore/settings/networksettings2/bluetooth/opie-networksettings2plugin-bluetooth.control index ea77bd7..c4d29f2 100644 --- a/noncore/settings/networksettings2/bluetooth/opie-networksettings2plugin-bluetooth.control +++ b/noncore/settings/networksettings2/bluetooth/opie-networksettings2plugin-bluetooth.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-bluetooth +Package: opie-networksettings2plugin-bluetooth Files: plugins/networksettings2/libbluetooth.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm -Depends: opie-networksettings2, libopiecore2, libopienet2 +Depends: opie-networksettings2, libopietooth2, libopiecore2, libopienet2 Description: Network settings bluetooth plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/cable/cable_NN.cpp b/noncore/settings/networksettings2/cable/cable_NN.cpp index 38568df..dc4205c 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.cpp +++ b/noncore/settings/networksettings2/cable/cable_NN.cpp @@ -1,49 +1,54 @@ #include "cable_NN.h" #include "cable_NNI.h" static const char * CableNeeds[] = { 0 }; +static const char * CableProvides[] = + { "line", + 0 + }; + /** * Constructor, find all of the possible interfaces */ CableNetNode::CableNetNode() : ANetNode(tr("Cable Connection")) { } /** * Delete any interfaces that we own. */ CableNetNode::~CableNetNode(){ } const QString CableNetNode::nodeDescription(){ return tr("\ <p>Sets up a wired serial or parallel.</p>\ " ); } ANetNodeInstance * CableNetNode::createInstance( void ) { return new ACable( this ); } const char ** CableNetNode::needs( void ) { return CableNeeds; } -const char * CableNetNode::provides( void ) { - return "line"; +const char ** CableNetNode::provides( void ) { + return CableProvides; } void CableNetNode::setSpecificAttribute( QString & , QString & ) { } void CableNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new CableNetNode() ); } } diff --git a/noncore/settings/networksettings2/cable/cable_NN.h b/noncore/settings/networksettings2/cable/cable_NN.h index 5cc2b2d..8d649cc 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.h +++ b/noncore/settings/networksettings2/cable/cable_NN.h @@ -1,36 +1,36 @@ #ifndef CABLE_NETNODE_H #define CABLE_NETNODE_H #include "netnode.h" class ACable; class CableNetNode : public ANetNode { Q_OBJECT public: CableNetNode(); virtual ~CableNetNode(); virtual const QString pixmapName() { return "Devices/cable"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/cable/cable_NNI.cpp b/noncore/settings/networksettings2/cable/cable_NNI.cpp index 4bd9421..12a00a2 100644 --- a/noncore/settings/networksettings2/cable/cable_NNI.cpp +++ b/noncore/settings/networksettings2/cable/cable_NNI.cpp @@ -1,89 +1,87 @@ #include "cableedit.h" #include "cable_NNI.h" #include "cable_NN.h" ACable::ACable( CableNetNode * PNN ) : ANetNodeInstance( PNN ) { // default values Data.Device = "/dev/ttyS0"; Data.LockFile = "/var/Lock"; Data.Speed = 115200; Data.DataBits = 8; Data.Parity = 0; Data.StopBits = 1; Data.HardwareControl = 0; Data.SoftwareControl = 0; GUI = 0; RT = 0; } void ACable::setSpecificAttribute( QString & A, QString & V) { if( A == "device" ) { Data.Device = V; } else if ( A == "lockfile" ) { Data.LockFile = V; } else if ( A == "speed" ) { Data.Speed = V.toLong(); } else if ( A == "parity" ) { Data.Parity = V.toShort(); } else if ( A == "databits" ) { Data.DataBits = V.toShort(); } else if ( A == "stopbits" ) { Data.StopBits = V.toShort(); } else if ( A == "hardwarecontrol" ) { Data.HardwareControl = ( V == "yes" ); } else if ( A == "softwarecontrol" ) { Data.SoftwareControl = ( V == "yes" ); } } void ACable::saveSpecificAttribute( QTextStream & TS ) { TS << "device=" << quote( Data.Device ) << endl; TS << "lockfile=" << quote( Data.LockFile ) << endl; TS << "speed=" << Data.Speed << endl; TS << "parity=" << Data.Parity << endl; TS << "databits=" << Data.DataBits << endl; TS << "stopbits=" << Data.StopBits << endl; TS << "hardwarecontrol=" << ((Data.HardwareControl) ? "yes" : "no") << endl; TS << "softwarecontrol=" << ((Data.SoftwareControl) ? "yes" : "no") << endl; } -short ACable::generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, +short ACable::generateFileEmbedded( SystemFile & SF, long DevNr ) { short rvl, rvd; rvl = 1; - if( ID == "peers" ) { - TS << Data.Device + if( SF.name() == "peers" ) { + SF << Data.Device << endl; - TS << Data.Speed + SF << Data.Speed << endl; - TS << "lock " + SF << "lock " << Data.LockFile << endl; rvl = 0; } - rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + rvd = ANetNodeInstance::generateFileEmbedded( SF, DevNr ); return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } QWidget * ACable::edit( QWidget * parent ) { GUI = new CableEdit( parent ); GUI->showData( Data ); return GUI; } QString ACable::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ACable::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } diff --git a/noncore/settings/networksettings2/cable/cable_NNI.h b/noncore/settings/networksettings2/cable/cable_NNI.h index d06cbbe..18a52de 100644 --- a/noncore/settings/networksettings2/cable/cable_NNI.h +++ b/noncore/settings/networksettings2/cable/cable_NNI.h @@ -1,46 +1,44 @@ #ifndef CABLE_H #define CABLE_H #include <netnode.h> #include "cabledata.h" #include "cablerun.h" class CableNetNode; class CableEdit; class ACable : public ANetNodeInstance { public : ACable( CableNetNode * PNN ); RuntimeInfo * runtime( void ) { return ( RT ) ? RT : ( RT = new CableRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); virtual void * data( void ) { return (void *)&Data; } - short generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, + short generateFileEmbedded( SystemFile & Sf, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : CableEdit * GUI; - CableData_t Data; + CableData Data; CableRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/cable/cabledata.h b/noncore/settings/networksettings2/cable/cabledata.h index c449d96..ea81f8d 100644 --- a/noncore/settings/networksettings2/cable/cabledata.h +++ b/noncore/settings/networksettings2/cable/cabledata.h @@ -1,18 +1,21 @@ #ifndef CABLE_DATA_H #define CABLE_DATA_H #include <qstring.h> -typedef struct CableData { +class CableData { + +public : + QString Device; QString LockFile; long Speed; short Parity; short DataBits; short StopBits; bool HardwareControl; bool SoftwareControl; -} CableData_t; +}; #endif diff --git a/noncore/settings/networksettings2/cable/cableedit.cpp b/noncore/settings/networksettings2/cable/cableedit.cpp index 6e1a13b..4e57845 100644 --- a/noncore/settings/networksettings2/cable/cableedit.cpp +++ b/noncore/settings/networksettings2/cable/cableedit.cpp @@ -1,68 +1,68 @@ #include <GUIUtils.h> #include <stdio.h> #include <qlineedit.h> #include <qcombobox.h> #include <qspinbox.h> #include <qcheckbox.h> #include "cabledata.h" #include "cableedit.h" static long SpeedTable[] = { 2400, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000, -1 }; CableEdit::CableEdit( QWidget * Parent ) : CableGUI( Parent ) { } -void CableEdit::showData( CableData_t & D ) { +void CableEdit::showData( CableData & D ) { DeviceFile_LE->setText( D.Device ); LockFile_LE->setText( D.LockFile ); for( long * Run = SpeedTable; *Run != -1; *Run ++ ) { if( *Run == D.Speed ) { Speed_CB->setCurrentItem( ((long)(Run)-(long)(SpeedTable))/sizeof(long) ); break; } } Parity_CB->setCurrentItem( D.Parity ); DataBits_SB->setValue( D.DataBits ); StopBits_CB->setCurrentItem( D.StopBits ); HardwareFC_CB->setChecked( D.HardwareControl ); SoftwareFC_CB->setChecked( D.SoftwareControl ); } QString CableEdit::acceptable( void ) { if( DeviceFile_LE->text().isEmpty() ) return tr("Device filename needed"); return QString(); } -bool CableEdit::commit( CableData_t & D ) { +bool CableEdit::commit( CableData & D ) { bool SM = 0; TXTM( D.Device, DeviceFile_LE, SM ); TXTM( D.LockFile, LockFile_LE, SM ); for( long * Run = SpeedTable; *Run != -1; *Run ++ ) { if( *Run == D.Speed ) { if( D.Speed != Speed_CB->currentText().toLong() ) { SM = 1; D.Speed = Speed_CB->currentText().toLong(); } break; } } CIM(D.Parity, Parity_CB, SM ); SBM(D.DataBits, DataBits_SB, SM ); CIM(D.StopBits, StopBits_CB, SM ); CBM( D.HardwareControl, HardwareFC_CB, SM ); CBM( D.SoftwareControl, SoftwareFC_CB, SM ); return SM; } diff --git a/noncore/settings/networksettings2/cable/cableedit.h b/noncore/settings/networksettings2/cable/cableedit.h index ffacc61..ad1e832 100644 --- a/noncore/settings/networksettings2/cable/cableedit.h +++ b/noncore/settings/networksettings2/cable/cableedit.h @@ -1,12 +1,12 @@ #include "cabledata.h" #include "cableGUI.h" class CableEdit : public CableGUI { public : CableEdit( QWidget * parent ); QString acceptable( void ); - bool commit( CableData_t & D ); - void showData( CableData_t & D ); + bool commit( CableData & D ); + void showData( CableData & D ); }; diff --git a/noncore/settings/networksettings2/cable/cablerun.cpp b/noncore/settings/networksettings2/cable/cablerun.cpp index 85660f6..7a8deb9 100644 --- a/noncore/settings/networksettings2/cable/cablerun.cpp +++ b/noncore/settings/networksettings2/cable/cablerun.cpp @@ -1,30 +1,22 @@ #include <fcntl.h> #include <unistd.h> #include "cablerun.h" -void CableRun::detectState( NodeCollection * NC ) { +State_t CableRun::detectState( void ) { int fd = open( Data->Device.latin1(), O_RDWR ); if( fd < 0 ) { - NC->setCurrentState( Unavailable ); + return Unavailable; } close( fd ); - NC->setCurrentState( Available ); + return Available; } -bool CableRun::setState( NodeCollection * NC, Action_t A, bool ) { - if( A == Activate ) { - detectState(NC); - return (NC->currentState() == Available); - } - return 1; -} - -bool CableRun::canSetState( State_t , Action_t ) { - return 1; +QString CableRun::setMyState( NodeCollection *, Action_t , bool ) { + return QString(); } QString CableRun::deviceFile( void ) { return Data->Device; } diff --git a/noncore/settings/networksettings2/cable/cablerun.h b/noncore/settings/networksettings2/cable/cablerun.h index 20608f6..41aea01 100644 --- a/noncore/settings/networksettings2/cable/cablerun.h +++ b/noncore/settings/networksettings2/cable/cablerun.h @@ -1,26 +1,26 @@ -#include <asline.h> +#include <netnode.h> #include "cabledata.h" -class CableRun : public AsLine { +class CableRun : public RuntimeInfo { public : CableRun( ANetNodeInstance * NNI, - CableData_t & D ) : AsLine( NNI ) + CableData & D ) : RuntimeInfo( NNI ) { Data = &D; } - virtual AsLine * asLine( void ) - { return (AsLine *)this; } + virtual RuntimeInfo * line( void ) + { return this; } virtual QString deviceFile( void ); + State_t detectState( void ); + protected : - void detectState( NodeCollection * NC ); - bool setState( NodeCollection * NC, Action_t A, bool Force ); - bool canSetState( State_t Curr, Action_t A ); + QString setMyState( NodeCollection * , Action_t, bool ); private : - CableData_t * Data; + CableData * Data; }; diff --git a/noncore/settings/networksettings2/cable/opie-networksettings2plugin-cable.control b/noncore/settings/networksettings2/cable/opie-networksettings2plugin-cable.control index 79520e2..dd08279 100644 --- a/noncore/settings/networksettings2/cable/opie-networksettings2plugin-cable.control +++ b/noncore/settings/networksettings2/cable/opie-networksettings2plugin-cable.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-bluetooth +Package: opie-networksettings2plugin-cable Files: plugins/networksettings2/libcable.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings cable plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/config.in b/noncore/settings/networksettings2/config.in index d0e5a32..d2b5f26 100644 --- a/noncore/settings/networksettings2/config.in +++ b/noncore/settings/networksettings2/config.in @@ -1,18 +1,21 @@ source noncore/settings/networksettings2/networksettings2/config.in + source noncore/settings/networksettings2/opietooth2/config.in + source noncore/settings/networksettings2/opietooth2_applet/config.in config NS2 boolean default "y" - depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH source noncore/settings/networksettings2/profile/config.in source noncore/settings/networksettings2/network/config.in source noncore/settings/networksettings2/lancard/config.in source noncore/settings/networksettings2/ppp/config.in source noncore/settings/networksettings2/wlan/config.in source noncore/settings/networksettings2/usb/config.in source noncore/settings/networksettings2/irda/config.in source noncore/settings/networksettings2/vpn/config.in source noncore/settings/networksettings2/bluetooth/config.in source noncore/settings/networksettings2/cable/config.in source noncore/settings/networksettings2/modem/config.in + source noncore/settings/networksettings2/gprs/config.in diff --git a/noncore/settings/networksettings2/editconnection.cpp b/noncore/settings/networksettings2/editconnection.cpp index 77826d1..3f8a53f 100644 --- a/noncore/settings/networksettings2/editconnection.cpp +++ b/noncore/settings/networksettings2/editconnection.cpp @@ -1,577 +1,631 @@ +#include <opie2/odebug.h> #include <qlistview.h> #include <qwidgetstack.h> #include <qframe.h> #include <qcombobox.h> #include <qtabwidget.h> #include <qmessagebox.h> #include <qpushbutton.h> #include <qlineedit.h> #include <qheader.h> #include <qpainter.h> #include <qcheckbox.h> #include <qlabel.h> #include "editconnection.h" #include "resources.h" #include "netnode.h" // // // THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS // // class MyQCheckListItem : public QCheckListItem { public: MyQCheckListItem( QListView *parent, const QString & S, Type T ) : QCheckListItem( parent, S, T ) { } MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) : QCheckListItem( parent, S, T ) { } MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) : QCheckListItem( parent, S, T ) { } + MyQCheckListItem( QListView *parent, const QString & S ) : + QCheckListItem( parent, S, QCheckListItem::Controller ) { } + MyQCheckListItem( QCheckListItem *parent, const QString & S ) : + QCheckListItem( parent, S, QCheckListItem::Controller ) { } + MyQCheckListItem( QListViewItem *parent, const QString & S ) : + QCheckListItem( parent, S, QCheckListItem::Controller ) { } + virtual void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); }; void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { QColorGroup _cg( cg ); QColor c = _cg.text(); if ( ! isSelectable() ) _cg.setColor( QColorGroup::Text, Qt::lightGray ); QCheckListItem::paintCell( p, _cg, column, width, alignment ); _cg.setColor( QColorGroup::Text, c ); } class MyQListViewItem : public QListViewItem { public: MyQListViewItem( QListView *parent, const QString & S ) : QListViewItem( parent, S ) { } MyQListViewItem( QListViewItem *parent, const QString & S ) : QListViewItem( parent, S ) { } virtual void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); }; void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { QColorGroup _cg( cg ); QColor c = _cg.text(); if ( ! isSelectable() ) _cg.setColor( QColorGroup::Text, Qt::lightGray ); QListViewItem::paintCell( p, _cg, column, width, alignment ); _cg.setColor( QColorGroup::Text, c ); } // // // REAL GUI // // bool EditConnection::AutoCollapse = 1; EditConnection::EditConnection( QWidget* parent ) : EditConnectionGUI( parent, 0, TRUE ), TmpCollection() { Tab_TB->setTabEnabled( Setup_FRM, FALSE ); Setup_FRM->setEnabled( FALSE ); TmpIsValid = 0; SelectedNodes = 0; AutoCollapse_CB->setChecked( AutoCollapse ); Mapping = new QPtrDict<ANetNode>; Mapping->setAutoDelete( FALSE ); Nodes_LV->header()->hide(); // popluate tree with all NetNodes buildFullTree(); } NodeCollection * EditConnection::getTmpCollection( void ) { if( TmpIsValid ) // content is stil OK return &(TmpCollection); // reset collection -> delete all NEW NetNodes for( QListIterator<ANetNodeInstance> it(TmpCollection); it.current(); ++it ) { if( it.current()->isNew() ) { delete it.current(); } } TmpCollection.clear(); // update content QListViewItem * it = Nodes_LV->firstChild(); ANetNode * NN; - // start iter + + // start iter (if there is a collection) + /* + + a node collection is sorted from the toplevel + node to the deepest node + + */ ANetNodeInstance * NNI = (SelectedNodes) ? SelectedNodes->first() : 0 ; TmpCollection.setModified( 0 ); + // the listview always starts with the toplevel + // hierarchy. This is always a controller item while ( it ) { NN = (*Mapping)[it]; if( NN == 0 ) { - // child is controller -> has sub radio - // check if one radio is selected + // this item is a controller -> + // has radio items as children -> + // find selected one it = it->firstChild(); while( it ) { if( ((QCheckListItem *)it)->isOn() ) { // this radio is selected -> go deeper - if( SelectedNodes == 0 || - NNI == 0 || + break; + } + it = it->nextSibling(); + } + + if( ! it ) { + owarn << "Radio not selected" << oendl; + TmpIsValid = 0; + return 0; + } + + // it now contains selected radio + NN = (*Mapping)[it]; + } + + // NN here contains the netnode of the + // current item -> this node needs to + // be stored in the collection + if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { // new item not in previous collection - ANetNodeInstance * NNI = (*Mapping)[it]->createInstance(); + ANetNodeInstance * NNI = NN->createInstance(); NNI->initialize(); // this node type not in collection TmpCollection.append( NNI ); // master collection changed because new item in it TmpCollection.setModified( 1 ); // no more valid items in old list NNI = 0; } else { // already in list -> copy pointer TmpCollection.append( NNI ); NNI = SelectedNodes->next(); } + + // go deeper to next level + // this level is can be a new controller + // or an item it = it->firstChild(); - // do not bother to check other items - break; - } - it = it->nextSibling(); - } - } else { - // check children - it = it->firstChild(); - } } TmpIsValid = 1; return &(TmpCollection); } // pass a connection NodeCollection to be edited void EditConnection::setConnection( NodeCollection * NC ) { ANetNodeInstance * NNI; ANetNode * NN; SelectedNodes = NC; Name_LE->setText( NC->name() ); NNI = NC->first(); // show configure tabl Tab_TB->setCurrentPage( 1 ); // valid colledction Tab_TB->setTabEnabled( Setup_FRM, FALSE ); Setup_FRM->setEnabled( FALSE ); // select items in collection QListViewItem * it = Nodes_LV->firstChild(); bool Found; TmpIsValid = 0; while ( it ) { - // listitem corresponds to netnode NN = (*Mapping)[it]; if( NN == 0 ) { - // child is controller -> has sub radio - QString Ctr = it->text(0); - // check if one radio is selected + // this item is a controller -> + // has radio items as children -> + // find selected one it = it->firstChild(); Found = 0; while( it ) { if( NNI && it->text(0) == NNI->nodeClass()->name() ) { // this radio is part of the collection ((QCheckListItem *)it)->setOn( 1 ); updateGUI( it, NNI->nodeClass() ); // check its children Found = 1; it = it->firstChild(); NNI = SelectedNodes->next(); // do not bother to check other items break; } it = it->nextSibling(); } + if( ! Found ) { // this means that this level is NOT present in collection // probably INCOMPATIBEL collection OR Missing plugin QMessageBox::warning( 0, tr( "Error presentig Connection" ), tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). - arg(Ctr) ); + arg(NNI->nodeClass()->name()) ); return; } + + // it now contains selected radio + NN = (*Mapping)[it]; } else { - // automatic item -> check children + // automatic selection + if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { + // should exist and be the same + if( NNI ) { + QMessageBox::warning( + 0, + tr( "Error presentig Connection" ), + tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). + arg(NNI->nodeClass()->name()) ); + } else { + QMessageBox::warning( + 0, + tr( "Error presentig Connection" ), + tr( "<p>Missing connection\"<i>%1</i>\"</p>" ). + arg(it->text(0)) ); + } + return; + } it = it->firstChild(); } } } // get result of editing (either new OR updated collection NodeCollection * EditConnection::connection( void ) { if( SelectedNodes == 0 ) { // new collection SelectedNodes = new NodeCollection; } // clean out old entries SelectedNodes->clear(); // transfer for( QListIterator<ANetNodeInstance> it(TmpCollection); it.current(); ++it ) { SelectedNodes->append( it.current() ); } if( TmpCollection.isModified() ) SelectedNodes->setModified( 1 ); if( SelectedNodes->name() != Name_LE->text() ) { SelectedNodes->setName( Name_LE->text() ); SelectedNodes->setModified( 1 ); } return SelectedNodes; } // Build device tree -> start void EditConnection::buildFullTree( void ) { ANetNode * NN; // toplevel item MyQCheckListItem * TheTop = new MyQCheckListItem( Nodes_LV, NSResources->netNode2Name("fullsetup"), QCheckListItem::Controller ); TheTop->setOpen( TRUE ); Description_LBL->setText( NSResources->netNode2Description( "fullsetup" ) ); Nodes_LV->setSelected( TheTop, TRUE ); - // find all Nodes that care toplevel nodes -> ie provide + // find all Nodes that are toplevel nodes -> ie provide // TCP/IP Connection for( QDictIterator<NetNode_t> Iter(NSResources->netNodes()); Iter.current(); ++Iter ) { NN = Iter.current()->NetNode; if( ! NN->isToplevel() ) { continue; } MyQCheckListItem * it = new MyQCheckListItem( TheTop, NN->name(), QCheckListItem::RadioButton ); - it->setPixmap( 0, NSResources->getPixmap( "Devices/commprofile" ) ); + it->setPixmap( 0, + NSResources->getPixmap( NN->pixmapName() ) + ); // remember that this node maps to this listitem Mapping->insert( it, NN ); buildSubTree( it, NN ); } } // Build device tree -> help function void EditConnection::buildSubTree( QListViewItem * it, ANetNode *NN ) { ANetNode::NetNodeList & NNL = NN->alternatives(); if( NNL.size() > 1 ) { // this node has alternatives -> needs radio buttons it = new MyQCheckListItem( it, - NSResources->netNode2Name(NNL[0]->provides()), + NSResources->netNode2Name(NN->needs()[0]), QCheckListItem::Controller ); it->setSelectable( FALSE ); } for ( unsigned int i=0; i < NNL.size(); i++ ) { QListViewItem * CI; if( NNL.size() > 1 ) { // generate radio buttons CI = new MyQCheckListItem( (QCheckListItem *)it, NNL[i]->name(), QCheckListItem::RadioButton ); // remember that this node maps to this listitem CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); Mapping->insert( CI, NNL[i] ); CI->setSelectable( FALSE ); } else { // Single item CI = new MyQListViewItem( it, NNL[i]->name() ); // remember that this node maps to this listitem Mapping->insert( CI, NNL[i] ); CI->setSelectable( FALSE ); CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); } buildSubTree( CI, NNL[i] ); } } // Clicked ok OK button void EditConnection::accept( void ) { if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { QMessageBox::warning( 0, tr( "Closing Connection Setup" ), tr( "Definition not complete or no name" ) ); return; } // check if all devices have acceptable input getTmpCollection(); { ANetNodeInstance * NNI; QString S; for( QListIterator<ANetNodeInstance> it(TmpCollection); it.current(); ++it ) { NNI = it.current(); // widget must show its own problems S = NNI->acceptable(); if( ! S.isEmpty() ) { QMessageBox::warning( 0, tr( "Cannot save" ), S ); return; } NNI->commit(); if( NNI->isModified() ) { TmpCollection.setModified( 1 ); // commit the data } } } QDialog::accept(); } // triggered by CB void EditConnection::SLOT_AutoCollapse( bool b ) { AutoCollapse = b; } // clicked on node in tree -> update GUI void EditConnection::SLOT_SelectNode( QListViewItem * it ) { ANetNode * NN; if( it == 0 || it->depth() == 0 ) { Description_LBL->setText( NSResources->netNode2Description( "fullsetup" ) ); // topevel or no selection return; } // store conversion from lvitem to node NN = (*Mapping)[ it ]; if( ! NN ) { // intermediate node - NN = (*Mapping)[ it->firstChild() ]; + NN = (*Mapping)[ it->parent() ]; if( NN ) { // figure out type of this node -> produce mesage - Description_LBL->setText( NSResources->netNode2Description(NN->provides()) ); + Description_LBL->setText( NSResources->netNode2Description( + NN->needs()[0]) ); } else { Description_LBL->setText( "" ); } return; } Description_LBL->setText( NN->nodeDescription() ); if( ! it->isSelectable() ) { return; } if( ! ((QCheckListItem *)it)->isOn() ) { // clicked on line but NOT on Check or Radio item return; } // item has really changed -> update TmpIsValid = 0; updateGUI( it, NN ); } // cliecked on TAB to go to setup void EditConnection::SLOT_AlterTab( const QString & S ) { if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) { // switched to setup -> update CB and populate ws with // forms for devices if( ! TmpIsValid ) { getTmpCollection(); // clear CB and Ws { QWidget * W; int i = 0; Devices_CB->clear(); while( ( W = Setup_WS->widget( i ) ) ) { Setup_WS->removeWidget( W ); i ++; } } // update CB // and populate WidgetStack { ANetNodeInstance * NNI; QListIterator<ANetNodeInstance> it(TmpCollection); int i = 0; QWidget * W; for ( ; it.current(); ++it ) { NNI = it.current(); Devices_CB->insertItem( NSResources->getPixmap( NNI->nodeClass()->pixmapName() ), NNI->nodeClass()->name() ); // add edit widget W = NNI->edit( Setup_WS ); if( ! W) { W = new QLabel( Setup_WS, tr("No configuration required")); } Setup_WS->addWidget( W , i ); i ++; } } Setup_WS->raiseWidget( 0 ); } // still valid } } // update visual feedback of selection state void EditConnection::updateGUI( QListViewItem * it, ANetNode * NN ) { bool HCC = haveCompleteConfig( it ); Tab_TB->setTabEnabled( Setup_FRM, HCC ); Setup_FRM->setEnabled( HCC ); // disable children of all siblings at same level QListViewItem * Sbl = it->parent()->firstChild(); while( Sbl ) { if ( Sbl != it ) { disableTree( Sbl->firstChild(), FALSE ); Sbl->setSelectable( TRUE ); if( AutoCollapse ) Sbl->setOpen( FALSE ); } Sbl = Sbl->nextSibling(); } // enable selected path (as deep as it goes it->setOpen( TRUE ); enablePath( it->firstChild(), (it->depth()==1) ? 1 : // toplevel always alternatives (NN->alternatives().size() > 1) ); } void EditConnection::disableTree( QListViewItem * it, bool Mode ) { while( it ) { // disable sbl's chidren it->setSelectable( Mode ); if( AutoCollapse ) it->setOpen( Mode ); disableTree( it->firstChild(), Mode ); it = it->nextSibling(); } } // pah : ParentHasAlternatives void EditConnection::enablePath( QListViewItem * it, bool pha ) { while( it ) { ANetNode * NN; NN = (*Mapping)[it]; if( NN ) { if( pha ) { bool doOn = ((QCheckListItem *)it)->isOn(); // we are a checklistitem for sure it->setSelectable( TRUE ); if( AutoCollapse && ! doOn ) it->setOpen( doOn ); if( doOn ) { // selected alternative enablePath( it->firstChild(), NN->alternatives().size() > 1); } else { // non-selected alternative disableTree( it->firstChild(), FALSE); } } else { // we are single subitem it->setSelectable( TRUE ); it->setOpen( TRUE ); enablePath( it->firstChild(), NN->alternatives().size() > 1); } } else { // controller node it->setSelectable( TRUE ); it->setOpen( TRUE ); enablePath( it->firstChild(), pha ); } it = it->nextSibling(); } } // do we have a complete configuration (all needs are provided for ?) bool EditConnection::haveCompleteConfig( QListViewItem * it ) { - if( it == 0 || ((QCheckListItem *)it)->isOn() ) { - // check children - it = (it) ? it->firstChild() : Nodes_LV->firstChild() ; + + // check if all below this level is selected + it = ( it ) ?it : Nodes_LV->firstChild(); + ANetNode *NN; + bool Found; + while ( it ) { - if( ((QCheckListItem *)it)->type() == - QCheckListItem::Controller ) { - // child is controller -> has sub radio - // check if one radio is selected + NN = (*Mapping)[it]; + if( NN == 0 ) { + // this item is a controller -> + // has radio items as children -> + // find selected one it = it->firstChild(); + Found = 0; while( it ) { if( ((QCheckListItem *)it)->isOn() ) { - // this radio is selected -> go deeper + Found = 1; + // go deeper it = it->firstChild(); - if( ! it ) { - // was deepest level - return 1; - } - // do not bother to check other items break; } it = it->nextSibling(); } - if( ! it ) { - // no radio selected - return 0; + + if( ! Found ) { + return 0; // no not complete -> a radio should have been chkd } + + // it now contains selected radio + NN = (*Mapping)[it]; } else { - // check children + // automatic selection it = it->firstChild(); } } - // deepest level -> all is still OK return 1; - } // was not ON - return 0; } diff --git a/noncore/settings/networksettings2/irda/irda_NN.cpp b/noncore/settings/networksettings2/irda/irda_NN.cpp index 9483e22..485cad3 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.cpp +++ b/noncore/settings/networksettings2/irda/irda_NN.cpp @@ -1,49 +1,54 @@ #include "irda_NN.h" #include "irda_NNI.h" static const char * IRDANeeds[] = { 0 }; +static const char * IRDAProvides[] = + { "line", + 0 + }; + /** * Constructor, find all of the possible interfaces */ IRDANetNode::IRDANetNode() : ANetNode(tr("Infrared link")) { } /** * Delete any interfaces that we own. */ IRDANetNode::~IRDANetNode(){ } const QString IRDANetNode::nodeDescription(){ return tr("\ <p>Sets up a infra red serial link.</p>\ " ); } ANetNodeInstance * IRDANetNode::createInstance( void ) { return new AIRDA( this ); } const char ** IRDANetNode::needs( void ) { return IRDANeeds; } -const char * IRDANetNode::provides( void ) { - return "line"; +const char ** IRDANetNode::provides( void ) { + return IRDAProvides; } void IRDANetNode::setSpecificAttribute( QString & , QString & ) { } void IRDANetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new IRDANetNode() ); } } diff --git a/noncore/settings/networksettings2/irda/irda_NN.h b/noncore/settings/networksettings2/irda/irda_NN.h index 900bbc6..9e5c5e6 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.h +++ b/noncore/settings/networksettings2/irda/irda_NN.h @@ -1,36 +1,36 @@ #ifndef IRDA_NETNODE_H #define IRDA_NETNODE_H #include "netnode.h" class AIRDA; class IRDANetNode : public ANetNode { Q_OBJECT public: IRDANetNode(); virtual ~IRDANetNode(); virtual const QString pixmapName() { return "Devices/irda"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/irda/irdadata.h b/noncore/settings/networksettings2/irda/irdadata.h index c3c683e..568f796 100644 --- a/noncore/settings/networksettings2/irda/irdadata.h +++ b/noncore/settings/networksettings2/irda/irdadata.h @@ -1,18 +1,19 @@ #ifndef IRDA_DATA_H #define IRDA_DATA_H #include <qstring.h> -typedef struct IRDAData { +class IRDAData { +public : QString Device; QString LockFile; long Speed; short Parity; short DataBits; short StopBits; bool HardwareControl; bool SoftwareControl; -} IRDAData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/irda/irdarun.h b/noncore/settings/networksettings2/irda/irdarun.h index 4258aff..d3b714b 100644 --- a/noncore/settings/networksettings2/irda/irdarun.h +++ b/noncore/settings/networksettings2/irda/irdarun.h @@ -1,28 +1,25 @@ -#include <asline.h> +#include <netnode.h> #include "irdadata.h" -class IRDARun : public AsLine { +class IRDARun : public RuntimeInfo { public : IRDARun( ANetNodeInstance * NNI, - IRDAData & Data ) : AsLine( NNI ) + IRDAData & Data ) : RuntimeInfo( NNI ) { } - virtual AsLine * asLine( void ) - { return (AsLine *)this; } + virtual RuntimeInfo * line( void ) + { return this; } virtual QString deviceFile( void ) { return QString( "/dev/irda" ); } -protected : - - void detectState( NodeCollection * ) - { } + State_t detectState( void ) + { return Unknown; } - bool setState( NodeCollection * , Action_t, bool ) - { return 0; } +protected : - bool canSetState( State_t , Action_t ) - { return 0; } + QString setMyState( NodeCollection * , Action_t, bool ) + { return QString(); } }; diff --git a/noncore/settings/networksettings2/irda/opie-networksettings2plugin-irda.control b/noncore/settings/networksettings2/irda/opie-networksettings2plugin-irda.control index 938bee5..4afbbcf 100644 --- a/noncore/settings/networksettings2/irda/opie-networksettings2plugin-irda.control +++ b/noncore/settings/networksettings2/irda/opie-networksettings2plugin-irda.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-irda +Package: opie-networksettings2plugin-irda Files: plugins/networksettings2/libirda.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings irda plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp index 20ae7f6..e36f757 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp @@ -1,71 +1,77 @@ #include "lancard_NN.h" #include "lancard_NNI.h" static const char * LanCardNeeds[] = - { 0 }; + { 0 + }; + +static const char * LanCardProvides[] = + { "device", + 0 + }; /** * Constructor, find all of the possible interfaces */ LanCardNetNode::LanCardNetNode() : ANetNode(tr("LAN card")), NICMACAddresses() { InstanceCount = 2; } /** * Delete any interfaces that we own. */ LanCardNetNode::~LanCardNetNode(){ } const QString LanCardNetNode::nodeDescription(){ return tr("\ <p>Sets up a wired regular LAN card.</p>\ <p>Use this to set up 10/100/1000 MBit LAN cards.</p>\ " ); } ANetNodeInstance * LanCardNetNode::createInstance( void ) { return new ALanCard( this ); } const char ** LanCardNetNode::needs( void ) { return LanCardNeeds; } -const char * LanCardNetNode::provides( void ) { - return "device"; +const char ** LanCardNetNode::provides( void ) { + return LanCardProvides; } QString LanCardNetNode::genNic( long nr ) { QString S; return S.sprintf( "eth%ld", nr ); } void LanCardNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { InstanceCount = V.toLong(); } else if ( A == "macaddress" ) { NICMACAddresses.append( V ); } } void LanCardNetNode::saveSpecificAttribute( QTextStream & TS) { TS << "interfacecount=" << InstanceCount << endl; for( QStringList::Iterator it = NICMACAddresses.begin(); it != NICMACAddresses.end(); ++it ) { TS << "macaddress=" << (*it) << endl; } } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new LanCardNetNode() ); } } diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.h b/noncore/settings/networksettings2/lancard/lancard_NN.h index 6882af7..dc7566a 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.h +++ b/noncore/settings/networksettings2/lancard/lancard_NN.h @@ -1,50 +1,50 @@ #ifndef LANCARD_NETNODE_H #define LANCARD_NETNODE_H #include <qstringlist.h> #include "netnode.h" class ALanCard; class LanCardNetNode : public ANetNode{ Q_OBJECT public: LanCardNetNode(); virtual ~LanCardNetNode(); virtual const QString pixmapName() { return "Devices/card"; } virtual QString genNic( long ); virtual long instanceCount( void ) { return InstanceCount; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); QStringList & addressesOfNIC( void ) { return NICMACAddresses; } private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); // number of interfaces for this device long InstanceCount; QStringList NICMACAddresses; }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/lancard/lancarddata.h b/noncore/settings/networksettings2/lancard/lancarddata.h index c76767f..8f5e2b5 100644 --- a/noncore/settings/networksettings2/lancard/lancarddata.h +++ b/noncore/settings/networksettings2/lancard/lancarddata.h @@ -1,13 +1,14 @@ #ifndef LANCARD_DATA_H #define LANCARD_DATA_H #include <qstringlist.h> #include <qstring.h> -typedef struct LanCardData { +class LanCardData { +public : bool AnyLanCard; QStringList HWAddresses; -} LanCardData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp index 1544ddc..470b797 100644 --- a/noncore/settings/networksettings2/lancard/lancardrun.cpp +++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp @@ -1,192 +1,148 @@ #include <qfile.h> #include <qtextstream.h> #include <qstringlist.h> #include <resources.h> #include "lancardrun.h" -void LanCardRun::detectState( NodeCollection * NC ) { +State_t LanCardRun::detectState( void ) { // unavailable : no card found // available : card found and assigned to us or free // up : card found and assigned to us and up - QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); + NodeCollection * NC = nodeCollection(); + QString S = QString( "/tmp/profile-%1.up" ). + arg( NC->number()); System & Sys = NSResources->system(); InterfaceInfo * Run; QFile F( S ); if( F.open( IO_ReadOnly ) ) { // could open file -> read interface and assign QString X; QTextStream TS(&F); X = TS.readLine(); // find interface if( handlesInterface( X ) ) { for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( X == Run->Name ) { - Run->assignNode( netNode() ); - assignInterface( Run ); - NC->setCurrentState( IsUp ); - return; + NC->assignInterface( Run ); + return IsUp; } } } } - if( ( Run = assignedInterface() ) ) { + if( ( Run = NC->assignedInterface() ) ) { // we already have an interface assigned -> still present ? if( ! Run->IsUp ) { // usb is still free -> keep assignment - NC->setCurrentState( Available ); - return; + return Available; } // else interface is up but NOT us -> some other profile } // nothing (valid) assigned to us - assignInterface( 0 ); + NC->assignInterface( 0 ); // find possible interface for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( *Run ) && ( Run->CardType == ARPHRD_ETHER #ifdef ARPHRD_IEEE1394 || Run->CardType == ARPHRD_IEEE1394 #endif ) && ! Run->IsUp ) { // proper type, and Not UP -> free - NC->setCurrentState( Off ); - return; + return Off; } } // no free found - NC->setCurrentState( Unavailable ); - + return Unavailable; } -bool LanCardRun::setState( NodeCollection * NC, Action_t A, bool ) { +QString LanCardRun::setMyState( NodeCollection * NC, Action_t A, bool ) { - // we only handle activate and deactivate - switch( A ) { - case Activate : - { - if( NC->currentState() != Off ) { - return 0; - } + if( A == Activate ) { InterfaceInfo * N = getInterface(); + if( ! N ) { // no interface available NC->setCurrentState( Unavailable ); - return 0; + return tr("No interface found"); } + // because we were OFF the interface // we get back is NOT assigned - N->assignNode( netNode() ); - assignInterface( N ); + NC->assignInterface( N ); NC->setCurrentState( Available ); - return 1; - } - case Deactivate : - if( NC->currentState() == IsUp ) { - // bring down first - if( ! connection()->setState( Down ) ) - // could not ... - return 0; - } else if( NC->currentState() != Available ) { - return 1; + return QString(); } - assignedInterface()->assignNode( 0 ); // release - assignInterface( 0 ); + + if( A == Deactivate ) { + NC->assignInterface( 0 ); NC->setCurrentState( Off ); - return 1; - default : - // FT - break; - } - return 0; } -bool LanCardRun::canSetState( State_t Curr, Action_t A ) { - // we only handle up down activate and deactivate - switch( A ) { - case Activate : - { // at least available - if( Curr == Available ) { - return 1; - } - // or we can make one available - InterfaceInfo * N = getInterface(); - if( ! N || N->assignedNode() != 0 ) { - // non available or assigned - return 0; - } - return 1; - } - case Deactivate : - return ( Curr >= Available ); - default : - // FT - break; - } - return 0; + return QString(); } // get interface that is free or assigned to us InterfaceInfo * LanCardRun::getInterface( void ) { System & S = NSResources->system(); InterfaceInfo * best = 0, * Run; for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( *Run ) && ( Run->CardType == ARPHRD_ETHER #ifdef ARPHRD_IEEE1394 || Run->CardType == ARPHRD_IEEE1394 #endif ) ) { // this is a LAN card - if( Run->assignedNode() == netNode() ) { + if( Run->assignedConnection() == netNode()->connection() ) { // assigned to us return Run; - } else if( Run->assignedNode() == 0 ) { + } else if( Run->assignedConnection() == 0 ) { // free best = Run; } } } return best; // can be 0 } bool LanCardRun::handlesInterface( const QString & S ) { InterfaceInfo * II; II = NSResources->system().interface( S ); if( ( II = NSResources->system().interface( S ) ) ) { return handlesInterface( *II ); } return Pat.match( S ) >= 0; } bool LanCardRun::handlesInterface( const InterfaceInfo & II ) { if( Pat.match( II.Name ) < 0 ) return 0; if( Data->AnyLanCard ) { return 1; } // must also match hardware address return ( Data->HWAddresses.findIndex( II.MACAddress ) >= 0 ); } diff --git a/noncore/settings/networksettings2/lancard/lancardrun.h b/noncore/settings/networksettings2/lancard/lancardrun.h index b28dda7..57ef3fb 100644 --- a/noncore/settings/networksettings2/lancard/lancardrun.h +++ b/noncore/settings/networksettings2/lancard/lancardrun.h @@ -1,39 +1,37 @@ #ifndef LANCARDRUN_H #define LANCARDRUN_H -#include <asdevice.h> +#include <netnode.h> #include <qregexp.h> #include "lancarddata.h" -class LanCardRun : public AsDevice { +class LanCardRun : public RuntimeInfo { public : LanCardRun( ANetNodeInstance * NNI, - LanCardData & D ) : AsDevice( NNI ), - Pat( "eth[0-9]" ) - { Data = &D; } + LanCardData & D ) : RuntimeInfo( NNI ), + Pat( "eth[0-9]" ) { + Data = &D; + } - virtual AsDevice * device( void ) - { return (AsDevice *)this; } + virtual RuntimeInfo * device( void ) + { return this; } - virtual AsDevice * asDevice( void ) - { return (AsDevice *)this; } + bool handlesInterface( const QString & I ); + bool handlesInterface( const InterfaceInfo & II ); -protected : + State_t detectState( void ); - void detectState( NodeCollection * NC ); - bool setState( NodeCollection * NC, Action_t A, bool Force ); - bool canSetState( State_t Curr, Action_t A ); +protected : - bool handlesInterface( const QString & I ); - bool handlesInterface( const InterfaceInfo & II ); + QString setMyState( NodeCollection * , Action_t, bool ); private : InterfaceInfo * getInterface( void ); QRegExp Pat; LanCardData * Data; }; #endif diff --git a/noncore/settings/networksettings2/lancard/opie-networksettings2plugin-lancard.control b/noncore/settings/networksettings2/lancard/opie-networksettings2plugin-lancard.control index d5aca66..4f87d04 100644 --- a/noncore/settings/networksettings2/lancard/opie-networksettings2plugin-lancard.control +++ b/noncore/settings/networksettings2/lancard/opie-networksettings2plugin-lancard.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-lancard +Package: opie-networksettings2plugin-lancard Files: plugins/networksettings2/liblancard.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings lancard plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index 18bf652..8487e3e 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp @@ -1,151 +1,175 @@ #include "nsdata.h" #include "activateprofile.h" #include "activatevpn.h" #include "networksettings.h" +#include <opie2/odebug.h> #include <qpe/qpeapplication.h> #include <opie2/oapplicationfactory.h> using namespace Opie::Core; #ifdef GONE OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) #else // just standard GUI #define ACT_GUI 0 // used by interfaces to request for allow of up/down #define ACT_REQUEST 1 // regenerate config files #define ACT_REGEN 2 // used by interfaces to request user prompt #define ACT_PROMPT 3 // used by interfaces to trigger VPN #define ACT_VPN 4 +// activate opietooth +#define ACT_OT 5 + +// include Opietooth GUI +#include <opietooth2/Opietooth.h> +using namespace Opietooth2; + +#include <qpushbutton.h> +#include <qlayout.h> +#include <qframe.h> +#include <qlabel.h> int main( int argc, char * argv[] ) { int rv = 0; int Action = ACT_GUI; // could be overruled by -qws QApplication::Type GuiType = QApplication::GuiClient; #ifdef _WS_QWS_ QPEApplication * TheApp; #else QApplication * TheApp; #endif for ( int i = 1; i < argc; i ++ ) { int rmv; rmv = 0; if( strcmp( argv[i], "--regen" ) == 0 ) { Action = ACT_REGEN; GuiType = QApplication::Tty; rmv = 1; } else if( strcmp( argv[i], "--prompt" ) == 0 ) { Action = ACT_PROMPT; rmv = 1; } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) { Action = ACT_VPN; rmv = 1; + } else if( strcmp( argv[i], "--opietooth" ) == 0 ) { + Action = ACT_OT; + rmv = 1; } if( rmv ) { memmove( argv+i, argv+i+rmv, sizeof( char * ) * (argc-i-rmv) ); i --; argc -= rmv; } } if( strstr( argv[0], "-request" ) ) { // called from system to request something GuiType = QApplication::Tty; Action = ACT_REQUEST; Log(("Request : %s\n", argv[1] )); + } else if( strstr( argv[0], "-opietooth" ) ) { + Action = ACT_OT; } // Start Qt #ifdef _WS_QWS_ // because QPEApplication does not handle GuiType well if( GuiType == QApplication::Tty ) { // this cast is NOT correct but we do not use // TheApp anymore ... TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); } else { TheApp = new QPEApplication( argc, argv, GuiType ); } #else TheApp = new QApplication( argc, argv, GuiType ); #endif // init qt with app widget switch( Action ) { case ACT_REQUEST : { NetworkSettingsData NS; if( NS.canStart( argv[1] ) ) { - QString S; - S.sprintf( QPEApplication::qpeDir()+ - "bin/networksettings2" ); - char * MyArgv[4]; - MyArgv[0] = "networksettings2"; - MyArgv[1] = "--prompt"; - MyArgv[2] = argv[1]; - MyArgv[3] = NULL; - NSResources->system().execAsUser( S, MyArgv ); + QStringList S; + S << QPEApplication::qpeDir() + "/bin/networksettings2"; + S << "networksettings2"; + S << "--prompt"; + S << argv[1]; + NSResources->system().execAsUser( S ); Log(("FAILED %s-cNN-allowed\n", argv[1] )); // if we come here , failed printf( "%s-cNN-disallowed", argv[1] ); } } break; case ACT_REGEN : { NetworkSettingsData NS; + QString S= NS.generateSettings(); // regen returns 0 if OK - rv = (NS.regenerate()) ? 1 : 0; + rv = ( S.isEmpty() ) ? 0 : 1; } break; case ACT_PROMPT : { ActivateProfile AP(argv[1]); if( AP.exec() == QDialog::Accepted ) { Log(("%s-c%ld-allowed\n", argv[1], AP.selectedProfile() )); printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); } else { Log(("%s-c%NN-disallowed\n", argv[1] )); printf( "%s-cNN-disallowed", argv[1] ); } } break; case ACT_VPN : { ActivateVPN AVPN; AVPN.exec(); } break; case ACT_GUI : - { QWidget * W = new NetworkSettings(0); + case ACT_OT : + { QWidget * W; + + if( Action == ACT_OT ) { + W = new OTMain( 0 ); + } else { + W = new NetworkSettings(0); + } TheApp->setMainWidget( W ); + W->show(); #ifdef _WS_QWS_ W->showMaximized(); #else W->resize( W->sizeHint() ); #endif rv = TheApp->exec(); + delete W; } break; } LogClose(); return rv; } #endif // main.cpp diff --git a/noncore/settings/networksettings2/modem/modem_NN.cpp b/noncore/settings/networksettings2/modem/modem_NN.cpp index ee61b10..06f417c 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.cpp +++ b/noncore/settings/networksettings2/modem/modem_NN.cpp @@ -1,50 +1,55 @@ #include "modem_NN.h" #include "modem_NNI.h" static const char * ModemNeeds[] = - { "line" + { "line", + 0 + }; +static const char * ModemProvides[] = + { "modem", + 0 }; /** * Constructor, find all of the possible interfaces */ ModemNetNode::ModemNetNode() : ANetNode(tr("Dialup modem")) { } /** * Delete any interfaces that we own. */ ModemNetNode::~ModemNetNode(){ } const QString ModemNetNode::nodeDescription(){ return tr("\ <p>Sets up a dialing procedures.</p>\ <p>Use this to dial up over modems, ISDN, GSM, ...</p>\ " ); } ANetNodeInstance * ModemNetNode::createInstance( void ) { return new AModem( this ); } const char ** ModemNetNode::needs( void ) { return ModemNeeds; } -const char * ModemNetNode::provides( void ) { - return "line"; +const char ** ModemNetNode::provides( void ) { + return ModemProvides; } void ModemNetNode::setSpecificAttribute( QString & , QString & ) { } void ModemNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new ModemNetNode() ); } } diff --git a/noncore/settings/networksettings2/modem/modem_NN.h b/noncore/settings/networksettings2/modem/modem_NN.h index a76525f..5b3b573 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.h +++ b/noncore/settings/networksettings2/modem/modem_NN.h @@ -1,36 +1,36 @@ #ifndef MODEM_NETNODE_H #define MODEM_NETNODE_H #include "netnode.h" class AModem; class ModemNetNode : public ANetNode{ Q_OBJECT public: ModemNetNode(); virtual ~ModemNetNode(); virtual const QString pixmapName() { return "Devices/modem"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/modem/modemdata.h b/noncore/settings/networksettings2/modem/modemdata.h index 773cb77..89656ed 100644 --- a/noncore/settings/networksettings2/modem/modemdata.h +++ b/noncore/settings/networksettings2/modem/modemdata.h @@ -1,17 +1,18 @@ #ifndef MODEM_DATA_H #define MODEM_DATA_H #include <qstring.h> -typedef struct ModemData { +class ModemData { +public : QString Device; QString LockFile; long Speed; short Parity; short DataBits; short StopBits; bool HardwareControl; bool SoftwareControl; -} ModemData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/modem/modemedit.cpp b/noncore/settings/networksettings2/modem/modemedit.cpp index fd3d694..d97d895 100644 --- a/noncore/settings/networksettings2/modem/modemedit.cpp +++ b/noncore/settings/networksettings2/modem/modemedit.cpp @@ -1,18 +1,18 @@ #include <GUIUtils.h> #include "modemedit.h" ModemEdit::ModemEdit( QWidget * Parent ) : ModemGUI( Parent ){ } QString ModemEdit::acceptable( void ) { return QString(); } -bool ModemEdit::commit( ModemData_t & Data ) { +bool ModemEdit::commit( ModemData & Data ) { return 0; } -void ModemEdit::showData( ModemData_t & Data ) { +void ModemEdit::showData( ModemData & Data ) { } diff --git a/noncore/settings/networksettings2/modem/modemedit.h b/noncore/settings/networksettings2/modem/modemedit.h index 56e2a82..ed9cfc0 100644 --- a/noncore/settings/networksettings2/modem/modemedit.h +++ b/noncore/settings/networksettings2/modem/modemedit.h @@ -1,12 +1,12 @@ #include "modemdata.h" #include "modemGUI.h" class ModemEdit : public ModemGUI { public : ModemEdit( QWidget * parent ); QString acceptable( void ); - bool commit( ModemData_t & Data ); - void showData( ModemData_t & Data ); + bool commit( ModemData & Data ); + void showData( ModemData & Data ); }; diff --git a/noncore/settings/networksettings2/modem/modemrun.h b/noncore/settings/networksettings2/modem/modemrun.h index 491a677..eb3a193 100644 --- a/noncore/settings/networksettings2/modem/modemrun.h +++ b/noncore/settings/networksettings2/modem/modemrun.h @@ -1,28 +1,25 @@ -#include <asline.h> +#include <netnode.h> #include "modemdata.h" -class ModemRun : public AsLine { +class ModemRun : public RuntimeInfo { public : ModemRun( ANetNodeInstance * NNI, - ModemData & Data ) : AsLine ( NNI ) + ModemData & Data ) : RuntimeInfo ( NNI ) { } - virtual AsLine * asLine( void ) - { return (AsLine *)this; } + virtual RuntimeInfo * line( void ) + { return this; } virtual QString deviceFile( void ) { return QString("/dev/modem"); } -protected : - - void detectState( NodeCollection * ) - { } + State_t detectState( void ) + { return Unknown;} - bool setState( NodeCollection *, Action_t, bool ) - { return 0; } +protected : - bool canSetState( State_t, Action_t ) - { return 0; } + QString setMyState( NodeCollection * , Action_t, bool ) + { return QString(); } }; diff --git a/noncore/settings/networksettings2/modem/opie-networksettings2plugin-modem.control b/noncore/settings/networksettings2/modem/opie-networksettings2plugin-modem.control index eaa6ab0..a73249a 100644 --- a/noncore/settings/networksettings2/modem/opie-networksettings2plugin-modem.control +++ b/noncore/settings/networksettings2/modem/opie-networksettings2plugin-modem.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-modem +Package: opie-networksettings2plugin-modem Files: plugins/networksettings2/libmodem.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings modem plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp index b5c41bf..23b3d44 100644 --- a/noncore/settings/networksettings2/network/network_NN.cpp +++ b/noncore/settings/networksettings2/network/network_NN.cpp @@ -1,85 +1,97 @@ #include <qpe/qpeapplication.h> -#include <asdevice.h> +#include <resources.h> +#include <netnode.h> #include "network_NN.h" #include "network_NNI.h" static const char * NetworkNeeds[] = { "device", 0 }; +static const char * NetworkProvides[] = + { "connection", + 0 + }; + /** * Constructor, find all of the possible interfaces */ NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) { + + NSResources->addSystemFile( + "interfaces", "/etc/network/interfaces", 1 ); } /** * Delete any interfaces that we own. */ NetworkNetNode::~NetworkNetNode(){ } const QString NetworkNetNode::nodeDescription(){ return tr("\ <p>Sets up TCP/IP options.</p>\ <p>Use this to configure the TCP/IP protocol</p>\ " ); } ANetNodeInstance * NetworkNetNode::createInstance( void ) { return new ANetwork( this ); } -bool NetworkNetNode::hasDataForFile( const QString & S ) { - return S == "interfaces"; +bool NetworkNetNode::hasDataForFile( SystemFile & S ) { + return S.name() == "interfaces"; } -short NetworkNetNode::generateFile( const QString & ID, - const QString & , - QTextStream & TS, +short NetworkNetNode::generateFile( SystemFile & SF, ANetNodeInstance * NNI, long DevNr ) { + if( DevNr < 0 ) { + // generate device specific but common part + return 1; + } + QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); - if( ID == "interfaces" ) { - Log(("Generate entry for %s in %s\n", NIC.latin1(), ID.latin1() )); + if( SF.name() == "interfaces" ) { + Log(("Generate entry for %s in %s\n", NIC.latin1(), SF.name().latin1() )); // generate mapping stanza for this interface - TS << "# check if " + SF << "# check if " << NIC << " can be brought UP" << endl; - TS << "mapping " + SF << "mapping " << NIC << endl; - TS << " script " + SF << " script " << QPEApplication::qpeDir() - << "/bin/networksettings2-request" + << "bin/networksettings2-request" << endl << endl; return 0; } return 1; } const char ** NetworkNetNode::needs( void ) { return NetworkNeeds; } -const char * NetworkNetNode::provides( void ) { - return "connection"; +const char ** NetworkNetNode::provides( void ) { + return NetworkProvides; } void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { } void NetworkNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new NetworkNetNode() ); } } diff --git a/noncore/settings/networksettings2/network/network_NN.h b/noncore/settings/networksettings2/network/network_NN.h index 745d1a7..b063d4c 100644 --- a/noncore/settings/networksettings2/network/network_NN.h +++ b/noncore/settings/networksettings2/network/network_NN.h @@ -1,43 +1,41 @@ #ifndef NETWORK_NETNODE_H #define NETWORK_NETNODE_H #include "netnode.h" class ANetwork; class NetworkNetNode : public ANetNode{ Q_OBJECT public: NetworkNetNode(); virtual ~NetworkNetNode(); - virtual bool hasDataForFile( const QString & S ); + virtual bool hasDataForFile( SystemFile & S ); - virtual short generateFile( const QString & ID, - const QString & Path, - QTextStream & TS, + virtual short generateFile( SystemFile & TS, ANetNodeInstance * NNI, long DevNr ); virtual const QString pixmapName() { return "Devices/tcpip"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp index 324c6e2..78e6545 100644 --- a/noncore/settings/networksettings2/network/network_NNI.cpp +++ b/noncore/settings/networksettings2/network/network_NNI.cpp @@ -1,219 +1,217 @@ #include <system.h> -#include <asdevice.h> +#include <netnode.h> #include "networkedit.h" #include "network_NNI.h" #include "network_NN.h" ANetwork::ANetwork( NetworkNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.UseDHCP = 1; Data.IPAddress = ""; Data.NetMask = ""; Data.Broadcast = ""; Data.Gateway = ""; Data.DNS1 = ""; Data.DNS2 = ""; Data.SendHostname = 0; Data.Hostname = ""; Data.PreUp_SL.clear(); Data.PreDown_SL.clear(); Data.PostUp_SL.clear(); Data.PostDown_SL.clear(); GUI = 0; RT = 0; } void ANetwork::setSpecificAttribute( QString & A, QString & V ) { if( A == "usedhcp" ) { Data.UseDHCP = (V == "yes"); } else if( A == "sendhostname" ) { Data.SendHostname = (V=="yes"); } else if( A == "hostname" ) { Data.Hostname = V; } else if( A == "ipaddress" ) { Data.IPAddress = V; } else if( A == "netmask" ) { Data.NetMask = V; } else if( A == "broadcast" ) { Data.Broadcast = V; } else if( A == "gateway" ) { Data.Gateway = V; } else if( A == "dns1" ) { Data.DNS1 = V; } else if( A == "dns2" ) { Data.DNS2 = V; } else if( A == "preup" ) { Data.PreUp_SL.append( V ); } else if( A == "predown" ) { Data.PreDown_SL.append( V ); } else if( A == "postup" ) { Data.PostUp_SL.append( V ); } else if( A == "postdown" ) { Data.PostDown_SL.append( V ); } } void ANetwork::saveSpecificAttribute( QTextStream & TS ) { TS << "usedhcp=" << ((Data.UseDHCP) ? "yes" : "no") << endl; TS << "sendhostname=" << ((Data.SendHostname) ? "yes" : "no") << endl; TS << "hostname=" << Data.Hostname << endl; TS << "ipaddress=" << Data.IPAddress << endl; TS << "netmask=" << Data.NetMask << endl; TS << "broadcast=" << Data.Broadcast << endl; TS << "gateway=" << Data.Gateway << endl; TS << "dns1=" << Data.DNS1 << endl; TS << "dns2=" << Data.DNS2 << endl; for ( QStringList::Iterator it = Data.PreUp_SL.begin(); it != Data.PreUp_SL.end(); ++it ) { TS << "preup=" << quote(*it) << endl; } for ( QStringList::Iterator it = Data.PreDown_SL.begin(); it != Data.PreDown_SL.end(); ++it ) { TS << "predown=" << quote(*it) << endl; } for ( QStringList::Iterator it = Data.PostUp_SL.begin(); it != Data.PostUp_SL.end(); ++it ) { TS << "postup=" << quote(*it) << endl; } for ( QStringList::Iterator it = Data.PostDown_SL.begin(); it != Data.PostDown_SL.end(); ++it ) { TS << "postdown=" << quote(*it) << endl; } } QWidget * ANetwork::edit( QWidget * parent ) { GUI = new NetworkEdit( parent ); GUI->showData( Data ); return GUI; } QString ANetwork::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ANetwork::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -bool ANetwork::hasDataForFile( const QString & S ) { - return S == "interfaces"; +bool ANetwork::hasDataForFile( SystemFile & S ) { + return S.name() == "interfaces"; } -short ANetwork::generateFile( const QString & ID, - const QString & Path, - QTextStream &TS, +short ANetwork::generateFile( SystemFile &SF, long DevNr ) { short rvl, rvd ; QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); rvl = 1; - if( ID == "interfaces" ) { - Log(("Generate Network for %s\n", ID.latin1() )); + if( SF.name() == "interfaces" ) { + Log(("Generate Network for %s\n", SF.name().latin1() )); // we can safely call from here since device item is deeper if( Data.UseDHCP ) { - TS << "iface " + SF << "iface " << NIC << "-c" << connection()->number() << "-allowed inet dhcp" << endl; - TS << " up echo \"" + SF << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << ".up" << endl; if( Data.SendHostname ) { - TS << " hostname " + SF << " hostname " << Data.Hostname << endl; } - TS << " down rm -f /tmp/profile-" + SF << " down rm -f /tmp/profile-" << connection()->number() << ".up" << endl; } else { - TS << "iface " + SF << "iface " << NIC << "-c" << connection()->number() << "-allowed inet static" << endl; - TS << " up echo \"" + SF << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << ".up" << endl; - TS << " down rm -f /tmp/profile-" + SF << " down rm -f /tmp/profile-" << connection()->number() << ".up" << endl; - TS << " address " + SF << " address " << Data.IPAddress << endl; - TS << " broadcast " + SF << " broadcast " << Data.Broadcast << endl; - TS << " netmask " + SF << " netmask " << Data.NetMask << endl; // derive network address = IPAddress & netmask { QString NW; QStringList ipal = QStringList::split( '.', Data.IPAddress ); QStringList nmal = QStringList::split( '.', Data.NetMask ); NW = QString( "%1.%2.%3.%4" ). arg( ipal[0].toShort() & nmal[0].toShort() ). arg( ipal[1].toShort() & nmal[1].toShort() ). arg( ipal[2].toShort() & nmal[2].toShort() ). arg( ipal[3].toShort() & nmal[3].toShort() ); - TS << " network " + SF << " network " << NW << endl; } } for ( QStringList::Iterator it = Data.PreUp_SL.begin(); it != Data.PreUp_SL.end(); ++it ) { - TS << " pre-up " + SF << " pre-up " << (*it) << endl; } for ( QStringList::Iterator it = Data.PostUp_SL.begin(); it != Data.PostUp_SL.end(); ++it ) { - TS << " up " + SF << " up " << (*it) << endl; } for ( QStringList::Iterator it = Data.PreDown_SL.begin(); it != Data.PreDown_SL.end(); ++it ) { - TS << " down " + SF << " down " << (*it) << endl; } for ( QStringList::Iterator it = Data.PostDown_SL.begin(); it != Data.PostDown_SL.end(); ++it ) { - TS << " post-down " + SF << " post-down " << (*it) << endl; } rvl = 0; } // embed other info in it - rvd = connection()->getToplevel()->generateFileEmbedded( ID, Path, TS, DevNr ); + rvd = connection()->getToplevel()->generateFileEmbedded( SF, DevNr ); return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/network/network_NNI.h b/noncore/settings/networksettings2/network/network_NNI.h index 5e42503..71c276a 100644 --- a/noncore/settings/networksettings2/network/network_NNI.h +++ b/noncore/settings/networksettings2/network/network_NNI.h @@ -1,48 +1,46 @@ #ifndef NETWORK_H #define NETWORK_H #include <netnode.h> #include "networkdata.h" #include "networkrun.h" class NetworkNetNode; class NetworkEdit; class SystemFile; class ANetwork : public ANetNodeInstance{ public : ANetwork( NetworkNetNode * PNN ); RuntimeInfo * runtime( void ) { return ( RT ) ? RT : ( RT = new NetworkRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataForFile( const QString & S ); - virtual short generateFile( const QString & ID, - const QString & Path, - QTextStream &TS, + virtual bool hasDataForFile( SystemFile & SF ); + virtual short generateFile( SystemFile &TS, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : NetworkEdit * GUI; - NetworkData_t Data; + NetworkData Data; NetworkRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/network/networkdata.h b/noncore/settings/networksettings2/network/networkdata.h index 2c5da37..1df9dc4 100644 --- a/noncore/settings/networksettings2/network/networkdata.h +++ b/noncore/settings/networksettings2/network/networkdata.h @@ -1,22 +1,23 @@ #ifndef NETWORK_DATA_H #define NETWORK_DATA_H #include <qstring.h> #include <qstringlist.h> -typedef struct NetworkData { +class NetworkData { +public : bool UseDHCP; QString Hostname; bool SendHostname; QString IPAddress; QString NetMask; QString Gateway; QString Broadcast; QString DNS1; QString DNS2; QStringList PreUp_SL; QStringList PostUp_SL; QStringList PreDown_SL; QStringList PostDown_SL; -} NetworkData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/network/networkedit.cpp b/noncore/settings/networksettings2/network/networkedit.cpp index 05110d9..d13cb66 100644 --- a/noncore/settings/networksettings2/network/networkedit.cpp +++ b/noncore/settings/networksettings2/network/networkedit.cpp @@ -1,224 +1,224 @@ #include <qtoolbutton.h> #include <qcheckbox.h> #include <qtabwidget.h> #include <qlineedit.h> #include <qlistbox.h> #include <GUIUtils.h> #include <resources.h> #include "networkedit.h" NetworkEdit::NetworkEdit( QWidget * Parent ) : NetworkGUI( Parent ){ AddPreDown_TB->setPixmap( NSResources->getPixmap( "add" ) ); AddPreUp_TB->setPixmap( NSResources->getPixmap( "add" ) ); AddPostDown_TB->setPixmap( NSResources->getPixmap( "add" ) ); AddPostUp_TB->setPixmap( NSResources->getPixmap( "add" ) ); DeletePreDown_TB->setPixmap( NSResources->getPixmap( "remove" ) ); DeletePreUp_TB->setPixmap( NSResources->getPixmap( "remove" ) ); DeletePostDown_TB->setPixmap( NSResources->getPixmap( "remove" ) ); DeletePostUp_TB->setPixmap( NSResources->getPixmap( "remove" ) ); UpPreDown_TB->setPixmap( NSResources->getPixmap( "up" ) ); UpPreUp_TB->setPixmap( NSResources->getPixmap( "up" ) ); UpPostDown_TB->setPixmap( NSResources->getPixmap( "up" ) ); UpPostUp_TB->setPixmap( NSResources->getPixmap( "up" ) ); DownPreDown_TB->setPixmap( NSResources->getPixmap( "down" ) ); DownPreUp_TB->setPixmap( NSResources->getPixmap( "down" ) ); DownPostDown_TB->setPixmap( NSResources->getPixmap( "down" ) ); DownPostUp_TB->setPixmap( NSResources->getPixmap( "down" ) ); } QString NetworkEdit::acceptable( void ) { if( DHCP_CB->isChecked() ) { if( SendHostname_CB->isChecked() ) if( Hostname_LE->text().isEmpty() ) return tr("Hostname needed"); return QString(); } if( IPAddress_LE->text().isEmpty() ) return tr("IPAddress needed"); if( Broadcast_LE->text().isEmpty() ) return tr("Broadcast needed"); if( SubnetMask_LE->text().isEmpty() ) return tr("Subnet mask needed"); // valid IP ? if( ! validIP( IPAddress_LE->text() ) ) return tr("IPAddress not valid"); if( ! validIP( SubnetMask_LE->text() ) ) return tr("Subnet mask not valid"); if( ! validIP( Broadcast_LE->text() ) ) return tr("Broadcast address not valid"); if( Gateway_LE->text().isEmpty() || ! validIP( Gateway_LE->text() ) ) return tr("Gateway address not valid"); if( ! DNS1_LE->text().isEmpty() && ! validIP( DNS1_LE->text() ) ) return tr("DNS1 address not valid"); if( ! DNS2_LE->text().isEmpty() && ! validIP( DNS2_LE->text() ) ) return tr("DNS2 address not valid"); return QString(); } -bool NetworkEdit::commit( NetworkData_t & Data ) { +bool NetworkEdit::commit( NetworkData & Data ) { bool SM = 0; CBM( Data.UseDHCP, DHCP_CB, SM ); TXTM( Data.IPAddress, IPAddress_LE, SM ); CBM( Data.SendHostname, SendHostname_CB, SM ); TXTM( Data.Hostname, Hostname_LE, SM ); TXTM( Data.Gateway, Gateway_LE, SM ); TXTM( Data.Broadcast, Broadcast_LE, SM ); TXTM( Data.NetMask, SubnetMask_LE, SM ); TXTM( Data.DNS1, DNS1_LE, SM ); TXTM( Data.DNS2, DNS2_LE, SM ); SM |= updateList( Data.PreUp_SL, PreUp_LB ); SM |= updateList( Data.PostUp_SL, PostUp_LB ); SM |= updateList( Data.PreDown_SL, PreDown_LB ); SM |= updateList( Data.PostDown_SL, PostDown_LB ); return SM; } -void NetworkEdit::showData( NetworkData_t & Data ) { +void NetworkEdit::showData( NetworkData & Data ) { DHCP_CB->setChecked( Data.UseDHCP ); SendHostname_CB->setChecked( Data.SendHostname ); Hostname_LE->setText( Data.Hostname ); IPAddress_LE->setText( Data.IPAddress ); Gateway_LE->setText( Data.Gateway ); SubnetMask_LE->setText( Data.NetMask ); Broadcast_LE->setText( Data.Broadcast ); DNS1_LE->setText( Data.DNS1 ); DNS2_LE->setText( Data.DNS2 ); populateList( Data.PreUp_SL, PreUp_LB ); populateList( Data.PostUp_SL, PostUp_LB ); populateList( Data.PreDown_SL, PreDown_LB ); populateList( Data.PostDown_SL, PostDown_LB ); } bool NetworkEdit::updateList( QStringList & SL, QListBox * LB ) { bool Changed; QStringList NewSL; // collect new list for( unsigned int i = 0; i < LB->count() ; i ++ ) { NewSL.append( LB->text(i) ); } if( NewSL.count() != SL.count() ) { // less or more items SL= NewSL; return 1; } // Same size -> same content ? Changed = 0; for ( QStringList::Iterator it = NewSL.begin(); it != NewSL.end(); ++it ) { if( SL.findIndex( (*it) ) < 0 ) { // new or modified item Changed = 1; SL = NewSL; break; } } return Changed; } void NetworkEdit::populateList( QStringList & SL, QListBox * LB ) { LB->clear(); for ( QStringList::Iterator it = SL.begin(); it != SL.end(); ++it ) { LB->insertItem( (*it) ); } } void NetworkEdit::SLOT_NetmaskModified( const QString & ) { QString IP, SN; IP = IPAddress_LE->text(); SN = SubnetMask_LE->text(); if( IP.isEmpty() || SN.isEmpty() ) return; if( ! validIP(IP) || ! validIP( SN ) ) return; // if all ones // broadcast = (IPAddress | ~netmask ) { QString NW; QStringList ipal = QStringList::split( '.', IP ); QStringList nmal = QStringList::split( '.', SN ); NW = QString( "%1.%2.%3.%4" ). arg( ipal[0].toShort() | ( ~ nmal[0].toShort() & 0x00ff) ). arg( ipal[1].toShort() | ( ~ nmal[1].toShort() & 0x00ff) ). arg( ipal[2].toShort() | ( ~ nmal[2].toShort() & 0x00ff) ). arg( ipal[3].toShort() | ( ~ nmal[3].toShort() & 0x00ff) ); Broadcast_LE->setText( NW ); } } QListBox * NetworkEdit::getActiveLB( void ) { switch( Tab_TAB->currentPageIndex() ) { case 0 : return PreUp_LB; case 1 : return PostUp_LB; case 2 : return PreDown_LB; } return PostDown_LB; } void NetworkEdit::SLOT_Add( void ) { if( Command_LE->text().isEmpty() ) return; QListBox * LB = getActiveLB(); LB->insertItem( Command_LE->text() ); } void NetworkEdit::SLOT_Remove( void ) { QListBox * LB = getActiveLB(); int i; if( ( i = LB->currentItem() ) >= 0 ) { LB->removeItem( i ); } } void NetworkEdit::SLOT_Up( void ) { QListBox * LB = getActiveLB(); int i; if( ( i = LB->currentItem() ) > 0 ) { QListBoxItem * LBI = LB->item(i); LB->takeItem( LBI ); LB->insertItem( LBI, --i ); LB->setCurrentItem( i ); } } void NetworkEdit::SLOT_Down( void ) { QListBox * LB = getActiveLB(); int i; if( ( i = LB->currentItem() ) >= 0 && (unsigned)(i+1) != LB->count() ) { QListBoxItem * LBI = LB->item(i); LB->takeItem( LBI ); LB->insertItem( LBI, ++i ); LB->setCurrentItem( i ); } } void NetworkEdit::SLOT_ShowCommand( QListBoxItem * It ) { Command_LE->setText( It->text() ); } diff --git a/noncore/settings/networksettings2/network/networkedit.h b/noncore/settings/networksettings2/network/networkedit.h index adc20e0..45635c8 100644 --- a/noncore/settings/networksettings2/network/networkedit.h +++ b/noncore/settings/networksettings2/network/networkedit.h @@ -1,29 +1,29 @@ #include "networkdata.h" #include "networkGUI.h" class QListBox; class NetworkEdit : public NetworkGUI { public : NetworkEdit( QWidget * parent ); QString acceptable( void ); - bool commit( NetworkData_t & Data ); - void showData( NetworkData_t & Data ); + bool commit( NetworkData & Data ); + void showData( NetworkData & Data ); public slots : void SLOT_NetmaskModified( const QString & S ); void SLOT_ShowCommand( QListBoxItem * LBI ); void SLOT_Add( void ); void SLOT_Remove( void ); void SLOT_Up( void ); void SLOT_Down( void ); private : QListBox * getActiveLB( void ); bool updateList( QStringList &SL, QListBox * LB ); void populateList( QStringList &SL, QListBox * LB ); }; diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp index 3e24c5f..c17aa7f 100644 --- a/noncore/settings/networksettings2/network/networkrun.cpp +++ b/noncore/settings/networksettings2/network/networkrun.cpp @@ -1,78 +1,51 @@ #include <system.h> -#include <asdevice.h> +#include <netnode.h> +#include <resources.h> #include "networkrun.h" -void NetworkRun::detectState( NodeCollection * NC ) { - RuntimeInfo * RI = netNode()->nextNode()->runtime(); - AsDevice * Next = RI->asDevice(); - InterfaceInfo * II = Next->assignedInterface(); +State_t NetworkRun::detectState( void ) { + InterfaceInfo * II = nodeCollection()->assignedInterface(); - if( II ) { + Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 )); + if( II && II->IsUp ) { // device has assigned interface - NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) ); - return; + return IsUp; } - Log(( "%s not ! UP or ava\n", NC->name().latin1() )); - // has no interface -> delegate - RI->detectState( NC ); + // had no interface or interface is no longer up -> release + nodeCollection()->assignInterface( 0 ); + + return Unknown; } -bool NetworkRun::setState( NodeCollection * NC, Action_t A, bool Force ) { +QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) { // we handle UP and DOWN - RuntimeInfo * RI = netNode()->nextNode()->runtime(); - AsDevice * Next = RI->asDevice(); - InterfaceInfo * II = Next->assignedInterface(); + InterfaceInfo * II = NC->assignedInterface(); if( A == Up ) { // we can bring UP if lower level is available - if( NC->currentState() == Available || Force ) { - QString S; - S.sprintf( "ifup %s=%s-c%d-allowed", - II->Name.latin1(), II->Name.latin1(), - connection()->number() ); - NSResources->system().runAsRoot( S ); - } - return 1; - } else if( A == Down ) { - QString S; - if( Force ) { - Log(("Force mode %d\n", Force )); - for( int i = 0; - i < RI->netNode()->nodeClass()->instanceCount(); - i ++ ) { - S.sprintf( "ifdown %s", - RI->netNode()->nodeClass()->genNic( i ).latin1() ); - NSResources->system().runAsRoot( S ); - } - } else { - if( NC->currentState() == IsUp ) { - S.sprintf( "ifdown %s=%s-c%d-allowed", + QStringList SL; + SL << "ifup" + << QString().sprintf( "%s=%s-c%d-allowed", II->Name.latin1(), II->Name.latin1(), - connection()->number() ); - NSResources->system().runAsRoot( S ); - } - } - return 1; + nodeCollection()->number() ); + if( ! NSResources->system().runAsRoot( SL ) ) { + return QString("Cannot call %1").arg(SL.join(" ")); } - // delegate - return RI->setState( NC, A, Force ); + return QString(); } -bool NetworkRun::canSetState( State_t Curr, Action_t A ) { - // we handle UP and DOWN - RuntimeInfo * RI = netNode()->nextNode()->runtime(); - - if( A == Up ) { - return ( Curr == Available ); - } else if( A == Down ) { - return ( Curr == IsUp ); + if( A == Down ) { + QStringList SL; + if( II ) { + SL << "ifdown" + << II->Name.latin1(); + if( ! NSResources->system().runAsRoot( SL ) ) { + return QString( "Cannot call %1" ).arg( SL.join( " " )); } - // delegate - return RI->canSetState( Curr, A ); + } else { + Log(( "no interface assigned." )); } - -bool NetworkRun::handlesInterface( const QString & S ) { - // donno -> pass deeper - return netNode()->nextNode()->runtime()->handlesInterface(S); + } + return QString(); } diff --git a/noncore/settings/networksettings2/network/networkrun.h b/noncore/settings/networksettings2/network/networkrun.h index 522a912..78a1694 100644 --- a/noncore/settings/networksettings2/network/networkrun.h +++ b/noncore/settings/networksettings2/network/networkrun.h @@ -1,23 +1,20 @@ -#include <asconnection.h> +#include <netnode.h> #include "networkdata.h" -class NetworkRun : public AsConnection { +class NetworkRun : public RuntimeInfo { public : NetworkRun( ANetNodeInstance * NNI, - NetworkData & Data ) : AsConnection( NNI ) + NetworkData & Data ) : RuntimeInfo( NNI ) { } - virtual AsConnection * asConnection( void ) - { return (AsConnection *)this; } + virtual RuntimeInfo * connection( void ) + { return this; } -protected : - - void detectState( NodeCollection * ); - bool setState( NodeCollection * ,Action_t A, bool ); - bool canSetState( State_t , Action_t A ); + State_t detectState( void ); - bool handlesInterface( const QString & I ); +protected : + QString setMyState( NodeCollection * , Action_t, bool ); }; diff --git a/noncore/settings/networksettings2/network/opie-networksettings2plugin-network.control b/noncore/settings/networksettings2/network/opie-networksettings2plugin-network.control index 3dbb808..7b1056b 100644 --- a/noncore/settings/networksettings2/network/opie-networksettings2plugin-network.control +++ b/noncore/settings/networksettings2/network/opie-networksettings2plugin-network.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-network +Package: opie-networksettings2plugin-network Files: plugins/networksettings2/libnetwork.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Generate TCPIP Network settings plugin Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index ce0eabc..a0d4c7c 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -1,469 +1,514 @@ #include <stdio.h> #include <unistd.h> #include <errno.h> +#include <opie2/odebug.h> +#include <opie2/oledbox.h> + #include <qpe/qpeapplication.h> #include <qlistbox.h> +#include <qlayout.h> #include <qgroupbox.h> #include <qtimer.h> #include <qlistbox.h> #include <qmessagebox.h> #include <qlabel.h> #include <qiconview.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qtoolbutton.h> #include <qevent.h> -#include <asdevice.h> #include "networksettings.h" #include "netnode.h" #include "editconnection.h" NetworkSettings::NetworkSettings( QWidget *parent, const char *name, WFlags fl ) : NetworkSettingsGUI(parent,name,fl), NSD() { UpdateTimer = new QTimer( this ); // set pixmaps Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); - Enable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); - Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); - Disconnect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); + Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); + Up_TB->setPixmap( NSResources->getPixmap( "more" ) ); + Down_TB->setPixmap( NSResources->getPixmap( "less" ) ); + + QVBoxLayout* V = new QVBoxLayout( LED_Frm ); + QHBoxLayout * H = new QHBoxLayout( 0 ); + V->addStretch(1); + V->addLayout( H ); + Leds[0] = new OLedBox( red, LED_Frm ); + H->addWidget( Leds[0], 0, Qt::AlignVCenter ); + Leds[1] = new OLedBox( red, LED_Frm ); + H->addWidget( Leds[1], 0, Qt::AlignVCenter ); + Leds[2] = new OLedBox( red, LED_Frm ); + H->addWidget( Leds[2], 0, Qt::AlignVCenter ); + V->addStretch(1); - On_TB->setPixmap( NSResources->getPixmap( "off" ) ); SLOT_ToProfile(); // populate main Listbox Profiles_LB->clear(); QPEApplication::setStylusOperation( Profiles_LB->viewport(), QPEApplication::RightOnHold ); connect( Profiles_LB, SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), this, SLOT(SLOT_EditNode(QListBoxItem*)) ); { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); } } if( Profiles_LB->count() ) { Profiles_LB->setSelected( 0, TRUE ); } // if no profiles -> auto popup editing if( NSResources->connections().count() == 0 ) { QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); } connect( &(NSResources->system()), - SIGNAL( lineFromCommand(const QString &) ), + SIGNAL( stdoutLine(const QString &) ), + this, SLOT( SLOT_CmdMessage(const QString &) ) ); + + connect( &(NSResources->system()), + SIGNAL( stderrLine(const QString &) ), + this, SLOT( SLOT_CmdMessage(const QString &) ) ); + + connect( &(NSResources->system()), + SIGNAL( processEvent(const QString &) ), this, SLOT( SLOT_CmdMessage(const QString &) ) ); UpdateTimer->start( 5000 ); connect( UpdateTimer, SIGNAL( timeout() ), this, SLOT( SLOT_RefreshStates() ) ); /* Add QCopChannel */ connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); } NetworkSettings::~NetworkSettings() { QString S; - if( isModified() ) { + owarn << "Dispose NS" << oendl; + if( NSD.isModified() ) { + owarn << "Modified" << oendl; S = NSD.saveSettings(); if( ! S.isEmpty() ) { + S.insert( 0, "<p>" ); + S.append( "</p>" ); // problem saving QMessageBox::warning( 0, tr( "Saving setup" ), S ); } SLOT_GenerateConfig(); + NSD.setModified( 0 ); } } void NetworkSettings::SLOT_CmdMessage( const QString & S ) { Messages_LB->insertItem( S ); Messages_LB->setCurrentItem( Messages_LB->count()-1 ); Messages_LB->ensureCurrentVisible(); } void NetworkSettings::SLOT_RefreshStates( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember if( LBI ) { NodeCollection * NC; NSResources->system().probeInterfaces(); // update current selection only NC = NSResources->findConnection( LBI->text() ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { updateProfileState( LBI ); } } } /* -> LATER !! bool is; NodeCollection * NC; for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { NC = NSResources->findConnection( Profiles_LB->text(i) ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { is = Profiles_LB->isSelected(i); Profiles_LB->changeItem( NC->statePixmap(NewS), NC->name(), i ); if( is ) { Profiles_LB->setSelected( i, TRUE ); } } } } if( ci >= 0 ) Profiles_LB->setCurrentItem( ci ); */ } void NetworkSettings::SLOT_AddNode( void ) { SLOT_EditNode( 0 ); } void NetworkSettings::SLOT_DeleteNode( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; if( QMessageBox::warning( 0, tr( "Removing profile" ), tr( "Remove selected profile ?" ), 1, 0 ) == 1 ) { NSResources->removeConnection( LBI->text() ); delete LBI; - setModified( 1 ); + NSD.setModified( 1 ); } } void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { QString OldName = ""; - printf( "------------------ Edit NOde\n" ); EditConnection EC( this ); if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); if( ! NC ) { return; } OldName = NC->name(); EC.setConnection( NC ); } EC.showMaximized(); // disable refresh timer UpdateTimer->stop(); // we need to retry while( 1 ) { if( EC.exec() == QDialog::Accepted ) { // toplevel item -> store NodeCollection * NC = EC.connection(); if( NC->isModified() ) { - setModified( 1 ); if( LBI ) { if( NC->name() != OldName ) { // find if new name is free NodeCollection * LCN = NSResources->findConnection( NC->name() ); if( LCN ) { QMessageBox::warning( 0, tr( "In System Config" ), tr( "Name %1 already exists" ).arg(NC->name()) ); continue; // restart exec } // else new name // new name -> remove item NSResources->removeConnection( OldName ); NSResources->addConnection( NC ); } // else not changed // must add it here since change will trigger event Profiles_LB->changeItem( NC->devicePixmap(), NC->name(), Profiles_LB->index( LBI ) ); } else { // new item int ci = Profiles_LB->count(); NSResources->addConnection( NC ); NC->setNumber( NSResources->assignConnectionNumber() ); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); Profiles_LB->setSelected( ci, TRUE ); } updateProfileState( LBI ); } } else { // cancelled : reset connection if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); NC->reassign(); } } break; } // reenable UpdateTimer->start( 5000 ); } void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { if( LBI == 0 ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); - // is button possible - bool EnabledPossible, OnPossible, ConnectPossible; - // is button On or Off - bool DisabledOn, OnOn, ConnectOn; + if( NC->description().isEmpty() ) { + Description_LBL->setText( tr( "<<No description>>" ) ); + } else { + Description_LBL->setText( NC->description() ); + } + + Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); - EnabledPossible = OnPossible = ConnectPossible = 1; - DisabledOn = 1; - OnOn = ConnectOn = 0; + bool FrmActive = 1; + bool IsEnabled = 1; + int leds = 0; + owarn << "State " << NC->state() << oendl; switch( NC->state() ) { - case Unknown : - // cannot occur here + case Disabled : // no further work + IsEnabled = 0; + FrmActive = 0; + owarn << "LEds " << leds << oendl; break; + case Unknown : case Unchecked : case Unavailable : - // cannot do anything but recheck - EnabledPossible = OnPossible = ConnectPossible = 0; - break; - case Disabled : - OnPossible = ConnectPossible = 0; + FrmActive = 0; break; case Off : - DisabledOn = 0; + leds = 1; break; case Available : - OnOn = 1; - Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); - DisabledOn = 0; + leds = 2; break; case IsUp : - OnOn = ConnectOn = 1; - Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); - DisabledOn = 0; + leds = 3; break; } - if( ! OnOn ) { - Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); - } - - // set button state - Enable_TB->setEnabled( EnabledPossible ); - On_TB->setEnabled( OnPossible ); - Connect_TB->setEnabled( ConnectPossible ); + Disable_TB->setOn( ! IsEnabled ); + LED_Frm->setEnabled( FrmActive ); - Enable_TB->setOn( DisabledOn ); - On_TB->setOn( OnOn ); - Connect_TB->setOn( ConnectOn ); - - if( NC->description().isEmpty() ) { - Description_LBL->setText( tr( "<<No description>>" ) ); - } else { - Description_LBL->setText( NC->description() ); + for( int i = 0 ; i < leds; i ++ ) { + Leds[i]->setColor( red ); + Leds[i]->setOn( true ); + } + for( int i = leds ; i < 3; i ++ ) { + Leds[i]->setColor( red ); + Leds[i]->setOn( false ); } - Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); + Up_TB->setEnabled( leds < 3 && leds != 0 ); + Down_TB->setEnabled( leds > 0 ); } void NetworkSettings::SLOT_CheckState( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; updateProfileState( LBI ); } void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { SLOT_ShowNode( LBI ); } } void NetworkSettings::SLOT_GenerateConfig( void ) { - NSD.regenerate(); + QString S = NSD.generateSettings(); + if( ! S.isEmpty() ) { + S.insert( 0, "<p>" ); + S.append( "</p>" ); + QMessageBox::warning( + 0, + tr( "Generate config" ), + S); + } } -void NetworkSettings::SLOT_Enable( void ) { +void NetworkSettings::SLOT_Disable( bool T ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); QString Msg; + if ( ! LBI ) return; - NodeCollection * NC = - NSResources->findConnection( LBI->text() ); - - bool rv; - switch( NC->state() ) { - case Disabled : - Msg = tr( "Cannot enable profile" ); - rv = NC->setState( Enable ); - break; - default : - Msg = tr( "Cannot disable profile" ); - rv = NC->setState( Disable ); - break; - } + NodeCollection * NC = NSResources->findConnection( LBI->text() ); - if( ! rv ) { + owarn << "Prepare to disable" << oendl; + Msg = NC->setState( (T) ? Disable : Enable ); + if( ! Msg.isEmpty() ) { + Msg.insert( 0, "<p>" ); + Msg.append( "</p>" ); QMessageBox::warning( 0, tr( "Activating profile" ), Msg ); return; } + + // reload new state + NC->state( true ); updateProfileState( LBI ); } -void NetworkSettings::SLOT_On( void ) { +void NetworkSettings::SLOT_Up( void ) { + // bring more up + QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); + QString Msg; + int led = -1; if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); - bool rv; switch( NC->state() ) { - case Off : - // activate interface - rv = NC->setState( Activate ); + case Disabled : // cannot modify this state + case Unknown : // cannot modify this state + case Unchecked : // cannot modify this state + case Unavailable : // cannot modify this state + case IsUp : // highest UP state + return; + case Off : // -> activate + led = 1; + Down_TB->setEnabled( true ); + Log(( "Activate interface %s\n", NC->name().latin1() )); + Msg = NC->setState( Activate ); break; - case Available : // deactivate - case IsUp : // deactivate (will also bring down if needed) - rv = NC->setState( Deactivate ); + case Available : // -> up + led = 2; + Log(( "Bring up interface %s\n", NC->name().latin1() )); + Msg = NC->setState( Up ); + if( Msg.isEmpty() ) { + Up_TB->setEnabled( false ); + } break; - default : - // others no change - return; } - if( ! rv ) { + if( ! Msg.isEmpty() ) { + Msg.insert( 0, "<p>" ); + Msg.append( "</p>" ); QMessageBox::warning( 0, - tr( "Activating profile" ), - tr( "Cannot enable profile" ) ); + tr( "Increase availability" ), + Msg ); return; } + updateProfileState( LBI ); + + // set color of led we should change + if( led > 0 ) { + Leds[led]->setColor( blue ); + Leds[led]->setOn( true ); } -void NetworkSettings::SLOT_Connect( void ) { +} + +void NetworkSettings::SLOT_Down( void ) { + // bring more down + QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); + int led = -1; + QString Msg; if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); - bool rv = 1 ; switch( NC->state() ) { - case IsUp : - // down interface - rv = NC->setState( Down ); - break; - case Available : - // up interface - rv = NC->setState( Up ); + case Disabled : // cannot modify this state + case Unknown : // cannot modify this state + case Unchecked : // cannot modify this state + case Unavailable : // cannot modify this state + case Off : // highest DOWN state break; - case Off : - // activate and bring up - rv = ( NC->setState( Activate ) && - NC->setState( Up ) ); + case Available : // -> down + led = 0; + Log(( "Deactivate interface %s\n", NC->name().latin1() )); + Msg = NC->setState( Deactivate ); + Down_TB->setEnabled( false ); break; - default : - // others no change + case IsUp : // highest UP state + led = 1; + Up_TB->setEnabled( true ); + Log(( "Bring down interface %s\n", NC->name().latin1() )); + Msg = NC->setState( Down, 1 ); + if( Msg.isEmpty() ) { + // remove 'up' file to make sure + unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );; + } break; } - if( ! rv ) { + if( ! Msg.isEmpty() ) { + Msg.insert( 0, "<p>" ); + Msg.append( "</p>" ); QMessageBox::warning( 0, - tr( "Activating profile" ), - tr( "Cannot enable profile" ) ); - } - - // we do not update the GUI but wait for the REAL upping of the device -} - -void NetworkSettings::SLOT_Disconnect( void ) { - QString S; - QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); - - if ( ! LBI ) + tr( "Decrease availability" ), + Msg ); return; + } - NodeCollection * NC = - NSResources->findConnection( LBI->text() ); + updateProfileState( LBI ); - Log(( "Force interface %s down\n", NC->name().latin1() )); - NC->setState( Down, 1 ); - // remove 'up' file to make sure - S.sprintf( "/tmp/Profile-%d.up", NC->number() ); - unlink( S.latin1() ); + // set color of led we should change + if( led >= 0 ) { + Leds[led]->setColor( blue ); + } } void NetworkSettings::SLOT_ToMessages( void ) { + Profiles_LB->hide(); Profile_GB->hide(); Messages_GB->show(); } void NetworkSettings::SLOT_ToProfile( void ) { + Profiles_LB->show(); Profile_GB->show(); Messages_GB->hide(); } void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { QDataStream stream( data, IO_ReadOnly ); if( msg == "raise" ) { raise(); return; } /* if ( msg == "someMessage(int,int,int)" ) { int a,b,c; stream >> a >> b >> c; ... } */ } diff --git a/noncore/settings/networksettings2/networksettings.h b/noncore/settings/networksettings2/networksettings.h index 8ec5d08..987e311 100644 --- a/noncore/settings/networksettings2/networksettings.h +++ b/noncore/settings/networksettings2/networksettings.h @@ -1,53 +1,59 @@ #include "nsdata.h" #include "networksettingsGUI.h" #include "resources.h" class ANetNode; class ANetNodeInstance; class QTimer; class QListBoxItem; class QEvent; +class OLedBox; class NetworkSettings : public NetworkSettingsGUI { Q_OBJECT public : NetworkSettings( QWidget *parent=0, const char *name=0, WFlags fl = 0 ); - ~NetworkSettings( void ); + virtual ~NetworkSettings( void ); static QString appName( void ) { return QString::fromLatin1("networksettings"); } - bool isModified( void ) - { return NSD.isModified(); } - void setModified( bool m ) - { NSD.setModified( m ); } - public slots : void SLOT_AddNode( void ); void SLOT_DeleteNode( void ); void SLOT_ShowNode( QListBoxItem * ); void SLOT_EditNode( QListBoxItem * ); void SLOT_CheckState( void ); - void SLOT_Enable( void ); - void SLOT_On( void ); - void SLOT_Connect( void ); - void SLOT_Disconnect( void ); + + void SLOT_Up( void ); + void SLOT_Down( void ); + void SLOT_Disable( bool ); + void SLOT_GenerateConfig( void ); void SLOT_RefreshStates( void ); void SLOT_QCopMessage( const QCString&,const QByteArray& ); void SLOT_ToProfile( void ); void SLOT_ToMessages( void ); void SLOT_CmdMessage( const QString & S ); private : void updateProfileState( QListBoxItem * it ); QTimer * UpdateTimer; NetworkSettingsData NSD; + /* + + no leds : not present, unknown, unchecked or disabled + (1) down : hardware present but inactive + (2) available : hardware present and active + (3) up : present active and connected + + */ + OLedBox * Leds[3]; }; diff --git a/noncore/settings/networksettings2/networksettings.pro b/noncore/settings/networksettings2/networksettings.pro index 5d9efbb..d201db1 100644 --- a/noncore/settings/networksettings2/networksettings.pro +++ b/noncore/settings/networksettings2/networksettings.pro @@ -1,24 +1,24 @@ # CONFIG = qt warn_on debug #CONFIG = qt warn_on release HEADERS = networksettings.h \ activateprofile.h \ activatevpn.h \ editconnection.h SOURCES = main.cpp \ networksettings.cpp \ nsdata.cpp \ activateprofile.cpp \ activatevpn.cpp \ editconnection.cpp -INCLUDEPATH += $(OPIEDIR)/include networksettings2/ -DEPENDPATH += $(OPIEDIR)/include networksettings2/ -LIBS += -lqpe -L$(OPIEDIR)/plugins/networksettings2 -lnetworksettings2 -lopiecore2 +INCLUDEPATH += $(OPIEDIR)/include networksettings2/ opietooth2/ +DEPENDPATH += $(OPIEDIR)/include networksettings2/ opietooth2/ +LIBS += -lqpe -L$(OPIEDIR)/plugins/networksettings2 -lnetworksettings2 -lopietooth2 -lopiecore2 INTERFACES = networksettingsGUI.ui \ editconnectionGUI.ui \ activatevpnGUI.ui \ activateprofileGUI.ui TARGET = $(OPIEDIR)/bin/networksettings2 include( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/networksettings2/GUIUtils.h b/noncore/settings/networksettings2/networksettings2/GUIUtils.h index 23290a9..baf6f0c 100644 --- a/noncore/settings/networksettings2/networksettings2/GUIUtils.h +++ b/noncore/settings/networksettings2/networksettings2/GUIUtils.h @@ -1,36 +1,45 @@ #ifndef __GUIUTILS_H #define __GUIUTILS_H #include <qstring.h> // if TEXT capable widget has changed #define TXTM( Data, Wdg, FL ) \ if( Wdg->text() != Data ) { \ FL = 1; \ Data = Wdg->text(); \ } // if IsChecked capable widget has changed #define CBM(Data,Wdg,FL) \ if( Wdg->isChecked() != Data) { \ FL = 1; \ Data = Wdg->isChecked(); \ } // if Value capable widget has changed #define SBM(Data,Wdg,FL) \ if( Wdg->value() != Data) { \ FL = 1; \ Data = Wdg->value(); \ } // if currentItem capable widget has changed #define CIM(Data,Wdg,FL) \ if( Wdg->currentItem() != Data) { \ FL = 1; \ Data = Wdg->currentItem(); \ } +#define STXT(a, b) \ + b->setText( a ); + +#define SCB(a, b) \ + b->setChecked( a ); + +#define SSB( Data,Wdg) \ + Wdg->setValue( Data ) + extern bool validIP( const QString & S ); #endif diff --git a/noncore/settings/networksettings2/networksettings2/Utils.h b/noncore/settings/networksettings2/networksettings2/Utils.h index 739476e..301aac1 100644 --- a/noncore/settings/networksettings2/networksettings2/Utils.h +++ b/noncore/settings/networksettings2/networksettings2/Utils.h @@ -1,9 +1,11 @@ #ifndef __UTILS_H #define __UTILS_H +#include <opie2/odebug.h> + #define Log(x) VLog x extern void VLog( char * Format, ... ); extern void LogClose( void ); extern QString removeSpaces( const QString & X ); #endif diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index 110786a..17653bd 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -1,337 +1,511 @@ #include <time.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> - #include <qpainter.h> #include <qbitmap.h> #include <qtextstream.h> #include <qpixmap.h> #include "resources.h" #include "netnode.h" -#include "asdevice.h" -#include "asline.h" -#include "asconnection.h" -#include "asfullsetup.h" +static char * ActionName[] = { + "Disable", + "Enable", + "Activate", + "Deactivate", + "Up", + "Down" +}; + +static char * StateName[] = { + "Unchecked", + "Unknown", + "Unavailable", + "Disabled", + "Off", + "Available", + "IsUp" +}; QString & deQuote( QString & X ) { if( X[0] == '"' ) { // remove end and trailing "" and \x -> x QChar R; long idx; idx = X.length()-1; X = X.mid( 1, idx ); idx = 0; while( ( idx = X.find( '\\', idx ) ) >= 0 ) { R = X.at( idx + 1 ); X.replace( idx, 2, &R, 1 ); } X = X.left( X.length()-1 ); } return X; } QString quote( QString X ) { if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { // need to quote this QString OutString = "\""; X.replace( QRegExp("\""), "\\\"" ); X.replace( QRegExp("\\"), "\\\\" ); X.replace( QRegExp(" "), "\\ " ); OutString += X; OutString += "\""; X = OutString; } return X; } // // // ANETNODE // // void ANetNode::saveAttributes( QTextStream & TS ) { saveSpecificAttribute( TS ); } void ANetNode::setAttribute( QString & Attr, QString & Value ){ setSpecificAttribute( Attr, Value ); } +bool ANetNode::isToplevel( void ) { + const char ** P = provides(); + while( *P ) { + if( strcmp( *P, "fullsetup") == 0 ) + return 1; + P ++; + } + return 0; +} + +bool ANetNode::openFile( SystemFile & SF, + ANetNodeInstance * NNI ) { + return (NNI ) ? NNI->openFile( SF ) : 0 ; +} + // // // ANETNODEINSTANCE // // long ANetNodeInstance::InstanceCounter = -1; void ANetNodeInstance::initialize( void ) { if( InstanceCounter == -1 ) InstanceCounter = time(0); // set name QString N; N.sprintf( "-%ld", InstanceCounter++ ); N.prepend( NodeType->name() ); setName( N.latin1() ); } void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ - if( Attr == "name" ) { + if( Attr == "__name" ) { setName( Value.latin1() ); } else { setSpecificAttribute( Attr, Value ); } } void ANetNodeInstance::saveAttributes( QTextStream & TS ) { - TS << "name=" << name() << endl; + TS << "__name=" << name() << endl; saveSpecificAttribute( TS ); } ANetNodeInstance * ANetNodeInstance::nextNode( void ) { return connection()->findNext( this ); } // // // NODECOLLECTION // // NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { IsModified = 0; Index = -1; Name=""; IsNew = 1; CurrentState = Unchecked; + AssignedInterface = 0; } NodeCollection::NodeCollection( QTextStream & TS ) : QList<ANetNodeInstance>() { long idx; bool InError = 0; QString S, A, N; IsModified = 0; Index = -1; Name=""; IsNew = 0; + AssignedInterface = 0; CurrentState = Unchecked; do { S = TS.readLine(); if( S.isEmpty() ) { if( InError ) { // remove all nodes clear(); } // empty line break; } idx = S.find('='); S.stripWhiteSpace(); A = S.left( idx ); A.lower(); N = S.mid( idx+1, S.length() ); N.stripWhiteSpace(); N = deQuote( N ); if( A == "name" ) { Name = N; } else if( A == "number" ) { - Log(( "Profile number %s\n", N.latin1() )); setNumber( N.toLong() ); } else if( A == "node" ) { ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); if( NNI && ! InError ) { append( NSResources->findNodeInstance( N ) ); } else { // could not find a node type -> collection invalid InError = 1; } } } while( 1 ); + + Log(( "Profile number %s : %d nodes\n", + N.latin1(), count() )); } NodeCollection::~NodeCollection( void ) { } const QString & NodeCollection::description( void ) { ANetNodeInstance * NNI = getToplevel(); - return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name; + return (NNI) ? NNI->runtime()->description() : Name; } void NodeCollection::append( ANetNodeInstance * NNI ) { NNI->setConnection( this ); QList<ANetNodeInstance>::append( NNI ); } void NodeCollection::save( QTextStream & TS ) { TS << "name=" << quote( Name ) << endl; TS << "number=" << number() << endl; ANetNodeInstance * NNI; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); TS << "node=" << NNI->name() << endl; } TS << endl; IsNew = 0; } ANetNodeInstance * NodeCollection::getToplevel( void ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); if( NNI->nodeClass()->isToplevel() ) break; } return NNI; } ANetNodeInstance * NodeCollection::findByName( const QString & S ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); if( NNI->name() == S ) break; } return NNI; } ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { ANetNodeInstance * NNNI; if( ! NNI ) getToplevel(); for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNNI = it.current(); if( NNNI == NNI ) { ++it; return it.current(); } } return 0; // no more next } int NodeCollection::compareItems( QCollection::Item I1, QCollection::Item I2 ) { ANetNodeInstance * NNI1, * NNI2; NNI1 = (ANetNodeInstance *)I1; NNI2 = (ANetNodeInstance *)I2; return strcmp( NNI1->name(), NNI2->name() ); } static char * State2PixmapTbl[] = { "NULL", // Unchecked : no pixmap "check", // Unknown "delete", // unavailable "disabled", // disabled "off", // off "disconnected", // available "connected" // up }; QPixmap NodeCollection::devicePixmap( void ) { QPixmap pm = NSResources->getPixmap( getToplevel()->nextNode()->pixmapName()+"-large"); - QPixmap Mini = NSResources->getPixmap( device()->netNode()->pixmapName() ); + QPixmap Mini = NSResources->getPixmap( + device()->netNode()->pixmapName() ); if( pm.isNull() || Mini.isNull() ) return Resource::loadPixmap("Unknown"); QPainter painter( &pm ); painter.drawPixmap( pm.width()-Mini.width(), pm.height()-Mini.height(), Mini ); pm.setMask( pm.createHeuristicMask( TRUE ) ); return pm; } QPixmap NodeCollection::statePixmap( State_t S) { return NSResources->getPixmap( State2PixmapTbl[S] ); } QString NodeCollection::stateName( State_t S) { switch( S ) { case Unknown : return qApp->translate( "networksettings2", "Unknown"); case Unavailable : return qApp->translate( "networksettings2", "Unavailable"); case Disabled : return qApp->translate( "networksettings2", "Disabled"); case Off : - return qApp->translate( "networksettings2", "Off"); + return qApp->translate( "networksettings2", "Inactive"); case Available : return qApp->translate( "networksettings2", "Available"); case IsUp : - return qApp->translate( "networksettings2", "IsUp"); + return qApp->translate( "networksettings2", "Up"); case Unchecked : /* FT */ default : break; } return QString(""); } void NodeCollection::reassign( void ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { it.current()->setConnection( this ); } } -bool NodeCollection::triggersVPN() { - return getToplevel()->runtime()->asFullSetup()->triggersVPN(); +const QStringList & NodeCollection::triggers() { + return getToplevel()->runtime()->triggers(); } -bool NodeCollection::hasDataForFile( const QString & S ) { +bool NodeCollection::hasDataForFile( SystemFile & S ) { return ( firstWithDataForFile( S ) != 0 ); } -ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) { +ANetNodeInstance * NodeCollection::firstWithDataForFile( SystemFile & S ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { if( it.current()->hasDataForFile( S ) ) { - Log(( "Node %s has data for %s\n", - it.current()->nodeClass()->name(), - S.latin1() )); return it.current(); } } return 0; } +State_t NodeCollection::state( bool Update ) { + State_t NodeState; + + if( CurrentState == Unchecked || Update ) { + // collect states of all nodes until with get the 'higest' + // state possible + + Log(( "Connection %s state %s\n", + Name.latin1(), StateName[CurrentState] )); + + CurrentState = Unknown; + for( QListIterator<ANetNodeInstance> it(*this); + it.current(); + ++it ) { + Log(( "-> Detect %s\n", it.current()->name() )); + NodeState = it.current()->runtime()->detectState(); + Log(( " state %s\n", StateName[NodeState] )); + + if( NodeState == Disabled || + NodeState == IsUp ) { + // max + CurrentState = NodeState; + break; + } + + if( NodeState > CurrentState ) { + // higher + CurrentState = NodeState; + } + } + } + + return CurrentState; +} + +QString NodeCollection::setState( Action_t A, bool Force ) { + + QString msg; + Action_t Actions[10]; + int NoOfActions = 0; + + // get current state + state( Force ); + + switch( A ) { + case Disable : + if( CurrentState < Disabled ) { + // disabled + CurrentState = Disabled; + return QString(); + } + + if( CurrentState == IsUp ) { + Actions[NoOfActions++] = Down; + Actions[NoOfActions++] = Deactivate; + } else if( CurrentState == Available ) { + Actions[NoOfActions++] = Deactivate; + } + Actions[NoOfActions++] = Disable; + break; + case Enable : + // always possible -> detected state is new state + Actions[NoOfActions++] = Enable; + break; + case Activate : + if( ! Force ) { + if( CurrentState >= Available ) { + // already available + return QString(); + } + + if( CurrentState != Off ) { + return qApp->translate( "System", + "State should be off" ); + } + } + + Actions[NoOfActions++] = Activate; + break; + case Deactivate : + if( ! Force ) { + if( CurrentState < Off ) { + // already inactive + return QString(); + } + } + + if( CurrentState == IsUp ) { + Actions[NoOfActions++] = Down; + } + Actions[NoOfActions++] = Deactivate; + break; + case Up : + if( ! Force ) { + if( CurrentState == IsUp ) { + return QString(); + } + if( CurrentState < Off ) { + return qApp->translate( "System", + "State should at least be off" ); + } + } + if( CurrentState == Off ) { + Actions[NoOfActions++] = Activate; + } + Actions[NoOfActions++] = Up; + break; + case Down : + if( ! Force ) { + if( CurrentState < Available ) { + // OK + return QString(); + } + } + Actions[NoOfActions++] = Down; + break; + } + + // send actions to all nodes + Log(( "Action %s requires %d steps\n", + ActionName[A], NoOfActions )); + + for( int i = 0 ; i < NoOfActions; i ++ ) { + // setState recurses through the tree depth first + msg = getToplevel()->runtime()->setState( this, Actions[i], Force ); + if( ! msg.isEmpty() ) { + return msg; + } + } + return QString(); +} + // // -// RUNTIMEINFO +// RuntimeInfo // // -InterfaceInfo * RuntimeInfo::assignedInterface( void ) { - return netNode()->nextNode()->runtime()->assignedInterface(); +QString RuntimeInfo::setState( NodeCollection * NC, + Action_t A, + bool Force ) { + QString M; + RuntimeInfo * Deeper = nextNode(); + + if( Deeper ) { + // first go deeper + M = Deeper->setState( NC, A, Force ); + if( ! M.isEmpty() ) + return M; } -AsDevice * RuntimeInfo::device( void ) { - return netNode()->nextNode()->runtime()->device(); + // set my own state + Log (( "-> Act upon %s\n", netNode()->name() )); + M = setMyState( NC, A, Force ); + Log (( " result %s\n", M.latin1() )); + return M; } diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index d3d7b34..4626381 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -1,494 +1,596 @@ #ifndef NETNODE_H #define NETNODE_H #include <qtextstream.h> #include <qlist.h> #include <qdict.h> #include <qpixmap.h> #include <qstringlist.h> #include <qobject.h> #include <time.h> #include <Utils.h> +#include <system.h> // difference feature interfaces class AsDevice; class AsLine; class AsConnection; class AsFullSetup; // needed for plugin creation function #include <qlist.h> class ANetNode; class ANetNodeInstance; class NodeCollection; class QTextStream; class RuntimeInfo; class InterfaceInfo; +class NSResources; extern QString & deQuote( QString & X ); extern QString quote( QString X ); #include "systemfile.h" typedef enum State { // if we have not yet detected the state of the device Unchecked = 0, // if we cannot determine the state Unknown = 1, // if connection cannot be established e.g. because // the hardware is not available Unavailable = 2, // if the connection cannot be establishec but NOT // because it is physically impossible but because // it has been disabled for FUNCTIONAL reasons Disabled = 3, // if connection is available to is currently down // i.e. the corresponding hardware is not activated Off = 4, // if connection is available to be used (i.e. the // devices if fully ready to be used Available = 5, // if connection is being used IsUp = 6 } State_t; typedef enum Action { - // to make the device unavailable functionally + // to make the device unavailable functionally -> to disabled Disable = 0, - // to make the device available functionally + // to make the device available functionally -> to off Enable = 1, - // bring the hardware up + // bring the hardware up -> to Available Activate = 2, - // bring the hardware down + // bring the hardware down -> to off Deactivate = 3, - // bring the connection up + // bring the connection up -> to IsUp Up = 4, - // bring the connection down + // bring the connection down -> to Available Down = 5 } Action_t; class ANetNode : public QObject{ public: typedef QArray<ANetNode *> NetNodeList; ANetNode( const char * Name ) : QObject( 0, Name ) {} virtual ~ANetNode(){}; // // // standard methods with sensible default // // inline int done( void ) { return Done; } inline void setDone( int D ) { Done = D; } // does this Node provide a Connection - inline bool isToplevel( void ) - { return strcmp( provides(), "fullsetup") == 0 ; } + bool isToplevel( void ); // set the value of an attribute void setAttribute( QString & Attr, QString & Value ) ; void saveAttributes( QTextStream & TS ) ; // compiled references to 'needed' NetNodes -> needs list inline void setAlternatives( NetNodeList * Alt ) { Alternatives = Alt; } inline NetNodeList & alternatives( void ) { return *Alternatives; } // // // Virtual methods with sensible default // // // do instances of this noce class have data for this file - virtual bool hasDataForFile( const QString & ) + virtual bool hasDataForFile( SystemFile & ) { return 0; } + // open proper file SF identified by S + // this method is called by NS2. + // + // overrule this ONLY if this proper file is a common file + // for all NNI of this node class and the data generated + // by each of the NNI needs to be put in one file + // + // if this is the case the file should be (re)opened in append + // return 0 if file cannot be opened + virtual bool openFile( SystemFile &SF, + ANetNodeInstance * NNI ); + // generate instance independent stuff // 0 : data output, 1 no data, 2 error - virtual short generateFile( const QString & , - const QString & , - QTextStream & , - long ) + virtual short generatePreamble( SystemFile & ) + { return 1; } + + // generate instance independent stuff + // 0 : data output, 1 no data, 2 error + virtual short generatePostamble( SystemFile & ) { return 1; } - // generate instance dependent but profile common stuff + // generate instance dependent but instance common stuff // 0 : data output, 1 no data, 2 error - virtual short generateFile( const QString & , - const QString & , - QTextStream & , + virtual short generateFile( SystemFile &, ANetNodeInstance * , long ) { return 1; } - // generate NIC name based on instance nr // only relevant if node instances are devices virtual QString genNic( long ) { return QString(""); } // max number of instances for this node type // only relevant if node instances are devices virtual long instanceCount( void ) { return 1; } - // return list of files that are specific for this node class - virtual QStringList * properFiles( void ) - { return 0; } + // return ID list for each file generated specially for + // this node type + virtual QStringList properFiles( void ) + { return QStringList(); } // // // pure virtual methods with sensible default // // // pixmap needed for this NetNode virtual const QString pixmapName() = 0; // description for this NetNode virtual const QString nodeDescription() = 0; // create a blank instance of a net node virtual ANetNodeInstance * createInstance( void ) = 0; - // return feature this NetNode provides - virtual const char * provides( void ) = 0; + // return features this NetNode provides + virtual const char ** provides( void ) = 0; + + // return features this NetNode needs virtual const char ** needs( void ) = 0; protected : NetNodeList * Alternatives; private : virtual void setSpecificAttribute( QString & , QString & ) = 0; virtual void saveSpecificAttribute( QTextStream & ) = 0; int Done; }; class ANetNodeInstance : public QObject { public: ANetNodeInstance( ANetNode * NN ) : QObject() { IsModified=0; NodeType = NN; IsNew = TRUE; } virtual ~ANetNodeInstance( void ) { } inline int done( void ) { return Done; } inline void setDone( int D ) { Done = D; } // return data was modified inline void setModified( bool M ) { IsModified = M; } inline bool isModified( void ) { return IsModified; } // get next node ANetNodeInstance * nextNode(); // return NetNode this is an instance of ANetNode * nodeClass( void ) { return NodeType; } // intialize am instance of a net node void initialize( void ); // set the value of an attribute void setAttribute( QString & Attr, QString & Value ) ; void saveAttributes( QTextStream & TS ) ; // return true if node isntance is NEW and not loaded inline void setNew( bool IsN ) { IsNew = IsN; } inline bool isNew( void ) { return IsNew; } // return description for this instance inline QString & description( void ) { return Description; } inline void setDescription( const QString & S ) { Description = S; } // pixmap for this instance -> from NetNode inline const QString pixmapName( void ) { return NodeType->pixmapName(); } - inline const char * provides( void ) + inline const char ** provides( void ) { return NodeType->provides(); } inline const char ** needs( void ) { return NodeType->needs(); } inline void setConnection( NodeCollection * NC ) { Connection = NC; } inline NodeCollection * connection( void ) { return Connection; } // // // Virtual methods with sensible defaults // // // open proper file identified by S - virtual QFile * openFile( const QString & ) + virtual bool openFile( SystemFile & ) { return 0; } // check if this node (or sub nodes) have data for this file - virtual bool hasDataForFile( const QString & S ) + virtual bool hasDataForFile( SystemFile & S ) { return nodeClass()->hasDataForFile( S ); } // generate code specific for this node but embedded // in the section of the parent // this is called within the code of the parent - virtual short generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, + virtual short generateFileEmbedded( SystemFile & SF, long DevNr ) { ANetNodeInstance * NNI = nextNode(); - return (NNI) ? NNI->generateFileEmbedded( ID, Path, TS, DevNr ) : 1; + return (NNI) ? NNI->generateFileEmbedded( SF, DevNr ) : 1; } // generate code specific for this node // (or find the first node that does) - virtual short generateFile( const QString & ID, - const QString & Path, - QTextStream & TS, + virtual short generateFile( SystemFile & SF, long DevNr ) { ANetNodeInstance * NNI = nextNode(); - return (NNI) ? NNI->generateFile( ID, Path, TS, DevNr ) : 1; + return (NNI) ? NNI->generateFile( SF, DevNr ) : 1; } // return true if this node instance is triggered by this trigger // could be delegated to deeper instances virtual bool triggeredBy( const QString & ) { return 0; } // // // Pure virtual functions // // // return runtime information for this node virtual RuntimeInfo * runtime( void ) = 0; // create edit widget under parent virtual QWidget * edit( QWidget * parent ) = 0; // is given data acceptable virtual QString acceptable( void ) = 0; // get data from GUI and store in node virtual void commit( void ) = 0; // returns node specific data -> only useful for 'buddy' virtual void * data( void ) = 0; protected : virtual void setSpecificAttribute( QString & , QString & ) = 0; virtual void saveSpecificAttribute( QTextStream & ) = 0; ANetNode * NodeType; // connection to which this node belongs to NodeCollection * Connection; QString Description; bool IsModified; bool IsNew; int Done; static long InstanceCounter; }; class RuntimeInfo : public QObject { Q_OBJECT public : RuntimeInfo( ANetNodeInstance * TheNNI ) { NNI = TheNNI; } - // downcast implemented by specify runtime classes - virtual AsDevice * asDevice( void ) - { return 0; } - virtual AsConnection * asConnection( void ) - { return 0; } - virtual AsLine * asLine( void ) - { return 0; } - virtual AsFullSetup * asFullSetup( void ) - { return 0; } + // + // + // methods to be overloaded by connection capable + // runtimes + // + // + + + // + // + // methods to be overloaded by device capable + // runtimes + // + // // does this node handles this interface e.g.eth0 // recurse deeper if this node cannot answer that question - virtual bool handlesInterface( const QString & ) - { return 0; } - virtual bool handlesInterface( const InterfaceInfo & ) - { return 0; } - virtual InterfaceInfo * assignedInterface( void ); - virtual AsDevice * device( void ); + virtual bool handlesInterface( const QString & S ) { + RuntimeInfo * RI = device(); + if( RI ) { + return RI->handlesInterface( S ); + } + return 0; + } + bool handlesInterface( const InterfaceInfo & I ) { + RuntimeInfo * RI = device(); + if( RI ) { + return RI->handlesInterface( I ); + } + return 0; + } - ANetNodeInstance * netNode() + // + // + // methods to be overloaded by full setup capable + // runtimes + // + // + + // return description for this full setup + virtual const QString & description( void ) { + return fullSetup()->description( ); + } + // return triggers that should fire when this + // setup is brought up + virtual const QStringList & triggers( void ) { + return fullSetup()->triggers( ); + } + + // + // + // methods to be overloaded by line capable + // runtimes + // + // + + // return the device file ('/dev/xxx') created + // by this line capable runtime + virtual QString deviceFile( void ) { + RuntimeInfo * RI = line(); + if( RI ) { + return RI->deviceFile(); + } + return QString(); + } + + // + // + // runtime interface + // + // + + // return the node that offers device capability + virtual RuntimeInfo * device( void ) + { RuntimeInfo * RI = nextNode(); + return (RI) ? RI->device() : 0; + } + + // return the node that offers connection capability + virtual RuntimeInfo * connection( void ) + { RuntimeInfo * RI = nextNode(); + return (RI) ? RI->connection() : 0; + } + + // return the node that offers line capability + virtual RuntimeInfo * line( void ) + { RuntimeInfo * RI = nextNode(); + return (RI) ? RI->line() : 0; + } + + // return the node that offers full setup capability + virtual RuntimeInfo * fullSetup( void ) + { RuntimeInfo * RI = nextNode(); + return (RI) ? RI->fullSetup() : 0; + } + + inline ANetNodeInstance * netNode() { return NNI; } - NodeCollection * connection() + + inline NodeCollection * nodeCollection() { return NNI->connection(); } - virtual void detectState( NodeCollection * NC ) = 0; - virtual bool setState( NodeCollection * NC, Action_t A, bool Force = 0 ) = 0; - virtual bool canSetState( State_t Curr, Action_t A ) = 0; + virtual State_t detectState( void ) = 0; + // public API to set the state + virtual QString setState( NodeCollection * NC, + Action_t A, + bool Force = 0 ); + + inline RuntimeInfo * nextNode( void ) { + ANetNodeInstance * NNI = netNode()->nextNode(); + return (NNI) ? NNI->runtime() : 0; + } signals : // sent by device if state changes void stateChanged( State_t S, ANetNodeInstance * NNI ); protected : + // set state of this node (private API) + virtual QString setMyState( NodeCollection * NC, + Action_t A, + bool Force = 0 ) = 0; + // connection this runtime info belongs to ANetNodeInstance * NNI; }; class NodeCollection : public QList<ANetNodeInstance> { public : NodeCollection( void ); NodeCollection( QTextStream & TS ); ~NodeCollection( void ); inline int done( void ) { return Done; } inline void setDone( int D ) { Done = D; } inline int number( void ) { return Number; } inline void setNumber( int i ) { Number = i; } inline bool isNew( void ) { return IsNew; } inline void setNew( bool N ) { IsNew = N ; } inline bool isModified( void ) { return IsModified; } inline void setModified( bool N ) { IsModified = N ; } inline bool handlesInterface( const QString & S ) { return getToplevel()->runtime()->handlesInterface( S ); } + // return the interface in the OS that is assigned to + // this device inline InterfaceInfo * assignedInterface( void ) { - return getToplevel()->runtime()->assignedInterface(); + return AssignedInterface; } - inline AsDevice * device() { - return getToplevel()->runtime()->device(); + // assign the interface to this device + inline void assignInterface( InterfaceInfo * NI ) { + if( NI == 0 ) { + if( AssignedInterface ) { + AssignedInterface->assignConnection( 0 ); } - - bool triggersVPN(); - - inline State_t state( bool Update = 0 ) - { Log(( "%s state %d(=%d?)\n", Name.latin1(), CurrentState, - Unchecked )); - if( CurrentState == Unchecked || Update ) { - Log(( "TL %p TLR %p\n", - getToplevel(), - getToplevel()->runtime() )); - // need to get current state - getToplevel()->runtime()->detectState( this ); } - return CurrentState; + AssignedInterface = NI; + if( AssignedInterface ) { + AssignedInterface->assignConnection( this ); + } } + inline RuntimeInfo * device() { + return getToplevel()->runtime()->device(); + } + + const QStringList & triggers(); + + State_t state( bool Update = 0 ); + // get the ixmap for this device QPixmap devicePixmap( void ); QPixmap statePixmap( State_t S ); inline QPixmap statePixmap( bool Update = 0 ) { return statePixmap( state(Update) ); } QString stateName( State_t ); inline QString stateName( bool Update = 0 ) { return stateName( state(Update) ); } - inline bool setState( Action_t A, bool Force =0 ) - { return getToplevel()->runtime()->setState( this, A, Force ); } - inline bool canSetState( Action_t A ) - { return getToplevel()->runtime()->canSetState( CurrentState, A ); } + QString setState( Action_t A, bool Force = 0 ); void save( QTextStream & TS ); void append( ANetNodeInstance * NNI ); // makes sure that all items in the connection point to // that connectoin void reassign( void ); ANetNodeInstance * getToplevel( void ); ANetNodeInstance * findNext( ANetNodeInstance * NNI ); ANetNodeInstance * findByName( const QString & S ); inline const QString & name() { return Name; } const QString & description( void ); inline void setName( const QString & N) { Name = N; } inline State_t currentState( void ) { return CurrentState; } inline void setCurrentState( State_t S ) { CurrentState = S; } // return TRUE if this node can have data to be inserted in // file identified by S - bool hasDataForFile( const QString & S ); - ANetNodeInstance * firstWithDataForFile( const QString & S ); + bool hasDataForFile( SystemFile & S ); + ANetNodeInstance * firstWithDataForFile( SystemFile & ); // generate items for this file -> toplevel call - short generateFile( const QString & FID, // identification of file - const QString & FName, // effective filename of file - QTextStream & TS, // stream to file + short generateFile( SystemFile & SF, long DN // device number ) - { return getToplevel()->generateFile( FID, FName, TS, DN ); } + { return getToplevel()->generateFile( SF, DN ); } bool triggeredBy( const QString & Trigger ) { return getToplevel()->triggeredBy( Trigger ); } private : int compareItems ( QCollection::Item item1, QCollection::Item item2 ); long Number; // state of this connection State_t CurrentState; QString Name; // true if this collection was just created (and not // loaded from file bool IsNew; // index in listbox int Index; bool IsModified; int Done; + InterfaceInfo * AssignedInterface; + }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/networksettings2.pro b/noncore/settings/networksettings2/networksettings2/networksettings2.pro index d1e42b7..f2ba9df 100644 --- a/noncore/settings/networksettings2/networksettings2/networksettings2.pro +++ b/noncore/settings/networksettings2/networksettings2/networksettings2.pro @@ -1,28 +1,24 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/lib$(PROJMAK) HEADERS = netnode.h \ resources.h \ system.h \ - asline.h \ GUIUtils.h \ - asconnection.h \ - asfullsetup.h \ systemfile.h \ - wextensions.h \ - asdevice.h + wextensions.h SOURCES = netnode.cpp \ GUIUtils.cpp \ system.cpp \ systemfile.cpp \ wextensions.cpp \ resources.cpp INCLUDEPATH += $(OPIEDIR)/include ../networksettings2 DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopiecore2 -lopieui2 INTERFACES = TARGET = networksettings2 VERSION = 1.0.0 include( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 2f17693..8b3b4fe 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -1,450 +1,470 @@ #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <pwd.h> #include <qpixmap.h> #include <qdir.h> #include <qpe/qlibrary.h> #include <qpe/qpeapplication.h> #include <opie2/odebug.h> #include <qtopia/resource.h> #include "netnode.h" #include "resources.h" #define PLUGINDIR "plugins/networksettings2" #define ICONDIR "/pics/networksettings2/" // single resources instance TheNSResources * _NSResources = 0; TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), ConnectionsMap() { _NSResources = this; detectCurrentUser(); // load available netnodes findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); // compile provides and needs lists { const char ** NeedsRun; QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); bool Done; for ( ; OuterIt.current(); ++OuterIt ) { // find needs list ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; ANetNode::NetNodeList & NNL = *(NNLP); // must iterate this way to avoid duplication pointers for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); InnerIt.current(); ++InnerIt ) { if( InnerIt.current() == OuterIt.current() ) // avoid recursive continue; - const char * Provides = InnerIt.current()->NetNode->provides(); + const char ** Provides = InnerIt.current()->NetNode->provides(); NeedsRun = OuterIt.current()->NetNode->needs(); + for( ; *NeedsRun; NeedsRun ++ ) { - if( strcmp( Provides, *NeedsRun ) == 0 ) { + const char ** PRun; + PRun = Provides; + for( ; *PRun; PRun ++ ) { + if( strcmp( *PRun, *NeedsRun ) == 0 ) { // inner provides what outer needs NNL.resize( NNL.size() + 1 ); NNL[NNL.size()-1] = InnerIt.current()->NetNode; Done = 1; // break from 2 loops break; } } } + } OuterIt.current()->NetNode->setAlternatives( NNLP ); } } - // define Node types to Description map - NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); - NodeTypeNameMap.insert( "line", tr( "Character device" ) ); - NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); - NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); - - NodeTypeDescriptionMap.insert( "device", + // define built in Node types to Description map + addNodeType( "device", tr( "Network Device" ), tr( "<p>Devices that can handle IP packets</p>" ) ); - NodeTypeDescriptionMap.insert( "line", + addNodeType( "line", tr( "Character device" ), tr( "<p>Devices that can handle single bytes</p>" ) ); - NodeTypeDescriptionMap.insert( "connection", + addNodeType( "connection", tr( "IP Connection" ), tr( "<p>Nodes that provide working IP connections</p>" ) ); - NodeTypeDescriptionMap.insert( "fullsetup", + addNodeType( "fullsetup", tr( "Connection Profile" ), tr( "<p>Fully configured connection profile</p>" ) ); - - // define system files - addSystemFile( "interfaces", "/tmp/interfaces", 1 ); + addNodeType( "GPRS", tr( "Connection to GPRS device" ), + tr( "<p>Connection to a GPRS capable device</p>" ) ); // get access to the system TheSystem = new System(); } TheNSResources::~TheNSResources( void ) { delete TheSystem; } +void TheNSResources::addNodeType( const QString & ID, + const QString & Name, + const QString & Descr ) { + if( NodeTypeNameMap[ID].isEmpty() ) { + NodeTypeNameMap.insert( ID, Name ); + NodeTypeDescriptionMap.insert( ID, Descr ); + } +} + void TheNSResources::addSystemFile( const QString & ID, const QString & P, bool KDI ) { if( ! SystemFiles.find( ID ) ) { // new system file SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); } // else existed } void TheNSResources::busy( bool ) { /* if( B ) { ShowWait->show(); qApp->process } else { ShowWait->hide(); } */ } /** * Load all modules that are found in the path * @param path a directory that is scaned for any plugins that can be loaded * and attempts to load them */ void TheNSResources::findAvailableNetNodes(const QString &path){ Log(("Locate plugins in %s\n", path.latin1() )); QDir d(path); if(!d.exists()) return; QString lang = ::getenv("LANG"); // Don't want sym links d.setFilter( QDir::Files | QDir::NoSymLinks ); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); QFileInfo *fi; while ( (fi=it.current()) ) { if( fi->fileName().contains(".so")){ /* if loaded install translation */ if( loadNetNode(path + "/" + fi->fileName()) ) { QTranslator *trans = new QTranslator(qApp); QString fn = QPEApplication::qpeDir()+ "/i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+ ".qm"; if( trans->load( fn ) ) qApp->installTranslator( trans ); else delete trans; } } ++it; } } // used to find unique connection number int TheNSResources::assignConnectionNumber( void ) { bool found = 1; for( int trial = 0; ; trial ++ ) { found = 1; for( QDictIterator<NodeCollection> it(ConnectionsMap); it.current(); ++it ) { if( it.current()->number() == trial ) { found = 0; break; } } if( found ) { Log(("Assign profile number %d\n", trial )); return trial; } } } /** * Attempt to load a function and resolve a function. * @param pluginFileName - the name of the file in which to attempt to load * @param resolveString - function pointer to resolve * @return true of loading is successful */ bool TheNSResources::loadNetNode( const QString &pluginFileName, const QString &resolveString){ QLibrary *lib = new QLibrary(pluginFileName); void * res = lib->resolve(resolveString); if( ! res ){ delete lib; return 0; } GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; // Try to get an object. QList<ANetNode> PNN; getNetNodeList( PNN ); if( PNN.isEmpty() ) { delete lib; return 0; } ANetNode * NNP; for( QListIterator<ANetNode> it(PNN); it.current(); ++it ) { NetNode_t * NN; NNP = it.current(); NN = new NetNode_t; NN->NetNode = NNP; NN->TheLibrary = lib; NN->NodeCountInLib = PNN.count(); // store mapping AllNodeTypes.insert( NN->NetNode->name(), NN ); } return 1; } QPixmap TheNSResources::getPixmap( const QString & QS ) { QPixmap P; QString S("networksettings2/"); S += QS; - Log(("%s\n", S.latin1() )); P = Resource::loadPixmap( S ); + if( P.isNull() ) { + Log(( "Cannot load %s\n", S.latin1() )); + } return ( P.isNull() ) ? QPixmap() : P; } QString TheNSResources::tr( const char * s ) { return qApp->translate( "resource", s ); } const QString & TheNSResources::netNode2Name( const char * s ) { return NodeTypeNameMap[s]; } const QString & TheNSResources::netNode2Description( const char * s ) { return NodeTypeDescriptionMap[s]; } void TheNSResources::addConnection( NodeCollection * NC ) { ANetNodeInstance * NNI; ConnectionsMap.insert( NC->name(), NC ); // add (new) nodes to NodeList for( QListIterator<ANetNodeInstance> it(*NC); it.current(); ++it ) { NNI = it.current(); if( findNodeInstance( NNI->name() ) == 0 ) { // new item addNodeInstance( NNI ); } } } void TheNSResources::removeConnection( const QString & N ) { NodeCollection * NC = findConnection( N ); if( ! NC ) return; // delete netnodes in this connection ANetNodeInstance * NNI; for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { removeNodeInstance( NNI->name() ); } ConnectionsMap.remove( N ); } NodeCollection * TheNSResources::findConnection( const QString & S ) { return ConnectionsMap[ S ]; } +NodeCollection * TheNSResources::getConnection( int nr ) { + for( QDictIterator<NodeCollection> it(ConnectionsMap); + it.current(); + ++it ) { + if( it.current()->number() == nr ) { + return it.current(); + } + } + return 0; +} /* void TheNSResources::renumberConnections( void ) { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections NodeCollection::resetMaxNr(); for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); NC->setNumber( NC->maxConnectionNumber()+1 ); NC->setModified( 1 ); } } */ typedef struct EnvVars { char * Name; int Len; } EnvVar_t; #define AnEV(x) x, sizeof(x)-1 static EnvVar_t EV[] = { AnEV( "HOME" ), AnEV( "LOGNAME" ), AnEV( "USER" ), AnEV( "LD_LIBRARY_PATH" ), AnEV( "PATH" ), AnEV( "QTDIR" ), AnEV( "OPIEDIR" ), AnEV( "SHELL" ), { NULL, 0 } }; void TheNSResources::detectCurrentUser( void ) { // find current running qpe QString QPEEnvFile = ""; CurrentUser.UserName = ""; CurrentUser.HomeDir = ""; if( getenv( "OPIEDIR" ) == 0 ) { // nothing known { // open proc dir and find all dirs in it QRegExp R("[0-9]+"); QDir ProcDir( "/proc" ); QFileInfo FI; QStringList EL = ProcDir.entryList( QDir::Dirs ); // print it out for ( QStringList::Iterator it = EL.begin(); it != EL.end(); ++it ) { if( R.match( (*it) ) >= 0 ) { QString S = ProcDir.path()+"/"+ (*it); S.append( "/exe" ); FI.setFile( S ); // get the link S = FI.readLink(); if( S.right( 8 ) == "/bin/qpe" ) { // found running qpe QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); break; } } } } if( QPEEnvFile.isEmpty() ) { // could not find qpe Log(("Could not find qpe\n" )); return; } // FI now contains path ProcDir to the cmd dir { char * Buf = 0; char TB[1024]; long BufSize = 0; int fd; int rd; fd = open( QPEEnvFile.latin1(), O_RDONLY ); if( fd < 0 ) { Log(("Could not open %s : %d\n", QPEEnvFile.latin1(), errno )); return; } while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { Buf = (char *)realloc( Buf, BufSize+rd ); memcpy( Buf+BufSize, TB, rd ); BufSize += rd; } char * Data = Buf; char * DataEnd = Data+BufSize-1; // get env items out of list while( Data < DataEnd ) { EnvVar_t * Run = EV; while( Run->Name ) { if( strncmp( Data, Run->Name, Run->Len ) == 0 && Data[Run->Len] == '=' ) { CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( Data ); if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { // put OPIEDIR in env putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); } else if( strcmp( Run->Name, "HOME" ) == 0 ) { CurrentUser.HomeDir = Data+5; } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { CurrentUser.UserName = Data+8; } break; } Run ++; } Data += strlen( Data )+1; } free( Buf ); if( ! CurrentUser.UserName.isEmpty() ) { // find user info struct passwd pwd; struct passwd * pwdres; if( getpwnam_r( CurrentUser.UserName.latin1(), &pwd, TB, sizeof(TB), &pwdres ) || pwdres == 0 ) { Log(("Could not determine user %s : %d\n", CurrentUser.UserName.latin1(), errno )); return; } CurrentUser.Uid = pwd.pw_uid; CurrentUser.Gid = pwd.pw_gid; } else{ CurrentUser.Uid = CurrentUser.Gid = -1; } } } else { char * X; QString S; EnvVar_t * Run = EV; while( Run->Name ) { if( ( X = getenv( Run->Name ) ) ) { Log(( "Env : %s = %s\n", Run->Name, X )); S.sprintf( "%s=%s", Run->Name, X ); CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( S.latin1() ); if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { CurrentUser.UserName = X; } else if( strcmp( Run->Name, "HOME" ) == 0 ) { CurrentUser.HomeDir = X; } // regulare env var } else { Log(("Could not determine %s\n", Run->Name )); } Run ++; } CurrentUser.Uid = getuid(); CurrentUser.Gid = getgid(); } } diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 23b120e..634cd39 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -1,137 +1,143 @@ #ifndef __RESOURCES__H #define __RESOURCES__H #include <qstring.h> #include <qdict.h> #include <qmap.h> #include <qlist.h> #include "netnode.h" #include "systemfile.h" #include "system.h" class QLibrary; class QPixmap; class ANetNode; class ANetNodeInstance; typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); typedef struct NetNode_S { ANetNode * NetNode; QLibrary * TheLibrary; long NodeCountInLib; } NetNode_t; class CurrentQPEUser { public : CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} inline bool known( void ) { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } QString UserName; QString HomeDir; int Uid; int Gid; QArray<char *> EnvList; }; typedef QDict<NetNode_t> Name2NetNode_t; typedef QDict<ANetNodeInstance > Name2Instance_t; typedef QDict<NodeCollection> Name2Connection_t; typedef QDict<SystemFile> Name2SystemFile_t; class TheNSResources { public : TheNSResources( void ); ~TheNSResources( ); // give busy feedback void busy( bool B ); System & system() { return *TheSystem; } int assignConnectionNumber(void); QPixmap getPixmap( const QString & Name ); Name2NetNode_t & netNodes( void ) { return AllNodeTypes; } bool netNodeExists( const QString & X ) { return AllNodeTypes.find(X)!=0; } ANetNode * findNetNode( const QString & N ) { NetNode_t * NNT = AllNodeTypes.find(N); return (NNT) ? NNT->NetNode : 0; } + // define new plugin (=node) + void addNodeType( const QString & ID, + const QString & LongName, + const QString & Description ); + Name2SystemFile_t & systemFiles( void ) { return SystemFiles; } void addSystemFile( const QString & ID, const QString & P, bool KDI ); ANetNodeInstance * createNodeInstance( const QString & S ) { ANetNodeInstance * NNI = 0; NetNode_t * NNT = AllNodeTypes[S]; if( ! NNT ) { return 0; } NNI = NNT->NetNode->createInstance(); NNI->initialize(); return NNI; } Name2Instance_t & netNodeInstances( void ) { return AllNodes; } void addNodeInstance( ANetNodeInstance * I ) { AllNodes.insert( I->name(), I ); } void removeNodeInstance( const QString & N ) { AllNodes.remove( N );} ANetNodeInstance * findNodeInstance( const QString & S ) { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } const QString & netNode2Name( const char * Type ); const QString & netNode2Description( const char * Type ); void addConnection( NodeCollection * NC ); void removeConnection( const QString & N ); NodeCollection * findConnection( const QString & N ); + NodeCollection * getConnection( int nr ); Name2Connection_t & connections( void ) { return ConnectionsMap; } inline bool userKnown( void ) { return CurrentUser.known(); } CurrentQPEUser & currentUser( void ) { return CurrentUser; } private : void detectCurrentUser( void ); QString tr( const char * path ); void findAvailableNetNodes( const QString &path ); bool loadNetNode( const QString &pluginFileName, const QString &resolveString = "create_plugin"); QMap< QString, QString> NodeTypeNameMap; QMap< QString, QString> NodeTypeDescriptionMap; Name2Connection_t ConnectionsMap; System * TheSystem; Name2SystemFile_t SystemFiles; // all node type classes Name2NetNode_t AllNodeTypes; // all nodes Name2Instance_t AllNodes; CurrentQPEUser CurrentUser; }; extern TheNSResources * _NSResources; #define NSResources _NSResources #endif diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index 298bdc9..141484c 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -1,433 +1,573 @@ #include <sys/types.h> #include <sys/wait.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> +#include <opie2/oprocess.h> + #include <qdir.h> #include <qregexp.h> #include <qstringlist.h> #include <qfile.h> #include <qtextstream.h> #include <qapplication.h> #include "resources.h" #include "system.h" #define PROCNETDEV "/proc/net/dev" #ifndef ARPHRD_IEEE80211 #define ARPHRD_IEEE80211 801 #endif static char Dig2Hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; // get HIGH nibble of byte #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] // get LOW nibble of byte #define LN(x) Dig2Hex[((x)&0x0f)] System::System( void ) : QObject(), ProbedInterfaces() { probeInterfaces(); } System::~System( void ) { if( ProcDevNet ) delete ProcDevNet; } -int System::runAsRoot( const QString & S ) { - QString MyS = S; +int System::runAsRoot( QStringList & S ) { char * usr = getenv("USER"); - char ch; - if( S.isEmpty() ) { + if( S.count() == 0 ) { // loophole to start shell return 8888; } if( usr == 0 || strcmp( usr, "root" ) ) { // unknown or non-root user -> use SUDO - MyS.prepend( "sudo " ); + S.prepend( "sudo" ); } - Log(("Executing %s\n", MyS.latin1() )); + if( getenv( "NS2TESTMODE" ) ) { + owarn << "TESTMODE !!! execute " + << S.join( " ") + << oendl; + } else { + MyProcess * P = new MyProcess(); + emit processEvent( tr("Command : ") + S.join( " " ) ); + + P->process() << S; + + connect( P, + SIGNAL( stdoutLine( const QString & ) ), + this, + SIGNAL( stdoutLine( const QString & ) ) ); + + connect( P, + SIGNAL( stderrLine( const QString & ) ), + this, + SIGNAL( stderrLine( const QString & ) ) ); + + connect( P, + SIGNAL(processExited(MyProcess*) ), + this, SLOT + (SLOT_ProcessExited(MyProcess*) ) ); - emit lineFromCommand( tr("Command : ") + MyS ); - emit lineFromCommand( "---------------" ); - Log(( "Command : %s\n", MyS.latin1() ) ); - MyS += " 2>&1 "; - OutputOfCmd = popen( MyS.latin1(), "r" ) ; - if( ! OutputOfCmd ) { - // cannot fork + Log(("Executing %s\n", S.join( " " ).latin1() )); + + if( ! P->process().start( OProcess::DontCare, + OProcess::AllOutput ) ) { + owarn << "Error starting " << S << oendl; + delete P; + // error starting app return 1; } + owarn << "Started " << S << oendl; + } - // read all data - QString Line = ""; - while( 1 ) { - if( fread( &ch, 1, 1, OutputOfCmd ) < 1 ) - // eof - break; - if( ch == '\n' || ch == '\r' ) { - if( ! Line.isEmpty() ) { - Log(( "read cmd output : **%s**\n", Line.latin1() ) ); - emit lineFromCommand( Line ); - Line = ""; - qApp->processEvents(); + // all is fine + return 0; } - } else { - Line += ch; + +int System::execAsUser( QStringList & SL ) { + MyProcess * P = new MyProcess(); + CurrentQPEUser CU = NSResources->currentUser(); + char * usr = getenv("USER"); + + if( strcmp( usr, "root" ) == 0 ) { + // find user running qpe + if( CU.UserName.isEmpty() ) { + // if we come here, the exec was not successfull + Log(("User not known \n" )); + return 0; + } + } + + // now we are ready to exec the requested command + setuid( CU.Uid ); + setgid( CU.Gid ); + + for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { + QString X; + QStringList SL; + X = CU.EnvList[i]; + SL = QStringList::split( "=", X ); + P->process().setEnvironment( SL[0], SL[1] ); } + + P->process() << SL; + + emit processEvent( tr("Command : ") + SL.join( " " ) ); + + Log(("Executing as user %s : %s\n", + CU.UserName.latin1(), + SL.join( " " ).latin1() )); + + int rv = ( P->process().start( OProcess::DontCare, + OProcess::NoCommunication ) ); + delete P; + + if( rv ) { + // if we come here, the exec was not successfull + Log(("Could not exec : %d\n", errno )); } - if( ! Line.isEmpty() ) { - emit lineFromCommand( Line ); - Log(( "read cmd output : **%s**\n", Line.latin1() ) ); + return rv; } - Log(( "End of command\n", Line.latin1() ) ); - if( pclose( OutputOfCmd ) < 0 ) { - // error in command - return 3; +void System::SLOT_ProcessExited( MyProcess * P ) { + QString R; + + for( QValueListConstIterator<QCString> it = P->process().args().begin(); + it != P->process().args().end(); + ++it ) { + R += (*it); + R += " "; } - // all is fine - return 0; + R += "Returned with " + QString().setNum( P->process().exitStatus() ); + emit processEvent( R ); + delete P; } void System::refreshStatistics( InterfaceInfo & I ) { if( ! ProcDevNet ) { return; } // cannot seek on dev ProcDevNet->close(); ProcDevNet->open( IO_ReadOnly ); QString line; QTextStream procTs(ProcDevNet); QStringList SL; int loc = -1; int version; procTs.readLine(); line = procTs.readLine(); // get version if( line.find("compressed") ) version = 3; else if( line.find( "bytes" ) ) version = 2; else version = 1; while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { if( (loc = line.find(":") ) == -1) { continue; } if( I.Name != line.left(loc) ) continue; // tokenize SL = QStringList::split( ' ', line, FALSE ); // update data switch( version ) { case 1 : I.RcvBytes = SL[1]; I.RcvErrors = SL[3]; I.RcvDropped = SL[4]; I.SndBytes = SL[6]; I.SndErrors = SL[8]; I.SndDropped = SL[9]; I.Collisions = SL[11]; break; case 2 : I.RcvBytes = SL[1]; I.RcvErrors = SL[3]; I.RcvDropped = SL[4]; I.SndBytes = SL[7]; I.SndErrors = SL[9]; I.SndDropped = SL[10]; I.Collisions = SL[12]; break; case 3 : I.RcvBytes = SL[1]; I.RcvErrors = SL[3]; I.RcvDropped = SL[4]; I.SndBytes = SL[9]; I.SndErrors = SL[11]; I.SndDropped = SL[12]; I.Collisions = SL[14]; break; } break; } } // // THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT // FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT // void System::probeInterfaces( void ) { // probe interfaces int sockfd; // get list of all interfaces struct ifreq ifrs; InterfaceInfo * IFI; // flag all as 'down' for( QDictIterator<InterfaceInfo> it( ProbedInterfaces ); it.current(); ++it ) { it.current()->IsUp = 0; } sockfd = socket(PF_INET, SOCK_DGRAM, 0); - if(sockfd == -1) + if(sockfd == -1) { + owarn << "Cannot open INET socket " + << errno + << " " + << strerror( errno ) + << oendl; return; + } // read interfaces from /proc/dev/net // SIOCGIFCONF does not return ALL interfaces ???!? ProcDevNet = new QFile(PROCNETDEV); if( ! ProcDevNet->open(IO_ReadOnly) ) { + owarn << "Cannot open " + << PROCNETDEV + << " " + << errno + << " " + << strerror( errno ) + << oendl; delete ProcDevNet; ProcDevNet =0; + ::close( sockfd ); return; } QString line; QString NicName; QTextStream procTs(ProcDevNet); int loc = -1; procTs.readLine(); // eat a line procTs.readLine(); // eat a line while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { if((loc = line.find(":")) == -1) { continue; } NicName = line.left(loc); // set name for ioctl strcpy( ifrs.ifr_name, NicName.latin1() ); if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) { // new nic - Log(("NEWNIC %s\n", NicName.latin1())); + Log(("New NIC found : %s\n", NicName.latin1())); IFI = new InterfaceInfo; IFI->Name = line.left(loc); - IFI->NetNode = 0; + IFI->Collection = 0; ProbedInterfaces.insert( IFI->Name, IFI ); // get dynamic info if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT); } else { IFI->IsPointToPoint = 0; } // settings that never change IFI->DstAddress = ""; if( IFI->IsPointToPoint ) { if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) { IFI->DstAddress = inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr); } } IFI->CardType = 999999; IFI->MACAddress = ""; if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) { - Log(("%s = %d\n", IFI->Name.latin1(), + Log(("Family for NIC %s : %d\n", IFI->Name.latin1(), ifrs.ifr_hwaddr.sa_family )); IFI->CardType = ifrs.ifr_hwaddr.sa_family; switch( ifrs.ifr_hwaddr.sa_family ) { case ARPHRD_ETHER : // regular MAC address // valid address -> convert to regular ::: format // length = 6 bytes = 12 DIGITS -> 6 : IFI->MACAddress.sprintf( "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", HN( ifrs.ifr_hwaddr.sa_data[0] ), LN( ifrs.ifr_hwaddr.sa_data[0] ), HN( ifrs.ifr_hwaddr.sa_data[1] ), LN( ifrs.ifr_hwaddr.sa_data[1] ), HN( ifrs.ifr_hwaddr.sa_data[2] ), LN( ifrs.ifr_hwaddr.sa_data[2] ), HN( ifrs.ifr_hwaddr.sa_data[3] ), LN( ifrs.ifr_hwaddr.sa_data[3] ), HN( ifrs.ifr_hwaddr.sa_data[4] ), LN( ifrs.ifr_hwaddr.sa_data[4] ), HN( ifrs.ifr_hwaddr.sa_data[5] ), LN( ifrs.ifr_hwaddr.sa_data[5] ) ); break; #ifdef ARPHRD_IEEE1394 case ARPHRD_IEEE1394 : // Firewire Eth address IFI->MACAddress.sprintf( "%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-00-00", HN( ifrs.ifr_hwaddr.sa_data[0] ), LN( ifrs.ifr_hwaddr.sa_data[0] ), HN( ifrs.ifr_hwaddr.sa_data[1] ), LN( ifrs.ifr_hwaddr.sa_data[1] ), HN( ifrs.ifr_hwaddr.sa_data[2] ), LN( ifrs.ifr_hwaddr.sa_data[2] ), HN( ifrs.ifr_hwaddr.sa_data[3] ), LN( ifrs.ifr_hwaddr.sa_data[3] ), HN( ifrs.ifr_hwaddr.sa_data[4] ), LN( ifrs.ifr_hwaddr.sa_data[4] ), HN( ifrs.ifr_hwaddr.sa_data[5] ), LN( ifrs.ifr_hwaddr.sa_data[5] ), HN( ifrs.ifr_hwaddr.sa_data[6] ), LN( ifrs.ifr_hwaddr.sa_data[6] ), HN( ifrs.ifr_hwaddr.sa_data[7] ), LN( ifrs.ifr_hwaddr.sa_data[7] ), HN( ifrs.ifr_hwaddr.sa_data[8] ), LN( ifrs.ifr_hwaddr.sa_data[8] ), HN( ifrs.ifr_hwaddr.sa_data[9] ), LN( ifrs.ifr_hwaddr.sa_data[9] ), HN( ifrs.ifr_hwaddr.sa_data[10] ), LN( ifrs.ifr_hwaddr.sa_data[10] ), HN( ifrs.ifr_hwaddr.sa_data[11] ), LN( ifrs.ifr_hwaddr.sa_data[11] ), HN( ifrs.ifr_hwaddr.sa_data[12] ), LN( ifrs.ifr_hwaddr.sa_data[12] ), HN( ifrs.ifr_hwaddr.sa_data[13] ), LN( ifrs.ifr_hwaddr.sa_data[13] ) ); break; #endif case ARPHRD_PPP : // PPP break; case ARPHRD_IEEE80211 : // WLAN break; case ARPHRD_IRDA : // IRDA break; } } } else // else already probed before -> just update - Log(("OLDNIC %s\n", NicName.latin1())); + Log(("Redetected NIC %s\n", NicName.latin1())); // get dynamic info if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) { IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP); IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST); } else { IFI->IsUp = 0; IFI->HasMulticast = 0; } if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) { IFI->Address = inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr); } else { IFI->Address = ""; IFI->IsUp = 0; } if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) { IFI->BCastAddress = inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr); } else { IFI->BCastAddress = ""; } if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) { IFI->Netmask = inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr); } else { IFI->Netmask = ""; } - Log(("NIC %s UP %d\n", NicName.latin1(), IFI->IsUp )); + Log(("NIC %s UP ? %d\n", NicName.latin1(), IFI->IsUp )); } -} - -void System::execAsUser( QString & Cmd, char * argv[] ) { - CurrentQPEUser CU = NSResources->currentUser(); - if( CU.UserName.isEmpty() ) { - // if we come here, the exec was not successfull - Log(("User not known \n" )); - return; + ::close( sockfd ); } - // now we are ready to exec the requested command - setuid( CU.Uid ); - setgid( CU.Gid ); - - char ** envp = (char **)alloca( sizeof( char *) * - (CU.EnvList.count()+1) ); - - for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) { - *(envp+i) = CU.EnvList[i]; +InterfaceInfo * System::findInterface( const QString & N ) { + InterfaceInfo * Run; + // has PAN connection UP interface ? + for( QDictIterator<InterfaceInfo> It(ProbedInterfaces); + It.current(); + ++It ) { + Run = It.current(); + if( N == Run->Name ) { + // this PAN connection is up + return Run; } - envp[CU.EnvList.count()]=NULL; - - execve( Cmd.latin1(), argv, envp ); - - // if we come here, the exec was not successfull - Log(("Could not exec : %d\n", errno )); + } + return 0; } #include <stdarg.h> static FILE * logf = 0; void VLog( char * Format, ... ) { va_list l; va_start(l, Format ); if( logf == (FILE *)0 ) { - if( getenv("NS2STDERR") ) { + QString S = getenv("NS2LOG"); + if( S == "stderr" ) { logf = stderr; - } else { + } else if( S.isEmpty() ) { logf = fopen( "/tmp/ns2log", "a" ); + } else { + logf = fopen( S, "a" ); } + if( ! logf ) { - fprintf( stderr, "Cannot open logfile /tmp/ns2log %d\n", - errno ); + fprintf( stderr, "Cannot open logfile %s : %d\n", + S.latin1(), errno ); logf = (FILE *)1; } else { fprintf( logf, "____ OPEN LOGFILE ____\n"); } } - if( (long)logf > 1 ) { + if( (unsigned long)logf > 1 ) { vfprintf( logf, Format, l ); } va_end( l ); + fflush( logf ); } void LogClose( void ) { if( (long)logf > 1 ) { fprintf( logf, "____ CLOSE LOGFILE ____\n"); if( logf != stderr ) { fclose( logf ); } logf = 0; } } QString removeSpaces( const QString & X ) { - QStringList SL; + QString Y; + Y = X.simplifyWhiteSpace(); + Y.replace( QRegExp(" "), "_" ); + owarn << X << " **" << Y << "**" << oendl; + return Y; +} + +// +// +// +// +// + +MyProcess::MyProcess() : QObject(), StdoutBuffer(), StderrBuffer() { + P = new OProcess(); + connect( P, + SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int ) ), + this, + SLOT( SLOT_Stdout(Opie::Core::OProcess*,char*,int) ) ); + + connect( P, + SIGNAL( receivedStderr(Opie::Core::OProcess*, char*, int ) ), + this, + SLOT( SLOT_Stderr(Opie::Core::OProcess*,char*,int) ) ); + connect( P, + SIGNAL( processExited(Opie::Core::OProcess*) ), + this, + SLOT( SLOT_ProcessExited(Opie::Core::OProcess*) ) ); +} + +MyProcess::~MyProcess() { + delete P; +} + +void MyProcess::SLOT_Stdout( Opie::Core::OProcess * , char * Buf, int len ) { + char * LB = (char *)alloca( len + 1 ); + memcpy( LB, Buf, len ); + LB[len] = '\0'; + + // now input is zero terminated + StdoutBuffer += LB; + + owarn << "Received " << len << " bytes on stdout" << oendl; + // see if we have some lines (allow empty lines) + QStringList SL = QStringList::split( "\n", StdoutBuffer, TRUE ); + + for( unsigned int i = 0; i < SL.count()-1; i ++ ) { + Log(( "Stdout : \"%s\"\n", SL[i].latin1() ) ); + emit stdoutLine( SL[i] ); + } + + // last line is rest + StdoutBuffer = SL[ SL.count()-1 ]; +} + +void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) { + char * LB = (char *)alloca( len + 1 ); + memcpy( LB, Buf, len ); + LB[len] = '\0'; + + // now input is zero terminated + StderrBuffer += LB; + + owarn << "Received " << len << " bytes on stderr" << oendl; + // see if we have some lines (allow empty lines) + QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE ); + + for( unsigned int i = 0; i < SL.count()-1; i ++ ) { + Log(( "Stderr : \"%s\"\n", SL[i].latin1() ) ); + emit stderrLine( SL[i] ); + } + + // last line is rest + StderrBuffer = SL[ SL.count()-1 ]; +} - SL = QStringList::split( " ", X ); - return SL.join( "_" ); +void MyProcess::SLOT_ProcessExited( Opie::Core::OProcess * ) { + emit processExited( this ); } diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h index 33af391..e67d695 100644 --- a/noncore/settings/networksettings2/networksettings2/system.h +++ b/noncore/settings/networksettings2/networksettings2/system.h @@ -1,90 +1,135 @@ #ifndef __SYSTEM__H #define __SYSTEM__H +#include <qstring.h> + +#include <opie2/oprocess.h> + +using namespace Opie::Core; + // for hardware types #include <net/if_arp.h> #include <qdict.h> #include <qobject.h> #include <stdio.h> +class NodeCollection; class ANetNodeInstance; class QFile; +class MyProcess : public QObject { + + Q_OBJECT + +public : + + MyProcess(); + ~MyProcess(); + + inline OProcess & process() + { return *P; } + +public slots : + + void SLOT_Stdout( Opie::Core::OProcess * P, char *, int ); + void SLOT_Stderr( Opie::Core::OProcess * P, char *, int ); + void SLOT_ProcessExited( Opie::Core::OProcess * P); + +signals : + + void stdoutLine( const QString & ); + void stderrLine( const QString & ); + void processExited( MyProcess * ); + +private : + + QString StdoutBuffer; + QString StderrBuffer; + OProcess * P; +}; + class InterfaceInfo { public : InterfaceInfo() : Name(), MACAddress(), BCastAddress(), Netmask(), DstAddress() { } - ANetNodeInstance * assignedNode() - { return NetNode; } + NodeCollection * assignedConnection() + { return Collection; } - void assignNode( ANetNodeInstance * NNI ) - { NetNode = NNI; } + void assignConnection( NodeCollection * NNI ) + { Collection = NNI; } - ANetNodeInstance * NetNode; // netnode taking care of me + NodeCollection * Collection; // connection taking care of me QString Name; // name of interface int CardType; // type of card QString MACAddress; // MAC address QString Address; // IP Address QString BCastAddress; // Broadcast Address QString Netmask; // Netmask QString DstAddress; // Peer address (if P-t-P) bool IsUp; // interface is UP bool HasMulticast; // Supports Multicast bool IsPointToPoint; // IsPointToPoint card QString RcvBytes; QString SndBytes; QString RcvErrors; QString SndErrors; QString RcvDropped; QString SndDropped; QString Collisions; }; class System : public QObject { Q_OBJECT public : System( void ); ~System( void ); QDict<InterfaceInfo> & interfaces( void ) { return ProbedInterfaces; } InterfaceInfo * interface( const QString& N ) { return ProbedInterfaces[N]; } // exec command as root - int runAsRoot( const QString & S ); + int runAsRoot( QStringList & S ); // exec command as user - void execAsUser( QString & Cmd, char * argv[] ); + int execAsUser( QStringList & Cmd ); // refresh stats for this interface void refreshStatistics( InterfaceInfo & ); // reloads interfaces void probeInterfaces( void ); + InterfaceInfo * findInterface( const QString & DevName ); + +private slots : + + void SLOT_ProcessExited( MyProcess * ); + signals : - void lineFromCommand( const QString & S ); + void stdoutLine( const QString & ); + void stderrLine( const QString & ); + void processEvent( const QString & ); private : QDict<InterfaceInfo> ProbedInterfaces; FILE * OutputOfCmd; QFile * ProcDevNet; - }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp index 2b40834..82fd43a 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.cpp +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp @@ -1,189 +1,235 @@ #include <stdio.h> #include <qpe/qpeapplication.h> #include <qfileinfo.h> #include <qmessagebox.h> #include <qfile.h> #include <qtextstream.h> #include "resources.h" #include "systemfile.h" #define TEMPLATEDIR "networktemplates/" QString TemplDir; SystemFile::SystemFile( const QString & N, const QString & P, bool KDI ){ Name = N; Path = P; + InAppend = 0; F = 0; // get template info { QString S; QFileInfo FI; // find location of templates TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR; FI.setFile( TemplDir ); if( ! FI.isDir() ) { // try current dir TemplDir = "./" TEMPLATEDIR; FI.setFile( TemplDir ); if( ! FI.isDir() ) { hasPreSection = hasPostSection = hasPreNodeSection = hasPostNodeSection = hasPreDeviceSection = hasPostDeviceSection = 0; return; } } // have found location S = TemplDir + Name + "/presection"; FI.setFile( S ); hasPreSection = ( FI.exists() && FI.isReadable() ); S = TemplDir + Name + "/postsection"; FI.setFile( S ); hasPostSection = ( FI.exists() && FI.isReadable() ); S = TemplDir + Name + "/prenodesection"; FI.setFile( S ); hasPreNodeSection = ( FI.exists() && FI.isReadable() ); S = TemplDir + Name + "/postnodesection"; FI.setFile( S ); hasPostNodeSection = ( FI.exists() && FI.isReadable() ); S = TemplDir + Name + "/predevicesection"; FI.setFile( S ); hasPreDeviceSection = ( FI.exists() && FI.isReadable() ); S = TemplDir + Name + "/postdevicesection"; FI.setFile( S ); hasPostDeviceSection = ( FI.exists() && FI.isReadable() ); } KnowsDeviceInstances = KDI; } +SystemFile::SystemFile( const QString & N, bool KDI ){ + Name = N; + Path = ""; + InAppend = 0; + F =0; + KnowsDeviceInstances = KDI; + hasPreSection = + hasPostSection = + hasPreNodeSection = + hasPostNodeSection = + hasPreDeviceSection = + hasPostDeviceSection = 0; +} + SystemFile::~SystemFile( void ) { - if( F ) - delete F; + close(); } bool SystemFile::open( void ) { + QString Prefix = getenv( "NS2OUTPUTTO" ); + + if( Prefix != "stderr" /* && Name != "interfaces" */ ) { + // generate files where the need to be if( F ) { F->close(); delete F; } - F = new QFile( Path + "bup" ); - if( ! F->open( IO_WriteOnly ) ) { + F = new QFile( Prefix + Path + ((InAppend)?"":"bup") ); + Log(( "Open systemfile %s\n", F->name().latin1() )); + if( ! F->open( ((InAppend)?IO_Append : 0 ) | IO_WriteOnly ) ) { return 0; } + } else { + if( ! F ) { + owarn << "!!!!!!!!!!!!!!!!!! " << oendl; + owarn << "!!!! TESTMODE !!!!" << oendl; + owarn << "!!!!!!!!!!!!!!!!!! " << oendl; + owarn << "!!!!" << oendl; + owarn << "!!!! GENERATE " << Path << oendl; + if( InAppend ) { + owarn << "!!!! In APPEND mode" << oendl; + } + owarn << "!!!!" << oendl; + owarn << "!!!!!!!!!!!!!!!!!!" << oendl; + + F = new QFile(); + F->open( IO_WriteOnly, stderr ); + } + } setDevice( F ); return 1; } bool SystemFile::close( void ) { - if( ! F ) { + if( ! F || ! F->isOpen() ) { return 1 ; } - QString OldP = Path + "bup"; + QString Prefix = getenv( "NS2OUTPUTTO" ); + + if( Prefix == "stderr" ) { + return 1; + } + + QString OldP = Prefix + Path + "bup"; F->close(); delete F; F = 0; + if( ! InAppend ) { + owarn << "Rename " << OldP << " to " << Path << oendl; return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); } + return 1; +} bool SystemFile::preSection( void ) { if( hasPreSection ) { QFile Fl( TemplDir + Name + "/presection" ); if( ! Fl.open( IO_ReadOnly ) ) return 0; // error // copy file to this file F->writeBlock( Fl.readAll() ); } return 1; } bool SystemFile::postSection( void ) { if( hasPostSection ) { QFile Fl( TemplDir + Name + "/postsection" ); if( ! Fl.open( IO_ReadOnly ) ) return 0; // error // copy file to this file F->writeBlock( Fl.readAll() ); } return 1; } bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { if( hasPreNodeSection ) { QFile Fl( TemplDir + Name + "/prenodesection" ); if( ! Fl.open( IO_ReadOnly ) ) return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S. arg(NNI->nodeClass()->name()); (*this) << Out << endl; S = TX.readLine(); } } return 1; } bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) { if( hasPostNodeSection ) { QFile Fl( TemplDir + Name + "/postnodesection" ); if( ! Fl.open( IO_ReadOnly ) ) return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S. arg(NNI->name()); (*this) << Out << endl; S = TX.readLine(); } } return 1; } bool SystemFile::preDeviceSection( ANetNode * NN ) { if( hasPreDeviceSection ) { QFile Fl( TemplDir + Name + "/predevicesection" ); if( ! Fl.open( IO_ReadOnly ) ) return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S.arg(NN->name()); (*this) << Out << endl; S = TX.readLine(); } } return 1; } bool SystemFile::postDeviceSection( ANetNode * NN ) { if( hasPostDeviceSection ) { QFile Fl( TemplDir + Name + "/postdevicesection" ); if( ! Fl.open( IO_ReadOnly ) ) return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S.arg(NN->name()); (*this) << Out << endl; S = TX.readLine(); } } return 1; } diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.h b/noncore/settings/networksettings2/networksettings2/systemfile.h index ceed605..a950c4d 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.h +++ b/noncore/settings/networksettings2/networksettings2/systemfile.h @@ -1,50 +1,61 @@ #ifndef __SYSTEMFILE__H #define __SYSTEMFILE__H #include <qstring.h> #include <qtextstream.h> class QFile; class ANetNodeInstance; class SystemFile : public QTextStream { public : SystemFile( const QString & Name, const QString & Path, bool KnowsDevicesInstances ); + SystemFile( const QString & Name, + bool KnowsDevicesInstances = 0 ); ~SystemFile( void ); + void setName( const QString & S ) + { Name = S; } const QString & name( void ) const { return Name; } + + void setPath( const QString & S ) + { Path = S; } const QString & path( void ) const { return Path; } + bool knowsDeviceInstances( void ) const { return KnowsDeviceInstances; } + void setAppendMode( bool A) + { InAppend = A; }; bool open( void ); bool close( void ); bool preSection( void ); bool postSection( void ); bool preNodeSection( ANetNodeInstance * NNI, long DevNr ); bool postNodeSection( ANetNodeInstance * NNI, long DevNr ); bool preDeviceSection( ANetNode * NN ); bool postDeviceSection( ANetNode * NN ); private : QString Name; QString Path; QFile * F; bool hasPreSection; bool hasPostSection; bool hasPreNodeSection; bool hasPostNodeSection; bool hasPreDeviceSection; bool hasPostDeviceSection; bool KnowsDeviceInstances; + bool InAppend; }; #endif diff --git a/noncore/settings/networksettings2/networksettingsGUI.ui b/noncore/settings/networksettings2/networksettingsGUI.ui index 6ed29f3..1085e08 100644 --- a/noncore/settings/networksettings2/networksettingsGUI.ui +++ b/noncore/settings/networksettings2/networksettingsGUI.ui @@ -1,572 +1,534 @@ <!DOCTYPE UI><UI> <class>NetworkSettingsGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>NetworkSettingsGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>144</width> - <height>260</height> + <width>383</width> + <height>359</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Network Settings</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>2</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QFrame</class> <property stdset="1"> <name>name</name> <cstring>Frame4</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>frameShape</name> <enum>NoFrame</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Raised</enum> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>1</number> + <number>0</number> </property> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>Add_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>Delete_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>CheckState_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>GenConfig_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer1</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>Enable_TB</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>0</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> + <cstring>Disable_TB</cstring> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>On_TB</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>0</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> + <cstring>Down_TB</cstring> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> <property stdset="1"> <name>toggleButton</name> - <bool>true</bool> + <bool>false</bool> </property> <property stdset="1"> <name>toggleButton</name> - <bool>true</bool> + <bool>false</bool> </property> </widget> <widget> - <class>QToolButton</class> + <class>QFrame</class> <property stdset="1"> <name>name</name> - <cstring>Connect_TB</cstring> + <cstring>LED_Frm</cstring> </property> <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>0</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> - </property> - <property stdset="1"> - <name>text</name> - <string>...</string> - </property> - <property stdset="1"> - <name>toggleButton</name> - <bool>true</bool> + <name>frameShape</name> + <enum>NoFrame</enum> </property> <property stdset="1"> - <name>toggleButton</name> - <bool>true</bool> + <name>frameShadow</name> + <enum>Raised</enum> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>Disconnect_TB</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>0</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> + <cstring>Up_TB</cstring> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> <property stdset="1"> <name>toggleButton</name> - <bool>true</bool> + <bool>false</bool> </property> <property stdset="1"> <name>toggleButton</name> - <bool>true</bool> + <bool>false</bool> </property> </widget> </hbox> </widget> <widget> <class>QListBox</class> <property stdset="1"> <name>name</name> <cstring>Profiles_LB</cstring> </property> </widget> <widget> <class>QGroupBox</class> <property stdset="1"> <name>name</name> <cstring>Profile_GB</cstring> </property> <property stdset="1"> <name>title</name> <string>Profile</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>4</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>Description_LBL</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>5</hsizetype> <vsizetype>7</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>frameShape</name> <enum>NoFrame</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Raised</enum> </property> <property stdset="1"> <name>text</name> <string></string> </property> <property stdset="1"> <name>alignment</name> <set>AlignTop|AlignLeft</set> </property> <property> <name>vAlign</name> </property> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout4</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <spacer> <property> <name>name</name> <cstring>Spacer4</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>ToMessages_BUT</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>1</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>Messages ...</string> </property> </widget> </hbox> </widget> </vbox> </widget> <widget> <class>QGroupBox</class> <property stdset="1"> <name>name</name> <cstring>Messages_GB</cstring> </property> <property stdset="1"> <name>title</name> <string>Messages</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>4</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QListBox</class> <property stdset="1"> <name>name</name> <cstring>Messages_LB</cstring> </property> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout2</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <spacer> <property> <name>name</name> <cstring>Spacer3</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>ToProfile_BUT</cstring> </property> <property stdset="1"> <name>text</name> <string>Profile ...</string> </property> </widget> </hbox> </widget> </vbox> </widget> </vbox> </widget> <connections> <connection> - <sender>Add_TB</sender> - <signal>clicked()</signal> - <receiver>NetworkSettingsGUI</receiver> - <slot>SLOT_AddNode()</slot> - </connection> - <connection> <sender>Delete_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_DeleteNode()</slot> </connection> <connection> <sender>CheckState_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_CheckState()</slot> </connection> <connection> - <sender>Enable_TB</sender> - <signal>clicked()</signal> - <receiver>NetworkSettingsGUI</receiver> - <slot>SLOT_Enable()</slot> - </connection> - <connection> - <sender>Connect_TB</sender> - <signal>clicked()</signal> - <receiver>NetworkSettingsGUI</receiver> - <slot>SLOT_Connect()</slot> - </connection> - <connection> - <sender>On_TB</sender> - <signal>clicked()</signal> - <receiver>NetworkSettingsGUI</receiver> - <slot>SLOT_On()</slot> - </connection> - <connection> <sender>GenConfig_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_GenerateConfig()</slot> </connection> <connection> <sender>Profiles_LB</sender> <signal>clicked(QListBoxItem*)</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ShowNode( QListBoxItem*)</slot> </connection> <connection> <sender>Profiles_LB</sender> <signal>currentChanged(QListBoxItem*)</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ShowNode( QListBoxItem*)</slot> </connection> <connection> <sender>Profiles_LB</sender> <signal>doubleClicked(QListBoxItem*)</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_EditNode( QListBoxItem *)</slot> </connection> <connection> <sender>ToProfile_BUT</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ToProfile()</slot> </connection> <connection> <sender>ToMessages_BUT</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ToMessages()</slot> </connection> <connection> - <sender>Disconnect_TB</sender> + <sender>Add_TB</sender> + <signal>clicked()</signal> + <receiver>NetworkSettingsGUI</receiver> + <slot>SLOT_AddNode()</slot> + </connection> + <connection> + <sender>Disable_TB</sender> + <signal>toggled(bool)</signal> + <receiver>NetworkSettingsGUI</receiver> + <slot>SLOT_Disable(bool)</slot> + </connection> + <connection> + <sender>Down_TB</sender> + <signal>clicked()</signal> + <receiver>NetworkSettingsGUI</receiver> + <slot>SLOT_Down()</slot> + </connection> + <connection> + <sender>Up_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> - <slot>SLOT_Disconnect()</slot> + <slot>SLOT_Up()</slot> </connection> <slot access="public">SLOT_AddNode()</slot> <slot access="public">SLOT_CheckState()</slot> - <slot access="public">SLOT_Connect()</slot> <slot access="public">SLOT_DeleteNode()</slot> + <slot access="public">SLOT_Disable(bool)</slot> <slot access="public">SLOT_EditNode( QListBoxItem *)</slot> - <slot access="public">SLOT_Enable()</slot> <slot access="public">SLOT_GenerateConfig()</slot> - <slot access="public">SLOT_On()</slot> + <slot access="public">SLOT_SetState(int)</slot> <slot access="public">SLOT_ShowNode( QListBoxItem*)</slot> <slot access="public">SLOT_ToMessages()</slot> <slot access="public">SLOT_ToProfile()</slot> - <slot access="public">SLOT_Disconnect()</slot> + <slot access="public">SLOT_Up()</slot> + <slot access="public">SLOT_Down()</slot> </connections> </UI> diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index e2dd5b5..698a941 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -1,603 +1,725 @@ #include <stdlib.h> +#include <opie2/odebug.h> #include <qpe/qpeapplication.h> #include <qtextstream.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include "nsdata.h" -#include <asdevice.h> +#include <netnode.h> #include <resources.h> static QString CfgFile; NetworkSettingsData::NetworkSettingsData( void ) { // init global resources structure new TheNSResources(); if( ! NSResources->userKnown() ) { Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", NSResources->currentUser().HomeDir.latin1(), NSResources->currentUser().UserName.latin1() )); return; } CfgFile.sprintf( "%s/Settings/NS2.conf", NSResources->currentUser().HomeDir.latin1() ); Log(( "Cfg from %s\n", CfgFile.latin1() )); // load settings - IsModified = 0; loadSettings(); + + // assign interfaces by scanning /tmp/profile-%s.Up files + { QDir D( "/tmp" ); + QFile * F = new QFile; + int profilenr; + QString interfacename; + QTextStream TS ( F ); + + QStringList SL = D.entryList( "profile-*.up"); + + Log(( "System reports %d interfaces. Found %d up\n", + NSResources->system().interfaces().count(), + SL.count() )); + + for ( QStringList::Iterator it = SL.begin(); + it != SL.end(); + ++it ) { + profilenr = atol( (*it).mid( 8 ).latin1() ); + // read the interface store int 'up' + F->setName( D.path() + "/" + (*it) ); + if( F->open( IO_ReadOnly ) ) { + NodeCollection * NC; + interfacename = TS.readLine(); + F->close(); + + Log(( "Assign interface %s to Profile nr %d\n", + interfacename.latin1(), profilenr )); + + NC = NSResources->getConnection( profilenr ); + if( NC ) { + NC->assignInterface( + NSResources->system().findInterface( interfacename ) ); + } else { + Log(( "Profile nr %d no longer defined\n", + profilenr )); + } + } + } + } } // saving is done by caller NetworkSettingsData::~NetworkSettingsData( void ) { delete NSResources; } void NetworkSettingsData::loadSettings( void ) { QString Line, S; QString Attr, Value; long idx; QFile F( CfgFile ); QTextStream TS( &F ); + ForceModified = 0; + do { if( ! F.open(IO_ReadOnly) ) break; /* load the file -> FORMAT : [NETNODETYPE] Entries ... <EMPTYLINE> [connection] Name=Name Node=Name <EMPTYLINE> */ while( ! TS.atEnd() ) { S = Line = TS.readLine(); if ( S.isEmpty() || S[0] != '[' ) continue; S = S.mid( 1, S.length()-2 ); if( ! NSResources ) { continue; } if( S == "connection" ) { // load connections -> collections of nodes NodeCollection * NC = new NodeCollection( TS ); NSResources->addConnection( NC ); } else { ANetNode * NN = 0; ANetNodeInstance* NNI = 0; if( S.startsWith( "nodetype " ) ) { S = S.mid( 9, S.length()-9 ); S = deQuote(S); // try to find netnode NN = NSResources->findNetNode( S ); - Log( ( "Node %s : %p\n", S.latin1(), NN ) ); } else { // try to find instance NNI = NSResources->createNodeInstance( S ); - Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); } if( NN == 0 && NNI == 0 ) { LeftOvers.append( Line ); } do { S = Line = TS.readLine(); if( NN || NNI ) { if( S.isEmpty() ) { // empty line break; } idx = S.find( '=' ); if( idx > 0 ) { Attr = S.left( idx ); Value = S.mid( idx+1, S.length() ); } else { Value=""; Attr = S; } Value.stripWhiteSpace(); Attr.stripWhiteSpace(); Attr.lower(); // dequote Attr Value = deQuote(Value); if( NN ) { // set the attribute NN->setAttribute( Attr, Value ); } else { // set the attribute NNI->setAttribute( Attr, Value ); } } else { LeftOvers.append( Line ); // add empty line too as delimiter if( S.isEmpty() ) { // empty line break; } } } while( 1 ); if( NNI ) { // loading from file -> exists + Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); NNI->setNew( FALSE ); NSResources->addNodeInstance( NNI ); } + if( NN ) { + Log( ( "Node %s : %p\n", NN->name(), NN ) ); + } } } } while( 0 ); } QString NetworkSettingsData::saveSettings( void ) { QString ErrS = ""; if( ! isModified() ) return ErrS; QString S; QFile F( CfgFile + ".bup" ); Log( ( "Saving settings to %s\n", CfgFile.latin1() )); if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { ErrS = qApp->translate( "NetworkSettings", "<p>Could not save setup to \"%1\" !</p>" ). arg(CfgFile); // problem return ErrS; } QTextStream TS( &F ); // save leftovers for ( QStringList::Iterator it = LeftOvers.begin(); it != LeftOvers.end(); ++it ) { TS << (*it) << endl; } // save global configs for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); it.current(); ++it ) { TS << "[nodetype " << quote( QString( it.current()->NetNode->name() ) ) << "]" << endl; it.current()->NetNode->saveAttributes( TS ); TS << endl; } { Name2Connection_t & M = NSResources->connections(); ANetNodeInstance * NNI; // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { // all nodes in those connections for( QListIterator<ANetNodeInstance> nit(*(it.current())); nit.current(); ++nit ) { // header NNI = nit.current(); TS << '[' << QString(NNI->nodeClass()->name()) << ']' << endl; NNI->saveAttributes( TS ); TS << endl; } TS << "[connection]" << endl; it.current()->save(TS); } } QDir D("."); D.rename( CfgFile + ".bup", CfgFile ); // // proper files AND system files regenerated // - setModified( 0 ); + + for( QDictIterator<NodeCollection> it(NSResources->connections()); + it.current(); + ++it ) { + it.current()->setModified( 0 ); + } + return ErrS; } QString NetworkSettingsData::generateSettings( void ) { QString S = ""; Name2SystemFile_t & SFM = NSResources->systemFiles(); Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; ANetNodeInstance * NNI; ANetNodeInstance * FirstWithData; - SystemFile * SF; - AsDevice * CurDev; + RuntimeInfo * CurDev; ANetNode * NN, * CurDevNN = 0; long NoOfDevs; long DevCtStart; bool needToGenerate; // regenerate system files Log( ( "Generating settings from %s\n", CfgFile.latin1() )); - // - // generate files proper to each netnodeinstance - // - { Name2Instance_t & NNIs = NSResources->netNodeInstances(); - - for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); - NNIIt.current(); - ++NNIIt ) { - // for all nodes find those that are modified - NNI = NNIIt.current(); + for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + nnit.current(); + ++nnit ) { + { QStringList SL; + bool FirstItem = 1; + bool Generated = 0; - { // get list of proper files for this nodeclass (if any) - QStringList * PF = NNI->nodeClass()->properFiles(); + CurDevNN = nnit.current()->NetNode; + SL = CurDevNN->properFiles(); - if( PF ) { - for ( QStringList::Iterator it = PF->begin(); - it != PF->end(); + for ( QStringList::Iterator it = SL.begin(); + it != SL.end(); ++it ) { - QFile * F = NNI->openFile( (*it) ); - if( F ) { - QTextStream TS( F ); - if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { - // problem generating + + Generated = 0; + FirstItem = 1; + // iterate over NNI's of this class + for( QDictIterator<ANetNodeInstance> nniit( + NSResources->netNodeInstances() ); + nniit.current(); + ++nniit ) { + if( nniit.current()->nodeClass() != CurDevNN ) + // different class + continue; + + // open proper file + { SystemFile SF( (*it) ); + + if( ! CurDevNN->openFile( SF, nniit.current()) ) { + // cannot open + S = qApp->translate( "NetworkSettings", + "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). + arg( (*it) ).arg( CurDevNN->name() ); + return S; + } + + if( ! SF.open() ) { + S = qApp->translate( "NetworkSettings", + "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). + arg( (*it) ).arg( CurDevNN->name() ); + return S; + } + + // preamble on first + if( FirstItem ) { + if( CurDevNN->generatePreamble( SF ) == 2 ) { S = qApp->translate( "NetworkSettings", - "<p>Cannot generate files proper to \"%1\"</p>" ). - arg(NNI->nodeClass()->name()) ; - delete F; + "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). + arg( (*it) ). + arg( CurDevNN->name() ); return S; } - delete F; } + FirstItem = 0; + Generated = 1; + + // item specific + if( nniit.current()->generateFile( SF, -1 ) == 2 ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). + arg( nniit.current()->name() ). + arg( (*it) ). + arg( CurDevNN->name() ); + return S; + } + } + } + + if( Generated ) { + SystemFile SF( (*it) ); + + if( CurDevNN->openFile( SF, 0 ) && + ! SF.path().isEmpty() + ) { + + if( ! SF.open() ) { + S = qApp->translate( "NetworkSettings", + "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). + arg( (*it) ).arg( CurDevNN->name() ); + return S; + } + + if( CurDevNN->generatePostamble( SF ) == 2 ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). + arg( (*it) ). + arg( CurDevNN->name() ); + return S; } + } // no postamble } } } } // - // generate all system files + // generate all registered files // for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { + SystemFile * SF; + SF = sfit.current(); // reset all for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { nnit.current()->NetNode->setDone(0); } for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); nniit.current(); ++nniit ) { nniit.current()->setDone(0); } for( QDictIterator<NodeCollection> ncit(M); ncit.current(); ++ncit ) { ncit.current()->setDone(0); } - Log( ( "Generating %s\n", SF->name().latin1() )); + Log( ( "Generating system file %s\n", SF->name().latin1() )); needToGenerate = 0; // are there netnodes that have instances and need // to write data in this system file ? for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); ! needToGenerate && nnit.current(); ++nnit ) { NN = nnit.current()->NetNode; - if( NN->hasDataForFile( SF->name() ) ) { + if( NN->hasDataForFile( *SF ) ) { // netnode can have data // are there instances of this node ? for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); ! needToGenerate && nniit.current(); ++nniit ) { if( nniit.current()->nodeClass() == NN ) { // yes Log(("Node %s has data\n", nniit.current()->name() )); needToGenerate = 1; break; } } } } if( ! needToGenerate ) { // no instances found that might need to write data // in this systemfile Log(("No nodes for systemfile %s\n", SF->name().latin1() )); continue; } // ok generate this system file - SF->open(); + if( ! SF->open() ) { + S = qApp->translate( "NetworkSettings", + "<p>Cannot open system file \"%1\"</p>" ). + arg( SF->name() ); + return S; + } // global presection for this system file if( ! SF->preSection() ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } // find connections that want to write to this file for( QDictIterator<NodeCollection> ncit(M); ncit.current(); ++ncit ) { NC = ncit.current(); if( NC->done() ) { // already done continue; } - if( ! NC->hasDataForFile( SF->name() ) ) { + if( ! NC->hasDataForFile( *SF ) ) { // no data continue; } Log(("Generating %s for connection %s\n", SF->name().latin1(), NC->name().latin1() )); // find highest item that wants to write data to this file - FirstWithData = NC->firstWithDataForFile( SF->name() ); + FirstWithData = NC->firstWithDataForFile( *SF ); // find device on which this connection works CurDev = NC->device(); // class of that node CurDevNN = CurDev->netNode()->nodeClass(); - Log(( "%s is done %d\n", - FirstWithData->nodeClass()->name(), - FirstWithData->nodeClass()->done() )); - if( ! FirstWithData->nodeClass()->done() ) { // generate fixed part if( ! SF->preDeviceSection( CurDevNN ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } if( FirstWithData->nodeClass()->generateFile( - SF->name(), SF->path(), *SF, -1 ) == 2 ) { + *SF, + FirstWithData, + -2 ) == 2 ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } FirstWithData->nodeClass()->setDone( 1 ); + Log(( "Systemfile %s for node instance %s is done\n", + SF->name().latin1(), + FirstWithData->name() )); } NoOfDevs = 0; DevCtStart = -1; if( SF->knowsDeviceInstances() ) { DevCtStart = 0; NoOfDevs = CurDevNN->instanceCount(); } - Log(( "Node %s is done %d\n", - CurDev->netNode()->nodeClass()->name(), - CurDev->netNode()->nodeClass()->done() )); - if( ! CurDev->netNode()->nodeClass()->done() ) { // first time this device is handled // generate common device specific part for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { if( FirstWithData->nodeClass()->generateFile( - SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { + *SF, CurDev->netNode(), i ) == 2 ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } } CurDev->netNode()->nodeClass()->setDone( 1 ); + + Log(( "Systemfile %s for Nodeclass %s is done\n", + SF->name().latin1(), + CurDev->netNode()->nodeClass()->name() + )); } // generate profile specific info // for all nodeconnections that work on the same device for( QDictIterator<NodeCollection> ncit2(M); ncit2.current(); ++ncit2 ) { if( ncit2.current()->device() != CurDev ) { // different device continue; } - Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); + Log(("Connection %s of family %s\n", + ncit2.current()->name().latin1(), + CurDev->name() )); // generate - NNI = ncit2.current()->firstWithDataForFile( SF->name() ); + NNI = ncit2.current()->firstWithDataForFile( *SF ); for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { if( ! SF->preNodeSection( NNI, i ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } - switch( NNI->generateFile( - SF->name(), SF->path(), *SF, i ) ) { + switch( NNI->generateFile( *SF, i ) ) { case 0 : (*SF) << endl; break; case 1 : break; case 2 : S = qApp->translate( "NetworkSettings", "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } if( ! SF->postNodeSection( NNI, i ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } } ncit2.current()->setDone( 1 ); } } if( ! SF->postDeviceSection( CurDevNN ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } if( ! SF->postSection() ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Closure\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } // end of file SF->close(); } return S; } QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { // collect connections that can work on top of this interface NodeCollection * NC; QList<NodeCollection> PossibleConnections; Name2Connection_t & M = NSResources->connections(); // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); // check if this profile handles the requested interface if( NC->handlesInterface( Interface ) && // if different Intf. NC->state() != Disabled && // if not enabled NC->state() != IsUp // if already used ) { Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); PossibleConnections.append( NC ); } } return PossibleConnections; } /* Called by the system to see if interface can be brought UP if allowed, echo Interface-allowed else Interface-disallowed */ bool NetworkSettingsData::canStart( const char * Interface ) { // load situation NodeCollection * NC = 0; QList<NodeCollection> PossibleConnections; PossibleConnections = collectPossible( Interface ); Log( ( "for %s : Possiblilies %d\n", Interface, PossibleConnections.count() )); switch( PossibleConnections.count() ) { case 0 : // no connections break; case 1 : // one connection NC = PossibleConnections.first(); break; default : // need to ask user ? return 1; } if( NC ) { switch( NC->state() ) { case Unchecked : case Unknown : case Unavailable : case Disabled : // this profile does not allow interface to be UP // -> try others break; case Off : // try to UP the device - if( ! NC->setState( Activate ) ) { - // cannot bring device Online -> try other alters + { QString S= NC->setState( Activate ); + if( ! S.isEmpty() ) { + // could not bring device Online -> try other alters + Log(( "%s-c%d-disallowed : %s\n", + Interface, NC->number(), S.latin1() )); break; } + // interface assigned + } // FT case Available : case IsUp : // also called for 'ifdown' // device is ready -> done Log(( "%s-c%d-allowed\n", Interface, NC->number() )); printf( "%s-c%d-allowed\n", Interface, NC->number() ); return 0; } } // if we come here no alternatives are possible Log(( "%s-cnn-disallowed\n", Interface )); printf( "%s-cnn-disallowed\n", Interface ); return 0; } -/* - Called by the system to regenerate config files -*/ +bool NetworkSettingsData::isModified( void ) { + if( ForceModified ) + return 1; -bool NetworkSettingsData::regenerate( void ) { - QString S = generateSettings(); - if( ! S.isEmpty() ) { - fprintf( stdout, "%s\n", S.latin1() ); + for( QDictIterator<NodeCollection> it(NSResources->connections()); + it.current(); + ++it ) { + if( it.current()->isModified() ) { return 1; } + } return 0; } diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h index 507185e..a0ae7d1 100644 --- a/noncore/settings/networksettings2/nsdata.h +++ b/noncore/settings/networksettings2/nsdata.h @@ -1,37 +1,34 @@ #ifndef __NSDATA_H #define __NSDATA_H -#include "netnode.h" +#include <netnode.h> class NetworkSettingsData { public : NetworkSettingsData( void ); ~NetworkSettingsData( void ); void loadSettings( void ); QString saveSettings( void ); QString generateSettings( void ); - bool isModified( void ) - { return IsModified; } - void setModified( bool m ) - { IsModified = m; } + bool isModified( void ); + inline void setModified( bool M ) + { ForceModified = M; } QList<NodeCollection> collectPossible( const char * Interface ); // return TRUE if we need gui to decide bool canStart( const char * Interface ); - bool regenerate( void ); private : - bool IsModified; + bool ForceModified; // collect strings in config file nobody wants QStringList LeftOvers; - }; #endif diff --git a/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp b/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp index 450d560..9403694 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp +++ b/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp @@ -1,105 +1,105 @@ #include <stdio.h> #include <qcombobox.h> #include <qmessagebox.h> #include <qradiobutton.h> #include <qlineedit.h> #include <GUIUtils.h> #include "PPPAuthedit.h" PPPAuthEdit::PPPAuthEdit( QWidget * Parent ) : PPPAuthGUI( Parent ){ } bool PPPAuthEdit::PAP_Checked( void ) { return ( Pap_RB->isChecked() || Chap_RB->isChecked() || EAP_RB->isChecked() ); } QString PPPAuthEdit::acceptable( void ) { if( Login_RB->isChecked() ) { if( LoginSend_LE->text().isEmpty() ) return tr("Login send missing"); if( LoginExpect_LE->text().isEmpty() ) return tr("Login expect missing"); if( PasswordSend_LE->text().isEmpty() ) return tr("Password send missing"); if( PasswordExpect_LE->text().isEmpty() ) return tr("Password expect missing"); } else if( PAP_Checked() ) { if( Client_LE->text().isEmpty() ) return tr("Pap/Chap/EAP client id missing"); if( Server_LE->text().isEmpty() ) return tr("Pap/Chap/EAP server id missing"); if( Secret_LE->text().isEmpty() ) return tr("Pap/Chap/EAP secret id missing"); } return QString(); } -bool PPPAuthEdit::commit( PPPData_t & D ) { +bool PPPAuthEdit::commit( PPPData & D ) { bool SM = 0; if( ( D.Auth.Mode == 0 && ! Login_RB->isChecked() ) || ( D.Auth.Mode == 1 && ! PAP_Checked() ) || ( D.Auth.Mode == 2 && ! Terminal_RB->isChecked() ) ) { // mode modifed SM = 1; D.Auth.Mode = ( Login_RB->isChecked() ) ? 0 : ( PAP_Checked() ) ? 1 : 2; } if( Login_RB->isChecked() ) { TXTM( D.Auth.Login.Expect, LoginExpect_LE, SM ); TXTM( D.Auth.Login.Send, LoginSend_LE, SM ); TXTM( D.Auth.Password.Expect, PasswordExpect_LE, SM ); TXTM( D.Auth.Password.Send, PasswordSend_LE, SM ); } else if( PAP_Checked() ) { TXTM( D.Auth.Client, Client_LE, SM ); TXTM( D.Auth.Server, Server_LE, SM ); TXTM( D.Auth.Secret, Secret_LE, SM ); if( Pap_RB->isChecked() ) { D.Auth.PCEMode = 0; } else if( Chap_RB->isChecked() ) { D.Auth.PCEMode = 1; } else if( EAP_RB->isChecked() ) { D.Auth.PCEMode = 2; } } return SM; } -void PPPAuthEdit::showData( PPPData_t & D ) { +void PPPAuthEdit::showData( PPPData & D ) { switch( D.Auth.Mode ) { case 0 : Login_RB->setChecked( TRUE ); break; case 1 : switch( D.Auth.PCEMode ) { case 0 : Pap_RB->setChecked( TRUE ); break; case 1 : Chap_RB->setChecked( TRUE ); break; case 2 : EAP_RB->setChecked( TRUE ); break; } break; case 2 : Terminal_RB->setChecked( TRUE ); break; } LoginExpect_LE->setText( D.Auth.Login.Expect ); PasswordExpect_LE->setText( D.Auth.Password.Expect ); LoginSend_LE->setText( D.Auth.Login.Send ); PasswordSend_LE->setText( D.Auth.Password.Send ); Client_LE->setText( D.Auth.Client ); Server_LE->setText( D.Auth.Server ); Secret_LE->setText( D.Auth.Secret ); } diff --git a/noncore/settings/networksettings2/ppp/PPPAuthedit.h b/noncore/settings/networksettings2/ppp/PPPAuthedit.h index 2392569..7a06657 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthedit.h +++ b/noncore/settings/networksettings2/ppp/PPPAuthedit.h @@ -1,17 +1,17 @@ #include "pppdata.h" #include "PPPAuthGUI.h" class PPPAuthEdit : public PPPAuthGUI { public : PPPAuthEdit( QWidget * parent ); QString acceptable( void ); - bool commit( PPPData_t & Data ); - void showData( PPPData_t & Data ); + bool commit( PPPData & Data ); + void showData( PPPData & Data ); bool PAP_Checked( void ); private : }; diff --git a/noncore/settings/networksettings2/ppp/PPPDNSedit.cpp b/noncore/settings/networksettings2/ppp/PPPDNSedit.cpp index 22f8e59..270f695 100644 --- a/noncore/settings/networksettings2/ppp/PPPDNSedit.cpp +++ b/noncore/settings/networksettings2/ppp/PPPDNSedit.cpp @@ -1,108 +1,108 @@ #include <qtoolbutton.h> #include <qmessagebox.h> #include <qlistbox.h> #include <qlineedit.h> #include <qradiobutton.h> #include <resources.h> #include <GUIUtils.h> #include "PPPDNSedit.h" PPPDNSEdit::PPPDNSEdit( QWidget * Parent ) : PPPDNSGUI( Parent ){ Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); Remove_TB->setPixmap( NSResources->getPixmap( "remove" ) ); } QString PPPDNSEdit::acceptable( void ) { if( DNSFixed_RB->isChecked() ) { if( DomainName_LE->text().isEmpty() ) tr("Domainname needed"); if( Servers_LB->count() == 0 ) tr("DNS Servers needed"); } return QString(); } -bool PPPDNSEdit::commit( PPPData_t & D ) { +bool PPPDNSEdit::commit( PPPData & D ) { bool SM = 0; CBM( D.DNS.ServerAssigned, DNSServerAssigned_RB, SM ); TXTM( D.DNS.DomainName, DomainName_LE, SM ); // new items in old ? for ( unsigned i = 0; i < Servers_LB->count(); i++ ) { QString S; bool Found; Found = 0; S = Servers_LB->text(i); for ( unsigned j = 0; j < D.DNS.Servers.size(); j++ ) { if( *(D.DNS.Servers[i]) == S ) { // still in list Found = 1; break; } } if( ! Found ) { SM = 1; D.DNS.Servers.resize( D.DNS.Servers.size()+1 ); D.DNS.Servers[D.DNS.Servers.size()] = new QString( S ); } } // old in new ? for ( unsigned j = 0; j < D.DNS.Servers.size(); j++ ) { bool Found; Found = 0; for ( unsigned i = 0; i < Servers_LB->count(); i++ ) { if( *(D.DNS.Servers[j]) == Servers_LB->text(i) ) { // still in list Found = 1; break; } } if( ! Found ) { // old obsolete SM = 1; delete D.DNS.Servers[j]; for( unsigned i = j+1; i < D.DNS.Servers.size(); i ++ ) { // compress array D.DNS.Servers[i-1] = D.DNS.Servers[i]; } // shrink D.DNS.Servers.resize( D.DNS.Servers.size()-1 ); } } return SM; } -void PPPDNSEdit::showData( PPPData_t & D) { +void PPPDNSEdit::showData( PPPData & D) { DNSServerAssigned_RB->setChecked( D.DNS.ServerAssigned ); DomainName_LE->setText( D.DNS.DomainName ); for( unsigned i = 0; i < D.DNS.Servers.size(); i ++ ) { Servers_LB->insertItem( *(D.DNS.Servers[i]) ); } } void PPPDNSEdit::SLOT_AddServer( void ) { if( ServerAddress_LE->text().isEmpty() ) return; Servers_LB->insertItem( ServerAddress_LE->text() ); ServerAddress_LE->setText( "" ); } void PPPDNSEdit::SLOT_RemoveServer( void ) { long i = Servers_LB->currentItem(); if( i < 0 ) return; Servers_LB->removeItem( i ); if( (unsigned) i >= Servers_LB->count() ) { i --; } if( i >= 0 ) { Servers_LB->setCurrentItem( i ); } } diff --git a/noncore/settings/networksettings2/ppp/PPPDNSedit.h b/noncore/settings/networksettings2/ppp/PPPDNSedit.h index 43e0067..1ca8c21 100644 --- a/noncore/settings/networksettings2/ppp/PPPDNSedit.h +++ b/noncore/settings/networksettings2/ppp/PPPDNSedit.h @@ -1,20 +1,20 @@ #include "pppdata.h" #include "PPPDNSGUI.h" class PPPDNSEdit : public PPPDNSGUI { public : PPPDNSEdit( QWidget * parent ); QString acceptable( void ); - bool commit( PPPData_t & Data ); - void showData( PPPData_t & Data ); + bool commit( PPPData & Data ); + void showData( PPPData & Data ); public slots : void SLOT_AddServer( void ); void SLOT_RemoveServer( void ); private : }; diff --git a/noncore/settings/networksettings2/ppp/PPPGUI.ui b/noncore/settings/networksettings2/ppp/PPPGUI.ui index 777e4a9..4c79fe3 100644 --- a/noncore/settings/networksettings2/ppp/PPPGUI.ui +++ b/noncore/settings/networksettings2/ppp/PPPGUI.ui @@ -1,103 +1,115 @@ <!DOCTYPE UI><UI> <class>PPPGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>PPPGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>124</width> - <height>29</height> + <width>528</width> + <height>345</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>PPP</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> - <number>2</number> + <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QComboBox</class> <item> <property> <name>text</name> <string>Authentication</string> </property> </item> <item> <property> <name>text</name> <string>IP settings</string> </property> </item> <item> <property> <name>text</name> <string>DNS Settings</string> </property> </item> + <item> + <property> + <name>text</name> + <string>Commands</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>Dialing</string> + </property> + </item> <property stdset="1"> <name>name</name> <cstring>PPPOptions_CB</cstring> </property> </widget> <widget> <class>QWidgetStack</class> <property stdset="1"> <name>name</name> <cstring>Options_WS</cstring> </property> </widget> </vbox> </widget> <customwidgets> <customwidget> <class>QWidgetStack</class> <header location="global">qwidgetstack.h</header> <sizehint> <width>-1</width> <height>-1</height> </sizehint> - <container>0</container> + <container>1</container> <sizepolicy> <hordata>7</hordata> <verdata>7</verdata> </sizepolicy> <pixmap>image0</pixmap> <slot access="public">raiseWidget( int )</slot> </customwidget> </customwidgets> <images> <image> <name>image0</name> <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data> </image> </images> <connections> <connection> <sender>PPPOptions_CB</sender> <signal>activated(int)</signal> <receiver>PPPGUI</receiver> <slot>SLOT_SelectTopic( int )</slot> </connection> <slot access="public">SLOT_SelectTopic( int )</slot> </connections> </UI> diff --git a/noncore/settings/networksettings2/ppp/PPPIPGUI.ui b/noncore/settings/networksettings2/ppp/PPPIPGUI.ui index f3d5019..21bd29e 100644 --- a/noncore/settings/networksettings2/ppp/PPPIPGUI.ui +++ b/noncore/settings/networksettings2/ppp/PPPIPGUI.ui @@ -1,444 +1,399 @@ <!DOCTYPE UI><UI> <class>PPPIPGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>PPPIPGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>133</width> - <height>235</height> + <width>258</width> + <height>232</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>PPPIP</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> - <number>3</number> + <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>2</number> + <number>1</number> </property> <widget> - <class>QButtonGroup</class> + <class>QGroupBox</class> <property stdset="1"> <name>name</name> - <cstring>ButtonGroup4</cstring> - </property> - <property stdset="1"> - <name>frameShape</name> - <enum>Box</enum> + <cstring>GroupBox1</cstring> </property> <property stdset="1"> <name>title</name> <string>IP</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> - <vbox> + <grid> <property stdset="1"> <name>margin</name> - <number>2</number> + <number>3</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> - <widget> - <class>QRadioButton</class> + <widget row="0" column="0" > + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>IPServerAssigned_RB</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Server assigned</string> + <cstring>TextLabel1</cstring> </property> <property stdset="1"> - <name>checked</name> + <name>enabled</name> <bool>true</bool> </property> - </widget> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>IPFixed_RB</cstring> - </property> <property stdset="1"> <name>text</name> - <string>Fixed</string> + <string>Local</string> </property> </widget> - <widget> - <class>QLayoutWidget</class> + <widget row="0" column="1" > + <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>Layout11</cstring> + <cstring>LocalAddress_LE</cstring> </property> - <hbox> <property stdset="1"> - <name>margin</name> - <number>0</number> + <name>enabled</name> + <bool>true</bool> </property> + </widget> + <widget row="0" column="2" > + <class>QCheckBox</class> <property stdset="1"> - <name>spacing</name> - <number>6</number> - </property> - <spacer> - <property> <name>name</name> - <cstring>Spacer8</cstring> - </property> - <property stdset="1"> - <name>orientation</name> - <enum>Horizontal</enum> + <cstring>ServerOverrulesLocal_CB</cstring> </property> <property stdset="1"> - <name>sizeType</name> - <enum>Fixed</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - <property> - <name>layoutMargin</name> - </property> - <property> - <name>layoutSpacing</name> + <name>text</name> + <string>Server Overrules</string> </property> - </spacer> - <widget> - <class>QFrame</class> + </widget> + <widget row="1" column="1" > + <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>Frame8</cstring> + <cstring>RemoteAddress_LE</cstring> </property> <property stdset="1"> <name>enabled</name> - <bool>false</bool> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>7</hsizetype> - <vsizetype>5</vsizetype> - </sizepolicy> - </property> - <property stdset="1"> - <name>frameShape</name> - <enum>NoFrame</enum> - </property> - <property stdset="1"> - <name>frameShadow</name> - <enum>Raised</enum> - </property> - <property> - <name>layoutMargin</name> - </property> - <property> - <name>layoutSpacing</name> - </property> - <grid> - <property stdset="1"> - <name>margin</name> - <number>2</number> - </property> - <property stdset="1"> - <name>spacing</name> - <number>2</number> - </property> - <widget row="0" column="1" > - <class>QLineEdit</class> - <property stdset="1"> - <name>name</name> - <cstring>IPAddress_LE</cstring> + <bool>true</bool> </property> </widget> - <widget row="1" column="0" > - <class>QLabel</class> + <widget row="1" column="2" > + <class>QCheckBox</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel3</cstring> + <cstring>ServerOverrulesRemote_CB</cstring> </property> <property stdset="1"> <name>text</name> - <string>Subnetmask</string> + <string>Server Overrules</string> </property> </widget> - <widget row="0" column="0" > + <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel2</cstring> + <cstring>TextLabel1_2</cstring> </property> <property stdset="1"> - <name>text</name> - <string>Address</string> + <name>enabled</name> + <bool>true</bool> </property> - </widget> - <widget row="1" column="1" > - <class>QLineEdit</class> <property stdset="1"> - <name>name</name> - <cstring>IPSubMask_LE</cstring> + <name>text</name> + <string>Remote</string> </property> </widget> </grid> </widget> - </hbox> - </widget> - </vbox> - </widget> <widget> <class>QButtonGroup</class> <property stdset="1"> <name>name</name> <cstring>ButtonGroup5</cstring> </property> <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> <name>title</name> <string>Gateway</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> - <number>2</number> + <number>3</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>GWServerAssigned_RB</cstring> </property> <property stdset="1"> <name>text</name> <string>Server assigned</string> </property> <property stdset="1"> <name>checked</name> <bool>true</bool> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> </widget> <widget> <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>GWFixed_RB</cstring> </property> <property stdset="1"> <name>text</name> <string>Fixed</string> </property> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout12</cstring> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <spacer> <property> <name>name</name> <cstring>Spacer9</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Fixed</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QFrame</class> <property stdset="1"> <name>name</name> <cstring>Frame9</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>5</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>frameShape</name> <enum>NoFrame</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Raised</enum> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <grid> <property stdset="1"> <name>margin</name> <number>2</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget row="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel4</cstring> </property> <property stdset="1"> <name>text</name> <string>Address</string> </property> </widget> <widget row="0" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>GWAddress_LE</cstring> </property> </widget> </grid> </widget> </hbox> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout3</cstring> + <cstring>Layout4</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>GWIsDefault_CB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Set as default</string> + </property> + </widget> <spacer> <property> <name>name</name> <cstring>Spacer3</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QCheckBox</class> <property stdset="1"> <name>name</name> - <cstring>GWIsDefault_CB</cstring> + <cstring>GWIfNotSet_CB</cstring> </property> <property stdset="1"> <name>text</name> - <string>Set as default</string> + <string>Only if not yet set</string> </property> </widget> </hbox> </widget> </vbox> </widget> + <spacer> + <property> + <name>name</name> + <cstring>Spacer4</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Vertical</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> </vbox> </widget> <connections> <connection> <sender>GWFixed_RB</sender> <signal>toggled(bool)</signal> <receiver>Frame9</receiver> <slot>setEnabled(bool)</slot> </connection> - <connection> - <sender>IPFixed_RB</sender> - <signal>toggled(bool)</signal> - <receiver>Frame8</receiver> - <slot>setEnabled(bool)</slot> - </connection> </connections> </UI> diff --git a/noncore/settings/networksettings2/ppp/PPPIPedit.cpp b/noncore/settings/networksettings2/ppp/PPPIPedit.cpp index 6965e5a..ef1b7c0 100644 --- a/noncore/settings/networksettings2/ppp/PPPIPedit.cpp +++ b/noncore/settings/networksettings2/ppp/PPPIPedit.cpp @@ -1,57 +1,54 @@ #include <qmessagebox.h> #include <qcheckbox.h> #include <qradiobutton.h> #include <qlineedit.h> #include <GUIUtils.h> #include "PPPIPedit.h" PPPIPEdit::PPPIPEdit( QWidget * Parent ) : PPPIPGUI( Parent ){ } QString PPPIPEdit::acceptable( void ) { - if( IPFixed_RB->isChecked() ) { - if( IPAddress_LE->text().isEmpty() ) - return tr("IPAddress needed" ); - if( ! validIP( IPAddress_LE->text() ) ) - return tr("IPAddress not valid" ); - if( IPSubMask_LE->text().isEmpty() ) - return tr("Subnet mask needed" ); - if( ! validIP( IPSubMask_LE->text() ) ) - return tr("Subnet mask not valid" ); - } else if( GWFixed_RB->isChecked() ) { + if( GWFixed_RB->isChecked() ) { if( GWAddress_LE->text().isEmpty() ) return tr("Gateway address needed" ); if( ! validIP( GWAddress_LE->text() ) ) return tr("Gateway address not valid" ); }; return QString(); } -bool PPPIPEdit::commit( PPPData_t & D ) { +bool PPPIPEdit::commit( PPPData & D ) { bool SM = 0; - CBM( D.IP.IPAutomatic, IPServerAssigned_RB, SM ); - if( ! D.IP.IPAutomatic ) { - TXTM( D.IP.IPAddress, IPAddress_LE, SM ); - TXTM( D.IP.IPSubMask, IPSubMask_LE, SM ); - } + CBM( D.IP.LocalOverrule, ServerOverrulesLocal_CB, SM ); + CBM( D.IP.RemoteOverrule, ServerOverrulesRemote_CB, SM ); + + TXTM( D.IP.LocalAddress, LocalAddress_LE, SM ); + TXTM( D.IP.RemoteAddress, RemoteAddress_LE, SM ); CBM( D.IP.GWAutomatic, GWServerAssigned_RB, SM ); + if( ! D.IP.GWAutomatic ) { TXTM( D.IP.GWAddress, GWAddress_LE, SM ); } CBM( D.IP.GWIsDefault, GWIsDefault_CB, SM ); + CBM( D.IP.GWIfNotSet, GWIfNotSet_CB, SM ); + return SM; } -void PPPIPEdit::showData( PPPData_t & D ) { - IPServerAssigned_RB->setChecked( D.IP.IPAutomatic ); - IPAddress_LE->setText( D.IP.IPAddress ); - IPSubMask_LE->setText( D.IP.IPSubMask ); +void PPPIPEdit::showData( PPPData & D ) { + ServerOverrulesLocal_CB->setChecked( D.IP.LocalOverrule ); + ServerOverrulesRemote_CB->setChecked( D.IP.RemoteOverrule ); + LocalAddress_LE->setText( D.IP.LocalAddress ); + RemoteAddress_LE->setText( D.IP.RemoteAddress ); + GWServerAssigned_RB->setChecked( D.IP.GWAutomatic ); GWAddress_LE->setText( D.IP.GWAddress ); GWIsDefault_CB->setChecked( D.IP.GWIsDefault ); + GWIfNotSet_CB->setChecked( D.IP.GWIfNotSet ); } diff --git a/noncore/settings/networksettings2/ppp/PPPIPedit.h b/noncore/settings/networksettings2/ppp/PPPIPedit.h index 153ee68..5ca4326 100644 --- a/noncore/settings/networksettings2/ppp/PPPIPedit.h +++ b/noncore/settings/networksettings2/ppp/PPPIPedit.h @@ -1,15 +1,15 @@ #include "pppdata.h" #include "PPPIPGUI.h" class PPPIPEdit : public PPPIPGUI { public : PPPIPEdit( QWidget * parent ); QString acceptable( void ); - bool commit( PPPData_t & Data ); - void showData( PPPData_t & Data ); + bool commit( PPPData & Data ); + void showData( PPPData & Data ); private : }; diff --git a/noncore/settings/networksettings2/ppp/PPPedit.cpp b/noncore/settings/networksettings2/ppp/PPPedit.cpp index eb4fdbf..17889aa 100644 --- a/noncore/settings/networksettings2/ppp/PPPedit.cpp +++ b/noncore/settings/networksettings2/ppp/PPPedit.cpp @@ -1,48 +1,55 @@ #include <qwidgetstack.h> #include "PPPIPedit.h" #include "PPPDNSedit.h" #include "PPPAuthedit.h" +#include "PPPRunedit.h" +#include "PPPDialingedit.h" #include "PPPedit.h" PPPEdit::PPPEdit( QWidget * Parent ) : PPPGUI( Parent ){ Auth = new PPPAuthEdit( Options_WS ); IP = new PPPIPEdit( Options_WS ); DNS = new PPPDNSEdit( Options_WS ); + Run = new PPPRunEdit( Options_WS ); + Dialing = new PPPDialingEdit( Options_WS ); + Options_WS->addWidget( Auth, 0 ); Options_WS->addWidget( IP, 1 ); Options_WS->addWidget( DNS, 2 ); + Options_WS->addWidget( Run, 3 ); + Options_WS->addWidget( Dialing, 4 ); Options_WS->raiseWidget( 0 ); } QString PPPEdit::acceptable( void ) { QString S; S = Auth->acceptable(); if( S.isEmpty() ) { S = IP->acceptable(); if( S.isEmpty() ) { S = DNS->acceptable(); } } return S; } -bool PPPEdit::commit( PPPData_t & Data ) { +bool PPPEdit::commit( PPPData & Data ) { bool SM ; SM = Auth->commit( Data ); SM |= IP->commit( Data ); SM |= DNS->commit( Data ); return SM; } -void PPPEdit::showData( PPPData_t & Data ) { +void PPPEdit::showData( PPPData & Data ) { Auth->showData( Data ) ; IP->showData( Data ); DNS->showData( Data ); } void PPPEdit::SLOT_SelectTopic( int v ) { Options_WS->raiseWidget( v ); } diff --git a/noncore/settings/networksettings2/ppp/PPPedit.h b/noncore/settings/networksettings2/ppp/PPPedit.h index 57d38ee..f674b17 100644 --- a/noncore/settings/networksettings2/ppp/PPPedit.h +++ b/noncore/settings/networksettings2/ppp/PPPedit.h @@ -1,27 +1,31 @@ #include "pppdata.h" #include "PPPGUI.h" class PPPAuthEdit; class PPPIPEdit; class PPPDNSEdit; +class PPPRunEdit; +class PPPDialingEdit; class PPPEdit : public PPPGUI { public : PPPEdit( QWidget * parent ); QString acceptable( void ); - bool commit( PPPData_t & Data ); - void showData( PPPData_t & Data ); + bool commit( PPPData & Data ); + void showData( PPPData & Data ); public slots : void SLOT_SelectTopic( int ); private : PPPAuthEdit * Auth; PPPDNSEdit * DNS; PPPIPEdit * IP; + PPPRunEdit * Run; + PPPDialingEdit * Dialing; }; diff --git a/noncore/settings/networksettings2/ppp/opie-networksettings2plugin-ppp.control b/noncore/settings/networksettings2/ppp/opie-networksettings2plugin-ppp.control index 7dfde38..19d1c89 100644 --- a/noncore/settings/networksettings2/ppp/opie-networksettings2plugin-ppp.control +++ b/noncore/settings/networksettings2/ppp/opie-networksettings2plugin-ppp.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-ppp +Package: opie-networksettings2plugin-ppp Files: plugins/networksettings2/libppp.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings ppp plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/ppp/ppp.pro b/noncore/settings/networksettings2/ppp/ppp.pro index f866bee..dd3408c 100644 --- a/noncore/settings/networksettings2/ppp/ppp.pro +++ b/noncore/settings/networksettings2/ppp/ppp.pro @@ -1,24 +1,33 @@ TEMPLATE = lib CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/plugins/networksettings2 HEADERS = ppp_NN.h \ ppp_NNI.h \ PPPedit.h \ PPPAuthedit.h \ PPPDNSedit.h \ + PPPRunedit.h \ + PPPDialingedit.h \ PPPIPedit.h SOURCES = ppp_NN.cpp \ ppp_NNI.cpp \ PPPedit.cpp \ PPPDNSedit.cpp \ + PPPRunedit.cpp \ + PPPDialingedit.cpp \ PPPAuthedit.cpp \ ppprun.cpp \ PPPIPedit.cpp INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 LIBS += -lqpe -INTERFACES = PPPGUI.ui PPPAuthGUI.ui PPPIPGUI.ui PPPDNSGUI.ui +INTERFACES = PPPGUI.ui \ + PPPAuthGUI.ui \ + PPPIPGUI.ui \ + PPPDNSGUI.ui \ + PPPDialingGUI.ui \ + PPPRunGUI.ui TARGET = ppp VERSION = 1.0.0 include( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.cpp b/noncore/settings/networksettings2/ppp/ppp_NN.cpp index ff4465c..51ba27d 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NN.cpp @@ -1,85 +1,85 @@ #include <qfile.h> +#include <resources.h> #include <qtextstream.h> #include "ppp_NN.h" #include "ppp_NNI.h" QStringList * PPPNetNode::ProperFiles = 0; static const char * PPPNeeds[] = - { "line", - "modem", + { "modem", + 0 + }; + +static const char * PPPProvides[] = + { "connection", 0 }; /** * Constructor, find all of the possible interfaces */ PPPNetNode::PPPNetNode() : ANetNode(tr("PPP Connection")) { - // proper files : will leak - ProperFiles =new QStringList; - *ProperFiles << "peers"; - *ProperFiles << "chatscript"; - - // system files NSResources->addSystemFile( - "pap-secrets", "/tmp/pap-secrets", 0 ); + "pap-secrets", "/etc/ppp/pap-secrets", 0 ); NSResources->addSystemFile( - "chap-secrets", "/tmp/chap-secrets", 0 ); + "chap-secrets", "/etc/ppp/chap-secrets", 0 ); } /** * Delete any interfaces that we own. */ PPPNetNode::~PPPNetNode(){ } const QString PPPNetNode::nodeDescription(){ return tr("\ <p>Sets up IP using PPP.</p>\ <p>Use this for dialup devices or serial setups</p>\ " ); } ANetNodeInstance * PPPNetNode::createInstance( void ) { return new APPP( this ); } const char ** PPPNetNode::needs( void ) { return PPPNeeds; } -const char * PPPNetNode::provides( void ) { - return "connection"; +const char ** PPPNetNode::provides( void ) { + return PPPProvides; } -QStringList * PPPNetNode::properFiles( void ) { - return ProperFiles; - +QStringList PPPNetNode::properFiles( void ) { + QStringList SL; + SL << "peers" << "chatscripts"; + return SL; } // need to generate : // /etc/ppp/pap-secrets // /etc/ppp/pap-secrets -bool PPPNetNode::hasDataForFile( const QString & S ) { - return S == "pap-secrets" || - S == "chap-secrets" ; +bool PPPNetNode::hasDataForFile( SystemFile & S ) { + return S.name() == "pap-secrets" || + S.name() == "chap-secrets" ; } QString PPPNetNode::genNic( long NicNr ) { QString S; return S.sprintf( "ppp%ld", NicNr ); } void PPPNetNode::setSpecificAttribute( QString & , QString & ) { } void PPPNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new PPPNetNode() ); } } diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.h b/noncore/settings/networksettings2/ppp/ppp_NN.h index 249be5a..3ead10e 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.h +++ b/noncore/settings/networksettings2/ppp/ppp_NN.h @@ -1,43 +1,43 @@ #ifndef PPP_NETNODE_H #define PPP_NETNODE_H #include "netnode.h" class APPP; class PPPNetNode : public ANetNode{ Q_OBJECT public: PPPNetNode(); virtual ~PPPNetNode(); virtual const QString pixmapName() { return "Devices/ppp"; } - virtual bool hasDataForFile( const QString & S ); + virtual bool hasDataForFile( SystemFile & S ); virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); virtual QString genNic( long NicNr ); - virtual QStringList * properFiles( void ); + virtual QStringList properFiles( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); static QStringList * ProperFiles; }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp index ba639de..9e3bb64 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp @@ -1,221 +1,235 @@ #include <qfile.h> #include <qfileinfo.h> #include "PPPedit.h" #include "ppp_NNI.h" #include "ppp_NN.h" APPP::APPP( PPPNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.DNS.ServerAssigned = 1; Data.DNS.DomainName = ""; Data.Auth.Mode = 0; Data.Auth.Login.Expect = "ogin:"; Data.Auth.Password.Expect = "assword:"; Data.Auth.PCEMode = 0; Data.Auth.Client = "*"; Data.Auth.Server = "*"; Data.Auth.Secret = ""; - Data.IP.IPAutomatic = 1; - Data.IP.IPAddress = ""; - Data.IP.IPSubMask = ""; + Data.IP.LocalAddress = "10.0.0.1"; + Data.IP.RemoteAddress = "10.0.0.2"; + Data.IP.LocalOverrule = 1; + Data.IP.RemoteOverrule = 1; + Data.IP.GWAutomatic = 1; Data.IP.GWAddress = ""; Data.IP.GWIsDefault = 1; + Data.IP.GWIfNotSet = 1; + + Data.Run.PreConnect = ""; + Data.Run.PostConnect = ""; + Data.Run.PreDisconnect = ""; + Data.Run.PostDisconnect = ""; + GUI = 0; RT = 0; } void APPP::setSpecificAttribute( QString & A, QString & V ) { if( A.startsWith( "dns" ) ) { if( A == "dnsserverassigned" ) { Data.DNS.ServerAssigned = (V == "yes"); } else if( A == "dnsdomainname" ) { Data.DNS.DomainName = V; } else if( A == "dnsserver" ) { Data.DNS.Servers.resize( Data.DNS.Servers.size()+1 ); Data.DNS.Servers[Data.DNS.Servers.size()-1] = new QString( V ); } } else if( A.startsWith( "auth" ) ) { if( A == "authmode" ) { Data.Auth.Mode = V.toShort(); } else if( A == "authloginexpect" ) { Data.Auth.Login.Expect = V; } else if( A == "authloginsend" ) { Data.Auth.Login.Send = V; } else if( A == "authpasswordexpect" ) { Data.Auth.Password.Expect = V; } else if( A == "authpasswordsend" ) { Data.Auth.Password.Send = V; } else if( A == "authpcemode" ) { Data.Auth.PCEMode = V.toShort(); } else if( A == "authclient" ) { Data.Auth.Client = V; } else if( A == "authserver" ) { Data.Auth.Server = V; } else if( A == "authsecret" ) { Data.Auth.Secret = V; } } else if( A.startsWith( "ip" ) ) { - if( A == "ipautomatic" ) { - Data.IP.IPAutomatic = (V == "yes"); - } else if( A == "gwautomatic" ) { + if( A == "iplocaloverrule" ) { + Data.IP.LocalOverrule = (V == "yes"); + } else if( A == "ipremoteoverrule" ) { + Data.IP.RemoteOverrule = (V == "yes"); + } else if( A == "ipgwautomatic" ) { Data.IP.GWAutomatic = (V == "yes"); - } else if( A == "gwisdefault" ) { + } else if( A == "ipgwisdefault" ) { Data.IP.GWIsDefault = (V == "yes"); - } else if( A == "ipaddress" ) { - Data.IP.IPAddress = V; - } else if( A == "ipsubmask" ) { - Data.IP.IPSubMask = V; - } else if( A == "gwaddress" ) { + } else if( A == "ipgwifnotset" ) { + Data.IP.GWIfNotSet = (V == "yes"); + } else if( A == "iplocaladdress" ) { + Data.IP.LocalAddress = V; + } else if( A == "ipremoteaddress" ) { + Data.IP.RemoteAddress = V; + } else if( A == "ipgwaddress" ) { Data.IP.GWAddress = V; } + } else if( A.startsWith( "run" ) ) { + if( A == "runpreconnect" ) { + Data.Run.PreConnect = V; + } else if( A == "runpostconnect" ) { + Data.Run.PostConnect = V; + } else if( A == "runpredisconnect" ) { + Data.Run.PreDisconnect = V; + } else if( A == "runpostdisconnect" ) { + Data.Run.PostDisconnect = V; + } } } void APPP::saveSpecificAttribute( QTextStream & TS ) { TS << "dnsserverassigned=" << ( ( Data.DNS.ServerAssigned ) ? "yes" : "no" ) << endl; TS << "dnsdomainname=" << Data.DNS.DomainName << endl; for( unsigned int i = 0; i < Data.DNS.Servers.size(); i ++ ) { TS << "dnsserver=" << *(Data.DNS.Servers[i]) << endl; } TS << "authmode=" << Data.Auth.Mode << endl; TS << "authloginexpect=" << quote( Data.Auth.Login.Expect ) << endl; TS << "authloginsend=" << quote( Data.Auth.Login.Send ) << endl; TS << "authpasswordexpect=" << quote( Data.Auth.Password.Expect ) << endl; TS << "authpasswordsend=" << quote( Data.Auth.Password.Send ) << endl; TS << "authpcemode=" << Data.Auth.PCEMode << endl; TS << "authclient=" << Data.Auth.Client << endl; TS << "authserver=" << Data.Auth.Server << endl; TS << "authsecret=" << quote( Data.Auth.Secret ) << endl; - TS << "ipautomatic=" << ( ( Data.IP.IPAutomatic ) ? "yes" : "no" ) << endl; - TS << "gwautomatic=" << ( ( Data.IP.GWAutomatic ) ? "yes" : "no" ) << endl; - TS << "gwisdefault=" << ( ( Data.IP.GWIsDefault ) ? "yes" : "no" ) << endl; - TS << "ipaddress=" << Data.IP.IPAddress << endl; - TS << "ipsubmask=" << Data.IP.IPSubMask << endl; - TS << "gwaddress=" << Data.IP.GWAddress << endl; + TS << "ipgwautomatic=" << ( ( Data.IP.GWAutomatic ) ? "yes" : "no" ) << endl; + TS << "ipgwisdefault=" << ( ( Data.IP.GWIsDefault ) ? "yes" : "no" ) << endl; + TS << "ipgwifnotset=" << ( ( Data.IP.GWIfNotSet ) ? "yes" : "no" ) << endl; + TS << "iplocaloverrule=" << ( ( Data.IP.LocalOverrule ) ? "yes" : "no" ) << endl; + TS << "ipremoteoverrule=" << ( ( Data.IP.RemoteOverrule ) ? "yes" : "no" ) << endl; + TS << "iplocaladdress=" << Data.IP.LocalAddress << endl; + TS << "ipremoteaddress=" << Data.IP.RemoteAddress << endl; + TS << "ipgwaddress=" << Data.IP.GWAddress << endl; + + TS << "runpreconnect=" << Data.Run.PreConnect << endl; + TS << "runpostconnect=" << Data.Run.PostConnect << endl; + TS << "runpredisconnect=" << Data.Run.PreDisconnect << endl; + TS << "runpostdisconnect=" << Data.Run.PostDisconnect << endl; + } QWidget * APPP::edit( QWidget * parent ) { GUI = new PPPEdit( parent ); GUI->showData( Data ); return GUI; } QString APPP::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void APPP::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } -QFile * APPP::openFile( const QString & ID ) { - QFile * F = 0; - QString S; - - if( ID == "peers" ) { - S = removeSpaces( QString("/tmp/") + connection()->name() ); - - F = new QFile( S ); - - if( ! F->open( IO_WriteOnly ) ) { - Log(("Cannot open file %s\n", S.latin1() )); - return 0; +bool APPP::openFile( SystemFile & SF ) { + if( SF.name() == "peers" ) { + SF.setPath( removeSpaces( + QString( "/tmp/ppp/peers/" ) + connection()->name() ) ); + return 1; + } else if ( SF.name() == "chatscripts" ) { + SF.setPath( removeSpaces( + QString( "/tmp/chatscripts/" ) + connection()->name() ) ); + return 1; } - } else if ( ID == "chatscripts" ) { - S = removeSpaces( QString("/tmp/") + connection()->name() + ".chat" ); - F = new QFile( S ); - - if( ! F->open( IO_WriteOnly ) ) { - Log(("Cannot open file %s\n", S.latin1() )); return 0; } - } - if( F ) { - Log(("Generate proper file %s = %s\n", - ID.latin1(), F->name().latin1())); - } - return F; -} -short APPP::generateFile( const QString & ID, - const QString & Path, - QTextStream & TS, - long DevNr ) { +short APPP::generateFile( SystemFile & SF, long DevNr ) { short rvl, rvd; rvl = 1; rvd = 1; - if( ID == "pap-secrets" ) { - Log(("Generate PPP for %s\n", ID.latin1() )); + if( SF.name() == "pap-secrets" ) { + Log(("Generate PPP for %s\n", SF.name().latin1() )); + if( Data.Auth.Mode == 1 && Data.Auth.PCEMode == 0 ) { - TS << "# secrets for " + SF << "# secrets for " << connection()->name().latin1() << endl; - TS << Data.Auth.Client + SF << Data.Auth.Client << " " << Data.Auth.Server << " " << Data.Auth.Secret << endl; rvl = 0; rvd = connection()->getToplevel()->generateFileEmbedded( - ID, Path, TS, DevNr ); + SF, DevNr ); } - } else if( ID == "chap-secrets" ) { - Log(("Generate PPP for %s\n", ID.latin1() )); + } else if( SF.name() == "chap-secrets" ) { + Log(("Generate PPP for %s\n", SF.name().latin1() )); if( Data.Auth.Mode == 1 && Data.Auth.PCEMode != 0 ) { // used for both EAP and Chap - TS << "# secrets for " + SF << "# secrets for " << connection()->name().latin1() << endl; - TS << Data.Auth.Client + SF << Data.Auth.Client << " " << Data.Auth.Server << " " << Data.Auth.Secret << endl; rvl = 0; rvd = connection()->getToplevel()->generateFileEmbedded( - ID, Path, TS, DevNr ); + SF, DevNr ); } - } else if ( ID == "peers" ) { - QFileInfo FI(Path); - Log(("Generate PPP for %s\n", ID.latin1() )); + } else if ( SF.name() == "peers" ) { + + QFileInfo FI(SF.path()); + Log(("Generate PPP for %s\n", SF.name().latin1() )); - TS << "connect \"/usr/sbin/chat -v -f /etc/ppp/" + SF << "connect \"/usr/sbin/chat -v -f /etc/chatscripts/" << FI.baseName() - << ".chat\"" + << "\"" << endl; if( Data.IP.GWIsDefault ) { - TS << "defaultroute" + SF << "defaultroute" << endl; } - TS << "linkname " - << removeSpaces( ID.latin1() ) + SF << "linkname " + << removeSpaces( SF.name().latin1() ) << endl; // insert other data here rvl = 0; rvd = connection()->getToplevel()->generateFileEmbedded( - ID, Path, TS, DevNr ); - } else if ( ID == "chatscripts" ) { - Log(("Generate PPP for %s\n", ID.latin1() )); + SF, DevNr ); + } else if ( SF.name() == "chatscripts" ) { + Log(("Generate PPP for %s\n", SF.name().latin1() )); rvl = 0; rvd = connection()->getToplevel()->generateFileEmbedded( - ID, Path, TS, DevNr ); + SF, DevNr ); } return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.h b/noncore/settings/networksettings2/ppp/ppp_NNI.h index 0bf8fa9..76afb21 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.h +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.h @@ -1,51 +1,45 @@ #ifndef PPP_H #define PPP_H #include <netnode.h> #include "pppdata.h" #include "ppprun.h" class PPPNetNode; class PPPEdit; class QTextStream; class APPP : public ANetNodeInstance { public : APPP( PPPNetNode * PNN ); RuntimeInfo * runtime( void ) - { if( RT == 0 ) { - RT = new PPPRun( this, Data ); - } - return RT->runtimeInfo(); - } + { return (RT) ? RT : (RT = new PPPRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); virtual void * data( void ) { return (void *)&Data; } - virtual QFile * openFile( const QString & ID ); - short generateFile( const QString & ID, - const QString & Path, - QTextStream & TS, + virtual bool openFile( SystemFile & Sf ); + short generateFile( SystemFile & TS, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : PPPEdit * GUI; PPPData Data; PPPRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/ppp/pppdata.h b/noncore/settings/networksettings2/ppp/pppdata.h index 9e8543c..68666f8 100644 --- a/noncore/settings/networksettings2/ppp/pppdata.h +++ b/noncore/settings/networksettings2/ppp/pppdata.h @@ -1,38 +1,50 @@ #ifndef PPP_DATA_H #define PPP_DATA_H #include <qstring.h> #include <qarray.h> -typedef struct PPPData { +class PPPData { + +public : + struct { - bool IPAutomatic; - QString IPAddress; - QString IPSubMask; + bool LocalOverrule; + bool RemoteOverrule; + QString LocalAddress; + QString RemoteAddress; bool GWAutomatic; QString GWAddress; bool GWIsDefault; + bool GWIfNotSet; } IP; + struct { short Mode; // 0 login, 1 chap/pap, 2 Terminal struct { QString Expect; QString Send; } Login; struct { QString Expect; QString Send; } Password; short PCEMode; // 0 pap, 1, chap 2, EAP QString Server; QString Client; QString Secret; } Auth; struct { bool ServerAssigned; QString DomainName; QArray<QString *> Servers; } DNS; -} PPPData_t; + struct { + QString PreConnect; + QString PostConnect; + QString PreDisconnect; + QString PostDisconnect; + } Run; +}; #endif diff --git a/noncore/settings/networksettings2/ppp/ppprun.cpp b/noncore/settings/networksettings2/ppp/ppprun.cpp index a8abc50..8403e6d 100644 --- a/noncore/settings/networksettings2/ppp/ppprun.cpp +++ b/noncore/settings/networksettings2/ppp/ppprun.cpp @@ -1,82 +1,52 @@ #include <resources.h> #include "ppprun.h" PPPRun::PPPRun( ANetNodeInstance * NNI, PPPData & Data ) : - AsConnection( NNI ), AsDevice( NNI ), Pat( "eth[0-9]" ) { + RuntimeInfo( NNI ), Pat( "eth[0-9]" ) { D = &Data; } -void PPPRun::detectState( NodeCollection * NC ) { +State_t PPPRun::detectState( void ) { if( isMyPPPDRunning( ) ) { - if( isMyPPPUp() ) { - NC->setCurrentState( IsUp ); - } else { - NC->setCurrentState( Available ); - } - } else { - NC->setCurrentState( Off ); // at least this - // but could also be unavailable - AsDevice::netNode()->nextNode()->runtime()->detectState( NC ); + return ( isMyPPPUp() ) ? IsUp : Available; } + return Off; } -bool PPPRun::setState( NodeCollection * NC, Action_t A, bool ) { - switch( A ) { - case Activate : - NC->setCurrentState( Available ); - // no - break; - case Deactivate : - if( NC->currentState() == IsUp ) { - NC->state( Down ); - } - // cannot really disable - NC->setCurrentState( Available ); - break; - case Up : - if( NC->currentState() != IsUp ) { - // start my PPPD - NC->setCurrentState( IsUp ); - } - break; - case Down : - if( NC->currentState() == IsUp ) { - // stop my PPPD - NC->setCurrentState( Available ); - } - break; - default : // FT - break; - } - return 1; +QString PPPRun::setMyState( NodeCollection * NC, Action_t A, bool ) { + return QString(); } bool PPPRun::isMyPPPDRunning( void ) { return 0; } bool PPPRun::isMyPPPUp( void ) { System & S = NSResources->system(); InterfaceInfo * Run; QRegExp R( "ppp[0-9]" ); for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); if( R.match( Run->Name ) >= 0 && Run->IsPointToPoint ) { // this is a LAN card - if( Run->assignedNode() == AsDevice::netNode() ) { + if( Run->assignedConnection() == netNode()->connection() ) { // assigned to us return 1; } } } return 0; } bool PPPRun::handlesInterface( const QString & S ) { return Pat.match( S ) >= 0; } + +bool PPPRun::handlesInterface( InterfaceInfo * I ) { + return handlesInterface( I->Name ); +} diff --git a/noncore/settings/networksettings2/ppp/ppprun.h b/noncore/settings/networksettings2/ppp/ppprun.h index 90a3f25..2990a96 100644 --- a/noncore/settings/networksettings2/ppp/ppprun.h +++ b/noncore/settings/networksettings2/ppp/ppprun.h @@ -1,47 +1,37 @@ #ifndef PPPRUN_H #define PPPRUN_H #include <qregexp.h> -#include <asconnection.h> -#include <asdevice.h> +#include <netnode.h> #include "pppdata.h" -class PPPRun : public AsConnection, public AsDevice { +class PPPRun : public RuntimeInfo { public : PPPRun( ANetNodeInstance * NNI, PPPData & Data ); - virtual AsDevice * asDevice( void ) - { return (AsDevice *)this; } - virtual AsConnection * asConnection( void ) - { return (AsConnection *)this; } - - virtual AsDevice * device( void ) - { return (AsDevice *)this; } + bool handlesInterface( const QString & I ); + bool handlesInterface( InterfaceInfo * ); - virtual RuntimeInfo * runtimeInfo( void ) - { return ( AsConnection *)this; } + State_t detectState( void ); + virtual RuntimeInfo * device( void ) + { return this; } + virtual RuntimeInfo * connection( void ) + { return this; } protected : - void detectState( NodeCollection * NC ); - bool setState( NodeCollection * NC, Action_t A, bool ); - bool canSetState( State_t S, Action_t A ) - { return AsDevice::connection()->findNext( - AsDevice::netNode() )->runtime()->canSetState( S,A ); } - - bool handlesInterface( const QString & I ); + QString setMyState( NodeCollection * , Action_t, bool ); private : bool isMyPPPDRunning( void ); bool isMyPPPUp( void ); - PPPData_t * D; + PPPData * D; QRegExp Pat; - }; #endif diff --git a/noncore/settings/networksettings2/profile/opie-networksettings2plugin-bluetooth.control b/noncore/settings/networksettings2/profile/opie-networksettings2plugin-bluetooth.control index c76f9b8..40c8b48 100644 --- a/noncore/settings/networksettings2/profile/opie-networksettings2plugin-bluetooth.control +++ b/noncore/settings/networksettings2/profile/opie-networksettings2plugin-bluetooth.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-profile +Package: opie-networksettings2plugin-profile Files: plugins/networksettings2/libprofile.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 -Description: Network settings profile plugin. +Description: Network settings usage profile plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/profile/profile_NN.cpp b/noncore/settings/networksettings2/profile/profile_NN.cpp index 945b48d..b7d8aa0 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.cpp +++ b/noncore/settings/networksettings2/profile/profile_NN.cpp @@ -1,51 +1,60 @@ +#include <resources.h> #include "profile_NN.h" #include "profile_NNI.h" static const char * ProfileNeeds[] = { "connection", 0 }; +static const char * ProfileProvides[] = + { "fullsetup", + 0 + }; /** * Constructor, find all of the possible interfaces */ ProfileNetNode::ProfileNetNode() : ANetNode( tr("Regular connection profile")) { + + NSResources->addSystemFile( + "interfaces", "/etc/network/interfaces", 1 ); + } /** * Delete any interfaces that we own. */ ProfileNetNode::~ProfileNetNode(){ } const QString ProfileNetNode::nodeDescription(){ return tr("\ <p>Define use of an IP connection.</p>\ <p>Configure if and when this connection needs to be established</p>\ " ); } ANetNodeInstance * ProfileNetNode::createInstance( void ) { return new AProfile( this ); } const char ** ProfileNetNode::needs( void ) { return ProfileNeeds; } -const char * ProfileNetNode::provides( void ) { - return "fullsetup"; +const char ** ProfileNetNode::provides( void ) { + return ProfileProvides; } void ProfileNetNode::setSpecificAttribute( QString & , QString & ) { } void ProfileNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new ProfileNetNode() ); } } diff --git a/noncore/settings/networksettings2/profile/profile_NN.h b/noncore/settings/networksettings2/profile/profile_NN.h index 1f1ee2c..f1648f9 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.h +++ b/noncore/settings/networksettings2/profile/profile_NN.h @@ -1,36 +1,36 @@ #ifndef PROFILE_NETNODE_H #define PROFILE_NETNODE_H #include "netnode.h" class AProfile; class ProfileNetNode : public ANetNode{ Q_OBJECT public: ProfileNetNode(); virtual ~ProfileNetNode(); virtual const QString pixmapName() { return "Devices/commprofile"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/profile/profile_NNI.cpp b/noncore/settings/networksettings2/profile/profile_NNI.cpp index f0f0b97..a1e1254 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.cpp +++ b/noncore/settings/networksettings2/profile/profile_NNI.cpp @@ -1,77 +1,76 @@ +#include <opie2/odebug.h> #include "profileedit.h" #include "profile_NNI.h" #include "profile_NN.h" AProfile::AProfile( ProfileNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.Automatic = 1; Data.Confirm = 0; Data.Description = ""; Data.Disabled = 0; Data.TriggerVPN = 0; GUI = 0; RT = 0; } void AProfile::setSpecificAttribute( QString & Attr, QString & Value ) { if ( Attr == "automatic" ) { Data.Automatic = (Value=="yes"); } else if ( Attr == "preconfirm" ) { Data.Confirm = (Value=="yes"); } else if ( Attr == "disabled" ) { Data.Disabled = (Value=="yes"); } else if ( Attr == "triggervpn" ) { Data.TriggerVPN = (Value=="yes"); } else if ( Attr == "description" ) { Data.Description = Value; } } void AProfile::saveSpecificAttribute( QTextStream & TS ) { TS << "automatic=" << ((Data.Automatic) ? "yes" : "no") << endl; TS << "preconfirm=" << ((Data.Confirm) ? "yes" : "no") << endl; TS << "disabled=" << ((Data.Disabled) ? "yes" : "no") << endl; TS << "triggervpn=" << ((Data.TriggerVPN) ? "yes" : "no") << endl; TS << "description=" << Data.Description << endl; } QWidget * AProfile::edit( QWidget * parent ) { GUI = new ProfileEdit( parent, this ); GUI->showData( Data ); return GUI; } QString AProfile::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AProfile::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -short AProfile::generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, +short AProfile::generateFileEmbedded( SystemFile & SF, long DevNr ) { short rvl, rvd; rvl = 1; - if( ID == "interfaces" ) { - Log(("Generate Profile for %s\n", ID.latin1() )); + if( SF.name() == "interfaces" ) { + Log(("Generate Profile for %s\n", SF.name().latin1() )); if( Data.TriggerVPN ) { // this profile triggers VPN -> insert trigger - TS << " up networksettings2 --triggervpn" + SF << " up networksettings2 --triggervpn" << endl; rvl = 0; } } - rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + rvd = ANetNodeInstance::generateFileEmbedded( SF, DevNr ); return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/profile/profile_NNI.h b/noncore/settings/networksettings2/profile/profile_NNI.h index 957f4af..ccd746c 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.h +++ b/noncore/settings/networksettings2/profile/profile_NNI.h @@ -1,50 +1,48 @@ #ifndef PROFILE_H #define PROFILE_H #include <netnode.h> #include "profiledata.h" #include "profilerun.h" class ProfileNetNode; class ProfileEdit; class AProfile : public ANetNodeInstance { public : AProfile( ProfileNetNode * PNN ); RuntimeInfo * runtime( void ) { return ( RT ) ? RT : ( RT = new ProfileRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); virtual void * data( void ) { return (void *)&Data; } - virtual short generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, + virtual short generateFileEmbedded( SystemFile & TS, long DevNr ); const QString & description( void ) { return Data.Description; } protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : ProfileEdit * GUI; ProfileData Data; ProfileRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/profile/profiledata.h b/noncore/settings/networksettings2/profile/profiledata.h index 246d50c..c9577e5 100644 --- a/noncore/settings/networksettings2/profile/profiledata.h +++ b/noncore/settings/networksettings2/profile/profiledata.h @@ -1,16 +1,17 @@ #ifndef PROFILE_DATA_H #define PROFILE_DATA_H #include <qstring.h> -typedef struct ProfileData { +class ProfileData { +public : QString Description; // start up automatically bool Automatic; // if started up automatically, ask user for confirmation bool Confirm; // Do not bring this connection up bool Disabled; bool TriggerVPN; -} ProfileData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/profile/profileedit.cpp b/noncore/settings/networksettings2/profile/profileedit.cpp index 87e503e..88aab15 100644 --- a/noncore/settings/networksettings2/profile/profileedit.cpp +++ b/noncore/settings/networksettings2/profile/profileedit.cpp @@ -1,98 +1,98 @@ #include <qlabel.h> #include <qframe.h> #include <qcheckbox.h> #include <qmultilineedit.h> #include <qcheckbox.h> #include <GUIUtils.h> -#include <asdevice.h> +#include <netnode.h> #include <resources.h> #include "profileedit.h" ProfileEdit::ProfileEdit( QWidget * Parent, ANetNodeInstance * TNNI ) : ProfileGUI( Parent ), RefreshTimer(this) { InterfaceInfo * II; NNI = TNNI; Dev = NNI->runtime()->device(); - if( ( II = Dev->assignedInterface() ) ) { + if( ( II = NNI->connection()->assignedInterface() ) ) { Refresh_CB->setEnabled( TRUE ); Snd_GB->setEnabled( TRUE ); Rcv_GB->setEnabled( TRUE ); Collisions_FRM->setEnabled( TRUE ); // show current content SLOT_Refresh(); // fill in static data InterfaceName_LBL->setText( II->Name ); IPAddress_LBL->setText( II->Address ); SubnetMask_LBL->setText( II->Netmask ); Broadcast_LBL->setText( II->BCastAddress ); MACAddress_LBL->setText( II->MACAddress ); if( II->IsPointToPoint ) { PointToPoint_LBL->setText( II->DstAddress ); } QString S; InterfaceName_LBL->setText( II->Name ); if( II->HasMulticast ) { S += "Multicast"; } if( ! S.isEmpty() ) { S.prepend( " : " ); } InterfaceOptions_LBL->setText( S ); connect( &RefreshTimer, SIGNAL( timeout() ), this, SLOT( SLOT_Refresh() ) ); } } QString ProfileEdit::acceptable( void ) { return QString(); } -void ProfileEdit::showData( ProfileData_t & Data ) { +void ProfileEdit::showData( ProfileData & Data ) { Description_LE->setText( Data.Description ); Automatic_CB->setChecked( Data.Automatic ); TriggersVPN_CB->setChecked( Data.TriggerVPN ); Confirm_CB->setChecked( Data.Confirm ); Disabled_CB->setChecked( Data.Disabled ); } -bool ProfileEdit::commit( ProfileData_t & Data ) { +bool ProfileEdit::commit( ProfileData & Data ) { bool SM = 0; TXTM( Data.Description, Description_LE, SM ); CBM( Data.Automatic, Automatic_CB, SM ); CBM( Data.TriggerVPN, TriggersVPN_CB, SM ); CBM( Data.Disabled, Disabled_CB, SM ); CBM( Data.Confirm, Confirm_CB, SM ); return SM; } void ProfileEdit::SLOT_Refresh( void ) { - InterfaceInfo * II = Dev->assignedInterface(); + InterfaceInfo * II = NNI->connection()->assignedInterface(); NSResources->system().refreshStatistics( *II ); RcvBytes_LBL->setText( II->RcvBytes ); SndBytes_LBL->setText( II->SndBytes ); RcvErrors_LBL->setText( II->RcvErrors ); SndErrors_LBL->setText( II->SndErrors ); RcvDropped_LBL->setText( II->RcvDropped ); SndDropped_LBL->setText( II->SndDropped ); Collisions_LBL->setText( II->Collisions ); } void ProfileEdit::SLOT_AutoRefresh( bool ar ) { if( ar ) { RefreshTimer.start( 1000 ); SLOT_Refresh(); } else { RefreshTimer.stop(); } } diff --git a/noncore/settings/networksettings2/profile/profileedit.h b/noncore/settings/networksettings2/profile/profileedit.h index b186b58..9cde845 100644 --- a/noncore/settings/networksettings2/profile/profileedit.h +++ b/noncore/settings/networksettings2/profile/profileedit.h @@ -1,29 +1,29 @@ #include "profiledata.h" #include "profileGUI.h" #include <qtimer.h> class ANetNodeInstance; -class AsDevice; +class RuntimeInfo; class ProfileEdit : public ProfileGUI { Q_OBJECT public : ProfileEdit( QWidget * parent, ANetNodeInstance * NNI ); QString acceptable( void ); - bool commit( ProfileData_t & Data ); - void showData( ProfileData_t & Data ); + bool commit( ProfileData & Data ); + void showData( ProfileData & Data ); public slots : void SLOT_AutoRefresh( bool ); void SLOT_Refresh( void ); private : QTimer RefreshTimer; ANetNodeInstance * NNI; - AsDevice * Dev; + RuntimeInfo * Dev; }; diff --git a/noncore/settings/networksettings2/profile/profilerun.cpp b/noncore/settings/networksettings2/profile/profilerun.cpp index 1a5b15b..ab57a00 100644 --- a/noncore/settings/networksettings2/profile/profilerun.cpp +++ b/noncore/settings/networksettings2/profile/profilerun.cpp @@ -1,67 +1,27 @@ #include <resources.h> #include "profilerun.h" -void ProfileRun::detectState( NodeCollection * NC ) { +State_t ProfileRun::detectState( void ) { if( Data->Disabled ) { - Log(( "%s disabled\n", NC->name().latin1() )); - NC->setCurrentState( Disabled ); - } else { - Log(( "%s not disabled\n", NC->name().latin1() )); - // find next item in connection - // convert to runtime and ask to detect the state - netNode()->nextNode()->runtime()->detectState( NC ); + return Disabled; } + return Unknown; } -bool ProfileRun::setState( NodeCollection * NC, Action_t A, bool F ) { - ANetNodeInstance * NNNI; - - NNNI = netNode()->nextNode(); - switch ( A ) { - case Enable : - if( NC->currentState() == Disabled ) { - Data->Disabled = 0; - NC->setCurrentState( Off ); // at least - // ... but request deeper - NNNI->runtime()->detectState(NC); - } - return 1; - case Disable : - switch( NC->currentState() ) { - case IsUp : - case Available : - // bring Deactivate (will bring down) - if( ! NNNI->runtime()->setState(NC, Deactivate) ) - return 0; - default : - break; - } +QString ProfileRun::setMyState( NodeCollection * NC, Action_t A, bool ) { + owarn << "Profile " << Data->Disabled << oendl; + if( A == Disable ) { + if( ! Data->Disabled ) { Data->Disabled = 1; - NC->setCurrentState( Disabled ); - return 1; - default : - break; + NC->setModified( 1 ); } - return NNNI->runtime()->setState(NC, A, F ); -} - -bool ProfileRun::canSetState( State_t Curr, Action_t A ) { - RuntimeInfo * RI; - switch ( A ) { - case Enable : - case Disable : - // always possible - return 1; - default : - break; + } else if( A == Enable ) { + if( Data->Disabled ) { + Data->Disabled = 0; + NC->setModified( 1 ); } - RI = netNode()->nextNode()->runtime(); - return ( Curr != Disabled ) ? - RI->canSetState(Curr, A) : 0; } -bool ProfileRun::handlesInterface( const QString & S ) { - // donno -> pass deeper - return netNode()->nextNode()->runtime()->handlesInterface(S); + return QString(); } diff --git a/noncore/settings/networksettings2/profile/profilerun.h b/noncore/settings/networksettings2/profile/profilerun.h index 400b56c..2d48b15 100644 --- a/noncore/settings/networksettings2/profile/profilerun.h +++ b/noncore/settings/networksettings2/profile/profilerun.h @@ -1,35 +1,33 @@ #ifndef PROFILERUN_H #define PROFILERUN_H -#include <asfullsetup.h> +#include <netnode.h> #include "profiledata.h" -class ProfileRun : public AsFullSetup { +class ProfileRun : public RuntimeInfo { public : ProfileRun( ANetNodeInstance * NNI, ProfileData & D ) : - AsFullSetup( NNI ) + RuntimeInfo( NNI ) { Data = &D; } - void detectState( NodeCollection * NC ); - bool setState( NodeCollection * NC, Action_t A, bool ); - bool canSetState( State_t Curr, Action_t A ); - - bool handlesInterface( const QString & I ); - + virtual RuntimeInfo * fullSetup( void ) + { return this; } virtual const QString & description( void ) { return Data->Description; } - - virtual AsFullSetup * asFullSetup( void ) - { return (AsFullSetup *)this; } - virtual bool triggersVPN( void ) { return Data->TriggerVPN; } + State_t detectState( void ); + +protected : + + QString setMyState( NodeCollection * , Action_t, bool ); + private : ProfileData * Data; }; #endif diff --git a/noncore/settings/networksettings2/usb/opie-networksettings2plugin-usb.control b/noncore/settings/networksettings2/usb/opie-networksettings2plugin-usb.control index 8b8508c..ffb3012 100644 --- a/noncore/settings/networksettings2/usb/opie-networksettings2plugin-usb.control +++ b/noncore/settings/networksettings2/usb/opie-networksettings2plugin-usb.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-usb +Package: opie-networksettings2plugin-usb Files: plugins/networksettings2/libusb.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings usb plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index 14c479a..bd9ae2b 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -1,54 +1,62 @@ +#include <resources.h> #include "usb_NN.h" #include "usb_NNI.h" static const char * USBNeeds[] = { 0 }; +static const char * USBProvides[] = + { "device", + 0 + }; + /** * Constructor, find all of the possible interfaces */ USBNetNode::USBNetNode() : ANetNode(tr("USB Cable Connect")) { + NSResources->addSystemFile( + "interfaces", "/etc/network/interfaces", 1 ); } /** * Delete any interfaces that we own. */ USBNetNode::~USBNetNode(){ } const QString USBNetNode::nodeDescription(){ return tr("\ <p>Configure Ethernet over USB.</p>\ <p>Use this for a computer to computer USB cable connection</p>\ " ); } ANetNodeInstance * USBNetNode::createInstance( void ) { return new AUSB( this ); } const char ** USBNetNode::needs( void ) { return USBNeeds; } -const char * USBNetNode::provides( void ) { - return "device"; +const char ** USBNetNode::provides( void ) { + return USBProvides; } QString USBNetNode::genNic( long ) { return QString( "usbf" ); } void USBNetNode::setSpecificAttribute( QString & , QString & ) { } void USBNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new USBNetNode() ); } } diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h index 73da15a..b825cec 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.h +++ b/noncore/settings/networksettings2/usb/usb_NN.h @@ -1,38 +1,38 @@ #ifndef USB_NETNODE_H #define USB_NETNODE_H #include "netnode.h" class AUSB; class USBNetNode : public ANetNode{ Q_OBJECT public: USBNetNode(); virtual ~USBNetNode(); virtual const QString pixmapName() { return "Devices/usb"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); virtual QString genNic( long nr ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp index 50c6e8d..600b771 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.cpp +++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp @@ -1,61 +1,59 @@ #include <qpe/qpeapplication.h> #include "usbedit.h" #include "usb_NNI.h" #include "usb_NN.h" AUSB::AUSB( USBNetNode * PNN ) : ANetNodeInstance( PNN ) { GUI = 0; RT = 0; } void AUSB::setSpecificAttribute( QString & , QString & ) { } void AUSB::saveSpecificAttribute( QTextStream & ) { } QWidget * AUSB::edit( QWidget * parent ) { GUI = new USBEdit( parent ); GUI->showData( Data ); return GUI; } QString AUSB::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AUSB::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } -short AUSB::generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, +short AUSB::generateFileEmbedded( SystemFile & SF, long DevNr ) { QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); short rvl, rvd; rvl = 1; - if( ID == "interfaces" ) { - Log(("Generate USB for %s\n", ID.latin1() )); + if( SF.name() == "interfaces" ) { + Log(("Generate USB for %s\n", SF.name().latin1() )); // generate mapping stanza for this interface - TS << " pre-up " + SF << " pre-up " << QPEApplication::qpeDir() << "bin/setmacaddress.sh " << NIC << " || true" << endl; rvl = 0; } - rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + rvd = ANetNodeInstance::generateFileEmbedded(SF, DevNr ); return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h index fcdfd91..27e71ee 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.h +++ b/noncore/settings/networksettings2/usb/usb_NNI.h @@ -1,46 +1,44 @@ #ifndef USB_H #define USB_H #include <netnode.h> #include "usbdata.h" #include "usbrun.h" class USBNetNode; class USBEdit; class AUSB : public ANetNodeInstance { public : AUSB( USBNetNode * PNN ); RuntimeInfo * runtime( void ) { return ( RT ) ? RT : ( RT = new USBRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); virtual void * data( void ) { return (void *)&Data; } - virtual short generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, + virtual short generateFileEmbedded( SystemFile & TS, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : USBEdit * GUI; USBData Data; USBRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/usb/usbdata.h b/noncore/settings/networksettings2/usb/usbdata.h index c59f508..fa357b5 100644 --- a/noncore/settings/networksettings2/usb/usbdata.h +++ b/noncore/settings/networksettings2/usb/usbdata.h @@ -1,8 +1,9 @@ #ifndef USB_DATA_H #define USB_DATA_H -typedef struct USBData { +class USBData { +public : bool Fake; -} USBData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/usb/usbedit.cpp b/noncore/settings/networksettings2/usb/usbedit.cpp index 153c497..cc96b96 100644 --- a/noncore/settings/networksettings2/usb/usbedit.cpp +++ b/noncore/settings/networksettings2/usb/usbedit.cpp @@ -1,17 +1,17 @@ #include <GUIUtils.h> #include "usbedit.h" USBEdit::USBEdit( QWidget * Parent ) : USBGUI( Parent ){ } QString USBEdit::acceptable( void ) { return QString(); } -void USBEdit::showData( USBData_t & Data ) { +void USBEdit::showData( USBData & Data ) { } -bool USBEdit::commit( USBData_t & Data ) { +bool USBEdit::commit( USBData & Data ) { return 1; } diff --git a/noncore/settings/networksettings2/usb/usbedit.h b/noncore/settings/networksettings2/usb/usbedit.h index 441f2f0..4179898 100644 --- a/noncore/settings/networksettings2/usb/usbedit.h +++ b/noncore/settings/networksettings2/usb/usbedit.h @@ -1,12 +1,12 @@ #include "usbdata.h" #include "usbGUI.h" class USBEdit : public USBGUI { public : USBEdit( QWidget * parent ); QString acceptable( void ); - bool commit( USBData_t & Data ); - void showData( USBData_t & Data ); + bool commit( USBData & Data ); + void showData( USBData & Data ); }; diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index b8ac8a8..f8824e0 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -1,178 +1,112 @@ #include <qfile.h> #include <qfileinfo.h> #include <qtextstream.h> #include <resources.h> #include "usbrun.h" -void USBRun::detectState( NodeCollection * NC ) { +State_t USBRun::detectState( void ) { // unavailable : no card found // available : card found and assigned to us or free // up : card found and assigned to us and up + NodeCollection * NC = nodeCollection(); QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); System & Sys = NSResources->system(); InterfaceInfo * Run; QFile F( S ); Log(("Detecting for %s\n", NC->name().latin1() )); if( F.open( IO_ReadOnly ) ) { // could open file -> read interface and assign QString X; QTextStream TS(&F); X = TS.readLine(); Log(("%s exists\n", S.latin1() )); // find interface if( handlesInterface( X ) ) { for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( X == Run->Name ) { - Run->assignNode( netNode() ); - assignInterface( Run ); - NC->setCurrentState( IsUp ); - return; + NC->assignInterface( Run ); + return IsUp; } } } } - Log(("Assigned %p\n", assignedInterface() )); - if( ( Run = assignedInterface() ) ) { + Log(("Assigned %p\n", NC->assignedInterface() )); + if( ( Run = NC->assignedInterface() ) ) { // we already have an interface assigned -> still present ? if( ! Run->IsUp ) { // usb is still free -> keep assignment - NC->setCurrentState( Available ); - return; + return Available; } // else interface is up but NOT us -> some other profile } // nothing (valid) assigned to us - assignInterface( 0 ); + NC->assignInterface( 0 ); // find possible interface for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); Log(("%s %d %d=%d %d\n", Run->Name.latin1(), handlesInterface( Run->Name ), Run->CardType, ARPHRD_ETHER, ! Run->IsUp )); if( handlesInterface( Run->Name ) && Run->CardType == ARPHRD_ETHER && ! Run->IsUp ) { - Log(("Released(OFF)\n" )); // proper type, and Not UP -> free - NC->setCurrentState( Off ); - return; + return Off; } } - // no free found - Log(("UNA\n" )); - NC->setCurrentState( Unavailable ); + return Unavailable; } -bool USBRun::setState( NodeCollection * NC, Action_t A, bool ) { - - // we only handle activate and deactivate - switch( A ) { - case Activate : - { - if( NC->currentState() != Off ) { - return 0; - } - InterfaceInfo * N = getInterface(); - if( ! N ) { - // no interface available - NC->setCurrentState( Unavailable ); - return 0; - } - // because we were OFF the interface - // we get back is NOT assigned - N->assignNode( netNode() ); - assignInterface( N ); - Log(("Assing %p\n", N )); - NC->setCurrentState( Available ); - return 1; - } - case Deactivate : - if( NC->currentState() == IsUp ) { - // bring down first - if( ! connection()->setState( Down ) ) - // could not ... - return 0; - } else if( NC->currentState() != Available ) { - return 1; - } - assignedInterface()->assignNode( 0 ); // release - assignInterface( 0 ); - NC->setCurrentState( Off ); - return 1; - default : - // FT - break; - } - return 0; -} - -bool USBRun::canSetState( State_t Curr, Action_t A ) { - // we only handle up down activate and deactivate - switch( A ) { - case Activate : - { // at least available - if( Curr == Available ) { - return 1; - } - // or we can make one available - InterfaceInfo * N = getInterface(); - if( ! N || N->assignedNode() != 0 ) { - // non available or assigned - return 0; - } - return 1; - } - case Deactivate : - return ( Curr >= Available ); - default : - // FT - break; - } - return 0; +QString USBRun::setMyState( NodeCollection *, Action_t , bool ) { + return QString(); } // get interface that is free or assigned to us InterfaceInfo * USBRun::getInterface( void ) { System & S = NSResources->system(); InterfaceInfo * best = 0, * Run; QRegExp R( "usb[0-9abcdef]" ); for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( Run->Name ) && Run->CardType == ARPHRD_ETHER ) { // this is a USB card - if( Run->assignedNode() == netNode() ) { + if( Run->assignedConnection() == netNode()->connection() ) { // assigned to us return Run; - } else if( Run->assignedNode() == 0 ) { + } else if( Run->assignedConnection() == 0 ) { // free best = Run; } } } return best; // can be 0 } bool USBRun::handlesInterface( const QString & S ) { return Pat.match( S ) >= 0; } +bool USBRun::handlesInterface( InterfaceInfo * I ) { + return handlesInterface( I->Name ); +} + diff --git a/noncore/settings/networksettings2/usb/usbrun.h b/noncore/settings/networksettings2/usb/usbrun.h index 03e21ab..6ce4fa2 100644 --- a/noncore/settings/networksettings2/usb/usbrun.h +++ b/noncore/settings/networksettings2/usb/usbrun.h @@ -1,37 +1,36 @@ #ifndef USBRUN_H #define USBRUN_H -#include <asdevice.h> +#include <netnode.h> #include <qregexp.h> #include "usbdata.h" -class USBRun : public AsDevice { +class USBRun : public RuntimeInfo { public : USBRun( ANetNodeInstance * NNI, USBData & Data ) : - AsDevice( NNI ), - Pat( "usb[0-9abcdef]" ) - { } + RuntimeInfo( NNI ), + Pat( "usb[0-9abcdef]" ) { + } - virtual AsDevice * device( void ) - { return (AsDevice *)this; } + virtual RuntimeInfo * device( void ) + { return this; } - virtual AsDevice * asDevice( void ) - { return (AsDevice *)this; } -protected : + bool handlesInterface( const QString & I ); + bool handlesInterface( InterfaceInfo * ); - void detectState( NodeCollection * ); - bool setState( NodeCollection * , Action_t A, bool ); - bool canSetState( State_t , Action_t A ); + State_t detectState( void ); - bool handlesInterface( const QString & I ); +protected : + + QString setMyState( NodeCollection * , Action_t, bool ); private : InterfaceInfo * getInterface( void ); QRegExp Pat; }; #endif diff --git a/noncore/settings/networksettings2/vpn/opie-networksettings2plugin-vpn.control b/noncore/settings/networksettings2/vpn/opie-networksettings2plugin-vpn.control index b346c5d..08f131f 100644 --- a/noncore/settings/networksettings2/vpn/opie-networksettings2plugin-vpn.control +++ b/noncore/settings/networksettings2/vpn/opie-networksettings2plugin-vpn.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-vpn +Package: opie-networksettings2plugin-vpn Files: plugins/networksettings2/libvpn.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings vpn plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/vpn/vpn_NN.cpp b/noncore/settings/networksettings2/vpn/vpn_NN.cpp index 9d3b6e7..23ec04a 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.cpp +++ b/noncore/settings/networksettings2/vpn/vpn_NN.cpp @@ -1,50 +1,54 @@ #include "vpn_NN.h" #include "vpn_NNI.h" static const char * VPNNeeds[] = { 0 }; +static const char * VPNProvides[] = + { "connection", + 0 + }; /** * Constructor, find all of the possible interfaces */ VPNNetNode::VPNNetNode() : ANetNode(tr("VPN Connection")) { } /** * Delete any interfaces that we own. */ VPNNetNode::~VPNNetNode(){ } const QString VPNNetNode::nodeDescription(){ return tr("\ <p>Configure private IP connection.</p>\ <p>Defines Secure tunnels over non secure IP sessions</p>\ " ); } ANetNodeInstance * VPNNetNode::createInstance( void ) { return new AVPN( this ); } const char ** VPNNetNode::needs( void ) { return VPNNeeds; } -const char * VPNNetNode::provides( void ) { - return "connection"; +const char ** VPNNetNode::provides( void ) { + return VPNProvides; } void VPNNetNode::setSpecificAttribute( QString & , QString & ) { } void VPNNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new VPNNetNode() ); } } diff --git a/noncore/settings/networksettings2/vpn/vpn_NN.h b/noncore/settings/networksettings2/vpn/vpn_NN.h index 3c7b5e0..c2e43d4 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.h +++ b/noncore/settings/networksettings2/vpn/vpn_NN.h @@ -1,36 +1,36 @@ #ifndef VPN_NETNODE_H #define VPN_NETNODE_H #include "netnode.h" class AVPN; class VPNNetNode : public ANetNode{ Q_OBJECT public: VPNNetNode(); virtual ~VPNNetNode(); virtual const QString pixmapName() { return "Devices/vpn"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/vpn/vpndata.h b/noncore/settings/networksettings2/vpn/vpndata.h index 5c986aa..ee88bc4 100644 --- a/noncore/settings/networksettings2/vpn/vpndata.h +++ b/noncore/settings/networksettings2/vpn/vpndata.h @@ -1,16 +1,17 @@ #ifndef VPN_DATA_H #define VPN_DATA_H #include <qstring.h> -typedef struct VPNData { +class VPNData { +public : QString Device; QString LockFile; long Speed; short Parity; short DataBits; short StopBits; bool HardwareControl; bool SoftwareControl; -} VPNData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/vpn/vpnedit.cpp b/noncore/settings/networksettings2/vpn/vpnedit.cpp index f336394..8445757 100644 --- a/noncore/settings/networksettings2/vpn/vpnedit.cpp +++ b/noncore/settings/networksettings2/vpn/vpnedit.cpp @@ -1,18 +1,18 @@ #include <GUIUtils.h> #include "vpnedit.h" VPNEdit::VPNEdit( QWidget * Parent ) : VPNGUI( Parent ){ } QString VPNEdit::acceptable( void ) { return QString(); } -void VPNEdit::showData( VPNData_t & Data ) { +void VPNEdit::showData( VPNData & Data ) { } -bool VPNEdit::commit( VPNData_t & Data ) { +bool VPNEdit::commit( VPNData & Data ) { return 0; } diff --git a/noncore/settings/networksettings2/vpn/vpnedit.h b/noncore/settings/networksettings2/vpn/vpnedit.h index 76480cd..156bcc5 100644 --- a/noncore/settings/networksettings2/vpn/vpnedit.h +++ b/noncore/settings/networksettings2/vpn/vpnedit.h @@ -1,12 +1,12 @@ #include "vpndata.h" #include "vpnGUI.h" class VPNEdit : public VPNGUI { public : VPNEdit( QWidget * parent ); QString acceptable( void ); - bool commit( VPNData_t & Data ); - void showData( VPNData_t & Data ); + bool commit( VPNData & Data ); + void showData( VPNData & Data ); }; diff --git a/noncore/settings/networksettings2/vpn/vpnrun.cpp b/noncore/settings/networksettings2/vpn/vpnrun.cpp index ab2966c..64728aa 100644 --- a/noncore/settings/networksettings2/vpn/vpnrun.cpp +++ b/noncore/settings/networksettings2/vpn/vpnrun.cpp @@ -1,6 +1 @@ #include "vpnrun.h" - -bool VPNRun::handlesInterface( const QString & ) { - // to be figured out - return 0; -} diff --git a/noncore/settings/networksettings2/vpn/vpnrun.h b/noncore/settings/networksettings2/vpn/vpnrun.h index c19b609..9a55625 100644 --- a/noncore/settings/networksettings2/vpn/vpnrun.h +++ b/noncore/settings/networksettings2/vpn/vpnrun.h @@ -1,32 +1,27 @@ #ifndef VPNRUN_H #define VPNRUN_H -#include <asconnection.h> +#include <netnode.h> #include "vpndata.h" -class VPNRun : public AsConnection { +class VPNRun : public RuntimeInfo { public : VPNRun( ANetNodeInstance * NNI, VPNData & Data ) : - AsConnection( NNI ) + RuntimeInfo( NNI ) { } - virtual AsConnection * asConnection( void ) - { return (AsConnection *)this; } -protected : - - void detectState( NodeCollection * ) - { } + virtual RuntimeInfo * connection( void ) + { return this; } - bool setState( NodeCollection *, Action_t, bool ) - { return 0; } + State_t detectState( void ) + { return Unknown; } - bool canSetState( State_t, Action_t ) - { return 0; } - - bool handlesInterface( const QString & I ); +protected : + QString setMyState( NodeCollection * , Action_t, bool ) + { return QString(); } }; #endif diff --git a/noncore/settings/networksettings2/wlan/opie-networksettings2plugin-wlan.control b/noncore/settings/networksettings2/wlan/opie-networksettings2plugin-wlan.control index 14afd21..90f195a 100644 --- a/noncore/settings/networksettings2/wlan/opie-networksettings2plugin-wlan.control +++ b/noncore/settings/networksettings2/wlan/opie-networksettings2plugin-wlan.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-wlan +Package: opie-networksettings2plugin-wlan Files: plugins/networksettings2/libwlan.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings wlan plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.cpp b/noncore/settings/networksettings2/wlan/wlan_NN.cpp index e4c3f60..36a5c33 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NN.cpp @@ -1,62 +1,70 @@ +#include <resources.h> #include "wlan_NN.h" #include "wlan_NNI.h" static const char * WLanNeeds[] = { 0 }; +static const char * WLanProvides[] = + { "device", + 0 + }; + /** * Constructor, find all of the possible interfaces */ WLanNetNode::WLanNetNode() : ANetNode(tr("WLan Device")) { + NSResources->addSystemFile( + "interfaces", "/etc/network/interfaces", 1 ); InstanceCount = 2; } /** * Delete any interfaces that we own. */ WLanNetNode::~WLanNetNode(){ } const QString WLanNetNode::nodeDescription(){ return tr("\ <p>Configure Wi/Fi or WLan network cards.</p>\ <p>Defines Wireless options for those cards</p>\ " ); } ANetNodeInstance * WLanNetNode::createInstance( void ) { return new AWLan( this ); } const char ** WLanNetNode::needs( void ) { return WLanNeeds; } -const char * WLanNetNode::provides( void ) { - return "device"; +const char ** WLanNetNode::provides( void ) { + return WLanProvides; } QString WLanNetNode::genNic( long nr ) { QString S; return S.sprintf( "wlan%ld", nr ); } void WLanNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { InstanceCount = V.toLong(); } } void WLanNetNode::saveSpecificAttribute( QTextStream & TS ) { TS << "interfacecount=" << InstanceCount << endl; } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new WLanNetNode() ); } } diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.h b/noncore/settings/networksettings2/wlan/wlan_NN.h index c13c05c..4bffd3d 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.h +++ b/noncore/settings/networksettings2/wlan/wlan_NN.h @@ -1,44 +1,44 @@ #ifndef WLAN_NETNODE_H #define WLAN_NETNODE_H #include "netnode.h" class AWLan; class WLanNetNode : public ANetNode{ Q_OBJECT public: WLanNetNode(); virtual ~WLanNetNode(); virtual const QString pixmapName() { return "Devices/wlan"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); virtual long instanceCount( void ) { return InstanceCount; } virtual QString genNic( long ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); // number of interfaces for this device long InstanceCount; }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp index 0e4fc4c..d5b1014 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp @@ -1,151 +1,149 @@ #include <unistd.h> #include "wlanedit.h" #include "wlan_NNI.h" #include "wlan_NN.h" AWLan::AWLan( WLanNetNode * PNN ) : ANetNodeInstance( PNN ) { GUI = 0; RT = 0; Data.ESSID = ""; Data.NodeName = tr("<UseHostName>"); Data.Mode = 0; Data.SpecificAP = 0; Data.APMac = ""; Data.Encrypted = 0; Data.AcceptNonEncrypted = 0; Data.Key[0] = ""; Data.Key[1] = ""; Data.Key[2] = ""; Data.Key[3] = ""; } void AWLan::setSpecificAttribute( QString & A, QString & V ) { if( A == "essid" ) { Data.ESSID = V; } else if( A == "nodename" ) { Data.NodeName = V; } else if( A == "mode" ) { Data.Mode = V.toShort(); } else if( A == "specificap" ) { Data.SpecificAP = (V=="yes"); } else if( A == "apmac" ) { Data.APMac = V; } else if( A == "encrypted" ) { Data.Encrypted = (V=="yes"); } else if( A == "acceptnonencrypted" ) { Data.AcceptNonEncrypted = (V=="yes"); } else if( A == "key0" ) { Data.Key[0] = V; } else if( A == "key1" ) { Data.Key[1] = V; } else if( A == "key2" ) { Data.Key[2] = V; } else if( A == "key3" ) { Data.Key[3] = V; } } void AWLan::saveSpecificAttribute( QTextStream & S ) { S << "essid=" << quote( Data.ESSID ) << endl; S << "nodename=" << quote( Data.NodeName ) << endl; S << "mode=" << Data.Mode << endl; S << "specificap=" << ((Data.SpecificAP) ? "yes" : "no") << endl; S << "apmac=" << Data.APMac << endl; S << "encrypted=" << ((Data.Encrypted) ? "yes" : "no") << endl; S << "acceptnonencrypted=" << ((Data.AcceptNonEncrypted) ? "yes" : "no") << endl; for( int i = 0 ;i < 4 ; i ++ ) { S << "key" << i << "=" << Data.Key[i] << endl; } } QWidget * AWLan::edit( QWidget * parent ) { GUI = new WLanEdit( parent, this ); GUI->showData( Data ); return GUI; } QString AWLan::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AWLan::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -short AWLan::generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, +short AWLan::generateFileEmbedded( SystemFile & SF, long DevNr ) { short rvl, rvd; rvl = 1; - if( ID == "interfaces" ) { - Log(("Generate WLanNNI for %s\n", ID.latin1() )); - TS << " wireless_essid \"" + if( SF.name() == "interfaces" ) { + Log(("Generate WLanNNI for %s\n", SF.name().latin1() )); + SF << " wireless_essid \"" << Data.ESSID << "\"" << endl; if( ! Data.NodeName.isEmpty() ) { if( Data.NodeName == tr("<UseHostName>") ) { char Buf[100]; if( gethostname(Buf, sizeof(Buf) ) == 0 ) { Buf[99] = '\0'; // just to make sure - TS << " wireless_nick " + SF << " wireless_nick " << Buf << endl; } } else { - TS << " wireless_nick \"" + SF << " wireless_nick \"" << Data.NodeName << "\"" << endl; } } char * M = "Auto"; switch ( Data.Mode ) { case 0 : break; case 1 : M = "Managed"; break; case 2 : M = "Ad-Hoc"; break; } - TS << " wireless_mode " + SF << " wireless_mode " << M << endl; if( Data.Encrypted ) { for( int i = 0; i < 4; i ++ ) { if( ! Data.Key[i].isEmpty() ) { - TS << " wireless_key" + SF << " wireless_key" << i << " " << Data.Key[i] << endl; } } - TS << " wireless_keymode " + SF << " wireless_keymode " << ((Data.AcceptNonEncrypted) ? "open" : "restricted") << endl; } rvl = 0; } - rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr); + rvd = ANetNodeInstance::generateFileEmbedded( SF, DevNr); return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.h b/noncore/settings/networksettings2/wlan/wlan_NNI.h index a9be65f..e3251c7 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.h +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.h @@ -1,47 +1,45 @@ #ifndef WLAN_H #define WLAN_H #include <netnode.h> #include "wlandata.h" #include "wlanrun.h" class WLanNetNode; class WLanEdit; class AWLan : public ANetNodeInstance { public : AWLan( WLanNetNode * PNN ); RuntimeInfo * runtime( void ) { return ( RT ) ? RT : ( RT = new WLanRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); virtual void * data( void ) { return (void *)&Data; } - virtual short generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, + virtual short generateFileEmbedded( SystemFile & Sf, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : WLanEdit * GUI; WLanData Data; WLanRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/wlan/wlandata.h b/noncore/settings/networksettings2/wlan/wlandata.h index 36990a9..f3cc1ab 100644 --- a/noncore/settings/networksettings2/wlan/wlandata.h +++ b/noncore/settings/networksettings2/wlan/wlandata.h @@ -1,16 +1,17 @@ #ifndef WLAN_DATA_H #define WLAN_DATA_H #include <qstring.h> -typedef struct WLanData { +class WLanData { +public : QString ESSID; QString NodeName; short Mode; bool SpecificAP; QString APMac; bool Encrypted; QString Key[4]; bool AcceptNonEncrypted; -} WLanData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/wlan/wlanedit.cpp b/noncore/settings/networksettings2/wlan/wlanedit.cpp index 8d3979e..74174bf 100644 --- a/noncore/settings/networksettings2/wlan/wlanedit.cpp +++ b/noncore/settings/networksettings2/wlan/wlanedit.cpp @@ -1,115 +1,115 @@ #include <qlineedit.h> #include <qprogressbar.h> #include <qcombobox.h> #include <qlabel.h> #include <qregexp.h> #include <qcheckbox.h> #include <GUIUtils.h> #include <resources.h> #include <wextensions.h> #include "wlanedit.h" #include "wlan_NN.h" #include "wlan_NNI.h" WLanEdit::WLanEdit( QWidget * Parent, ANetNodeInstance * TNNI ) : WLanGUI( Parent ), RefreshTimer(this){ InterfaceInfo * II; NNI = TNNI; Dev = NNI->runtime()->device(); WE = 0; - if( ( II = Dev->assignedInterface() ) ) { + if( ( II = NNI->connection()->assignedInterface() ) ) { // show data WE = new WExtensions( II->Name ); if( WE->doesHaveWirelessExtensions() ) { QString S; Station_LBL->setText( WE->station() ); ESSID_LBL->setText( WE->essid() ); Mode_LBL->setText( WE->mode() ); S.setNum( WE->frequency() ); Frequency_LBL->setText( S ); S.setNum( WE->channel() ); Channel_LBL->setText( S ); S.setNum( WE->rate() ); Rate_LBL->setText( S ); AP_LBL->setText( WE->ap() ); SLOT_Refresh(); connect( &RefreshTimer, SIGNAL( timeout() ), this, SLOT( SLOT_Refresh() ) ); } } } WLanEdit::~WLanEdit( void ) { if( WE ) delete WE; } QString WLanEdit::acceptable( void ) { if( ESSID_LE->text().isEmpty() ) { return QString("ESSID is mandatory"); } if( SpecifyAP_CB->isChecked() && APMac_LE->text().isEmpty() ) { return QString("APMac must have value"); } return QString(); } -void WLanEdit::showData( WLanData_t & Data ) { +void WLanEdit::showData( WLanData & Data ) { Mode_CB->setCurrentItem( Data.Mode ); ESSID_LE->setText( Data.ESSID ); NodeName_LE->setText( Data.NodeName ); SpecifyAP_CB->setChecked( Data.SpecificAP ); APMac_LE->setText( Data.APMac ); EnableWEP_CB->setChecked( Data.Encrypted ); AcceptNonEncrypted_CB->setChecked( Data.AcceptNonEncrypted ); Key1_LE->setText( Data.Key[0] ); Key2_LE->setText( Data.Key[1] ); Key3_LE->setText( Data.Key[2] ); Key4_LE->setText( Data.Key[3] ); } -bool WLanEdit::commit( WLanData_t & Data ) { +bool WLanEdit::commit( WLanData & Data ) { bool SM = 0; TXTM( Data.ESSID, ESSID_LE, SM ); TXTM( Data.NodeName, NodeName_LE, SM ); TXTM( Data.APMac, APMac_LE, SM ); TXTM( Data.Key[0], Key1_LE, SM ); TXTM( Data.Key[1], Key2_LE, SM ); TXTM( Data.Key[2], Key3_LE, SM ); TXTM( Data.Key[3], Key4_LE, SM ); CBM( Data.SpecificAP, SpecifyAP_CB, SM ); CBM( Data.Encrypted, EnableWEP_CB, SM ); CBM( Data.AcceptNonEncrypted, AcceptNonEncrypted_CB, SM ); CIM( Data.Mode, Mode_CB, SM ); return 0; } void WLanEdit::SLOT_Refresh( void ) { if( WE ) { int signal, noise, quality; WE->stats( signal, noise, quality); Signal_PB->setProgress( signal ); Noise_PB->setProgress( noise ); Quality_PB->setProgress( quality ); } } void WLanEdit::SLOT_AutoRefresh( bool ar ) { if( ar ) { RefreshTimer.start( 1000 ); SLOT_Refresh(); } else { RefreshTimer.stop(); } } diff --git a/noncore/settings/networksettings2/wlan/wlanedit.h b/noncore/settings/networksettings2/wlan/wlanedit.h index e550c14..8f219d9 100644 --- a/noncore/settings/networksettings2/wlan/wlanedit.h +++ b/noncore/settings/networksettings2/wlan/wlanedit.h @@ -1,32 +1,32 @@ #include <qtimer.h> #include <wextensions.h> #include "wlandata.h" #include "wlanGUI.h" class ANetNodeInstance; -class AsDevice; +class RuntimeInfo; class WExtensions; class WLanEdit : public WLanGUI { public : WLanEdit( QWidget * parent, ANetNodeInstance * NNI ); ~WLanEdit( void ); QString acceptable( void ); - void showData( WLanData_t & Data ); - bool commit( WLanData_t & Data ); + void showData( WLanData & Data ); + bool commit( WLanData & Data ); public slots : void SLOT_AutoRefresh( bool ); void SLOT_Refresh( void ); private : ANetNodeInstance * NNI; - AsDevice * Dev; + RuntimeInfo * Dev; QTimer RefreshTimer; WExtensions * WE; }; diff --git a/noncore/settings/networksettings2/wlan/wlanrun.cpp b/noncore/settings/networksettings2/wlan/wlanrun.cpp index 3f1d4a9..fe49c4e 100644 --- a/noncore/settings/networksettings2/wlan/wlanrun.cpp +++ b/noncore/settings/networksettings2/wlan/wlanrun.cpp @@ -1,185 +1,120 @@ #include <qfile.h> #include <qtextstream.h> #include <qstringlist.h> #include <resources.h> #include "wlanrun.h" -void WLanRun::detectState( NodeCollection * NC ) { +State_t WLanRun::detectState( void ) { // unavailable : no card found // available : card found and assigned to us or free // up : card found and assigned to us and up + NodeCollection * NC = nodeCollection(); QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); System & Sys = NSResources->system(); InterfaceInfo * Run; QFile F( S ); if( F.open( IO_ReadOnly ) ) { // could open file -> read interface and assign QString X; QTextStream TS(&F); X = TS.readLine(); // find interface if( handlesInterface( X ) ) { for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( X == Run->Name ) { - Run->assignNode( netNode() ); - assignInterface( Run ); - NC->setCurrentState( IsUp ); - return; + NC->assignInterface( Run ); + return IsUp; } } } } - if( ( Run = assignedInterface() ) ) { + if( ( Run = NC->assignedInterface() ) ) { // we already have an interface assigned -> still present ? if( ! Run->IsUp ) { // usb is still free -> keep assignment - NC->setCurrentState( Available ); - return; + return Available; } // else interface is up but NOT us -> some other profile } // nothing (valid) assigned to us - assignInterface( 0 ); + NC->assignInterface( 0 ); // find possible interface for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( *Run ) && ( Run->CardType == ARPHRD_ETHER #ifdef ARPHRD_IEEE1394 || Run->CardType == ARPHRD_IEEE1394 #endif ) && ! Run->IsUp ) { // proper type, and Not UP -> free - NC->setCurrentState( Off ); - return; + return Off; } } - // no free found - NC->setCurrentState( Unavailable ); + return Unavailable; } -bool WLanRun::setState( NodeCollection * NC, Action_t A, bool ) { +QString WLanRun::setMyState( NodeCollection * , Action_t , bool ) { // we only handle activate and deactivate - switch( A ) { - case Activate : - { - if( NC->currentState() != Off ) { - return 0; - } - InterfaceInfo * N = getInterface(); - if( ! N ) { - // no interface available - NC->setCurrentState( Unavailable ); - return 0; - } - // because we were OFF the interface - // we get back is NOT assigned - N->assignNode( netNode() ); - assignInterface( N ); - NC->setCurrentState( Available ); - return 1; - } - case Deactivate : - if( NC->currentState() == IsUp ) { - // bring down first - if( ! connection()->setState( Down ) ) - // could not ... - return 0; - } else if( NC->currentState() != Available ) { - return 1; - } - assignedInterface()->assignNode( 0 ); // release - assignInterface( 0 ); - NC->setCurrentState( Off ); - return 1; - default : - // FT - break; - } - return 0; -} - -bool WLanRun::canSetState( State_t Curr, Action_t A ) { - // we only handle up down activate and deactivate - switch( A ) { - case Activate : - { // at least available - if( Curr == Available ) { - return 1; - } - // or we can make one available - InterfaceInfo * N = getInterface(); - if( ! N || N->assignedNode() != 0 ) { - // non available or assigned - return 0; - } - return 1; - } - case Deactivate : - return ( Curr >= Available ); - default : - // FT - break; - } - return 0; + return QString(); } // get interface that is free or assigned to us InterfaceInfo * WLanRun::getInterface( void ) { System & S = NSResources->system(); InterfaceInfo * best = 0, * Run; for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( *Run ) && ( Run->CardType == ARPHRD_ETHER #ifdef ARPHRD_IEEE1394 || Run->CardType == ARPHRD_IEEE1394 #endif ) ) { // this is a LAN card - if( Run->assignedNode() == netNode() ) { + if( Run->assignedConnection() == netNode()->connection() ) { // assigned to us return Run; - } else if( Run->assignedNode() == 0 ) { + } else if( Run->assignedConnection() == 0 ) { // free best = Run; } } } return best; // can be 0 } bool WLanRun::handlesInterface( const QString & S ) { InterfaceInfo * II; II = NSResources->system().interface( S ); if( ( II = NSResources->system().interface( S ) ) ) { return handlesInterface( *II ); } return Pat.match( S ) >= 0; } bool WLanRun::handlesInterface( const InterfaceInfo & II ) { return ( Pat.match( II.Name ) < 0 ); } diff --git a/noncore/settings/networksettings2/wlan/wlanrun.h b/noncore/settings/networksettings2/wlan/wlanrun.h index 25d5b96..fd325d4 100644 --- a/noncore/settings/networksettings2/wlan/wlanrun.h +++ b/noncore/settings/networksettings2/wlan/wlanrun.h @@ -1,37 +1,36 @@ #ifndef WLANRUN_H #define WLANRUN_H #include <qregexp.h> -#include <asdevice.h> +#include <netnode.h> #include "wlandata.h" -class WLanRun : public AsDevice { +class WLanRun : public RuntimeInfo { public : WLanRun( ANetNodeInstance * NNI, WLanData & Data ) : - AsDevice( NNI ), - Pat( "wlan[0-9]" ) - { } + RuntimeInfo( NNI ), + Pat( "wlan[0-9]" ) { + } - virtual AsDevice * device( void ) - { return (AsDevice *)this; } - virtual AsDevice * asDevice( void ) - { return (AsDevice *)this; } + virtual RuntimeInfo * device( void ) + { return this; } -protected : - - void detectState( NodeCollection * ); - bool setState( NodeCollection *, Action_t, bool ); - bool canSetState( State_t, Action_t ); bool handlesInterface( const QString & I ); bool handlesInterface( const InterfaceInfo & II ); + State_t detectState( void ); + +protected : + + QString setMyState( NodeCollection * , Action_t, bool ); + private : InterfaceInfo * getInterface( void ); QRegExp Pat; WLanData * Data; }; #endif diff --git a/noncore/settings/packagemanager/oconfitem.h b/noncore/settings/packagemanager/oconfitem.h index 9972c00..7b52ce4 100644 --- a/noncore/settings/packagemanager/oconfitem.h +++ b/noncore/settings/packagemanager/oconfitem.h @@ -1,96 +1,101 @@ /* This file is part of the Opie Project Copyright (c) 2003 Dan Williams <drw@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OCONFITEM_H #define OCONFITEM_H #include <qlist.h> #include <qstring.h> class OConfItem { public: - enum Type { Source, Destination, Option, Arch, NotDefined }; + enum Type { Source=0x01, + GzSource=0x02, + Destination=0x04, + Option=0x08, + Arch=0x10, + NotDefined=0x20 }; OConfItem( Type type = NotDefined, const QString &name = QString::null, const QString &value = QString::null, const QString &features = QString::null, bool active = true ); Type type() { return m_type; } const QString &name() { return m_name; } const QString &value() { return m_value; } const QString &features() { return m_features; } bool active() { return m_active; } void setType( Type type ) { m_type = type; } void setName( const QString &name ) { m_name = name; } void setValue( const QString &value ) { m_value = value; } void setFeatures( const QString &features ) { m_features = features; } void setActive( bool active ) { m_active = active; } private: Type m_type; // Type of configuration item QString m_name; // Name of item QString m_value; // Value of item QString m_features; // Comma-deliminated list of features this item supports bool m_active; // Indicates whether item is currently active }; class OConfItemList : public QList<OConfItem> { private: int compareItems( QCollection::Item item1, QCollection::Item item2 ) { // Sort by OConfItem location then by type OConfItem::Type type1 = reinterpret_cast<OConfItem*>(item1)->type(); OConfItem::Type type2 = reinterpret_cast<OConfItem*>(item2)->type(); if ( type1 < type2 ) return -1; else if ( type1 == type2 ) { QString name1 = reinterpret_cast<OConfItem*>(item1)->name(); QString name2 = reinterpret_cast<OConfItem*>(item2)->name(); if ( name1 < name2 ) return -1; else if ( name1 == name2 ) return 0; else /*if ( name1 > name2 )*/ return 1; } else /*if ( type1 > type2 )*/ return 1; } }; typedef QListIterator<OConfItem> OConfItemListIterator; #endif diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp index f2d7e39..a885ef8 100644 --- a/noncore/settings/packagemanager/oipkg.cpp +++ b/noncore/settings/packagemanager/oipkg.cpp @@ -1,765 +1,768 @@ /* This file is part of the Opie Project Copyright (c) 2003 Dan Williams <drw@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "oipkg.h" #include <qdir.h> #include <qfile.h> #include <qtextstream.h> #include <stdlib.h> #include <unistd.h> const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location const QString IPKG_INFO_PATH = "usr/lib/ipkg/info"; // Package file lists location OIpkg *oipkg; // Ipkg callback functions int fsignalIpkgMessage( ipkg_conf_t *conf, message_level_t level, char *msg ) { // Display message only if it is below the message level threshold if ( conf && ( conf->verbosity < level ) ) return 0; else oipkg->ipkgMessage( msg ); return 0; } char *fIpkgResponse( char */*question*/ ) { return 0l; } int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ ) { oipkg->ipkgStatus( desc ); return 0; } int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, void */*userdata*/ ) { oipkg->ipkgList( desc ); return 0; } OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) : QObject( parent, name ) , m_config( config ) , m_confInfo( NULL ) , m_ipkgExecOptions( 0 ) , m_ipkgExecVerbosity( 1 ) { // Keep pointer to self for the Ipkg callback functions oipkg = this; // Initialize libipkg ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); // Default ipkg run-time arguments m_ipkgArgs.noaction = false; m_ipkgArgs.force_defaults = true; } OIpkg::~OIpkg() { // Upon destruction, ensure that items in config list are deleted with list if ( m_confInfo ) m_confInfo->setAutoDelete( true ); // Free up libipkg resources ipkg_deinit( &m_ipkgArgs ); } OConfItemList *OIpkg::configItems() { // Retrieve all configuration items return filterConfItems(); } OConfItemList *OIpkg::servers() { // Retrieve only servers - return filterConfItems( OConfItem::Source ); + return filterConfItems( (OConfItem::Type)((int)OConfItem::Source | + (int)OConfItem::GzSource) ); } OConfItemList *OIpkg::destinations() { // Retrieve only destinations return filterConfItems( OConfItem::Destination ); } OConfItemList *OIpkg::options() { // Retrieve only destinations return filterConfItems( OConfItem::Option ); } void OIpkg::setConfigItems( OConfItemList *configList ) { if ( m_confInfo ) delete m_confInfo; m_confInfo = configList; // Write out new /etc/ipkg.conf QFile confFile( IPKG_CONF ); if ( confFile.open( IO_WriteOnly ) ) { QTextStream confStream( &confFile ); confStream << "# Generated by Opie Package Manager\n\n"; OConfItemListIterator it( *m_confInfo ); for ( ; it.current(); ++it ) { OConfItem *item = it.current(); // Only write out valid conf items if ( item->type() != OConfItem::NotDefined ) { QString confLine; if ( !item->active() ) confLine = "#"; switch ( item->type() ) { case OConfItem::Source : { if ( item->features().contains( "Compressed" ) ) confLine.append( "src/gz " ); else confLine.append( "src " ); } break; case OConfItem::Destination : confLine.append( "dest " ); break; case OConfItem::Option : confLine.append( "option " ); break; case OConfItem::Arch : confLine.append( "arch " ); break; default : break; }; confStream << confLine << " " << item->name() << " " << item->value() << "\n"; } } confFile.close(); } else { // Problem writing to /etc/ipkg.conf, exit before removing other conf files return; } // Delete /etc/ipkg/*.conf files (/etc/ipkg.conf should now have all settings QStringList confFiles; QDir confDir( IPKG_CONF_DIR ); if ( confDir.exists() ) { confDir.setNameFilter( "*.conf" ); confDir.setFilter( QDir::Files ); confFiles = confDir.entryList( "*.conf", QDir::Files ); QStringList::Iterator lastFile = confFiles.end(); for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) { // Create absolute file path if necessary QString absFile = (*it); if ( !absFile.startsWith( "/" ) ) absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); // Delete file QFile::remove( absFile ); } } // Reinitialize libipkg to pick up new configuration ipkg_deinit( &m_ipkgArgs ); ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); m_ipkgArgs.noaction = false; m_ipkgArgs.force_defaults = true; } void OIpkg::saveSettings() { // Save Ipkg execution options to application configuration file if ( m_config ) { m_config->setGroup( "Ipkg" ); m_config->writeEntry( "ExecOptions", m_ipkgExecOptions ); m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity ); } } OPackageList *OIpkg::availablePackages( const QString &server ) { // Load Ipkg configuration info if not already cached if ( !m_confInfo ) loadConfiguration(); // Build new server list (caller is responsible for deleting) OPackageList *pl = new OPackageList; // Open package list file QFile f( IPKG_PKG_PATH + "/" + server ); if ( !f.open( IO_ReadOnly ) ) return NULL; QTextStream t( &f ); // Process all information in package list file OPackage *package = NULL; QString line = t.readLine(); while ( !t.eof() ) { // Determine key/value pair int pos = line.find( ':', 0 ); QString key; if ( pos > -1 ) key = line.mid( 0, pos ); else key = QString::null; QString value = line.mid( pos+2, line.length()-pos ); // Allocate new package and insert into list if ( package == NULL && !key.isEmpty() ) { package = new OPackage( value ); package->setSource( server ); pl->append( package ); } // Update package data if ( key == "Package" ) package->setName( value ); else if ( key == "Version" ) package->setVersion( value ); else if ( key == "Section" ) package->setCategory( value ); //DataManager::setAvailableCategories( value ); else if ( key.isEmpty() && value.isEmpty() ) package = NULL; // Skip past all description lines if ( key == "Description" ) { line = t.readLine(); while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) line = t.readLine(); } else line = t.readLine(); } f.close(); return pl; } OPackageList *OIpkg::installedPackages( const QString &destName, const QString &destPath ) { // Load Ipkg configuration info if not already cached if ( !m_confInfo ) loadConfiguration(); // Build new server list (caller is responsible for deleting) OPackageList *pl = new OPackageList; // Open status file QString path = destPath; if ( path.right( 1 ) != "/" ) path.append( "/" ); path.append( IPKG_STATUS_PATH ); QFile f( path ); if ( !f.open( IO_ReadOnly ) ) return NULL; QTextStream t( &f ); // Process all information in status file bool newPackage = false; QString line = t.readLine(); QString name; QString version; QString status; while ( !t.eof() ) { // Determine key/value pair int pos = line.find( ':', 0 ); QString key; if ( pos > -1 ) key = line.mid( 0, pos ); else key = QString::null; QString value = line.mid( pos+2, line.length()-pos ); // Allocate new package and insert into list if ( newPackage && !key.isEmpty() ) { // Add to list only if it has a valid name and is installed if ( !name.isNull() && status.contains( " installed" ) ) { pl->append( new OPackage( name, QString::null, version, QString::null, destName ) ); name = QString::null; version = QString::null; status = QString::null; newPackage = false; } } // Update package data if ( key == "Package" ) name = value; else if ( key == "Version" ) version = value; else if ( key == "Status" ) status = value; else if ( key.isEmpty() && value.isEmpty() ) newPackage = true; // Skip past all description lines if ( key == "Description" ) { line = t.readLine(); while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) line = t.readLine(); } else line = t.readLine(); } f.close(); return pl; } OConfItem *OIpkg::findConfItem( OConfItem::Type type, const QString &name ) { // Find configuration item in list OConfItemListIterator configIt( *m_confInfo ); OConfItem *config = 0l; for ( ; configIt.current(); ++configIt ) { config = configIt.current(); if ( config->type() == type && config->name() == name ) break; } if ( config && config->type() == type && config->name() == name ) return config; return 0l; } bool OIpkg::executeCommand( OPackage::Command command, const QStringList ¶meters, const QString &destination, const QObject *receiver, const char *slotOutput, bool rawOutput ) { if ( command == OPackage::NotDefined ) return false; // Set ipkg run-time options/arguments m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS ); m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL ); // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE ); m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE ); m_ipkgArgs.verbosity = m_ipkgExecVerbosity; if ( m_ipkgArgs.dest ) free( m_ipkgArgs.dest ); if ( !destination.isNull() ) { int len = destination.length() + 1; m_ipkgArgs.dest = (char *)malloc( len ); strncpy( m_ipkgArgs.dest, destination, destination.length() ); m_ipkgArgs.dest[ len - 1 ] = '\0'; } else m_ipkgArgs.dest = 0l; // Connect output signal to widget if ( !rawOutput ) { // TODO - connect to local slot and parse output before emitting signalIpkgMessage } switch( command ) { case OPackage::Update : { connect( this, SIGNAL(signalIpkgMessage(const QString &)), receiver, slotOutput ); ipkg_lists_update( &m_ipkgArgs ); }; break; case OPackage::Upgrade : { connect( this, SIGNAL(signalIpkgMessage(const QString &)), receiver, slotOutput ); ipkg_packages_upgrade( &m_ipkgArgs ); // Re-link non-root destinations to make sure everything is in sync OConfItemList *destList = destinations(); OConfItemListIterator it( *destList ); for ( ; it.current(); ++it ) { OConfItem *dest = it.current(); if ( dest->name() != "root" ) linkPackageDir( dest->name() ); } delete destList; }; break; case OPackage::Install : { connect( this, SIGNAL(signalIpkgMessage(const QString &)), receiver, slotOutput ); for ( QStringList::ConstIterator it = parameters.begin(); it != parameters.end(); ++it ) { ipkg_packages_install( &m_ipkgArgs, (*it) ); } if ( destination != "root" ) linkPackageDir( destination ); }; break; case OPackage::Remove : { connect( this, SIGNAL(signalIpkgMessage(const QString &)), receiver, slotOutput ); // Get list of destinations for unlinking of packages not installed to root OConfItemList *destList = destinations(); for ( QStringList::ConstIterator it = parameters.begin(); it != parameters.end(); ++it ) { unlinkPackage( (*it), destList ); ipkg_packages_remove( &m_ipkgArgs, (*it), true ); } delete destList; }; break; case OPackage::Download : { connect( this, SIGNAL(signalIpkgMessage(const QString &)), receiver, slotOutput ); for ( QStringList::ConstIterator it = parameters.begin(); it != parameters.end(); ++it ) { ipkg_packages_download( &m_ipkgArgs, (*it) ); } }; break; case OPackage::Info : { connect( this, SIGNAL(signalIpkgStatus(const QString &)), receiver, slotOutput ); ipkg_packages_info( &m_ipkgArgs, (*parameters.begin()), &fIpkgStatus, 0l ); }; break; case OPackage::Files : { connect( this, SIGNAL(signalIpkgList(const QString &)), receiver, slotOutput ); ipkg_package_files( &m_ipkgArgs, (*parameters.begin()), &fIpkgFiles, 0l ); }; break; default : break; }; return true; } void OIpkg::ipkgMessage( char *msg ) { emit signalIpkgMessage( msg ); } void OIpkg::ipkgStatus( char *status ) { emit signalIpkgStatus( status ); } void OIpkg::ipkgList( char *filelist ) { emit signalIpkgList( filelist ); } void OIpkg::loadConfiguration() { if ( m_confInfo ) delete m_confInfo; // Load configuration item list m_confInfo = new OConfItemList(); QStringList confFiles; QDir confDir( IPKG_CONF_DIR ); if ( confDir.exists() ) { confDir.setNameFilter( "*.conf" ); confDir.setFilter( QDir::Files ); confFiles = confDir.entryList( "*.conf", QDir::Files ); } confFiles << IPKG_CONF; QStringList::Iterator lastFile = confFiles.end(); for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) { // Create absolute file path if necessary QString absFile = (*it); if ( !absFile.startsWith( "/" ) ) absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); // Read in file QFile f( absFile ); if ( f.open( IO_ReadOnly ) ) { QTextStream s( &f ); while ( !s.eof() ) { QString line = s.readLine().simplifyWhiteSpace(); // Parse line and save info to the conf options list if ( !line.isEmpty() ) { if ( !line.startsWith( "#" ) || line.startsWith( "#src" ) || + line.startsWith( "#src/gz" ) || line.startsWith( "#dest" ) || line.startsWith( "#arch" ) || line.startsWith( "#option" ) ) { int pos = line.find( ' ', 1 ); // Type QString typeStr = line.left( pos ); OConfItem::Type type; QString features; if ( typeStr == "src" || typeStr == "#src" ) type = OConfItem::Source; else if ( typeStr == "src/gz" || typeStr == "#src/gz" ) { type = OConfItem::Source; features = "Compressed"; } else if ( typeStr == "dest" || typeStr == "#dest" ) type = OConfItem::Destination; else if ( typeStr == "option" || typeStr == "#option" ) type = OConfItem::Option; else if ( typeStr == "arch" || typeStr == "#arch" ) type = OConfItem::Arch; else type = OConfItem::NotDefined; ++pos; int endpos = line.find( ' ', pos ); // Name QString name = line.mid( pos, endpos - pos ); // Value QString value = ""; if ( endpos > -1 ) value = line.right( line.length() - endpos - 1 ); // Active bool active = !line.startsWith( "#" ); // Add to list m_confInfo->append( new OConfItem( type, name, value, features, active ) ); } } } f.close(); } } // Load Ipkg execution options from application configuration file if ( m_config ) { m_config->setGroup( "Ipkg" ); m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions ); m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity ); } } OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter ) { // Load Ipkg configuration info if not already cached if ( !m_confInfo ) loadConfiguration(); // Build new server list (caller is responsible for deleting) OConfItemList *sl = new OConfItemList; // If typefilter is empty, retrieve all items bool retrieveAll = ( typefilter == OConfItem::NotDefined ); // Parse configuration info for servers OConfItemListIterator it( *m_confInfo ); for ( ; it.current(); ++it ) { OConfItem *item = it.current(); - if ( retrieveAll || item->type() == typefilter ) + if ( retrieveAll || + ( item->type() & typefilter ) ) { sl->append( item ); } } return sl; } const QString &OIpkg::rootPath() { if ( m_rootPath.isEmpty() ) { OConfItem *rootDest = findConfItem( OConfItem::Destination, "root" ); rootDest ? m_rootPath = rootDest->value() : m_rootPath = '/'; if ( m_rootPath.right( 1 ) == '/' ) m_rootPath.truncate( m_rootPath.length() - 1 ); } return m_rootPath; } void OIpkg::linkPackageDir( const QString &dest ) { if ( !dest.isNull() ) { OConfItem *destConfItem = findConfItem( OConfItem::Destination, dest ); emit signalIpkgMessage( tr( "Linking packages installed in: %1" ).arg( dest ) ); // Set package destination directory QString destDir = destConfItem->value(); QString destInfoDir = destDir; if ( destInfoDir.right( 1 ) != '/' ) destInfoDir.append( '/' ); destInfoDir.append( IPKG_INFO_PATH ); // Get list of installed packages in destination QDir packageDir( destInfoDir ); QStringList packageFiles; if ( packageDir.exists() ) { packageDir.setNameFilter( "*.list" ); packageDir.setFilter( QDir::Files ); packageFiles = packageDir.entryList( "*.list", QDir::Files ); } // Link all files for every package installed in desination QStringList::Iterator lastFile = packageFiles.end(); for ( QStringList::Iterator it = packageFiles.begin(); it != lastFile; ++it ) { //emit signalIpkgMessage( QString( "Processing: %1/%2" ).arg( destInfoDir ).arg (*it) ); QString packageFileName = destInfoDir; packageFileName.append( '/' ); packageFileName.append( (*it) ); QFile packageFile( packageFileName ); if ( packageFile.open( IO_ReadOnly ) ) { QTextStream t( &packageFile ); QString linkFile; while ( !t.eof() ) { // Get the name of the file to link and build the sym link filename linkFile = t.readLine(); QString linkDest( linkFile.right( linkFile.length() - destDir.length() ) ); linkDest.prepend( rootPath() ); // If file installed file is actually symbolic link, use actual file for linking QFileInfo fileInfo( linkFile ); if ( fileInfo.isSymLink() && !fileInfo.readLink().isEmpty() ) linkFile = fileInfo.readLink(); // See if directory exists in 'root', if not, create fileInfo.setFile( linkDest ); QString linkDestDirName = fileInfo.dirPath( true ); QDir linkDestDir( linkDestDirName ); if ( !linkDestDir.exists() ) { linkDestDir.mkdir( linkDestDirName ); } else { // Remove any previous link to make sure we will be pointing to the current version if ( QFile::exists( linkDest ) ) QFile::remove( linkDest ); } // Link the file //emit signalIpkgMessage( QString( "Linking '%1' to '%2'" ).arg( linkFile ).arg( linkDest ) ); if ( symlink( linkFile, linkDest ) == -1 ) emit signalIpkgMessage( tr( "Error linkling '%1' to '%2'" ) .arg( linkFile ) .arg( linkDest ) ); } packageFile.close(); } } } } void OIpkg::unlinkPackage( const QString &package, OConfItemList *destList ) { if ( !package.isNull() ) { // Find destination package is installed in if ( destList ) { OConfItemListIterator it( *destList ); for ( ; it.current(); ++it ) { OConfItem *dest = it.current(); QString destInfoFileName = QString( "%1/%2/%3.list" ).arg( dest->value() ) .arg( IPKG_INFO_PATH ) .arg( package ); //emit signalIpkgMessage( QString( "Looking for '%1'" ).arg ( destInfoFileName ) ); // If found and destination is not 'root', remove symbolic links if ( QFile::exists( destInfoFileName ) && dest->name() != "root" ) { QFile destInfoFile( destInfoFileName ); if ( destInfoFile.open( IO_ReadOnly ) ) { QTextStream t( &destInfoFile ); QString linkFile; while ( !t.eof() ) { // Get the name of the file to link and build the sym link filename linkFile = t.readLine(); QString linkDest( linkFile.right( linkFile.length() - dest->value().length() ) ); linkDest.prepend( rootPath() ); //emit signalIpkgMessage( QString( "Deleting: '%1'" ).arg( linkDest ) ); QFile::remove( linkDest ); } destInfoFile.close(); } emit signalIpkgMessage( tr( "Links removed for: %1" ).arg( package ) ); return; } } } } } diff --git a/noncore/settings/packagemanager/opie-packagemanager.control b/noncore/settings/packagemanager/opie-packagemanager.control index da3ddfe..0153d40 100644 --- a/noncore/settings/packagemanager/opie-packagemanager.control +++ b/noncore/settings/packagemanager/opie-packagemanager.control @@ -1,10 +1,10 @@ Package: opie-packagemanager Files: plugins/application/libpackagemanager.so* bin/packagemanager pics/packagemanager apps/Settings/packagemanager.desktop Priority: optional Section: opie/settings -Depends: task-opie-minimal, libopiecore2, libopieui2, libipkg (>=0.99.120) +Depends: task-opie-minimal, libopiecore2, libopieui2, libipkg0 (>=0.99.120), ipkg-link Replaces: packagemanager Architecture: arm Maintainer: Dan Williams (drw@handhelds.org) Description: Opie package management client -Version: 0.6.1$EXTRAVERSION +Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/tools/opie-sh/opie-sh.control b/noncore/tools/opie-sh/opie-sh.control index 106a183..496a036 100644 --- a/noncore/tools/opie-sh/opie-sh.control +++ b/noncore/tools/opie-sh/opie-sh.control @@ -1,11 +1,11 @@ Package: opie-sh Files: bin/opie-sh apps/Opie-SH/opie-sh.desktop pics/opie-sh/*.png help/opie-sh/*.html Priority: optional Section: opie/sh Maintainer: Thomas Stephens <spiralman@softhome.net> Architecture: arm -Version: 0.5-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal License: GPL Description: A QDialog shell frontend A program to let you use various dialogs from the console (or a shell script) diff --git a/noncore/tools/opie-sh/scripts/opie-sh-wavelanchooser.control b/noncore/tools/opie-sh/scripts/opie-sh-wavelanchooser.control index 3c3463f..0d6b235 100644 --- a/noncore/tools/opie-sh/scripts/opie-sh-wavelanchooser.control +++ b/noncore/tools/opie-sh/scripts/opie-sh-wavelanchooser.control @@ -1,11 +1,11 @@ Package: opie-sh-wavelanchooser Files: bin/opie-sh-wavelanchooser.sh apps/Opie-SH/opie-sh-wavelanchooser.desktop pics/opie-sh-scripts/qtwavelan.png Installed-Size: 0 -Version: 0.1-20020527-1 +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal (1.5.0+), opie-sh Priority: optional Section: opie/sh Maintainer: gonz <gonz@directbox.com> Architecture: all License: GPL Description: Frontend to choose wavelan config diff --git a/noncore/unsupported/filebrowser/opie-filebrowser.control b/noncore/unsupported/filebrowser/opie-filebrowser.control index d40bd8a..50080a1 100644 --- a/noncore/unsupported/filebrowser/opie-filebrowser.control +++ b/noncore/unsupported/filebrowser/opie-filebrowser.control @@ -1,10 +1,10 @@ Package: opie-filebrowser Files: bin/filebrowser apps/Applications/filebrowser.desktop pics/filebrowser/ Priority: optional Section: opie/applications Maintainer: Opie Team <opie@handhelds.org> Architecture: arm -Version: $QPE_VERSION-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal Description: Browse the file system The filebrowser for the Opie environment. diff --git a/noncore/unsupported/gsmtool/opie-gsmtool.control b/noncore/unsupported/gsmtool/opie-gsmtool.control index 6bd3b46..d987b11 100644 --- a/noncore/unsupported/gsmtool/opie-gsmtool.control +++ b/noncore/unsupported/gsmtool/opie-gsmtool.control @@ -1,11 +1,11 @@ Package: opie-gsmtool Files: plugins/application/libgsmtool.so* bin/gsmtool apps/Applications/gsmtool.desktop pics/gsmtool Priority: optional Section: opie/applications Maintainer: David Woodhouse <dwmw2@infradead.org> Architecture: arm -Version: 1.0.0-2 +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, gsmlib License: Public Domain Description: GSMTool program An GSM phone utility program for the Opie environment. diff --git a/noncore/unsupported/oipkg/opie-oipkg.control b/noncore/unsupported/oipkg/opie-oipkg.control index 17e7049..da6c755 100644 --- a/noncore/unsupported/oipkg/opie-oipkg.control +++ b/noncore/unsupported/oipkg/opie-oipkg.control @@ -1,10 +1,10 @@ Package: opie-oipkg Files: bin/oipkg apps/Settings/oipkg.desktop pics/oipkg/* Priority: optional Section: opie/settings Maintainer: Patrick S. Vogt <tille@almana.ch> Architecture: arm -Version: $QPE_VERSION-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal, ipkg (>0.99.20), ar Description: Opie Projects advanced gui ipkg installer A GUI front-end to ipkg for the Opie environment. diff --git a/noncore/unsupported/ubrowser/opie-ubrowser.control b/noncore/unsupported/ubrowser/opie-ubrowser.control index cf96888..bfa6c30 100644 --- a/noncore/unsupported/ubrowser/opie-ubrowser.control +++ b/noncore/unsupported/ubrowser/opie-ubrowser.control @@ -1,10 +1,10 @@ Package: opie-ubrowser Files: bin/ubrowser apps/Applications/ubrowser.desktop pics/ubrowser/*.png plugins/application/libubrowser.so* Priority: optional Section: opie/applications Maintainer: Thomas Stephens <spiralman@softhome.net> Architecture: arm -Version: 0.1-$SUB_VERSION +Version: $QPE_VERSION$EXTRAVERSION Depends: task-opie-minimal License: GPL Description: A very small web browser |