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

scandialog.cpp

Go to the documentation of this file.
00001 /* main.cpp
00002  *
00003  * ---------------------
00004  *
00005  * copyright   : (c) 2002 by Maximilian Reiß
00006  * email       : max.reiss@gmx.de
00007  *
00008  */
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #include "scandialog.h"
00020 
00021 #include <qheader.h>
00022 #include <qlistview.h>
00023 #include <qpushbutton.h>
00024 #include <qlayout.h>
00025 #include <qvariant.h>
00026 #include <qtooltip.h>
00027 #include <qwhatsthis.h>
00028 #include <qprogressbar.h>
00029 #include <qlist.h>
00030 
00031 #include <manager.h>
00032 #include <device.h>
00033 
00034 #include <opie2/odebug.h>
00035 using namespace Opie::Core;
00036 
00037 
00038 namespace OpieTooth {
00039 
00040 #include <remotedevice.h>
00041 
00044     ScanDialog::ScanDialog( QWidget* parent,  const char* name, bool modal, WFlags fl )
00045         : QDialog( parent, name, modal, fl ) {
00046 
00047         setCaption( tr( "Scan for devices" ) );
00048 
00049         Layout11 = new QVBoxLayout( this );
00050         Layout11->setSpacing( 6 );
00051         Layout11->setMargin( 0 );
00052 
00053         progress = new QProgressBar( this, "progbar");
00054         progress->setTotalSteps(20);
00055 
00056         StartStopButton = new QPushButton( this, "StartButton" );
00057         StartStopButton->setText( tr( "Start scan" ) );
00058 
00059         serviceView = new QListView( this, "serviceView" );
00060 
00061         //serviceView->addColumn( tr( "Add" ) );
00062         serviceView->addColumn( tr( "Add Device" ) );
00063         //serviceView->addColumn( tr( "Type" ) );
00064 
00065         Layout11->addWidget( serviceView );
00066         Layout11->addWidget( progress );
00067         Layout11->addWidget( StartStopButton );
00068 
00069         localDevice = new Manager( "hci0" );
00070 
00071         connect( StartStopButton, SIGNAL( clicked() ), this, SLOT( startSearch() ) );
00072         connect( localDevice, SIGNAL( foundDevices(const QString&,RemoteDevice::ValueList) ),
00073                  this, SLOT( fillList(const QString&,RemoteDevice::ValueList) ) ) ;
00074 
00075         progressStat = 0;
00076         m_search = false;
00077     }
00078 
00079 // hack, make cleaner later
00080     void ScanDialog::progressTimer() {
00081 
00082         progressStat++;
00083         if ( progressStat++ < 20 && m_search ) {
00084             QTimer::singleShot( 2000, this, SLOT( progressTimer() ) );
00085             progress->setProgress( progressStat++ );
00086         }
00087     }
00088 
00089     void ScanDialog::accept() {
00090         emitToManager();
00091         QDialog::accept();
00092     }
00093 
00094 
00095     void ScanDialog::startSearch() {
00096         if ( m_search ) {
00097             stopSearch();
00098             return;
00099         }
00100         m_search = true;
00101         progress->setProgress(0);
00102         progressStat = 0;
00103 
00104         // empty list before a new scan
00105         serviceView->clear();
00106 
00107         progressTimer();
00108         // when finished, it emmite foundDevices()
00109         // checken ob initialisiert , qcop ans applet.
00110         StartStopButton->setText( tr( "Stop scan" ) );
00111 
00112         localDevice->searchDevices();
00113 
00114     }
00115 
00116     void ScanDialog::stopSearch() {
00117         m_search = true;
00118     }
00119 
00120     void ScanDialog::fillList(const QString&, RemoteDevice::ValueList deviceList) {
00121         progress->setProgress(0);
00122         progressStat = 0;
00123         QCheckListItem * deviceItem;
00124 
00125         RemoteDevice::ValueList::Iterator it;
00126         for( it = deviceList.begin(); it != deviceList.end(); ++it ) {
00127 
00128             deviceItem = new QCheckListItem( serviceView, (*it).name(),  QCheckListItem::CheckBox );
00129             deviceItem->setText( 1, (*it).mac() );
00130         }
00131         m_search = false;
00132         StartStopButton->setText( tr( "Start scan" ) );
00133     }
00134 
00139     void ScanDialog::emitToManager() {
00140 
00141         if (!serviceView) {
00142             return;
00143         }
00144 
00145         QValueList<RemoteDevice> deviceList;
00146 
00147         QListViewItemIterator it( serviceView );
00148         for ( ; it.current(); ++it ) {
00149             if ( ( (QCheckListItem*)it.current() )->isOn() ) {
00150                 RemoteDevice device(  it.current()->text(1), it.current()->text(0) );
00151                 deviceList.append( device );
00152             }
00153         }
00154         emit selectedDevices( deviceList );
00155     }
00156 
00160     ScanDialog::~ScanDialog() {
00161         owarn << "delete scan dialog" << oendl; 
00162         delete localDevice;
00163     }
00164 }

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