Fontes Estes são os fontes do programa de conexão a internet para o Debian, demais distribuiçoes usam, eu acho,formas diferentes de conexão, no Conectiva era "adsl-start", porem o programa pode ser ampliado para outras distribuições. No debian se usa o pacote pppoe , e os comandos são pon dsl-provider para iniciar a conexão, poff -a para finalizar e plog para o status da conexão. O shell-script que eu criei necessita que se edite o arquivo /etc/sudoers para dar permissão sudo ao route e ao plog, pois eles não executam como usuario normal. Cabeçalho: /*************************************************************************** * Copyright (C) 2007 by Rodolfo Ribeiro Machado * * rodolfo@Programador * * * * 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. * * * * 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef CONECTAR_H #define CONECTAR_H #include class util; /** @author Rodolfo Ribeiro Machado */ class fConectar_Internet : public QMainWindow,private Ui::fConectar { Q_OBJECT public: fConectar_Internet(QWidget *parent = 0, const char *name = 0); ~fConectar_Internet(); protected: class util* ut; private: QString* retorno; private slots: void fecha_Aplicacao(); void conecta_Internet(); void desconecta_Internet(); void estado_da_Conexao(); }; #endif corpo: /*************************************************************************** * Copyright (C) 2007 by Rodolfo Ribeiro Machado * * rodolfo@Programador * * * * 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. * * * * 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "conectar.h" #include "util.h" #include #include #include fConectar_Internet::fConectar_Internet(QWidget *parent, const char *name) : QMainWindow(parent) { setupUi(this); this->setAttribute(Qt::WA_DeleteOnClose,true); ut=new util(); ut->fixa_Tamanho(this); ut->centraliza_na_Tela(this); connect(botao_Sair,SIGNAL(clicked()),this,SLOT(fecha_Aplicacao())); connect(botao_Conectar,SIGNAL(clicked()),this,SLOT(conecta_Internet())); connect(botao_Desconectar,SIGNAL(clicked()),this,SLOT(desconecta_Internet())); connect(botao_Estado,SIGNAL(clicked()),this,SLOT(estado_da_Conexao())); retorno=new QString; *retorno=ut->lanca_Aplicativo("/Scripts/verifica_Conexao","",this); if (retorno->at(0)==QChar('s')) { botao_Conectar->setEnabled(false); QMessageBox::information(0,"Conectar à Internet","Sistema já esta conectado"); } } fConectar_Internet::~fConectar_Internet() { delete retorno; delete ut; } void fConectar_Internet::fecha_Aplicacao() { this->close(); } void fConectar_Internet::conecta_Internet() { *retorno=ut->lanca_Aplicativo("/Scripts/net","",this); QMessageBox::information(0,"Conectar à Internet",*retorno); *retorno=ut->lanca_Aplicativo("/Scripts/verifica_Conexao","",this); if (retorno->at(0)==QChar('n')) { if (!botao_Conectar->isEnabled()) botao_Conectar->setEnabled(true); } else botao_Conectar->setEnabled(false); } void fConectar_Internet::desconecta_Internet() { *retorno=ut->lanca_Aplicativo("/Scripts/net_off","",this); QMessageBox::information(0,"Conectar à Internet",*retorno); *retorno=ut->lanca_Aplicativo("/Scripts/verifica_Conexao","",this); if (retorno->at(0)==QChar('n')) { if (!botao_Conectar->isEnabled()) botao_Conectar->setEnabled(true); } } void fConectar_Internet::estado_da_Conexao() { *retorno=ut->lanca_Aplicativo("/Scripts/estado_da_Conexao","",this); QMessageBox::information(0,"Conectar à Internet",*retorno); } main: /*************************************************************************** * Copyright (C) 2007 by Rodolfo Ribeiro Machado * * rodolfo@Programador * * * * 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. * * * * 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include "conectar.h" int main( int argc, char ** argv ) { QApplication a( argc, argv ); fConectar_Internet * fConexao_net = new fConectar_Internet(); fConexao_net->show(); a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); return a.exec(); } util.h: #ifndef UTIL_H #define UTIL_H class QMainWindow; class QKeyEvent; class QSqlQuery; class QSqlQueryModel; class QString; class QTableView; class QWidget; class QAction; class QDesktopWidget; class QRect; class QStringList; class QLineEdit; class QLabel; class QCloseEvent; /** @author Rodolfo Ribeiro Machado,,, */ class util { public: util(); ~util(); void fixa_Tamanho(QWidget* comp); void centraliza_na_Tela(QWidget* comp); QString lanca_Aplicativo(QString aplicativo,QString argumento,QWidget* comp); }; #endif util.cpp: #include "util.h" #include #include #include #include #include #include util::util() { } util::~util() { } void util::fixa_Tamanho(QWidget* comp) { QSize* tamanho=new QSize(); *tamanho=comp->size(); comp->setFixedSize (*tamanho); delete tamanho; } void util::centraliza_na_Tela(QWidget* comp) { QSize* tamanho=new QSize(); *tamanho=comp->size(); QDesktopWidget* desk=new QDesktopWidget(); QRect rect=desk->screenGeometry(0); int * x1=new int; int * y1=new int; int * x2=new int; int * y2=new int; rect.getCoords(x1,y1,x2,y2); comp->setGeometry((*x2-tamanho-> width ())/2,(*y2-tamanho-> height ())/2,tamanho-> width (),tamanho-> height ()); delete tamanho; delete x1; delete x2; delete y1; delete y2; delete desk; } QString util::lanca_Aplicativo(QString aplicativo,QString argumento,QWidget* comp) { QStringList argumento_2; argumento_2<start(aplicativo, argumento_2); myProcess->waitForFinished(); return myProcess->readAllStandardOutput(); } Este é o arquivo gerado pelo QTDesigner, copie e salve como fConectar.ui, ao abrir no Designer ele ira reclamar a falta do arquivo de icones, substitua por um seu. fConectar 0 0 322 135 Conectar-se à Internet :/new/prefix1/icones/connect_creating.png false 6 12 151 41 &Conectar :/new/prefix1/icones/connect_creating.png 6 72 151 41 &Desconectar :/new/prefix1/icones/connect_no.png 166 72 151 41 &Sair :/new/prefix1/icones/exit.png 166 12 151 41 &Estado da Conexão :/new/prefix1/icones/connect_established.png botao_Conectar botao_Estado botao_Desconectar botao_Sair Agora são os shell-scripts: nomeie este como "verifica_Conexao" #!/bin/bash if ps -el | grep ppp > /dev/null; then echo s; else echo n fi; nomeie este como "net" #!/bin/bash if [ -e /usr/bin/pon ]; then if pon dsl-provider; then sleep 3; if /sbin/ifconfig | grep ppp0; then if sudo /sbin/route add default ppp0; then echo Conexão bem sucedida.; else /usr/bin/poff -a; sleep 5; echo Não foi possivel estabelecer uma conexão; fi; else /usr/bin/poff -a; echo Não foi possivel estabelecer uma conexão; fi; else echo Não foi possivel estabelecer uma conexão; fi; else echo /usr/bin/pon não esta instalado!; fi; nomeie este como "net_off" #!/bin/bash if /usr/bin/poff -a; then sleep 5; echo Conexão terminada; fi; nomeie este como "estado_da_Conexao" #!/bin/bash sudo plog Crie um arquivo texto com os nomes indicados para cada um e salve em um diretório de sua preferencia, tomando o cuidado de alterar os fontes para o caminho de seu diretório. Substituam todos os caminhos de diretórios no fonte pelos seus.