00001 00002 #include "pindlg.h" 00003 00004 /* OPIE */ 00005 #include <qpe/config.h> 00006 #include <qpe/qpeapplication.h> 00007 00008 /* QT */ 00009 #include <qcheckbox.h> 00010 #include <qlabel.h> 00011 #include <qlineedit.h> 00012 #include <qpushbutton.h> 00013 00014 /* STD */ 00015 #include <stdio.h> 00016 00017 using namespace OpieTooth; 00018 00019 PinDlg::PinDlg(QWidget* parent, 00020 const char* name, 00021 Qt::WFlags f ) 00022 : PinDlgBase( parent, name, f ) 00023 { 00024 m_mac = makeMacFromArgs(); 00025 00026 if(m_mac.isEmpty()) 00027 { 00028 // can't obtain MAC 00029 printf("ERR\n"); 00030 ::exit(0); 00031 } 00032 else 00033 { 00034 test( m_mac ); 00035 txtStatus->setText(makeTextFromArgs()); 00036 QPEApplication::showDialog( this , false) ; 00037 } 00038 } 00039 00040 PinDlg::~PinDlg() 00041 {} 00042 00043 void PinDlg::setMac( const QString& mac ) 00044 { 00045 txtStatus->setText( mac ); 00046 } 00047 00048 QString PinDlg::pin() const 00049 { 00050 return lnePin->text(); 00051 } 00052 00053 void PinDlg::test( const QString& mac ) 00054 { 00055 if (!mac.isEmpty() ) 00056 { 00057 Config cfg("bluepin"); 00058 cfg.setGroup(mac); 00059 lnePin->setText(cfg.readEntryCrypt("pin", QString::null ) ); 00060 } 00061 } 00062 00063 QString PinDlg::makeTextFromArgs() 00064 { 00065 if(qApp->argc() > 2) 00066 { 00067 QCString dir(qApp->argv()[1]) ; 00068 QCString bdaddr(qApp->argv()[2]) ; 00069 00070 QCString name; 00071 if ( qApp->argc() > 3 ) { 00072 name = qApp->argv()[3]; 00073 } 00074 QString status; 00075 if (dir == "out" ) { 00076 status = QObject::tr("Outgoing connection to "); 00077 } else 00078 status = QObject::tr("Incoming connection from "); 00079 00080 status += name; 00081 status += "<br>"; 00082 status += "[" + bdaddr + "]"; 00083 00084 return status ; 00085 } 00086 else 00087 return QString::null; 00088 } 00089 00090 QString PinDlg::makeMacFromArgs() 00091 { 00092 if(qApp->argc() < 3) 00093 return QString::null; 00094 else 00095 return qApp->argv()[2] ; 00096 } 00097 00098 void PinDlg::addnum() 00099 { 00100 if( sender()->inherits( "QPushButton") ) { 00101 const QPushButton* btn = static_cast<const QPushButton*> (sender()); 00102 lnePin->setText(lnePin->text() + btn->text()); 00103 } 00104 } 00105 00106 void PinDlg::accept() 00107 { 00108 if ( ckbPin->isChecked() ) 00109 { 00110 Config cfg("bluepin"); 00111 cfg.setGroup(m_mac ); 00112 cfg.writeEntryCrypt("pin", lnePin->text() ); 00113 } 00114 printf("PIN:%s\n", lnePin->text().latin1()); 00115 QDialog::accept(); 00116 qApp->quit(); 00117 ::exit(0); 00118 } 00119
1.4.2