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

rfcommassigndialogimpl.cpp

Go to the documentation of this file.
00001 
00002 #include "rfcommassigndialogimpl.h"
00003 #include "rfcommassigndialogitem.h"
00004 #include "rfcommconfhandler.h"
00005 
00006 /* OPIE */
00007 #include <qpe/config.h>
00008 #include <qpe/qpeapplication.h>
00009 #include <opie2/odebug.h>
00010 using namespace Opie::Core;
00011 
00012 /* QT */
00013 #include <qlayout.h>
00014 
00015 using namespace OpieTooth;
00016 
00017 // TODO: write only the file in bluebase?
00018 // muss rfcommd dann neu gestartet werden
00019 // sollte rfcomm bind all nicht eh default config sein ( polled das? - d.h. sobald nen gerät in der nähe ist bindet es?
00020 
00021 
00022 RfcommAssignDialog::RfcommAssignDialog( QWidget* parent,  const char* name, bool modal, WFlags fl )
00023         : RfcommAssignDialogBase( parent, name, modal, fl )
00024 {
00025 
00026     m_range = 5;
00027 
00028     m_scrollView = new QScrollView( this );
00029     m_scrollView->setResizePolicy( QScrollView::AutoOneFit );
00030     m_scrollView->setHScrollBarMode( QScrollView::AlwaysOff );
00031 
00032     RfcommAssignDialogBaseLayout->addWidget( m_scrollView );
00033 
00034     m_box = new QVBox( m_scrollView->viewport() );
00035     m_scrollView->addChild( m_box );
00036 
00037     confHandler = new RfCommConfHandler( "/etc/bluetooth/rfcomm.conf" );
00038 
00039     loadConfig();
00040 }
00041 
00042 RfcommAssignDialog::~RfcommAssignDialog()
00043 {
00044     if ( confHandler )
00045     {
00046         delete confHandler;
00047     }
00048 }
00049 
00050 
00051 void RfcommAssignDialog::newDevice( const QString & mac )
00052 {
00053 
00054     for ( int i = 0 ; i < m_range; i++ )
00055     {
00056 
00057         QMap<QString, RfCommConfObject*>::Iterator it;
00058         it = confHandler->foundEntries().find( QString("%1").arg( i ) );
00059         // make sure that rfcommX is not assigned yet
00060         if (  it == confHandler->foundEntries().end() )
00061         {
00062             QDialog dialog( this,  "newdevice", true, WStyle_ContextHelp );
00063 
00064             RfcommDialogItem *newDev = new RfcommDialogItem( &dialog );
00065             newDev->setIdent( i );
00066             newDev->setMac( mac );
00067 
00068             if ( QPEApplication::execDialog( &dialog ) == QDialog::Accepted )
00069             {
00070                 RfcommDialogItem *rfcomm = new RfcommDialogItem( m_box );
00071                 m_itemList.insert( i , rfcomm );
00072                 rfcomm->setIdent( i );
00073                 rfcomm->setMac( mac );
00074                 rfcomm->setChannel( newDev->channel() );
00075                 rfcomm->setComment( newDev->comment() );
00076                 odebug << "New device set up" << oendl; 
00077             }
00078         }
00079     }
00080 }
00081 
00082 void RfcommAssignDialog::loadConfig()
00083 {
00084 
00085     //Config cfg( "bluetoothmanager-rfcommbind" );
00086 
00087     for ( int i = 0 ; i < m_range; i++ )
00088     {
00089         // cfg.setGroup( QString("%1").arg( i ) );
00090         RfcommDialogItem *rfcomm = new RfcommDialogItem( m_box );
00091         m_itemList.insert( i , rfcomm );
00092         rfcomm->setIdent( i );
00093         QMap<QString, RfCommConfObject*>::Iterator it;
00094         it = confHandler->foundEntries().find( QString("%1").arg( i ) );
00095         if ( it != confHandler->foundEntries().end() )
00096         {
00097             odebug << "Found key in foundEntries() " << oendl; 
00098             rfcomm->setMac( it.data()->mac() );
00099             rfcomm->setChannel( it.data()->channel() );
00100             rfcomm->setComment( it.data()->comment() );
00101         }
00102         /* Use rfcomm.conf directly for now
00103          * rfcomm->setMac( cfg.readEntry( "mac",  "" ) );
00104          * rfcomm->setChannel( cfg.readNumEntry( "channel", 1 ) );
00105          * rfcomm->setComment( cfg.readEntry( "comment", "" ) );
00106          */
00107     }
00108 }
00109 
00110 
00111 void RfcommAssignDialog::saveConfig()
00112 {
00113 
00114     //Config cfg( "bluetoothmanager-rfcommbind" );
00115 
00116     QMap< int, RfcommDialogItem*>::Iterator it;
00117 
00118     QMap< QString, RfCommConfObject*> outMap;
00119 
00120     for( it = m_itemList.begin(); it != m_itemList.end(); ++it )
00121     {
00122 
00123         //cfg.setGroup( QString("%1").arg( it.key() ) );
00124         RfcommDialogItem *rfcomm = it.data();
00125 
00126 
00127         outMap.insert( QString( "%1").arg( it.key() ), new RfCommConfObject( it.key(), rfcomm->mac(), rfcomm->channel(),  rfcomm->comment() ) );
00128 
00129 
00130         //cfg.writeEntry( "mac",  rfcomm->mac() );
00131         //cfg.writeEntry( "channel", rfcomm->channel() );
00132         //cfg.writeEntry( "comment", rfcomm->comment() );
00133     }
00134 
00135     confHandler->save( outMap );
00136 
00137 }

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