-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.cpp | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp index 88a474d..bb46dd7 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.cpp +++ b/noncore/net/wellenreiter/gui/mainwindow.cpp @@ -12,36 +12,40 @@ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "configwindow.h" #include "gps.h" #include "logwindow.h" #include "hexwindow.h" #include "mainwindow.h" #include "wellenreiter.h" #include "scanlist.h" #include <qcombobox.h> #include <qdatastream.h> #include <qfile.h> #include <qfileinfo.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> #include <qiconset.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qpopupmenu.h> +#include <qpushbutton.h> #include <qstatusbar.h> #include <qtextstream.h> #include <qtoolbutton.h> #ifdef QWS #include <qpe/resource.h> #include <opie/ofiledialog.h> #else #include "resource.h" #include <qapplication.h> #include <qfiledialog.h> #endif WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) :QMainWindow( parent, name, f ) { @@ -74,34 +78,34 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) ); stopButton->setEnabled( false ); connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) ); QToolButton* d = new QToolButton( 0 ); #ifdef QWS d->setAutoRaise( true ); #endif d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) ); connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); uploadButton = new QToolButton( 0 ); #ifdef QWS uploadButton->setAutoRaise( true ); #endif uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); - //uploadButton->setEnabled( false ); - uploadButton->setEnabled( true ); + uploadButton->setEnabled( false ); + //uploadButton->setEnabled( true ); // DEBUGGING connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); // setup menu bar int id; QMenuBar* mb = menuBar(); QPopupMenu* fileSave = new QPopupMenu( mb ); fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) ); fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) ); fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) ); QPopupMenu* fileLoad = new QPopupMenu( mb ); fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) ); //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); @@ -363,52 +367,84 @@ void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) } else { QMainWindow::closeEvent( e ); } } static const char* CAP_hostname = "www.vanille.de"; #include <netdb.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> void WellenreiterMainWindow::uploadSession() { + QLineEdit* from; + QLineEdit* location; + QLineEdit* comments; + QPushButton* accept; + QPushButton* reject; + + QDialog* d = new QDialog( 0, "session upload", true ); + d->setCaption( tr( "Upload Session" ) ); + QGridLayout* g = new QGridLayout( d, 4, 2, 3 ); + g->addWidget( new QLabel( tr( "From: " ), d ), 0, 0 ); + g->addWidget( from = new QLineEdit( d ), 0, 1 ); + g->addWidget( new QLabel( tr( "Location: " ), d ), 1, 0 ); + g->addWidget( location = new QLineEdit( d ), 1, 1 ); + g->addWidget( new QLabel( tr( "Comments: " ), d ), 2, 0 ); + g->addWidget( comments = new QLineEdit( d ), 2, 1 ); + g->addWidget( accept = new QPushButton( tr( "&Ok" ), d ), 3, 0 ); + g->addWidget( reject = new QPushButton( tr( "&Cancel" ), d ), 3, 1 ); + accept->setDefault( true ); + accept->setAutoDefault( true ); + from->setText( "WL II User" ); + location->setText( "WL II Location" ); + comments->setText( "No Comments." ); + connect( accept, SIGNAL( clicked() ), d, SLOT( accept() ) ); + connect( reject, SIGNAL( clicked() ), d, SLOT( reject() ) ); + int result = d->exec(); + + if ( !result ) + { + qDebug( "Session upload cancelled :(" ); + return; + } + qDebug( "Starting upload..." ); struct sockaddr_in raddr; struct hostent *rhost_info; int sock = -1; bool ok = false; rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname ); if ( rhost_info ) { if ( !QFile::exists( "/var/log/dump.wellenreiter" ) ) { - qDebug( "no file to upload!" ); + QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Logfile doesn't exist</p>") ); return; } QFile f( "/var/log/dump.wellenreiter" ); if ( !f.open( IO_ReadOnly ) ) { - qDebug( "can't open file!" ); + QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Can't open Logfile</p>") ); return; } int content_length = f.size(); ::memset( &raddr, 0, sizeof (struct sockaddr_in) ); ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); raddr.sin_family = rhost_info-> h_addrtype; raddr.sin_port = htons ( 80 ); sock = ::socket( AF_INET, SOCK_STREAM, 0 ); if ( sock >= 0 ) { if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) { @@ -422,49 +458,53 @@ void WellenreiterMainWindow::uploadSession() "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031010 Galeon/1.3.10\r\n" "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n" "Accept-Language: en\r\n" "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n" "Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n" "Keep-Alive: 300\r\n" "Connection: keep-alive\r\n" "Referer: http://www.vanille.de/projects/capturedump.spy\r\n" "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n" "Content-Length: %1\r\n" "\r\n"; content = "" "-----------------------------97267758015830030481215568065\r\n" "Content-Disposition: form-data; name=\"Name\"\r\n" "\r\n" - "Anonymous Wellenreiter II User\r\n" + "%1\r\n" "-----------------------------97267758015830030481215568065\r\n" "Content-Disposition: form-data; name=\"Location\"\r\n" "\r\n" - "Anonymous Wellenreiter II Location\r\n" + "%2\r\n" "-----------------------------97267758015830030481215568065\r\n" "Content-Disposition: form-data; name=\"Comments\"\r\n" "\r\n" - "Anonymous Wellenreiter II Comments\r\n" + "%3\r\n" "-----------------------------97267758015830030481215568065\r\n" "Content-Disposition: form-data; name=\"upfile\"; filename=\"/var/log/dump.wellenreiter\"\r\n" "Content-Type: application/octet-stream\r\n" "\r\n"; preambel = "" "\r\n-----------------------------97267758015830030481215568065--\r\n"; + content = content.arg( from->text().isEmpty() ? QString( "Anonymous Wellenreiter II User" ) : from->text() ); + content = content.arg( location->text().isEmpty() ? QString( "Anonymous Wellenreiter II Location" ) : location->text() ); + content = content.arg( comments->text().isEmpty() ? QString( "Anonymous Wellenreiter II Comments" ) : comments->text() ); + header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) ); // write header const char* ascii = header.latin1(); uint ascii_len = ::strlen( ascii ); ::write ( sock, ascii, ascii_len ); // write fixed content ascii = content.latin1(); ascii_len = ::strlen( ascii ); ::write ( sock, ascii, ascii_len ); // write variable content @@ -476,21 +516,23 @@ void WellenreiterMainWindow::uploadSession() } // write preambel ascii = preambel.latin1(); ascii_len = ::strlen( ascii ); ::write ( sock, ascii, ascii_len ); // done! ok = true; } } ::close ( sock ); } if ( ok ) - QMessageBox::information ( 0, tr( "Success" ), QString ( "<p>%1</p>" ). arg( tr( "Capture Dump was uploaded to %1" )).arg ( CAP_hostname )); + QMessageBox::information( 0, tr( "Success" ), + QString ( "<p>%1</p>" ).arg( tr( "Capture Dump was uploaded to %1" ) ).arg( CAP_hostname ) ); else - QMessageBox::warning ( 0, tr( "Error" ), QString ( "<p>%1</p>" ). arg ( tr( "Connection to %1 failed." )). arg ( CAP_hostname )); + QMessageBox::warning( 0, tr( "Error" ), + QString ( "<p>%1</p>" ).arg ( tr( "Connection to %1 failed" ) ).arg( CAP_hostname ) ); } |